diff --git a/src/compiler/parse/read/style.ts b/src/compiler/parse/read/style.ts index dd9d1286f2..70633cc6a8 100644 --- a/src/compiler/parse/read/style.ts +++ b/src/compiler/parse/read/style.ts @@ -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-global-without-selector`, + message: `:global() must contain a selector, cannot be used on its own` + }, node.loc.start.offset); + } + if (node.loc) { node.start = node.loc.start.offset; node.end = node.loc.end.offset; @@ -87,4 +94,4 @@ function is_ref_selector(a: any, b: any) { // TODO add CSS node types a.name === 'ref' && b.type === 'PseudoClassSelector' ); -} \ No newline at end of file +} diff --git a/test/parser/samples/error-css-global-without-selector/error.json b/test/parser/samples/error-css-global-without-selector/error.json new file mode 100644 index 0000000000..1759181e84 --- /dev/null +++ b/test/parser/samples/error-css-global-without-selector/error.json @@ -0,0 +1,10 @@ +{ + "code": "css-global-without-selector", + "message": ":global() must contain a selector, cannot be used on its own", + "start": { + "line": 2, + "column": 1, + "character": 9 + }, + "pos": 9 +} diff --git a/test/parser/samples/error-css-global-without-selector/input.svelte b/test/parser/samples/error-css-global-without-selector/input.svelte new file mode 100644 index 0000000000..a626136cfc --- /dev/null +++ b/test/parser/samples/error-css-global-without-selector/input.svelte @@ -0,0 +1,3 @@ +