From 0fd34b1f41d1f45ae4ab592c471efddfd985e680 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 30 Jun 2019 17:39:57 -0400 Subject: [PATCH] add scoping attribute for pseudo-class selectors without a type/class - fixes #1705 --- src/compiler/compile/css/Selector.ts | 5 ++++- test/css/samples/not-selector/expected.css | 1 + test/css/samples/not-selector/input.svelte | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/css/samples/not-selector/expected.css create mode 100644 test/css/samples/not-selector/input.svelte diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index bb4a29ebe3..005e5320fd 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -61,7 +61,10 @@ export default class Selector { let i = block.selectors.length; while (i--) { const selector = block.selectors[i]; - if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector') continue; + if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector') { + if (i === 0) code.prependRight(selector.start, attr); + continue; + } if (selector.type === 'TypeSelector' && selector.name === '*') { code.overwrite(selector.start, selector.end, attr); diff --git a/test/css/samples/not-selector/expected.css b/test/css/samples/not-selector/expected.css new file mode 100644 index 0000000000..83a819a9e0 --- /dev/null +++ b/test/css/samples/not-selector/expected.css @@ -0,0 +1 @@ +.svelte-xyz:not(.foo){color:red} \ No newline at end of file diff --git a/test/css/samples/not-selector/input.svelte b/test/css/samples/not-selector/input.svelte new file mode 100644 index 0000000000..31a880f2bb --- /dev/null +++ b/test/css/samples/not-selector/input.svelte @@ -0,0 +1,8 @@ +

foo

+

bar

+ + \ No newline at end of file