format: prettify entire project
This commit is contained in:
130
node_modules/clean-css/lib/optimizer/level-2/reduce-non-adjacent.js
generated
vendored
130
node_modules/clean-css/lib/optimizer/level-2/reduce-non-adjacent.js
generated
vendored
@ -11,9 +11,12 @@ var serializeRules = require('../../writer/one-time').rules;
|
||||
|
||||
function reduceNonAdjacent(tokens, context) {
|
||||
var options = context.options;
|
||||
var mergeablePseudoClasses = options.compatibility.selectors.mergeablePseudoClasses;
|
||||
var mergeablePseudoElements = options.compatibility.selectors.mergeablePseudoElements;
|
||||
var multiplePseudoMerging = options.compatibility.selectors.multiplePseudoMerging;
|
||||
var mergeablePseudoClasses =
|
||||
options.compatibility.selectors.mergeablePseudoClasses;
|
||||
var mergeablePseudoElements =
|
||||
options.compatibility.selectors.mergeablePseudoElements;
|
||||
var multiplePseudoMerging =
|
||||
options.compatibility.selectors.multiplePseudoMerging;
|
||||
var candidates = {};
|
||||
var repeated = [];
|
||||
|
||||
@ -27,26 +30,31 @@ function reduceNonAdjacent(tokens, context) {
|
||||
}
|
||||
|
||||
var selectorAsString = serializeRules(token[1]);
|
||||
var isComplexAndNotSpecial = token[1].length > 1 &&
|
||||
isMergeable(selectorAsString, mergeablePseudoClasses, mergeablePseudoElements, multiplePseudoMerging);
|
||||
var isComplexAndNotSpecial =
|
||||
token[1].length > 1 &&
|
||||
isMergeable(
|
||||
selectorAsString,
|
||||
mergeablePseudoClasses,
|
||||
mergeablePseudoElements,
|
||||
multiplePseudoMerging
|
||||
);
|
||||
var wrappedSelectors = wrappedSelectorsFrom(token[1]);
|
||||
var selectors = isComplexAndNotSpecial ?
|
||||
[selectorAsString].concat(wrappedSelectors) :
|
||||
[selectorAsString];
|
||||
var selectors =
|
||||
isComplexAndNotSpecial ?
|
||||
[selectorAsString].concat(wrappedSelectors)
|
||||
: [selectorAsString];
|
||||
|
||||
for (var j = 0, m = selectors.length; j < m; j++) {
|
||||
var selector = selectors[j];
|
||||
|
||||
if (!candidates[selector])
|
||||
candidates[selector] = [];
|
||||
else
|
||||
repeated.push(selector);
|
||||
if (!candidates[selector]) candidates[selector] = [];
|
||||
else repeated.push(selector);
|
||||
|
||||
candidates[selector].push({
|
||||
where: i,
|
||||
list: wrappedSelectors,
|
||||
isPartial: isComplexAndNotSpecial && j > 0,
|
||||
isComplex: isComplexAndNotSpecial && j === 0
|
||||
isComplex: isComplexAndNotSpecial && j === 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -65,31 +73,45 @@ function wrappedSelectorsFrom(list) {
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
function reduceSimpleNonAdjacentCases(tokens, repeated, candidates, options, context) {
|
||||
function reduceSimpleNonAdjacentCases(
|
||||
tokens,
|
||||
repeated,
|
||||
candidates,
|
||||
options,
|
||||
context
|
||||
) {
|
||||
function filterOut(idx, bodies) {
|
||||
return data[idx].isPartial && bodies.length === 0;
|
||||
}
|
||||
|
||||
function reduceBody(token, newBody, processedCount, tokenIdx) {
|
||||
if (!data[processedCount - tokenIdx - 1].isPartial)
|
||||
token[2] = newBody;
|
||||
if (!data[processedCount - tokenIdx - 1].isPartial) token[2] = newBody;
|
||||
}
|
||||
|
||||
for (var i = 0, l = repeated.length; i < l; i++) {
|
||||
var selector = repeated[i];
|
||||
var data = candidates[selector];
|
||||
|
||||
reduceSelector(tokens, data, {
|
||||
filterOut: filterOut,
|
||||
callback: reduceBody
|
||||
}, options, context);
|
||||
reduceSelector(
|
||||
tokens,
|
||||
data,
|
||||
{
|
||||
filterOut: filterOut,
|
||||
callback: reduceBody,
|
||||
},
|
||||
options,
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function reduceComplexNonAdjacentCases(tokens, candidates, options, context) {
|
||||
var mergeablePseudoClasses = options.compatibility.selectors.mergeablePseudoClasses;
|
||||
var mergeablePseudoElements = options.compatibility.selectors.mergeablePseudoElements;
|
||||
var multiplePseudoMerging = options.compatibility.selectors.multiplePseudoMerging;
|
||||
var mergeablePseudoClasses =
|
||||
options.compatibility.selectors.mergeablePseudoClasses;
|
||||
var mergeablePseudoElements =
|
||||
options.compatibility.selectors.mergeablePseudoElements;
|
||||
var multiplePseudoMerging =
|
||||
options.compatibility.selectors.multiplePseudoMerging;
|
||||
var localContext = {};
|
||||
|
||||
function filterOut(idx) {
|
||||
@ -97,23 +119,28 @@ function reduceComplexNonAdjacentCases(tokens, candidates, options, context) {
|
||||
}
|
||||
|
||||
function collectReducedBodies(token, newBody, processedCount, tokenIdx) {
|
||||
if (tokenIdx === 0)
|
||||
localContext.reducedBodies.push(newBody);
|
||||
if (tokenIdx === 0) localContext.reducedBodies.push(newBody);
|
||||
}
|
||||
|
||||
allSelectors:
|
||||
for (var complexSelector in candidates) {
|
||||
allSelectors: for (var complexSelector in candidates) {
|
||||
var into = candidates[complexSelector];
|
||||
if (!into[0].isComplex)
|
||||
continue;
|
||||
if (!into[0].isComplex) continue;
|
||||
|
||||
var intoPosition = into[into.length - 1].where;
|
||||
var intoToken = tokens[intoPosition];
|
||||
var reducedBodies = [];
|
||||
|
||||
var selectors = isMergeable(complexSelector, mergeablePseudoClasses, mergeablePseudoElements, multiplePseudoMerging) ?
|
||||
into[0].list :
|
||||
[complexSelector];
|
||||
var selectors =
|
||||
(
|
||||
isMergeable(
|
||||
complexSelector,
|
||||
mergeablePseudoClasses,
|
||||
mergeablePseudoElements,
|
||||
multiplePseudoMerging
|
||||
)
|
||||
) ?
|
||||
into[0].list
|
||||
: [complexSelector];
|
||||
|
||||
localContext.intoPosition = intoPosition;
|
||||
localContext.reducedBodies = reducedBodies;
|
||||
@ -122,17 +149,25 @@ function reduceComplexNonAdjacentCases(tokens, candidates, options, context) {
|
||||
var selector = selectors[j];
|
||||
var data = candidates[selector];
|
||||
|
||||
if (data.length < 2)
|
||||
continue allSelectors;
|
||||
if (data.length < 2) continue allSelectors;
|
||||
|
||||
localContext.data = data;
|
||||
|
||||
reduceSelector(tokens, data, {
|
||||
filterOut: filterOut,
|
||||
callback: collectReducedBodies
|
||||
}, options, context);
|
||||
reduceSelector(
|
||||
tokens,
|
||||
data,
|
||||
{
|
||||
filterOut: filterOut,
|
||||
callback: collectReducedBodies,
|
||||
},
|
||||
options,
|
||||
context
|
||||
);
|
||||
|
||||
if (serializeBody(reducedBodies[reducedBodies.length - 1]) != serializeBody(reducedBodies[0]))
|
||||
if (
|
||||
serializeBody(reducedBodies[reducedBodies.length - 1]) !=
|
||||
serializeBody(reducedBodies[0])
|
||||
)
|
||||
continue allSelectors;
|
||||
}
|
||||
|
||||
@ -146,8 +181,7 @@ function reduceSelector(tokens, data, context, options, outerContext) {
|
||||
var processedTokens = [];
|
||||
|
||||
for (var j = data.length - 1; j >= 0; j--) {
|
||||
if (context.filterOut(j, bodies))
|
||||
continue;
|
||||
if (context.filterOut(j, bodies)) continue;
|
||||
|
||||
var where = data[j].where;
|
||||
var token = tokens[where];
|
||||
@ -165,13 +199,23 @@ function reduceSelector(tokens, data, context, options, outerContext) {
|
||||
var tokenIdx = processedCount - 1;
|
||||
|
||||
while (tokenIdx >= 0) {
|
||||
if ((tokenIdx === 0 || (bodies[propertyIdx] && bodiesAsList[tokenIdx].indexOf(bodies[propertyIdx]) > -1)) && propertyIdx > -1) {
|
||||
if (
|
||||
(tokenIdx === 0 ||
|
||||
(bodies[propertyIdx] &&
|
||||
bodiesAsList[tokenIdx].indexOf(bodies[propertyIdx]) > -1)) &&
|
||||
propertyIdx > -1
|
||||
) {
|
||||
propertyIdx--;
|
||||
continue;
|
||||
}
|
||||
|
||||
var newBody = bodies.splice(propertyIdx + 1);
|
||||
context.callback(tokens[processedTokens[tokenIdx]], newBody, processedCount, tokenIdx);
|
||||
context.callback(
|
||||
tokens[processedTokens[tokenIdx]],
|
||||
newBody,
|
||||
processedCount,
|
||||
tokenIdx
|
||||
);
|
||||
|
||||
tokenIdx--;
|
||||
}
|
||||
|
Reference in New Issue
Block a user