remove unused code

pull/698/head
Rich Harris 8 years ago
parent 03a9ce353a
commit fd177771af

@ -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;
}

@ -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);
}
}
});
}

@ -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);
}
}
}
}

@ -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';

Loading…
Cancel
Save