From f79e90142959c3a3e4645a47af82aa879fb81463 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 2 Jul 2017 09:22:36 -0400 Subject: [PATCH] bug fix --- src/generators/extractSelectors.ts | 6 ++++-- .../_config.js | 7 +++++++ .../expected.css | 4 ++++ .../expected.html | 1 + .../input.html | 9 +++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/css/samples/omit-scoping-attribute-descendant-global-inner-class/_config.js create mode 100644 test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.css create mode 100644 test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.html create mode 100644 test/css/samples/omit-scoping-attribute-descendant-global-inner-class/input.html diff --git a/src/generators/extractSelectors.ts b/src/generators/extractSelectors.ts index c715b7744f..024542ddcc 100644 --- a/src/generators/extractSelectors.ts +++ b/src/generators/extractSelectors.ts @@ -32,8 +32,10 @@ export default function extractSelectors(css: Node) :Node[] { const applies = selectorAppliesTo(parts, node, stack.slice()); if (applies) { + // add svelte-123xyz attribute to outermost and innermost + // elements — no need to add it to intermediate elements node._needsCssAttribute = true; - if (selector.children.find(isDescendantSelector)) stack[0]._needsCssAttribute = true; + if (stack[0] && selector.children.find(isDescendantSelector)) stack[0]._needsCssAttribute = true; } } }); @@ -43,7 +45,7 @@ export default function extractSelectors(css: Node) :Node[] { } function isDescendantSelector(selector: Node) { - return selector.type === 'WhiteSpace'; // TODO or '>' + return selector.type === 'WhiteSpace' || selector.type === 'Combinator'; } function selectorAppliesTo(parts: Node[], node: Node, stack: Node[]): boolean { diff --git a/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/_config.js b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/_config.js new file mode 100644 index 0000000000..0371e65c7e --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/_config.js @@ -0,0 +1,7 @@ +export default { + cascade: false, + + data: { + raw: '

raw

' + } +}; \ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.css b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.css new file mode 100644 index 0000000000..5b0fe980e6 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.css @@ -0,0 +1,4 @@ + + .foo[svelte-2122726581] .bar { + color: red; + } diff --git a/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.html b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.html new file mode 100644 index 0000000000..008c017374 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/expected.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/input.html b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/input.html new file mode 100644 index 0000000000..c2f6057255 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global-inner-class/input.html @@ -0,0 +1,9 @@ +
+ +
+ + \ No newline at end of file