@tbela99/css-parser 2.1.0 → 2.3.0
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/CHANGELOG.md +66 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
- package/dist/{src/lib/ast → ast}/arena.js +304 -139
- package/dist/{src/lib/ast → ast}/cache.js +40 -24
- package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
- package/dist/{src/lib/ast → ast}/features/if.js +6 -6
- package/dist/ast/features/index.d.ts +7 -0
- package/dist/{src/lib/ast → ast}/features/index.js +3 -2
- package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
- package/dist/ast/features/mixin.js +953 -0
- package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
- package/dist/ast/features/shorthand.js +129 -0
- package/dist/ast/features/transform.js +188 -0
- package/dist/{src/lib/ast → ast}/features/type.js +2 -2
- package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
- package/dist/{src/lib/ast → ast}/math/math.js +2 -2
- package/dist/{src/lib/ast → ast}/minify.js +745 -201
- package/dist/ast/mixins/custom-function.js +393 -0
- package/dist/ast/mixins/utils.js +53 -0
- package/dist/ast/mixins/variables.js +678 -0
- package/dist/ast/strings.js +910 -0
- package/dist/ast/transform/compute.js +560 -0
- package/dist/ast/transform/matrix.js +67 -0
- package/dist/ast/transform/minify.js +325 -0
- package/dist/ast/transform/perspective.js +24 -0
- package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
- package/dist/ast/transform/scale.js +43 -0
- package/dist/ast/transform/skew.js +38 -0
- package/dist/ast/transform/translate.js +56 -0
- package/dist/ast/transform/utils.js +390 -0
- package/dist/{src/lib/ast → ast}/types.js +2 -2
- package/dist/{src/lib/ast → ast}/walk.js +2 -2
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +30 -21
- package/dist/{src/lib/fs → fs}/resolve.js +2 -2
- package/dist/index-umd-web.js +19727 -10719
- package/dist/index.d.ts +738 -100
- package/dist/{src/node.js → node.js} +70 -52
- package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
- package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
- package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
- package/dist/{src/lib/parser → parser}/input.js +18 -3
- package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
- package/dist/{src/lib/parser → parser}/parse.js +444 -278
- package/dist/{src/lib/parser → parser}/source.js +3 -3
- package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
- package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
- package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
- package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
- package/dist/parser/utils/cache.js +53 -0
- package/dist/parser/utils/canonical.js +78 -0
- package/dist/parser/utils/codes.js +93 -0
- package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
- package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
- package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
- package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
- package/dist/{src/lib/printer → printer}/render.js +582 -153
- package/dist/printer/result.js +148 -0
- package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
- package/dist/printer/writer.js +252 -0
- package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
- package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
- package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
- package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +12 -7
- package/dist/validation/compiled/builtins.js +32 -0
- package/dist/validation/compiled/runtime.js +705 -0
- package/dist/validation/compiled/syntaxes.js +1620 -0
- package/dist/{src/lib/validation → validation}/config.js +63 -16
- package/dist/validation/first.js +574 -0
- package/dist/{src/lib/validation → validation}/match.js +376 -161
- package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
- package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
- package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +68 -55
- package/package.json +15 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -95
- package/dist/src/lib/ast/features/transform.js +0 -90
- package/dist/src/lib/ast/transform/compute.js +0 -362
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/types.d.ts +0 -21
- package/dist/utils/sync.d.ts +0 -16
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
|
|
@@ -11,11 +11,11 @@ import { renderValue } from '../printer/render.js';
|
|
|
11
11
|
import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent } from '../ast/types.js';
|
|
12
12
|
import { minify } from '../ast/minify.js';
|
|
13
13
|
import { Tokenizer, createParseInfo } from './tokenize.js';
|
|
14
|
-
import { ResponseType } from '
|
|
14
|
+
import { ResponseType } from '../types.js';
|
|
15
15
|
import { AstArena, TokenField } from '../ast/arena.js';
|
|
16
16
|
import { AstArenaNode, ARENAID } from '../ast/arena-node.js';
|
|
17
|
-
import { tokensfuncDefMap, pageMarginBoxType } from '../syntax/constants.js';
|
|
18
|
-
import { hashAlgorithms,
|
|
17
|
+
import { isFunctionDefType, tokensfuncDefMap, pageMarginBoxType } from '../syntax/constants.js';
|
|
18
|
+
import { hashAlgorithms, syncHash, hash } from './utils/hash.js';
|
|
19
19
|
import { parseSelector } from './utils/selector.js';
|
|
20
20
|
import { parseDeclaration } from './utils/declaration.js';
|
|
21
21
|
import { getSyntaxRule } from '../validation/config.js';
|
|
@@ -34,6 +34,7 @@ import { memoize } from './utils/cache.js';
|
|
|
34
34
|
import { SourceFile } from './source.js';
|
|
35
35
|
import { dirname } from '../fs/resolve.js';
|
|
36
36
|
import { NodeWalker, ValueWalker } from '../ast/walk.js';
|
|
37
|
+
import { EvaluateMixinFeature } from '../ast/features/mixin.js';
|
|
37
38
|
|
|
38
39
|
function renderTokens(arena, tokens, options) {
|
|
39
40
|
if (tokens == null || tokens.length === 0)
|
|
@@ -55,7 +56,7 @@ function renderTokens(arena, tokens, options) {
|
|
|
55
56
|
* @param block
|
|
56
57
|
*/
|
|
57
58
|
function createAtRuleNode(arena, atRule, typ, tokens, state, errors, end, val, block) {
|
|
58
|
-
const node = arena.createAtRule(typ, arena.
|
|
59
|
+
const node = arena.createAtRule(typ, arena.name[atRule], val, block, tokens, state, errors);
|
|
59
60
|
arena.spanLocation(node, atRule, end);
|
|
60
61
|
return node;
|
|
61
62
|
}
|
|
@@ -95,10 +96,20 @@ function visitorResult(arena, replacement) {
|
|
|
95
96
|
* @param token
|
|
96
97
|
*/
|
|
97
98
|
function createCommentNode(arena, token) {
|
|
98
|
-
|
|
99
|
+
// the comment is an interned string id: the string is not created
|
|
100
|
+
const node = arena.createComment(arena.dataTypes[token], arena.stringValue[token]);
|
|
99
101
|
arena.copyLocation(node, token);
|
|
100
102
|
return node;
|
|
101
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* empty an array and keep its capacity: `array.length = 0` drops the backing store, the next pushes allocate it again
|
|
106
|
+
* @param array
|
|
107
|
+
*/
|
|
108
|
+
function clearArray(array) {
|
|
109
|
+
while (array.length > 0) {
|
|
110
|
+
array.pop();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
102
113
|
/**
|
|
103
114
|
* initial arena capacity: one node for every 4 bytes of css. the statement tokens that are not attached to the tree
|
|
104
115
|
* are recycled, so a parse + minify allocates 0.07 to 0.22 node per byte (up to 0.5 for keyframes heavy stylesheets
|
|
@@ -118,27 +129,30 @@ function arenaCapacity(tokenizer) {
|
|
|
118
129
|
*/
|
|
119
130
|
function allocateToken(arena, tokenizer, sourceIndex) {
|
|
120
131
|
const item = arena.allocate();
|
|
121
|
-
const val = tokenizer.val;
|
|
122
132
|
arena.dataTypes[item] = tokenizer.typ;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
// the string values are interned from the code units of the source: no string is created when the value has
|
|
134
|
+
// already been interned
|
|
135
|
+
switch (tokenizer.field) {
|
|
136
|
+
case 4 /* TokenValueField.Unit */:
|
|
137
|
+
arena.numericValue[item] = tokenizer.num;
|
|
138
|
+
arena.unit[item] = tokenizer.internValue(arena, sourceIndex);
|
|
139
|
+
break;
|
|
140
|
+
case 2 /* TokenValueField.Name */:
|
|
141
|
+
arena.name[item] = tokenizer.internValue(arena, sourceIndex);
|
|
142
|
+
break;
|
|
143
|
+
case 1 /* TokenValueField.Number */:
|
|
144
|
+
arena.numericValue[item] = tokenizer.num;
|
|
145
|
+
break;
|
|
146
|
+
case 3 /* TokenValueField.Value */:
|
|
135
147
|
// whitespace is always rendered as a single space: the text is not kept
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
if (tokenizer.typ !== EnumToken.WhitespaceTokenType) {
|
|
149
|
+
arena.stringValue[item] = tokenizer.internValue(arena, sourceIndex);
|
|
150
|
+
}
|
|
151
|
+
if (tokenizer.kin != null) {
|
|
152
|
+
// inlined: arena.setColorType(item, tokenizer.kin)
|
|
153
|
+
arena.colorType[item] = tokenizer.kin;
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
142
156
|
}
|
|
143
157
|
if (sourceIndex >= 0) {
|
|
144
158
|
arena.setTokenLocation(item, sourceIndex, tokenizer.sta, tokenizer.end);
|
|
@@ -228,13 +242,12 @@ function reject(reason) {
|
|
|
228
242
|
* @private
|
|
229
243
|
*/
|
|
230
244
|
const getKeyName = memoize((key, how) => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return dasherize(key);
|
|
245
|
+
// the case transforms are flags
|
|
246
|
+
if (how & (ModuleCaseTransformEnum.CamelCase | ModuleCaseTransformEnum.CamelCaseOnly)) {
|
|
247
|
+
return camelize(key);
|
|
248
|
+
}
|
|
249
|
+
if (how & (ModuleCaseTransformEnum.DashCase | ModuleCaseTransformEnum.DashCaseOnly)) {
|
|
250
|
+
return dasherize(key);
|
|
238
251
|
}
|
|
239
252
|
return key;
|
|
240
253
|
});
|
|
@@ -482,8 +495,8 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
482
495
|
valuesHandlers.get(EnumToken[key]).push(value);
|
|
483
496
|
}
|
|
484
497
|
else if (typeof value === "object") {
|
|
485
|
-
if ("type" in value && "handler" in value && value.type
|
|
486
|
-
if (value.type
|
|
498
|
+
if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
|
|
499
|
+
if (value.type & WalkerEvent.Enter) {
|
|
487
500
|
if (!preValuesHandlers.has(EnumToken[key])) {
|
|
488
501
|
preValuesHandlers.set(EnumToken[key], []);
|
|
489
502
|
}
|
|
@@ -491,7 +504,7 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
491
504
|
.get(EnumToken[key])
|
|
492
505
|
.push(value.handler);
|
|
493
506
|
}
|
|
494
|
-
|
|
507
|
+
if (value.type & WalkerEvent.Leave) {
|
|
495
508
|
if (!postValuesHandlers.has(EnumToken[key])) {
|
|
496
509
|
postValuesHandlers.set(EnumToken[key], []);
|
|
497
510
|
}
|
|
@@ -520,8 +533,8 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
520
533
|
.push(value);
|
|
521
534
|
}
|
|
522
535
|
else if (typeof value === "object") {
|
|
523
|
-
if ("type" in value && "handler" in value && value.type
|
|
524
|
-
if (value.type
|
|
536
|
+
if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
|
|
537
|
+
if (value.type & WalkerEvent.Enter) {
|
|
525
538
|
if (!preVisitorsHandlersMap.has(key)) {
|
|
526
539
|
preVisitorsHandlersMap.set(key, []);
|
|
527
540
|
}
|
|
@@ -529,7 +542,7 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
529
542
|
.get(key)
|
|
530
543
|
.push(value.handler);
|
|
531
544
|
}
|
|
532
|
-
|
|
545
|
+
if (value.type & WalkerEvent.Leave) {
|
|
533
546
|
if (!postVisitorsHandlersMap.has(key)) {
|
|
534
547
|
postVisitorsHandlersMap.set(key, []);
|
|
535
548
|
}
|
|
@@ -556,11 +569,11 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
556
569
|
allVisitorsHandlers.add(value);
|
|
557
570
|
}
|
|
558
571
|
else if (typeof value === "object") {
|
|
559
|
-
if ("type" in value && "handler" in value && value.type
|
|
560
|
-
if (value.type
|
|
572
|
+
if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
|
|
573
|
+
if (value.type & WalkerEvent.Enter) {
|
|
561
574
|
preAllVisitorsHandlers.add(value.handler);
|
|
562
575
|
}
|
|
563
|
-
|
|
576
|
+
if (value.type & WalkerEvent.Leave) {
|
|
564
577
|
postAllVisitorsHandlers.add(value.handler);
|
|
565
578
|
}
|
|
566
579
|
}
|
|
@@ -637,6 +650,8 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
637
650
|
computeShorthand: true,
|
|
638
651
|
computeCalcExpression: true,
|
|
639
652
|
inlineCssVariables: false,
|
|
653
|
+
evaluateMixins: false,
|
|
654
|
+
keepMixins: false,
|
|
640
655
|
setParent: true,
|
|
641
656
|
removePrefix: false,
|
|
642
657
|
validation: false,
|
|
@@ -682,9 +697,15 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
682
697
|
// @ts-ignore ignore error
|
|
683
698
|
let parensMatch = 0;
|
|
684
699
|
let curlyBracketMatch = 0;
|
|
700
|
+
// '{' opened inside parentheses and not closed yet: `@apply --mixin({a, b})`. their '}' does not end a block
|
|
701
|
+
let parensBlockMatch = 0;
|
|
702
|
+
// the current '{' or '}' belongs to a block opened inside parentheses
|
|
703
|
+
let parensBlock;
|
|
685
704
|
// tokens are located in the tokenizer source (the imported file when parsing an @import)
|
|
686
705
|
arena.setLocation(ast, tokenizer.sourceId, 0, 0);
|
|
687
706
|
const sourceIndex = arena.sourceIndex(tokenizer.sourceId);
|
|
707
|
+
// the strings of the tokens are ranges of the content of the source
|
|
708
|
+
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
688
709
|
let itemType;
|
|
689
710
|
// inlined: tokenizer.done()
|
|
690
711
|
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
@@ -707,13 +728,25 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
707
728
|
// bad token
|
|
708
729
|
continue;
|
|
709
730
|
}
|
|
710
|
-
if (itemType === EnumToken.StartParensTokenType ||
|
|
731
|
+
if (itemType === EnumToken.StartParensTokenType || isFunctionDefType(itemType)) {
|
|
711
732
|
parensMatch++;
|
|
712
733
|
}
|
|
713
734
|
else if (itemType === EnumToken.EndParensTokenType && parensMatch > 0) {
|
|
714
735
|
parensMatch--;
|
|
736
|
+
if (parensMatch === 0) {
|
|
737
|
+
parensBlockMatch = 0;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
parensBlock = false;
|
|
741
|
+
if (parensMatch > 0 && itemType === EnumToken.BlockStartTokenType) {
|
|
742
|
+
parensBlockMatch++;
|
|
743
|
+
parensBlock = true;
|
|
715
744
|
}
|
|
716
|
-
if (itemType === EnumToken.
|
|
745
|
+
else if (parensMatch > 0 && parensBlockMatch > 0 && itemType === EnumToken.BlockEndTokenType) {
|
|
746
|
+
parensBlockMatch--;
|
|
747
|
+
parensBlock = true;
|
|
748
|
+
}
|
|
749
|
+
else if (itemType === EnumToken.BlockStartTokenType) {
|
|
717
750
|
curlyBracketMatch++;
|
|
718
751
|
}
|
|
719
752
|
else if (itemType === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
|
|
@@ -734,7 +767,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
734
767
|
}
|
|
735
768
|
else if (itemType === EnumToken.BlockStartTokenType) {
|
|
736
769
|
let inBlock = 1;
|
|
737
|
-
tokens
|
|
770
|
+
clearArray(tokens);
|
|
738
771
|
tokens.push(item);
|
|
739
772
|
do {
|
|
740
773
|
tokenizer.next();
|
|
@@ -763,12 +796,14 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
763
796
|
}
|
|
764
797
|
}
|
|
765
798
|
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
766
|
-
statement
|
|
767
|
-
tokens
|
|
799
|
+
clearArray(statement);
|
|
800
|
+
clearArray(tokens);
|
|
768
801
|
errorStart = errors.length;
|
|
769
802
|
invalidStart = invalidNodes.length;
|
|
770
803
|
}
|
|
771
|
-
else if (
|
|
804
|
+
else if (!parensBlock &&
|
|
805
|
+
(parensMatch === 0 || curlyBracketMatch === 0) &&
|
|
806
|
+
itemType === EnumToken.BlockEndTokenType) {
|
|
772
807
|
parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
773
808
|
// inlined: arena.setSpanEnd(context, arena.getSpanEnd(item))
|
|
774
809
|
arena.setSpan(context, arena.getSourceId(context), arena.getSpanStart(context), arena.getSpanEnd(item));
|
|
@@ -777,15 +812,19 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
777
812
|
if (options.removeEmpty &&
|
|
778
813
|
previousNode != null &&
|
|
779
814
|
arena.firstChild[previousNode] === 0 &&
|
|
815
|
+
// an empty contents block is kept: `@apply --mixin {}` does not use the default contents of the mixin.
|
|
816
|
+
// an empty mixin or custom function is a definition
|
|
817
|
+
!isDefinitionBlock(arena, previousNode) &&
|
|
780
818
|
arena.lastChild[context] === previousNode) {
|
|
781
819
|
arena.detach(previousNode);
|
|
782
820
|
}
|
|
783
821
|
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
784
|
-
statement
|
|
785
|
-
tokens
|
|
822
|
+
clearArray(statement);
|
|
823
|
+
clearArray(tokens);
|
|
786
824
|
errorStart = errors.length;
|
|
787
825
|
invalidStart = invalidNodes.length;
|
|
788
826
|
parensMatch = 0;
|
|
827
|
+
parensBlockMatch = 0;
|
|
789
828
|
curlyBracketMatch = 0;
|
|
790
829
|
}
|
|
791
830
|
}
|
|
@@ -799,6 +838,15 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
799
838
|
}
|
|
800
839
|
}
|
|
801
840
|
const endParseTime = performance.now();
|
|
841
|
+
// the mixins are evaluated before the nesting rules are expanded: the mixin body is nested in the rule it is
|
|
842
|
+
// applied to. the imported stylesheets are evaluated with the stylesheet that imports them
|
|
843
|
+
// the mixins are evaluated once
|
|
844
|
+
const minifyOptions = options.evaluateMixins ? { ...options, evaluateMixins: false } : options;
|
|
845
|
+
if (options.evaluateMixins) {
|
|
846
|
+
// the invalid nodes are not evaluated
|
|
847
|
+
dropInvalidNodes(arena, invalidNodes, options);
|
|
848
|
+
EvaluateMixinFeature.evaluate(arena, ast, options);
|
|
849
|
+
}
|
|
802
850
|
if (options.expandNestingRules) {
|
|
803
851
|
ast = arena.expand(ast);
|
|
804
852
|
}
|
|
@@ -848,9 +896,9 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
848
896
|
? "Rule"
|
|
849
897
|
: null;
|
|
850
898
|
let keyName = nodeType === EnumToken.DeclarationNodeType || nodeType === EnumToken.AtRuleNodeType
|
|
851
|
-
? camelize(arena.
|
|
899
|
+
? camelize(arena.resolveString(arena.name[node]))
|
|
852
900
|
: nodeType === EnumToken.KeyframesAtRuleNodeType
|
|
853
|
-
? camelize(arena.
|
|
901
|
+
? camelize(arena.resolveString(arena.stringValue[node]))
|
|
854
902
|
: null;
|
|
855
903
|
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
856
904
|
handlers.push(...visitors.allVisitorsHandlers);
|
|
@@ -950,30 +998,20 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
950
998
|
}
|
|
951
999
|
nodes = null;
|
|
952
1000
|
}
|
|
953
|
-
|
|
954
|
-
for (const node of invalidNodes) {
|
|
955
|
-
if (options.lenient && arena.flags[node] & EnumAstNodeStatus.Unknown) {
|
|
956
|
-
continue;
|
|
957
|
-
}
|
|
958
|
-
if (arena.flags[node] &
|
|
959
|
-
(EnumAstNodeStatus.Invalid |
|
|
960
|
-
EnumAstNodeStatus.Unknown |
|
|
961
|
-
EnumAstNodeStatus.Unparsed |
|
|
962
|
-
EnumAstNodeStatus.Malformed |
|
|
963
|
-
EnumAstNodeStatus.Disallowed)) {
|
|
964
|
-
arena.detach(node);
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
}
|
|
1001
|
+
dropInvalidNodes(arena, invalidNodes, options);
|
|
968
1002
|
if (options.minifyAST) {
|
|
969
1003
|
if (arena.firstChild[ast] !== 0) {
|
|
970
1004
|
let passes = options.pass ?? 1;
|
|
971
1005
|
while (passes--) {
|
|
972
|
-
minify(arena, ast,
|
|
1006
|
+
minify(arena, ast, minifyOptions, true, errors, false);
|
|
973
1007
|
}
|
|
974
1008
|
}
|
|
975
1009
|
}
|
|
976
1010
|
stats.bytesIn += stats.importedBytesIn;
|
|
1011
|
+
// the source is no longer tokenized: the code units are not kept
|
|
1012
|
+
arena.releaseSourceCodes(sourceIndex);
|
|
1013
|
+
// the render buffer is allocated from the input length
|
|
1014
|
+
arena.inputLengths[ast] = stats.bytesIn;
|
|
977
1015
|
let endTime = performance.now();
|
|
978
1016
|
const result = {
|
|
979
1017
|
ast,
|
|
@@ -1071,7 +1109,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1071
1109
|
const fromToken = arena
|
|
1072
1110
|
.fieldTokens(node, TokenField.L)
|
|
1073
1111
|
.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType || isIdentColor(arena, t));
|
|
1074
|
-
const from = { val: arena.
|
|
1112
|
+
const from = { val: arena.resolveString(arena.stringValue[fromToken]) };
|
|
1075
1113
|
if (!(from.val in cssVariablesMap)) {
|
|
1076
1114
|
errors.push({
|
|
1077
1115
|
node,
|
|
@@ -1083,16 +1121,16 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1083
1121
|
// @ts-ignore
|
|
1084
1122
|
for (const token of arena.tokens(node)) {
|
|
1085
1123
|
if (arena.dataTypes[token] === EnumToken.IdenTokenType || isIdentColor(arena, token)) {
|
|
1086
|
-
if (!(arena.
|
|
1124
|
+
if (!(arena.resolveString(arena.stringValue[token]) in cssVariablesMap[from.val])) {
|
|
1087
1125
|
errors.push({
|
|
1088
1126
|
node,
|
|
1089
|
-
message: `value '${arena.
|
|
1127
|
+
message: `value '${arena.resolveString(arena.stringValue[token])}' is not exported from '${from.val}'`,
|
|
1090
1128
|
action: "drop",
|
|
1091
1129
|
});
|
|
1092
1130
|
continue;
|
|
1093
1131
|
}
|
|
1094
1132
|
result.cssModuleVariables ??= {};
|
|
1095
|
-
result.cssModuleVariables[arena.
|
|
1133
|
+
result.cssModuleVariables[arena.resolveString(arena.stringValue[token])] = importedCssVariables[arena.resolveString(arena.stringValue[token])] = cssVariablesMap[from.val][arena.resolveString(arena.stringValue[token])];
|
|
1096
1134
|
}
|
|
1097
1135
|
}
|
|
1098
1136
|
}
|
|
@@ -1106,30 +1144,30 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1106
1144
|
}
|
|
1107
1145
|
// inlined: cssVariableToken(arena, node as AstNode): the object view of the css variable node
|
|
1108
1146
|
// inlined: arena.toObject(node as AstNode)
|
|
1109
|
-
result.cssModuleVariables[arena.
|
|
1147
|
+
result.cssModuleVariables[arena.resolveString(arena.name[node])] = new AstArenaNode(arena, node);
|
|
1110
1148
|
}
|
|
1111
1149
|
arena.detach(node);
|
|
1112
1150
|
continue;
|
|
1113
1151
|
}
|
|
1114
1152
|
if (nodeType === EnumToken.DeclarationNodeType) {
|
|
1115
|
-
if (arena.
|
|
1116
|
-
if (!(arena.
|
|
1153
|
+
if (arena.resolveString(arena.name[node]).startsWith("--")) {
|
|
1154
|
+
if (!(arena.resolveString(arena.name[node]) in namesMapping)) {
|
|
1117
1155
|
let value = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1118
|
-
? arena.
|
|
1119
|
-
: moduleSettings.generateScopedName(arena.
|
|
1120
|
-
mapping[arena.
|
|
1156
|
+
? arena.resolveString(arena.name[node])
|
|
1157
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.name[node]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1158
|
+
mapping[arena.resolveString(arena.name[node])] =
|
|
1121
1159
|
"--" +
|
|
1122
1160
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
1123
1161
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
1124
1162
|
? getKeyName(value, moduleSettings.naming)
|
|
1125
1163
|
: value);
|
|
1126
|
-
revMapping[arena.
|
|
1127
|
-
arena.
|
|
1164
|
+
revMapping[arena.resolveString(arena.name[node])] =
|
|
1165
|
+
arena.resolveString(arena.name[node]);
|
|
1128
1166
|
}
|
|
1129
|
-
// inlined: arena.setNameString(node as AstNode, mapping[arena.
|
|
1130
|
-
arena.name[node] = arena.internString(mapping[arena.
|
|
1167
|
+
// inlined: arena.setNameString(node as AstNode, mapping[arena.resolveString(arena.name[node as AstNode])])
|
|
1168
|
+
arena.name[node] = arena.internString(mapping[arena.resolveString(arena.name[node])]);
|
|
1131
1169
|
}
|
|
1132
|
-
if (equalsIgnoreCase("composes", arena.
|
|
1170
|
+
if (equalsIgnoreCase("composes", arena.resolveString(arena.name[node]))) {
|
|
1133
1171
|
const composeSelectors = [];
|
|
1134
1172
|
// let isValid: boolean = true;
|
|
1135
1173
|
for (let token = arena.firstToken[node]; token !== 0; token = arena.nextSibling[token]) {
|
|
@@ -1159,29 +1197,29 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1159
1197
|
arena.dataTypes[rule] === EnumToken.CommentTokenType) {
|
|
1160
1198
|
continue;
|
|
1161
1199
|
}
|
|
1162
|
-
if (!(arena.
|
|
1200
|
+
if (!(arena.resolveString(arena.stringValue[rule]) in mapping)) {
|
|
1163
1201
|
let value = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1164
|
-
? arena.
|
|
1165
|
-
: moduleSettings.generateScopedName(arena.
|
|
1166
|
-
mapping[arena.
|
|
1202
|
+
? arena.resolveString(arena.stringValue[rule])
|
|
1203
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[rule]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1204
|
+
mapping[arena.resolveString(arena.stringValue[rule])] =
|
|
1167
1205
|
(arena.dataTypes[rule] === EnumToken.DashedIdenTokenType ? "--" : "") +
|
|
1168
1206
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
1169
1207
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
1170
1208
|
? getKeyName(value, moduleSettings.naming)
|
|
1171
1209
|
: value);
|
|
1172
|
-
revMapping[mapping[arena.
|
|
1173
|
-
arena.
|
|
1210
|
+
revMapping[mapping[arena.resolveString(arena.stringValue[rule])]] =
|
|
1211
|
+
arena.resolveString(arena.stringValue[rule]);
|
|
1174
1212
|
}
|
|
1175
1213
|
if (parentRule !== 0) {
|
|
1176
1214
|
for (const tk of arena.tokens(parentRule)) {
|
|
1177
1215
|
if (arena.dataTypes[tk] === EnumToken.ClassSelectorTokenType) {
|
|
1178
|
-
const val = arena.
|
|
1216
|
+
const val = arena.resolveString(arena.stringValue[tk]).slice(1);
|
|
1179
1217
|
if (val in revMapping) {
|
|
1180
1218
|
const key = revMapping[val];
|
|
1181
1219
|
mapping[key] = [
|
|
1182
1220
|
...new Set([
|
|
1183
1221
|
...mapping[key].split(" "),
|
|
1184
|
-
mapping[arena.
|
|
1222
|
+
mapping[arena.resolveString(arena.stringValue[rule])],
|
|
1185
1223
|
]),
|
|
1186
1224
|
].join(" ");
|
|
1187
1225
|
}
|
|
@@ -1200,16 +1238,16 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1200
1238
|
else if (arena.dataTypes[arena.field(token, TokenField.R)] === EnumToken.IdenTokenType) {
|
|
1201
1239
|
// global
|
|
1202
1240
|
if (parentRule !== 0) {
|
|
1203
|
-
if (equalsIgnoreCase("global", arena.
|
|
1241
|
+
if (equalsIgnoreCase("global", arena.resolveString(arena.stringValue[arena.field(token, TokenField.R)]))) {
|
|
1204
1242
|
for (const tk of arena.tokens(parentRule)) {
|
|
1205
1243
|
if (arena.dataTypes[tk] === EnumToken.ClassSelectorTokenType) {
|
|
1206
|
-
const val = arena.
|
|
1244
|
+
const val = arena.resolveString(arena.stringValue[tk]).slice(1);
|
|
1207
1245
|
if (val in revMapping) {
|
|
1208
1246
|
const key = revMapping[val];
|
|
1209
1247
|
const composedNames = [];
|
|
1210
1248
|
for (const curr of arena.fieldTokens(token, TokenField.L)) {
|
|
1211
1249
|
if (arena.dataTypes[curr] === EnumToken.IdenTokenType) {
|
|
1212
|
-
composedNames.push(arena.
|
|
1250
|
+
composedNames.push(arena.resolveString(arena.stringValue[curr]));
|
|
1213
1251
|
}
|
|
1214
1252
|
}
|
|
1215
1253
|
mapping[key] = [
|
|
@@ -1222,7 +1260,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1222
1260
|
else {
|
|
1223
1261
|
errors.push({
|
|
1224
1262
|
action: "drop",
|
|
1225
|
-
message: `composes '${arena.
|
|
1263
|
+
message: `composes '${arena.resolveString(arena.stringValue[arena.field(token, TokenField.R)])}' is not supported`,
|
|
1226
1264
|
node,
|
|
1227
1265
|
});
|
|
1228
1266
|
}
|
|
@@ -1241,13 +1279,13 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1241
1279
|
"grid-template",
|
|
1242
1280
|
"grid-template-columns",
|
|
1243
1281
|
"grid-template-rows",
|
|
1244
|
-
].includes(arena.
|
|
1282
|
+
].includes(arena.resolveString(arena.name[node]))) {
|
|
1245
1283
|
// inlined: arena.walkValues(node as AstNode)
|
|
1246
1284
|
for (const value of new ValueWalker(arena, node)) {
|
|
1247
1285
|
if (arena.dataTypes[value] !== EnumToken.IdenTokenType) {
|
|
1248
1286
|
continue;
|
|
1249
1287
|
}
|
|
1250
|
-
let idenToken = arena.
|
|
1288
|
+
let idenToken = arena.resolveString(arena.stringValue[value]);
|
|
1251
1289
|
let suffix = "";
|
|
1252
1290
|
if (idenToken.endsWith("-start")) {
|
|
1253
1291
|
suffix = "-start";
|
|
@@ -1275,26 +1313,26 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1275
1313
|
arena.stringValue[value] = arena.internString(mapping[idenToken]);
|
|
1276
1314
|
}
|
|
1277
1315
|
}
|
|
1278
|
-
else if (arena.
|
|
1279
|
-
arena.
|
|
1316
|
+
else if (arena.resolveString(arena.name[node]) === "grid-template-areas" ||
|
|
1317
|
+
arena.resolveString(arena.name[node]) === "grid-template") {
|
|
1280
1318
|
for (let token = arena.firstToken[node]; token !== 0; token = arena.nextSibling[token]) {
|
|
1281
1319
|
if (arena.dataTypes[token] === EnumToken.StringTokenType) {
|
|
1282
|
-
const str = arena.
|
|
1320
|
+
const str = arena.resolveString(arena.stringValue[token]);
|
|
1283
1321
|
const tokens = parseString(arena, str.slice(1, -1));
|
|
1284
1322
|
// inlined: arena.walkValues(tokens)
|
|
1285
1323
|
for (const value of new ValueWalker(arena, tokens)) {
|
|
1286
1324
|
if (arena.dataTypes[value] === EnumToken.IdenTokenType ||
|
|
1287
1325
|
arena.dataTypes[value] === EnumToken.DashedIdenTokenType) {
|
|
1288
|
-
if (arena.
|
|
1289
|
-
// inlined: arena.setStr(value, mapping[arena.
|
|
1290
|
-
arena.stringValue[value] = arena.internString(mapping[arena.
|
|
1326
|
+
if (arena.resolveString(arena.stringValue[value]) in mapping) {
|
|
1327
|
+
// inlined: arena.setStr(value, mapping[arena.resolveString(arena.stringValue[value])])
|
|
1328
|
+
arena.stringValue[value] = arena.internString(mapping[arena.resolveString(arena.stringValue[value])]);
|
|
1291
1329
|
}
|
|
1292
1330
|
else {
|
|
1293
1331
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1294
|
-
? arena.
|
|
1295
|
-
: moduleSettings.generateScopedName(arena.
|
|
1296
|
-
mapping[arena.
|
|
1297
|
-
revMapping[result] = arena.
|
|
1332
|
+
? arena.resolveString(arena.stringValue[value])
|
|
1333
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[value]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1334
|
+
mapping[arena.resolveString(arena.stringValue[value])] = result;
|
|
1335
|
+
revMapping[result] = arena.resolveString(arena.stringValue[value]);
|
|
1298
1336
|
// inlined: arena.setStr(value, result)
|
|
1299
1337
|
arena.stringValue[value] = arena.internString(result);
|
|
1300
1338
|
}
|
|
@@ -1305,8 +1343,8 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1305
1343
|
}
|
|
1306
1344
|
}
|
|
1307
1345
|
}
|
|
1308
|
-
else if (arena.
|
|
1309
|
-
arena.
|
|
1346
|
+
else if (arena.resolveString(arena.name[node]) === "animation" ||
|
|
1347
|
+
arena.resolveString(arena.name[node]) === "animation-name") {
|
|
1310
1348
|
// inlined: arena.walkValues(node as AstNode)
|
|
1311
1349
|
for (const value of new ValueWalker(arena, node)) {
|
|
1312
1350
|
if (arena.dataTypes[value] === EnumToken.IdenTokenType &&
|
|
@@ -1338,37 +1376,40 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1338
1376
|
"inherit",
|
|
1339
1377
|
"initial",
|
|
1340
1378
|
"unset",
|
|
1341
|
-
].includes(arena.
|
|
1342
|
-
if (!(arena.
|
|
1343
|
-
mapping[arena.
|
|
1379
|
+
].includes(arena.resolveString(arena.stringValue[value]))) {
|
|
1380
|
+
if (!(arena.resolveString(arena.stringValue[value]) in mapping)) {
|
|
1381
|
+
mapping[arena.resolveString(arena.stringValue[value])] =
|
|
1344
1382
|
moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1345
|
-
? arena.
|
|
1346
|
-
: moduleSettings.generateScopedName(arena.
|
|
1347
|
-
revMapping[mapping[arena.
|
|
1348
|
-
arena.
|
|
1383
|
+
? arena.resolveString(arena.stringValue[value])
|
|
1384
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[value]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1385
|
+
revMapping[mapping[arena.resolveString(arena.stringValue[value])]] =
|
|
1386
|
+
arena.resolveString(arena.stringValue[value]);
|
|
1349
1387
|
}
|
|
1350
|
-
// inlined: arena.setStr(value, mapping[arena.
|
|
1351
|
-
arena.stringValue[value] = arena.internString(mapping[arena.
|
|
1388
|
+
// inlined: arena.setStr(value, mapping[arena.resolveString(arena.stringValue[value])])
|
|
1389
|
+
arena.stringValue[value] = arena.internString(mapping[arena.resolveString(arena.stringValue[value])]);
|
|
1352
1390
|
}
|
|
1353
1391
|
}
|
|
1354
1392
|
}
|
|
1355
1393
|
// inlined: arena.walkValues(node as AstNode)
|
|
1356
1394
|
for (const value of new ValueWalker(arena, node)) {
|
|
1357
1395
|
if (arena.dataTypes[value] === EnumToken.DashedIdenTokenType) {
|
|
1358
|
-
|
|
1359
|
-
|
|
1396
|
+
const mapped = mapping[arena.resolveString(arena.stringValue[value])];
|
|
1397
|
+
// a custom property that is not declared is not renamed
|
|
1398
|
+
if (mapped !== undefined) {
|
|
1399
|
+
arena.stringValue[value] = arena.internString(mapped);
|
|
1400
|
+
}
|
|
1360
1401
|
}
|
|
1361
1402
|
else if ((arena.dataTypes[value] === EnumToken.IdenTokenType || isIdentColor(arena, value)) &&
|
|
1362
|
-
arena.
|
|
1403
|
+
arena.resolveString(arena.stringValue[value]) in importedCssVariables) {
|
|
1363
1404
|
arena.replaceToken(value, ...arena
|
|
1364
|
-
.tokens(importedCssVariables[arena.
|
|
1405
|
+
.tokens(importedCssVariables[arena.resolveString(arena.stringValue[value])][ARENAID])
|
|
1365
1406
|
.map((token) => arena.clone(token, true)));
|
|
1366
1407
|
}
|
|
1367
1408
|
}
|
|
1368
1409
|
}
|
|
1369
1410
|
else if (nodeType === EnumToken.RuleNodeType) {
|
|
1370
1411
|
// if (node[TOKENS] == null) {
|
|
1371
|
-
const tokens = parseString(arena, arena.
|
|
1412
|
+
const tokens = parseString(arena, arena.resolveString(arena.name[node]));
|
|
1372
1413
|
matchSelectorSyntax(arena, tokens, [], options);
|
|
1373
1414
|
arena.setTokenList(node, trimArray(arena, tokens));
|
|
1374
1415
|
let hasIdOrClass = false;
|
|
@@ -1376,7 +1417,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1376
1417
|
for (const value of new ValueWalker(arena, node, (arena, value) => {
|
|
1377
1418
|
if (arena.dataTypes[value] === EnumToken.PseudoClassTokenType ||
|
|
1378
1419
|
arena.dataTypes[value] === EnumToken.PseudoElementTokenType) {
|
|
1379
|
-
const val = arena.
|
|
1420
|
+
const val = arena.resolveString(arena.stringValue[value]).toLowerCase();
|
|
1380
1421
|
switch (val) {
|
|
1381
1422
|
case ":local":
|
|
1382
1423
|
case ":global":
|
|
@@ -1394,7 +1435,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1394
1435
|
}
|
|
1395
1436
|
}
|
|
1396
1437
|
else if (arena.dataTypes[value] === EnumToken.PseudoClassFuncTokenType) {
|
|
1397
|
-
switch (arena.
|
|
1438
|
+
switch (arena.resolveString(arena.stringValue[value]).toLowerCase()) {
|
|
1398
1439
|
case ":global":
|
|
1399
1440
|
for (const token of arena.tokens(value)) {
|
|
1400
1441
|
global.add(token);
|
|
@@ -1425,7 +1466,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1425
1466
|
continue;
|
|
1426
1467
|
}
|
|
1427
1468
|
if (arena.dataTypes[value] === EnumToken.ClassSelectorTokenType) {
|
|
1428
|
-
const val = arena.
|
|
1469
|
+
const val = arena.resolveString(arena.stringValue[value]).slice(1);
|
|
1429
1470
|
if (!(val in mapping)) {
|
|
1430
1471
|
let value = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1431
1472
|
? val
|
|
@@ -1446,7 +1487,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1446
1487
|
if (!hasIdOrClass) {
|
|
1447
1488
|
throw new Error(
|
|
1448
1489
|
// inlined: options.source!.getOffsets(arena.getSpanStart(node as AstNode))
|
|
1449
|
-
`pure module: No id or class found in selector '${arena.
|
|
1490
|
+
`pure module: No id or class found in selector '${arena.resolveString(arena.name[node])}' at '${options.source.lineStarts.getOffsets(arena.getSpanStart(node)).join(":")}'`);
|
|
1450
1491
|
}
|
|
1451
1492
|
}
|
|
1452
1493
|
// inlined: arena.setSelector(node as AstNode, arena.tokens(node as AstNode).reduce((acc: string, token: Token) => acc + renderValue(arena, token), ""))
|
|
@@ -1455,31 +1496,31 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1455
1496
|
.reduce((acc, token) => acc + renderValue(arena, token), ""));
|
|
1456
1497
|
}
|
|
1457
1498
|
else if (nodeType === EnumToken.AtRuleNodeType || nodeType === EnumToken.KeyframesAtRuleNodeType) {
|
|
1458
|
-
const val = arena.
|
|
1499
|
+
const val = arena.resolveString(arena.name[node]).toLowerCase();
|
|
1459
1500
|
if (arena.firstToken[node] === 0) {
|
|
1460
|
-
// inlined: arena.setTokens(node as AstNode, ...parseString(arena, arena.
|
|
1461
|
-
arena.setTokenList(node, parseString(arena, arena.
|
|
1501
|
+
// inlined: arena.setTokens(node as AstNode, ...parseString(arena, arena.resolveString(arena.stringValue[node as AstNode])))
|
|
1502
|
+
arena.setTokenList(node, parseString(arena, arena.resolveString(arena.stringValue[node])));
|
|
1462
1503
|
}
|
|
1463
1504
|
if (val === "property" || val === "keyframes") {
|
|
1464
1505
|
const prefix = val === "property" ? "--" : "";
|
|
1465
1506
|
for (const value of arena.tokens(node)) {
|
|
1466
1507
|
if ((prefix === "--" && arena.dataTypes[value] === EnumToken.DashedIdenTokenType) ||
|
|
1467
1508
|
(prefix === "" && arena.dataTypes[value] === EnumToken.IdenTokenType)) {
|
|
1468
|
-
if (!(arena.
|
|
1509
|
+
if (!(arena.resolveString(arena.stringValue[value]) in mapping)) {
|
|
1469
1510
|
let val = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1470
|
-
? arena.
|
|
1471
|
-
: moduleSettings.generateScopedName(arena.
|
|
1472
|
-
mapping[arena.
|
|
1511
|
+
? arena.resolveString(arena.stringValue[value])
|
|
1512
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[value]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1513
|
+
mapping[arena.resolveString(arena.stringValue[value])] =
|
|
1473
1514
|
prefix +
|
|
1474
1515
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
1475
1516
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
1476
1517
|
? getKeyName(val, moduleSettings.naming)
|
|
1477
1518
|
: val);
|
|
1478
|
-
revMapping[mapping[arena.
|
|
1479
|
-
arena.
|
|
1519
|
+
revMapping[mapping[arena.resolveString(arena.stringValue[value])]] =
|
|
1520
|
+
arena.resolveString(arena.stringValue[value]);
|
|
1480
1521
|
}
|
|
1481
|
-
// inlined: arena.setStr(value, mapping[arena.
|
|
1482
|
-
arena.stringValue[value] = arena.internString(mapping[arena.
|
|
1522
|
+
// inlined: arena.setStr(value, mapping[arena.resolveString(arena.stringValue[value])])
|
|
1523
|
+
arena.stringValue[value] = arena.internString(mapping[arena.resolveString(arena.stringValue[value])]);
|
|
1483
1524
|
}
|
|
1484
1525
|
}
|
|
1485
1526
|
// inlined: arena.setValueString(node as AstNode, renderTokens(arena, arena.tokens(node as AstNode)))
|
|
@@ -1487,7 +1528,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1487
1528
|
}
|
|
1488
1529
|
}
|
|
1489
1530
|
}
|
|
1490
|
-
if (moduleSettings.naming
|
|
1531
|
+
if ((moduleSettings.naming & ModuleCaseTransformEnum.IgnoreCase) == 0) {
|
|
1491
1532
|
revMapping = {};
|
|
1492
1533
|
mapping = {};
|
|
1493
1534
|
let keyName;
|
|
@@ -1540,6 +1581,8 @@ async function doParse(iter, options = {}) {
|
|
|
1540
1581
|
computeShorthand: true,
|
|
1541
1582
|
computeCalcExpression: true,
|
|
1542
1583
|
inlineCssVariables: false,
|
|
1584
|
+
evaluateMixins: false,
|
|
1585
|
+
keepMixins: false,
|
|
1543
1586
|
setParent: true,
|
|
1544
1587
|
removePrefix: false,
|
|
1545
1588
|
validation: false,
|
|
@@ -1590,9 +1633,15 @@ async function doParse(iter, options = {}) {
|
|
|
1590
1633
|
// @ts-ignore ignore error
|
|
1591
1634
|
let parensMatch = 0;
|
|
1592
1635
|
let curlyBracketMatch = 0;
|
|
1636
|
+
// '{' opened inside parentheses and not closed yet: `@apply --mixin({a, b})`. their '}' does not end a block
|
|
1637
|
+
let parensBlockMatch = 0;
|
|
1638
|
+
// the current '{' or '}' belongs to a block opened inside parentheses
|
|
1639
|
+
let parensBlock;
|
|
1593
1640
|
// tokens are located in the tokenizer source (the imported file when parsing an @import)
|
|
1594
1641
|
arena.setLocation(ast, tokenizer.sourceId, 0, 0);
|
|
1595
1642
|
const sourceIndex = arena.sourceIndex(tokenizer.sourceId);
|
|
1643
|
+
// the strings of the tokens are ranges of the content of the source
|
|
1644
|
+
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
1596
1645
|
let itemType;
|
|
1597
1646
|
// inlined: tokenizer.done()
|
|
1598
1647
|
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
@@ -1615,13 +1664,25 @@ async function doParse(iter, options = {}) {
|
|
|
1615
1664
|
// bad token
|
|
1616
1665
|
continue;
|
|
1617
1666
|
}
|
|
1618
|
-
if (itemType === EnumToken.StartParensTokenType ||
|
|
1667
|
+
if (itemType === EnumToken.StartParensTokenType || isFunctionDefType(itemType)) {
|
|
1619
1668
|
parensMatch++;
|
|
1620
1669
|
}
|
|
1621
1670
|
else if (itemType === EnumToken.EndParensTokenType && parensMatch > 0) {
|
|
1622
1671
|
parensMatch--;
|
|
1672
|
+
if (parensMatch === 0) {
|
|
1673
|
+
parensBlockMatch = 0;
|
|
1674
|
+
}
|
|
1623
1675
|
}
|
|
1624
|
-
|
|
1676
|
+
parensBlock = false;
|
|
1677
|
+
if (parensMatch > 0 && itemType === EnumToken.BlockStartTokenType) {
|
|
1678
|
+
parensBlockMatch++;
|
|
1679
|
+
parensBlock = true;
|
|
1680
|
+
}
|
|
1681
|
+
else if (parensMatch > 0 && parensBlockMatch > 0 && itemType === EnumToken.BlockEndTokenType) {
|
|
1682
|
+
parensBlockMatch--;
|
|
1683
|
+
parensBlock = true;
|
|
1684
|
+
}
|
|
1685
|
+
else if (itemType === EnumToken.BlockStartTokenType) {
|
|
1625
1686
|
curlyBracketMatch++;
|
|
1626
1687
|
}
|
|
1627
1688
|
else if (itemType === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
|
|
@@ -1640,13 +1701,13 @@ async function doParse(iter, options = {}) {
|
|
|
1640
1701
|
context = node;
|
|
1641
1702
|
}
|
|
1642
1703
|
else if (arena.dataTypes[node] === EnumToken.AtRuleNodeType &&
|
|
1643
|
-
arena.
|
|
1704
|
+
arena.resolveString(arena.name[node]) === "import") {
|
|
1644
1705
|
imports.push(node);
|
|
1645
1706
|
}
|
|
1646
1707
|
}
|
|
1647
1708
|
else if (itemType === EnumToken.BlockStartTokenType) {
|
|
1648
1709
|
let inBlock = 1;
|
|
1649
|
-
tokens
|
|
1710
|
+
clearArray(tokens);
|
|
1650
1711
|
tokens.push(item);
|
|
1651
1712
|
do {
|
|
1652
1713
|
tokenizer.next();
|
|
@@ -1675,12 +1736,14 @@ async function doParse(iter, options = {}) {
|
|
|
1675
1736
|
}
|
|
1676
1737
|
}
|
|
1677
1738
|
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
1678
|
-
statement
|
|
1679
|
-
tokens
|
|
1739
|
+
clearArray(statement);
|
|
1740
|
+
clearArray(tokens);
|
|
1680
1741
|
errorStart = errors.length;
|
|
1681
1742
|
invalidStart = invalidNodes.length;
|
|
1682
1743
|
}
|
|
1683
|
-
else if (
|
|
1744
|
+
else if (!parensBlock &&
|
|
1745
|
+
(parensMatch === 0 || curlyBracketMatch === 0) &&
|
|
1746
|
+
itemType === EnumToken.BlockEndTokenType) {
|
|
1684
1747
|
parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
1685
1748
|
// inlined: arena.setSpanEnd(context, arena.getSpanEnd(item))
|
|
1686
1749
|
arena.setSpan(context, arena.getSourceId(context), arena.getSpanStart(context), arena.getSpanEnd(item));
|
|
@@ -1689,15 +1752,19 @@ async function doParse(iter, options = {}) {
|
|
|
1689
1752
|
if (options.removeEmpty &&
|
|
1690
1753
|
previousNode != null &&
|
|
1691
1754
|
arena.firstChild[previousNode] === 0 &&
|
|
1755
|
+
// an empty contents block is kept: `@apply --mixin {}` does not use the default contents of the mixin.
|
|
1756
|
+
// an empty mixin or custom function is a definition
|
|
1757
|
+
!isDefinitionBlock(arena, previousNode) &&
|
|
1692
1758
|
arena.lastChild[context] === previousNode) {
|
|
1693
1759
|
arena.detach(previousNode);
|
|
1694
1760
|
}
|
|
1695
1761
|
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
1696
|
-
statement
|
|
1697
|
-
tokens
|
|
1762
|
+
clearArray(statement);
|
|
1763
|
+
clearArray(tokens);
|
|
1698
1764
|
errorStart = errors.length;
|
|
1699
1765
|
invalidStart = invalidNodes.length;
|
|
1700
1766
|
parensMatch = 0;
|
|
1767
|
+
parensBlockMatch = 0;
|
|
1701
1768
|
curlyBracketMatch = 0;
|
|
1702
1769
|
}
|
|
1703
1770
|
}
|
|
@@ -1705,7 +1772,7 @@ async function doParse(iter, options = {}) {
|
|
|
1705
1772
|
node = parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
1706
1773
|
if (node != null) {
|
|
1707
1774
|
if (arena.dataTypes[node] === EnumToken.AtRuleNodeType &&
|
|
1708
|
-
"import" === arena.
|
|
1775
|
+
"import" === arena.resolveString(arena.stringValue[node])) {
|
|
1709
1776
|
imports.push(node);
|
|
1710
1777
|
}
|
|
1711
1778
|
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
@@ -1721,8 +1788,8 @@ async function doParse(iter, options = {}) {
|
|
|
1721
1788
|
}
|
|
1722
1789
|
const token = arena.firstToken[node];
|
|
1723
1790
|
const url = arena.dataTypes[token] === EnumToken.StringTokenType
|
|
1724
|
-
? arena.
|
|
1725
|
-
: arena.
|
|
1791
|
+
? arena.resolveString(arena.stringValue[token]).slice(1, -1)
|
|
1792
|
+
: arena.resolveString(arena.stringValue[token]);
|
|
1726
1793
|
try {
|
|
1727
1794
|
const src = options.resolve(url, options.src ? dirname(options.src) : options.cwd);
|
|
1728
1795
|
// the imported file is loaded as an ArrayBuffer: the preferred input of the tokenizer
|
|
@@ -1738,6 +1805,8 @@ async function doParse(iter, options = {}) {
|
|
|
1738
1805
|
: new Tokenizer(parseInfo), Object.assign({}, options, {
|
|
1739
1806
|
minify: false,
|
|
1740
1807
|
setParent: false,
|
|
1808
|
+
// the mixins are evaluated once the imported stylesheet is merged
|
|
1809
|
+
evaluateMixins: false,
|
|
1741
1810
|
src: options.resolve(url, options.src || options.cwd).relative,
|
|
1742
1811
|
}));
|
|
1743
1812
|
stats.importedBytesIn += root.stats.bytesIn;
|
|
@@ -1762,6 +1831,15 @@ async function doParse(iter, options = {}) {
|
|
|
1762
1831
|
}));
|
|
1763
1832
|
}
|
|
1764
1833
|
const endParseTime = performance.now();
|
|
1834
|
+
// the mixins are evaluated before the nesting rules are expanded: the mixin body is nested in the rule it is
|
|
1835
|
+
// applied to. the imported stylesheets are evaluated with the stylesheet that imports them
|
|
1836
|
+
// the mixins are evaluated once
|
|
1837
|
+
const minifyOptions = options.evaluateMixins ? { ...options, evaluateMixins: false } : options;
|
|
1838
|
+
if (options.evaluateMixins) {
|
|
1839
|
+
// the invalid nodes are not evaluated
|
|
1840
|
+
dropInvalidNodes(arena, invalidNodes, options);
|
|
1841
|
+
EvaluateMixinFeature.evaluate(arena, ast, options);
|
|
1842
|
+
}
|
|
1765
1843
|
if (options.expandNestingRules) {
|
|
1766
1844
|
ast = arena.expand(ast);
|
|
1767
1845
|
}
|
|
@@ -1811,9 +1889,9 @@ async function doParse(iter, options = {}) {
|
|
|
1811
1889
|
? "Rule"
|
|
1812
1890
|
: null;
|
|
1813
1891
|
let keyName = nodeType === EnumToken.DeclarationNodeType || nodeType === EnumToken.AtRuleNodeType
|
|
1814
|
-
? camelize(arena.
|
|
1892
|
+
? camelize(arena.resolveString(arena.name[node]))
|
|
1815
1893
|
: nodeType === EnumToken.KeyframesAtRuleNodeType
|
|
1816
|
-
? camelize(arena.
|
|
1894
|
+
? camelize(arena.resolveString(arena.stringValue[node]))
|
|
1817
1895
|
: null;
|
|
1818
1896
|
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
1819
1897
|
handlers.push(...visitors.allVisitorsHandlers);
|
|
@@ -1916,30 +1994,20 @@ async function doParse(iter, options = {}) {
|
|
|
1916
1994
|
}
|
|
1917
1995
|
nodes = null;
|
|
1918
1996
|
}
|
|
1919
|
-
|
|
1920
|
-
for (const node of invalidNodes) {
|
|
1921
|
-
if (options.lenient && arena.flags[node] & EnumAstNodeStatus.Unknown) {
|
|
1922
|
-
continue;
|
|
1923
|
-
}
|
|
1924
|
-
if (arena.flags[node] &
|
|
1925
|
-
(EnumAstNodeStatus.Invalid |
|
|
1926
|
-
EnumAstNodeStatus.Unknown |
|
|
1927
|
-
EnumAstNodeStatus.Unparsed |
|
|
1928
|
-
EnumAstNodeStatus.Malformed |
|
|
1929
|
-
EnumAstNodeStatus.Disallowed)) {
|
|
1930
|
-
arena.detach(node);
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1997
|
+
dropInvalidNodes(arena, invalidNodes, options);
|
|
1934
1998
|
if (options.minifyAST) {
|
|
1935
1999
|
if (arena.firstChild[ast] !== 0) {
|
|
1936
2000
|
let passes = options.pass ?? 1;
|
|
1937
2001
|
while (passes--) {
|
|
1938
|
-
minify(arena, ast,
|
|
2002
|
+
minify(arena, ast, minifyOptions, true, errors, false);
|
|
1939
2003
|
}
|
|
1940
2004
|
}
|
|
1941
2005
|
}
|
|
1942
2006
|
stats.bytesIn += stats.importedBytesIn;
|
|
2007
|
+
// the source is no longer tokenized: the code units are not kept
|
|
2008
|
+
arena.releaseSourceCodes(sourceIndex);
|
|
2009
|
+
// the render buffer is allocated from the input length
|
|
2010
|
+
arena.inputLengths[ast] = stats.bytesIn;
|
|
1943
2011
|
let endTime = performance.now();
|
|
1944
2012
|
const result = {
|
|
1945
2013
|
ast,
|
|
@@ -2025,7 +2093,7 @@ async function doParse(iter, options = {}) {
|
|
|
2025
2093
|
const parent = arena.parents[node];
|
|
2026
2094
|
const nodeType = arena.dataTypes[node];
|
|
2027
2095
|
if (nodeType === EnumToken.CssVariableImportTokenType) {
|
|
2028
|
-
const url = arena.
|
|
2096
|
+
const url = arena.resolveString(arena.stringValue[arena.findToken(node, (arena, t) => arena.dataTypes[t] === EnumToken.StringTokenType)]).slice(1, -1);
|
|
2029
2097
|
const src = options.resolve(url, options.dirname(options.src), options.cwd);
|
|
2030
2098
|
const result = options.load(src, "", ResponseType.ArrayBuffer);
|
|
2031
2099
|
const stream = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == "AsyncFunction"
|
|
@@ -2040,10 +2108,11 @@ async function doParse(iter, options = {}) {
|
|
|
2040
2108
|
source,
|
|
2041
2109
|
minify: false,
|
|
2042
2110
|
setParent: false,
|
|
2111
|
+
evaluateMixins: false,
|
|
2043
2112
|
src: src.relative,
|
|
2044
2113
|
}));
|
|
2045
2114
|
// options.parseInfo!.time += parseInfo.time;
|
|
2046
|
-
cssVariablesMap[arena.
|
|
2115
|
+
cssVariablesMap[arena.resolveString(arena.name[node])] = root.cssModuleVariables;
|
|
2047
2116
|
arena.detach(node);
|
|
2048
2117
|
continue;
|
|
2049
2118
|
}
|
|
@@ -2053,7 +2122,7 @@ async function doParse(iter, options = {}) {
|
|
|
2053
2122
|
const fromToken = arena
|
|
2054
2123
|
.fieldTokens(node, TokenField.L)
|
|
2055
2124
|
.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType || isIdentColor(arena, t));
|
|
2056
|
-
const from = { val: arena.
|
|
2125
|
+
const from = { val: arena.resolveString(arena.stringValue[fromToken]) };
|
|
2057
2126
|
if (!(from.val in cssVariablesMap)) {
|
|
2058
2127
|
errors.push({
|
|
2059
2128
|
node,
|
|
@@ -2065,16 +2134,16 @@ async function doParse(iter, options = {}) {
|
|
|
2065
2134
|
// @ts-ignore
|
|
2066
2135
|
for (const token of arena.tokens(node)) {
|
|
2067
2136
|
if (arena.dataTypes[token] === EnumToken.IdenTokenType || isIdentColor(arena, token)) {
|
|
2068
|
-
if (!(arena.
|
|
2137
|
+
if (!(arena.resolveString(arena.stringValue[token]) in cssVariablesMap[from.val])) {
|
|
2069
2138
|
errors.push({
|
|
2070
2139
|
node,
|
|
2071
|
-
message: `value '${arena.
|
|
2140
|
+
message: `value '${arena.resolveString(arena.stringValue[token])}' is not exported from '${from.val}'`,
|
|
2072
2141
|
action: "drop",
|
|
2073
2142
|
});
|
|
2074
2143
|
continue;
|
|
2075
2144
|
}
|
|
2076
2145
|
result.cssModuleVariables ??= {};
|
|
2077
|
-
result.cssModuleVariables[arena.
|
|
2146
|
+
result.cssModuleVariables[arena.resolveString(arena.stringValue[token])] = importedCssVariables[arena.resolveString(arena.stringValue[token])] = cssVariablesMap[from.val][arena.resolveString(arena.stringValue[token])];
|
|
2078
2147
|
}
|
|
2079
2148
|
}
|
|
2080
2149
|
}
|
|
@@ -2088,32 +2157,32 @@ async function doParse(iter, options = {}) {
|
|
|
2088
2157
|
}
|
|
2089
2158
|
// inlined: cssVariableToken(arena, node as AstNode): the object view of the css variable node
|
|
2090
2159
|
// inlined: arena.toObject(node as AstNode)
|
|
2091
|
-
result.cssModuleVariables[arena.
|
|
2160
|
+
result.cssModuleVariables[arena.resolveString(arena.name[node])] = new AstArenaNode(arena, node);
|
|
2092
2161
|
}
|
|
2093
2162
|
arena.detach(node);
|
|
2094
2163
|
continue;
|
|
2095
2164
|
}
|
|
2096
2165
|
if (nodeType === EnumToken.DeclarationNodeType) {
|
|
2097
|
-
if (arena.
|
|
2098
|
-
if (!(arena.
|
|
2166
|
+
if (arena.resolveString(arena.name[node]).startsWith("--")) {
|
|
2167
|
+
if (!(arena.resolveString(arena.name[node]) in namesMapping)) {
|
|
2099
2168
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2100
|
-
? arena.
|
|
2101
|
-
: moduleSettings.generateScopedName(arena.
|
|
2169
|
+
? arena.resolveString(arena.name[node])
|
|
2170
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.name[node]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2102
2171
|
// @ts-ignore
|
|
2103
2172
|
let value = result instanceof Promise ? await result : result;
|
|
2104
|
-
mapping[arena.
|
|
2173
|
+
mapping[arena.resolveString(arena.name[node])] =
|
|
2105
2174
|
"--" +
|
|
2106
2175
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2107
2176
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2108
2177
|
? getKeyName(value, moduleSettings.naming)
|
|
2109
2178
|
: value);
|
|
2110
|
-
revMapping[arena.
|
|
2111
|
-
arena.
|
|
2179
|
+
revMapping[arena.resolveString(arena.name[node])] =
|
|
2180
|
+
arena.resolveString(arena.name[node]);
|
|
2112
2181
|
}
|
|
2113
|
-
// inlined: arena.setNameString(node as AstNode, mapping[arena.
|
|
2114
|
-
arena.name[node] = arena.internString(mapping[arena.
|
|
2182
|
+
// inlined: arena.setNameString(node as AstNode, mapping[arena.resolveString(arena.name[node as AstNode])])
|
|
2183
|
+
arena.name[node] = arena.internString(mapping[arena.resolveString(arena.name[node])]);
|
|
2115
2184
|
}
|
|
2116
|
-
if (equalsIgnoreCase("composes", arena.
|
|
2185
|
+
if (equalsIgnoreCase("composes", arena.resolveString(arena.name[node]))) {
|
|
2117
2186
|
const composeSelectors = [];
|
|
2118
2187
|
// let isValid: boolean = true;
|
|
2119
2188
|
for (let token = arena.firstToken[node]; token !== 0; token = arena.nextSibling[token]) {
|
|
@@ -2144,31 +2213,31 @@ async function doParse(iter, options = {}) {
|
|
|
2144
2213
|
arena.dataTypes[rule] === EnumToken.CommentTokenType) {
|
|
2145
2214
|
continue;
|
|
2146
2215
|
}
|
|
2147
|
-
if (!(arena.
|
|
2216
|
+
if (!(arena.resolveString(arena.stringValue[rule]) in mapping)) {
|
|
2148
2217
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2149
|
-
? arena.
|
|
2150
|
-
: moduleSettings.generateScopedName(arena.
|
|
2218
|
+
? arena.resolveString(arena.stringValue[rule])
|
|
2219
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[rule]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2151
2220
|
// @ts-expect-error
|
|
2152
2221
|
let value = result instanceof Promise ? await result : result;
|
|
2153
|
-
mapping[arena.
|
|
2222
|
+
mapping[arena.resolveString(arena.stringValue[rule])] =
|
|
2154
2223
|
(arena.dataTypes[rule] === EnumToken.DashedIdenTokenType ? "--" : "") +
|
|
2155
2224
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2156
2225
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2157
2226
|
? getKeyName(value, moduleSettings.naming)
|
|
2158
2227
|
: value);
|
|
2159
|
-
revMapping[mapping[arena.
|
|
2160
|
-
arena.
|
|
2228
|
+
revMapping[mapping[arena.resolveString(arena.stringValue[rule])]] =
|
|
2229
|
+
arena.resolveString(arena.stringValue[rule]);
|
|
2161
2230
|
}
|
|
2162
2231
|
if (parentRule !== 0) {
|
|
2163
2232
|
for (const tk of arena.tokens(parentRule)) {
|
|
2164
2233
|
if (arena.dataTypes[tk] === EnumToken.ClassSelectorTokenType) {
|
|
2165
|
-
const val = arena.
|
|
2234
|
+
const val = arena.resolveString(arena.stringValue[tk]).slice(1);
|
|
2166
2235
|
if (val in revMapping) {
|
|
2167
2236
|
const key = revMapping[val];
|
|
2168
2237
|
mapping[key] = [
|
|
2169
2238
|
...new Set([
|
|
2170
2239
|
...mapping[key].split(" "),
|
|
2171
|
-
mapping[arena.
|
|
2240
|
+
mapping[arena.resolveString(arena.stringValue[rule])],
|
|
2172
2241
|
]),
|
|
2173
2242
|
].join(" ");
|
|
2174
2243
|
}
|
|
@@ -2179,7 +2248,7 @@ async function doParse(iter, options = {}) {
|
|
|
2179
2248
|
}
|
|
2180
2249
|
// composes: a b c from 'file.css';
|
|
2181
2250
|
else if (arena.dataTypes[arena.field(token, TokenField.R)] === EnumToken.StringTokenType) {
|
|
2182
|
-
const url = arena.
|
|
2251
|
+
const url = arena.resolveString(arena.stringValue[arena.field(token, TokenField.R)]).slice(1, -1);
|
|
2183
2252
|
const src = options.resolve(url, options.dirname(options.src), options.cwd);
|
|
2184
2253
|
const result = options.load(src, "", ResponseType.ArrayBuffer);
|
|
2185
2254
|
const stream = result instanceof Promise ||
|
|
@@ -2191,6 +2260,7 @@ async function doParse(iter, options = {}) {
|
|
|
2191
2260
|
: new Tokenizer(createParseInfo(stream, new SourceFile("", [], src.relative))), Object.assign({}, options, {
|
|
2192
2261
|
minify: false,
|
|
2193
2262
|
setParent: false,
|
|
2263
|
+
evaluateMixins: false,
|
|
2194
2264
|
src: src.relative,
|
|
2195
2265
|
}));
|
|
2196
2266
|
let srcIndex = options.resolve(src.absolute, resolvedSrc.absolute).relative;
|
|
@@ -2203,7 +2273,7 @@ async function doParse(iter, options = {}) {
|
|
|
2203
2273
|
if (parentRule !== 0) {
|
|
2204
2274
|
for (const tk of arena.tokens(parentRule)) {
|
|
2205
2275
|
if (arena.dataTypes[tk] === EnumToken.ClassSelectorTokenType) {
|
|
2206
|
-
const val = arena.
|
|
2276
|
+
const val = arena.resolveString(arena.stringValue[tk]).slice(1);
|
|
2207
2277
|
if (val in revMapping) {
|
|
2208
2278
|
const key = revMapping[val];
|
|
2209
2279
|
const values = [];
|
|
@@ -2212,23 +2282,23 @@ async function doParse(iter, options = {}) {
|
|
|
2212
2282
|
arena.dataTypes[iden] !== EnumToken.DashedIdenTokenType) {
|
|
2213
2283
|
continue;
|
|
2214
2284
|
}
|
|
2215
|
-
if (!(arena.
|
|
2285
|
+
if (!(arena.resolveString(arena.stringValue[iden]) in root.mapping)) {
|
|
2216
2286
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2217
|
-
? arena.
|
|
2218
|
-
: moduleSettings.generateScopedName(arena.
|
|
2287
|
+
? arena.resolveString(arena.stringValue[iden])
|
|
2288
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[iden]), srcIndex, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2219
2289
|
let value =
|
|
2220
2290
|
// @ts-expect-error
|
|
2221
2291
|
result instanceof Promise ? await result : result;
|
|
2222
|
-
root.mapping[arena.
|
|
2292
|
+
root.mapping[arena.resolveString(arena.stringValue[iden])] =
|
|
2223
2293
|
moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2224
2294
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2225
2295
|
? getKeyName(value, moduleSettings.naming)
|
|
2226
2296
|
: value;
|
|
2227
|
-
root.revMapping[root.mapping[arena.
|
|
2297
|
+
root.revMapping[root.mapping[arena.resolveString(arena.stringValue[iden])]] = arena.resolveString(arena.stringValue[iden]);
|
|
2228
2298
|
}
|
|
2229
|
-
importMapping[srcIndex][arena.
|
|
2230
|
-
root.mapping[arena.
|
|
2231
|
-
values.push(root.mapping[arena.
|
|
2299
|
+
importMapping[srcIndex][arena.resolveString(arena.stringValue[iden])] =
|
|
2300
|
+
root.mapping[arena.resolveString(arena.stringValue[iden])];
|
|
2301
|
+
values.push(root.mapping[arena.resolveString(arena.stringValue[iden])]);
|
|
2232
2302
|
}
|
|
2233
2303
|
mapping[key] = [...new Set([...mapping[key].split(" "), ...values])].join(" ");
|
|
2234
2304
|
}
|
|
@@ -2240,16 +2310,16 @@ async function doParse(iter, options = {}) {
|
|
|
2240
2310
|
else if (arena.dataTypes[arena.field(token, TokenField.R)] === EnumToken.IdenTokenType) {
|
|
2241
2311
|
// global
|
|
2242
2312
|
if (parentRule !== 0) {
|
|
2243
|
-
if (equalsIgnoreCase("global", arena.
|
|
2313
|
+
if (equalsIgnoreCase("global", arena.resolveString(arena.stringValue[arena.field(token, TokenField.R)]))) {
|
|
2244
2314
|
for (const tk of arena.tokens(parentRule)) {
|
|
2245
2315
|
if (arena.dataTypes[tk] === EnumToken.ClassSelectorTokenType) {
|
|
2246
|
-
const val = arena.
|
|
2316
|
+
const val = arena.resolveString(arena.stringValue[tk]).slice(1);
|
|
2247
2317
|
if (val in revMapping) {
|
|
2248
2318
|
const key = revMapping[val];
|
|
2249
2319
|
const composedNames = [];
|
|
2250
2320
|
for (const curr of arena.fieldTokens(token, TokenField.L)) {
|
|
2251
2321
|
if (arena.dataTypes[curr] === EnumToken.IdenTokenType) {
|
|
2252
|
-
composedNames.push(arena.
|
|
2322
|
+
composedNames.push(arena.resolveString(arena.stringValue[curr]));
|
|
2253
2323
|
}
|
|
2254
2324
|
}
|
|
2255
2325
|
mapping[key] = [
|
|
@@ -2262,7 +2332,7 @@ async function doParse(iter, options = {}) {
|
|
|
2262
2332
|
else {
|
|
2263
2333
|
errors.push({
|
|
2264
2334
|
action: "drop",
|
|
2265
|
-
message: `composes '${arena.
|
|
2335
|
+
message: `composes '${arena.resolveString(arena.stringValue[arena.field(token, TokenField.R)])}' is not supported`,
|
|
2266
2336
|
node,
|
|
2267
2337
|
});
|
|
2268
2338
|
}
|
|
@@ -2281,13 +2351,13 @@ async function doParse(iter, options = {}) {
|
|
|
2281
2351
|
"grid-template",
|
|
2282
2352
|
"grid-template-columns",
|
|
2283
2353
|
"grid-template-rows",
|
|
2284
|
-
].includes(arena.
|
|
2354
|
+
].includes(arena.resolveString(arena.name[node]))) {
|
|
2285
2355
|
// inlined: arena.walkValues(node as AstNode)
|
|
2286
2356
|
for (const value of new ValueWalker(arena, node)) {
|
|
2287
2357
|
if (arena.dataTypes[value] !== EnumToken.IdenTokenType) {
|
|
2288
2358
|
continue;
|
|
2289
2359
|
}
|
|
2290
|
-
let idenToken = arena.
|
|
2360
|
+
let idenToken = arena.resolveString(arena.stringValue[value]);
|
|
2291
2361
|
let suffix = "";
|
|
2292
2362
|
if (idenToken.endsWith("-start")) {
|
|
2293
2363
|
suffix = "-start";
|
|
@@ -2319,30 +2389,30 @@ async function doParse(iter, options = {}) {
|
|
|
2319
2389
|
arena.stringValue[value] = arena.internString(mapping[idenToken]);
|
|
2320
2390
|
}
|
|
2321
2391
|
}
|
|
2322
|
-
else if (arena.
|
|
2323
|
-
arena.
|
|
2392
|
+
else if (arena.resolveString(arena.name[node]) === "grid-template-areas" ||
|
|
2393
|
+
arena.resolveString(arena.name[node]) === "grid-template") {
|
|
2324
2394
|
for (let token = arena.firstToken[node]; token !== 0; token = arena.nextSibling[token]) {
|
|
2325
2395
|
if (arena.dataTypes[token] === EnumToken.StringTokenType) {
|
|
2326
|
-
const str = arena.
|
|
2396
|
+
const str = arena.resolveString(arena.stringValue[token]);
|
|
2327
2397
|
const tokens = parseString(arena, str.slice(1, -1));
|
|
2328
2398
|
// inlined: arena.walkValues(tokens)
|
|
2329
2399
|
for (const value of new ValueWalker(arena, tokens)) {
|
|
2330
2400
|
if (arena.dataTypes[value] === EnumToken.IdenTokenType ||
|
|
2331
2401
|
arena.dataTypes[value] === EnumToken.DashedIdenTokenType) {
|
|
2332
|
-
if (arena.
|
|
2333
|
-
// inlined: arena.setStr(value, mapping[arena.
|
|
2334
|
-
arena.stringValue[value] = arena.internString(mapping[arena.
|
|
2402
|
+
if (arena.resolveString(arena.stringValue[value]) in mapping) {
|
|
2403
|
+
// inlined: arena.setStr(value, mapping[arena.resolveString(arena.stringValue[value])])
|
|
2404
|
+
arena.stringValue[value] = arena.internString(mapping[arena.resolveString(arena.stringValue[value])]);
|
|
2335
2405
|
}
|
|
2336
2406
|
else {
|
|
2337
2407
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2338
|
-
? arena.
|
|
2339
|
-
: moduleSettings.generateScopedName(arena.
|
|
2408
|
+
? arena.resolveString(arena.stringValue[value])
|
|
2409
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[value]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2340
2410
|
// @ts-expect-error
|
|
2341
2411
|
if (result instanceof Promise) {
|
|
2342
2412
|
result = await result;
|
|
2343
2413
|
}
|
|
2344
|
-
mapping[arena.
|
|
2345
|
-
revMapping[result] = arena.
|
|
2414
|
+
mapping[arena.resolveString(arena.stringValue[value])] = result;
|
|
2415
|
+
revMapping[result] = arena.resolveString(arena.stringValue[value]);
|
|
2346
2416
|
// inlined: arena.setStr(value, result)
|
|
2347
2417
|
arena.stringValue[value] = arena.internString(result);
|
|
2348
2418
|
}
|
|
@@ -2353,8 +2423,8 @@ async function doParse(iter, options = {}) {
|
|
|
2353
2423
|
}
|
|
2354
2424
|
}
|
|
2355
2425
|
}
|
|
2356
|
-
else if (arena.
|
|
2357
|
-
arena.
|
|
2426
|
+
else if (arena.resolveString(arena.name[node]) === "animation" ||
|
|
2427
|
+
arena.resolveString(arena.name[node]) === "animation-name") {
|
|
2358
2428
|
// inlined: arena.walkValues(node as AstNode)
|
|
2359
2429
|
for (const value of new ValueWalker(arena, node)) {
|
|
2360
2430
|
if (arena.dataTypes[value] === EnumToken.IdenTokenType &&
|
|
@@ -2386,39 +2456,42 @@ async function doParse(iter, options = {}) {
|
|
|
2386
2456
|
"inherit",
|
|
2387
2457
|
"initial",
|
|
2388
2458
|
"unset",
|
|
2389
|
-
].includes(arena.
|
|
2390
|
-
if (!(arena.
|
|
2459
|
+
].includes(arena.resolveString(arena.stringValue[value]))) {
|
|
2460
|
+
if (!(arena.resolveString(arena.stringValue[value]) in mapping)) {
|
|
2391
2461
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2392
|
-
? arena.
|
|
2393
|
-
: moduleSettings.generateScopedName(arena.
|
|
2394
|
-
mapping[arena.
|
|
2462
|
+
? arena.resolveString(arena.stringValue[value])
|
|
2463
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[value]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2464
|
+
mapping[arena.resolveString(arena.stringValue[value])] =
|
|
2395
2465
|
// @ts-expect-error
|
|
2396
2466
|
result instanceof Promise ? await result : result;
|
|
2397
|
-
revMapping[mapping[arena.
|
|
2398
|
-
arena.
|
|
2467
|
+
revMapping[mapping[arena.resolveString(arena.stringValue[value])]] =
|
|
2468
|
+
arena.resolveString(arena.stringValue[value]);
|
|
2399
2469
|
}
|
|
2400
|
-
// inlined: arena.setStr(value, mapping[arena.
|
|
2401
|
-
arena.stringValue[value] = arena.internString(mapping[arena.
|
|
2470
|
+
// inlined: arena.setStr(value, mapping[arena.resolveString(arena.stringValue[value])])
|
|
2471
|
+
arena.stringValue[value] = arena.internString(mapping[arena.resolveString(arena.stringValue[value])]);
|
|
2402
2472
|
}
|
|
2403
2473
|
}
|
|
2404
2474
|
}
|
|
2405
2475
|
// inlined: arena.walkValues(node as AstNode)
|
|
2406
2476
|
for (const value of new ValueWalker(arena, node)) {
|
|
2407
2477
|
if (arena.dataTypes[value] === EnumToken.DashedIdenTokenType) {
|
|
2408
|
-
|
|
2409
|
-
|
|
2478
|
+
const mapped = mapping[arena.resolveString(arena.stringValue[value])];
|
|
2479
|
+
// a custom property that is not declared is not renamed
|
|
2480
|
+
if (mapped !== undefined) {
|
|
2481
|
+
arena.stringValue[value] = arena.internString(mapped);
|
|
2482
|
+
}
|
|
2410
2483
|
}
|
|
2411
2484
|
else if ((arena.dataTypes[value] === EnumToken.IdenTokenType || isIdentColor(arena, value)) &&
|
|
2412
|
-
arena.
|
|
2485
|
+
arena.resolveString(arena.stringValue[value]) in importedCssVariables) {
|
|
2413
2486
|
arena.replaceToken(value, ...arena
|
|
2414
|
-
.tokens(importedCssVariables[arena.
|
|
2487
|
+
.tokens(importedCssVariables[arena.resolveString(arena.stringValue[value])][ARENAID])
|
|
2415
2488
|
.map((token) => arena.clone(token, true)));
|
|
2416
2489
|
}
|
|
2417
2490
|
}
|
|
2418
2491
|
}
|
|
2419
2492
|
else if (nodeType === EnumToken.RuleNodeType) {
|
|
2420
2493
|
// if (node[TOKENS] == null) {
|
|
2421
|
-
const tokens = parseString(arena, arena.
|
|
2494
|
+
const tokens = parseString(arena, arena.resolveString(arena.name[node]));
|
|
2422
2495
|
matchSelectorSyntax(arena, tokens, [], options);
|
|
2423
2496
|
arena.setTokenList(node, trimArray(arena, tokens));
|
|
2424
2497
|
let hasIdOrClass = false;
|
|
@@ -2426,7 +2499,7 @@ async function doParse(iter, options = {}) {
|
|
|
2426
2499
|
for (const value of new ValueWalker(arena, node, (arena, value) => {
|
|
2427
2500
|
if (arena.dataTypes[value] === EnumToken.PseudoClassTokenType ||
|
|
2428
2501
|
arena.dataTypes[value] === EnumToken.PseudoElementTokenType) {
|
|
2429
|
-
const val = arena.
|
|
2502
|
+
const val = arena.resolveString(arena.stringValue[value]).toLowerCase();
|
|
2430
2503
|
switch (val) {
|
|
2431
2504
|
case ":local":
|
|
2432
2505
|
case ":global":
|
|
@@ -2444,7 +2517,7 @@ async function doParse(iter, options = {}) {
|
|
|
2444
2517
|
}
|
|
2445
2518
|
}
|
|
2446
2519
|
else if (arena.dataTypes[value] === EnumToken.PseudoClassFuncTokenType) {
|
|
2447
|
-
switch (arena.
|
|
2520
|
+
switch (arena.resolveString(arena.stringValue[value]).toLowerCase()) {
|
|
2448
2521
|
case ":global":
|
|
2449
2522
|
for (const token of arena.tokens(value)) {
|
|
2450
2523
|
global.add(token);
|
|
@@ -2475,7 +2548,7 @@ async function doParse(iter, options = {}) {
|
|
|
2475
2548
|
continue;
|
|
2476
2549
|
}
|
|
2477
2550
|
if (arena.dataTypes[value] === EnumToken.ClassSelectorTokenType) {
|
|
2478
|
-
const val = arena.
|
|
2551
|
+
const val = arena.resolveString(arena.stringValue[value]).slice(1);
|
|
2479
2552
|
if (!(val in mapping)) {
|
|
2480
2553
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2481
2554
|
? val
|
|
@@ -2498,7 +2571,7 @@ async function doParse(iter, options = {}) {
|
|
|
2498
2571
|
if (!hasIdOrClass) {
|
|
2499
2572
|
throw new Error(
|
|
2500
2573
|
// inlined: options.source?.getOffsets?.(arena.getSpanStart(node as AstNode))
|
|
2501
|
-
`pure module: No id or class found in selector '${arena.
|
|
2574
|
+
`pure module: No id or class found in selector '${arena.resolveString(arena.name[node])}' at '${(options.source?.lineStarts.getOffsets(arena.getSpanStart(node)) ?? []).join(":")}'`);
|
|
2502
2575
|
}
|
|
2503
2576
|
}
|
|
2504
2577
|
// inlined: arena.setSelector(node as AstNode, arena.tokens(node as AstNode).reduce((acc: string, token: Token) => acc + renderValue(arena, token), ""))
|
|
@@ -2507,33 +2580,33 @@ async function doParse(iter, options = {}) {
|
|
|
2507
2580
|
.reduce((acc, token) => acc + renderValue(arena, token), ""));
|
|
2508
2581
|
}
|
|
2509
2582
|
else if (nodeType === EnumToken.AtRuleNodeType || nodeType === EnumToken.KeyframesAtRuleNodeType) {
|
|
2510
|
-
const val = arena.
|
|
2583
|
+
const val = arena.resolveString(arena.name[node]).toLowerCase();
|
|
2511
2584
|
if (arena.firstToken[node] === 0) {
|
|
2512
|
-
// inlined: arena.setTokens(node as AstNode, ...parseString(arena, arena.
|
|
2513
|
-
arena.setTokenList(node, parseString(arena, arena.
|
|
2585
|
+
// inlined: arena.setTokens(node as AstNode, ...parseString(arena, arena.resolveString(arena.stringValue[node as AstNode])))
|
|
2586
|
+
arena.setTokenList(node, parseString(arena, arena.resolveString(arena.stringValue[node])));
|
|
2514
2587
|
}
|
|
2515
2588
|
if (val === "property" || val === "keyframes") {
|
|
2516
2589
|
const prefix = val === "property" ? "--" : "";
|
|
2517
2590
|
for (const value of arena.tokens(node)) {
|
|
2518
2591
|
if ((prefix === "--" && arena.dataTypes[value] === EnumToken.DashedIdenTokenType) ||
|
|
2519
2592
|
(prefix === "" && arena.dataTypes[value] === EnumToken.IdenTokenType)) {
|
|
2520
|
-
if (!(arena.
|
|
2593
|
+
if (!(arena.resolveString(arena.stringValue[value]) in mapping)) {
|
|
2521
2594
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2522
|
-
? arena.
|
|
2523
|
-
: moduleSettings.generateScopedName(arena.
|
|
2595
|
+
? arena.resolveString(arena.stringValue[value])
|
|
2596
|
+
: moduleSettings.generateScopedName(arena.resolveString(arena.stringValue[value]), moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2524
2597
|
// @ts-expect-error
|
|
2525
2598
|
let val = result instanceof Promise ? await result : result;
|
|
2526
|
-
mapping[arena.
|
|
2599
|
+
mapping[arena.resolveString(arena.stringValue[value])] =
|
|
2527
2600
|
prefix +
|
|
2528
2601
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2529
2602
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2530
2603
|
? getKeyName(val, moduleSettings.naming)
|
|
2531
2604
|
: val);
|
|
2532
|
-
revMapping[mapping[arena.
|
|
2533
|
-
arena.
|
|
2605
|
+
revMapping[mapping[arena.resolveString(arena.stringValue[value])]] =
|
|
2606
|
+
arena.resolveString(arena.stringValue[value]);
|
|
2534
2607
|
}
|
|
2535
|
-
// inlined: arena.setStr(value, mapping[arena.
|
|
2536
|
-
arena.stringValue[value] = arena.internString(mapping[arena.
|
|
2608
|
+
// inlined: arena.setStr(value, mapping[arena.resolveString(arena.stringValue[value])])
|
|
2609
|
+
arena.stringValue[value] = arena.internString(mapping[arena.resolveString(arena.stringValue[value])]);
|
|
2537
2610
|
}
|
|
2538
2611
|
}
|
|
2539
2612
|
// inlined: arena.setValueString(node as AstNode, renderTokens(arena, arena.tokens(node as AstNode)))
|
|
@@ -2541,7 +2614,7 @@ async function doParse(iter, options = {}) {
|
|
|
2541
2614
|
}
|
|
2542
2615
|
}
|
|
2543
2616
|
}
|
|
2544
|
-
if (moduleSettings.naming
|
|
2617
|
+
if ((moduleSettings.naming & ModuleCaseTransformEnum.IgnoreCase) == 0) {
|
|
2545
2618
|
revMapping = {};
|
|
2546
2619
|
mapping = Object.entries(mapping).reduce((acc, [key, value]) => {
|
|
2547
2620
|
const keyName = getKeyName(key, moduleSettings.naming);
|
|
@@ -2623,8 +2696,12 @@ function parseNode(arena, tokens, context, options, errors, stats, invalidNodes,
|
|
|
2623
2696
|
arena.appendChildList(context, [createCommentNode(arena, tokens[k])]);
|
|
2624
2697
|
}
|
|
2625
2698
|
}
|
|
2626
|
-
|
|
2627
|
-
tokens.length
|
|
2699
|
+
// a loop: Array.prototype.copyWithin() is a slow generic builtin for the arrays
|
|
2700
|
+
const length = tokens.length - i;
|
|
2701
|
+
for (let k = 0; k < length; k++) {
|
|
2702
|
+
tokens[k] = tokens[k + i];
|
|
2703
|
+
}
|
|
2704
|
+
tokens.length = length;
|
|
2628
2705
|
i = 0;
|
|
2629
2706
|
}
|
|
2630
2707
|
for (; i < tokens.length; i++) {
|
|
@@ -2745,6 +2822,56 @@ function parseNode(arena, tokens, context, options, errors, stats, invalidNodes,
|
|
|
2745
2822
|
}
|
|
2746
2823
|
return null;
|
|
2747
2824
|
}
|
|
2825
|
+
/**
|
|
2826
|
+
* detach the invalid nodes: the nodes that are not valid, not parsed, malformed or not allowed. the unknown nodes are
|
|
2827
|
+
* kept in lenient mode
|
|
2828
|
+
* @param arena
|
|
2829
|
+
* @param invalidNodes
|
|
2830
|
+
* @param options
|
|
2831
|
+
*/
|
|
2832
|
+
function dropInvalidNodes(arena, invalidNodes, options) {
|
|
2833
|
+
for (const node of invalidNodes) {
|
|
2834
|
+
if (options.lenient && arena.flags[node] & EnumAstNodeStatus.Unknown) {
|
|
2835
|
+
continue;
|
|
2836
|
+
}
|
|
2837
|
+
if (arena.flags[node] &
|
|
2838
|
+
(EnumAstNodeStatus.Invalid |
|
|
2839
|
+
EnumAstNodeStatus.Unknown |
|
|
2840
|
+
EnumAstNodeStatus.Unparsed |
|
|
2841
|
+
EnumAstNodeStatus.Malformed |
|
|
2842
|
+
EnumAstNodeStatus.Disallowed)) {
|
|
2843
|
+
arena.detach(node);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
/**
|
|
2848
|
+
* true if the node is an at-rule whose block is kept when it is empty: `@apply --mixin {}`, `@mixin --name {}`,
|
|
2849
|
+
* `@function --name() {}`
|
|
2850
|
+
* @param arena
|
|
2851
|
+
* @param node
|
|
2852
|
+
*/
|
|
2853
|
+
function isDefinitionBlock(arena, node) {
|
|
2854
|
+
return (arena.dataTypes[node] === EnumToken.AtRuleNodeType &&
|
|
2855
|
+
(arena.stringEquals(arena.name[node], "apply") ||
|
|
2856
|
+
arena.stringEquals(arena.name[node], "mixin") ||
|
|
2857
|
+
arena.stringEquals(arena.name[node], "function")));
|
|
2858
|
+
}
|
|
2859
|
+
/**
|
|
2860
|
+
* true if a mixin can be defined in the node: the stylesheet, or a conditional group rule (`@media`, `@supports`,
|
|
2861
|
+
* `@container`, `@when`, `@else`) or a cascade layer (`@layer`) that is not nested in a style rule
|
|
2862
|
+
* @param arena
|
|
2863
|
+
* @param node
|
|
2864
|
+
*/
|
|
2865
|
+
function isMixinScope(arena, node) {
|
|
2866
|
+
while (node !== 0 && arena.dataTypes[node] !== EnumToken.StyleSheetNodeType) {
|
|
2867
|
+
if (arena.dataTypes[node] !== EnumToken.AtRuleNodeType ||
|
|
2868
|
+
!["media", "supports", "container", "layer", "when", "else"].includes(arena.resolveString(arena.name[node]))) {
|
|
2869
|
+
return false;
|
|
2870
|
+
}
|
|
2871
|
+
node = arena.parents[node];
|
|
2872
|
+
}
|
|
2873
|
+
return true;
|
|
2874
|
+
}
|
|
2748
2875
|
/**
|
|
2749
2876
|
* @param arena
|
|
2750
2877
|
* @param stream
|
|
@@ -2756,10 +2883,10 @@ function parseNode(arena, tokens, context, options, errors, stats, invalidNodes,
|
|
|
2756
2883
|
function parseAtRule(arena, stream, context, options, errors, parseAsBlock = null) {
|
|
2757
2884
|
let success = true;
|
|
2758
2885
|
const contextType = arena.dataTypes[context];
|
|
2759
|
-
const contextName = contextType === EnumToken.AtRuleNodeType ? arena.
|
|
2886
|
+
const contextName = contextType === EnumToken.AtRuleNodeType ? arena.resolveString(arena.name[context]) : null;
|
|
2760
2887
|
const atRule = stream.shift();
|
|
2761
2888
|
// at-rule name
|
|
2762
|
-
const nam = arena.
|
|
2889
|
+
const nam = arena.resolveString(arena.name[atRule]);
|
|
2763
2890
|
let atRuleName = nam;
|
|
2764
2891
|
// prelude tokens, state, errors and last token of the at-rule node
|
|
2765
2892
|
let atRuleTokens = null;
|
|
@@ -2868,7 +2995,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
2868
2995
|
message: "expecting <string>",
|
|
2869
2996
|
});
|
|
2870
2997
|
}
|
|
2871
|
-
if (success && arena.
|
|
2998
|
+
if (success && arena.resolveString(arena.stringValue[stream[1]]).charCodeAt(0) !== 0x22) {
|
|
2872
2999
|
success = false;
|
|
2873
3000
|
errors.push({
|
|
2874
3001
|
action: "drop",
|
|
@@ -3112,8 +3239,8 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3112
3239
|
if (sibling === 0 || arena.dataTypes[sibling] !== EnumToken.AtRuleNodeType) {
|
|
3113
3240
|
missingWhen = true;
|
|
3114
3241
|
}
|
|
3115
|
-
else if (arena.
|
|
3116
|
-
if (arena.
|
|
3242
|
+
else if (arena.resolveString(arena.name[sibling]) !== "when") {
|
|
3243
|
+
if (arena.resolveString(arena.name[sibling]) !== "else") {
|
|
3117
3244
|
missingWhen = true;
|
|
3118
3245
|
}
|
|
3119
3246
|
else if (arena.stringValue[sibling] === 0) {
|
|
@@ -3218,7 +3345,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3218
3345
|
;
|
|
3219
3346
|
if (index < stream.length) {
|
|
3220
3347
|
if (arena.dataTypes[stream[index]] !== EnumToken.IdenTokenType ||
|
|
3221
|
-
"to" !== arena.
|
|
3348
|
+
"to" !== arena.resolveString(arena.stringValue[stream[index]]).toLowerCase()) {
|
|
3222
3349
|
errors.push({
|
|
3223
3350
|
action: "drop",
|
|
3224
3351
|
node: stream[index],
|
|
@@ -3249,7 +3376,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3249
3376
|
success = false;
|
|
3250
3377
|
}
|
|
3251
3378
|
else {
|
|
3252
|
-
context = createValidationContext(arena, stream
|
|
3379
|
+
context = createValidationContext(arena, stream, index);
|
|
3253
3380
|
// @ts-ignore
|
|
3254
3381
|
range = context.peekRange((t) => arena.dataTypes[t] === EnumToken.EndParensTokenType);
|
|
3255
3382
|
// inlined: arena.typeOf(range.at(-1))
|
|
@@ -3355,8 +3482,8 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3355
3482
|
if (arena.dataTypes[stream[index]] === EnumToken.PseudoClassTokenType) {
|
|
3356
3483
|
const colon = arena.createToken(EnumToken.ColonTokenType);
|
|
3357
3484
|
arena.copyLocation(colon, stream[index]);
|
|
3358
|
-
// inlined: arena.setStr(stream[index], arena.
|
|
3359
|
-
arena.stringValue[stream[index]] = arena.internString(arena.
|
|
3485
|
+
// inlined: arena.setStr(stream[index], arena.resolveString(arena.stringValue[stream[index]]).slice(1))
|
|
3486
|
+
arena.stringValue[stream[index]] = arena.internString(arena.resolveString(arena.stringValue[stream[index]]).slice(1));
|
|
3360
3487
|
arena.dataTypes[stream[index]] = EnumToken.IdenTokenType;
|
|
3361
3488
|
stream.splice(index, 0, colon);
|
|
3362
3489
|
isVarDeclaration = true;
|
|
@@ -3367,7 +3494,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3367
3494
|
break;
|
|
3368
3495
|
}
|
|
3369
3496
|
else if (arena.dataTypes[stream[index]] === EnumToken.IdenTokenType &&
|
|
3370
|
-
equalsIgnoreCase("from", arena.
|
|
3497
|
+
equalsIgnoreCase("from", arena.resolveString(arena.stringValue[stream[index]]))) {
|
|
3371
3498
|
break;
|
|
3372
3499
|
}
|
|
3373
3500
|
}
|
|
@@ -3396,7 +3523,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3396
3523
|
// the variable value is stored as the node values
|
|
3397
3524
|
const node = arena.createDeclaration(value.length === 1 && arena.dataTypes[value[0]] === EnumToken.StringTokenType
|
|
3398
3525
|
? EnumToken.CssVariableImportTokenType
|
|
3399
|
-
: EnumToken.CssVariableTokenType, arena.
|
|
3526
|
+
: EnumToken.CssVariableTokenType, arena.stringValue[nam], value, EnumAstNodeStatus.Validated, []);
|
|
3400
3527
|
arena.spanLocation(node, atRule, atRuleEnd);
|
|
3401
3528
|
return node;
|
|
3402
3529
|
}
|
|
@@ -3437,7 +3564,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3437
3564
|
const stack = [];
|
|
3438
3565
|
for (; i < stream.length; i++) {
|
|
3439
3566
|
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType ||
|
|
3440
|
-
|
|
3567
|
+
isFunctionDefType(arena.dataTypes[stream[i]])) {
|
|
3441
3568
|
stack.push(stream[i]);
|
|
3442
3569
|
continue;
|
|
3443
3570
|
}
|
|
@@ -3461,7 +3588,9 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3461
3588
|
atRuleErrors = result.errors;
|
|
3462
3589
|
switch (nam) {
|
|
3463
3590
|
case "mixin":
|
|
3464
|
-
|
|
3591
|
+
// a mixin is defined at the top level of the stylesheet, or in a conditional group rule or a
|
|
3592
|
+
// cascade layer that is not nested in a style rule
|
|
3593
|
+
if (!isMixinScope(arena, context)) {
|
|
3465
3594
|
atRuleState |= EnumAstNodeStatus.Disallowed;
|
|
3466
3595
|
atRuleErrors.push({
|
|
3467
3596
|
action: "drop",
|
|
@@ -3475,11 +3604,12 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3475
3604
|
}
|
|
3476
3605
|
break;
|
|
3477
3606
|
case "contents":
|
|
3607
|
+
case "result":
|
|
3478
3608
|
let parent = context;
|
|
3479
3609
|
let valid = false;
|
|
3480
3610
|
while (parent !== 0) {
|
|
3481
3611
|
if (arena.dataTypes[parent] === EnumToken.AtRuleNodeType &&
|
|
3482
|
-
"mixin" === arena.
|
|
3612
|
+
"mixin" === arena.resolveString(arena.name[parent])) {
|
|
3483
3613
|
valid = true;
|
|
3484
3614
|
break;
|
|
3485
3615
|
}
|
|
@@ -3489,7 +3619,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3489
3619
|
atRuleState |= EnumAstNodeStatus.Disallowed;
|
|
3490
3620
|
atRuleErrors.push({
|
|
3491
3621
|
action: "drop",
|
|
3492
|
-
message:
|
|
3622
|
+
message: `${nam} rule cannot be used outside mixin rule`,
|
|
3493
3623
|
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3494
3624
|
location: [
|
|
3495
3625
|
options.source.file,
|
|
@@ -3503,7 +3633,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3503
3633
|
let parent = context;
|
|
3504
3634
|
while (parent !== 0) {
|
|
3505
3635
|
if (arena.dataTypes[parent] === EnumToken.AtRuleNodeType &&
|
|
3506
|
-
arena.
|
|
3636
|
+
arena.resolveString(arena.name[parent]) === "mixin") {
|
|
3507
3637
|
atRuleState |= EnumAstNodeStatus.Disallowed;
|
|
3508
3638
|
atRuleErrors.push({
|
|
3509
3639
|
action: "drop",
|
|
@@ -3561,6 +3691,42 @@ function parseDeclarations(declaration, arena) {
|
|
|
3561
3691
|
}
|
|
3562
3692
|
return { arena: result.arena, nodes };
|
|
3563
3693
|
}
|
|
3694
|
+
/**
|
|
3695
|
+
* Parse a string as the content of a style rule: declarations, nested rules and at-rules. the nested rules are
|
|
3696
|
+
* relative to the style rule (`&`). the nodes are allocated in the arena and detached, the comments are dropped
|
|
3697
|
+
* @param content
|
|
3698
|
+
* @param arena
|
|
3699
|
+
* @param options parser options: `parseColor`
|
|
3700
|
+
*
|
|
3701
|
+
* @internal
|
|
3702
|
+
*/
|
|
3703
|
+
function parseRuleContent(content, arena, options = {}) {
|
|
3704
|
+
const source = new SourceFile("", [], "");
|
|
3705
|
+
const result = doParseSync(new Tokenizer(createParseInfo(`.x{${content}}`, source)), {
|
|
3706
|
+
setParent: false,
|
|
3707
|
+
minify: false,
|
|
3708
|
+
validation: false,
|
|
3709
|
+
lenient: true,
|
|
3710
|
+
nestingRules: true,
|
|
3711
|
+
expandNestingRules: false,
|
|
3712
|
+
evaluateMixins: false,
|
|
3713
|
+
parseColor: options.parseColor ?? true,
|
|
3714
|
+
arena,
|
|
3715
|
+
source,
|
|
3716
|
+
sourcesMap: new Map([[source.id, source]]),
|
|
3717
|
+
});
|
|
3718
|
+
const rule = arena.firstChild[result.ast];
|
|
3719
|
+
const nodes = [];
|
|
3720
|
+
for (let node = rule === 0 ? 0 : arena.firstChild[rule]; node !== 0;) {
|
|
3721
|
+
const next = arena.nextSibling[node];
|
|
3722
|
+
if (arena.dataTypes[node] !== EnumToken.CommentNodeType) {
|
|
3723
|
+
arena.detach(node);
|
|
3724
|
+
nodes.push(node);
|
|
3725
|
+
}
|
|
3726
|
+
node = next;
|
|
3727
|
+
}
|
|
3728
|
+
return nodes;
|
|
3729
|
+
}
|
|
3564
3730
|
/**
|
|
3565
3731
|
* Parse css string and return an array of tokens
|
|
3566
3732
|
* @param arena
|
|
@@ -3646,9 +3812,9 @@ function parseTokens(arena, tokens, options, errors) {
|
|
|
3646
3812
|
arena.dataTypes[tokens[i - 1]] === EnumToken.DoubleColonTokenType)) {
|
|
3647
3813
|
// merge the colon and the function name into a pseudo class function
|
|
3648
3814
|
const previous = tokens[i - 1];
|
|
3649
|
-
// inlined: arena.setStr(previous, (arena.dataTypes[previous] === EnumToken.ColonTokenType ? ":" : "::") + arena.
|
|
3815
|
+
// inlined: arena.setStr(previous, (arena.dataTypes[previous] === EnumToken.ColonTokenType ? ":" : "::") + arena.resolveString(arena.stringValue[t]))
|
|
3650
3816
|
arena.stringValue[previous] = arena.internString((arena.dataTypes[previous] === EnumToken.ColonTokenType ? ":" : "::") +
|
|
3651
|
-
arena.
|
|
3817
|
+
arena.resolveString(arena.stringValue[t]));
|
|
3652
3818
|
arena.dataTypes[previous] = EnumToken.PseudoClassFunctionTokenDefType;
|
|
3653
3819
|
// inlined: arena.setSpanEnd(previous, arena.getSpanEnd(t))
|
|
3654
3820
|
arena.setSpan(previous, arena.getSourceId(previous), arena.getSpanStart(previous), arena.getSpanEnd(t));
|
|
@@ -3659,14 +3825,14 @@ function parseTokens(arena, tokens, options, errors) {
|
|
|
3659
3825
|
}
|
|
3660
3826
|
if (typ === EnumToken.AttrStartTokenType ||
|
|
3661
3827
|
typ === EnumToken.StartParensTokenType ||
|
|
3662
|
-
|
|
3828
|
+
isFunctionDefType(typ)) {
|
|
3663
3829
|
stack.push(t);
|
|
3664
3830
|
continue;
|
|
3665
3831
|
}
|
|
3666
3832
|
if (typ === EnumToken.EndParensTokenType) {
|
|
3667
3833
|
if (stack.length === 0 ||
|
|
3668
3834
|
(arena.dataTypes[stack[stack.length - 1]] !== EnumToken.StartParensTokenType &&
|
|
3669
|
-
!
|
|
3835
|
+
!isFunctionDefType(arena.dataTypes[stack[stack.length - 1]]))) {
|
|
3670
3836
|
// unbalanced parens
|
|
3671
3837
|
const node = stack[stack.length - 1];
|
|
3672
3838
|
errors?.push?.({
|
|
@@ -3727,7 +3893,7 @@ function parseTokens(arena, tokens, options, errors) {
|
|
|
3727
3893
|
continue;
|
|
3728
3894
|
}
|
|
3729
3895
|
if (typ === EnumToken.IdenTokenType) {
|
|
3730
|
-
if (arena.
|
|
3896
|
+
if (arena.resolveString(arena.stringValue[t]) === "from" && i > 0) {
|
|
3731
3897
|
const left = [];
|
|
3732
3898
|
const right = [];
|
|
3733
3899
|
let foundLeft = 0;
|
|
@@ -3815,8 +3981,8 @@ function parseTokens(arena, tokens, options, errors) {
|
|
|
3815
3981
|
arena.dataTypes[tokens[i + 1]] = EnumToken.PseudoClassFuncTokenType;
|
|
3816
3982
|
}
|
|
3817
3983
|
else if (next === EnumToken.IdenTokenType) {
|
|
3818
|
-
// inlined: arena.setStr(tokens[i + 1], ":" + arena.
|
|
3819
|
-
arena.stringValue[tokens[i + 1]] = arena.internString(":" + arena.
|
|
3984
|
+
// inlined: arena.setStr(tokens[i + 1], ":" + arena.resolveString(arena.stringValue[tokens[i + 1]]))
|
|
3985
|
+
arena.stringValue[tokens[i + 1]] = arena.internString(":" + arena.resolveString(arena.stringValue[tokens[i + 1]]));
|
|
3820
3986
|
arena.dataTypes[tokens[i + 1]] = EnumToken.PseudoClassTokenType;
|
|
3821
3987
|
}
|
|
3822
3988
|
if (next === EnumToken.FunctionTokenType || next === EnumToken.IdenTokenType) {
|
|
@@ -3848,4 +4014,4 @@ function parseTokens(arena, tokens, options, errors) {
|
|
|
3848
4014
|
return tokens;
|
|
3849
4015
|
}
|
|
3850
4016
|
|
|
3851
|
-
export { doParse, doParseSync, generateScopedName, generateSyncScopedName, getKeyName, getShortNameGenerator, parseAtRule, parseDeclarations, parseString, parseTokens, trimWhiteSpace };
|
|
4017
|
+
export { doParse, doParseSync, generateScopedName, generateSyncScopedName, getKeyName, getShortNameGenerator, isDefinitionBlock, parseAtRule, parseDeclarations, parseRuleContent, parseString, parseTokens, trimWhiteSpace };
|