Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide parser error when :global appears without selector in CSS #4936

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/compiler/parse/read/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export default function read_style(parser: Parser, start: number, attributes: No
}, node.start);
}

if (node.type === 'PseudoClassSelector' && node.name === 'global' && node.children === null) {
parser.error({
code: `css-syntax-error`,
message: `:global() must contain a selector`
}, node.loc.start.offset);
}

if (node.loc) {
node.start = node.loc.start.offset;
node.end = node.loc.end.offset;
Expand Down Expand Up @@ -87,4 +94,4 @@ function is_ref_selector(a: any, b: any) { // TODO add CSS node types
a.name === 'ref' &&
b.type === 'PseudoClassSelector'
);
}
}
10 changes: 10 additions & 0 deletions test/parser/samples/error-css-global-without-selector/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"code": "css-syntax-error",
"message": ":global() must contain a selector",
"start": {
"line": 2,
"column": 1,
"character": 9
},
"pos": 9
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<style>
:global {}
</style>