@tbela99/css-parser 1.8.2 → 2.0.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 +62 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27383 -24083
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/fingerprint.js +333 -0
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1658
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35870
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
|
|
9
9
|
import { camelize, equalsIgnoreCase, dasherize } from './utils/text.js';
|
|
10
10
|
import { renderValue } from '../printer/render.js';
|
|
11
|
-
import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions } from '../ast/types.js';
|
|
11
|
+
import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent } from '../ast/types.js';
|
|
12
12
|
import { minify } from '../ast/minify.js';
|
|
13
|
-
import { expand } from '../ast/expand.js';
|
|
14
|
-
import { walk, walkValues, WalkerEvent } from '../ast/walk.js';
|
|
15
13
|
import { Tokenizer } from './tokenize.js';
|
|
16
|
-
import {
|
|
14
|
+
import { AstArena, TokenField } from '../ast/arena.js';
|
|
15
|
+
import { AstArenaNode, ARENAID } from '../ast/arena-node.js';
|
|
16
|
+
import { tokensfuncDefMap, pageMarginBoxType } from '../syntax/constants.js';
|
|
17
17
|
import { hashAlgorithms, hash, syncHash } from './utils/hash.js';
|
|
18
18
|
import { parseSelector } from './utils/selector.js';
|
|
19
19
|
import { parseDeclaration } from './utils/declaration.js';
|
|
@@ -23,7 +23,7 @@ import { ValidationSyntaxGroupEnum } from '../validation/parser/typedef.js';
|
|
|
23
23
|
import { matchAtRuleImportSyntax } from './utils/at-rule-import.js';
|
|
24
24
|
import { matchAtRuleWhenElseSyntax } from './utils/at-rule-when-else.js';
|
|
25
25
|
import { parseAtRuleSupportSyntax } from './utils/at-rule-support.js';
|
|
26
|
-
import {
|
|
26
|
+
import { trimWhiteSpaceTokens } from './utils/token.js';
|
|
27
27
|
import { parseAtRuleContainerQueryList } from './utils/at-rule-container.js';
|
|
28
28
|
import { parseMediaqueryList } from './utils/at-rule-media.js';
|
|
29
29
|
import { matchAtRuleSyntax } from './utils/at-rule.js';
|
|
@@ -32,13 +32,146 @@ import { matchGenericSyntax } from './utils/at-rule-generic.js';
|
|
|
32
32
|
import { memoize } from './utils/cache.js';
|
|
33
33
|
import { SourceFile } from './source.js';
|
|
34
34
|
import { dirname } from '../fs/resolve.js';
|
|
35
|
+
import { NodeWalker, ValueWalker } from '../ast/walk.js';
|
|
35
36
|
|
|
36
|
-
function renderTokens(tokens, options) {
|
|
37
|
+
function renderTokens(arena, tokens, options) {
|
|
37
38
|
if (tokens == null || tokens.length === 0)
|
|
38
39
|
return "";
|
|
39
40
|
if (options != null)
|
|
40
|
-
return tokens.map((t) => renderValue(t, options)).join("");
|
|
41
|
-
return tokens.map((t) => renderValue(t)).join("");
|
|
41
|
+
return tokens.map((t) => renderValue(arena, t, options)).join("");
|
|
42
|
+
return tokens.map((t) => renderValue(arena, t)).join("");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* allocate an at-rule node from an at-rule token
|
|
46
|
+
* @param arena
|
|
47
|
+
* @param atRule at-rule token: name and location
|
|
48
|
+
* @param typ
|
|
49
|
+
* @param tokens prelude tokens
|
|
50
|
+
* @param state
|
|
51
|
+
* @param errors
|
|
52
|
+
* @param end last token of the at-rule
|
|
53
|
+
* @param val
|
|
54
|
+
* @param block
|
|
55
|
+
*/
|
|
56
|
+
function createAtRuleNode(arena, atRule, typ, tokens, state, errors, end, val, block) {
|
|
57
|
+
const node = arena.createAtRule(typ, arena.strings[arena.name[atRule]], val, block, tokens, state, errors);
|
|
58
|
+
arena.spanLocation(node, atRule, end);
|
|
59
|
+
return node;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* convert a visitor result to node ids. the object views of the arena ({@link AstArenaNode}) are not copied, the views
|
|
63
|
+
* of another arena are imported, plain objects are allocated in the arena
|
|
64
|
+
* @param arena
|
|
65
|
+
* @param replacement
|
|
66
|
+
*/
|
|
67
|
+
function visitorResult(arena, replacement) {
|
|
68
|
+
if (Array.isArray(replacement)) {
|
|
69
|
+
const result = [];
|
|
70
|
+
for (const item of replacement) {
|
|
71
|
+
if (typeof item == "number") {
|
|
72
|
+
result.push(item);
|
|
73
|
+
}
|
|
74
|
+
else if (item != null && typeof item == "object") {
|
|
75
|
+
result.push(arena.fromObject(item));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
if (typeof replacement == "number") {
|
|
84
|
+
return replacement;
|
|
85
|
+
}
|
|
86
|
+
if (replacement != null && typeof replacement == "object") {
|
|
87
|
+
return arena.fromObject(replacement);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* allocate a comment node from a comment token
|
|
93
|
+
* @param arena
|
|
94
|
+
* @param token
|
|
95
|
+
*/
|
|
96
|
+
function createCommentNode(arena, token) {
|
|
97
|
+
const node = arena.createComment(arena.dataTypes[token], arena.strings[arena.stringValue[token]]);
|
|
98
|
+
arena.copyLocation(node, token);
|
|
99
|
+
return node;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* initial arena capacity: one node for every 4 bytes of css. the statement tokens that are not attached to the tree
|
|
103
|
+
* are recycled, so a parse + minify allocates 0.07 to 0.22 node per byte (up to 0.5 for keyframes heavy stylesheets
|
|
104
|
+
* or when nesting rules are expanded): the arena seldom grows. the length of a stream is unknown: 4096 nodes
|
|
105
|
+
* @param tokenizer
|
|
106
|
+
*/
|
|
107
|
+
function arenaCapacity(tokenizer) {
|
|
108
|
+
const length = tokenizer.streamLength;
|
|
109
|
+
// small inputs (css modules, inline styles, ...) do not allocate a large arena, the arena grows when needed
|
|
110
|
+
return length == 0 ? 4096 : Math.min(1 << 25, Math.ceil(length / 4) + 1024);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* allocate the current tokenizer token in the arena
|
|
114
|
+
* @param arena
|
|
115
|
+
* @param tokenizer
|
|
116
|
+
* @param sourceIndex index of the source in the arena sources table. negative when the token has no location
|
|
117
|
+
*/
|
|
118
|
+
function allocateToken(arena, tokenizer, sourceIndex) {
|
|
119
|
+
const item = arena.allocate();
|
|
120
|
+
const val = tokenizer.val;
|
|
121
|
+
arena.dataTypes[item] = tokenizer.typ;
|
|
122
|
+
if (tokenizer.unit != null) {
|
|
123
|
+
arena.numericValue[item] = val;
|
|
124
|
+
arena.unit[item] = arena.internString(tokenizer.unit);
|
|
125
|
+
}
|
|
126
|
+
else if (tokenizer.nam != null) {
|
|
127
|
+
arena.name[item] = arena.internString(tokenizer.nam);
|
|
128
|
+
}
|
|
129
|
+
else if (val !== null) {
|
|
130
|
+
if (typeof val == "number") {
|
|
131
|
+
arena.numericValue[item] = val;
|
|
132
|
+
}
|
|
133
|
+
else if (tokenizer.typ != EnumToken.WhitespaceTokenType) {
|
|
134
|
+
// whitespace is always rendered as a single space: the text is not kept
|
|
135
|
+
arena.stringValue[item] = arena.internString(val);
|
|
136
|
+
}
|
|
137
|
+
if (tokenizer.kin != null) {
|
|
138
|
+
// inlined: arena.setColorType(item, tokenizer.kin)
|
|
139
|
+
arena.colorType[item] = tokenizer.kin;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (sourceIndex >= 0) {
|
|
143
|
+
arena.setTokenLocation(item, sourceIndex, tokenizer.sta, tokenizer.end);
|
|
144
|
+
}
|
|
145
|
+
return item;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* recycle the tokens of a statement that were not attached to the tree: their ids are reused by the next allocations.
|
|
149
|
+
* the tokens referenced by the errors or the invalid nodes of the statement are kept
|
|
150
|
+
* @param arena
|
|
151
|
+
* @param tokens statement tokens
|
|
152
|
+
* @param errors
|
|
153
|
+
* @param errorStart index of the first error of the statement
|
|
154
|
+
* @param invalidNodes
|
|
155
|
+
* @param invalidStart index of the first invalid node of the statement
|
|
156
|
+
*/
|
|
157
|
+
function recycleStatementTokens(arena, tokens, errors, errorStart, invalidNodes, invalidStart) {
|
|
158
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
159
|
+
const token = tokens[i];
|
|
160
|
+
// already recycled (a token can be recorded twice), attached or holding other tokens
|
|
161
|
+
if (arena.dataTypes[token] == 0 ||
|
|
162
|
+
arena.parents[token] != 0 ||
|
|
163
|
+
arena.firstChild[token] != 0 ||
|
|
164
|
+
arena.firstToken[token] != 0) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
let referenced = invalidNodes.indexOf(token, invalidStart) != -1;
|
|
168
|
+
for (let j = errorStart; !referenced && j < errors.length; j++) {
|
|
169
|
+
referenced = errors[j].node === token;
|
|
170
|
+
}
|
|
171
|
+
if (!referenced) {
|
|
172
|
+
arena.recycle(token);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
42
175
|
}
|
|
43
176
|
const trimWhiteSpace = [
|
|
44
177
|
EnumToken.CommentTokenType,
|
|
@@ -48,12 +181,16 @@ const trimWhiteSpace = [
|
|
|
48
181
|
EnumToken.LteTokenType,
|
|
49
182
|
EnumToken.ColumnCombinatorTokenType,
|
|
50
183
|
];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
184
|
+
/**
|
|
185
|
+
* bad comment, cdo, url or string token
|
|
186
|
+
* @param type
|
|
187
|
+
*/
|
|
188
|
+
function isBadToken(type) {
|
|
189
|
+
return (type == EnumToken.BadCommentTokenType ||
|
|
190
|
+
type == EnumToken.BadCdoTokenType ||
|
|
191
|
+
type == EnumToken.BadUrlTokenType ||
|
|
192
|
+
type == EnumToken.BadStringTokenType);
|
|
193
|
+
}
|
|
57
194
|
let keyNameCounter = 0;
|
|
58
195
|
/**
|
|
59
196
|
* Short-scoped name generator.
|
|
@@ -327,6 +464,13 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
327
464
|
if (typeof value == "function") {
|
|
328
465
|
key = value.name;
|
|
329
466
|
}
|
|
467
|
+
else if (value != null && typeof value == "object") {
|
|
468
|
+
// array of visitor maps: flatten. this used to depend on the array index being an EnumToken value
|
|
469
|
+
for (const val of Object.entries(value)) {
|
|
470
|
+
visitors.push(val);
|
|
471
|
+
}
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
330
474
|
}
|
|
331
475
|
if (key in EnumToken) {
|
|
332
476
|
if (typeof value == "function") {
|
|
@@ -497,9 +641,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
497
641
|
lenient: true,
|
|
498
642
|
...options,
|
|
499
643
|
};
|
|
500
|
-
|
|
501
|
-
options.validation = !!options.validation;
|
|
502
|
-
}
|
|
644
|
+
options.validation = !!options.validation;
|
|
503
645
|
if (options.module) {
|
|
504
646
|
options.expandNestingRules = true;
|
|
505
647
|
}
|
|
@@ -523,10 +665,14 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
523
665
|
imports: [],
|
|
524
666
|
};
|
|
525
667
|
const invalidNodes = [];
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
668
|
+
// first error / invalid node of the current statement
|
|
669
|
+
let errorStart = errors.length;
|
|
670
|
+
let invalidStart = 0;
|
|
671
|
+
// tokens allocated for the current statement (parseNode() may remove tokens from the statement array)
|
|
672
|
+
const statement = [];
|
|
673
|
+
// nested parses share the arena of the parent
|
|
674
|
+
const arena = options.arena ?? (options.arena = new AstArena(arenaCapacity(tokenizer)));
|
|
675
|
+
let ast = arena.current == 1 ? arena.root : arena.createStyleSheet();
|
|
530
676
|
let tokens = [];
|
|
531
677
|
let context = ast;
|
|
532
678
|
let item;
|
|
@@ -534,160 +680,114 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
534
680
|
// @ts-ignore ignore error
|
|
535
681
|
let parensMatch = 0;
|
|
536
682
|
let curlyBracketMatch = 0;
|
|
537
|
-
|
|
538
|
-
ast
|
|
539
|
-
|
|
683
|
+
// tokens are located in the tokenizer source (the imported file when parsing an @import)
|
|
684
|
+
arena.setLocation(ast, tokenizer.sourceId, 0, 0);
|
|
685
|
+
const sourceIndex = arena.sourceIndex(tokenizer.sourceId);
|
|
686
|
+
let itemType;
|
|
687
|
+
// inlined: tokenizer.done()
|
|
688
|
+
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
540
689
|
tokenizer.next();
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
typ: tokenizer.typ,
|
|
544
|
-
val: tokenizer.val,
|
|
545
|
-
unit: tokenizer.unit,
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
else if (tokenizer.nam != null) {
|
|
549
|
-
item = {
|
|
550
|
-
typ: tokenizer.typ,
|
|
551
|
-
nam: tokenizer.nam,
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
else if (tokenizer.val === null) {
|
|
555
|
-
item = {
|
|
556
|
-
typ: tokenizer.typ,
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
else if (tokenizer.kin != null) {
|
|
560
|
-
item = {
|
|
561
|
-
typ: tokenizer.typ,
|
|
562
|
-
val: tokenizer.val,
|
|
563
|
-
kin: tokenizer.kin,
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
item = {
|
|
568
|
-
typ: tokenizer.typ,
|
|
569
|
-
val: tokenizer.val,
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
item[LOCSRCID] = tokenizer.srcId;
|
|
573
|
-
item[LOCSTA] = tokenizer.sta;
|
|
574
|
-
item[LOCEND] = tokenizer.end;
|
|
690
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
691
|
+
itemType = tokenizer.typ;
|
|
575
692
|
stats.bytesIn = tokenizer.bytesIn;
|
|
576
693
|
stats.tokensCount++;
|
|
577
|
-
if (
|
|
694
|
+
if (isBadToken(itemType)) {
|
|
578
695
|
tokens.push(item);
|
|
696
|
+
statement.push(item);
|
|
579
697
|
errors.push({
|
|
580
698
|
action: "drop",
|
|
581
699
|
message: "Bad token",
|
|
582
700
|
syntax: null,
|
|
583
701
|
node: item,
|
|
584
|
-
|
|
702
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(item))
|
|
703
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(item))],
|
|
585
704
|
});
|
|
586
705
|
// bad token
|
|
587
706
|
continue;
|
|
588
707
|
}
|
|
589
|
-
if (
|
|
708
|
+
if (itemType === EnumToken.StartParensTokenType || tokensfuncDefMap.has(itemType)) {
|
|
590
709
|
parensMatch++;
|
|
591
710
|
}
|
|
592
|
-
else if (
|
|
711
|
+
else if (itemType === EnumToken.EndParensTokenType && parensMatch > 0) {
|
|
593
712
|
parensMatch--;
|
|
594
713
|
}
|
|
595
|
-
if (
|
|
714
|
+
if (itemType === EnumToken.BlockStartTokenType) {
|
|
596
715
|
curlyBracketMatch++;
|
|
597
716
|
}
|
|
598
|
-
else if (
|
|
717
|
+
else if (itemType === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
|
|
599
718
|
curlyBracketMatch--;
|
|
600
719
|
}
|
|
601
720
|
tokens.push(item);
|
|
721
|
+
statement.push(item);
|
|
602
722
|
if (parensMatch === 0 &&
|
|
603
|
-
(
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
723
|
+
(itemType === EnumToken.SemiColonTokenType ||
|
|
724
|
+
itemType === EnumToken.BlockStartTokenType ||
|
|
725
|
+
itemType === EnumToken.EOFTokenType)) {
|
|
726
|
+
node = parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
607
727
|
if (node != null) {
|
|
608
|
-
if (
|
|
728
|
+
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
609
729
|
stack.push(node);
|
|
610
730
|
context = node;
|
|
611
731
|
}
|
|
612
732
|
}
|
|
613
|
-
else if (
|
|
733
|
+
else if (itemType == EnumToken.BlockStartTokenType) {
|
|
614
734
|
let inBlock = 1;
|
|
615
735
|
tokens.length = 0;
|
|
616
736
|
tokens.push(item);
|
|
617
737
|
do {
|
|
618
738
|
tokenizer.next();
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
typ: tokenizer.typ,
|
|
622
|
-
val: tokenizer.val,
|
|
623
|
-
unit: tokenizer.unit,
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
else if (tokenizer.nam != null) {
|
|
627
|
-
item = {
|
|
628
|
-
typ: tokenizer.typ,
|
|
629
|
-
nam: tokenizer.nam,
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
else if (tokenizer.val === null) {
|
|
633
|
-
item = {
|
|
634
|
-
typ: tokenizer.typ,
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
else if (tokenizer.kin != null) {
|
|
638
|
-
item = {
|
|
639
|
-
typ: tokenizer.typ,
|
|
640
|
-
val: tokenizer.val,
|
|
641
|
-
kin: tokenizer.kin,
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
item = {
|
|
646
|
-
typ: tokenizer.typ,
|
|
647
|
-
val: tokenizer.val,
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
item[LOCSRCID] = tokenizer.srcId;
|
|
651
|
-
item[LOCSTA] = tokenizer.sta;
|
|
652
|
-
item[LOCEND] = tokenizer.end;
|
|
739
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
740
|
+
itemType = tokenizer.typ;
|
|
653
741
|
tokens.push(item);
|
|
654
|
-
|
|
742
|
+
statement.push(item);
|
|
743
|
+
if (itemType === EnumToken.BlockStartTokenType) {
|
|
655
744
|
inBlock++;
|
|
656
745
|
}
|
|
657
|
-
else if (
|
|
746
|
+
else if (itemType === EnumToken.BlockEndTokenType) {
|
|
658
747
|
inBlock--;
|
|
659
748
|
}
|
|
660
|
-
|
|
749
|
+
// inlined: tokenizer.done()
|
|
750
|
+
} while (inBlock != 0 && !(tokenizer.typ === EnumToken.EOF));
|
|
661
751
|
if (tokens.length > 0) {
|
|
662
752
|
errors.push({
|
|
663
753
|
action: "drop",
|
|
664
754
|
message: "invalid block",
|
|
665
|
-
|
|
755
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[0]))
|
|
756
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[0]))],
|
|
666
757
|
});
|
|
667
758
|
}
|
|
668
759
|
}
|
|
760
|
+
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
761
|
+
statement.length = 0;
|
|
669
762
|
tokens.length = 0;
|
|
763
|
+
errorStart = errors.length;
|
|
764
|
+
invalidStart = invalidNodes.length;
|
|
670
765
|
}
|
|
671
|
-
else if ((parensMatch === 0 || curlyBracketMatch === 0) &&
|
|
672
|
-
parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
673
|
-
context
|
|
766
|
+
else if ((parensMatch === 0 || curlyBracketMatch === 0) && itemType === EnumToken.BlockEndTokenType) {
|
|
767
|
+
parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
768
|
+
// inlined: arena.setSpanEnd(context, arena.getSpanEnd(item))
|
|
769
|
+
arena.setSpan(context, arena.getSourceId(context), arena.getSpanStart(context), arena.getSpanEnd(item));
|
|
674
770
|
const previousNode = stack.pop();
|
|
675
|
-
context =
|
|
771
|
+
context = stack[stack.length - 1] ?? ast;
|
|
676
772
|
if (options.removeEmpty &&
|
|
677
773
|
previousNode != null &&
|
|
678
|
-
previousNode
|
|
679
|
-
|
|
680
|
-
|
|
774
|
+
arena.firstChild[previousNode] == 0 &&
|
|
775
|
+
arena.lastChild[context] == previousNode) {
|
|
776
|
+
arena.detach(previousNode);
|
|
681
777
|
}
|
|
778
|
+
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
779
|
+
statement.length = 0;
|
|
682
780
|
tokens.length = 0;
|
|
781
|
+
errorStart = errors.length;
|
|
782
|
+
invalidStart = invalidNodes.length;
|
|
683
783
|
parensMatch = 0;
|
|
684
784
|
curlyBracketMatch = 0;
|
|
685
785
|
}
|
|
686
786
|
}
|
|
687
787
|
if (tokens.length > 0) {
|
|
688
|
-
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
788
|
+
node = parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
689
789
|
if (node != null) {
|
|
690
|
-
if (
|
|
790
|
+
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
691
791
|
stack.push(node);
|
|
692
792
|
context = node;
|
|
693
793
|
}
|
|
@@ -695,238 +795,57 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
695
795
|
}
|
|
696
796
|
const endParseTime = performance.now();
|
|
697
797
|
if (options.expandNestingRules) {
|
|
698
|
-
ast = expand(ast);
|
|
798
|
+
ast = arena.expand(ast);
|
|
699
799
|
}
|
|
700
800
|
let replacement;
|
|
701
801
|
if (options.visitor != null) {
|
|
702
802
|
const handlers = [];
|
|
703
803
|
const visitors = parseVisitors(options.visitor, errors);
|
|
704
|
-
let parens;
|
|
705
804
|
let genericKey;
|
|
706
805
|
let nodes = [ast];
|
|
707
806
|
let node;
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
case EnumToken.KeyframesRuleNodeType:
|
|
715
|
-
case EnumToken.KeyframesAtRuleNodeType:
|
|
716
|
-
for (let i =
|
|
717
|
-
// @ts-ignore
|
|
718
|
-
node[TOKENS].length -
|
|
719
|
-
1; i >= 0; i--) {
|
|
720
|
-
// @ts-ignore
|
|
721
|
-
node[TOKENS][i][PARENT] =
|
|
722
|
-
node;
|
|
723
|
-
nodes.push(
|
|
724
|
-
// @ts-ignore
|
|
725
|
-
node[TOKENS][i]);
|
|
726
|
-
}
|
|
727
|
-
break;
|
|
728
|
-
case EnumToken.DeclarationNodeType:
|
|
729
|
-
for (let i =
|
|
730
|
-
// @ts-ignore
|
|
731
|
-
node.val.length - 1; i >= 0; i--) {
|
|
732
|
-
node.val[i][PARENT] = node;
|
|
733
|
-
// @ts-ignore
|
|
734
|
-
nodes.push(node.val[i]);
|
|
735
|
-
}
|
|
736
|
-
break;
|
|
807
|
+
let nodeType;
|
|
808
|
+
// push the children of a node or the sub tokens of a value token onto the stack
|
|
809
|
+
const enqueue = (node) => {
|
|
810
|
+
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
811
|
+
for (let child = arena.lastChild[node]; child != 0; child = arena.previousSibling[child]) {
|
|
812
|
+
nodes.push(child);
|
|
737
813
|
}
|
|
738
|
-
// @ts-ignore
|
|
739
|
-
// if (node.l != null) {
|
|
740
|
-
// // @ts-ignore
|
|
741
|
-
// if (node.op2 != null) {
|
|
742
|
-
// // @ts-ignore
|
|
743
|
-
// nodes.push(node.op2);
|
|
744
|
-
// // @ts-ignore
|
|
745
|
-
// node.op2[PARENT] = node;
|
|
746
|
-
// }
|
|
747
|
-
// // @ts-ignore
|
|
748
|
-
// if (node.op1 != null) {
|
|
749
|
-
// // @ts-ignore
|
|
750
|
-
// nodes.push(node.op1);
|
|
751
|
-
// // @ts-ignore
|
|
752
|
-
// node.op1[PARENT] = node;
|
|
753
|
-
// }
|
|
754
|
-
// // @ts-ignore
|
|
755
|
-
// if (nodes.op != null && node.op.typ != null) {
|
|
756
|
-
// // @ts-ignore
|
|
757
|
-
// nodes.push(node.op);
|
|
758
|
-
// // @ts-ignore
|
|
759
|
-
// node.op[PARENT] = node;
|
|
760
|
-
// }
|
|
761
|
-
// // @ts-ignore
|
|
762
|
-
// if (node.r != null) {
|
|
763
|
-
// // @ts-ignore
|
|
764
|
-
// if (Array.isArray(node.r)) {
|
|
765
|
-
// // @ts-ignore
|
|
766
|
-
// for (let i = node.r.length - 1; i >= 0; i--) {
|
|
767
|
-
// // @ts-ignore
|
|
768
|
-
// nodes.push(node.r[i]);
|
|
769
|
-
// // @ts-ignore
|
|
770
|
-
// node.r[i][PARENT] = node;
|
|
771
|
-
// }
|
|
772
|
-
// } else {
|
|
773
|
-
// // @ts-ignore
|
|
774
|
-
// nodes.push(node.r);
|
|
775
|
-
// // @ts-ignore
|
|
776
|
-
// node.r[PARENT] = node;
|
|
777
|
-
// }
|
|
778
|
-
// }
|
|
779
|
-
// // @ts-ignore
|
|
780
|
-
// if (Array.isArray(node.l)) {
|
|
781
|
-
// // @ts-ignore
|
|
782
|
-
// for (let i = node.l.length - 1; i >= 0; i--) {
|
|
783
|
-
// // @ts-ignore
|
|
784
|
-
// nodes.push(node.l[i]);
|
|
785
|
-
// // @ts-ignore
|
|
786
|
-
// node.l[i][PARENT] = node;
|
|
787
|
-
// }
|
|
788
|
-
// } else {
|
|
789
|
-
// // @ts-ignore
|
|
790
|
-
// nodes.push(node.l);
|
|
791
|
-
// // @ts-ignore
|
|
792
|
-
// node.l[PARENT] = node;
|
|
793
|
-
// }
|
|
794
|
-
// }
|
|
795
|
-
}
|
|
796
|
-
switch (node.typ) {
|
|
797
|
-
case EnumToken.BinaryExpressionTokenType:
|
|
798
|
-
case EnumToken.IfElseConditionTokenType:
|
|
799
|
-
nodes.push(node.r);
|
|
800
|
-
node.r[PARENT] = node;
|
|
801
|
-
nodes.push(node.l);
|
|
802
|
-
node.l[PARENT] = node;
|
|
803
|
-
break;
|
|
804
|
-
case EnumToken.MatchExpressionTokenType:
|
|
805
|
-
nodes.push(node.r);
|
|
806
|
-
node.r[PARENT] = node;
|
|
807
|
-
nodes.push(node.op);
|
|
808
|
-
node.op[PARENT] = node;
|
|
809
|
-
nodes.push(node.l);
|
|
810
|
-
node.l[PARENT] = node;
|
|
811
|
-
break;
|
|
812
|
-
case EnumToken.SupportsQueryConditionTokenType:
|
|
813
|
-
case EnumToken.MediaQueryConditionTokenType:
|
|
814
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
815
|
-
const element = node.r[i];
|
|
816
|
-
nodes.push(element);
|
|
817
|
-
element[PARENT] = node;
|
|
818
|
-
}
|
|
819
|
-
nodes.push(node.op);
|
|
820
|
-
node.op[PARENT] = node;
|
|
821
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
822
|
-
const element = node.l[i];
|
|
823
|
-
nodes.push(element);
|
|
824
|
-
element[PARENT] = node;
|
|
825
|
-
}
|
|
826
|
-
break;
|
|
827
|
-
case EnumToken.WhenElseQueryConditionTokenType:
|
|
828
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
829
|
-
const element = node.r[i];
|
|
830
|
-
nodes.push(element);
|
|
831
|
-
element[PARENT] = node;
|
|
832
|
-
}
|
|
833
|
-
nodes.push(node.l);
|
|
834
|
-
node.l[PARENT] = node;
|
|
835
|
-
break;
|
|
836
|
-
case EnumToken.IfConditionTokenType:
|
|
837
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
838
|
-
const element = node.r[i];
|
|
839
|
-
nodes.push(element);
|
|
840
|
-
element[PARENT] = node;
|
|
841
|
-
}
|
|
842
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
843
|
-
const element = node.l[i];
|
|
844
|
-
nodes.push(element);
|
|
845
|
-
element[PARENT] = node;
|
|
846
|
-
}
|
|
847
|
-
break;
|
|
848
|
-
case EnumToken.ComposesSelectorNodeType:
|
|
849
|
-
if (node.r != null) {
|
|
850
|
-
nodes.push(node.r);
|
|
851
|
-
node.r[PARENT] = node;
|
|
852
|
-
}
|
|
853
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
854
|
-
const element = node.l[i];
|
|
855
|
-
nodes.push(element);
|
|
856
|
-
element[PARENT] = node;
|
|
857
|
-
}
|
|
858
|
-
break;
|
|
859
|
-
case EnumToken.ContainerStyleRangeTokenType:
|
|
860
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
861
|
-
const element = node.r[i];
|
|
862
|
-
nodes.push(element);
|
|
863
|
-
element[PARENT] = node;
|
|
864
|
-
}
|
|
865
|
-
for (let i = node.op.length - 1; i >= 0; i--) {
|
|
866
|
-
const element = node.op[i];
|
|
867
|
-
nodes.push(element);
|
|
868
|
-
element[PARENT] = node;
|
|
869
|
-
}
|
|
870
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
871
|
-
const element = node.l[i];
|
|
872
|
-
nodes.push(element);
|
|
873
|
-
element[PARENT] = node;
|
|
874
|
-
}
|
|
875
|
-
break;
|
|
876
|
-
case EnumToken.MediaRangeQueryTokenType:
|
|
877
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
878
|
-
const element = node.r[i];
|
|
879
|
-
nodes.push(element);
|
|
880
|
-
element[PARENT] = node;
|
|
881
|
-
}
|
|
882
|
-
nodes.push(node.op2);
|
|
883
|
-
node.op2[PARENT] = node;
|
|
884
|
-
for (let i = node.val.length - 1; i >= 0; i--) {
|
|
885
|
-
const element = node.val[i];
|
|
886
|
-
nodes.push(element);
|
|
887
|
-
element[PARENT] = node;
|
|
888
|
-
}
|
|
889
|
-
nodes.push(node.op1);
|
|
890
|
-
node.op1[PARENT] = node;
|
|
891
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
892
|
-
const element = node.l[i];
|
|
893
|
-
nodes.push(element);
|
|
894
|
-
element[PARENT] = node;
|
|
895
|
-
}
|
|
896
|
-
break;
|
|
897
814
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
//
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
nodes.push(
|
|
815
|
+
if (visitors.includeTokens &&
|
|
816
|
+
arena.dataTypes[node] != EnumToken.RuleNodeType &&
|
|
817
|
+
arena.dataTypes[node] != EnumToken.KeyframesRuleNodeType) {
|
|
818
|
+
// at-rule prelude, declaration values or token children. selector tokens are not visited
|
|
819
|
+
const values = arena.subTokens(node);
|
|
820
|
+
for (let i = values.length - 1; i >= 0; i--) {
|
|
821
|
+
nodes.push(values[i]);
|
|
905
822
|
}
|
|
906
823
|
}
|
|
907
|
-
|
|
824
|
+
};
|
|
825
|
+
while (nodes.length > 0) {
|
|
826
|
+
node = nodes.pop();
|
|
827
|
+
nodeType = arena.dataTypes[node];
|
|
828
|
+
replacement = null;
|
|
908
829
|
handlers.length = 0;
|
|
909
830
|
if (visitors.preAllVisitorsHandlers?.size > 0) {
|
|
910
831
|
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
911
832
|
}
|
|
912
833
|
genericKey =
|
|
913
|
-
|
|
834
|
+
nodeType == EnumToken.DeclarationNodeType
|
|
914
835
|
? "Declaration"
|
|
915
|
-
:
|
|
836
|
+
: nodeType == EnumToken.AtRuleNodeType
|
|
916
837
|
? "AtRule"
|
|
917
|
-
:
|
|
838
|
+
: nodeType == EnumToken.KeyframesAtRuleNodeType
|
|
918
839
|
? "KeyframesAtRule"
|
|
919
|
-
:
|
|
840
|
+
: nodeType === EnumToken.KeyframesRuleNodeType
|
|
920
841
|
? "KeyframesRule"
|
|
921
|
-
:
|
|
842
|
+
: nodeType == EnumToken.RuleNodeType
|
|
922
843
|
? "Rule"
|
|
923
|
-
:
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
: node.typ == EnumToken.KeyframesAtRuleNodeType
|
|
929
|
-
? camelize(node.val)
|
|
844
|
+
: null;
|
|
845
|
+
let keyName = nodeType == EnumToken.DeclarationNodeType || nodeType == EnumToken.AtRuleNodeType
|
|
846
|
+
? camelize(arena.strings[arena.name[node]])
|
|
847
|
+
: nodeType == EnumToken.KeyframesAtRuleNodeType
|
|
848
|
+
? camelize(arena.strings[arena.stringValue[node]])
|
|
930
849
|
: null;
|
|
931
850
|
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
932
851
|
handlers.push(...visitors.allVisitorsHandlers);
|
|
@@ -946,9 +865,9 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
946
865
|
}
|
|
947
866
|
}
|
|
948
867
|
}
|
|
949
|
-
if (map.has(
|
|
868
|
+
if (map.has(nodeType)) {
|
|
950
869
|
// @ts-ignore
|
|
951
|
-
for (const handler of map.get(
|
|
870
|
+
for (const handler of map.get(nodeType)) {
|
|
952
871
|
if (typeof handler == "function") {
|
|
953
872
|
handlers.push(handler);
|
|
954
873
|
}
|
|
@@ -973,63 +892,79 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
973
892
|
if (visitors.postAllVisitorsHandlers?.size > 0) {
|
|
974
893
|
handlers.push(...visitors.postAllVisitorsHandlers);
|
|
975
894
|
}
|
|
976
|
-
if (handlers.length
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
if (
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
895
|
+
if (handlers.length > 0) {
|
|
896
|
+
for (const callable of handlers) {
|
|
897
|
+
// the parent, the root, ... are read from the arena
|
|
898
|
+
replacement = callable(arena, node);
|
|
899
|
+
if (replacement == null) {
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
if (replacement == node) {
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
//
|
|
906
|
+
if (Array.isArray(replacement)) {
|
|
907
|
+
break;
|
|
989
908
|
}
|
|
990
|
-
});
|
|
991
|
-
if (replacement == null) {
|
|
992
|
-
continue;
|
|
993
|
-
}
|
|
994
|
-
if (replacement == node) {
|
|
995
|
-
continue;
|
|
996
909
|
}
|
|
997
910
|
// @ts-ignore
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
911
|
+
if (replacement != null && node != replacement) {
|
|
912
|
+
// nodes and tokens are replaced by ids allocated in the arena. the object views of the arena are
|
|
913
|
+
// not copied, plain objects are imported
|
|
914
|
+
replacement = visitorResult(arena, replacement);
|
|
915
|
+
if (replacement == node) ;
|
|
916
|
+
else if (replacement != null) {
|
|
917
|
+
if (arena.flags[node] & (EnumAstNodeStatus.HasChildren | EnumAstNodeStatus.HasValues)) {
|
|
918
|
+
arena.replaceChild(node, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
arena.replaceToken(node, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
errors.push({
|
|
926
|
+
action: "ignore",
|
|
927
|
+
message: "doParse: visitor must return node ids, objects or arrays of node ids and objects",
|
|
928
|
+
node,
|
|
929
|
+
});
|
|
930
|
+
}
|
|
1002
931
|
}
|
|
1003
932
|
}
|
|
1004
|
-
//
|
|
1005
|
-
if (replacement
|
|
1006
|
-
|
|
1007
|
-
|
|
933
|
+
// visit the children of the node or of its replacement
|
|
934
|
+
if (replacement == null || replacement == node) {
|
|
935
|
+
enqueue(node);
|
|
936
|
+
}
|
|
937
|
+
else if (Array.isArray(replacement)) {
|
|
938
|
+
for (let i = replacement.length - 1; i >= 0; i--) {
|
|
939
|
+
enqueue(replacement[i]);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
enqueue(replacement);
|
|
1008
944
|
}
|
|
1009
945
|
}
|
|
1010
946
|
nodes = null;
|
|
1011
947
|
}
|
|
1012
948
|
if (invalidNodes.length > 0) {
|
|
1013
949
|
for (const node of invalidNodes) {
|
|
1014
|
-
if (options.lenient && node
|
|
950
|
+
if (options.lenient && arena.flags[node] & EnumAstNodeStatus.Unknown) {
|
|
1015
951
|
continue;
|
|
1016
952
|
}
|
|
1017
|
-
if (node
|
|
953
|
+
if (arena.flags[node] &
|
|
1018
954
|
(EnumAstNodeStatus.Invalid |
|
|
1019
955
|
EnumAstNodeStatus.Unknown |
|
|
1020
956
|
EnumAstNodeStatus.Unparsed |
|
|
1021
957
|
EnumAstNodeStatus.Malformed |
|
|
1022
958
|
EnumAstNodeStatus.Disallowed)) {
|
|
1023
|
-
|
|
1024
|
-
node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1);
|
|
959
|
+
arena.detach(node);
|
|
1025
960
|
}
|
|
1026
961
|
}
|
|
1027
962
|
}
|
|
1028
963
|
if (options.minifyAST) {
|
|
1029
|
-
if (ast
|
|
964
|
+
if (arena.firstChild[ast] != 0) {
|
|
1030
965
|
let passes = options.pass ?? 1;
|
|
1031
966
|
while (passes--) {
|
|
1032
|
-
minify(ast, options, true, errors, false);
|
|
967
|
+
minify(arena, ast, options, true, errors, false);
|
|
1033
968
|
}
|
|
1034
969
|
}
|
|
1035
970
|
}
|
|
@@ -1037,6 +972,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1037
972
|
let endTime = performance.now();
|
|
1038
973
|
const result = {
|
|
1039
974
|
ast,
|
|
975
|
+
arena,
|
|
1040
976
|
errors,
|
|
1041
977
|
stats: {
|
|
1042
978
|
...stats,
|
|
@@ -1112,15 +1048,22 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1112
1048
|
moduleSettings.filePath = filePath;
|
|
1113
1049
|
moduleSettings.pattern =
|
|
1114
1050
|
pattern != null && pattern !== "" ? pattern : filePath === "" ? `[local]_[hash]` : `[local]_[hash]_[name]`;
|
|
1115
|
-
|
|
1116
|
-
|
|
1051
|
+
// inlined: arena.walk(ast)
|
|
1052
|
+
for (const node of new NodeWalker(arena, ast)) {
|
|
1053
|
+
const parent = arena.parents[node];
|
|
1054
|
+
const nodeType = arena.dataTypes[node];
|
|
1055
|
+
if (nodeType == EnumToken.CssVariableImportTokenType) {
|
|
1117
1056
|
throw new Error("css variable import not supported by parseSync() or transformSync(). use parse() or transform() instead.\nat " +
|
|
1118
|
-
options.source
|
|
1057
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(node as AstNode))
|
|
1058
|
+
[options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(node))].join(":"));
|
|
1119
1059
|
}
|
|
1120
1060
|
// @ts-ignore
|
|
1121
|
-
if (
|
|
1061
|
+
if (nodeType == EnumToken.CssVariableDeclarationMapTokenType) {
|
|
1122
1062
|
// @ts-ignore
|
|
1123
|
-
const
|
|
1063
|
+
const fromToken = arena
|
|
1064
|
+
.fieldTokens(node, TokenField.L)
|
|
1065
|
+
.find((t) => arena.dataTypes[t] == EnumToken.IdenTokenType || isIdentColor(arena, t));
|
|
1066
|
+
const from = { val: arena.strings[arena.stringValue[fromToken]] };
|
|
1124
1067
|
if (!(from.val in cssVariablesMap)) {
|
|
1125
1068
|
errors.push({
|
|
1126
1069
|
node,
|
|
@@ -1130,63 +1073,66 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1130
1073
|
}
|
|
1131
1074
|
else {
|
|
1132
1075
|
// @ts-ignore
|
|
1133
|
-
for (const token of node
|
|
1134
|
-
if (token
|
|
1135
|
-
if (!(token
|
|
1076
|
+
for (const token of arena.tokens(node)) {
|
|
1077
|
+
if (arena.dataTypes[token] == EnumToken.IdenTokenType || isIdentColor(arena, token)) {
|
|
1078
|
+
if (!(arena.strings[arena.stringValue[token]] in cssVariablesMap[from.val])) {
|
|
1136
1079
|
errors.push({
|
|
1137
1080
|
node,
|
|
1138
|
-
message: `value '${token
|
|
1081
|
+
message: `value '${arena.strings[arena.stringValue[token]]}' is not exported from '${from.val}'`,
|
|
1139
1082
|
action: "drop",
|
|
1140
1083
|
});
|
|
1141
1084
|
continue;
|
|
1142
1085
|
}
|
|
1143
1086
|
result.cssModuleVariables ??= {};
|
|
1144
|
-
result.cssModuleVariables[token
|
|
1087
|
+
result.cssModuleVariables[arena.strings[arena.stringValue[token]]] = importedCssVariables[arena.strings[arena.stringValue[token]]] = cssVariablesMap[from.val][arena.strings[arena.stringValue[token]]];
|
|
1145
1088
|
}
|
|
1146
1089
|
}
|
|
1147
1090
|
}
|
|
1148
|
-
|
|
1091
|
+
arena.detach(node);
|
|
1149
1092
|
continue;
|
|
1150
1093
|
}
|
|
1151
|
-
if (
|
|
1152
|
-
if (parent
|
|
1094
|
+
if (nodeType == EnumToken.CssVariableTokenType) {
|
|
1095
|
+
if (parent != null && arena.dataTypes[parent] == EnumToken.StyleSheetNodeType) {
|
|
1153
1096
|
if (result.cssModuleVariables == null) {
|
|
1154
1097
|
result.cssModuleVariables = {};
|
|
1155
1098
|
}
|
|
1156
|
-
//
|
|
1157
|
-
|
|
1099
|
+
// inlined: cssVariableToken(arena, node as AstNode): the object view of the css variable node
|
|
1100
|
+
// inlined: arena.toObject(node as AstNode)
|
|
1101
|
+
result.cssModuleVariables[arena.strings[arena.name[node]]] = new AstArenaNode(arena, node);
|
|
1158
1102
|
}
|
|
1159
|
-
|
|
1103
|
+
arena.detach(node);
|
|
1160
1104
|
continue;
|
|
1161
1105
|
}
|
|
1162
|
-
if (
|
|
1163
|
-
if (node.
|
|
1164
|
-
if (!(node
|
|
1106
|
+
if (nodeType == EnumToken.DeclarationNodeType) {
|
|
1107
|
+
if (arena.strings[arena.name[node]].startsWith("--")) {
|
|
1108
|
+
if (!(arena.strings[arena.name[node]] in namesMapping)) {
|
|
1165
1109
|
let value = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1166
|
-
? node
|
|
1167
|
-
: moduleSettings.generateScopedName(node
|
|
1168
|
-
mapping[node
|
|
1110
|
+
? arena.strings[arena.name[node]]
|
|
1111
|
+
: moduleSettings.generateScopedName(arena.strings[arena.name[node]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1112
|
+
mapping[arena.strings[arena.name[node]]] =
|
|
1169
1113
|
"--" +
|
|
1170
1114
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
1171
1115
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
1172
1116
|
? getKeyName(value, moduleSettings.naming)
|
|
1173
1117
|
: value);
|
|
1174
|
-
revMapping[node
|
|
1118
|
+
revMapping[arena.strings[arena.name[node]]] =
|
|
1119
|
+
arena.strings[arena.name[node]];
|
|
1175
1120
|
}
|
|
1176
|
-
node
|
|
1121
|
+
// inlined: arena.setNameString(node as AstNode, mapping[arena.strings[arena.name[node as AstNode]]])
|
|
1122
|
+
arena.name[node] = arena.internString(mapping[arena.strings[arena.name[node]]]);
|
|
1177
1123
|
}
|
|
1178
|
-
if (equalsIgnoreCase("composes", node
|
|
1124
|
+
if (equalsIgnoreCase("composes", arena.strings[arena.name[node]])) {
|
|
1179
1125
|
const composeSelectors = [];
|
|
1180
1126
|
// let isValid: boolean = true;
|
|
1181
|
-
for (
|
|
1182
|
-
if (token
|
|
1127
|
+
for (let token = arena.firstToken[node]; token != 0; token = arena.nextSibling[token]) {
|
|
1128
|
+
if (arena.dataTypes[token] == EnumToken.ComposesSelectorNodeType) {
|
|
1183
1129
|
composeSelectors.push(token);
|
|
1184
1130
|
}
|
|
1185
1131
|
}
|
|
1186
1132
|
// find parent rule
|
|
1187
|
-
let parentRule = parent;
|
|
1188
|
-
while (parentRule !=
|
|
1189
|
-
parentRule = parentRule
|
|
1133
|
+
let parentRule = parent ?? 0;
|
|
1134
|
+
while (parentRule != 0 && arena.dataTypes[parentRule] != EnumToken.RuleNodeType) {
|
|
1135
|
+
parentRule = arena.parents[parentRule];
|
|
1190
1136
|
}
|
|
1191
1137
|
if ( /* !isValid || */composeSelectors.length == 0) {
|
|
1192
1138
|
errors.push({
|
|
@@ -1194,39 +1140,40 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1194
1140
|
message: `composes is empty`,
|
|
1195
1141
|
node,
|
|
1196
1142
|
});
|
|
1197
|
-
|
|
1143
|
+
arena.detach(node);
|
|
1198
1144
|
continue;
|
|
1199
1145
|
}
|
|
1200
1146
|
for (const token of composeSelectors) {
|
|
1201
1147
|
// composes: a b c;
|
|
1202
|
-
if (token.
|
|
1203
|
-
for (const rule of token.
|
|
1204
|
-
if (rule
|
|
1205
|
-
rule
|
|
1148
|
+
if (!arena.hasField(token, TokenField.R)) {
|
|
1149
|
+
for (const rule of arena.fieldTokens(token, TokenField.L)) {
|
|
1150
|
+
if (arena.dataTypes[rule] == EnumToken.WhitespaceTokenType ||
|
|
1151
|
+
arena.dataTypes[rule] == EnumToken.CommentTokenType) {
|
|
1206
1152
|
continue;
|
|
1207
1153
|
}
|
|
1208
|
-
if (!(rule
|
|
1154
|
+
if (!(arena.strings[arena.stringValue[rule]] in mapping)) {
|
|
1209
1155
|
let value = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1210
|
-
? rule
|
|
1211
|
-
: moduleSettings.generateScopedName(rule
|
|
1212
|
-
mapping[rule
|
|
1213
|
-
(rule
|
|
1156
|
+
? arena.strings[arena.stringValue[rule]]
|
|
1157
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[rule]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1158
|
+
mapping[arena.strings[arena.stringValue[rule]]] =
|
|
1159
|
+
(arena.dataTypes[rule] == EnumToken.DashedIdenTokenType ? "--" : "") +
|
|
1214
1160
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
1215
1161
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
1216
1162
|
? getKeyName(value, moduleSettings.naming)
|
|
1217
1163
|
: value);
|
|
1218
|
-
revMapping[mapping[rule
|
|
1164
|
+
revMapping[mapping[arena.strings[arena.stringValue[rule]]]] =
|
|
1165
|
+
arena.strings[arena.stringValue[rule]];
|
|
1219
1166
|
}
|
|
1220
|
-
if (parentRule !=
|
|
1221
|
-
for (const tk of parentRule
|
|
1222
|
-
if (tk
|
|
1223
|
-
const val = tk.
|
|
1167
|
+
if (parentRule != 0) {
|
|
1168
|
+
for (const tk of arena.tokens(parentRule)) {
|
|
1169
|
+
if (arena.dataTypes[tk] == EnumToken.ClassSelectorTokenType) {
|
|
1170
|
+
const val = arena.strings[arena.stringValue[tk]].slice(1);
|
|
1224
1171
|
if (val in revMapping) {
|
|
1225
1172
|
const key = revMapping[val];
|
|
1226
1173
|
mapping[key] = [
|
|
1227
1174
|
...new Set([
|
|
1228
1175
|
...mapping[key].split(" "),
|
|
1229
|
-
mapping[rule
|
|
1176
|
+
mapping[arena.strings[arena.stringValue[rule]]],
|
|
1230
1177
|
]),
|
|
1231
1178
|
].join(" ");
|
|
1232
1179
|
}
|
|
@@ -1236,28 +1183,31 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1236
1183
|
}
|
|
1237
1184
|
}
|
|
1238
1185
|
// composes: a b c from 'file.css';
|
|
1239
|
-
else if (
|
|
1240
|
-
throw new Error(
|
|
1186
|
+
else if (arena.dataTypes[arena.field(token, TokenField.R)] == EnumToken.StringTokenType) {
|
|
1187
|
+
throw new Error(
|
|
1188
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(node as AstNode))
|
|
1189
|
+
`composes from file is not supported using parseSync() or transformSync(). Use parse() or transform() instead.\nat ${[options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(node))].join(":")}`);
|
|
1241
1190
|
}
|
|
1242
1191
|
// composes: a b c from global;
|
|
1243
|
-
else if (
|
|
1192
|
+
else if (arena.dataTypes[arena.field(token, TokenField.R)] == EnumToken.IdenTokenType) {
|
|
1244
1193
|
// global
|
|
1245
|
-
if (parentRule !=
|
|
1246
|
-
if (equalsIgnoreCase("global", token.
|
|
1247
|
-
for (const tk of parentRule
|
|
1248
|
-
if (tk
|
|
1249
|
-
const val = tk.
|
|
1194
|
+
if (parentRule != 0) {
|
|
1195
|
+
if (equalsIgnoreCase("global", arena.strings[arena.stringValue[arena.field(token, TokenField.R)]])) {
|
|
1196
|
+
for (const tk of arena.tokens(parentRule)) {
|
|
1197
|
+
if (arena.dataTypes[tk] == EnumToken.ClassSelectorTokenType) {
|
|
1198
|
+
const val = arena.strings[arena.stringValue[tk]].slice(1);
|
|
1250
1199
|
if (val in revMapping) {
|
|
1251
1200
|
const key = revMapping[val];
|
|
1201
|
+
const composedNames = [];
|
|
1202
|
+
for (const curr of arena.fieldTokens(token, TokenField.L)) {
|
|
1203
|
+
if (arena.dataTypes[curr] == EnumToken.IdenTokenType) {
|
|
1204
|
+
composedNames.push(arena.strings[arena.stringValue[curr]]);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1252
1207
|
mapping[key] = [
|
|
1253
1208
|
...new Set([
|
|
1254
1209
|
...mapping[key].split(" "),
|
|
1255
|
-
...
|
|
1256
|
-
if (curr.typ == EnumToken.IdenTokenType) {
|
|
1257
|
-
acc.push(curr.val);
|
|
1258
|
-
}
|
|
1259
|
-
return acc;
|
|
1260
|
-
}, []),
|
|
1210
|
+
...composedNames,
|
|
1261
1211
|
]),
|
|
1262
1212
|
].join(" ");
|
|
1263
1213
|
}
|
|
@@ -1267,32 +1217,32 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1267
1217
|
else {
|
|
1268
1218
|
errors.push({
|
|
1269
1219
|
action: "drop",
|
|
1270
|
-
message: `composes '${token.
|
|
1220
|
+
message: `composes '${arena.strings[arena.stringValue[arena.field(token, TokenField.R)]]}' is not supported`,
|
|
1271
1221
|
node,
|
|
1272
1222
|
});
|
|
1273
1223
|
}
|
|
1274
1224
|
}
|
|
1275
1225
|
}
|
|
1276
1226
|
}
|
|
1277
|
-
|
|
1278
|
-
}
|
|
1279
|
-
if (
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
for (const
|
|
1292
|
-
if (value
|
|
1227
|
+
arena.detach(node);
|
|
1228
|
+
}
|
|
1229
|
+
if ([
|
|
1230
|
+
"grid-column",
|
|
1231
|
+
"grid-column-start",
|
|
1232
|
+
"grid-column-end",
|
|
1233
|
+
"grid-row",
|
|
1234
|
+
"grid-row-start",
|
|
1235
|
+
"grid-row-end",
|
|
1236
|
+
"grid-template",
|
|
1237
|
+
"grid-template-columns",
|
|
1238
|
+
"grid-template-rows",
|
|
1239
|
+
].includes(arena.strings[arena.name[node]])) {
|
|
1240
|
+
// inlined: arena.walkValues(node as AstNode)
|
|
1241
|
+
for (const value of new ValueWalker(arena, node)) {
|
|
1242
|
+
if (arena.dataTypes[value] != EnumToken.IdenTokenType) {
|
|
1293
1243
|
continue;
|
|
1294
1244
|
}
|
|
1295
|
-
let idenToken = value
|
|
1245
|
+
let idenToken = arena.strings[arena.stringValue[value]];
|
|
1296
1246
|
let suffix = "";
|
|
1297
1247
|
if (idenToken.endsWith("-start")) {
|
|
1298
1248
|
suffix = "-start";
|
|
@@ -1316,41 +1266,45 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1316
1266
|
}
|
|
1317
1267
|
}
|
|
1318
1268
|
}
|
|
1319
|
-
value
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1269
|
+
// inlined: arena.setStr(value, mapping[idenToken])
|
|
1270
|
+
arena.stringValue[value] = arena.internString(mapping[idenToken]);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
else if (arena.strings[arena.name[node]] == "grid-template-areas" ||
|
|
1274
|
+
arena.strings[arena.name[node]] == "grid-template") {
|
|
1275
|
+
for (let token = arena.firstToken[node]; token != 0; token = arena.nextSibling[token]) {
|
|
1276
|
+
if (arena.dataTypes[token] == EnumToken.StringTokenType) {
|
|
1277
|
+
const str = arena.strings[arena.stringValue[token]];
|
|
1278
|
+
const tokens = parseString(arena, str.slice(1, -1));
|
|
1279
|
+
// inlined: arena.walkValues(tokens)
|
|
1280
|
+
for (const value of new ValueWalker(arena, tokens)) {
|
|
1281
|
+
if (arena.dataTypes[value] == EnumToken.IdenTokenType ||
|
|
1282
|
+
arena.dataTypes[value] == EnumToken.DashedIdenTokenType) {
|
|
1283
|
+
if (arena.strings[arena.stringValue[value]] in mapping) {
|
|
1284
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
1285
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
1332
1286
|
}
|
|
1333
1287
|
else {
|
|
1334
1288
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1335
|
-
? value
|
|
1336
|
-
: moduleSettings.generateScopedName(value
|
|
1337
|
-
mapping[value
|
|
1338
|
-
revMapping[result] = value
|
|
1339
|
-
value
|
|
1289
|
+
? arena.strings[arena.stringValue[value]]
|
|
1290
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[value]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1291
|
+
mapping[arena.strings[arena.stringValue[value]]] = result;
|
|
1292
|
+
revMapping[result] = arena.strings[arena.stringValue[value]];
|
|
1293
|
+
// inlined: arena.setStr(value, result)
|
|
1294
|
+
arena.stringValue[value] = arena.internString(result);
|
|
1340
1295
|
}
|
|
1341
1296
|
}
|
|
1342
1297
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
renderTokens(tokens) +
|
|
1346
|
-
node.val[i].val.charAt(node.val[i].val.length - 1);
|
|
1298
|
+
// inlined: arena.setStr(token, str.charAt(0) + renderTokens(arena, tokens) + str.charAt(str.length - 1))
|
|
1299
|
+
arena.stringValue[token] = arena.internString((str.charAt(0) + renderTokens(arena, tokens) + str.charAt(str.length - 1)));
|
|
1347
1300
|
}
|
|
1348
1301
|
}
|
|
1349
1302
|
}
|
|
1350
|
-
else if (node
|
|
1351
|
-
node
|
|
1352
|
-
|
|
1353
|
-
|
|
1303
|
+
else if (arena.strings[arena.name[node]] == "animation" ||
|
|
1304
|
+
arena.strings[arena.name[node]] == "animation-name") {
|
|
1305
|
+
// inlined: arena.walkValues(node as AstNode)
|
|
1306
|
+
for (const value of new ValueWalker(arena, node)) {
|
|
1307
|
+
if (arena.dataTypes[value] == EnumToken.IdenTokenType &&
|
|
1354
1308
|
![
|
|
1355
1309
|
"none",
|
|
1356
1310
|
"infinite",
|
|
@@ -1379,83 +1333,89 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1379
1333
|
"inherit",
|
|
1380
1334
|
"initial",
|
|
1381
1335
|
"unset",
|
|
1382
|
-
].includes(value
|
|
1383
|
-
if (!(value
|
|
1384
|
-
mapping[value
|
|
1336
|
+
].includes(arena.strings[arena.stringValue[value]])) {
|
|
1337
|
+
if (!(arena.strings[arena.stringValue[value]] in mapping)) {
|
|
1338
|
+
mapping[arena.strings[arena.stringValue[value]]] =
|
|
1385
1339
|
moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1386
|
-
? value
|
|
1387
|
-
: moduleSettings.generateScopedName(value
|
|
1388
|
-
revMapping[mapping[value
|
|
1340
|
+
? arena.strings[arena.stringValue[value]]
|
|
1341
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[value]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1342
|
+
revMapping[mapping[arena.strings[arena.stringValue[value]]]] = arena.strings[arena.stringValue[value]];
|
|
1389
1343
|
}
|
|
1390
|
-
value
|
|
1344
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
1345
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
1391
1346
|
}
|
|
1392
1347
|
}
|
|
1393
1348
|
}
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1349
|
+
// inlined: arena.walkValues(node as AstNode)
|
|
1350
|
+
for (const value of new ValueWalker(arena, node)) {
|
|
1351
|
+
if (arena.dataTypes[value] == EnumToken.DashedIdenTokenType) {
|
|
1352
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
1353
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
1397
1354
|
}
|
|
1398
|
-
else if ((
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
replaceNodeOrValue(r.parent, r.value, importedCssVariables[value.val].val);
|
|
1355
|
+
else if ((arena.dataTypes[value] == EnumToken.IdenTokenType || isIdentColor(arena, value)) &&
|
|
1356
|
+
arena.strings[arena.stringValue[value]] in importedCssVariables) {
|
|
1357
|
+
arena.replaceToken(value, ...arena.tokens(importedCssVariables[arena.strings[arena.stringValue[value]]][ARENAID]).map((token) => arena.clone(token, true)));
|
|
1402
1358
|
}
|
|
1403
1359
|
}
|
|
1404
1360
|
}
|
|
1405
|
-
else if (
|
|
1361
|
+
else if (nodeType == EnumToken.RuleNodeType) {
|
|
1406
1362
|
// if (node[TOKENS] == null) {
|
|
1407
|
-
const tokens = parseString(node
|
|
1408
|
-
matchSelectorSyntax(tokens, [], options);
|
|
1409
|
-
node
|
|
1363
|
+
const tokens = parseString(arena, arena.strings[arena.name[node]]);
|
|
1364
|
+
matchSelectorSyntax(arena, tokens, [], options);
|
|
1365
|
+
arena.setTokenList(node, trimArray(arena, tokens));
|
|
1410
1366
|
let hasIdOrClass = false;
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
const val = value.val.toLowerCase();
|
|
1367
|
+
// inlined: arena.walkValues(node as AstNode, filter)
|
|
1368
|
+
for (const value of new ValueWalker(arena, node, (arena, value) => {
|
|
1369
|
+
if (arena.dataTypes[value] == EnumToken.PseudoClassTokenType ||
|
|
1370
|
+
arena.dataTypes[value] == EnumToken.PseudoElementTokenType) {
|
|
1371
|
+
const val = arena.strings[arena.stringValue[value]].toLowerCase();
|
|
1417
1372
|
switch (val) {
|
|
1418
1373
|
case ":local":
|
|
1419
1374
|
case ":global":
|
|
1420
1375
|
{
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1376
|
+
// remove the pseudo class and the following whitespace
|
|
1377
|
+
const next = arena.nextSibling[value];
|
|
1378
|
+
arena.detach(value);
|
|
1379
|
+
if (next != 0 &&
|
|
1380
|
+
(arena.dataTypes[next] == EnumToken.WhitespaceTokenType ||
|
|
1381
|
+
arena.dataTypes[next] == EnumToken.DescendantCombinatorTokenType)) {
|
|
1382
|
+
arena.detach(next);
|
|
1427
1383
|
}
|
|
1428
1384
|
}
|
|
1429
1385
|
break;
|
|
1430
1386
|
}
|
|
1431
1387
|
}
|
|
1432
|
-
else if (value
|
|
1433
|
-
switch (value.
|
|
1388
|
+
else if (arena.dataTypes[value] == EnumToken.PseudoClassFuncTokenType) {
|
|
1389
|
+
switch (arena.strings[arena.stringValue[value]].toLowerCase()) {
|
|
1434
1390
|
case ":global":
|
|
1435
|
-
for (const token of value
|
|
1391
|
+
for (const token of arena.tokens(value)) {
|
|
1436
1392
|
global.add(token);
|
|
1437
1393
|
}
|
|
1438
|
-
case ":local":
|
|
1439
|
-
|
|
1440
|
-
|
|
1394
|
+
case ":local": {
|
|
1395
|
+
// replace the function by its arguments. the arguments are visited
|
|
1396
|
+
const children = arena.tokens(value);
|
|
1397
|
+
arena.replaceToken(value, ...children);
|
|
1398
|
+
return children;
|
|
1399
|
+
}
|
|
1441
1400
|
}
|
|
1442
1401
|
}
|
|
1402
|
+
return null;
|
|
1443
1403
|
})) {
|
|
1444
|
-
if (value
|
|
1404
|
+
if (arena.dataTypes[value] == EnumToken.HashTokenType || arena.dataTypes[value] == EnumToken.ClassSelectorTokenType) {
|
|
1445
1405
|
hasIdOrClass = true;
|
|
1446
1406
|
}
|
|
1447
1407
|
if (processed.has(value)) {
|
|
1448
1408
|
continue;
|
|
1449
1409
|
}
|
|
1450
1410
|
processed.add(value);
|
|
1451
|
-
if (value
|
|
1452
|
-
else if (value
|
|
1411
|
+
if (arena.dataTypes[value] == EnumToken.PseudoClassTokenType || arena.dataTypes[value] == EnumToken.PseudoElementTokenType) ;
|
|
1412
|
+
else if (arena.dataTypes[value] == EnumToken.PseudoClassFuncTokenType) ;
|
|
1453
1413
|
else {
|
|
1454
1414
|
if (global.has(value)) {
|
|
1455
1415
|
continue;
|
|
1456
1416
|
}
|
|
1457
|
-
if (value
|
|
1458
|
-
const val = value.
|
|
1417
|
+
if (arena.dataTypes[value] == EnumToken.ClassSelectorTokenType) {
|
|
1418
|
+
const val = arena.strings[arena.stringValue[value]].slice(1);
|
|
1459
1419
|
if (!(val in mapping)) {
|
|
1460
1420
|
let value = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1461
1421
|
? val
|
|
@@ -1467,46 +1427,50 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1467
1427
|
: value;
|
|
1468
1428
|
revMapping[mapping[val]] = val;
|
|
1469
1429
|
}
|
|
1470
|
-
value
|
|
1430
|
+
// inlined: arena.setStr(value, "." + mapping[val])
|
|
1431
|
+
arena.stringValue[value] = arena.internString(("." + mapping[val]));
|
|
1471
1432
|
}
|
|
1472
1433
|
}
|
|
1473
1434
|
}
|
|
1474
1435
|
if (moduleSettings.scoped & ModuleScopeEnumOptions.Pure) {
|
|
1475
1436
|
if (!hasIdOrClass) {
|
|
1476
|
-
throw new Error(
|
|
1437
|
+
throw new Error(
|
|
1438
|
+
// inlined: options.source!.getOffsets(arena.getSpanStart(node as AstNode))
|
|
1439
|
+
`pure module: No id or class found in selector '${arena.strings[arena.name[node]]}' at '${options.source.lineStarts.getOffsets(arena.getSpanStart(node)).join(":")}'`);
|
|
1477
1440
|
}
|
|
1478
1441
|
}
|
|
1479
|
-
node.
|
|
1480
|
-
|
|
1481
|
-
node.sel += renderValue(token);
|
|
1482
|
-
}
|
|
1442
|
+
// inlined: arena.setSelector(node as AstNode, arena.tokens(node as AstNode).reduce((acc: string, token: Token) => acc + renderValue(arena, token), ""))
|
|
1443
|
+
arena.name[node] = arena.internString(arena.tokens(node).reduce((acc, token) => acc + renderValue(arena, token), ""));
|
|
1483
1444
|
}
|
|
1484
|
-
else if (
|
|
1485
|
-
const val = node.
|
|
1486
|
-
if (node
|
|
1487
|
-
node
|
|
1445
|
+
else if (nodeType == EnumToken.AtRuleNodeType || nodeType == EnumToken.KeyframesAtRuleNodeType) {
|
|
1446
|
+
const val = arena.strings[arena.name[node]].toLowerCase();
|
|
1447
|
+
if (arena.firstToken[node] == 0) {
|
|
1448
|
+
// inlined: arena.setTokens(node as AstNode, ...parseString(arena, arena.strings[arena.stringValue[node as AstNode]]))
|
|
1449
|
+
arena.setTokenList(node, parseString(arena, arena.strings[arena.stringValue[node]]));
|
|
1488
1450
|
}
|
|
1489
1451
|
if (val == "property" || val == "keyframes") {
|
|
1490
1452
|
const prefix = val == "property" ? "--" : "";
|
|
1491
|
-
for (const value of node
|
|
1492
|
-
if ((prefix == "--" && value
|
|
1493
|
-
(prefix == "" && value
|
|
1494
|
-
if (!(value
|
|
1453
|
+
for (const value of arena.tokens(node)) {
|
|
1454
|
+
if ((prefix == "--" && arena.dataTypes[value] == EnumToken.DashedIdenTokenType) ||
|
|
1455
|
+
(prefix == "" && arena.dataTypes[value] == EnumToken.IdenTokenType)) {
|
|
1456
|
+
if (!(arena.strings[arena.stringValue[value]] in mapping)) {
|
|
1495
1457
|
let val = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
1496
|
-
? value
|
|
1497
|
-
: moduleSettings.generateScopedName(value
|
|
1498
|
-
mapping[value
|
|
1458
|
+
? arena.strings[arena.stringValue[value]]
|
|
1459
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[value]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
1460
|
+
mapping[arena.strings[arena.stringValue[value]]] =
|
|
1499
1461
|
prefix +
|
|
1500
1462
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
1501
1463
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
1502
1464
|
? getKeyName(val, moduleSettings.naming)
|
|
1503
1465
|
: val);
|
|
1504
|
-
revMapping[mapping[value
|
|
1466
|
+
revMapping[mapping[arena.strings[arena.stringValue[value]]]] = arena.strings[arena.stringValue[value]];
|
|
1505
1467
|
}
|
|
1506
|
-
value
|
|
1468
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
1469
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
1507
1470
|
}
|
|
1508
1471
|
}
|
|
1509
|
-
node
|
|
1472
|
+
// inlined: arena.setValueString(node as AstNode, renderTokens(arena, arena.tokens(node as AstNode)))
|
|
1473
|
+
arena.stringValue[node] = arena.internString(renderTokens(arena, arena.tokens(node)));
|
|
1510
1474
|
}
|
|
1511
1475
|
}
|
|
1512
1476
|
}
|
|
@@ -1570,9 +1534,7 @@ async function doParse(iter, options = {}) {
|
|
|
1570
1534
|
...options,
|
|
1571
1535
|
};
|
|
1572
1536
|
options.minifyAST ??= options.minify;
|
|
1573
|
-
|
|
1574
|
-
options.validation = !!options.validation;
|
|
1575
|
-
}
|
|
1537
|
+
options.validation = !!options.validation;
|
|
1576
1538
|
if (options.module) {
|
|
1577
1539
|
options.expandNestingRules = true;
|
|
1578
1540
|
}
|
|
@@ -1598,10 +1560,15 @@ async function doParse(iter, options = {}) {
|
|
|
1598
1560
|
imports: [],
|
|
1599
1561
|
};
|
|
1600
1562
|
const invalidNodes = [];
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1563
|
+
// first error / invalid node of the current statement
|
|
1564
|
+
let errorStart = errors.length;
|
|
1565
|
+
let invalidStart = 0;
|
|
1566
|
+
// tokens allocated for the current statement (parseNode() may remove tokens from the statement array)
|
|
1567
|
+
const statement = [];
|
|
1568
|
+
let tokenizer = iter instanceof Promise ? await iter : iter;
|
|
1569
|
+
// nested parses share the arena of the parent
|
|
1570
|
+
const arena = options.arena ?? (options.arena = new AstArena(arenaCapacity(tokenizer)));
|
|
1571
|
+
let ast = arena.current == 1 ? arena.root : arena.createStyleSheet();
|
|
1605
1572
|
let tokens = [];
|
|
1606
1573
|
let context = ast;
|
|
1607
1574
|
const imports = [];
|
|
@@ -1610,169 +1577,123 @@ async function doParse(iter, options = {}) {
|
|
|
1610
1577
|
// @ts-ignore ignore error
|
|
1611
1578
|
let parensMatch = 0;
|
|
1612
1579
|
let curlyBracketMatch = 0;
|
|
1613
|
-
|
|
1614
|
-
ast
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1580
|
+
// tokens are located in the tokenizer source (the imported file when parsing an @import)
|
|
1581
|
+
arena.setLocation(ast, tokenizer.sourceId, 0, 0);
|
|
1582
|
+
const sourceIndex = arena.sourceIndex(tokenizer.sourceId);
|
|
1583
|
+
let itemType;
|
|
1584
|
+
// inlined: tokenizer.done()
|
|
1585
|
+
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
1618
1586
|
tokenizer.next();
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
typ: tokenizer.typ,
|
|
1622
|
-
val: tokenizer.val,
|
|
1623
|
-
unit: tokenizer.unit,
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
else if (tokenizer.nam != null) {
|
|
1627
|
-
item = {
|
|
1628
|
-
typ: tokenizer.typ,
|
|
1629
|
-
nam: tokenizer.nam,
|
|
1630
|
-
};
|
|
1631
|
-
}
|
|
1632
|
-
else if (tokenizer.val === null) {
|
|
1633
|
-
item = {
|
|
1634
|
-
typ: tokenizer.typ,
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
else if (tokenizer.kin != null) {
|
|
1638
|
-
item = {
|
|
1639
|
-
typ: tokenizer.typ,
|
|
1640
|
-
val: tokenizer.val,
|
|
1641
|
-
kin: tokenizer.kin,
|
|
1642
|
-
};
|
|
1643
|
-
}
|
|
1644
|
-
else {
|
|
1645
|
-
item = {
|
|
1646
|
-
typ: tokenizer.typ,
|
|
1647
|
-
val: tokenizer.val,
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
item[LOCSRCID] = tokenizer.srcId;
|
|
1651
|
-
item[LOCSTA] = tokenizer.sta;
|
|
1652
|
-
item[LOCEND] = tokenizer.end;
|
|
1587
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
1588
|
+
itemType = tokenizer.typ;
|
|
1653
1589
|
stats.bytesIn = tokenizer.bytesIn;
|
|
1654
1590
|
stats.tokensCount++;
|
|
1655
|
-
if (
|
|
1591
|
+
if (isBadToken(itemType)) {
|
|
1656
1592
|
tokens.push(item);
|
|
1593
|
+
statement.push(item);
|
|
1657
1594
|
errors.push({
|
|
1658
1595
|
action: "drop",
|
|
1659
1596
|
message: "Bad token",
|
|
1660
1597
|
syntax: null,
|
|
1661
1598
|
node: item,
|
|
1662
|
-
|
|
1599
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(item))
|
|
1600
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(item))],
|
|
1663
1601
|
});
|
|
1664
1602
|
// bad token
|
|
1665
1603
|
continue;
|
|
1666
1604
|
}
|
|
1667
|
-
if (
|
|
1605
|
+
if (itemType === EnumToken.StartParensTokenType || tokensfuncDefMap.has(itemType)) {
|
|
1668
1606
|
parensMatch++;
|
|
1669
1607
|
}
|
|
1670
|
-
else if (
|
|
1608
|
+
else if (itemType === EnumToken.EndParensTokenType && parensMatch > 0) {
|
|
1671
1609
|
parensMatch--;
|
|
1672
1610
|
}
|
|
1673
|
-
if (
|
|
1611
|
+
if (itemType === EnumToken.BlockStartTokenType) {
|
|
1674
1612
|
curlyBracketMatch++;
|
|
1675
1613
|
}
|
|
1676
|
-
else if (
|
|
1614
|
+
else if (itemType === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
|
|
1677
1615
|
curlyBracketMatch--;
|
|
1678
1616
|
}
|
|
1679
1617
|
tokens.push(item);
|
|
1618
|
+
statement.push(item);
|
|
1680
1619
|
if (parensMatch === 0 &&
|
|
1681
|
-
(
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
1620
|
+
(itemType === EnumToken.SemiColonTokenType ||
|
|
1621
|
+
itemType === EnumToken.BlockStartTokenType ||
|
|
1622
|
+
itemType === EnumToken.EOFTokenType)) {
|
|
1623
|
+
node = parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
1685
1624
|
if (node != null) {
|
|
1686
|
-
if (
|
|
1625
|
+
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
1687
1626
|
stack.push(node);
|
|
1688
1627
|
context = node;
|
|
1689
1628
|
}
|
|
1690
|
-
else if (node
|
|
1629
|
+
else if (arena.dataTypes[node] == EnumToken.AtRuleNodeType &&
|
|
1630
|
+
arena.strings[arena.name[node]] === "import") {
|
|
1691
1631
|
imports.push(node);
|
|
1692
1632
|
}
|
|
1693
1633
|
}
|
|
1694
|
-
else if (
|
|
1634
|
+
else if (itemType == EnumToken.BlockStartTokenType) {
|
|
1695
1635
|
let inBlock = 1;
|
|
1696
1636
|
tokens.length = 0;
|
|
1697
1637
|
tokens.push(item);
|
|
1698
1638
|
do {
|
|
1699
1639
|
tokenizer.next();
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
typ: tokenizer.typ,
|
|
1703
|
-
val: tokenizer.val,
|
|
1704
|
-
unit: tokenizer.unit,
|
|
1705
|
-
};
|
|
1706
|
-
}
|
|
1707
|
-
else if (tokenizer.nam != null) {
|
|
1708
|
-
item = {
|
|
1709
|
-
typ: tokenizer.typ,
|
|
1710
|
-
nam: tokenizer.nam,
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
else if (tokenizer.val === null) {
|
|
1714
|
-
item = {
|
|
1715
|
-
typ: tokenizer.typ,
|
|
1716
|
-
};
|
|
1717
|
-
}
|
|
1718
|
-
else if (tokenizer.kin != null) {
|
|
1719
|
-
item = {
|
|
1720
|
-
typ: tokenizer.typ,
|
|
1721
|
-
val: tokenizer.val,
|
|
1722
|
-
kin: tokenizer.kin,
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1725
|
-
else {
|
|
1726
|
-
item = {
|
|
1727
|
-
typ: tokenizer.typ,
|
|
1728
|
-
val: tokenizer.val,
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
item[LOCSRCID] = tokenizer.srcId;
|
|
1732
|
-
item[LOCSTA] = tokenizer.sta;
|
|
1733
|
-
item[LOCEND] = tokenizer.end;
|
|
1640
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
1641
|
+
itemType = tokenizer.typ;
|
|
1734
1642
|
tokens.push(item);
|
|
1735
|
-
|
|
1643
|
+
statement.push(item);
|
|
1644
|
+
if (itemType === EnumToken.BlockStartTokenType) {
|
|
1736
1645
|
inBlock++;
|
|
1737
1646
|
}
|
|
1738
|
-
else if (
|
|
1647
|
+
else if (itemType === EnumToken.BlockEndTokenType) {
|
|
1739
1648
|
inBlock--;
|
|
1740
1649
|
}
|
|
1741
|
-
|
|
1650
|
+
// inlined: tokenizer.done()
|
|
1651
|
+
} while (inBlock != 0 && !(tokenizer.typ === EnumToken.EOF));
|
|
1742
1652
|
if (tokens.length > 0) {
|
|
1743
1653
|
errors.push({
|
|
1744
1654
|
action: "drop",
|
|
1745
1655
|
message: "invalid block",
|
|
1746
|
-
|
|
1656
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[0]))
|
|
1657
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[0]))],
|
|
1747
1658
|
});
|
|
1748
1659
|
}
|
|
1749
1660
|
}
|
|
1661
|
+
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
1662
|
+
statement.length = 0;
|
|
1750
1663
|
tokens.length = 0;
|
|
1664
|
+
errorStart = errors.length;
|
|
1665
|
+
invalidStart = invalidNodes.length;
|
|
1751
1666
|
}
|
|
1752
|
-
else if ((parensMatch === 0 || curlyBracketMatch === 0) &&
|
|
1753
|
-
parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
1754
|
-
context
|
|
1667
|
+
else if ((parensMatch === 0 || curlyBracketMatch === 0) && itemType === EnumToken.BlockEndTokenType) {
|
|
1668
|
+
parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
1669
|
+
// inlined: arena.setSpanEnd(context, arena.getSpanEnd(item))
|
|
1670
|
+
arena.setSpan(context, arena.getSourceId(context), arena.getSpanStart(context), arena.getSpanEnd(item));
|
|
1755
1671
|
const previousNode = stack.pop();
|
|
1756
|
-
context =
|
|
1672
|
+
context = stack[stack.length - 1] ?? ast;
|
|
1757
1673
|
if (options.removeEmpty &&
|
|
1758
1674
|
previousNode != null &&
|
|
1759
|
-
previousNode
|
|
1760
|
-
|
|
1761
|
-
|
|
1675
|
+
arena.firstChild[previousNode] == 0 &&
|
|
1676
|
+
arena.lastChild[context] == previousNode) {
|
|
1677
|
+
arena.detach(previousNode);
|
|
1762
1678
|
}
|
|
1679
|
+
recycleStatementTokens(arena, statement, errors, errorStart, invalidNodes, invalidStart);
|
|
1680
|
+
statement.length = 0;
|
|
1763
1681
|
tokens.length = 0;
|
|
1682
|
+
errorStart = errors.length;
|
|
1683
|
+
invalidStart = invalidNodes.length;
|
|
1764
1684
|
parensMatch = 0;
|
|
1765
1685
|
curlyBracketMatch = 0;
|
|
1766
1686
|
}
|
|
1767
1687
|
// }
|
|
1768
1688
|
}
|
|
1769
1689
|
if (tokens.length > 0) {
|
|
1770
|
-
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
1690
|
+
node = parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch);
|
|
1771
1691
|
if (node != null) {
|
|
1772
|
-
if (node
|
|
1692
|
+
if (arena.dataTypes[node] == EnumToken.AtRuleNodeType &&
|
|
1693
|
+
"import" === arena.strings[arena.stringValue[node]]) {
|
|
1773
1694
|
imports.push(node);
|
|
1774
1695
|
}
|
|
1775
|
-
if (
|
|
1696
|
+
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
1776
1697
|
stack.push(node);
|
|
1777
1698
|
context = node;
|
|
1778
1699
|
}
|
|
@@ -1780,11 +1701,13 @@ async function doParse(iter, options = {}) {
|
|
|
1780
1701
|
}
|
|
1781
1702
|
if (imports.length > 0 && options.resolveImport) {
|
|
1782
1703
|
await Promise.all(imports.map(async (node) => {
|
|
1783
|
-
if (node
|
|
1704
|
+
if ((arena.flags[node] & EnumAstNodeStatus.StateMask) !== EnumAstNodeStatus.Validated) {
|
|
1784
1705
|
return;
|
|
1785
1706
|
}
|
|
1786
|
-
const token = node
|
|
1787
|
-
const url = token
|
|
1707
|
+
const token = arena.firstToken[node];
|
|
1708
|
+
const url = arena.dataTypes[token] == EnumToken.StringTokenType
|
|
1709
|
+
? arena.strings[arena.stringValue[token]].slice(1, -1)
|
|
1710
|
+
: arena.strings[arena.stringValue[token]];
|
|
1788
1711
|
try {
|
|
1789
1712
|
const src = options.resolve(url, options.src ? dirname(options.src) : options.cwd);
|
|
1790
1713
|
const result = options.load(src);
|
|
@@ -1812,8 +1735,11 @@ async function doParse(iter, options = {}) {
|
|
|
1812
1735
|
stats.nodesCount += root.stats.nodesCount;
|
|
1813
1736
|
stats.tokensCount += root.stats.tokensCount;
|
|
1814
1737
|
stats.imports.push(root.stats);
|
|
1815
|
-
// @
|
|
1816
|
-
|
|
1738
|
+
// the imported stylesheet is allocated in the same arena: its children replace the @import rule
|
|
1739
|
+
if (arena.parents[node] != 0) {
|
|
1740
|
+
arena.moveChildren(root.ast, arena.parents[node], node);
|
|
1741
|
+
arena.detach(node);
|
|
1742
|
+
}
|
|
1817
1743
|
if (root.errors.length > 0) {
|
|
1818
1744
|
for (const error of root.errors) {
|
|
1819
1745
|
errors.push(error);
|
|
@@ -1828,240 +1754,57 @@ async function doParse(iter, options = {}) {
|
|
|
1828
1754
|
}
|
|
1829
1755
|
const endParseTime = performance.now();
|
|
1830
1756
|
if (options.expandNestingRules) {
|
|
1831
|
-
ast = expand(ast);
|
|
1757
|
+
ast = arena.expand(ast);
|
|
1832
1758
|
}
|
|
1833
1759
|
let replacement;
|
|
1834
1760
|
if (options.visitor != null) {
|
|
1835
|
-
let parens;
|
|
1836
|
-
let genericKey;
|
|
1837
1761
|
const handlers = [];
|
|
1838
1762
|
const visitors = parseVisitors(options.visitor, errors);
|
|
1763
|
+
let genericKey;
|
|
1839
1764
|
let nodes = [ast];
|
|
1840
1765
|
let node;
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
if (
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
case EnumToken.AtRuleNodeType:
|
|
1848
|
-
case EnumToken.KeyframesRuleNodeType:
|
|
1849
|
-
case EnumToken.KeyframesAtRuleNodeType:
|
|
1850
|
-
for (let i =
|
|
1851
|
-
// @ts-ignore
|
|
1852
|
-
node[TOKENS].length -
|
|
1853
|
-
1; i >= 0; i--) {
|
|
1854
|
-
// @ts-ignore
|
|
1855
|
-
node[TOKENS][i][PARENT] =
|
|
1856
|
-
node;
|
|
1857
|
-
nodes.push(
|
|
1858
|
-
// @ts-ignore
|
|
1859
|
-
node[TOKENS][i]);
|
|
1860
|
-
}
|
|
1861
|
-
break;
|
|
1862
|
-
case EnumToken.DeclarationNodeType:
|
|
1863
|
-
for (let i =
|
|
1864
|
-
// @ts-ignore
|
|
1865
|
-
node.val.length - 1; i >= 0; i--) {
|
|
1866
|
-
// @ts-ignore
|
|
1867
|
-
node.val[i][PARENT] = node;
|
|
1868
|
-
// @ts-ignore
|
|
1869
|
-
nodes.push(node.val[i]);
|
|
1870
|
-
}
|
|
1871
|
-
break;
|
|
1766
|
+
let nodeType;
|
|
1767
|
+
// push the children of a node or the sub tokens of a value token onto the stack
|
|
1768
|
+
const enqueue = (node) => {
|
|
1769
|
+
if (arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
1770
|
+
for (let child = arena.lastChild[node]; child != 0; child = arena.previousSibling[child]) {
|
|
1771
|
+
nodes.push(child);
|
|
1872
1772
|
}
|
|
1873
|
-
// @ts-ignore
|
|
1874
|
-
// if (node.l != null) {
|
|
1875
|
-
// // @ts-ignore
|
|
1876
|
-
// if (node.op2 != null) {
|
|
1877
|
-
// // @ts-ignore
|
|
1878
|
-
// nodes.push(node.op2);
|
|
1879
|
-
// // @ts-ignore
|
|
1880
|
-
// nodes.op2[PARENT] = node;
|
|
1881
|
-
// }
|
|
1882
|
-
// // @ts-ignore
|
|
1883
|
-
// if (node.op1 != null) {
|
|
1884
|
-
// // @ts-ignore
|
|
1885
|
-
// nodes.push(node.op1);
|
|
1886
|
-
// // @ts-ignore
|
|
1887
|
-
// nodes.op1[PARENT] = node;
|
|
1888
|
-
// }
|
|
1889
|
-
// // @ts-ignore
|
|
1890
|
-
// if (nodes.op != null && node.op.typ != null) {
|
|
1891
|
-
// // @ts-ignore
|
|
1892
|
-
// nodes.push(node.op);
|
|
1893
|
-
// // @ts-ignore
|
|
1894
|
-
// nodes.op[PARENT] = node;
|
|
1895
|
-
// }
|
|
1896
|
-
// // @ts-ignore
|
|
1897
|
-
// if (node.r != null) {
|
|
1898
|
-
// // @ts-ignore
|
|
1899
|
-
// if (Array.isArray(node.r)) {
|
|
1900
|
-
// // @ts-ignore
|
|
1901
|
-
// for (let i = node.r.length - 1; i >= 0; i--) {
|
|
1902
|
-
// // @ts-ignore
|
|
1903
|
-
// nodes.push(node.r[i]);
|
|
1904
|
-
// // @ts-ignore
|
|
1905
|
-
// node.r[i][PARENT] = node;
|
|
1906
|
-
// }
|
|
1907
|
-
// } else {
|
|
1908
|
-
// // @ts-ignore
|
|
1909
|
-
// nodes.push(node.r);
|
|
1910
|
-
// // @ts-ignore
|
|
1911
|
-
// node.r[PARENT] = node;
|
|
1912
|
-
// }
|
|
1913
|
-
// }
|
|
1914
|
-
// // @ts-ignore
|
|
1915
|
-
// if (Array.isArray(node.l)) {
|
|
1916
|
-
// // @ts-ignore
|
|
1917
|
-
// for (let i = node.l.length - 1; i >= 0; i--) {
|
|
1918
|
-
// // @ts-ignore
|
|
1919
|
-
// node.l[i][PARENT] = node;
|
|
1920
|
-
// // @ts-ignore
|
|
1921
|
-
// nodes.push(node.l[i]);
|
|
1922
|
-
// }
|
|
1923
|
-
// } else {
|
|
1924
|
-
// // @ts-ignore
|
|
1925
|
-
// nodes.push(node.l);
|
|
1926
|
-
// // @ts-ignore
|
|
1927
|
-
// node.l[PARENT] = node;
|
|
1928
|
-
// }
|
|
1929
|
-
// }
|
|
1930
|
-
}
|
|
1931
|
-
switch (node.typ) {
|
|
1932
|
-
case EnumToken.BinaryExpressionTokenType:
|
|
1933
|
-
case EnumToken.IfElseConditionTokenType:
|
|
1934
|
-
nodes.push(node.r);
|
|
1935
|
-
node.r[PARENT] = node;
|
|
1936
|
-
nodes.push(node.l);
|
|
1937
|
-
node.l[PARENT] = node;
|
|
1938
|
-
break;
|
|
1939
|
-
case EnumToken.MatchExpressionTokenType:
|
|
1940
|
-
nodes.push(node.r);
|
|
1941
|
-
node.r[PARENT] = node;
|
|
1942
|
-
nodes.push(node.op);
|
|
1943
|
-
node.op[PARENT] = node;
|
|
1944
|
-
nodes.push(node.l);
|
|
1945
|
-
node.l[PARENT] = node;
|
|
1946
|
-
break;
|
|
1947
|
-
case EnumToken.SupportsQueryConditionTokenType:
|
|
1948
|
-
case EnumToken.MediaQueryConditionTokenType:
|
|
1949
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
1950
|
-
const element = node.r[i];
|
|
1951
|
-
nodes.push(element);
|
|
1952
|
-
element[PARENT] = node;
|
|
1953
|
-
}
|
|
1954
|
-
nodes.push(node.op);
|
|
1955
|
-
node.op[PARENT] = node;
|
|
1956
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
1957
|
-
const element = node.l[i];
|
|
1958
|
-
nodes.push(element);
|
|
1959
|
-
element[PARENT] = node;
|
|
1960
|
-
}
|
|
1961
|
-
break;
|
|
1962
|
-
case EnumToken.WhenElseQueryConditionTokenType:
|
|
1963
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
1964
|
-
const element = node.r[i];
|
|
1965
|
-
nodes.push(element);
|
|
1966
|
-
element[PARENT] = node;
|
|
1967
|
-
}
|
|
1968
|
-
nodes.push(node.l);
|
|
1969
|
-
node.l[PARENT] = node;
|
|
1970
|
-
break;
|
|
1971
|
-
case EnumToken.IfConditionTokenType:
|
|
1972
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
1973
|
-
const element = node.r[i];
|
|
1974
|
-
nodes.push(element);
|
|
1975
|
-
element[PARENT] = node;
|
|
1976
|
-
}
|
|
1977
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
1978
|
-
const element = node.l[i];
|
|
1979
|
-
nodes.push(element);
|
|
1980
|
-
element[PARENT] = node;
|
|
1981
|
-
}
|
|
1982
|
-
break;
|
|
1983
|
-
case EnumToken.ComposesSelectorNodeType:
|
|
1984
|
-
if (node.r != null) {
|
|
1985
|
-
nodes.push(node.r);
|
|
1986
|
-
node.r[PARENT] = node;
|
|
1987
|
-
}
|
|
1988
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
1989
|
-
const element = node.l[i];
|
|
1990
|
-
nodes.push(element);
|
|
1991
|
-
element[PARENT] = node;
|
|
1992
|
-
}
|
|
1993
|
-
break;
|
|
1994
|
-
case EnumToken.ContainerStyleRangeTokenType:
|
|
1995
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
1996
|
-
const element = node.r[i];
|
|
1997
|
-
nodes.push(element);
|
|
1998
|
-
element[PARENT] = node;
|
|
1999
|
-
}
|
|
2000
|
-
for (let i = node.op.length - 1; i >= 0; i--) {
|
|
2001
|
-
const element = node.op[i];
|
|
2002
|
-
nodes.push(element);
|
|
2003
|
-
element[PARENT] = node;
|
|
2004
|
-
}
|
|
2005
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
2006
|
-
const element = node.l[i];
|
|
2007
|
-
nodes.push(element);
|
|
2008
|
-
element[PARENT] = node;
|
|
2009
|
-
}
|
|
2010
|
-
break;
|
|
2011
|
-
case EnumToken.MediaRangeQueryTokenType:
|
|
2012
|
-
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
2013
|
-
const element = node.r[i];
|
|
2014
|
-
nodes.push(element);
|
|
2015
|
-
element[PARENT] = node;
|
|
2016
|
-
}
|
|
2017
|
-
nodes.push(node.op2);
|
|
2018
|
-
node.op2[PARENT] = node;
|
|
2019
|
-
for (let i = node.val.length - 1; i >= 0; i--) {
|
|
2020
|
-
const element = node.val[i];
|
|
2021
|
-
nodes.push(element);
|
|
2022
|
-
element[PARENT] = node;
|
|
2023
|
-
}
|
|
2024
|
-
nodes.push(node.op1);
|
|
2025
|
-
node.op1[PARENT] = node;
|
|
2026
|
-
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
2027
|
-
const element = node.l[i];
|
|
2028
|
-
nodes.push(element);
|
|
2029
|
-
element[PARENT] = node;
|
|
2030
|
-
}
|
|
2031
|
-
break;
|
|
2032
1773
|
}
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
//
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
nodes.push(
|
|
1774
|
+
if (visitors.includeTokens &&
|
|
1775
|
+
arena.dataTypes[node] != EnumToken.RuleNodeType &&
|
|
1776
|
+
arena.dataTypes[node] != EnumToken.KeyframesRuleNodeType) {
|
|
1777
|
+
// at-rule prelude, declaration values or token children. selector tokens are not visited
|
|
1778
|
+
const values = arena.subTokens(node);
|
|
1779
|
+
for (let i = values.length - 1; i >= 0; i--) {
|
|
1780
|
+
nodes.push(values[i]);
|
|
2040
1781
|
}
|
|
2041
1782
|
}
|
|
2042
|
-
|
|
1783
|
+
};
|
|
1784
|
+
while (nodes.length > 0) {
|
|
1785
|
+
node = nodes.pop();
|
|
1786
|
+
nodeType = arena.dataTypes[node];
|
|
1787
|
+
replacement = null;
|
|
2043
1788
|
handlers.length = 0;
|
|
2044
1789
|
if (visitors.preAllVisitorsHandlers?.size > 0) {
|
|
2045
1790
|
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
2046
1791
|
}
|
|
2047
1792
|
genericKey =
|
|
2048
|
-
|
|
1793
|
+
nodeType == EnumToken.DeclarationNodeType
|
|
2049
1794
|
? "Declaration"
|
|
2050
|
-
:
|
|
1795
|
+
: nodeType == EnumToken.AtRuleNodeType
|
|
2051
1796
|
? "AtRule"
|
|
2052
|
-
:
|
|
1797
|
+
: nodeType == EnumToken.KeyframesAtRuleNodeType
|
|
2053
1798
|
? "KeyframesAtRule"
|
|
2054
|
-
:
|
|
1799
|
+
: nodeType === EnumToken.KeyframesRuleNodeType
|
|
2055
1800
|
? "KeyframesRule"
|
|
2056
|
-
:
|
|
1801
|
+
: nodeType == EnumToken.RuleNodeType
|
|
2057
1802
|
? "Rule"
|
|
2058
|
-
:
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
: node.typ == EnumToken.KeyframesAtRuleNodeType
|
|
2064
|
-
? camelize(node.val)
|
|
1803
|
+
: null;
|
|
1804
|
+
let keyName = nodeType == EnumToken.DeclarationNodeType || nodeType == EnumToken.AtRuleNodeType
|
|
1805
|
+
? camelize(arena.strings[arena.name[node]])
|
|
1806
|
+
: nodeType == EnumToken.KeyframesAtRuleNodeType
|
|
1807
|
+
? camelize(arena.strings[arena.stringValue[node]])
|
|
2065
1808
|
: null;
|
|
2066
1809
|
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
2067
1810
|
handlers.push(...visitors.allVisitorsHandlers);
|
|
@@ -2081,9 +1824,9 @@ async function doParse(iter, options = {}) {
|
|
|
2081
1824
|
}
|
|
2082
1825
|
}
|
|
2083
1826
|
}
|
|
2084
|
-
if (map.has(
|
|
1827
|
+
if (map.has(nodeType)) {
|
|
2085
1828
|
// @ts-ignore
|
|
2086
|
-
for (const handler of map.get(
|
|
1829
|
+
for (const handler of map.get(nodeType)) {
|
|
2087
1830
|
if (typeof handler == "function") {
|
|
2088
1831
|
handlers.push(handler);
|
|
2089
1832
|
}
|
|
@@ -2108,67 +1851,82 @@ async function doParse(iter, options = {}) {
|
|
|
2108
1851
|
if (visitors.postAllVisitorsHandlers?.size > 0) {
|
|
2109
1852
|
handlers.push(...visitors.postAllVisitorsHandlers);
|
|
2110
1853
|
}
|
|
2111
|
-
if (handlers.length
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
if (
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
1854
|
+
if (handlers.length > 0) {
|
|
1855
|
+
for (const callable of handlers) {
|
|
1856
|
+
// the parent, the root, ... are read from the arena
|
|
1857
|
+
replacement = callable(arena, node);
|
|
1858
|
+
if (replacement == null) {
|
|
1859
|
+
continue;
|
|
1860
|
+
}
|
|
1861
|
+
if (replacement instanceof Promise) {
|
|
1862
|
+
replacement = await replacement;
|
|
1863
|
+
}
|
|
1864
|
+
if (replacement == node) {
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
//
|
|
1868
|
+
if (Array.isArray(replacement)) {
|
|
1869
|
+
break;
|
|
2125
1870
|
}
|
|
2126
|
-
});
|
|
2127
|
-
if (replacement == null) {
|
|
2128
|
-
continue;
|
|
2129
|
-
}
|
|
2130
|
-
if (replacement instanceof Promise) {
|
|
2131
|
-
replacement = await replacement;
|
|
2132
|
-
}
|
|
2133
|
-
if (replacement == null || replacement == node) {
|
|
2134
|
-
continue;
|
|
2135
1871
|
}
|
|
2136
1872
|
// @ts-ignore
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
1873
|
+
if (replacement != null && node != replacement) {
|
|
1874
|
+
// nodes and tokens are replaced by ids allocated in the arena. the object views of the arena are
|
|
1875
|
+
// not copied, plain objects are imported
|
|
1876
|
+
replacement = visitorResult(arena, replacement);
|
|
1877
|
+
if (replacement == node) ;
|
|
1878
|
+
else if (replacement != null) {
|
|
1879
|
+
if (arena.flags[node] & (EnumAstNodeStatus.HasChildren | EnumAstNodeStatus.HasValues)) {
|
|
1880
|
+
arena.replaceChild(node, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
1881
|
+
}
|
|
1882
|
+
else {
|
|
1883
|
+
arena.replaceToken(node, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
errors.push({
|
|
1888
|
+
action: "ignore",
|
|
1889
|
+
message: "doParse: visitor must return node ids, objects or arrays of node ids and objects",
|
|
1890
|
+
node,
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
2141
1893
|
}
|
|
2142
1894
|
}
|
|
2143
|
-
//
|
|
2144
|
-
if (replacement
|
|
2145
|
-
|
|
2146
|
-
|
|
1895
|
+
// visit the children of the node or of its replacement
|
|
1896
|
+
if (replacement == null || replacement == node) {
|
|
1897
|
+
enqueue(node);
|
|
1898
|
+
}
|
|
1899
|
+
else if (Array.isArray(replacement)) {
|
|
1900
|
+
for (let i = replacement.length - 1; i >= 0; i--) {
|
|
1901
|
+
enqueue(replacement[i]);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
else {
|
|
1905
|
+
enqueue(replacement);
|
|
2147
1906
|
}
|
|
2148
1907
|
}
|
|
2149
1908
|
nodes = null;
|
|
2150
1909
|
}
|
|
2151
1910
|
if (invalidNodes.length > 0) {
|
|
2152
1911
|
for (const node of invalidNodes) {
|
|
2153
|
-
if (options.lenient && node
|
|
1912
|
+
if (options.lenient && arena.flags[node] & EnumAstNodeStatus.Unknown) {
|
|
2154
1913
|
continue;
|
|
2155
1914
|
}
|
|
2156
|
-
if (node
|
|
1915
|
+
if (arena.flags[node] &
|
|
2157
1916
|
(EnumAstNodeStatus.Invalid |
|
|
2158
1917
|
EnumAstNodeStatus.Unknown |
|
|
2159
1918
|
EnumAstNodeStatus.Unparsed |
|
|
2160
1919
|
EnumAstNodeStatus.Malformed |
|
|
2161
1920
|
EnumAstNodeStatus.Disallowed)) {
|
|
2162
|
-
|
|
2163
|
-
node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1);
|
|
1921
|
+
arena.detach(node);
|
|
2164
1922
|
}
|
|
2165
1923
|
}
|
|
2166
1924
|
}
|
|
2167
1925
|
if (options.minifyAST) {
|
|
2168
|
-
if (ast
|
|
1926
|
+
if (arena.firstChild[ast] != 0) {
|
|
2169
1927
|
let passes = options.pass ?? 1;
|
|
2170
1928
|
while (passes--) {
|
|
2171
|
-
minify(ast, options, true, errors, false);
|
|
1929
|
+
minify(arena, ast, options, true, errors, false);
|
|
2172
1930
|
}
|
|
2173
1931
|
}
|
|
2174
1932
|
}
|
|
@@ -2176,6 +1934,7 @@ async function doParse(iter, options = {}) {
|
|
|
2176
1934
|
let endTime = performance.now();
|
|
2177
1935
|
const result = {
|
|
2178
1936
|
ast,
|
|
1937
|
+
arena,
|
|
2179
1938
|
errors,
|
|
2180
1939
|
stats: {
|
|
2181
1940
|
...stats,
|
|
@@ -2252,9 +2011,12 @@ async function doParse(iter, options = {}) {
|
|
|
2252
2011
|
moduleSettings.filePath = filePath;
|
|
2253
2012
|
moduleSettings.pattern =
|
|
2254
2013
|
pattern != null && pattern !== "" ? pattern : filePath === "" ? `[local]_[hash]` : `[local]_[hash]_[name]`;
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2014
|
+
// inlined: arena.walk(ast)
|
|
2015
|
+
for (const node of new NodeWalker(arena, ast)) {
|
|
2016
|
+
const parent = arena.parents[node];
|
|
2017
|
+
const nodeType = arena.dataTypes[node];
|
|
2018
|
+
if (nodeType == EnumToken.CssVariableImportTokenType) {
|
|
2019
|
+
const url = arena.strings[arena.stringValue[arena.findToken(node, (arena, t) => arena.dataTypes[t] == EnumToken.StringTokenType)]].slice(1, -1);
|
|
2258
2020
|
const src = options.resolve(url, options.dirname(options.src), options.cwd);
|
|
2259
2021
|
const result = options.load(src, "");
|
|
2260
2022
|
const stream = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == "AsyncFunction"
|
|
@@ -2280,14 +2042,17 @@ async function doParse(iter, options = {}) {
|
|
|
2280
2042
|
src: src.relative,
|
|
2281
2043
|
}));
|
|
2282
2044
|
// options.parseInfo!.time += parseInfo.time;
|
|
2283
|
-
cssVariablesMap[node
|
|
2284
|
-
|
|
2045
|
+
cssVariablesMap[arena.strings[arena.name[node]]] = root.cssModuleVariables;
|
|
2046
|
+
arena.detach(node);
|
|
2285
2047
|
continue;
|
|
2286
2048
|
}
|
|
2287
2049
|
// @ts-ignore
|
|
2288
|
-
if (
|
|
2050
|
+
if (nodeType == EnumToken.CssVariableDeclarationMapTokenType) {
|
|
2289
2051
|
// @ts-ignore
|
|
2290
|
-
const
|
|
2052
|
+
const fromToken = arena
|
|
2053
|
+
.fieldTokens(node, TokenField.L)
|
|
2054
|
+
.find((t) => arena.dataTypes[t] == EnumToken.IdenTokenType || isIdentColor(arena, t));
|
|
2055
|
+
const from = { val: arena.strings[arena.stringValue[fromToken]] };
|
|
2291
2056
|
if (!(from.val in cssVariablesMap)) {
|
|
2292
2057
|
errors.push({
|
|
2293
2058
|
node,
|
|
@@ -2297,65 +2062,68 @@ async function doParse(iter, options = {}) {
|
|
|
2297
2062
|
}
|
|
2298
2063
|
else {
|
|
2299
2064
|
// @ts-ignore
|
|
2300
|
-
for (const token of node
|
|
2301
|
-
if (token
|
|
2302
|
-
if (!(token
|
|
2065
|
+
for (const token of arena.tokens(node)) {
|
|
2066
|
+
if (arena.dataTypes[token] == EnumToken.IdenTokenType || isIdentColor(arena, token)) {
|
|
2067
|
+
if (!(arena.strings[arena.stringValue[token]] in cssVariablesMap[from.val])) {
|
|
2303
2068
|
errors.push({
|
|
2304
2069
|
node,
|
|
2305
|
-
message: `value '${token
|
|
2070
|
+
message: `value '${arena.strings[arena.stringValue[token]]}' is not exported from '${from.val}'`,
|
|
2306
2071
|
action: "drop",
|
|
2307
2072
|
});
|
|
2308
2073
|
continue;
|
|
2309
2074
|
}
|
|
2310
2075
|
result.cssModuleVariables ??= {};
|
|
2311
|
-
result.cssModuleVariables[token
|
|
2076
|
+
result.cssModuleVariables[arena.strings[arena.stringValue[token]]] = importedCssVariables[arena.strings[arena.stringValue[token]]] = cssVariablesMap[from.val][arena.strings[arena.stringValue[token]]];
|
|
2312
2077
|
}
|
|
2313
2078
|
}
|
|
2314
2079
|
}
|
|
2315
|
-
|
|
2080
|
+
arena.detach(node);
|
|
2316
2081
|
continue;
|
|
2317
2082
|
}
|
|
2318
|
-
if (
|
|
2319
|
-
if (parent
|
|
2083
|
+
if (nodeType == EnumToken.CssVariableTokenType) {
|
|
2084
|
+
if (parent != null && arena.dataTypes[parent] == EnumToken.StyleSheetNodeType) {
|
|
2320
2085
|
if (result.cssModuleVariables == null) {
|
|
2321
2086
|
result.cssModuleVariables = {};
|
|
2322
2087
|
}
|
|
2323
|
-
//
|
|
2324
|
-
|
|
2088
|
+
// inlined: cssVariableToken(arena, node as AstNode): the object view of the css variable node
|
|
2089
|
+
// inlined: arena.toObject(node as AstNode)
|
|
2090
|
+
result.cssModuleVariables[arena.strings[arena.name[node]]] = new AstArenaNode(arena, node);
|
|
2325
2091
|
}
|
|
2326
|
-
|
|
2092
|
+
arena.detach(node);
|
|
2327
2093
|
continue;
|
|
2328
2094
|
}
|
|
2329
|
-
if (
|
|
2330
|
-
if (node.
|
|
2331
|
-
if (!(node
|
|
2095
|
+
if (nodeType == EnumToken.DeclarationNodeType) {
|
|
2096
|
+
if (arena.strings[arena.name[node]].startsWith("--")) {
|
|
2097
|
+
if (!(arena.strings[arena.name[node]] in namesMapping)) {
|
|
2332
2098
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2333
|
-
? node
|
|
2334
|
-
: moduleSettings.generateScopedName(node
|
|
2099
|
+
? arena.strings[arena.name[node]]
|
|
2100
|
+
: moduleSettings.generateScopedName(arena.strings[arena.name[node]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2335
2101
|
// @ts-ignore
|
|
2336
2102
|
let value = result instanceof Promise ? await result : result;
|
|
2337
|
-
mapping[node
|
|
2103
|
+
mapping[arena.strings[arena.name[node]]] =
|
|
2338
2104
|
"--" +
|
|
2339
2105
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2340
2106
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2341
2107
|
? getKeyName(value, moduleSettings.naming)
|
|
2342
2108
|
: value);
|
|
2343
|
-
revMapping[node
|
|
2109
|
+
revMapping[arena.strings[arena.name[node]]] =
|
|
2110
|
+
arena.strings[arena.name[node]];
|
|
2344
2111
|
}
|
|
2345
|
-
node
|
|
2112
|
+
// inlined: arena.setNameString(node as AstNode, mapping[arena.strings[arena.name[node as AstNode]]])
|
|
2113
|
+
arena.name[node] = arena.internString(mapping[arena.strings[arena.name[node]]]);
|
|
2346
2114
|
}
|
|
2347
|
-
if (equalsIgnoreCase("composes", node
|
|
2115
|
+
if (equalsIgnoreCase("composes", arena.strings[arena.name[node]])) {
|
|
2348
2116
|
const composeSelectors = [];
|
|
2349
2117
|
// let isValid: boolean = true;
|
|
2350
|
-
for (
|
|
2351
|
-
if (token
|
|
2118
|
+
for (let token = arena.firstToken[node]; token != 0; token = arena.nextSibling[token]) {
|
|
2119
|
+
if (arena.dataTypes[token] == EnumToken.ComposesSelectorNodeType) {
|
|
2352
2120
|
composeSelectors.push(token);
|
|
2353
2121
|
}
|
|
2354
2122
|
}
|
|
2355
2123
|
// find parent rule
|
|
2356
|
-
let parentRule = parent;
|
|
2357
|
-
while (parentRule !=
|
|
2358
|
-
parentRule = parentRule
|
|
2124
|
+
let parentRule = parent ?? 0;
|
|
2125
|
+
while (parentRule != 0 && arena.dataTypes[parentRule] != EnumToken.RuleNodeType) {
|
|
2126
|
+
parentRule = arena.parents[parentRule];
|
|
2359
2127
|
}
|
|
2360
2128
|
if ( /* !isValid || */composeSelectors.length == 0) {
|
|
2361
2129
|
errors.push({
|
|
@@ -2363,42 +2131,43 @@ async function doParse(iter, options = {}) {
|
|
|
2363
2131
|
message: `composes is empty`,
|
|
2364
2132
|
node,
|
|
2365
2133
|
});
|
|
2366
|
-
|
|
2134
|
+
arena.detach(node);
|
|
2367
2135
|
continue;
|
|
2368
2136
|
}
|
|
2369
2137
|
const resolvedSrc = options.resolve(options.src, options.cwd);
|
|
2370
2138
|
for (const token of composeSelectors) {
|
|
2371
2139
|
// composes: a b c;
|
|
2372
|
-
if (token.
|
|
2373
|
-
for (const rule of token.
|
|
2374
|
-
if (rule
|
|
2375
|
-
rule
|
|
2140
|
+
if (!arena.hasField(token, TokenField.R)) {
|
|
2141
|
+
for (const rule of arena.fieldTokens(token, TokenField.L)) {
|
|
2142
|
+
if (arena.dataTypes[rule] == EnumToken.WhitespaceTokenType ||
|
|
2143
|
+
arena.dataTypes[rule] == EnumToken.CommentTokenType) {
|
|
2376
2144
|
continue;
|
|
2377
2145
|
}
|
|
2378
|
-
if (!(rule
|
|
2146
|
+
if (!(arena.strings[arena.stringValue[rule]] in mapping)) {
|
|
2379
2147
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2380
|
-
? rule
|
|
2381
|
-
: moduleSettings.generateScopedName(rule
|
|
2148
|
+
? arena.strings[arena.stringValue[rule]]
|
|
2149
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[rule]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2382
2150
|
// @ts-expect-error
|
|
2383
2151
|
let value = result instanceof Promise ? await result : result;
|
|
2384
|
-
mapping[rule
|
|
2385
|
-
(rule
|
|
2152
|
+
mapping[arena.strings[arena.stringValue[rule]]] =
|
|
2153
|
+
(arena.dataTypes[rule] == EnumToken.DashedIdenTokenType ? "--" : "") +
|
|
2386
2154
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2387
2155
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2388
2156
|
? getKeyName(value, moduleSettings.naming)
|
|
2389
2157
|
: value);
|
|
2390
|
-
revMapping[mapping[rule
|
|
2158
|
+
revMapping[mapping[arena.strings[arena.stringValue[rule]]]] =
|
|
2159
|
+
arena.strings[arena.stringValue[rule]];
|
|
2391
2160
|
}
|
|
2392
|
-
if (parentRule !=
|
|
2393
|
-
for (const tk of parentRule
|
|
2394
|
-
if (tk
|
|
2395
|
-
const val = tk.
|
|
2161
|
+
if (parentRule != 0) {
|
|
2162
|
+
for (const tk of arena.tokens(parentRule)) {
|
|
2163
|
+
if (arena.dataTypes[tk] == EnumToken.ClassSelectorTokenType) {
|
|
2164
|
+
const val = arena.strings[arena.stringValue[tk]].slice(1);
|
|
2396
2165
|
if (val in revMapping) {
|
|
2397
2166
|
const key = revMapping[val];
|
|
2398
2167
|
mapping[key] = [
|
|
2399
2168
|
...new Set([
|
|
2400
2169
|
...mapping[key].split(" "),
|
|
2401
|
-
mapping[rule
|
|
2170
|
+
mapping[arena.strings[arena.stringValue[rule]]],
|
|
2402
2171
|
]),
|
|
2403
2172
|
].join(" ");
|
|
2404
2173
|
}
|
|
@@ -2408,8 +2177,8 @@ async function doParse(iter, options = {}) {
|
|
|
2408
2177
|
}
|
|
2409
2178
|
}
|
|
2410
2179
|
// composes: a b c from 'file.css';
|
|
2411
|
-
else if (
|
|
2412
|
-
const url = token.
|
|
2180
|
+
else if (arena.dataTypes[arena.field(token, TokenField.R)] == EnumToken.StringTokenType) {
|
|
2181
|
+
const url = arena.strings[arena.stringValue[arena.field(token, TokenField.R)]].slice(1, -1);
|
|
2413
2182
|
const src = options.resolve(url, options.dirname(options.src), options.cwd);
|
|
2414
2183
|
const result = options.load(src, "");
|
|
2415
2184
|
const stream = result instanceof Promise ||
|
|
@@ -2441,35 +2210,35 @@ async function doParse(iter, options = {}) {
|
|
|
2441
2210
|
if (Object.keys(root.mapping).length > 0) {
|
|
2442
2211
|
importMapping[srcIndex] = {};
|
|
2443
2212
|
}
|
|
2444
|
-
if (parentRule !=
|
|
2445
|
-
for (const tk of parentRule
|
|
2446
|
-
if (tk
|
|
2447
|
-
const val = tk.
|
|
2213
|
+
if (parentRule != 0) {
|
|
2214
|
+
for (const tk of arena.tokens(parentRule)) {
|
|
2215
|
+
if (arena.dataTypes[tk] == EnumToken.ClassSelectorTokenType) {
|
|
2216
|
+
const val = arena.strings[arena.stringValue[tk]].slice(1);
|
|
2448
2217
|
if (val in revMapping) {
|
|
2449
2218
|
const key = revMapping[val];
|
|
2450
2219
|
const values = [];
|
|
2451
|
-
for (const iden of token.
|
|
2452
|
-
if (iden
|
|
2453
|
-
iden
|
|
2220
|
+
for (const iden of arena.fieldTokens(token, TokenField.L)) {
|
|
2221
|
+
if (arena.dataTypes[iden] != EnumToken.IdenTokenType &&
|
|
2222
|
+
arena.dataTypes[iden] != EnumToken.DashedIdenTokenType) {
|
|
2454
2223
|
continue;
|
|
2455
2224
|
}
|
|
2456
|
-
if (!(iden
|
|
2225
|
+
if (!(arena.strings[arena.stringValue[iden]] in root.mapping)) {
|
|
2457
2226
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2458
|
-
? iden
|
|
2459
|
-
: moduleSettings.generateScopedName(iden
|
|
2227
|
+
? arena.strings[arena.stringValue[iden]]
|
|
2228
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[iden]], srcIndex, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2460
2229
|
let value =
|
|
2461
2230
|
// @ts-expect-error
|
|
2462
2231
|
result instanceof Promise ? await result : result;
|
|
2463
|
-
root.mapping[iden
|
|
2232
|
+
root.mapping[arena.strings[arena.stringValue[iden]]] =
|
|
2464
2233
|
moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2465
2234
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2466
2235
|
? getKeyName(value, moduleSettings.naming)
|
|
2467
2236
|
: value;
|
|
2468
|
-
root.revMapping[root.mapping[iden
|
|
2237
|
+
root.revMapping[root.mapping[arena.strings[arena.stringValue[iden]]]] = arena.strings[arena.stringValue[iden]];
|
|
2469
2238
|
}
|
|
2470
|
-
importMapping[srcIndex][iden
|
|
2471
|
-
root.mapping[iden
|
|
2472
|
-
values.push(root.mapping[iden
|
|
2239
|
+
importMapping[srcIndex][arena.strings[arena.stringValue[iden]]] =
|
|
2240
|
+
root.mapping[arena.strings[arena.stringValue[iden]]];
|
|
2241
|
+
values.push(root.mapping[arena.strings[arena.stringValue[iden]]]);
|
|
2473
2242
|
}
|
|
2474
2243
|
mapping[key] = [...new Set([...mapping[key].split(" "), ...values])].join(" ");
|
|
2475
2244
|
}
|
|
@@ -2478,24 +2247,25 @@ async function doParse(iter, options = {}) {
|
|
|
2478
2247
|
}
|
|
2479
2248
|
}
|
|
2480
2249
|
// composes: a b c from global;
|
|
2481
|
-
else if (
|
|
2250
|
+
else if (arena.dataTypes[arena.field(token, TokenField.R)] == EnumToken.IdenTokenType) {
|
|
2482
2251
|
// global
|
|
2483
|
-
if (parentRule !=
|
|
2484
|
-
if (equalsIgnoreCase("global", token.
|
|
2485
|
-
for (const tk of parentRule
|
|
2486
|
-
if (tk
|
|
2487
|
-
const val = tk.
|
|
2252
|
+
if (parentRule != 0) {
|
|
2253
|
+
if (equalsIgnoreCase("global", arena.strings[arena.stringValue[arena.field(token, TokenField.R)]])) {
|
|
2254
|
+
for (const tk of arena.tokens(parentRule)) {
|
|
2255
|
+
if (arena.dataTypes[tk] == EnumToken.ClassSelectorTokenType) {
|
|
2256
|
+
const val = arena.strings[arena.stringValue[tk]].slice(1);
|
|
2488
2257
|
if (val in revMapping) {
|
|
2489
2258
|
const key = revMapping[val];
|
|
2259
|
+
const composedNames = [];
|
|
2260
|
+
for (const curr of arena.fieldTokens(token, TokenField.L)) {
|
|
2261
|
+
if (arena.dataTypes[curr] == EnumToken.IdenTokenType) {
|
|
2262
|
+
composedNames.push(arena.strings[arena.stringValue[curr]]);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2490
2265
|
mapping[key] = [
|
|
2491
2266
|
...new Set([
|
|
2492
2267
|
...mapping[key].split(" "),
|
|
2493
|
-
...
|
|
2494
|
-
if (curr.typ == EnumToken.IdenTokenType) {
|
|
2495
|
-
acc.push(curr.val);
|
|
2496
|
-
}
|
|
2497
|
-
return acc;
|
|
2498
|
-
}, []),
|
|
2268
|
+
...composedNames,
|
|
2499
2269
|
]),
|
|
2500
2270
|
].join(" ");
|
|
2501
2271
|
}
|
|
@@ -2505,32 +2275,32 @@ async function doParse(iter, options = {}) {
|
|
|
2505
2275
|
else {
|
|
2506
2276
|
errors.push({
|
|
2507
2277
|
action: "drop",
|
|
2508
|
-
message: `composes '${token.
|
|
2278
|
+
message: `composes '${arena.strings[arena.stringValue[arena.field(token, TokenField.R)]]}' is not supported`,
|
|
2509
2279
|
node,
|
|
2510
2280
|
});
|
|
2511
2281
|
}
|
|
2512
2282
|
}
|
|
2513
2283
|
}
|
|
2514
2284
|
}
|
|
2515
|
-
|
|
2516
|
-
}
|
|
2517
|
-
if (
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
for (const
|
|
2530
|
-
if (value
|
|
2285
|
+
arena.detach(node);
|
|
2286
|
+
}
|
|
2287
|
+
if ([
|
|
2288
|
+
"grid-column",
|
|
2289
|
+
"grid-column-start",
|
|
2290
|
+
"grid-column-end",
|
|
2291
|
+
"grid-row",
|
|
2292
|
+
"grid-row-start",
|
|
2293
|
+
"grid-row-end",
|
|
2294
|
+
"grid-template",
|
|
2295
|
+
"grid-template-columns",
|
|
2296
|
+
"grid-template-rows",
|
|
2297
|
+
].includes(arena.strings[arena.name[node]])) {
|
|
2298
|
+
// inlined: arena.walkValues(node as AstNode)
|
|
2299
|
+
for (const value of new ValueWalker(arena, node)) {
|
|
2300
|
+
if (arena.dataTypes[value] != EnumToken.IdenTokenType) {
|
|
2531
2301
|
continue;
|
|
2532
2302
|
}
|
|
2533
|
-
let idenToken = value
|
|
2303
|
+
let idenToken = arena.strings[arena.stringValue[value]];
|
|
2534
2304
|
let suffix = "";
|
|
2535
2305
|
if (idenToken.endsWith("-start")) {
|
|
2536
2306
|
suffix = "-start";
|
|
@@ -2558,45 +2328,49 @@ async function doParse(iter, options = {}) {
|
|
|
2558
2328
|
}
|
|
2559
2329
|
}
|
|
2560
2330
|
}
|
|
2561
|
-
value
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2331
|
+
// inlined: arena.setStr(value, mapping[idenToken])
|
|
2332
|
+
arena.stringValue[value] = arena.internString(mapping[idenToken]);
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
else if (arena.strings[arena.name[node]] == "grid-template-areas" ||
|
|
2336
|
+
arena.strings[arena.name[node]] == "grid-template") {
|
|
2337
|
+
for (let token = arena.firstToken[node]; token != 0; token = arena.nextSibling[token]) {
|
|
2338
|
+
if (arena.dataTypes[token] == EnumToken.StringTokenType) {
|
|
2339
|
+
const str = arena.strings[arena.stringValue[token]];
|
|
2340
|
+
const tokens = parseString(arena, str.slice(1, -1));
|
|
2341
|
+
// inlined: arena.walkValues(tokens)
|
|
2342
|
+
for (const value of new ValueWalker(arena, tokens)) {
|
|
2343
|
+
if (arena.dataTypes[value] == EnumToken.IdenTokenType ||
|
|
2344
|
+
arena.dataTypes[value] == EnumToken.DashedIdenTokenType) {
|
|
2345
|
+
if (arena.strings[arena.stringValue[value]] in mapping) {
|
|
2346
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
2347
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
2574
2348
|
}
|
|
2575
2349
|
else {
|
|
2576
2350
|
let result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2577
|
-
? value
|
|
2578
|
-
: moduleSettings.generateScopedName(value
|
|
2351
|
+
? arena.strings[arena.stringValue[value]]
|
|
2352
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[value]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2579
2353
|
// @ts-expect-error
|
|
2580
2354
|
if (result instanceof Promise) {
|
|
2581
2355
|
result = await result;
|
|
2582
2356
|
}
|
|
2583
|
-
mapping[value
|
|
2584
|
-
revMapping[result] = value
|
|
2585
|
-
value
|
|
2357
|
+
mapping[arena.strings[arena.stringValue[value]]] = result;
|
|
2358
|
+
revMapping[result] = arena.strings[arena.stringValue[value]];
|
|
2359
|
+
// inlined: arena.setStr(value, result)
|
|
2360
|
+
arena.stringValue[value] = arena.internString(result);
|
|
2586
2361
|
}
|
|
2587
2362
|
}
|
|
2588
2363
|
}
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
renderTokens(tokens) +
|
|
2592
|
-
node.val[i].val.charAt(node.val[i].val.length - 1);
|
|
2364
|
+
// inlined: arena.setStr(token, str.charAt(0) + renderTokens(arena, tokens) + str.charAt(str.length - 1))
|
|
2365
|
+
arena.stringValue[token] = arena.internString((str.charAt(0) + renderTokens(arena, tokens) + str.charAt(str.length - 1)));
|
|
2593
2366
|
}
|
|
2594
2367
|
}
|
|
2595
2368
|
}
|
|
2596
|
-
else if (node
|
|
2597
|
-
node
|
|
2598
|
-
|
|
2599
|
-
|
|
2369
|
+
else if (arena.strings[arena.name[node]] == "animation" ||
|
|
2370
|
+
arena.strings[arena.name[node]] == "animation-name") {
|
|
2371
|
+
// inlined: arena.walkValues(node as AstNode)
|
|
2372
|
+
for (const value of new ValueWalker(arena, node)) {
|
|
2373
|
+
if (arena.dataTypes[value] == EnumToken.IdenTokenType &&
|
|
2600
2374
|
![
|
|
2601
2375
|
"none",
|
|
2602
2376
|
"infinite",
|
|
@@ -2625,86 +2399,90 @@ async function doParse(iter, options = {}) {
|
|
|
2625
2399
|
"inherit",
|
|
2626
2400
|
"initial",
|
|
2627
2401
|
"unset",
|
|
2628
|
-
].includes(value
|
|
2629
|
-
if (!(value
|
|
2402
|
+
].includes(arena.strings[arena.stringValue[value]])) {
|
|
2403
|
+
if (!(arena.strings[arena.stringValue[value]] in mapping)) {
|
|
2630
2404
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2631
|
-
? value
|
|
2632
|
-
: moduleSettings.generateScopedName(value
|
|
2405
|
+
? arena.strings[arena.stringValue[value]]
|
|
2406
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[value]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2633
2407
|
// @ts-expect-error
|
|
2634
|
-
mapping[value
|
|
2635
|
-
revMapping[mapping[value
|
|
2408
|
+
mapping[arena.strings[arena.stringValue[value]]] = result instanceof Promise ? await result : result;
|
|
2409
|
+
revMapping[mapping[arena.strings[arena.stringValue[value]]]] = arena.strings[arena.stringValue[value]];
|
|
2636
2410
|
}
|
|
2637
|
-
value
|
|
2411
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
2412
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
2638
2413
|
}
|
|
2639
2414
|
}
|
|
2640
2415
|
}
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2416
|
+
// inlined: arena.walkValues(node as AstNode)
|
|
2417
|
+
for (const value of new ValueWalker(arena, node)) {
|
|
2418
|
+
if (arena.dataTypes[value] == EnumToken.DashedIdenTokenType) {
|
|
2419
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
2420
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
2644
2421
|
}
|
|
2645
|
-
else if ((value
|
|
2646
|
-
value
|
|
2647
|
-
|
|
2648
|
-
// @ts-ignore
|
|
2649
|
-
parent, value, importedCssVariables[value.val].val);
|
|
2422
|
+
else if ((arena.dataTypes[value] == EnumToken.IdenTokenType || isIdentColor(arena, value)) &&
|
|
2423
|
+
arena.strings[arena.stringValue[value]] in importedCssVariables) {
|
|
2424
|
+
arena.replaceToken(value, ...arena.tokens(importedCssVariables[arena.strings[arena.stringValue[value]]][ARENAID]).map((token) => arena.clone(token, true)));
|
|
2650
2425
|
}
|
|
2651
2426
|
}
|
|
2652
2427
|
}
|
|
2653
|
-
else if (
|
|
2428
|
+
else if (nodeType == EnumToken.RuleNodeType) {
|
|
2654
2429
|
// if (node[TOKENS] == null) {
|
|
2655
|
-
const tokens = parseString(node
|
|
2656
|
-
matchSelectorSyntax(tokens, [], options);
|
|
2657
|
-
node
|
|
2658
|
-
// }
|
|
2430
|
+
const tokens = parseString(arena, arena.strings[arena.name[node]]);
|
|
2431
|
+
matchSelectorSyntax(arena, tokens, [], options);
|
|
2432
|
+
arena.setTokenList(node, trimArray(arena, tokens));
|
|
2659
2433
|
let hasIdOrClass = false;
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
const val = value.val.toLowerCase();
|
|
2434
|
+
// inlined: arena.walkValues(node as AstNode, filter)
|
|
2435
|
+
for (const value of new ValueWalker(arena, node, (arena, value) => {
|
|
2436
|
+
if (arena.dataTypes[value] == EnumToken.PseudoClassTokenType ||
|
|
2437
|
+
arena.dataTypes[value] == EnumToken.PseudoElementTokenType) {
|
|
2438
|
+
const val = arena.strings[arena.stringValue[value]].toLowerCase();
|
|
2666
2439
|
switch (val) {
|
|
2667
2440
|
case ":local":
|
|
2668
2441
|
case ":global":
|
|
2669
2442
|
{
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2443
|
+
// remove the pseudo class and the following whitespace
|
|
2444
|
+
const next = arena.nextSibling[value];
|
|
2445
|
+
arena.detach(value);
|
|
2446
|
+
if (next != 0 &&
|
|
2447
|
+
(arena.dataTypes[next] == EnumToken.WhitespaceTokenType ||
|
|
2448
|
+
arena.dataTypes[next] == EnumToken.DescendantCombinatorTokenType)) {
|
|
2449
|
+
arena.detach(next);
|
|
2676
2450
|
}
|
|
2677
2451
|
}
|
|
2678
2452
|
break;
|
|
2679
2453
|
}
|
|
2680
2454
|
}
|
|
2681
|
-
else if (value
|
|
2682
|
-
switch (value.
|
|
2455
|
+
else if (arena.dataTypes[value] == EnumToken.PseudoClassFuncTokenType) {
|
|
2456
|
+
switch (arena.strings[arena.stringValue[value]].toLowerCase()) {
|
|
2683
2457
|
case ":global":
|
|
2684
|
-
for (const token of value
|
|
2458
|
+
for (const token of arena.tokens(value)) {
|
|
2685
2459
|
global.add(token);
|
|
2686
2460
|
}
|
|
2687
|
-
case ":local":
|
|
2688
|
-
|
|
2689
|
-
|
|
2461
|
+
case ":local": {
|
|
2462
|
+
// replace the function by its arguments. the arguments are visited
|
|
2463
|
+
const children = arena.tokens(value);
|
|
2464
|
+
arena.replaceToken(value, ...children);
|
|
2465
|
+
return children;
|
|
2466
|
+
}
|
|
2690
2467
|
}
|
|
2691
2468
|
}
|
|
2469
|
+
return null;
|
|
2692
2470
|
})) {
|
|
2693
|
-
if (value
|
|
2471
|
+
if (arena.dataTypes[value] == EnumToken.HashTokenType || arena.dataTypes[value] == EnumToken.ClassSelectorTokenType) {
|
|
2694
2472
|
hasIdOrClass = true;
|
|
2695
2473
|
}
|
|
2696
2474
|
if (processed.has(value)) {
|
|
2697
2475
|
continue;
|
|
2698
2476
|
}
|
|
2699
2477
|
processed.add(value);
|
|
2700
|
-
if (value
|
|
2701
|
-
else if (value
|
|
2478
|
+
if (arena.dataTypes[value] == EnumToken.PseudoClassTokenType || arena.dataTypes[value] == EnumToken.PseudoElementTokenType) ;
|
|
2479
|
+
else if (arena.dataTypes[value] == EnumToken.PseudoClassFuncTokenType) ;
|
|
2702
2480
|
else {
|
|
2703
2481
|
if (global.has(value)) {
|
|
2704
2482
|
continue;
|
|
2705
2483
|
}
|
|
2706
|
-
if (value
|
|
2707
|
-
const val = value.
|
|
2484
|
+
if (arena.dataTypes[value] == EnumToken.ClassSelectorTokenType) {
|
|
2485
|
+
const val = arena.strings[arena.stringValue[value]].slice(1);
|
|
2708
2486
|
if (!(val in mapping)) {
|
|
2709
2487
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2710
2488
|
? val
|
|
@@ -2718,48 +2496,52 @@ async function doParse(iter, options = {}) {
|
|
|
2718
2496
|
: value;
|
|
2719
2497
|
revMapping[mapping[val]] = val;
|
|
2720
2498
|
}
|
|
2721
|
-
value
|
|
2499
|
+
// inlined: arena.setStr(value, "." + mapping[val])
|
|
2500
|
+
arena.stringValue[value] = arena.internString(("." + mapping[val]));
|
|
2722
2501
|
}
|
|
2723
2502
|
}
|
|
2724
2503
|
}
|
|
2725
2504
|
if (moduleSettings.scoped & ModuleScopeEnumOptions.Pure) {
|
|
2726
2505
|
if (!hasIdOrClass) {
|
|
2727
|
-
throw new Error(
|
|
2506
|
+
throw new Error(
|
|
2507
|
+
// inlined: options.source?.getOffsets?.(arena.getSpanStart(node as AstNode))
|
|
2508
|
+
`pure module: No id or class found in selector '${arena.strings[arena.name[node]]}' at '${(options.source?.lineStarts.getOffsets(arena.getSpanStart(node)) ?? []).join(":")}'`);
|
|
2728
2509
|
}
|
|
2729
2510
|
}
|
|
2730
|
-
node.
|
|
2731
|
-
|
|
2732
|
-
node.sel += renderValue(token);
|
|
2733
|
-
}
|
|
2511
|
+
// inlined: arena.setSelector(node as AstNode, arena.tokens(node as AstNode).reduce((acc: string, token: Token) => acc + renderValue(arena, token), ""))
|
|
2512
|
+
arena.name[node] = arena.internString(arena.tokens(node).reduce((acc, token) => acc + renderValue(arena, token), ""));
|
|
2734
2513
|
}
|
|
2735
|
-
else if (
|
|
2736
|
-
const val = node.
|
|
2737
|
-
if (node
|
|
2738
|
-
node
|
|
2514
|
+
else if (nodeType == EnumToken.AtRuleNodeType || nodeType == EnumToken.KeyframesAtRuleNodeType) {
|
|
2515
|
+
const val = arena.strings[arena.name[node]].toLowerCase();
|
|
2516
|
+
if (arena.firstToken[node] == 0) {
|
|
2517
|
+
// inlined: arena.setTokens(node as AstNode, ...parseString(arena, arena.strings[arena.stringValue[node as AstNode]]))
|
|
2518
|
+
arena.setTokenList(node, parseString(arena, arena.strings[arena.stringValue[node]]));
|
|
2739
2519
|
}
|
|
2740
2520
|
if (val == "property" || val == "keyframes") {
|
|
2741
2521
|
const prefix = val == "property" ? "--" : "";
|
|
2742
|
-
for (const value of node
|
|
2743
|
-
if ((prefix == "--" && value
|
|
2744
|
-
(prefix == "" && value
|
|
2745
|
-
if (!(value
|
|
2522
|
+
for (const value of arena.tokens(node)) {
|
|
2523
|
+
if ((prefix == "--" && arena.dataTypes[value] == EnumToken.DashedIdenTokenType) ||
|
|
2524
|
+
(prefix == "" && arena.dataTypes[value] == EnumToken.IdenTokenType)) {
|
|
2525
|
+
if (!(arena.strings[arena.stringValue[value]] in mapping)) {
|
|
2746
2526
|
const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
|
|
2747
|
-
? value
|
|
2748
|
-
: moduleSettings.generateScopedName(value
|
|
2527
|
+
? arena.strings[arena.stringValue[value]]
|
|
2528
|
+
: moduleSettings.generateScopedName(arena.strings[arena.stringValue[value]], moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
2749
2529
|
// @ts-expect-error
|
|
2750
2530
|
let val = result instanceof Promise ? await result : result;
|
|
2751
|
-
mapping[value
|
|
2531
|
+
mapping[arena.strings[arena.stringValue[value]]] =
|
|
2752
2532
|
prefix +
|
|
2753
2533
|
(moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
|
|
2754
2534
|
moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
|
|
2755
2535
|
? getKeyName(val, moduleSettings.naming)
|
|
2756
2536
|
: val);
|
|
2757
|
-
revMapping[mapping[value
|
|
2537
|
+
revMapping[mapping[arena.strings[arena.stringValue[value]]]] = arena.strings[arena.stringValue[value]];
|
|
2758
2538
|
}
|
|
2759
|
-
value
|
|
2539
|
+
// inlined: arena.setStr(value, mapping[arena.strings[arena.stringValue[value]]])
|
|
2540
|
+
arena.stringValue[value] = arena.internString(mapping[arena.strings[arena.stringValue[value]]]);
|
|
2760
2541
|
}
|
|
2761
2542
|
}
|
|
2762
|
-
node
|
|
2543
|
+
// inlined: arena.setValueString(node as AstNode, renderTokens(arena, arena.tokens(node as AstNode)))
|
|
2544
|
+
arena.stringValue[node] = arena.internString(renderTokens(arena, arena.tokens(node)));
|
|
2763
2545
|
}
|
|
2764
2546
|
}
|
|
2765
2547
|
}
|
|
@@ -2786,110 +2568,115 @@ async function doParse(iter, options = {}) {
|
|
|
2786
2568
|
}
|
|
2787
2569
|
return result;
|
|
2788
2570
|
}
|
|
2789
|
-
function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
2571
|
+
function parseNode(arena, tokens, context, options, errors, stats, invalidNodes, parensMatch) {
|
|
2790
2572
|
let i = 0;
|
|
2791
|
-
|
|
2573
|
+
const contextType = arena.dataTypes[context];
|
|
2574
|
+
const dataTypes = arena.dataTypes;
|
|
2575
|
+
const lastToken = tokens[tokens.length - 1];
|
|
2576
|
+
if (lastToken != null && dataTypes[lastToken] === EnumToken.EOFTokenType) {
|
|
2792
2577
|
tokens.pop();
|
|
2793
2578
|
// check parenthesis are balanced
|
|
2794
|
-
let matchCount =
|
|
2795
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
2796
|
-
const token = tokens[i];
|
|
2797
|
-
if (token.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(token.typ)) {
|
|
2798
|
-
matchCount++;
|
|
2799
|
-
}
|
|
2800
|
-
else if (token.typ === EnumToken.EndParensTokenType) {
|
|
2801
|
-
matchCount--;
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2579
|
+
let matchCount = parensMatch;
|
|
2804
2580
|
if (matchCount > 0) {
|
|
2805
2581
|
let k = tokens.length;
|
|
2806
2582
|
while (k-- > 0 &&
|
|
2807
|
-
(tokens[k]
|
|
2583
|
+
(dataTypes[tokens[k]] === EnumToken.WhitespaceTokenType || dataTypes[tokens[k]] === EnumToken.CommentTokenType))
|
|
2808
2584
|
;
|
|
2809
|
-
if (tokens[k]
|
|
2585
|
+
if (dataTypes[tokens[k]] == EnumToken.SemiColonTokenType) {
|
|
2810
2586
|
matchCount = 0;
|
|
2811
2587
|
}
|
|
2812
2588
|
while (matchCount > 0) {
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
});
|
|
2589
|
+
const closing = arena.createToken(EnumToken.EndParensTokenType);
|
|
2590
|
+
if (k >= 0) {
|
|
2591
|
+
arena.copyLocation(closing, tokens[k]);
|
|
2592
|
+
}
|
|
2593
|
+
tokens.push(closing);
|
|
2819
2594
|
matchCount--;
|
|
2820
2595
|
}
|
|
2821
2596
|
}
|
|
2822
2597
|
}
|
|
2823
2598
|
for (; i < tokens.length; i++) {
|
|
2824
|
-
if (tokens[i]
|
|
2599
|
+
if (arena.dataTypes[tokens[i]] === EnumToken.CDOCOMMTokenType && contextType !== EnumToken.StyleSheetNodeType) {
|
|
2825
2600
|
errors.push({
|
|
2826
2601
|
action: "drop",
|
|
2827
2602
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
2828
2603
|
node: tokens[i],
|
|
2829
|
-
|
|
2604
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[i]))
|
|
2605
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[i]))],
|
|
2830
2606
|
});
|
|
2831
|
-
|
|
2607
|
+
// the misplaced CDO / CDC comment is rendered as an empty string
|
|
2608
|
+
arena.dataTypes[tokens[i]] = EnumToken.BadCdoTokenType;
|
|
2832
2609
|
continue;
|
|
2833
2610
|
}
|
|
2834
|
-
if (tokens[i]
|
|
2835
|
-
tokens[i]
|
|
2836
|
-
tokens[i]
|
|
2611
|
+
if (arena.dataTypes[tokens[i]] === EnumToken.CommentTokenType ||
|
|
2612
|
+
arena.dataTypes[tokens[i]] === EnumToken.CDOCOMMTokenType ||
|
|
2613
|
+
arena.dataTypes[tokens[i]] === EnumToken.WhitespaceTokenType) {
|
|
2837
2614
|
continue;
|
|
2838
2615
|
}
|
|
2839
2616
|
break;
|
|
2840
2617
|
}
|
|
2841
2618
|
if (i > 0) {
|
|
2842
|
-
context
|
|
2619
|
+
// the leading comments are appended to the context, then removed with the whitespace (no array is created)
|
|
2620
|
+
for (let k = 0; k < i; k++) {
|
|
2621
|
+
if (arena.dataTypes[tokens[k]] !== EnumToken.WhitespaceTokenType) {
|
|
2622
|
+
// inlined: arena.appendChildren(context, createCommentNode(arena, tokens[k]))
|
|
2623
|
+
arena.appendChildList(context, [createCommentNode(arena, tokens[k])]);
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
tokens.copyWithin(0, i);
|
|
2627
|
+
tokens.length -= i;
|
|
2843
2628
|
i = 0;
|
|
2844
2629
|
}
|
|
2845
2630
|
for (; i < tokens.length; i++) {
|
|
2846
|
-
if (tokens[i]
|
|
2847
|
-
if (tokens[i]
|
|
2631
|
+
if (arena.dataTypes[tokens[i]] == EnumToken.CommentTokenType || arena.dataTypes[tokens[i]] == EnumToken.CDOCOMMTokenType) {
|
|
2632
|
+
if (arena.dataTypes[tokens[i]] == EnumToken.CDOCOMMTokenType && contextType != EnumToken.StyleSheetNodeType) {
|
|
2848
2633
|
errors.push({
|
|
2849
2634
|
action: "drop",
|
|
2850
2635
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
2851
2636
|
node: tokens[i],
|
|
2852
|
-
|
|
2637
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(tokens[i]))
|
|
2638
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(tokens[i]))],
|
|
2853
2639
|
});
|
|
2854
|
-
|
|
2640
|
+
// the misplaced CDO / CDC comment is rendered as an empty string
|
|
2641
|
+
arena.dataTypes[tokens[i]] = EnumToken.BadCdoTokenType;
|
|
2855
2642
|
continue;
|
|
2856
2643
|
}
|
|
2857
|
-
|
|
2858
|
-
|
|
2644
|
+
// inlined: arena.appendChildren(context, createCommentNode(arena, tokens[i]))
|
|
2645
|
+
arena.appendChildList(context, [createCommentNode(arena, tokens[i])]);
|
|
2859
2646
|
stats.nodesCount++;
|
|
2860
2647
|
}
|
|
2861
|
-
else if (tokens[i]
|
|
2648
|
+
else if (arena.dataTypes[tokens[i]] != EnumToken.WhitespaceTokenType) {
|
|
2862
2649
|
break;
|
|
2863
2650
|
}
|
|
2864
2651
|
}
|
|
2865
2652
|
if (tokens.length == 0) {
|
|
2866
2653
|
return null;
|
|
2867
2654
|
}
|
|
2868
|
-
let delim = tokens.
|
|
2869
|
-
if (delim
|
|
2870
|
-
delim
|
|
2871
|
-
delim
|
|
2655
|
+
let delim = tokens[tokens.length - 1];
|
|
2656
|
+
if (arena.dataTypes[delim] == EnumToken.SemiColonTokenType ||
|
|
2657
|
+
arena.dataTypes[delim] == EnumToken.BlockStartTokenType ||
|
|
2658
|
+
arena.dataTypes[delim] == EnumToken.BlockEndTokenType) {
|
|
2872
2659
|
tokens.pop();
|
|
2873
2660
|
}
|
|
2874
2661
|
if (tokens.length == 0) {
|
|
2875
2662
|
return null;
|
|
2876
2663
|
}
|
|
2877
|
-
if (tokens[0]
|
|
2664
|
+
if (arena.dataTypes[tokens[0]] == EnumToken.AtRuleTokenType) {
|
|
2878
2665
|
let nestedRule = false;
|
|
2879
2666
|
let parent = context;
|
|
2880
2667
|
let node;
|
|
2881
|
-
while (parent !=
|
|
2882
|
-
if (parent
|
|
2668
|
+
while (parent != 0) {
|
|
2669
|
+
if (arena.dataTypes[parent] == EnumToken.RuleNodeType) {
|
|
2883
2670
|
nestedRule = true;
|
|
2884
2671
|
break;
|
|
2885
2672
|
}
|
|
2886
|
-
parent = parent
|
|
2673
|
+
parent = arena.parents[parent];
|
|
2887
2674
|
}
|
|
2888
|
-
node = parseAtRule(tokens, context, { ...options, nestedRule }, errors, delim
|
|
2675
|
+
node = parseAtRule(arena, tokens, context, { ...options, nestedRule }, errors, arena.dataTypes[delim] == EnumToken.BlockStartTokenType);
|
|
2889
2676
|
if (node == null) {
|
|
2890
2677
|
return null;
|
|
2891
2678
|
}
|
|
2892
|
-
if (node
|
|
2679
|
+
if (arena.flags[node] &
|
|
2893
2680
|
(EnumAstNodeStatus.Invalid |
|
|
2894
2681
|
EnumAstNodeStatus.Disallowed |
|
|
2895
2682
|
EnumAstNodeStatus.Unknown |
|
|
@@ -2898,48 +2685,47 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2898
2685
|
invalidNodes.push(node);
|
|
2899
2686
|
}
|
|
2900
2687
|
stats.nodesCount++;
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
node[PARENT] = context;
|
|
2904
|
-
// @ts-ignore
|
|
2688
|
+
// inlined: arena.appendChildren(context, node)
|
|
2689
|
+
arena.appendChildList(context, [node]);
|
|
2905
2690
|
return node;
|
|
2906
2691
|
}
|
|
2907
2692
|
else {
|
|
2908
2693
|
stats.nodesCount++;
|
|
2909
2694
|
// rule
|
|
2910
|
-
if (delim
|
|
2911
|
-
const node = parseSelector(tokens, context, options, errors);
|
|
2912
|
-
|
|
2913
|
-
node
|
|
2914
|
-
node
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2695
|
+
if (arena.dataTypes[delim] == EnumToken.BlockStartTokenType) {
|
|
2696
|
+
const node = parseSelector(arena, tokens, context, options, errors);
|
|
2697
|
+
// inlined: arena.appendChildren(context, node)
|
|
2698
|
+
arena.appendChildList(context, [node]);
|
|
2699
|
+
if (arena.flags[node] &
|
|
2700
|
+
(EnumAstNodeStatus.Invalid |
|
|
2701
|
+
EnumAstNodeStatus.Disallowed |
|
|
2702
|
+
EnumAstNodeStatus.Unknown |
|
|
2703
|
+
EnumAstNodeStatus.Unparsed |
|
|
2704
|
+
EnumAstNodeStatus.Malformed)) {
|
|
2920
2705
|
invalidNodes.push(node);
|
|
2921
2706
|
}
|
|
2922
2707
|
return node;
|
|
2923
2708
|
}
|
|
2924
2709
|
else {
|
|
2925
|
-
const node = parseDeclaration(tokens, context, options, errors);
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
node[STATE] |=
|
|
2710
|
+
const node = parseDeclaration(arena, tokens, context, options, errors);
|
|
2711
|
+
if (contextType === EnumToken.StyleSheetNodeType &&
|
|
2712
|
+
arena.dataTypes[node] === EnumToken.DeclarationNodeType) {
|
|
2713
|
+
arena.flags[node] |=
|
|
2930
2714
|
EnumAstNodeStatus.Invalid &
|
|
2931
2715
|
~(EnumAstNodeStatus.Validated | EnumAstNodeStatus.Unvalidated | EnumAstNodeStatus.Unparsed);
|
|
2932
2716
|
errors.push({
|
|
2933
2717
|
message: "<declaration> not allowed in <stylesheet>",
|
|
2934
2718
|
action: "drop",
|
|
2935
2719
|
node,
|
|
2936
|
-
|
|
2720
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(node))
|
|
2721
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(node))],
|
|
2937
2722
|
});
|
|
2938
2723
|
}
|
|
2939
|
-
else if (options.lenient || node
|
|
2940
|
-
|
|
2724
|
+
else if (options.lenient || arena.dataTypes[node] === EnumToken.DeclarationNodeType) {
|
|
2725
|
+
// inlined: arena.appendChildren(context, node)
|
|
2726
|
+
arena.appendChildList(context, [node]);
|
|
2941
2727
|
}
|
|
2942
|
-
if (node
|
|
2728
|
+
if (arena.flags[node] &
|
|
2943
2729
|
(EnumAstNodeStatus.Invalid |
|
|
2944
2730
|
EnumAstNodeStatus.Disallowed |
|
|
2945
2731
|
EnumAstNodeStatus.Unknown |
|
|
@@ -2958,166 +2744,151 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2958
2744
|
* @param errors
|
|
2959
2745
|
* @param parseAsBlock
|
|
2960
2746
|
*/
|
|
2961
|
-
function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
2747
|
+
function parseAtRule(arena, stream, context, options, errors, parseAsBlock = null) {
|
|
2962
2748
|
let success = true;
|
|
2963
|
-
|
|
2749
|
+
const contextType = arena.dataTypes[context];
|
|
2750
|
+
const contextName = contextType === EnumToken.AtRuleNodeType ? arena.strings[arena.name[context]] : null;
|
|
2751
|
+
const atRule = stream.shift();
|
|
2752
|
+
// at-rule name
|
|
2753
|
+
const nam = arena.strings[arena.name[atRule]];
|
|
2754
|
+
let atRuleName = nam;
|
|
2755
|
+
// prelude tokens, state, errors and last token of the at-rule node
|
|
2756
|
+
let atRuleTokens = null;
|
|
2757
|
+
let atRuleState = 0;
|
|
2758
|
+
let atRuleErrors = [];
|
|
2759
|
+
let atRuleEnd = atRule;
|
|
2964
2760
|
if (atRuleName.startsWith("-")) {
|
|
2965
2761
|
atRuleName = atRuleName.replace(/^-[a-z]+-/, "").toLowerCase();
|
|
2966
2762
|
}
|
|
2967
|
-
const
|
|
2968
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + atRule.nam);
|
|
2763
|
+
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + nam);
|
|
2969
2764
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
2970
2765
|
const blockAllowed = syntaxRules?.getBlockRules() != null;
|
|
2971
2766
|
if (syntaxRules == null) {
|
|
2972
2767
|
errors.push({
|
|
2973
2768
|
action: "drop",
|
|
2974
2769
|
node: atRule,
|
|
2975
|
-
|
|
2770
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
2771
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
2976
2772
|
message: "unknown at-rule",
|
|
2977
2773
|
});
|
|
2978
|
-
const result = matchGenericSyntax(stream, options);
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
return Object.assign(atRule, {
|
|
2984
|
-
typ: EnumToken.AtRuleNodeType,
|
|
2985
|
-
val: renderTokens(trimArray(stream), options),
|
|
2986
|
-
...(parseAsBlock ? { chi: [] } : {}),
|
|
2987
|
-
});
|
|
2774
|
+
const result = matchGenericSyntax(arena, stream, options);
|
|
2775
|
+
atRuleTokens = parseTokens(arena, stream);
|
|
2776
|
+
atRuleState = result.success ? EnumAstNodeStatus.Unknown : EnumAstNodeStatus.Invalid;
|
|
2777
|
+
atRuleErrors = result.success ? [errors[errors.length - 1]] : [errors[errors.length - 1], ...result.errors];
|
|
2778
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimArray(arena, stream), options), !!parseAsBlock);
|
|
2988
2779
|
}
|
|
2989
|
-
else if (
|
|
2990
|
-
"page" === context.nam &&
|
|
2991
|
-
pageMarginBoxType.has(atRuleName.toLowerCase())) {
|
|
2780
|
+
else if (contextName === "page" && pageMarginBoxType.has(atRuleName.toLowerCase())) {
|
|
2992
2781
|
if (parseAsBlock === false && syntaxRules.optionalBody === false) {
|
|
2993
2782
|
errors.push({
|
|
2994
2783
|
action: "drop",
|
|
2995
2784
|
node: atRule,
|
|
2996
|
-
|
|
2785
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
2786
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
2997
2787
|
message: parseAsBlock ? "at-rule block not supported" : "at-rule block is required",
|
|
2998
2788
|
});
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
return Object.assign(atRule, {
|
|
3004
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3005
|
-
val: renderTokens(trimArray(stream), options),
|
|
3006
|
-
...(parseAsBlock ? { chi: [] } : {}),
|
|
3007
|
-
});
|
|
2789
|
+
atRuleTokens = parseTokens(arena, stream);
|
|
2790
|
+
atRuleState = EnumAstNodeStatus.Invalid;
|
|
2791
|
+
atRuleErrors = [errors[errors.length - 1]];
|
|
2792
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimArray(arena, stream), options), !!parseAsBlock);
|
|
3008
2793
|
}
|
|
3009
|
-
const token = stream.find((t) => t
|
|
2794
|
+
const token = stream.find((t) => arena.dataTypes[t] != EnumToken.WhitespaceTokenType && arena.dataTypes[t] === EnumToken.CommentTokenType) ?? null;
|
|
3010
2795
|
if (token != null) {
|
|
3011
2796
|
errors.push({
|
|
3012
2797
|
action: "drop",
|
|
3013
2798
|
node: token,
|
|
3014
|
-
|
|
2799
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
2800
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
3015
2801
|
message: `unexpected token`,
|
|
3016
2802
|
});
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
return Object.assign(atRule, {
|
|
3022
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3023
|
-
val: renderTokens(trimArray(stream), options),
|
|
3024
|
-
...(parseAsBlock ? { chi: [] } : {}),
|
|
3025
|
-
});
|
|
2803
|
+
atRuleTokens = parseTokens(arena, stream);
|
|
2804
|
+
atRuleState = EnumAstNodeStatus.Invalid;
|
|
2805
|
+
atRuleErrors = [errors[errors.length - 1]];
|
|
2806
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimArray(arena, stream), options), !!parseAsBlock);
|
|
3026
2807
|
}
|
|
3027
2808
|
}
|
|
3028
2809
|
if (parseAsBlock === null) {
|
|
3029
2810
|
parseAsBlock = blockAllowed;
|
|
3030
2811
|
}
|
|
3031
|
-
if (syntax != null &&
|
|
2812
|
+
if (syntax != null && nam !== "layer" && parseAsBlock !== blockAllowed && !syntaxRules.optionalBody) {
|
|
3032
2813
|
errors.push({
|
|
3033
2814
|
action: "drop",
|
|
3034
2815
|
node: atRule,
|
|
3035
|
-
|
|
2816
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
2817
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3036
2818
|
message: parseAsBlock ? "at-rule block not supported" : "at-rule block is required",
|
|
3037
2819
|
});
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
return Object.assign(atRule, {
|
|
3043
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3044
|
-
val: renderTokens(trimArray(stream), options),
|
|
3045
|
-
...(parseAsBlock ? { chi: [] } : {}),
|
|
3046
|
-
});
|
|
2820
|
+
atRuleTokens = parseTokens(arena, stream);
|
|
2821
|
+
atRuleState = EnumAstNodeStatus.Invalid;
|
|
2822
|
+
atRuleErrors = [errors[errors.length - 1]];
|
|
2823
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimArray(arena, stream), options), !!parseAsBlock);
|
|
3047
2824
|
}
|
|
3048
2825
|
switch (atRuleName) {
|
|
3049
2826
|
case "charset": {
|
|
3050
2827
|
let success = true;
|
|
2828
|
+
// exactly one space is expected. the whitespace text is not stored: check the source
|
|
3051
2829
|
if (stream.length === 0 ||
|
|
3052
|
-
stream[0]
|
|
3053
|
-
stream[0].
|
|
2830
|
+
arena.dataTypes[stream[0]] !== EnumToken.WhitespaceTokenType ||
|
|
2831
|
+
arena.getSpanEnd(stream[0]) - arena.getSpanStart(stream[0]) !== 1 ||
|
|
2832
|
+
// inlined: arena.getSource(stream[0]), options.sourcesMap?.get(...)?.getContent()
|
|
2833
|
+
options.sourcesMap?.get(arena.sources[arena.getSourceId(stream[0])] ?? 0)?.content.charCodeAt(arena.getSpanStart(stream[0])) !==
|
|
2834
|
+
0x20) {
|
|
3054
2835
|
success = false;
|
|
3055
2836
|
errors.push({
|
|
3056
2837
|
action: "drop",
|
|
3057
2838
|
node: stream[0] ?? atRule,
|
|
3058
|
-
|
|
2839
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[0] ?? atRule))
|
|
2840
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[0] ?? atRule))],
|
|
3059
2841
|
message: "expecting <space>",
|
|
3060
2842
|
});
|
|
3061
2843
|
}
|
|
3062
|
-
else if (stream[1]
|
|
2844
|
+
else if (arena.dataTypes[stream[1]] !== EnumToken.StringTokenType) {
|
|
3063
2845
|
success = false;
|
|
3064
2846
|
errors.push({
|
|
3065
2847
|
action: "drop",
|
|
3066
2848
|
node: stream[1] ?? atRule,
|
|
3067
|
-
|
|
2849
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[1] ?? atRule))
|
|
2850
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[1] ?? atRule))],
|
|
3068
2851
|
message: "expecting <string>",
|
|
3069
2852
|
});
|
|
3070
2853
|
}
|
|
3071
|
-
if (success && stream[1].
|
|
2854
|
+
if (success && arena.strings[arena.stringValue[stream[1]]].charCodeAt(0) !== 0x22) {
|
|
3072
2855
|
success = false;
|
|
3073
2856
|
errors.push({
|
|
3074
2857
|
action: "drop",
|
|
3075
2858
|
node: stream[1] ?? atRule,
|
|
3076
|
-
|
|
2859
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[1] ?? atRule))
|
|
2860
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[1] ?? atRule))],
|
|
3077
2861
|
message: "expecting double-quoted string",
|
|
3078
2862
|
});
|
|
3079
2863
|
}
|
|
3080
2864
|
if (!success) {
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
return Object.assign(atRule, {
|
|
3087
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3088
|
-
val: renderTokens(trimArray(stream), options),
|
|
3089
|
-
});
|
|
2865
|
+
atRuleTokens = stream;
|
|
2866
|
+
atRuleState = EnumAstNodeStatus.Invalid;
|
|
2867
|
+
atRuleErrors = [errors[errors.length - 1]];
|
|
2868
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
2869
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimArray(arena, stream), options), false);
|
|
3090
2870
|
}
|
|
3091
2871
|
if (options.removeCharset) {
|
|
3092
2872
|
return null;
|
|
3093
2873
|
}
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
return Object.assign(atRule, {
|
|
3100
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3101
|
-
val: renderTokens(trimArray(stream), options),
|
|
3102
|
-
});
|
|
2874
|
+
atRuleTokens = stream;
|
|
2875
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2876
|
+
atRuleErrors = [];
|
|
2877
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
2878
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimArray(arena, stream), options), false);
|
|
3103
2879
|
}
|
|
3104
2880
|
case "font-feature-values": {
|
|
3105
|
-
const result = parseAtRuleFontFeatureValues(stream, atRule, options);
|
|
2881
|
+
const result = parseAtRuleFontFeatureValues(arena, stream, atRule, options);
|
|
3106
2882
|
if (result.errors.length > 0) {
|
|
3107
2883
|
for (const error of result.errors) {
|
|
3108
2884
|
errors.push(error);
|
|
3109
2885
|
}
|
|
3110
2886
|
}
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
return Object.assign(atRule, {
|
|
3117
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3118
|
-
val: renderTokens(trimWhiteSpaceTokens(stream), options),
|
|
3119
|
-
chi: [],
|
|
3120
|
-
});
|
|
2887
|
+
atRuleTokens = stream;
|
|
2888
|
+
atRuleState = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2889
|
+
atRuleErrors = result.success ? [] : result.errors;
|
|
2890
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
2891
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimWhiteSpaceTokens(arena, stream), options), true);
|
|
3121
2892
|
}
|
|
3122
2893
|
case "stylistic":
|
|
3123
2894
|
case "historical-forms":
|
|
@@ -3125,60 +2896,52 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3125
2896
|
case "swash":
|
|
3126
2897
|
case "ornaments":
|
|
3127
2898
|
case "annotation": {
|
|
3128
|
-
let success =
|
|
2899
|
+
let success = contextName === "font-feature-values";
|
|
3129
2900
|
if (!success) {
|
|
3130
2901
|
errors.push({
|
|
3131
2902
|
action: "drop",
|
|
3132
2903
|
node: atRule,
|
|
3133
|
-
|
|
3134
|
-
|
|
2904
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
2905
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
2906
|
+
message: `unexpected at-rule ${nam}`,
|
|
3135
2907
|
});
|
|
3136
2908
|
}
|
|
3137
2909
|
if (success) {
|
|
3138
2910
|
for (const token of stream) {
|
|
3139
|
-
if (token
|
|
2911
|
+
if (arena.dataTypes[token] !== EnumToken.CommentTokenType && arena.dataTypes[token] !== EnumToken.WhitespaceTokenType) {
|
|
3140
2912
|
success = false;
|
|
3141
2913
|
errors.push({
|
|
3142
2914
|
action: "drop",
|
|
3143
2915
|
node: token,
|
|
3144
|
-
|
|
2916
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(token))
|
|
2917
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(token))],
|
|
3145
2918
|
message: `unexpected token`,
|
|
3146
2919
|
});
|
|
3147
2920
|
}
|
|
3148
2921
|
}
|
|
3149
2922
|
}
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
return Object.assign(atRule, {
|
|
3156
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3157
|
-
val: renderTokens(trimWhiteSpaceTokens(stream), options),
|
|
3158
|
-
chi: [],
|
|
3159
|
-
});
|
|
2923
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
2924
|
+
atRuleTokens = stream;
|
|
2925
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2926
|
+
atRuleErrors = [errors[errors.length - 1]];
|
|
2927
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimWhiteSpaceTokens(arena, stream), options), true);
|
|
3160
2928
|
}
|
|
3161
2929
|
case "container": {
|
|
3162
|
-
const result = parseAtRuleContainerQueryList(stream, atRule, options);
|
|
2930
|
+
const result = parseAtRuleContainerQueryList(arena, stream, atRule, options);
|
|
3163
2931
|
if (result.errors.length > 0) {
|
|
3164
2932
|
for (const error of result.errors) {
|
|
3165
2933
|
errors.push(error);
|
|
3166
2934
|
}
|
|
3167
2935
|
}
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
return Object.assign(atRule, {
|
|
3174
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3175
|
-
val: renderTokens(trimWhiteSpaceTokens(stream), options),
|
|
3176
|
-
chi: [],
|
|
3177
|
-
});
|
|
2936
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
2937
|
+
atRuleTokens = stream;
|
|
2938
|
+
atRuleState = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2939
|
+
atRuleErrors = result.success ? [] : result.errors;
|
|
2940
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimWhiteSpaceTokens(arena, stream), options), true);
|
|
3178
2941
|
}
|
|
3179
2942
|
case "custom-media": {
|
|
3180
|
-
const tokens = trimArray(stream.slice(1));
|
|
3181
|
-
const result = matchAllSyntaxes(syntax, createValidationContext(tokens), options);
|
|
2943
|
+
const tokens = trimArray(arena, stream.slice(1));
|
|
2944
|
+
const result = matchAllSyntaxes(arena, syntax, createValidationContext(arena, tokens), options);
|
|
3182
2945
|
if (result.errors.length > 0) {
|
|
3183
2946
|
for (const error of result.errors) {
|
|
3184
2947
|
errors.push(error);
|
|
@@ -3186,46 +2949,38 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3186
2949
|
}
|
|
3187
2950
|
// @ts-expect-error
|
|
3188
2951
|
options = { ...options, convertColor: false };
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
return Object.assign(atRule, {
|
|
3195
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3196
|
-
val: renderTokens(trimWhiteSpaceTokens(tokens), options),
|
|
3197
|
-
});
|
|
2952
|
+
atRuleEnd = tokens.at(-1) ?? atRule;
|
|
2953
|
+
atRuleTokens = tokens;
|
|
2954
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed;
|
|
2955
|
+
atRuleErrors = result.success ? [] : result.errors;
|
|
2956
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimWhiteSpaceTokens(arena, tokens), options), false);
|
|
3198
2957
|
}
|
|
3199
2958
|
case "keyframes": {
|
|
3200
|
-
const tokens = trimArray(stream.slice(1));
|
|
3201
|
-
const filtered = stream.filter((t) => t
|
|
2959
|
+
const tokens = trimArray(arena, stream.slice(1));
|
|
2960
|
+
const filtered = stream.filter((t) => arena.dataTypes[t] !== EnumToken.WhitespaceTokenType && arena.dataTypes[t] !== EnumToken.CommentTokenType);
|
|
3202
2961
|
if (filtered.length != 1 ||
|
|
3203
|
-
(filtered[0]
|
|
3204
|
-
filtered[0]
|
|
3205
|
-
filtered[0]
|
|
2962
|
+
(arena.dataTypes[filtered[0]] !== EnumToken.IdenTokenType &&
|
|
2963
|
+
arena.dataTypes[filtered[0]] !== EnumToken.StringTokenType &&
|
|
2964
|
+
arena.dataTypes[filtered[0]] !== EnumToken.DashedIdenTokenType)) {
|
|
3206
2965
|
errors.push({
|
|
3207
2966
|
action: "drop",
|
|
3208
2967
|
node: atRule,
|
|
3209
|
-
|
|
2968
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
2969
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3210
2970
|
message: `expected <keyframe-name>`,
|
|
3211
2971
|
});
|
|
3212
2972
|
success = false;
|
|
3213
2973
|
}
|
|
3214
2974
|
// @ts-expect-error
|
|
3215
2975
|
options = { ...options, convertColor: false };
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
return Object.assign(atRule, {
|
|
3222
|
-
typ: EnumToken.KeyframesAtRuleNodeType,
|
|
3223
|
-
val: renderTokens(tokens, options),
|
|
3224
|
-
chi: [],
|
|
3225
|
-
});
|
|
2976
|
+
atRuleEnd = tokens.at(-1) ?? atRule;
|
|
2977
|
+
atRuleTokens = tokens;
|
|
2978
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2979
|
+
atRuleErrors = success ? [] : [errors[errors.length - 1]];
|
|
2980
|
+
return createAtRuleNode(arena, atRule, EnumToken.KeyframesAtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, tokens, options), true);
|
|
3226
2981
|
}
|
|
3227
2982
|
case "namespace": {
|
|
3228
|
-
const result = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
2983
|
+
const result = matchAllSyntaxes(arena, syntax, createValidationContext(arena, stream), options);
|
|
3229
2984
|
if (!result.success) {
|
|
3230
2985
|
for (const error of result.errors) {
|
|
3231
2986
|
errors.push(error);
|
|
@@ -3240,13 +2995,13 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3240
2995
|
let end = -1;
|
|
3241
2996
|
let hasString = false;
|
|
3242
2997
|
for (start = 0; start < stream.length; start++) {
|
|
3243
|
-
if (stream[start]
|
|
2998
|
+
if (arena.dataTypes[stream[start]] == EnumToken.UrlFunctionTokenDefType) {
|
|
3244
2999
|
start++;
|
|
3245
3000
|
for (end = start; end < stream.length; end++) {
|
|
3246
|
-
if (stream[end]
|
|
3001
|
+
if (arena.dataTypes[stream[end]] == EnumToken.EndParensTokenType) {
|
|
3247
3002
|
break;
|
|
3248
3003
|
}
|
|
3249
|
-
if (stream[end]
|
|
3004
|
+
if (arena.dataTypes[stream[end]] === EnumToken.StringTokenType) {
|
|
3250
3005
|
hasString = true;
|
|
3251
3006
|
}
|
|
3252
3007
|
}
|
|
@@ -3258,91 +3013,77 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3258
3013
|
stream.splice(start - 1, end - start + 2, ...stream.slice(start, end));
|
|
3259
3014
|
}
|
|
3260
3015
|
}
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
(stream.length < index + 3 || stream[index + 2]?.typ === EnumToken.WhitespaceTokenType))
|
|
3273
|
-
? ""
|
|
3274
|
-
: renderValue(t, options)), ""),
|
|
3275
|
-
...(parseAsBlock ? { chi: [] } : {}),
|
|
3276
|
-
});
|
|
3016
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3017
|
+
atRuleTokens = stream.slice();
|
|
3018
|
+
atRuleState = valid ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3019
|
+
atRuleErrors = valid ? [] : result.errors;
|
|
3020
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, trimArray(arena, stream).reduce((acc, t, index) => acc +
|
|
3021
|
+
(arena.dataTypes[t] === EnumToken.CommentTokenType ||
|
|
3022
|
+
(arena.dataTypes[t] === EnumToken.WhitespaceTokenType &&
|
|
3023
|
+
arena.dataTypes[stream[index + 1]] === EnumToken.CommentTokenType &&
|
|
3024
|
+
(stream.length < index + 3 || arena.dataTypes[stream[index + 2]] === EnumToken.WhitespaceTokenType))
|
|
3025
|
+
? ""
|
|
3026
|
+
: renderValue(arena, t, options)), ""), !!parseAsBlock);
|
|
3277
3027
|
}
|
|
3278
3028
|
case "import": {
|
|
3279
|
-
const result = matchAtRuleImportSyntax(atRule, stream,
|
|
3029
|
+
const result = matchAtRuleImportSyntax(arena, atRule, stream, options);
|
|
3280
3030
|
if (result.errors.length > 0) {
|
|
3281
3031
|
for (const error of result.errors) {
|
|
3282
3032
|
errors.push(error);
|
|
3283
3033
|
}
|
|
3284
3034
|
}
|
|
3285
3035
|
else {
|
|
3286
|
-
if (stream[0]
|
|
3287
|
-
stream[0].
|
|
3288
|
-
stream.splice(0, 1, ...stream[0]
|
|
3289
|
-
}
|
|
3290
|
-
}
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
(stream.length < index + 3 || stream[index + 2]?.typ === EnumToken.WhitespaceTokenType))
|
|
3303
|
-
? ""
|
|
3304
|
-
: renderValue(t, options)), ""),
|
|
3305
|
-
});
|
|
3036
|
+
if (arena.dataTypes[stream[0]] == EnumToken.UrlFunctionTokenType &&
|
|
3037
|
+
arena.tokens(stream[0]).some((t) => arena.dataTypes[t] == EnumToken.StringTokenType || arena.dataTypes[t] == EnumToken.UrlTokenTokenType)) {
|
|
3038
|
+
stream.splice(0, 1, ...arena.tokens(stream[0]));
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3042
|
+
atRuleTokens = stream.slice();
|
|
3043
|
+
atRuleState = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3044
|
+
atRuleErrors = result.success ? [] : result.errors;
|
|
3045
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, stream.reduce((acc, t, index) => acc +
|
|
3046
|
+
(arena.dataTypes[t] === EnumToken.CommentTokenType ||
|
|
3047
|
+
(arena.dataTypes[t] === EnumToken.WhitespaceTokenType &&
|
|
3048
|
+
arena.dataTypes[stream[index + 1]] === EnumToken.CommentTokenType &&
|
|
3049
|
+
(stream.length < index + 3 || arena.dataTypes[stream[index + 2]] === EnumToken.WhitespaceTokenType))
|
|
3050
|
+
? ""
|
|
3051
|
+
: renderValue(arena, t, options)), ""), false);
|
|
3306
3052
|
}
|
|
3307
3053
|
case "supports":
|
|
3308
3054
|
case "when":
|
|
3309
3055
|
case "else": {
|
|
3310
|
-
trimWhiteSpaceTokens(stream);
|
|
3056
|
+
trimWhiteSpaceTokens(arena, stream);
|
|
3311
3057
|
const result = atRuleName === "supports"
|
|
3312
|
-
? parseAtRuleSupportSyntax(stream, atRule, options)
|
|
3313
|
-
: matchAtRuleWhenElseSyntax(stream, atRule, options);
|
|
3058
|
+
? parseAtRuleSupportSyntax(arena, stream, atRule, options)
|
|
3059
|
+
: matchAtRuleWhenElseSyntax(arena, stream, atRule, options);
|
|
3314
3060
|
if (result.errors.length > 0) {
|
|
3315
3061
|
for (const error of result.errors) {
|
|
3316
3062
|
errors.push(error);
|
|
3317
3063
|
}
|
|
3318
3064
|
}
|
|
3319
3065
|
let success = result.success;
|
|
3320
|
-
if (
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
siblings[l].typ === EnumToken.CDOCOMMTokenType) {
|
|
3066
|
+
if (nam === "else") {
|
|
3067
|
+
let sibling = arena.lastChild[context];
|
|
3068
|
+
while (sibling != 0) {
|
|
3069
|
+
if (arena.dataTypes[sibling] === EnumToken.WhitespaceTokenType ||
|
|
3070
|
+
arena.dataTypes[sibling] === EnumToken.CommentTokenType ||
|
|
3071
|
+
arena.dataTypes[sibling] === EnumToken.CDOCOMMTokenType) {
|
|
3072
|
+
sibling = arena.previousSibling[sibling];
|
|
3328
3073
|
continue;
|
|
3329
3074
|
}
|
|
3330
|
-
sibling = siblings[l];
|
|
3331
3075
|
break;
|
|
3332
3076
|
}
|
|
3333
3077
|
let missingWhen = false;
|
|
3334
3078
|
let definedAfterLastElse = false;
|
|
3335
|
-
if (sibling ==
|
|
3079
|
+
if (sibling == 0 || arena.dataTypes[sibling] !== EnumToken.AtRuleNodeType) {
|
|
3336
3080
|
missingWhen = true;
|
|
3337
|
-
// @ts-expect-error
|
|
3338
3081
|
}
|
|
3339
|
-
else if (sibling
|
|
3340
|
-
|
|
3341
|
-
if (sibling.nam !== "else") {
|
|
3082
|
+
else if (arena.strings[arena.name[sibling]] !== "when") {
|
|
3083
|
+
if (arena.strings[arena.name[sibling]] !== "else") {
|
|
3342
3084
|
missingWhen = true;
|
|
3343
|
-
// @ts-expect-error
|
|
3344
3085
|
}
|
|
3345
|
-
else if (sibling
|
|
3086
|
+
else if (arena.stringValue[sibling] === 0) {
|
|
3346
3087
|
definedAfterLastElse = true;
|
|
3347
3088
|
}
|
|
3348
3089
|
}
|
|
@@ -3351,7 +3092,8 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3351
3092
|
errors.push({
|
|
3352
3093
|
action: "drop",
|
|
3353
3094
|
node: atRule,
|
|
3354
|
-
|
|
3095
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3096
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3355
3097
|
message: "at-rule @when is required before @else block",
|
|
3356
3098
|
});
|
|
3357
3099
|
}
|
|
@@ -3360,155 +3102,143 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3360
3102
|
errors.push({
|
|
3361
3103
|
action: "drop",
|
|
3362
3104
|
node: atRule,
|
|
3363
|
-
|
|
3105
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3106
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3364
3107
|
message: "at-rule @else block is defined after last @else block",
|
|
3365
3108
|
});
|
|
3366
3109
|
}
|
|
3367
3110
|
}
|
|
3368
3111
|
// @ts-expect-error
|
|
3369
3112
|
options = { ...options, minify: false, convertColor: false };
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
return Object.assign(atRule, {
|
|
3376
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3377
|
-
val: renderTokens(stream, options),
|
|
3378
|
-
chi: [],
|
|
3379
|
-
});
|
|
3113
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3114
|
+
atRuleTokens = stream.slice();
|
|
3115
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3116
|
+
atRuleErrors = result.success ? [] : [errors[errors.length - 1]].concat(result.errors);
|
|
3117
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, stream, options), true);
|
|
3380
3118
|
}
|
|
3381
3119
|
case "media": {
|
|
3382
3120
|
options = { ...options, parseColor: false };
|
|
3383
|
-
const result = parseMediaqueryList(stream, options);
|
|
3121
|
+
const result = parseMediaqueryList(arena, stream, options);
|
|
3384
3122
|
if (result.errors.length > 0) {
|
|
3385
3123
|
for (const error of result.errors) {
|
|
3386
3124
|
errors.push(error);
|
|
3387
3125
|
}
|
|
3388
3126
|
}
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
return Object.assign(atRule, {
|
|
3395
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3396
|
-
val: renderTokens(stream, options),
|
|
3397
|
-
chi: [],
|
|
3398
|
-
});
|
|
3127
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3128
|
+
atRuleTokens = stream.slice();
|
|
3129
|
+
atRuleState = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3130
|
+
atRuleErrors = result.success ? [] : result.errors;
|
|
3131
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, stream, options), true);
|
|
3399
3132
|
}
|
|
3400
3133
|
case "scope": {
|
|
3401
|
-
let context = createValidationContext(trimArray(stream));
|
|
3134
|
+
let context = createValidationContext(arena, trimArray(arena, stream));
|
|
3402
3135
|
let success = true;
|
|
3403
3136
|
// @ts-ignore
|
|
3404
|
-
let range = context.peekRange((t) => t
|
|
3405
|
-
if (range[0]
|
|
3137
|
+
let range = context.peekRange((t) => arena.dataTypes[t] === EnumToken.EndParensTokenType);
|
|
3138
|
+
if (arena.dataTypes[range[0]] !== EnumToken.StartParensTokenType) {
|
|
3406
3139
|
errors.push({
|
|
3407
3140
|
action: "drop",
|
|
3408
3141
|
node: range[0] ?? atRule,
|
|
3409
|
-
|
|
3142
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(range[0] ?? atRule))
|
|
3143
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(range[0] ?? atRule))],
|
|
3410
3144
|
message: "expected '(' at start of @scope block",
|
|
3411
3145
|
});
|
|
3412
3146
|
success = false;
|
|
3147
|
+
// inlined: arena.typeOf(range.at(-1))
|
|
3413
3148
|
}
|
|
3414
|
-
else if (range.at(-1)
|
|
3149
|
+
else if (arena.dataTypes[range.at(-1)] !== EnumToken.EndParensTokenType) {
|
|
3415
3150
|
errors.push({
|
|
3416
3151
|
action: "drop",
|
|
3417
3152
|
node: range.at(-1) ?? atRule,
|
|
3418
|
-
|
|
3153
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(range.at(-1) ?? atRule))
|
|
3154
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(range.at(-1) ?? atRule))],
|
|
3419
3155
|
message: "expected ')' at end of @scope block",
|
|
3420
3156
|
});
|
|
3421
3157
|
success = false;
|
|
3422
3158
|
}
|
|
3423
3159
|
else {
|
|
3424
3160
|
const srange = range.slice(1, -1);
|
|
3425
|
-
const result = matchSelectorSyntax(srange, errors, options, true);
|
|
3161
|
+
const result = matchSelectorSyntax(arena, srange, errors, options, true);
|
|
3426
3162
|
if (!result.success) {
|
|
3427
3163
|
success = false;
|
|
3428
3164
|
}
|
|
3429
3165
|
else {
|
|
3430
|
-
stream.splice(stream.indexOf(range[0]) + 1, range.length - 2, ...trimWhiteSpaceTokens(srange));
|
|
3166
|
+
stream.splice(stream.indexOf(range[0]) + 1, range.length - 2, ...trimWhiteSpaceTokens(arena, srange));
|
|
3431
3167
|
}
|
|
3432
3168
|
}
|
|
3433
3169
|
let index = stream.indexOf(range.at(-1));
|
|
3434
3170
|
if (stream.length > index + 1) {
|
|
3435
|
-
while (stream[++index]
|
|
3436
|
-
stream[index]
|
|
3171
|
+
while (arena.dataTypes[stream[++index]] === EnumToken.WhitespaceTokenType ||
|
|
3172
|
+
arena.dataTypes[stream[index]] === EnumToken.CommentTokenType)
|
|
3437
3173
|
;
|
|
3438
3174
|
if (index < stream.length) {
|
|
3439
|
-
if (stream[index]
|
|
3440
|
-
"to" !== stream[index].
|
|
3175
|
+
if (arena.dataTypes[stream[index]] !== EnumToken.IdenTokenType ||
|
|
3176
|
+
"to" !== arena.strings[arena.stringValue[stream[index]]].toLowerCase()) {
|
|
3441
3177
|
errors.push({
|
|
3442
3178
|
action: "drop",
|
|
3443
3179
|
node: stream[index],
|
|
3444
|
-
|
|
3180
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[index]))
|
|
3181
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[index]))],
|
|
3445
3182
|
message: "expected 'to' at end of @scope block",
|
|
3446
3183
|
});
|
|
3447
3184
|
success = false;
|
|
3448
3185
|
}
|
|
3449
3186
|
else {
|
|
3450
|
-
while (stream[++index]
|
|
3451
|
-
stream[index]
|
|
3187
|
+
while (arena.dataTypes[stream[++index]] === EnumToken.WhitespaceTokenType ||
|
|
3188
|
+
arena.dataTypes[stream[index]] === EnumToken.CommentTokenType)
|
|
3452
3189
|
;
|
|
3453
|
-
if (stream[index]
|
|
3190
|
+
if (arena.dataTypes[stream[index]] !== EnumToken.StartParensTokenType) {
|
|
3454
3191
|
errors.push({
|
|
3455
3192
|
action: "drop",
|
|
3456
3193
|
node: stream[index],
|
|
3457
|
-
|
|
3194
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[index]))
|
|
3195
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[index]))],
|
|
3458
3196
|
message: "expected 'to' at end of @scope block",
|
|
3459
3197
|
});
|
|
3460
3198
|
success = false;
|
|
3461
3199
|
}
|
|
3462
3200
|
else {
|
|
3463
|
-
context = createValidationContext(stream.slice(index));
|
|
3201
|
+
context = createValidationContext(arena, stream.slice(index));
|
|
3464
3202
|
// @ts-ignore
|
|
3465
|
-
range = context.peekRange((t) => t
|
|
3466
|
-
|
|
3203
|
+
range = context.peekRange((t) => arena.dataTypes[t] === EnumToken.EndParensTokenType);
|
|
3204
|
+
// inlined: arena.typeOf(range.at(-1))
|
|
3205
|
+
if (arena.dataTypes[range.at(-1)] !== EnumToken.EndParensTokenType) {
|
|
3467
3206
|
errors.push({
|
|
3468
3207
|
action: "drop",
|
|
3469
3208
|
node: range.at(-1) ?? atRule,
|
|
3470
|
-
|
|
3209
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(range.at(-1) ?? atRule))
|
|
3210
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(range.at(-1) ?? atRule))],
|
|
3471
3211
|
message: "expected ')' at end of @scope block",
|
|
3472
3212
|
});
|
|
3473
3213
|
success = false;
|
|
3474
3214
|
}
|
|
3475
3215
|
else {
|
|
3476
3216
|
const srange = range.slice(1, -1);
|
|
3477
|
-
const result = matchSelectorSyntax(srange, errors, options, true);
|
|
3217
|
+
const result = matchSelectorSyntax(arena, srange, errors, options, true);
|
|
3478
3218
|
if (!result.success) {
|
|
3479
3219
|
success = false;
|
|
3480
3220
|
}
|
|
3481
3221
|
else {
|
|
3482
|
-
stream.splice(stream.indexOf(range[0]) + 1, range.length - 2, ...trimWhiteSpaceTokens(srange));
|
|
3222
|
+
stream.splice(stream.indexOf(range[0]) + 1, range.length - 2, ...trimWhiteSpaceTokens(arena, srange));
|
|
3483
3223
|
}
|
|
3484
3224
|
}
|
|
3485
3225
|
}
|
|
3486
3226
|
}
|
|
3487
3227
|
}
|
|
3488
3228
|
}
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
return Object.assign(atRule, {
|
|
3495
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3496
|
-
val: renderTokens(stream, options),
|
|
3497
|
-
chi: [],
|
|
3498
|
-
});
|
|
3229
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3230
|
+
atRuleTokens = stream.slice();
|
|
3231
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3232
|
+
atRuleErrors = success ? [] : [errors[errors.length - 1]];
|
|
3233
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, stream, options), true);
|
|
3499
3234
|
}
|
|
3500
3235
|
case "page": {
|
|
3501
|
-
trimArray(stream);
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
return Object.assign(atRule, {
|
|
3508
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3509
|
-
val: renderTokens(stream, options),
|
|
3510
|
-
chi: [],
|
|
3511
|
-
});
|
|
3236
|
+
trimArray(arena, stream);
|
|
3237
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3238
|
+
atRuleTokens = stream.slice();
|
|
3239
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3240
|
+
atRuleErrors = success ? [] : [errors[errors.length - 1]];
|
|
3241
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, stream, options), true);
|
|
3512
3242
|
}
|
|
3513
3243
|
case "top-left-corner":
|
|
3514
3244
|
case "top-left":
|
|
@@ -3525,66 +3255,59 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3525
3255
|
case "right-top":
|
|
3526
3256
|
case "right-middle":
|
|
3527
3257
|
case "right-bottom": {
|
|
3528
|
-
if (
|
|
3258
|
+
if (contextName !== "page") {
|
|
3529
3259
|
success = false;
|
|
3530
3260
|
errors.push({
|
|
3531
3261
|
action: "drop",
|
|
3532
3262
|
node: atRule,
|
|
3533
|
-
|
|
3263
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3264
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3534
3265
|
message: "node is allowed only in @page rule",
|
|
3535
3266
|
});
|
|
3536
3267
|
}
|
|
3537
3268
|
else {
|
|
3538
|
-
trimArray(stream);
|
|
3269
|
+
trimArray(arena, stream);
|
|
3539
3270
|
for (let i = 0; i < stream.length; i++) {
|
|
3540
|
-
if (stream[i]
|
|
3541
|
-
stream[i]
|
|
3271
|
+
if (arena.dataTypes[stream[i]] !== EnumToken.WhitespaceTokenType &&
|
|
3272
|
+
arena.dataTypes[stream[i]] !== EnumToken.CommentTokenType) {
|
|
3542
3273
|
success = false;
|
|
3543
3274
|
errors.push({
|
|
3544
3275
|
action: "drop",
|
|
3545
3276
|
node: stream[i],
|
|
3546
|
-
|
|
3277
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(stream[i]))
|
|
3278
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i]))],
|
|
3547
3279
|
message: "expected whitespace or comment",
|
|
3548
3280
|
});
|
|
3549
3281
|
break;
|
|
3550
3282
|
}
|
|
3551
3283
|
}
|
|
3552
3284
|
}
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
return Object.assign(atRule, {
|
|
3559
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3560
|
-
val: renderTokens(stream, options),
|
|
3561
|
-
chi: [],
|
|
3562
|
-
});
|
|
3285
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3286
|
+
atRuleTokens = stream.slice();
|
|
3287
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3288
|
+
atRuleErrors = success ? [] : [errors[errors.length - 1]];
|
|
3289
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, stream, options), true);
|
|
3563
3290
|
}
|
|
3564
3291
|
case "value": {
|
|
3565
3292
|
let index = 0;
|
|
3566
3293
|
let isVarDeclaration = false;
|
|
3567
3294
|
for (; index < stream.length; index++) {
|
|
3568
|
-
if (stream[index]
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
stream
|
|
3574
|
-
|
|
3575
|
-
[LOCSRCID]: stream[index][LOCSRCID],
|
|
3576
|
-
[LOCSTA]: stream[index][LOCSTA],
|
|
3577
|
-
[LOCEND]: stream[index][LOCEND],
|
|
3578
|
-
});
|
|
3295
|
+
if (arena.dataTypes[stream[index]] == EnumToken.PseudoClassTokenType) {
|
|
3296
|
+
const colon = arena.createToken(EnumToken.ColonTokenType);
|
|
3297
|
+
arena.copyLocation(colon, stream[index]);
|
|
3298
|
+
// inlined: arena.setStr(stream[index], arena.strings[arena.stringValue[stream[index]]].slice(1))
|
|
3299
|
+
arena.stringValue[stream[index]] = arena.internString(arena.strings[arena.stringValue[stream[index]]].slice(1));
|
|
3300
|
+
arena.dataTypes[stream[index]] = EnumToken.IdenTokenType;
|
|
3301
|
+
stream.splice(index, 0, colon);
|
|
3579
3302
|
isVarDeclaration = true;
|
|
3580
3303
|
break;
|
|
3581
3304
|
}
|
|
3582
|
-
else if (stream[index]
|
|
3305
|
+
else if (arena.dataTypes[stream[index]] == EnumToken.ColonTokenType) {
|
|
3583
3306
|
isVarDeclaration = true;
|
|
3584
3307
|
break;
|
|
3585
3308
|
}
|
|
3586
|
-
else if (stream[index]
|
|
3587
|
-
equalsIgnoreCase("from", stream[index]
|
|
3309
|
+
else if (arena.dataTypes[stream[index]] == EnumToken.IdenTokenType &&
|
|
3310
|
+
equalsIgnoreCase("from", arena.strings[arena.stringValue[stream[index]]])) {
|
|
3588
3311
|
break;
|
|
3589
3312
|
}
|
|
3590
3313
|
}
|
|
@@ -3592,63 +3315,40 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3592
3315
|
// @value <ident>: <string>; // import from file as alias
|
|
3593
3316
|
// @value id : <declaration-value>; // variable declaration
|
|
3594
3317
|
// @value <ident># from <ident>; // import variables from alias
|
|
3595
|
-
let result = matchAllSyntaxes(syntaxRules?.getPreludeRules()?.slice?.(1), createValidationContext(stream), options);
|
|
3596
|
-
|
|
3597
|
-
|
|
3318
|
+
let result = matchAllSyntaxes(arena, syntaxRules?.getPreludeRules()?.slice?.(1), createValidationContext(arena, stream), options);
|
|
3319
|
+
atRuleState = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3320
|
+
atRuleErrors = success ? [] : [errors[errors.length - 1]];
|
|
3321
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3598
3322
|
if (!result.success) {
|
|
3599
3323
|
for (const error of result.errors) {
|
|
3600
3324
|
errors.push(error);
|
|
3601
3325
|
}
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
[LOCSTA]: atRule[LOCSTA],
|
|
3607
|
-
[LOCEND]: stream.at(-1)?.[LOCEND] ?? atRule[LOCEND],
|
|
3608
|
-
[TOKENS]: stream,
|
|
3609
|
-
[STATE]: EnumAstNodeStatus.Invalid,
|
|
3610
|
-
[ERRORS]: result.errors,
|
|
3611
|
-
};
|
|
3326
|
+
atRuleTokens = stream;
|
|
3327
|
+
atRuleState = EnumAstNodeStatus.Invalid;
|
|
3328
|
+
atRuleErrors = result.errors;
|
|
3329
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, stream, options), false);
|
|
3612
3330
|
}
|
|
3613
3331
|
if (isVarDeclaration) {
|
|
3614
|
-
const nam = stream.find((t) => t
|
|
3615
|
-
const value = trimArray(stream.slice(index + 1).filter((t) => t
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
val: value,
|
|
3635
|
-
[LOCSRCID]: atRule[LOCSRCID],
|
|
3636
|
-
[LOCSTA]: atRule[LOCSTA],
|
|
3637
|
-
[LOCEND]: stream.at(-1)?.[LOCEND] ?? atRule[LOCEND],
|
|
3638
|
-
[TOKENS]: stream,
|
|
3639
|
-
[STATE]: EnumAstNodeStatus.Validated,
|
|
3640
|
-
[ERRORS]: [],
|
|
3641
|
-
};
|
|
3642
|
-
}
|
|
3643
|
-
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
3644
|
-
atRule[STATE] = EnumAstNodeStatus.Validated;
|
|
3645
|
-
atRule[ERRORS] = [];
|
|
3646
|
-
// @ts-expect-error
|
|
3647
|
-
return Object.assign(atRule, {
|
|
3648
|
-
typ: EnumToken.CssVariableDeclarationMapTokenType,
|
|
3649
|
-
vars: trimArray(stream.slice(0, index)),
|
|
3650
|
-
from: stream.slice(index + 1),
|
|
3651
|
-
});
|
|
3332
|
+
const nam = stream.find((t) => arena.dataTypes[t] == EnumToken.IdenTokenType);
|
|
3333
|
+
const value = trimArray(arena, stream.slice(index + 1).filter((t) => arena.dataTypes[t] != EnumToken.CommentTokenType));
|
|
3334
|
+
// import from file as alias: @value <ident>: <string>;
|
|
3335
|
+
// variable declaration: @value <ident>: <declaration-value>;
|
|
3336
|
+
// the variable value is stored as the node values
|
|
3337
|
+
const node = arena.createDeclaration(value.length == 1 && arena.dataTypes[value[0]] == EnumToken.StringTokenType
|
|
3338
|
+
? EnumToken.CssVariableImportTokenType
|
|
3339
|
+
: EnumToken.CssVariableTokenType, arena.strings[arena.stringValue[nam]], value, EnumAstNodeStatus.Validated, []);
|
|
3340
|
+
arena.spanLocation(node, atRule, atRuleEnd);
|
|
3341
|
+
return node;
|
|
3342
|
+
}
|
|
3343
|
+
atRuleState = EnumAstNodeStatus.Validated;
|
|
3344
|
+
atRuleErrors = [];
|
|
3345
|
+
// import variables from alias: @value <ident># from <ident>;
|
|
3346
|
+
// the imported variable names are stored as the node values, the alias tokens as the `l` field
|
|
3347
|
+
const node = arena.createDeclaration(EnumToken.CssVariableDeclarationMapTokenType, nam, trimArray(arena, stream.slice(0, index)), EnumAstNodeStatus.Validated, []);
|
|
3348
|
+
// inlined: arena.setField(node, TokenField.L, ...stream.slice(index + 1))
|
|
3349
|
+
arena.setTokenList(arena.fieldList(node, TokenField.L), stream.slice(index + 1));
|
|
3350
|
+
arena.spanLocation(node, atRule, atRuleEnd);
|
|
3351
|
+
return node;
|
|
3652
3352
|
}
|
|
3653
3353
|
default: {
|
|
3654
3354
|
options = { ...options, parseColor: false };
|
|
@@ -3658,7 +3358,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3658
3358
|
// check commas ',' or ',,'
|
|
3659
3359
|
// check colon ':'
|
|
3660
3360
|
// check 'or' and 'and'
|
|
3661
|
-
result = matchGenericSyntax(stream, options);
|
|
3361
|
+
result = matchGenericSyntax(arena, stream, options);
|
|
3662
3362
|
if (result.errors.length > 0) {
|
|
3663
3363
|
for (const error of result.errors) {
|
|
3664
3364
|
errors.push(error);
|
|
@@ -3666,7 +3366,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3666
3366
|
}
|
|
3667
3367
|
}
|
|
3668
3368
|
else {
|
|
3669
|
-
result = matchAtRuleSyntax(atRule, stream, options);
|
|
3369
|
+
result = matchAtRuleSyntax(arena, atRule, stream, options);
|
|
3670
3370
|
if (result.errors.length > 0) {
|
|
3671
3371
|
for (const error of result.errors) {
|
|
3672
3372
|
errors.push(error);
|
|
@@ -3676,17 +3376,17 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3676
3376
|
let i = 0;
|
|
3677
3377
|
const stack = [];
|
|
3678
3378
|
for (; i < stream.length; i++) {
|
|
3679
|
-
if (stream[i]
|
|
3379
|
+
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType || tokensfuncDefMap.has(arena.dataTypes[stream[i]])) {
|
|
3680
3380
|
stack.push(stream[i]);
|
|
3681
3381
|
continue;
|
|
3682
3382
|
}
|
|
3683
|
-
if (stream[i]
|
|
3383
|
+
if (arena.dataTypes[stream[i]] === EnumToken.EndParensTokenType && stack.length > 0) {
|
|
3684
3384
|
const index = stream.indexOf(stack[stack.length - 1]);
|
|
3685
|
-
stream[index]
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3385
|
+
// inlined: arena.setSpanEnd(stream[index], arena.getSpanEnd(stream[i]))
|
|
3386
|
+
arena.setSpan(stream[index], arena.getSourceId(stream[index]), arena.getSpanStart(stream[index]), arena.getSpanEnd(stream[i]));
|
|
3387
|
+
arena.dataTypes[stream[index]] = tokensfuncDefMap.get(arena.dataTypes[stream[index]]);
|
|
3388
|
+
// inlined: arena.setTokens(stream[index], ...trimWhiteSpaceTokens(arena, stream.splice(index + 1, i - index - 1)))
|
|
3389
|
+
arena.setTokenList(stream[index], trimWhiteSpaceTokens(arena, stream.splice(index + 1, i - index - 1)));
|
|
3690
3390
|
i = index;
|
|
3691
3391
|
stream.splice(index + 1, 1);
|
|
3692
3392
|
stack.pop();
|
|
@@ -3694,86 +3394,108 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3694
3394
|
}
|
|
3695
3395
|
}
|
|
3696
3396
|
}
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
switch (
|
|
3397
|
+
atRuleEnd = stream.at(-1) ?? atRule;
|
|
3398
|
+
atRuleTokens = stream.slice();
|
|
3399
|
+
atRuleState = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3400
|
+
atRuleErrors = result.errors;
|
|
3401
|
+
switch (nam) {
|
|
3702
3402
|
case "mixin":
|
|
3703
|
-
if (
|
|
3704
|
-
|
|
3705
|
-
|
|
3403
|
+
if (contextType != EnumToken.StyleSheetNodeType) {
|
|
3404
|
+
atRuleState |= EnumAstNodeStatus.Disallowed;
|
|
3405
|
+
atRuleErrors.push({
|
|
3406
|
+
action: "drop",
|
|
3706
3407
|
message: "mixin rule cannot be a nested group rule or rule style body",
|
|
3707
|
-
|
|
3408
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3409
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3708
3410
|
});
|
|
3709
3411
|
}
|
|
3710
3412
|
break;
|
|
3711
3413
|
case "contents":
|
|
3712
3414
|
let parent = context;
|
|
3713
|
-
let valid =
|
|
3714
|
-
while (parent !=
|
|
3715
|
-
if (parent
|
|
3415
|
+
let valid = false;
|
|
3416
|
+
while (parent != 0) {
|
|
3417
|
+
if (arena.dataTypes[parent] == EnumToken.AtRuleNodeType &&
|
|
3418
|
+
"mixin" == arena.strings[arena.name[parent]]) {
|
|
3716
3419
|
valid = true;
|
|
3717
3420
|
break;
|
|
3718
3421
|
}
|
|
3719
|
-
parent = parent
|
|
3422
|
+
parent = arena.parents[parent];
|
|
3720
3423
|
}
|
|
3721
3424
|
if (!valid) {
|
|
3722
|
-
|
|
3723
|
-
|
|
3425
|
+
atRuleState |= EnumAstNodeStatus.Disallowed;
|
|
3426
|
+
atRuleErrors.push({
|
|
3427
|
+
action: "drop",
|
|
3724
3428
|
message: "contents rule cannot be used outside mixin rule",
|
|
3725
|
-
|
|
3429
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3430
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3726
3431
|
});
|
|
3727
3432
|
}
|
|
3728
3433
|
break;
|
|
3729
3434
|
case "layer":
|
|
3730
|
-
if (
|
|
3435
|
+
if (contextType != EnumToken.StyleSheetNodeType) {
|
|
3731
3436
|
let parent = context;
|
|
3732
|
-
while (parent !=
|
|
3733
|
-
if (parent
|
|
3734
|
-
|
|
3735
|
-
|
|
3437
|
+
while (parent != 0) {
|
|
3438
|
+
if (arena.dataTypes[parent] == EnumToken.AtRuleNodeType &&
|
|
3439
|
+
arena.strings[arena.name[parent]] == "mixin") {
|
|
3440
|
+
atRuleState |= EnumAstNodeStatus.Disallowed;
|
|
3441
|
+
atRuleErrors.push({
|
|
3442
|
+
action: "drop",
|
|
3736
3443
|
message: "at-rule layeris not allowed inside mixin rule",
|
|
3737
|
-
|
|
3444
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(atRule))
|
|
3445
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(atRule))],
|
|
3738
3446
|
});
|
|
3739
3447
|
break;
|
|
3740
3448
|
}
|
|
3741
|
-
parent = parent
|
|
3449
|
+
parent = arena.parents[parent];
|
|
3742
3450
|
}
|
|
3743
3451
|
}
|
|
3744
3452
|
}
|
|
3745
|
-
|
|
3746
|
-
return Object.assign(atRule, {
|
|
3747
|
-
typ: EnumToken.AtRuleNodeType,
|
|
3748
|
-
val: renderTokens(trimWhiteSpaceTokens(stream), options),
|
|
3749
|
-
...(parseAsBlock ? { chi: [] } : {}),
|
|
3750
|
-
});
|
|
3453
|
+
return createAtRuleNode(arena, atRule, EnumToken.AtRuleNodeType, atRuleTokens, atRuleState, atRuleErrors, atRuleEnd, renderTokens(arena, trimWhiteSpaceTokens(arena, stream), options), !!parseAsBlock);
|
|
3751
3454
|
}
|
|
3752
3455
|
}
|
|
3753
3456
|
}
|
|
3754
3457
|
/**
|
|
3755
|
-
* Parse a string as an array of declaration nodes
|
|
3458
|
+
* Parse a string as an array of declaration nodes.
|
|
3459
|
+
* The nodes are allocated in the given arena, or in a new arena when none is provided
|
|
3756
3460
|
* @param declaration
|
|
3461
|
+
* @param arena
|
|
3757
3462
|
*
|
|
3758
3463
|
* Example:
|
|
3759
3464
|
* ````ts
|
|
3760
3465
|
*
|
|
3761
|
-
* const
|
|
3762
|
-
* console.log(
|
|
3466
|
+
* const {arena, nodes} = parseDeclarations('color: red; background: blue');
|
|
3467
|
+
* console.log(nodes.map((node) => arena.toObject(node)));
|
|
3763
3468
|
* ```
|
|
3764
3469
|
*/
|
|
3765
|
-
function parseDeclarations(declaration) {
|
|
3470
|
+
function parseDeclarations(declaration, arena) {
|
|
3766
3471
|
const stream = `.x{${declaration}}`;
|
|
3472
|
+
const source = new SourceFile(stream, [], "");
|
|
3767
3473
|
const result = doParseSync(new Tokenizer({
|
|
3768
3474
|
stream,
|
|
3769
3475
|
offset: 0,
|
|
3770
3476
|
position: 0,
|
|
3771
|
-
source
|
|
3477
|
+
source,
|
|
3772
3478
|
currentPosition: 0,
|
|
3773
|
-
}), {
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3479
|
+
}), {
|
|
3480
|
+
setParent: false,
|
|
3481
|
+
minify: false,
|
|
3482
|
+
validation: false,
|
|
3483
|
+
arena,
|
|
3484
|
+
source,
|
|
3485
|
+
sourcesMap: new Map([[source.id, source]]),
|
|
3486
|
+
});
|
|
3487
|
+
const rule = result.arena.firstChild[result.ast];
|
|
3488
|
+
const nodes = [];
|
|
3489
|
+
for (let node = rule == 0 ? 0 : result.arena.firstChild[rule]; node != 0;) {
|
|
3490
|
+
const next = result.arena.nextSibling[node];
|
|
3491
|
+
if (result.arena.dataTypes[node] == EnumToken.DeclarationNodeType ||
|
|
3492
|
+
result.arena.dataTypes[node] == EnumToken.CommentNodeType) {
|
|
3493
|
+
result.arena.detach(node);
|
|
3494
|
+
nodes.push(node);
|
|
3495
|
+
}
|
|
3496
|
+
node = next;
|
|
3497
|
+
}
|
|
3498
|
+
return { arena: result.arena, nodes };
|
|
3777
3499
|
}
|
|
3778
3500
|
/**
|
|
3779
3501
|
* Parse css string and return an array of tokens
|
|
@@ -3790,14 +3512,15 @@ function parseDeclarations(declaration) {
|
|
|
3790
3512
|
*
|
|
3791
3513
|
* import {parseString} from '@tbela99/css-parser';
|
|
3792
3514
|
*
|
|
3793
|
-
*
|
|
3794
|
-
*
|
|
3515
|
+
* const arena = new AstArena();
|
|
3516
|
+
* let tokens = parseString(arena, 'body { color: red; }');
|
|
3517
|
+
* console.log(tokens.map((token) => arena.toObject(token)));
|
|
3795
3518
|
*
|
|
3796
|
-
* tokens = parseString('#c322c980');
|
|
3797
|
-
* console.log(tokens);
|
|
3519
|
+
* tokens = parseString(arena, '#c322c980');
|
|
3520
|
+
* console.log(tokens.map((token) => arena.toObject(token)));
|
|
3798
3521
|
* ```
|
|
3799
3522
|
*/
|
|
3800
|
-
function parseString(src, options = { parseColor: true }, errors) {
|
|
3523
|
+
function parseString(arena, src, options = { parseColor: true }, errors) {
|
|
3801
3524
|
const tokenizer = new Tokenizer({
|
|
3802
3525
|
stream: src,
|
|
3803
3526
|
buffer: "",
|
|
@@ -3809,42 +3532,20 @@ function parseString(src, options = { parseColor: true }, errors) {
|
|
|
3809
3532
|
currentPosition: 0,
|
|
3810
3533
|
});
|
|
3811
3534
|
const mapped = [];
|
|
3812
|
-
|
|
3813
|
-
while (!tokenizer.
|
|
3535
|
+
// inlined: tokenizer.done()
|
|
3536
|
+
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
3814
3537
|
tokenizer.next();
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
typ: tokenizer.typ,
|
|
3825
|
-
};
|
|
3826
|
-
}
|
|
3827
|
-
else if (tokenizer.kin != null) {
|
|
3828
|
-
token = {
|
|
3829
|
-
typ: tokenizer.typ,
|
|
3830
|
-
val: tokenizer.val,
|
|
3831
|
-
kin: tokenizer.kin,
|
|
3832
|
-
};
|
|
3538
|
+
// tokens parsed from a string have no location
|
|
3539
|
+
mapped.push(allocateToken(arena, tokenizer, -1));
|
|
3540
|
+
}
|
|
3541
|
+
const result = parseTokens(arena, mapped, options, errors);
|
|
3542
|
+
// remove the EOF token and the whitespace before it: their ids are recycled
|
|
3543
|
+
const removed = result.splice(result.length - (arena.dataTypes[result[result.length - 2]] === EnumToken.WhitespaceTokenType ? 2 : 1), 2);
|
|
3544
|
+
for (let i = 0; i < removed.length; i++) {
|
|
3545
|
+
if (arena.parents[removed[i]] == 0 && arena.firstToken[removed[i]] == 0 && arena.firstChild[removed[i]] == 0) {
|
|
3546
|
+
arena.recycle(removed[i]);
|
|
3833
3547
|
}
|
|
3834
|
-
|
|
3835
|
-
token = {
|
|
3836
|
-
typ: tokenizer.typ,
|
|
3837
|
-
val: tokenizer.val,
|
|
3838
|
-
};
|
|
3839
|
-
}
|
|
3840
|
-
token[LOCSRCID] = tokenizer.source.id;
|
|
3841
|
-
token[LOCEND] = tokenizer.end;
|
|
3842
|
-
token[LOCSTA] = tokenizer.sta;
|
|
3843
|
-
mapped.push(token);
|
|
3844
|
-
}
|
|
3845
|
-
const result = parseTokens(mapped, options, errors);
|
|
3846
|
-
// remove EOF token
|
|
3847
|
-
result.splice(result.length - (result[result.length - 2]?.typ === EnumToken.WhitespaceTokenType ? 2 : 1), 2);
|
|
3548
|
+
}
|
|
3848
3549
|
return result;
|
|
3849
3550
|
}
|
|
3850
3551
|
/**
|
|
@@ -3861,97 +3562,107 @@ function parseString(src, options = { parseColor: true }, errors) {
|
|
|
3861
3562
|
*
|
|
3862
3563
|
* import {parseString, parseTokens} from '@tbela99/css-parser';
|
|
3863
3564
|
*
|
|
3864
|
-
* let tokens = parseString('body { color: red; }');
|
|
3865
|
-
* console.log(parseTokens(tokens));
|
|
3565
|
+
* let tokens = parseString(arena, 'body { color: red; }');
|
|
3566
|
+
* console.log(parseTokens(arena, tokens));
|
|
3866
3567
|
*
|
|
3867
|
-
* tokens = parseString('#c322c980');
|
|
3868
|
-
* console.log(parseTokens(tokens));
|
|
3568
|
+
* tokens = parseString(arena, '#c322c980');
|
|
3569
|
+
* console.log(parseTokens(arena, tokens));
|
|
3869
3570
|
* ```
|
|
3870
3571
|
*
|
|
3871
3572
|
* @private
|
|
3872
3573
|
*/
|
|
3873
|
-
function parseTokens(tokens, options, errors) {
|
|
3574
|
+
function parseTokens(arena, tokens, options, errors) {
|
|
3874
3575
|
const stack = [];
|
|
3875
3576
|
let i = 0;
|
|
3876
3577
|
let index;
|
|
3877
3578
|
let t;
|
|
3579
|
+
let typ;
|
|
3878
3580
|
options ??= { parseColor: true };
|
|
3879
3581
|
for (; i < tokens.length; i++) {
|
|
3880
3582
|
t = tokens[i];
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3583
|
+
typ = arena.dataTypes[t];
|
|
3584
|
+
if (typ === EnumToken.FunctionTokenDefType) {
|
|
3585
|
+
if (i > 0 &&
|
|
3586
|
+
(arena.dataTypes[tokens[i - 1]] === EnumToken.ColonTokenType ||
|
|
3587
|
+
arena.dataTypes[tokens[i - 1]] === EnumToken.DoubleColonTokenType)) {
|
|
3588
|
+
// merge the colon and the function name into a pseudo class function
|
|
3589
|
+
const previous = tokens[i - 1];
|
|
3590
|
+
// inlined: arena.setStr(previous, (arena.dataTypes[previous] === EnumToken.ColonTokenType ? ":" : "::") + arena.strings[arena.stringValue[t]])
|
|
3591
|
+
arena.stringValue[previous] = arena.internString(((arena.dataTypes[previous] === EnumToken.ColonTokenType ? ":" : "::") +
|
|
3592
|
+
arena.strings[arena.stringValue[t]]));
|
|
3593
|
+
arena.dataTypes[previous] = EnumToken.PseudoClassFunctionTokenDefType;
|
|
3594
|
+
// inlined: arena.setSpanEnd(previous, arena.getSpanEnd(t))
|
|
3595
|
+
arena.setSpan(previous, arena.getSourceId(previous), arena.getSpanStart(previous), arena.getSpanEnd(t));
|
|
3890
3596
|
tokens.splice(i--, 1);
|
|
3597
|
+
t = previous;
|
|
3598
|
+
typ = EnumToken.PseudoClassFunctionTokenDefType;
|
|
3891
3599
|
}
|
|
3892
3600
|
}
|
|
3893
|
-
if (
|
|
3894
|
-
|
|
3895
|
-
tokensfuncDefMap.has(
|
|
3601
|
+
if (typ === EnumToken.AttrStartTokenType ||
|
|
3602
|
+
typ === EnumToken.StartParensTokenType ||
|
|
3603
|
+
tokensfuncDefMap.has(typ)) {
|
|
3896
3604
|
stack.push(t);
|
|
3897
3605
|
continue;
|
|
3898
3606
|
}
|
|
3899
|
-
if (
|
|
3607
|
+
if (typ === EnumToken.EndParensTokenType) {
|
|
3900
3608
|
if (stack.length === 0 ||
|
|
3901
|
-
(stack.
|
|
3609
|
+
(arena.dataTypes[stack[stack.length - 1]] !== EnumToken.StartParensTokenType &&
|
|
3610
|
+
!tokensfuncDefMap.has(arena.dataTypes[stack[stack.length - 1]]))) {
|
|
3902
3611
|
// unbalanced parens
|
|
3903
|
-
const node = stack.
|
|
3612
|
+
const node = stack[stack.length - 1];
|
|
3904
3613
|
errors?.push?.({
|
|
3905
3614
|
action: "drop",
|
|
3906
3615
|
message: `Unbalanced token ')'`,
|
|
3907
3616
|
node,
|
|
3908
|
-
|
|
3617
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(node))
|
|
3618
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(node))],
|
|
3909
3619
|
});
|
|
3910
3620
|
// return [];
|
|
3911
3621
|
continue;
|
|
3912
3622
|
}
|
|
3913
3623
|
tokens.splice(i, 1);
|
|
3914
|
-
index = tokens.indexOf(stack.
|
|
3915
|
-
|
|
3916
|
-
|
|
3624
|
+
index = tokens.indexOf(stack[stack.length - 1]);
|
|
3625
|
+
const func = tokens[index];
|
|
3626
|
+
arena.dataTypes[func] =
|
|
3627
|
+
arena.dataTypes[func] === EnumToken.StartParensTokenType
|
|
3917
3628
|
? EnumToken.ParensTokenType
|
|
3918
|
-
: tokensfuncDefMap.get(
|
|
3919
|
-
|
|
3920
|
-
|
|
3629
|
+
: tokensfuncDefMap.get(arena.dataTypes[func]);
|
|
3630
|
+
arena.setTokenList(func, trimArray(arena, tokens.splice(index + 1, i - index - 1)));
|
|
3631
|
+
// inlined: arena.setSpanEnd(func, arena.getSpanEnd(t))
|
|
3632
|
+
arena.setSpan(func, arena.getSourceId(func), arena.getSpanStart(func), arena.getSpanEnd(t));
|
|
3921
3633
|
i = index;
|
|
3922
|
-
if (
|
|
3923
|
-
parseColor(
|
|
3634
|
+
if (arena.dataTypes[func] === EnumToken.ColorTokenType && options?.parseColor) {
|
|
3635
|
+
parseColor(arena, func);
|
|
3924
3636
|
}
|
|
3925
3637
|
stack.pop();
|
|
3926
3638
|
continue;
|
|
3927
3639
|
}
|
|
3928
|
-
if (
|
|
3929
|
-
if (stack.
|
|
3640
|
+
if (typ === EnumToken.AttrEndTokenType) {
|
|
3641
|
+
if (stack.length === 0 || arena.dataTypes[stack[stack.length - 1]] !== EnumToken.AttrStartTokenType) {
|
|
3930
3642
|
// unbalanced
|
|
3931
|
-
const node = stack.
|
|
3643
|
+
const node = stack[stack.length - 1];
|
|
3932
3644
|
errors?.push?.({
|
|
3933
3645
|
action: "drop",
|
|
3934
3646
|
message: `Unbalanced token ']'`,
|
|
3935
3647
|
node,
|
|
3936
|
-
|
|
3648
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(node))
|
|
3649
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(node))],
|
|
3937
3650
|
});
|
|
3938
3651
|
continue;
|
|
3939
3652
|
}
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
attr
|
|
3653
|
+
const attr = stack[stack.length - 1];
|
|
3654
|
+
index = tokens.indexOf(attr);
|
|
3655
|
+
// inlined: arena.setSpanEnd(attr, arena.getSpanEnd(t))
|
|
3656
|
+
arena.setSpan(attr, arena.getSourceId(attr), arena.getSpanStart(attr), arena.getSpanEnd(t));
|
|
3943
3657
|
tokens.splice(i, 1);
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
chi: tokens.splice(index + 1, i - index - 1),
|
|
3947
|
-
});
|
|
3948
|
-
tokens[index] = attr;
|
|
3658
|
+
arena.dataTypes[attr] = EnumToken.AttrTokenType;
|
|
3659
|
+
arena.setTokenList(attr, tokens.splice(index + 1, i - index - 1));
|
|
3949
3660
|
i = index;
|
|
3950
3661
|
stack.pop();
|
|
3951
3662
|
continue;
|
|
3952
3663
|
}
|
|
3953
|
-
if (
|
|
3954
|
-
if (t
|
|
3664
|
+
if (typ == EnumToken.IdenTokenType) {
|
|
3665
|
+
if (arena.strings[arena.stringValue[t]] == "from" && i > 0) {
|
|
3955
3666
|
const left = [];
|
|
3956
3667
|
const right = [];
|
|
3957
3668
|
let foundLeft = 0;
|
|
@@ -3959,13 +3670,13 @@ function parseTokens(tokens, options, errors) {
|
|
|
3959
3670
|
let k = i;
|
|
3960
3671
|
let l = i;
|
|
3961
3672
|
while (k > 0) {
|
|
3962
|
-
if (tokens[k - 1]
|
|
3963
|
-
tokens[k - 1]
|
|
3673
|
+
if (arena.dataTypes[tokens[k - 1]] == EnumToken.CommentTokenType ||
|
|
3674
|
+
arena.dataTypes[tokens[k - 1]] == EnumToken.WhitespaceTokenType) {
|
|
3964
3675
|
left.push(tokens[--k]);
|
|
3965
3676
|
continue;
|
|
3966
3677
|
}
|
|
3967
|
-
if (tokens[k - 1]
|
|
3968
|
-
tokens[k - 1]
|
|
3678
|
+
if (arena.dataTypes[tokens[k - 1]] == EnumToken.IdenTokenType ||
|
|
3679
|
+
arena.dataTypes[tokens[k - 1]] == EnumToken.DashedIdenTokenType) {
|
|
3969
3680
|
foundLeft++;
|
|
3970
3681
|
left.push(tokens[--k]);
|
|
3971
3682
|
continue;
|
|
@@ -3973,11 +3684,13 @@ function parseTokens(tokens, options, errors) {
|
|
|
3973
3684
|
break;
|
|
3974
3685
|
}
|
|
3975
3686
|
while (++l < tokens.length) {
|
|
3976
|
-
if (tokens[l]
|
|
3687
|
+
if (arena.dataTypes[tokens[l]] == EnumToken.CommentTokenType ||
|
|
3688
|
+
arena.dataTypes[tokens[l]] == EnumToken.WhitespaceTokenType) {
|
|
3977
3689
|
right.push(tokens[l]);
|
|
3978
3690
|
continue;
|
|
3979
3691
|
}
|
|
3980
|
-
if (tokens[l]
|
|
3692
|
+
if (arena.dataTypes[tokens[l]] == EnumToken.IdenTokenType ||
|
|
3693
|
+
arena.dataTypes[tokens[l]] == EnumToken.StringTokenType) {
|
|
3981
3694
|
foundRight++;
|
|
3982
3695
|
right.push(tokens[l]);
|
|
3983
3696
|
continue;
|
|
@@ -3985,32 +3698,38 @@ function parseTokens(tokens, options, errors) {
|
|
|
3985
3698
|
break;
|
|
3986
3699
|
}
|
|
3987
3700
|
if (foundLeft > 0 && foundRight == 1) {
|
|
3988
|
-
while (left
|
|
3701
|
+
while (left.length > 0 && arena.dataTypes[left[0]] == EnumToken.WhitespaceTokenType) {
|
|
3989
3702
|
left.shift();
|
|
3990
3703
|
}
|
|
3991
|
-
while (left.
|
|
3704
|
+
while (left.length > 0 && arena.dataTypes[left[left.length - 1]] == EnumToken.WhitespaceTokenType) {
|
|
3992
3705
|
left.pop();
|
|
3993
3706
|
}
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
3707
|
+
// composes selector: l = <ident>+, r = <ident> | <string> | null
|
|
3708
|
+
const composes = arena.createToken(EnumToken.ComposesSelectorNodeType);
|
|
3709
|
+
let from = 0;
|
|
3710
|
+
for (const b of right) {
|
|
3711
|
+
if (from == 0 ||
|
|
3712
|
+
arena.dataTypes[b] == EnumToken.IdenTokenType ||
|
|
3713
|
+
arena.dataTypes[b] == EnumToken.StringTokenType) {
|
|
3714
|
+
from = b;
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
// inlined: arena.setField(composes, TokenField.L, ...left)
|
|
3718
|
+
arena.setTokenList(arena.fieldList(composes, TokenField.L), left);
|
|
3719
|
+
if (from != 0) {
|
|
3720
|
+
// inlined: arena.setField(composes, TokenField.R, from)
|
|
3721
|
+
arena.setTokenList(arena.fieldList(composes, TokenField.R), [from]);
|
|
3722
|
+
}
|
|
3723
|
+
tokens.splice(k, l - k + 1, composes);
|
|
4005
3724
|
i = k;
|
|
4006
3725
|
continue;
|
|
4007
3726
|
}
|
|
4008
3727
|
}
|
|
4009
|
-
else if (options?.parseColor && isColor(t)) {
|
|
4010
|
-
parseColor(t);
|
|
3728
|
+
else if (options?.parseColor && isColor(arena, t)) {
|
|
3729
|
+
parseColor(arena, t);
|
|
4011
3730
|
}
|
|
4012
3731
|
}
|
|
4013
|
-
if (
|
|
3732
|
+
if (typ == EnumToken.WhitespaceTokenType &&
|
|
4014
3733
|
(i == 0 ||
|
|
4015
3734
|
i + 1 == tokens.length ||
|
|
4016
3735
|
[
|
|
@@ -4018,44 +3737,46 @@ function parseTokens(tokens, options, errors) {
|
|
|
4018
3737
|
EnumToken.GteTokenType,
|
|
4019
3738
|
EnumToken.LteTokenType,
|
|
4020
3739
|
EnumToken.ColumnCombinatorTokenType,
|
|
4021
|
-
].includes(tokens[i + 1]
|
|
4022
|
-
(i > 0 && trimWhiteSpace.includes(tokens[i - 1]
|
|
3740
|
+
].includes(arena.dataTypes[tokens[i + 1]]) ||
|
|
3741
|
+
(i > 0 && trimWhiteSpace.includes(arena.dataTypes[tokens[i - 1]])))) {
|
|
4023
3742
|
tokens.splice(i--, 1);
|
|
4024
3743
|
continue;
|
|
4025
3744
|
}
|
|
4026
|
-
if (
|
|
4027
|
-
const
|
|
4028
|
-
if (
|
|
4029
|
-
if (
|
|
4030
|
-
tokens[i + 1]
|
|
3745
|
+
if (typ == EnumToken.ColonTokenType) {
|
|
3746
|
+
const next = i + 1 < tokens.length ? arena.dataTypes[tokens[i + 1]] : undefined;
|
|
3747
|
+
if (next != null) {
|
|
3748
|
+
if (next == EnumToken.FunctionTokenType) {
|
|
3749
|
+
arena.dataTypes[tokens[i + 1]] = EnumToken.PseudoClassFuncTokenType;
|
|
4031
3750
|
}
|
|
4032
|
-
else if (
|
|
4033
|
-
tokens[i + 1]
|
|
4034
|
-
tokens[i + 1]
|
|
3751
|
+
else if (next == EnumToken.IdenTokenType) {
|
|
3752
|
+
// inlined: arena.setStr(tokens[i + 1], ":" + arena.strings[arena.stringValue[tokens[i + 1]]])
|
|
3753
|
+
arena.stringValue[tokens[i + 1]] = arena.internString((":" + arena.strings[arena.stringValue[tokens[i + 1]]]));
|
|
3754
|
+
arena.dataTypes[tokens[i + 1]] = EnumToken.PseudoClassTokenType;
|
|
4035
3755
|
}
|
|
4036
|
-
if (
|
|
3756
|
+
if (next == EnumToken.FunctionTokenType || next == EnumToken.IdenTokenType) {
|
|
4037
3757
|
tokens.splice(i, 1);
|
|
4038
3758
|
i--;
|
|
4039
3759
|
}
|
|
4040
3760
|
}
|
|
4041
3761
|
}
|
|
4042
|
-
if (
|
|
4043
|
-
if (tokens[i + 1]
|
|
3762
|
+
if (typ === EnumToken.CommaTokenType) {
|
|
3763
|
+
if (i + 1 < tokens.length && arena.dataTypes[tokens[i + 1]] === EnumToken.WhitespaceTokenType) {
|
|
4044
3764
|
tokens.splice(i + 1, 1);
|
|
4045
3765
|
}
|
|
4046
|
-
if (tokens[i - 1]
|
|
3766
|
+
if (i > 0 && arena.dataTypes[tokens[i - 1]] === EnumToken.WhitespaceTokenType) {
|
|
4047
3767
|
tokens.splice(i - 1, 1);
|
|
4048
3768
|
i--;
|
|
4049
3769
|
}
|
|
4050
3770
|
}
|
|
4051
3771
|
}
|
|
4052
3772
|
if (stack.length > 0) {
|
|
4053
|
-
const node = stack.
|
|
3773
|
+
const node = stack[stack.length - 1];
|
|
4054
3774
|
errors?.push?.({
|
|
4055
3775
|
action: "drop",
|
|
4056
|
-
message: `Unbalanced token. Expecting ${node
|
|
3776
|
+
message: `Unbalanced token. Expecting ${arena.dataTypes[node] === EnumToken.AttrStartTokenType ? "']'" : ")"}'`,
|
|
4057
3777
|
node,
|
|
4058
|
-
|
|
3778
|
+
// inlined: options.source!.getSourceLocation(arena.getSpanStart(node))
|
|
3779
|
+
location: [options.source.file, ...options.source.lineStarts.getOffsets(arena.getSpanStart(node))],
|
|
4059
3780
|
});
|
|
4060
3781
|
}
|
|
4061
3782
|
return tokens;
|