From d2e36df0502ad21336b68b76031fe9ad529d6316 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 3 Jul 2017 17:35:39 -0400 Subject: [PATCH] allow :global(...) selectors to have trailing modifiers --- src/utils/css.ts | 2 +- src/validate/css/index.ts | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/utils/css.ts b/src/utils/css.ts index ac78bdd96a..ec547bd784 100644 --- a/src/utils/css.ts +++ b/src/utils/css.ts @@ -1,7 +1,7 @@ import { Node } from '../interfaces'; export function isGlobalSelector(block: Node[]) { - return block.length === 1 && block[0].type === 'PseudoClassSelector' && block[0].name === 'global'; + return block[0].type === 'PseudoClassSelector' && block[0].name === 'global'; } export function groupSelectors(selector: Node) { diff --git a/src/validate/css/index.ts b/src/validate/css/index.ts index 6251f59fb0..8b90eff09c 100644 --- a/src/validate/css/index.ts +++ b/src/validate/css/index.ts @@ -10,17 +10,13 @@ export default function validateCss(validator: Validator, css: Node) { function validateSelector(selector: Node) { const blocks: Node[][] = groupSelectors(selector); - blocks.forEach((block, i) => { - if (block.find((part: Node) => part.type === 'PseudoClassSelector' && part.name === 'global')) { - // check that :global(...) is by itself - if (block.length !== 1) { - validator.error(`:global(...) cannot be mixed with non-global selectors`, block[0].start); + blocks.forEach((block) => { + let i = block.length; + while (i-- > 1) { + const part = block[i]; + if (part.type === 'PseudoClassSelector' && part.name === 'global') { + validator.error(`:global(...) must be the first element in a compound selector`, part.start); } - - // check that :global(...) isn't sandwiched by other selectors - // if (i > 0 && i < blocks.length - 1) { - // validator.error(`:global(...) can be at the start or end of a selector sequence, but not in the middle`, block[0].start); - // } } });