single-file-core 1.5.52 → 1.5.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/css-rules-minifier.js +14 -19
- package/package.json +1 -1
|
@@ -65,6 +65,8 @@ const BLOCK_CLOSE = "}";
|
|
|
65
65
|
const EMPTY_STRING = "";
|
|
66
66
|
const CSS_IMPORTANCE_NOT_IMPORTANT = 0;
|
|
67
67
|
const CSS_IMPORTANCE_IMPORTANT = 1;
|
|
68
|
+
const INVALID_CSS_ESCAPE_TEST = /\\(?![0-9a-fA-F]{1,6}\s|[^0-9a-zA-Z])/;
|
|
69
|
+
const ANONYMOUS_LAYER_PLACEHOLDER = "\u0000";
|
|
68
70
|
|
|
69
71
|
export {
|
|
70
72
|
process
|
|
@@ -124,12 +126,6 @@ function minifyRules(stylesheets, docContext) {
|
|
|
124
126
|
if (!stylesheetInfo.scoped && stylesheetInfo.stylesheet && !key.urlNode) {
|
|
125
127
|
if (hasChildNodes(stylesheetInfo.stylesheet)) {
|
|
126
128
|
const topConditionalStack = stylesheetInfo.mediaText ? [{ name: "media", prelude: stylesheetInfo.mediaText }] : [];
|
|
127
|
-
if (stylesheetInfo.layerName !== undefined) {
|
|
128
|
-
topConditionalStack.push({ name: "layer", prelude: stylesheetInfo.layerName });
|
|
129
|
-
}
|
|
130
|
-
if (stylesheetInfo.supportsCondition !== undefined) {
|
|
131
|
-
topConditionalStack.push({ name: "supports", prelude: stylesheetInfo.supportsCondition });
|
|
132
|
-
}
|
|
133
129
|
minifyStylesheetRules(stylesheetInfo.stylesheet.children, stylesheets, {
|
|
134
130
|
ancestorsSelectors: [],
|
|
135
131
|
layerStack: [],
|
|
@@ -191,13 +187,11 @@ function buildConditionalStack(conditionalStack, ruleData, docContext) {
|
|
|
191
187
|
|
|
192
188
|
function registerLayerDeclaration(layerStack, layerName, conditionalStack, docContext) {
|
|
193
189
|
const fullLayerName = getFullLayerName([...layerStack, layerName]);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
});
|
|
200
|
-
}
|
|
190
|
+
docContext.layerDeclarations.push({
|
|
191
|
+
name: fullLayerName,
|
|
192
|
+
order: docContext.layerDeclarationCounter++,
|
|
193
|
+
conditionalStack: conditionalStack.slice()
|
|
194
|
+
});
|
|
201
195
|
}
|
|
202
196
|
|
|
203
197
|
function minifyStylesheetRules(cssRules, stylesheets, processingContext, docContext) {
|
|
@@ -421,10 +415,11 @@ function collectDeclarationItemsForElement(element, docContext) {
|
|
|
421
415
|
const declarations = cssRule.block.children;
|
|
422
416
|
for (let declaration = declarations.head; declaration; declaration = declaration.next) {
|
|
423
417
|
const { type, value } = declaration.data;
|
|
424
|
-
if (type === DECLARATION_TYPE && value) {
|
|
418
|
+
if (type === DECLARATION_TYPE && value && value.type !== RAW_TYPE) {
|
|
425
419
|
const isRawValue = value.type === RAW_TYPE;
|
|
426
|
-
const isVendorValue = value.type === VALUE_TYPE && value
|
|
427
|
-
|
|
420
|
+
const isVendorValue = value.type === VALUE_TYPE && hasChildNodes(value) && value.children.head.data.name && value.children.head.data.name.startsWith(VENDOR_PREFIX);
|
|
421
|
+
const isInvalidValue = value.type === VALUE_TYPE && hasChildNodes(value) && value.children.head.data.name && INVALID_CSS_ESCAPE_TEST.test(value.children.head.data.name);
|
|
422
|
+
if (!isRawValue && !isVendorValue && !isInvalidValue) {
|
|
428
423
|
allDeclarations.push({
|
|
429
424
|
declaration,
|
|
430
425
|
selector,
|
|
@@ -634,8 +629,8 @@ function compareDeclarations(declarationA, declarationB, docContext) {
|
|
|
634
629
|
}
|
|
635
630
|
|
|
636
631
|
function compareLayers(layersA, layersB, docContext) {
|
|
637
|
-
const isUnlayeredA = layersA.length === 0
|
|
638
|
-
const isUnlayeredB = layersB.length === 0
|
|
632
|
+
const isUnlayeredA = layersA.length === 0;
|
|
633
|
+
const isUnlayeredB = layersB.length === 0;
|
|
639
634
|
if (isUnlayeredA && isUnlayeredB) {
|
|
640
635
|
return 0;
|
|
641
636
|
}
|
|
@@ -878,7 +873,7 @@ function getPreludeText(prelude, docContext) {
|
|
|
878
873
|
}
|
|
879
874
|
|
|
880
875
|
function getFullLayerName(layers) {
|
|
881
|
-
return layers.
|
|
876
|
+
return layers.map(layerName => layerName === EMPTY_STRING ? ANONYMOUS_LAYER_PLACEHOLDER : layerName).join(LAYER_NAME_SEPARATOR);
|
|
882
877
|
}
|
|
883
878
|
|
|
884
879
|
function parseCss(text, context = SELECTOR_CONTEXT) {
|