From fd177771af2fe654529b6d3a5289551f220ff31f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 8 Jul 2017 00:20:19 -0400 Subject: [PATCH] remove unused code --- src/generators/Selector.ts | 29 ++++++++++++++++++++++++++- src/utils/css.ts | 41 -------------------------------------- src/validate/css/index.ts | 40 ------------------------------------- src/validate/index.ts | 1 - 4 files changed, 28 insertions(+), 83 deletions(-) delete mode 100644 src/utils/css.ts delete mode 100644 src/validate/css/index.ts diff --git a/src/generators/Selector.ts b/src/generators/Selector.ts index ee95236a39..bf01005114 100644 --- a/src/generators/Selector.ts +++ b/src/generators/Selector.ts @@ -1,5 +1,4 @@ import MagicString from 'magic-string'; -import { groupSelectors } from '../utils/css'; import { Validator } from '../validate/index'; import { Node } from '../interfaces'; @@ -207,4 +206,32 @@ function unquote(str: string) { if (str[0] === str[str.length - 1] && str[0] === "'" || str[0] === '"') { return str.slice(1, str.length - 1); } +} + +function groupSelectors(selector: Node) { + let block = { + global: selector.children[0].type === 'PseudoClassSelector' && selector.children[0].name === 'global', + selectors: [], + combinator: null + }; + + const blocks = [block]; + + selector.children.forEach((child: Node, i: number) => { + if (child.type === 'WhiteSpace' || child.type === 'Combinator') { + const next = selector.children[i + 1]; + + block = { + global: next.type === 'PseudoClassSelector' && next.name === 'global', + selectors: [], + combinator: child + }; + + blocks.push(block); + } else { + block.selectors.push(child); + } + }); + + return blocks; } \ No newline at end of file diff --git a/src/utils/css.ts b/src/utils/css.ts deleted file mode 100644 index b398956760..0000000000 --- a/src/utils/css.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Node } from '../interfaces'; - -export function groupSelectors(selector: Node) { - let block = { - global: selector.children[0].type === 'PseudoClassSelector' && selector.children[0].name === 'global', - selectors: [], - combinator: null - }; - - const blocks = [block]; - - selector.children.forEach((child: Node, i: number) => { - if (child.type === 'WhiteSpace' || child.type === 'Combinator') { - const next = selector.children[i + 1]; - - block = { - global: next.type === 'PseudoClassSelector' && next.name === 'global', - selectors: [], - combinator: child - }; - - blocks.push(block); - } else { - block.selectors.push(child); - } - }); - - return blocks; -} - -export function walkRules(nodes: Node[], callback: (node: Node) => void) { - nodes.forEach((node: Node) => { - if (node.type === 'Rule') { - callback(node); - } else if (node.type === 'Atrule') { - if (node.name === 'media' || node.name === 'supports' || node.name === 'document') { - walkRules(node.block.children, callback); - } - } - }); -} \ No newline at end of file diff --git a/src/validate/css/index.ts b/src/validate/css/index.ts deleted file mode 100644 index 658b3631bb..0000000000 --- a/src/validate/css/index.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { groupSelectors, walkRules } from '../../utils/css'; -import { Validator } from '../index'; -import { Node } from '../../interfaces'; - -export default function validateCss(validator: Validator, css: Node) { - walkRules(css.children, rule => { - rule.selector.children.forEach(validateSelector); - }); - - function validateSelector(selector: Node) { - const blocks = groupSelectors(selector); - - blocks.forEach((block) => { - let i = block.selectors.length; - while (i-- > 1) { - const part = block.selectors[i]; - if (part.type === 'PseudoClassSelector' && part.name === 'global') { - validator.error(`:global(...) must be the first element in a compound selector`, part.start); - } - } - }); - - let start = 0; - let end = blocks.length; - - for (; start < end; start += 1) { - if (!blocks[start].global) break; - } - - for (; end > start; end -= 1) { - if (!blocks[end - 1].global) break; - } - - for (let i = start; i < end; i += 1) { - if (blocks[i].global) { - validator.error(`:global(...) can be at the start or end of a selector sequence, but not in the middle`, blocks[i].selectors[0].start); - } - } - } -} \ No newline at end of file diff --git a/src/validate/index.ts b/src/validate/index.ts index 4e5fe1caa4..00d9d649f0 100644 --- a/src/validate/index.ts +++ b/src/validate/index.ts @@ -1,5 +1,4 @@ import validateJs from './js/index'; -import validateCss from './css/index'; import validateHtml from './html/index'; import { getLocator, Location } from 'locate-character'; import getCodeFrame from '../utils/getCodeFrame';