format: prettify entire project
This commit is contained in:
245
node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js
generated
vendored
245
node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js
generated
vendored
@ -22,12 +22,15 @@ function wouldBreakCompatibility(property, validator) {
|
||||
for (var i = 0; i < property.components.length; i++) {
|
||||
var component = property.components[i];
|
||||
var descriptor = compactable[component.name];
|
||||
var canOverride = descriptor && descriptor.canOverride || canOverride.sameValue;
|
||||
var canOverride =
|
||||
(descriptor && descriptor.canOverride) || canOverride.sameValue;
|
||||
|
||||
var _component = shallowClone(component);
|
||||
_component.value = [[Token.PROPERTY_VALUE, descriptor.defaultValue]];
|
||||
|
||||
if (!everyValuesPair(canOverride.bind(null, validator), _component, component)) {
|
||||
if (
|
||||
!everyValuesPair(canOverride.bind(null, validator), _component, component)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -54,12 +57,9 @@ function overrideSimple(property, by) {
|
||||
}
|
||||
|
||||
function override(property, by) {
|
||||
if (by.multiplex)
|
||||
overrideByMultiplex(property, by);
|
||||
else if (property.multiplex)
|
||||
overrideIntoMultiplex(property, by);
|
||||
else
|
||||
overrideSimple(property, by);
|
||||
if (by.multiplex) overrideByMultiplex(property, by);
|
||||
else if (property.multiplex) overrideIntoMultiplex(property, by);
|
||||
else overrideSimple(property, by);
|
||||
}
|
||||
|
||||
function overrideShorthand(property, by) {
|
||||
@ -96,9 +96,11 @@ function turnShorthandValueIntoMultiplex(property, size) {
|
||||
function turnLonghandValueIntoMultiplex(property, size) {
|
||||
var descriptor = compactable[property.name];
|
||||
var withRealValue = descriptor.intoMultiplexMode == 'real';
|
||||
var withValue = descriptor.intoMultiplexMode == 'real' ?
|
||||
property.value.slice(0) :
|
||||
(descriptor.intoMultiplexMode == 'placeholder' ? descriptor.placeholderValue : descriptor.defaultValue);
|
||||
var withValue =
|
||||
descriptor.intoMultiplexMode == 'real' ? property.value.slice(0)
|
||||
: descriptor.intoMultiplexMode == 'placeholder' ?
|
||||
descriptor.placeholderValue
|
||||
: descriptor.defaultValue;
|
||||
var i = multiplexSize(property);
|
||||
var j;
|
||||
var m = withValue.length;
|
||||
@ -108,10 +110,14 @@ function turnLonghandValueIntoMultiplex(property, size) {
|
||||
|
||||
if (Array.isArray(withValue)) {
|
||||
for (j = 0; j < m; j++) {
|
||||
property.value.push(withRealValue ? withValue[j] : [Token.PROPERTY_VALUE, withValue[j]]);
|
||||
property.value.push(
|
||||
withRealValue ? withValue[j] : [Token.PROPERTY_VALUE, withValue[j]]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
property.value.push(withRealValue ? withValue : [Token.PROPERTY_VALUE, withValue]);
|
||||
property.value.push(
|
||||
withRealValue ? withValue : [Token.PROPERTY_VALUE, withValue]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,8 +126,7 @@ function multiplexSize(component) {
|
||||
var size = 0;
|
||||
|
||||
for (var i = 0, l = component.value.length; i < l; i++) {
|
||||
if (component.value[i][1] == Marker.COMMA)
|
||||
size++;
|
||||
if (component.value[i][1] == Marker.COMMA) size++;
|
||||
}
|
||||
|
||||
return size + 1;
|
||||
@ -130,7 +135,7 @@ function multiplexSize(component) {
|
||||
function lengthOf(property) {
|
||||
var fakeAsArray = [
|
||||
Token.PROPERTY,
|
||||
[Token.PROPERTY_NAME, property.name]
|
||||
[Token.PROPERTY_NAME, property.name],
|
||||
].concat(property.value);
|
||||
return serializeProperty([fakeAsArray], 0).length;
|
||||
}
|
||||
@ -142,10 +147,8 @@ function moreSameShorthands(properties, startAt, name) {
|
||||
var count = 0;
|
||||
|
||||
for (var i = startAt; i >= 0; i--) {
|
||||
if (properties[i].name == name && !properties[i].unused)
|
||||
count++;
|
||||
if (count > 1)
|
||||
break;
|
||||
if (properties[i].name == name && !properties[i].unused) count++;
|
||||
if (count > 1) break;
|
||||
}
|
||||
|
||||
return count > 1;
|
||||
@ -153,7 +156,10 @@ function moreSameShorthands(properties, startAt, name) {
|
||||
|
||||
function overridingFunction(shorthand, validator) {
|
||||
for (var i = 0, l = shorthand.components.length; i < l; i++) {
|
||||
if (!anyValue(validator.isUrl, shorthand.components[i]) && anyValue(validator.isFunction, shorthand.components[i])) {
|
||||
if (
|
||||
!anyValue(validator.isUrl, shorthand.components[i]) &&
|
||||
anyValue(validator.isFunction, shorthand.components[i])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -163,18 +169,19 @@ function overridingFunction(shorthand, validator) {
|
||||
|
||||
function anyValue(fn, property) {
|
||||
for (var i = 0, l = property.value.length; i < l; i++) {
|
||||
if (property.value[i][1] == Marker.COMMA)
|
||||
continue;
|
||||
if (property.value[i][1] == Marker.COMMA) continue;
|
||||
|
||||
if (fn(property.value[i][1]))
|
||||
return true;
|
||||
if (fn(property.value[i][1])) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function wouldResultInLongerValue(left, right) {
|
||||
if (!left.multiplex && !right.multiplex || left.multiplex && right.multiplex)
|
||||
if (
|
||||
(!left.multiplex && !right.multiplex) ||
|
||||
(left.multiplex && right.multiplex)
|
||||
)
|
||||
return false;
|
||||
|
||||
var multiplex = left.multiplex ? left : right;
|
||||
@ -210,19 +217,20 @@ function isCompactable(property) {
|
||||
}
|
||||
|
||||
function noneOverrideHack(left, right) {
|
||||
return !left.multiplex &&
|
||||
return (
|
||||
!left.multiplex &&
|
||||
(left.name == 'background' || left.name == 'background-image') &&
|
||||
right.multiplex &&
|
||||
(right.name == 'background' || right.name == 'background-image') &&
|
||||
anyLayerIsNone(right.value);
|
||||
anyLayerIsNone(right.value)
|
||||
);
|
||||
}
|
||||
|
||||
function anyLayerIsNone(values) {
|
||||
var layers = intoLayers(values);
|
||||
|
||||
for (var i = 0, l = layers.length; i < l; i++) {
|
||||
if (layers[i].length == 1 && layers[i][0][1] == 'none')
|
||||
return true;
|
||||
if (layers[i].length == 1 && layers[i][0][1] == 'none') return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -253,55 +261,54 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
var overridable;
|
||||
var i, j, k;
|
||||
|
||||
propertyLoop:
|
||||
for (i = properties.length - 1; i >= 0; i--) {
|
||||
propertyLoop: for (i = properties.length - 1; i >= 0; i--) {
|
||||
right = properties[i];
|
||||
|
||||
if (!isCompactable(right))
|
||||
continue;
|
||||
if (!isCompactable(right)) continue;
|
||||
|
||||
if (right.block)
|
||||
continue;
|
||||
if (right.block) continue;
|
||||
|
||||
mayOverride = compactable[right.name].canOverride;
|
||||
|
||||
traverseLoop:
|
||||
for (j = i - 1; j >= 0; j--) {
|
||||
traverseLoop: for (j = i - 1; j >= 0; j--) {
|
||||
left = properties[j];
|
||||
|
||||
if (!isCompactable(left))
|
||||
continue;
|
||||
if (!isCompactable(left)) continue;
|
||||
|
||||
if (left.block)
|
||||
continue;
|
||||
if (left.block) continue;
|
||||
|
||||
if (left.unused || right.unused)
|
||||
continue;
|
||||
if (left.unused || right.unused) continue;
|
||||
|
||||
if (left.hack && !right.hack && !right.important || !left.hack && !left.important && right.hack)
|
||||
if (
|
||||
(left.hack && !right.hack && !right.important) ||
|
||||
(!left.hack && !left.important && right.hack)
|
||||
)
|
||||
continue;
|
||||
|
||||
if (left.important == right.important && left.hack[0] != right.hack[0])
|
||||
continue;
|
||||
|
||||
if (left.important == right.important && (left.hack[0] != right.hack[0] || (left.hack[1] && left.hack[1] != right.hack[1])))
|
||||
if (
|
||||
left.important == right.important &&
|
||||
(left.hack[0] != right.hack[0] ||
|
||||
(left.hack[1] && left.hack[1] != right.hack[1]))
|
||||
)
|
||||
continue;
|
||||
|
||||
if (hasInherit(right))
|
||||
continue;
|
||||
if (hasInherit(right)) continue;
|
||||
|
||||
if (noneOverrideHack(left, right))
|
||||
continue;
|
||||
if (noneOverrideHack(left, right)) continue;
|
||||
|
||||
if (right.shorthand && isComponentOf(right, left)) {
|
||||
// maybe `left` can be overridden by `right` which is a shorthand?
|
||||
if (!right.important && left.important)
|
||||
continue;
|
||||
if (!right.important && left.important) continue;
|
||||
|
||||
if (!sameVendorPrefixesIn([left], right.components))
|
||||
continue;
|
||||
if (!sameVendorPrefixesIn([left], right.components)) continue;
|
||||
|
||||
if (!anyValue(validator.isFunction, left) && overridingFunction(right, validator))
|
||||
if (
|
||||
!anyValue(validator.isFunction, left) &&
|
||||
overridingFunction(right, validator)
|
||||
)
|
||||
continue;
|
||||
|
||||
if (!isMergeableShorthand(right)) {
|
||||
@ -311,10 +318,15 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
|
||||
component = findComponentIn(right, left);
|
||||
mayOverride = compactable[left.name].canOverride;
|
||||
if (everyValuesPair(mayOverride.bind(null, validator), left, component)) {
|
||||
if (
|
||||
everyValuesPair(mayOverride.bind(null, validator), left, component)
|
||||
) {
|
||||
left.unused = true;
|
||||
}
|
||||
} else if (right.shorthand && overridesNonComponentShorthand(right, left)) {
|
||||
} else if (
|
||||
right.shorthand &&
|
||||
overridesNonComponentShorthand(right, left)
|
||||
) {
|
||||
// `right` is a shorthand while `left` can be overriden by it, think `border` and `border-top`
|
||||
if (!right.important && left.important) {
|
||||
continue;
|
||||
@ -324,29 +336,40 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!anyValue(validator.isFunction, left) && overridingFunction(right, validator)) {
|
||||
if (
|
||||
!anyValue(validator.isFunction, left) &&
|
||||
overridingFunction(right, validator)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
overriddenComponents = left.shorthand ?
|
||||
left.components:
|
||||
[left];
|
||||
overriddenComponents = left.shorthand ? left.components : [left];
|
||||
|
||||
for (k = overriddenComponents.length - 1; k >= 0; k--) {
|
||||
overriddenComponent = overriddenComponents[k];
|
||||
overridingComponent = findComponentIn(right, overriddenComponent);
|
||||
mayOverride = compactable[overriddenComponent.name].canOverride;
|
||||
|
||||
if (!everyValuesPair(mayOverride.bind(null, validator), left, overridingComponent)) {
|
||||
if (
|
||||
!everyValuesPair(
|
||||
mayOverride.bind(null, validator),
|
||||
left,
|
||||
overridingComponent
|
||||
)
|
||||
) {
|
||||
continue traverseLoop;
|
||||
}
|
||||
}
|
||||
|
||||
left.unused = true;
|
||||
} else if (withMerging && left.shorthand && !right.shorthand && isComponentOf(left, right, true)) {
|
||||
} else if (
|
||||
withMerging &&
|
||||
left.shorthand &&
|
||||
!right.shorthand &&
|
||||
isComponentOf(left, right, true)
|
||||
) {
|
||||
// maybe `right` can be pulled into `left` which is a shorthand?
|
||||
if (right.important && !left.important)
|
||||
continue;
|
||||
if (right.important && !left.important) continue;
|
||||
|
||||
if (!right.important && left.important) {
|
||||
right.unused = true;
|
||||
@ -354,34 +377,41 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
}
|
||||
|
||||
// Pending more clever algorithm in #527
|
||||
if (moreSameShorthands(properties, i - 1, left.name))
|
||||
continue;
|
||||
if (moreSameShorthands(properties, i - 1, left.name)) continue;
|
||||
|
||||
if (overridingFunction(left, validator))
|
||||
continue;
|
||||
if (overridingFunction(left, validator)) continue;
|
||||
|
||||
if (!isMergeableShorthand(left))
|
||||
continue;
|
||||
if (!isMergeableShorthand(left)) continue;
|
||||
|
||||
component = findComponentIn(left, right);
|
||||
if (everyValuesPair(mayOverride.bind(null, validator), component, right)) {
|
||||
if (
|
||||
everyValuesPair(mayOverride.bind(null, validator), component, right)
|
||||
) {
|
||||
var disabledBackgroundMerging =
|
||||
!compatibility.properties.backgroundClipMerging && component.name.indexOf('background-clip') > -1 ||
|
||||
!compatibility.properties.backgroundOriginMerging && component.name.indexOf('background-origin') > -1 ||
|
||||
!compatibility.properties.backgroundSizeMerging && component.name.indexOf('background-size') > -1;
|
||||
var nonMergeableValue = compactable[right.name].nonMergeableValue === right.value[0][1];
|
||||
(!compatibility.properties.backgroundClipMerging &&
|
||||
component.name.indexOf('background-clip') > -1) ||
|
||||
(!compatibility.properties.backgroundOriginMerging &&
|
||||
component.name.indexOf('background-origin') > -1) ||
|
||||
(!compatibility.properties.backgroundSizeMerging &&
|
||||
component.name.indexOf('background-size') > -1);
|
||||
var nonMergeableValue =
|
||||
compactable[right.name].nonMergeableValue === right.value[0][1];
|
||||
|
||||
if (disabledBackgroundMerging || nonMergeableValue)
|
||||
if (disabledBackgroundMerging || nonMergeableValue) continue;
|
||||
|
||||
if (
|
||||
!compatibility.properties.merging &&
|
||||
wouldBreakCompatibility(left, validator)
|
||||
)
|
||||
continue;
|
||||
|
||||
if (!compatibility.properties.merging && wouldBreakCompatibility(left, validator))
|
||||
if (
|
||||
component.value[0][1] != right.value[0][1] &&
|
||||
(hasInherit(left) || hasInherit(right))
|
||||
)
|
||||
continue;
|
||||
|
||||
if (component.value[0][1] != right.value[0][1] && (hasInherit(left) || hasInherit(right)))
|
||||
continue;
|
||||
|
||||
if (wouldResultInLongerValue(left, right))
|
||||
continue;
|
||||
if (wouldResultInLongerValue(left, right)) continue;
|
||||
|
||||
if (!left.multiplex && right.multiplex)
|
||||
turnIntoMultiplex(left, multiplexSize(right));
|
||||
@ -389,11 +419,15 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
override(component, right);
|
||||
left.dirty = true;
|
||||
}
|
||||
} else if (withMerging && left.shorthand && right.shorthand && left.name == right.name) {
|
||||
} else if (
|
||||
withMerging &&
|
||||
left.shorthand &&
|
||||
right.shorthand &&
|
||||
left.name == right.name
|
||||
) {
|
||||
// merge if all components can be merged
|
||||
|
||||
if (!left.multiplex && right.multiplex)
|
||||
continue;
|
||||
if (!left.multiplex && right.multiplex) continue;
|
||||
|
||||
if (!right.important && left.important) {
|
||||
right.unused = true;
|
||||
@ -415,21 +449,33 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
var rightComponent = right.components[k];
|
||||
|
||||
mayOverride = compactable[leftComponent.name].canOverride;
|
||||
if (!everyValuesPair(mayOverride.bind(null, validator), leftComponent, rightComponent))
|
||||
if (
|
||||
!everyValuesPair(
|
||||
mayOverride.bind(null, validator),
|
||||
leftComponent,
|
||||
rightComponent
|
||||
)
|
||||
)
|
||||
continue propertyLoop;
|
||||
}
|
||||
|
||||
overrideShorthand(left, right);
|
||||
left.dirty = true;
|
||||
} else if (withMerging && left.shorthand && right.shorthand && isComponentOf(left, right)) {
|
||||
} else if (
|
||||
withMerging &&
|
||||
left.shorthand &&
|
||||
right.shorthand &&
|
||||
isComponentOf(left, right)
|
||||
) {
|
||||
// border is a shorthand but any of its components is a shorthand too
|
||||
|
||||
if (!left.important && right.important)
|
||||
continue;
|
||||
if (!left.important && right.important) continue;
|
||||
|
||||
component = findComponentIn(left, right);
|
||||
mayOverride = compactable[right.name].canOverride;
|
||||
if (!everyValuesPair(mayOverride.bind(null, validator), component, right))
|
||||
if (
|
||||
!everyValuesPair(mayOverride.bind(null, validator), component, right)
|
||||
)
|
||||
continue;
|
||||
|
||||
if (left.important && !right.important) {
|
||||
@ -438,8 +484,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
}
|
||||
|
||||
var rightRestored = compactable[right.name].restore(right, compactable);
|
||||
if (rightRestored.length > 1)
|
||||
continue;
|
||||
if (rightRestored.length > 1) continue;
|
||||
|
||||
component = findComponentIn(left, right);
|
||||
override(component, right);
|
||||
@ -454,11 +499,21 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
|
||||
overridingComponent = right.components[k];
|
||||
mayOverride = compactable[overridingComponent.name].canOverride;
|
||||
|
||||
overridable = overridable && everyValuesPair(mayOverride.bind(null, validator), overriddenComponent, overridingComponent);
|
||||
overridable =
|
||||
overridable &&
|
||||
everyValuesPair(
|
||||
mayOverride.bind(null, validator),
|
||||
overriddenComponent,
|
||||
overridingComponent
|
||||
);
|
||||
}
|
||||
} else {
|
||||
mayOverride = compactable[right.name].canOverride;
|
||||
overridable = everyValuesPair(mayOverride.bind(null, validator), left, right);
|
||||
overridable = everyValuesPair(
|
||||
mayOverride.bind(null, validator),
|
||||
left,
|
||||
right
|
||||
);
|
||||
}
|
||||
|
||||
if (left.important && !right.important && overridable) {
|
||||
|
Reference in New Issue
Block a user