diff --git a/src/generators/extractSelectors.ts b/src/generators/extractSelectors.ts index b0a1aee417..df539a45b2 100644 --- a/src/generators/extractSelectors.ts +++ b/src/generators/extractSelectors.ts @@ -25,10 +25,25 @@ export default function extractSelectors(css: Node) :Node[] { } function processSelector(selector: Node) { + // take trailing :global(...) selectors out of consideration + let i = selector.children.length; + while (i > 2) { + const last = selector.children[i-1]; + const penultimate = selector.children[i-2]; + + if (last.type === 'PseudoClassSelector' && last.name === 'global') { + i -= 2; + } else { + break; + } + } + + const parts = selector.children.slice(0, i); + selectors.push({ used: false, // TODO use this! warn on unused selectors apply: (node: Node, stack: Node[]) => { - const applies = selectorAppliesTo(selector.children, node, stack.slice()); + const applies = selectorAppliesTo(parts, node, stack.slice()); if (applies) { node._needsCssAttribute = true; @@ -52,15 +67,20 @@ function selectorAppliesTo(parts: Node[], node: Node, stack: Node[]) { let j = stack.length; while (i--) { + if (!node) { + return parts.every((part: Node) => { + return part.type === 'Combinator' || (part.type === 'PseudoClassSelector' && part.name === 'global'); + }); + } + const part = parts[i]; if (part.type === 'PseudoClassSelector' && part.name === 'global') { - // bail - return true; + // TODO shouldn't see this here... maybe we should enforce that :global(...) + // cannot be sandwiched between non-global selectors? + return false; } - if (!node) return false; - if (part.type === 'PseudoClassSelector' || part.type === 'PseudoElementSelector') { continue; } diff --git a/test/css/samples/omit-scoping-attribute-descendant-global/_config.js b/test/css/samples/omit-scoping-attribute-descendant-global/_config.js new file mode 100644 index 0000000000..0371e65c7e --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global/_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/expected.css b/test/css/samples/omit-scoping-attribute-descendant-global/expected.css new file mode 100644 index 0000000000..be34059793 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global/expected.css @@ -0,0 +1,4 @@ + + div { + color: red; + } diff --git a/test/css/samples/omit-scoping-attribute-descendant-global/expected.html b/test/css/samples/omit-scoping-attribute-descendant-global/expected.html new file mode 100644 index 0000000000..281c6866c3 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global/expected.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/css/samples/omit-scoping-attribute-descendant-global/input.html b/test/css/samples/omit-scoping-attribute-descendant-global/input.html new file mode 100644 index 0000000000..a85bfa0bb3 --- /dev/null +++ b/test/css/samples/omit-scoping-attribute-descendant-global/input.html @@ -0,0 +1,7 @@ +
+ + \ No newline at end of file