From be9b79f805a3f738986dd6a2fc9f39e07efe46bf Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 27 Jan 2020 18:25:24 -0500 Subject: [PATCH] fix detection of unused partially global CSS selectors (#4332) --- CHANGELOG.md | 1 + src/compiler/compile/css/Selector.ts | 2 +- .../global-with-unused-descendant/_config.js | 24 +++++++++++++++++++ .../expected.css | 0 .../input.svelte | 5 ++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/css/samples/global-with-unused-descendant/_config.js create mode 100644 test/css/samples/global-with-unused-descendant/expected.css create mode 100644 test/css/samples/global-with-unused-descendant/input.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 217651e20b..8c68dc1068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Fix code generation error with adjacent inline and block comments ([#4312](https://github.com/sveltejs/svelte/issues/4312)) +* Fix detection of unused CSS selectors that begin with a `:global()` but contain a scoped portion ([#4314](https://github.com/sveltejs/svelte/issues/4314)) ## 3.18.0 diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index 39bbc2e8d1..6bc046c93e 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -32,7 +32,7 @@ export default class Selector { } this.local_blocks = this.blocks.slice(0, i); - this.used = this.blocks[0].global; + this.used = this.local_blocks.length === 0; } apply(node: Element, stack: Element[]) { diff --git a/test/css/samples/global-with-unused-descendant/_config.js b/test/css/samples/global-with-unused-descendant/_config.js new file mode 100644 index 0000000000..3ed2dd2728 --- /dev/null +++ b/test/css/samples/global-with-unused-descendant/_config.js @@ -0,0 +1,24 @@ +export default { + warnings: [{ + code: 'css-unused-selector', + end: { + character: 27, + column: 19, + line: 2 + }, + frame: ` + 1: