This commit is contained in:
hatuhn
2019-09-13 09:45:04 +07:00
parent f14a34ba19
commit 558fb07261
16790 changed files with 0 additions and 1642370 deletions

View File

@@ -1,32 +0,0 @@
var translate = require('../../../utils/translate.js');
function Index() {
this.seed = 0;
this.map = Object.create(null);
}
Index.prototype.resolve = function(str) {
var index = this.map[str];
if (!index) {
index = ++this.seed;
this.map[str] = index;
}
return index;
};
module.exports = function createDeclarationIndexer() {
var names = new Index();
var values = new Index();
return function markDeclaration(node) {
var property = node.property.name;
var value = translate(node.value);
node.id = names.resolve(property) + (values.resolve(value) << 12);
node.length = property.length + 1 + value.length;
return node;
};
};

View File

@@ -1,44 +0,0 @@
var resolveKeyword = require('../../../utils/names.js').keyword;
var walkRules = require('../../../utils/walk.js').rules;
var translate = require('../../../utils/translate.js');
var createDeclarationIndexer = require('./createDeclarationIndexer.js');
var processSelector = require('./processSelector.js');
function walk(node, markDeclaration, usageData) {
switch (node.type) {
case 'Ruleset':
node.block.declarations.each(markDeclaration);
processSelector(node, usageData);
break;
case 'Atrule':
if (node.expression) {
node.expression.id = translate(node.expression);
}
// compare keyframe selectors by its values
// NOTE: still no clarification about problems with keyframes selector grouping (issue #197)
if (resolveKeyword(node.name).name === 'keyframes') {
node.block.avoidRulesMerge = true; /* probably we don't need to prevent those merges for @keyframes
TODO: need to be checked */
node.block.rules.each(function(ruleset) {
ruleset.selector.selectors.each(function(simpleselector) {
simpleselector.compareMarker = simpleselector.id;
});
});
}
break;
}
};
module.exports = function prepare(ast, usageData) {
var markDeclaration = createDeclarationIndexer();
walkRules(ast, function(node) {
walk(node, markDeclaration, usageData);
});
return {
declaration: markDeclaration
};
};

View File

@@ -1,99 +0,0 @@
var translate = require('../../../utils/translate.js');
var specificity = require('./specificity.js');
var nonFreezePseudoElements = {
'first-letter': true,
'first-line': true,
'after': true,
'before': true
};
var nonFreezePseudoClasses = {
'link': true,
'visited': true,
'hover': true,
'active': true,
'first-letter': true,
'first-line': true,
'after': true,
'before': true
};
module.exports = function freeze(node, usageData) {
var pseudos = Object.create(null);
var hasPseudo = false;
node.selector.selectors.each(function(simpleSelector) {
var tagName = '*';
var scope = 0;
simpleSelector.sequence.some(function(node) {
switch (node.type) {
case 'Class':
if (usageData && usageData.scopes) {
var classScope = usageData.scopes[node.name] || 0;
if (scope !== 0 && classScope !== scope) {
throw new Error('Selector can\'t has classes from different scopes: ' + translate(simpleSelector));
}
scope = classScope;
}
break;
case 'PseudoClass':
if (!nonFreezePseudoClasses.hasOwnProperty(node.name)) {
pseudos[node.name] = true;
hasPseudo = true;
}
break;
case 'PseudoElement':
if (!nonFreezePseudoElements.hasOwnProperty(node.name)) {
pseudos[node.name] = true;
hasPseudo = true;
}
break;
case 'FunctionalPseudo':
pseudos[node.name] = true;
hasPseudo = true;
break;
case 'Negation':
pseudos.not = true;
hasPseudo = true;
break;
case 'Identifier':
tagName = node.name;
break;
case 'Attribute':
if (node.flags) {
pseudos['[' + node.flags + ']'] = true;
hasPseudo = true;
}
break;
case 'Combinator':
tagName = '*';
break;
}
});
simpleSelector.id = translate(simpleSelector);
simpleSelector.compareMarker = specificity(simpleSelector).toString();
if (scope) {
simpleSelector.compareMarker += ':' + scope;
}
if (tagName !== '*') {
simpleSelector.compareMarker += ',' + tagName;
}
});
if (hasPseudo) {
node.pseudoSignature = Object.keys(pseudos).sort().join(',');
}
};

View File

@@ -1,48 +0,0 @@
module.exports = function specificity(simpleSelector) {
var A = 0;
var B = 0;
var C = 0;
simpleSelector.sequence.each(function walk(data) {
switch (data.type) {
case 'SimpleSelector':
case 'Negation':
data.sequence.each(walk);
break;
case 'Id':
A++;
break;
case 'Class':
case 'Attribute':
case 'FunctionalPseudo':
B++;
break;
case 'Identifier':
if (data.name !== '*') {
C++;
}
break;
case 'PseudoElement':
C++;
break;
case 'PseudoClass':
var name = data.name.toLowerCase();
if (name === 'before' ||
name === 'after' ||
name === 'first-line' ||
name === 'first-letter') {
C++;
} else {
B++;
}
break;
}
});
return [A, B, C];
};