From 44228739649d716ed0edb6205434ec72588129bb Mon Sep 17 00:00:00 2001 From: Cameron Messinides Date: Mon, 8 Jun 2020 11:20:34 -0400 Subject: [PATCH] throw parser error when :global() appears without a selector (#4936) --- src/compiler/parse/read/style.ts | 9 ++++++++- .../error-css-global-without-selector/error.json | 10 ++++++++++ .../error-css-global-without-selector/input.svelte | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/parser/samples/error-css-global-without-selector/error.json create mode 100644 test/parser/samples/error-css-global-without-selector/input.svelte diff --git a/src/compiler/parse/read/style.ts b/src/compiler/parse/read/style.ts index dd9d1286f2..71fd629151 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-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; @@ -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..f4237c65d3 --- /dev/null +++ b/test/parser/samples/error-css-global-without-selector/error.json @@ -0,0 +1,10 @@ +{ + "code": "css-syntax-error", + "message": ":global() must contain a selector", + "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 @@ +