diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index c88a244a13..d9868f4530 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -227,7 +227,8 @@ function apply_selector(blocks: Block[], node: Element, to_encapsulate: Array<{ return false; } else if (block.combinator.name === '>') { - if (apply_selector(blocks, get_element_parent(node), to_encapsulate)) { + const has_global_parent = blocks.every(block => block.global); + if (has_global_parent || apply_selector(blocks, get_element_parent(node), to_encapsulate)) { to_encapsulate.push({ node, block }); return true; } diff --git a/test/css/samples/global-with-child-combinator-2/_config.js b/test/css/samples/global-with-child-combinator-2/_config.js new file mode 100644 index 0000000000..2286f4fe3c --- /dev/null +++ b/test/css/samples/global-with-child-combinator-2/_config.js @@ -0,0 +1,27 @@ +export default { + warnings: [ + { + code: 'css-unused-selector', + end: { + character: 111, + column: 21, + line: 8 + }, + frame: ` + 6: color: red; + 7: } + 8: a:global(.foo) > div { + ^ + 9: color: red; + 10: } + `, + message: 'Unused CSS selector "a:global(.foo) > div"', + pos: 91, + start: { + character: 91, + column: 1, + line: 8 + } + } + ] +}; diff --git a/test/css/samples/global-with-child-combinator-2/expected.css b/test/css/samples/global-with-child-combinator-2/expected.css new file mode 100644 index 0000000000..3f406244a3 --- /dev/null +++ b/test/css/samples/global-with-child-combinator-2/expected.css @@ -0,0 +1 @@ +div>div.svelte-xyz.svelte-xyz{color:red}div.svelte-xyz.foo>div.svelte-xyz{color:red} \ No newline at end of file diff --git a/test/css/samples/global-with-child-combinator-2/expected.html b/test/css/samples/global-with-child-combinator-2/expected.html new file mode 100644 index 0000000000..32ff99e34f --- /dev/null +++ b/test/css/samples/global-with-child-combinator-2/expected.html @@ -0,0 +1,3 @@ +
+
+
\ No newline at end of file diff --git a/test/css/samples/global-with-child-combinator-2/input.svelte b/test/css/samples/global-with-child-combinator-2/input.svelte new file mode 100644 index 0000000000..caf7c5869a --- /dev/null +++ b/test/css/samples/global-with-child-combinator-2/input.svelte @@ -0,0 +1,15 @@ + + +
+
+
\ No newline at end of file diff --git a/test/css/samples/global-with-child-combinator-3/_config.js b/test/css/samples/global-with-child-combinator-3/_config.js new file mode 100644 index 0000000000..c81f1a9f82 --- /dev/null +++ b/test/css/samples/global-with-child-combinator-3/_config.js @@ -0,0 +1,3 @@ +export default { + warnings: [] +}; diff --git a/test/css/samples/global-with-child-combinator-3/expected.css b/test/css/samples/global-with-child-combinator-3/expected.css new file mode 100644 index 0000000000..11c60c7147 --- /dev/null +++ b/test/css/samples/global-with-child-combinator-3/expected.css @@ -0,0 +1 @@ +a>b>div.svelte-xyz{color:red} \ No newline at end of file diff --git a/test/css/samples/global-with-child-combinator-3/expected.html b/test/css/samples/global-with-child-combinator-3/expected.html new file mode 100644 index 0000000000..32ff99e34f --- /dev/null +++ b/test/css/samples/global-with-child-combinator-3/expected.html @@ -0,0 +1,3 @@ +
+
+
\ No newline at end of file diff --git a/test/css/samples/global-with-child-combinator-3/input.svelte b/test/css/samples/global-with-child-combinator-3/input.svelte new file mode 100644 index 0000000000..146f302633 --- /dev/null +++ b/test/css/samples/global-with-child-combinator-3/input.svelte @@ -0,0 +1,9 @@ + + +
+
+
\ No newline at end of file diff --git a/test/css/samples/global-with-child-combinator/expected.html b/test/css/samples/global-with-child-combinator/expected.html new file mode 100644 index 0000000000..32ff99e34f --- /dev/null +++ b/test/css/samples/global-with-child-combinator/expected.html @@ -0,0 +1,3 @@ +
+
+
\ No newline at end of file