1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-04 12:40:05 +02:00

update node modules

This commit is contained in:
s2
2021-05-07 15:56:33 +02:00
parent d81e8e9fb8
commit 3ec373077c
550 changed files with 84712 additions and 15991 deletions

View File

@@ -1,4 +1,4 @@
var compactable = require('../compactable');
var configuration = require('../../configuration');
function findComponentIn(shorthand, longhand) {
var comparator = nameComparator(longhand);
@@ -21,7 +21,7 @@ function findInSubComponents(shorthand, comparator) {
var longhandMatch;
var i, l;
if (!compactable[shorthand.name].shorthandComponents) {
if (!configuration[shorthand.name].shorthandComponents) {
return;
}

View File

@@ -0,0 +1,14 @@
function hasSameValues(property) {
var firstValue = property.value[0][1];
var i, l;
for (i = 1, l = property.value.length; i < l; i++) {
if (property.value[i][1] != firstValue) {
return false;
}
}
return true;
}
module.exports = hasSameValues;

View File

@@ -0,0 +1,10 @@
function hasUnset(property) {
for (var i = property.value.length - 1; i >= 0; i--) {
if (property.value[i][1] == 'unset')
return true;
}
return false;
}
module.exports = hasUnset;

View File

@@ -1,12 +1,12 @@
var compactable = require('../compactable');
var configuration = require('../../configuration');
function isComponentOf(property1, property2, shallow) {
return isDirectComponentOf(property1, property2) ||
!shallow && !!compactable[property1.name].shorthandComponents && isSubComponentOf(property1, property2);
!shallow && !!configuration[property1.name].shorthandComponents && isSubComponentOf(property1, property2);
}
function isDirectComponentOf(property1, property2) {
var descriptor = compactable[property1.name];
var descriptor = configuration[property1.name];
return 'components' in descriptor && descriptor.components.indexOf(property2.name) > -1;
}

View File

@@ -1,9 +1,10 @@
var everyValuesPair = require('./every-values-pair');
var hasInherit = require('./has-inherit');
var hasSameValues = require('./has-same-values');
var populateComponents = require('./populate-components');
var compactable = require('../compactable');
var deepClone = require('../clone').deep;
var configuration = require('../../configuration');
var deepClone = require('../../clone').deep;
var restoreWithComponents = require('../restore-with-components');
var restoreFromOptimizing = require('../../restore-from-optimizing');
@@ -27,7 +28,11 @@ function mergeIntoShorthands(properties, validator) {
for (i = 0, l = properties.length; i < l; i++) {
property = properties[i];
descriptor = compactable[property.name];
descriptor = configuration[property.name];
if (property.dynamic) {
continue;
}
if (property.unused) {
continue;
@@ -41,6 +46,10 @@ function mergeIntoShorthands(properties, validator) {
continue;
}
if (descriptor && descriptor.singleTypeComponents && !hasSameValues(property)) {
continue;
}
invalidateOrCompact(properties, i, candidates, validator);
if (descriptor && descriptor.componentOf) {
@@ -61,13 +70,15 @@ function invalidateOrCompact(properties, position, candidates, validator) {
var shorthandName;
var shorthandDescriptor;
var candidateComponents;
var replacedCandidates = [];
var i;
for (shorthandName in candidates) {
if (undefined !== invalidatedBy && shorthandName == invalidatedBy.name) {
continue;
}
shorthandDescriptor = compactable[shorthandName];
shorthandDescriptor = configuration[shorthandName];
candidateComponents = candidates[shorthandName];
if (invalidatedBy && invalidates(candidates, shorthandName, invalidatedBy)) {
delete candidates[shorthandName];
@@ -95,12 +106,18 @@ function invalidateOrCompact(properties, position, candidates, validator) {
} else {
replaceWithShorthand(properties, candidateComponents, shorthandName, validator);
}
replacedCandidates.push(shorthandName);
}
for (i = replacedCandidates.length - 1; i >= 0; i--) {
delete candidates[replacedCandidates[i]];
}
}
function invalidates(candidates, shorthandName, invalidatedBy) {
var shorthandDescriptor = compactable[shorthandName];
var invalidatedByDescriptor = compactable[invalidatedBy.name];
var shorthandDescriptor = configuration[shorthandName];
var invalidatedByDescriptor = configuration[invalidatedBy.name];
var componentName;
if ('overridesShorthands' in shorthandDescriptor && shorthandDescriptor.overridesShorthands.indexOf(invalidatedBy.name) > -1) {
@@ -134,7 +151,7 @@ function mixedImportance(components) {
}
function overridable(components, shorthandName, validator) {
var descriptor = compactable[shorthandName];
var descriptor = configuration[shorthandName];
var newValuePlaceholder = [
Token.PROPERTY,
[Token.PROPERTY_NAME, shorthandName],
@@ -149,7 +166,7 @@ function overridable(components, shorthandName, validator) {
for (i = 0, l = descriptor.components.length; i < l; i++) {
component = components[descriptor.components[i]];
mayOverride = compactable[component.name].canOverride;
mayOverride = configuration[component.name].canOverride || sameValue;
if (!everyValuesPair(mayOverride.bind(null, validator), newProperty.components[i], component)) {
return false;
@@ -159,6 +176,10 @@ function overridable(components, shorthandName, validator) {
return true;
}
function sameValue(_validator, value1, value2) {
return value1 === value2;
}
function mergeable(components) {
var lastCount = null;
var currentCount;
@@ -169,14 +190,14 @@ function mergeable(components) {
for (componentName in components) {
component = components[componentName];
descriptor = compactable[componentName];
descriptor = configuration[componentName];
if (!('restore' in descriptor)) {
continue;
}
restoreFromOptimizing([component.all[component.position]], restoreWithComponents);
values = descriptor.restore(component, compactable);
values = descriptor.restore(component, configuration);
currentCount = values.length;
@@ -217,24 +238,30 @@ function replaceWithInheritBestFit(properties, candidateComponents, shorthandNam
var newTokensSequence = isLonghandsShorter ? longhandTokensSequence : shorthandTokensSequence;
var newProperty = isLonghandsShorter ? viaLonghands[1] : viaShorthand[1];
var newComponents = isLonghandsShorter ? viaLonghands[2] : viaShorthand[2];
var all = candidateComponents[Object.keys(candidateComponents)[0]].all;
var lastComponent = candidateComponents[Object.keys(candidateComponents).pop()];
var all = lastComponent.all;
var insertAt = lastComponent.position;
var componentName;
var oldComponent;
var newComponent;
var newToken;
newProperty.position = all.length;
newProperty.position = insertAt;
newProperty.shorthand = true;
newProperty.important = lastComponent.important;
newProperty.multiplex = false;
newProperty.dirty = true;
newProperty.all = all;
newProperty.all.push(newTokensSequence[0]);
newProperty.all[insertAt] = newTokensSequence[0];
properties.push(newProperty);
properties.splice(insertAt, 1, newProperty);
for (componentName in candidateComponents) {
oldComponent = candidateComponents[componentName];
oldComponent.unused = true;
newProperty.multiplex = newProperty.multiplex || oldComponent.multiplex;
if (oldComponent.name in newComponents) {
newComponent = newComponents[oldComponent.name];
newToken = findTokenIn(newTokensSequence, componentName);
@@ -252,7 +279,7 @@ function buildSequenceWithInheritLonghands(components, shorthandName, validator)
var tokensSequence = [];
var inheritComponents = {};
var nonInheritComponents = {};
var descriptor = compactable[shorthandName];
var descriptor = configuration[shorthandName];
var shorthandToken = [
Token.PROPERTY,
[Token.PROPERTY_NAME, shorthandName],
@@ -289,6 +316,8 @@ function buildSequenceWithInheritLonghands(components, shorthandName, validator)
}
}
newProperty.important = components[Object.keys(components).pop()].important;
nameMetadata = joinMetadata(nonInheritComponents, 1);
shorthandToken[1].push(nameMetadata);
@@ -303,7 +332,7 @@ function buildSequenceWithInheritLonghands(components, shorthandName, validator)
}
function inferComponentValue(components, propertyName) {
var descriptor = compactable[propertyName];
var descriptor = configuration[propertyName];
if ('oppositeTo' in descriptor) {
return components[descriptor.oppositeTo].value;
@@ -349,7 +378,7 @@ function buildSequenceWithInheritShorthand(components, shorthandName, validator)
var tokensSequence = [];
var inheritComponents = {};
var nonInheritComponents = {};
var descriptor = compactable[shorthandName];
var descriptor = configuration[shorthandName];
var shorthandToken = [
Token.PROPERTY,
[Token.PROPERTY_NAME, shorthandName],
@@ -400,7 +429,7 @@ function findTokenIn(tokens, componentName) {
}
function replaceWithShorthand(properties, candidateComponents, shorthandName, validator) {
var descriptor = compactable[shorthandName];
var descriptor = configuration[shorthandName];
var nameMetadata;
var valueMetadata;
var newValuePlaceholder = [
@@ -409,10 +438,12 @@ function replaceWithShorthand(properties, candidateComponents, shorthandName, va
[Token.PROPERTY_VALUE, descriptor.defaultValue]
];
var all;
var insertAt = inferInsertAtFrom(properties, candidateComponents, shorthandName);
var newProperty = wrapSingle(newValuePlaceholder);
newProperty.shorthand = true;
newProperty.dirty = true;
newProperty.multiplex = false;
populateComponents([newProperty], validator, []);
@@ -421,6 +452,7 @@ function replaceWithShorthand(properties, candidateComponents, shorthandName, va
newProperty.components[i] = deepClone(component);
newProperty.important = component.important;
newProperty.multiplex = newProperty.multiplex || component.multiplex;
all = component.all;
}
@@ -435,11 +467,33 @@ function replaceWithShorthand(properties, candidateComponents, shorthandName, va
valueMetadata = joinMetadata(candidateComponents, 2);
newValuePlaceholder[2].push(valueMetadata);
newProperty.position = all.length;
newProperty.position = insertAt;
newProperty.all = all;
newProperty.all.push(newValuePlaceholder);
newProperty.all[insertAt] = newValuePlaceholder;
properties.push(newProperty);
properties.splice(insertAt, 1, newProperty);
}
function inferInsertAtFrom(properties, candidateComponents, shorthandName) {
var candidateComponentNames = Object.keys(candidateComponents);
var firstCandidatePosition = candidateComponents[candidateComponentNames[0]].position;
var lastCandidatePosition = candidateComponents[candidateComponentNames[candidateComponentNames.length - 1]].position;
if (shorthandName == 'border' && traversesVia(properties.slice(firstCandidatePosition, lastCandidatePosition), 'border-image')) {
return firstCandidatePosition;
} else {
return lastCandidatePosition;
}
}
function traversesVia(properties, propertyName) {
for (var i = properties.length - 1; i >= 0; i--) {
if (properties[i].name == propertyName) {
return true;
}
}
return false;
}
module.exports = mergeIntoShorthands;

View File

@@ -12,7 +12,7 @@ var OptimizationLevel = require('../../../options/optimization-level').Optimizat
function optimizeProperties(properties, withOverriding, withMerging, context) {
var levelOptions = context.options.level[OptimizationLevel.Two];
var _properties = wrapForOptimizing(properties, false, levelOptions.skipProperties);
var _properties = wrapForOptimizing(properties, levelOptions.skipProperties);
var _property;
var i, l;

View File

@@ -1,15 +1,16 @@
var hasInherit = require('./has-inherit');
var hasUnset = require('./has-unset');
var everyValuesPair = require('./every-values-pair');
var findComponentIn = require('./find-component-in');
var isComponentOf = require('./is-component-of');
var isMergeableShorthand = require('./is-mergeable-shorthand');
var overridesNonComponentShorthand = require('./overrides-non-component-shorthand');
var sameVendorPrefixesIn = require('./vendor-prefixes').same;
var sameVendorPrefixesIn = require('./../../vendor-prefixes').same;
var compactable = require('../compactable');
var deepClone = require('../clone').deep;
var configuration = require('../../configuration');
var deepClone = require('../../clone').deep;
var restoreWithComponents = require('../restore-with-components');
var shallowClone = require('../clone').shallow;
var shallowClone = require('../../clone').shallow;
var restoreFromOptimizing = require('../../restore-from-optimizing');
@@ -18,11 +19,15 @@ var Marker = require('../../../tokenizer/marker');
var serializeProperty = require('../../../writer/one-time').property;
function sameValue(_validator, value1, value2) {
return value1 === value2;
}
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 descriptor = configuration[component.name];
var canOverride = descriptor && descriptor.canOverride || sameValue;
var _component = shallowClone(component);
_component.value = [[Token.PROPERTY_VALUE, descriptor.defaultValue]];
@@ -73,7 +78,7 @@ function overrideShorthand(property, by) {
function turnIntoMultiplex(property, size) {
property.multiplex = true;
if (compactable[property.name].shorthand) {
if (configuration[property.name].shorthand) {
turnShorthandValueIntoMultiplex(property, size);
} else {
turnLonghandValueIntoMultiplex(property, size);
@@ -94,7 +99,7 @@ function turnShorthandValueIntoMultiplex(property, size) {
}
function turnLonghandValueIntoMultiplex(property, size) {
var descriptor = compactable[property.name];
var descriptor = configuration[property.name];
var withRealValue = descriptor.intoMultiplexMode == 'real';
var withValue = descriptor.intoMultiplexMode == 'real' ?
property.value.slice(0) :
@@ -206,7 +211,7 @@ function wouldResultInLongerValue(left, right) {
}
function isCompactable(property) {
return property.name in compactable;
return property.name in configuration;
}
function noneOverrideHack(left, right) {
@@ -263,7 +268,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
if (right.block)
continue;
mayOverride = compactable[right.name].canOverride;
mayOverride = configuration[right.name].canOverride || sameValue;
traverseLoop:
for (j = i - 1; j >= 0; j--) {
@@ -275,6 +280,9 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
if (left.block)
continue;
if (left.dynamic || right.dynamic)
continue;
if (left.unused || right.unused)
continue;
@@ -310,7 +318,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
}
component = findComponentIn(right, left);
mayOverride = compactable[left.name].canOverride;
mayOverride = configuration[left.name].canOverride || sameValue;
if (everyValuesPair(mayOverride.bind(null, validator), left, component)) {
left.unused = true;
}
@@ -335,7 +343,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
for (k = overriddenComponents.length - 1; k >= 0; k--) {
overriddenComponent = overriddenComponents[k];
overridingComponent = findComponentIn(right, overriddenComponent);
mayOverride = compactable[overriddenComponent.name].canOverride;
mayOverride = configuration[overriddenComponent.name].canOverride || sameValue;
if (!everyValuesPair(mayOverride.bind(null, validator), left, overridingComponent)) {
continue traverseLoop;
@@ -363,13 +371,16 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
if (!isMergeableShorthand(left))
continue;
if (hasUnset(left) || hasUnset(right))
continue;
component = findComponentIn(left, 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];
var nonMergeableValue = configuration[right.name].nonMergeableValue === right.value[0][1];
if (disabledBackgroundMerging || nonMergeableValue)
continue;
@@ -414,7 +425,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
var leftComponent = left.components[k];
var rightComponent = right.components[k];
mayOverride = compactable[leftComponent.name].canOverride;
mayOverride = configuration[leftComponent.name].canOverride || sameValue;
if (!everyValuesPair(mayOverride.bind(null, validator), leftComponent, rightComponent))
continue propertyLoop;
}
@@ -428,7 +439,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
continue;
component = findComponentIn(left, right);
mayOverride = compactable[right.name].canOverride;
mayOverride = configuration[right.name].canOverride || sameValue;
if (!everyValuesPair(mayOverride.bind(null, validator), component, right))
continue;
@@ -437,7 +448,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
continue;
}
var rightRestored = compactable[right.name].restore(right, compactable);
var rightRestored = configuration[right.name].restore(right, configuration);
if (rightRestored.length > 1)
continue;
@@ -452,12 +463,12 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
for (k = right.components.length - 1; k >= 0 && overridable; k--) {
overriddenComponent = left.components[k];
overridingComponent = right.components[k];
mayOverride = compactable[overridingComponent.name].canOverride;
mayOverride = configuration[overridingComponent.name].canOverride || sameValue;
overridable = overridable && everyValuesPair(mayOverride.bind(null, validator), overriddenComponent, overridingComponent);
}
} else {
mayOverride = compactable[right.name].canOverride;
mayOverride = configuration[right.name].canOverride || sameValue;
overridable = everyValuesPair(mayOverride.bind(null, validator), left, right);
}

View File

@@ -1,9 +1,9 @@
var compactable = require('../compactable');
var configuration = require('../../configuration');
function overridesNonComponentShorthand(property1, property2) {
return property1.name in compactable &&
'overridesShorthands' in compactable[property1.name] &&
compactable[property1.name].overridesShorthands.indexOf(property2.name) > -1;
return property1.name in configuration &&
'overridesShorthands' in configuration[property1.name] &&
configuration[property1.name].overridesShorthands.indexOf(property2.name) > -1;
}
module.exports = overridesNonComponentShorthand;

View File

@@ -1,5 +1,5 @@
var compactable = require('../compactable');
var InvalidPropertyError = require('../invalid-property-error');
var configuration = require('../../configuration');
var InvalidPropertyError = require('../../invalid-property-error');
function populateComponents(properties, validator, warnings) {
var component;
@@ -7,19 +7,24 @@ function populateComponents(properties, validator, warnings) {
for (var i = properties.length - 1; i >= 0; i--) {
var property = properties[i];
var descriptor = compactable[property.name];
var descriptor = configuration[property.name];
if (!property.dynamic && descriptor && descriptor.shorthand) {
if (onlyValueIsVariable(property, validator) || moreThanOneValueIsVariable(property, validator)) {
property.optimizable = false;
continue;
}
if (descriptor && descriptor.shorthand) {
property.shorthand = true;
property.dirty = true;
try {
property.components = descriptor.breakUp(property, compactable, validator);
property.components = descriptor.breakUp(property, configuration, validator);
if (descriptor.shorthandComponents) {
for (j = 0, m = property.components.length; j < m; j++) {
component = property.components[j];
component.components = compactable[component.name].breakUp(component, compactable, validator);
component.components = configuration[component.name].breakUp(component, configuration, validator);
}
}
} catch (e) {
@@ -39,4 +44,12 @@ function populateComponents(properties, validator, warnings) {
}
}
function onlyValueIsVariable(property, validator) {
return property.value.length == 1 && validator.isVariable(property.value[0][1]);
}
function moreThanOneValueIsVariable(property, validator) {
return property.value.length > 1 && property.value.filter(function (value) { return validator.isVariable(value[1]); }).length > 1;
}
module.exports = populateComponents;

View File

@@ -1,15 +0,0 @@
var sameVendorPrefixes = require('./vendor-prefixes').same;
function understandable(validator, value1, value2, _position, isPaired) {
if (!sameVendorPrefixes(value1, value2)) {
return false;
}
if (isPaired && validator.isVariable(value1) !== validator.isVariable(value2)) {
return false;
}
return true;
}
module.exports = understandable;

View File

@@ -1,23 +0,0 @@
var VENDOR_PREFIX_PATTERN = /(?:^|\W)(\-\w+\-)/g;
function unique(value) {
var prefixes = [];
var match;
while ((match = VENDOR_PREFIX_PATTERN.exec(value)) !== null) {
if (prefixes.indexOf(match[0]) == -1) {
prefixes.push(match[0]);
}
}
return prefixes;
}
function same(value1, value2) {
return unique(value1).sort().join(',') == unique(value2).sort().join(',');
}
module.exports = {
unique: unique,
same: same
};