@tbela99/css-parser 1.5.0 → 1.6.1
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 +59 -0
- package/README.md +10 -10
- package/dist/index-umd-web.js +5998 -4972
- package/dist/index.cjs +6001 -4977
- package/dist/index.d.ts +52 -38
- package/dist/lib/ast/expand.js +21 -7
- package/dist/lib/ast/features/calc.js +17 -55
- package/dist/lib/ast/features/if.js +7 -3
- package/dist/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/lib/ast/features/prefix.js +41 -44
- package/dist/lib/ast/features/shorthand.js +10 -5
- package/dist/lib/ast/features/transform.js +2 -2
- package/dist/lib/ast/math/expression.js +207 -34
- package/dist/lib/ast/minify.js +121 -24
- package/dist/lib/ast/node.js +5 -3
- package/dist/lib/ast/transform/compute.js +37 -5
- package/dist/lib/ast/transform/minify.js +7 -7
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +46 -18
- package/dist/lib/ast/walk.js +28 -4
- package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
- package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
- package/dist/lib/fs/resolve.js +11 -2
- package/dist/lib/parser/declaration/list.js +22 -7
- package/dist/lib/parser/declaration/map.js +26 -8
- package/dist/lib/parser/declaration/set.js +3 -1
- package/dist/lib/parser/linesmap.js +2 -4
- package/dist/lib/parser/parse.js +393 -231
- package/dist/lib/parser/tokenize.js +1478 -819
- package/dist/lib/parser/utils/at-rule-container.js +28 -196
- package/dist/lib/parser/utils/at-rule-generic.js +6 -7
- package/dist/lib/parser/utils/at-rule-import.js +17 -13
- package/dist/lib/parser/utils/at-rule-media.js +36 -19
- package/dist/lib/parser/utils/at-rule-support.js +19 -9
- package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
- package/dist/lib/parser/utils/at-rule.js +0 -18
- package/dist/lib/parser/utils/config.js +1 -1
- package/dist/lib/parser/utils/declaration.js +40 -97
- package/dist/lib/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +179 -224
- package/dist/lib/parser/utils/text.js +4 -2
- package/dist/lib/renderer/render.js +104 -74
- package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
- package/dist/lib/syntax/color/a98rgb.js +14 -4
- package/dist/lib/syntax/color/cmyk.js +14 -21
- package/dist/lib/syntax/color/color-mix.js +21 -34
- package/dist/lib/syntax/color/color.js +32 -49
- package/dist/lib/syntax/color/hsl.js +15 -15
- package/dist/lib/syntax/color/hwb.js +18 -17
- package/dist/lib/syntax/color/lab.js +17 -17
- package/dist/lib/syntax/color/lch.js +13 -13
- package/dist/lib/syntax/color/oklab.js +10 -11
- package/dist/lib/syntax/color/oklch.js +15 -18
- package/dist/lib/syntax/color/p3.js +18 -12
- package/dist/lib/syntax/color/prophotorgb.js +26 -28
- package/dist/lib/syntax/color/rec2020.js +8 -4
- package/dist/lib/syntax/color/relative-color.js +26 -10
- package/dist/lib/syntax/color/srgb.js +9 -7
- package/dist/lib/syntax/color/utils/distance.js +1 -1
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/color/xyzd50.js +2 -2
- package/dist/lib/syntax/constants.js +13 -3
- package/dist/lib/syntax/syntax.js +32 -108
- package/dist/lib/validation/config.js +1 -1
- package/dist/lib/validation/match.js +29 -26
- package/dist/lib/validation/parser/parse.js +7 -3
- package/dist/node.js +16 -9
- package/dist/types.d.ts +5 -1
- package/dist/types.js +4 -0
- package/dist/utils/sync.js +22 -1
- package/dist/web.js +13 -4
- package/package.json +4 -4
- package/llms.txt +0 -80
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
2
|
import { evaluate } from '../../ast/math/expression.js';
|
|
3
3
|
import { gcd } from '../../ast/math/math.js';
|
|
4
|
-
import { tokensfuncDefMap, mediaTypes,
|
|
4
|
+
import { tokensfuncDefMap, mediaTypes, LOCSTA, LOCEND, mFLT, mFGT, LOCSRCID } from '../../syntax/constants.js';
|
|
5
5
|
import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue } from '../../validation/match.js';
|
|
6
6
|
import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
|
|
7
7
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
@@ -61,7 +61,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
61
61
|
action: "drop",
|
|
62
62
|
message: `expecting '<media-type>'`,
|
|
63
63
|
node: stream[i],
|
|
64
|
-
location: options.source.getSourceLocation(stream[i][
|
|
64
|
+
location: options.source.getSourceLocation(stream[i][LOCSTA]),
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -71,7 +71,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
71
71
|
action: "drop",
|
|
72
72
|
message: `expecting '('`,
|
|
73
73
|
node: stream[i],
|
|
74
|
-
location: options.source.getSourceLocation(stream[i][
|
|
74
|
+
location: options.source.getSourceLocation(stream[i][LOCSTA]),
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -113,7 +113,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
113
113
|
action: "drop",
|
|
114
114
|
node: stream[i],
|
|
115
115
|
message: `<or> is not allowed outside of parentheses`,
|
|
116
|
-
location: options.source.getSourceLocation(stream[i][
|
|
116
|
+
location: options.source.getSourceLocation(stream[i][LOCSTA]),
|
|
117
117
|
});
|
|
118
118
|
break;
|
|
119
119
|
}
|
|
@@ -123,7 +123,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
123
123
|
action: "drop",
|
|
124
124
|
node: stream[i],
|
|
125
125
|
message: `cannot mix <and> and <or> at the same level`,
|
|
126
|
-
location: options.source.getSourceLocation(stream[i][
|
|
126
|
+
location: options.source.getSourceLocation(stream[i][LOCSTA]),
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
currentScope.add(stream[i].typ);
|
|
@@ -134,7 +134,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
134
134
|
case EnumToken.EndParensTokenType:
|
|
135
135
|
if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
136
136
|
const index = tokens.indexOf(stack.at(-1));
|
|
137
|
-
tokens[index][
|
|
137
|
+
tokens[index][LOCEND] = stream[i][LOCEND];
|
|
138
138
|
Object.assign(tokens[index], {
|
|
139
139
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
140
140
|
chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
|
|
@@ -145,7 +145,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
145
145
|
scopes.pop();
|
|
146
146
|
currentScope = scopes.at(-1);
|
|
147
147
|
if (!result.success) {
|
|
148
|
-
|
|
148
|
+
for (const error of result.errors) {
|
|
149
|
+
errors.push(error);
|
|
150
|
+
}
|
|
149
151
|
success = false;
|
|
150
152
|
}
|
|
151
153
|
break;
|
|
@@ -177,7 +179,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
177
179
|
val[l].val === "calc") {
|
|
178
180
|
const value = evaluate([val[l]]);
|
|
179
181
|
if (value.length == 1) {
|
|
180
|
-
value[0][
|
|
182
|
+
value[0][LOCSRCID] = val[l][LOCSRCID];
|
|
183
|
+
value[0][LOCSTA] = val[l][LOCSTA];
|
|
184
|
+
value[0][LOCEND] = val[l][LOCEND];
|
|
181
185
|
val[l] = value[0];
|
|
182
186
|
}
|
|
183
187
|
}
|
|
@@ -212,7 +216,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
212
216
|
op1: prevToken,
|
|
213
217
|
op2: stack.at(-1),
|
|
214
218
|
r: right,
|
|
215
|
-
[
|
|
219
|
+
[LOCSRCID]: left[0][LOCSRCID],
|
|
220
|
+
[LOCSTA]: left[0][LOCSTA],
|
|
221
|
+
[LOCEND]: right.at(-1)[LOCEND],
|
|
216
222
|
});
|
|
217
223
|
stack.pop();
|
|
218
224
|
stack.pop();
|
|
@@ -240,7 +246,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
240
246
|
val[l].val === "calc") {
|
|
241
247
|
const value = evaluate([val[l]]);
|
|
242
248
|
if (value.length == 1) {
|
|
243
|
-
value[0][
|
|
249
|
+
value[0][LOCSRCID] = val[l][LOCSRCID];
|
|
250
|
+
value[0][LOCSTA] = val[l][LOCSTA];
|
|
251
|
+
value[0][LOCEND] = val[l][LOCEND];
|
|
244
252
|
val[l] = value[0];
|
|
245
253
|
}
|
|
246
254
|
}
|
|
@@ -256,7 +264,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
256
264
|
errors.push({
|
|
257
265
|
action: "drop",
|
|
258
266
|
node: arr[0],
|
|
259
|
-
location: options.source.getSourceLocation(arr[0]?.[
|
|
267
|
+
location: options.source.getSourceLocation(arr[0]?.[LOCSTA]),
|
|
260
268
|
message: `${mfValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"}`,
|
|
261
269
|
});
|
|
262
270
|
break;
|
|
@@ -277,13 +285,15 @@ function parseMediaqueryList(stream, options) {
|
|
|
277
285
|
val.splice(0, val.length, ...filteredValues);
|
|
278
286
|
}
|
|
279
287
|
}
|
|
288
|
+
// @ts-expect-error
|
|
280
289
|
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
281
290
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
282
291
|
l: names,
|
|
283
292
|
op: stack.pop(),
|
|
284
293
|
r: values,
|
|
285
|
-
|
|
286
|
-
[
|
|
294
|
+
[LOCSRCID]: names[0][LOCSRCID],
|
|
295
|
+
[LOCSTA]: names[0][LOCSTA],
|
|
296
|
+
[LOCEND]: values.at(-1)[LOCEND],
|
|
287
297
|
});
|
|
288
298
|
}
|
|
289
299
|
if (stack.length === 0) {
|
|
@@ -291,7 +301,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
291
301
|
errors.push({
|
|
292
302
|
action: "drop",
|
|
293
303
|
node: stream[i],
|
|
294
|
-
location: options.source.getSourceLocation(stream[i]?.[
|
|
304
|
+
location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
|
|
295
305
|
message: `unmatched ')'`,
|
|
296
306
|
});
|
|
297
307
|
break;
|
|
@@ -301,8 +311,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
301
311
|
tokens[index] = {
|
|
302
312
|
typ: EnumToken.ParensTokenType,
|
|
303
313
|
chi: tokens.slice(index + 1, tokens.length - 1),
|
|
304
|
-
|
|
305
|
-
[
|
|
314
|
+
[LOCSRCID]: tokens[index][LOCSRCID],
|
|
315
|
+
[LOCSTA]: tokens[index][LOCSTA],
|
|
316
|
+
[LOCEND]: stream[i][LOCEND],
|
|
306
317
|
};
|
|
307
318
|
tokens.length = index + 1;
|
|
308
319
|
scopes.pop();
|
|
@@ -324,7 +335,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
324
335
|
op: stack.pop(),
|
|
325
336
|
l: left,
|
|
326
337
|
r: right,
|
|
327
|
-
[
|
|
338
|
+
[LOCSRCID]: left[0][LOCSRCID],
|
|
339
|
+
[LOCSTA]: left[0][LOCSTA],
|
|
340
|
+
[LOCEND]: right.at(-1)[LOCEND],
|
|
328
341
|
};
|
|
329
342
|
tokens.length = l + 1;
|
|
330
343
|
expectAndOrComma = true;
|
|
@@ -341,7 +354,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
341
354
|
parts.splice(parts.indexOf(stream), 1);
|
|
342
355
|
}
|
|
343
356
|
stream.length = 0;
|
|
344
|
-
|
|
357
|
+
for (const t of trimArray(tokens)) {
|
|
358
|
+
stream.push(t);
|
|
359
|
+
}
|
|
345
360
|
}
|
|
346
361
|
}
|
|
347
362
|
stream.length = 0;
|
|
@@ -351,7 +366,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
351
366
|
if (acc.length > 0) {
|
|
352
367
|
acc.push({ typ: EnumToken.CommaTokenType });
|
|
353
368
|
}
|
|
354
|
-
|
|
369
|
+
for (const t of b) {
|
|
370
|
+
acc.push(t);
|
|
371
|
+
}
|
|
355
372
|
return acc;
|
|
356
373
|
}, []));
|
|
357
374
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { pseudoElements,
|
|
2
|
+
import { pseudoElements, LOCEND, tokensfuncDefMap, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
|
|
3
3
|
import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
|
|
4
4
|
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
5
5
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
@@ -34,7 +34,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
34
34
|
: EnumToken.PseudoClassTokenType,
|
|
35
35
|
val: ":" + val,
|
|
36
36
|
});
|
|
37
|
-
stream[i][
|
|
37
|
+
stream[i][LOCEND] = stream[i + 1][LOCEND];
|
|
38
38
|
stream.splice(i + 1, 1);
|
|
39
39
|
continue;
|
|
40
40
|
}
|
|
@@ -47,7 +47,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
47
47
|
val,
|
|
48
48
|
});
|
|
49
49
|
stack.push(stream[i]);
|
|
50
|
-
stream[i][
|
|
50
|
+
stream[i][LOCEND] = stream[i + 1][LOCEND];
|
|
51
51
|
stream.splice(i + 1, 1);
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
@@ -97,7 +97,9 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
97
97
|
tokens[index] = {
|
|
98
98
|
typ: EnumToken.ParensTokenType,
|
|
99
99
|
chi: slice,
|
|
100
|
-
[
|
|
100
|
+
[LOCSRCID]: stack.at(-1)[LOCSRCID],
|
|
101
|
+
[LOCSTA]: stack.at(-1)[LOCSTA],
|
|
102
|
+
[LOCEND]: stream[i]?.[LOCEND],
|
|
101
103
|
};
|
|
102
104
|
stack.pop();
|
|
103
105
|
tokens.pop();
|
|
@@ -111,7 +113,9 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
111
113
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
112
114
|
val: stack.at(-1).val,
|
|
113
115
|
chi: trimArray(tokens.splice(index + 1, tokens.length - index - 2)),
|
|
114
|
-
[
|
|
116
|
+
[LOCSRCID]: stack.at(-1)[LOCSRCID],
|
|
117
|
+
[LOCSTA]: stack.at(-1)[LOCSTA],
|
|
118
|
+
[LOCEND]: stream[i]?.[LOCEND],
|
|
115
119
|
};
|
|
116
120
|
if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
|
|
117
121
|
// not a declaration
|
|
@@ -142,7 +146,9 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
142
146
|
typ: EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
143
147
|
l: stack.at(-1),
|
|
144
148
|
r: trimArray(tokens.splice(index + 1, i - index - 1)),
|
|
145
|
-
[
|
|
149
|
+
[LOCSRCID]: stack.at(-1)[LOCSRCID],
|
|
150
|
+
[LOCSTA]: stack.at(-1)[LOCSTA],
|
|
151
|
+
[LOCEND]: stream[i]?.[LOCEND],
|
|
146
152
|
};
|
|
147
153
|
stack.pop();
|
|
148
154
|
}
|
|
@@ -157,7 +163,9 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
157
163
|
op: stack.at(-1),
|
|
158
164
|
l: left,
|
|
159
165
|
r: trimArray(tokens.slice(index + 1)),
|
|
160
|
-
[
|
|
166
|
+
[LOCSRCID]: stack.at(-1)[LOCSRCID],
|
|
167
|
+
[LOCSTA]: stack.at(-1)[LOCSTA],
|
|
168
|
+
[LOCEND]: stream[i]?.[LOCEND],
|
|
161
169
|
};
|
|
162
170
|
tokens.length = index2 + 1;
|
|
163
171
|
stack.pop();
|
|
@@ -178,7 +186,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
178
186
|
if ("and" === val || "or" === val) {
|
|
179
187
|
if ("or" === val && scopes.length === 1) {
|
|
180
188
|
const fileName = options.source.getFileName() ?? "";
|
|
181
|
-
const [line, column] = options.source.getOffsets(stream[i]?.[
|
|
189
|
+
const [line, column] = options.source.getOffsets(stream[i]?.[LOCSTA]);
|
|
182
190
|
return {
|
|
183
191
|
success: false,
|
|
184
192
|
errors: [
|
|
@@ -202,7 +210,9 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
212
|
stream.length = 0;
|
|
205
|
-
|
|
213
|
+
for (const token of trimArray(tokens)) {
|
|
214
|
+
stream.push(token);
|
|
215
|
+
}
|
|
206
216
|
return { success, errors };
|
|
207
217
|
}
|
|
208
218
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
2
|
import { trimArray } from '../../validation/match.js';
|
|
3
|
-
import { tokensfuncDefMap,
|
|
3
|
+
import { tokensfuncDefMap, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
|
|
4
4
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
5
5
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
6
6
|
|
|
@@ -60,7 +60,9 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
60
60
|
const tokenList = [
|
|
61
61
|
{
|
|
62
62
|
typ: EnumToken.StartParensTokenType,
|
|
63
|
-
[
|
|
63
|
+
[LOCSRCID]: stream[i][LOCSRCID],
|
|
64
|
+
[LOCSTA]: stream[i][LOCSTA],
|
|
65
|
+
[LOCEND]: stream[j]?.[LOCEND],
|
|
64
66
|
},
|
|
65
67
|
// @ts-expect-error
|
|
66
68
|
].concat(slice.slice(1));
|
|
@@ -83,32 +85,13 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
83
85
|
return result;
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
// errors.push({
|
|
88
|
-
// action: "ignore",
|
|
89
|
-
// message: `unknown <boolean-condition> function '${funcName}' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
90
|
-
// node: stream[i],
|
|
91
|
-
// location: stream[i][LOC],
|
|
92
|
-
// });
|
|
93
|
-
// }
|
|
94
|
-
stream[i][LOC] = { ...stream[i][LOC], end: stream[j]?.[LOC]?.end };
|
|
88
|
+
stream[i][LOCEND] = stream[j]?.[LOCEND];
|
|
95
89
|
Object.assign(stream[i], {
|
|
96
90
|
typ: tokensfuncDefMap.get(stream[i].typ),
|
|
97
91
|
chi: stream[i].typ === EnumToken.SupportsFunctionTokenDefType
|
|
98
92
|
? trimArray(slice.slice(1, -1))
|
|
99
93
|
: tokenList[0].chi,
|
|
100
94
|
});
|
|
101
|
-
// if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
|
|
102
|
-
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
103
|
-
// tokens[index] = {
|
|
104
|
-
// typ: EnumToken.WhenElseUnaryConditionTokenType,
|
|
105
|
-
// l: stack.at(-1)!,
|
|
106
|
-
// r: trimArray(tokens.slice(index + 1)),
|
|
107
|
-
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
108
|
-
// } as WhenElseUnaryConditionToken;
|
|
109
|
-
// tokens.length = index + 1;
|
|
110
|
-
// stack.pop();
|
|
111
|
-
// }
|
|
112
95
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
113
96
|
const index = tokens.indexOf(stack.at(-1));
|
|
114
97
|
const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
|
|
@@ -117,7 +100,9 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
117
100
|
op: stack.at(-1),
|
|
118
101
|
l: trimArray(tokens.slice(index2, index)),
|
|
119
102
|
r: trimArray(tokens.slice(index + 1)),
|
|
120
|
-
[
|
|
103
|
+
[LOCSRCID]: stack.at(-1)[LOCSRCID],
|
|
104
|
+
[LOCSTA]: stack.at(-1)[LOCSTA],
|
|
105
|
+
[LOCEND]: stream[i]?.[LOCEND],
|
|
121
106
|
};
|
|
122
107
|
tokens.length = index2 + 1;
|
|
123
108
|
stack.pop();
|
|
@@ -128,22 +113,10 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
128
113
|
break;
|
|
129
114
|
}
|
|
130
115
|
}
|
|
131
|
-
// if (stack.length > 0) {
|
|
132
|
-
// return {
|
|
133
|
-
// success: false,
|
|
134
|
-
// errors: [
|
|
135
|
-
// {
|
|
136
|
-
// action: "drop",
|
|
137
|
-
// node: stack.at(-1),
|
|
138
|
-
// message: `unmatched token '${renderValue(stack.at(-1) as Token)}' at ${stack.at(-1)![LOC]!.src}:${
|
|
139
|
-
// stack.at(-1)![LOC]!.sta.lin
|
|
140
|
-
// }:${stack.at(-1)![LOC]!.sta.col}`,
|
|
141
|
-
// },
|
|
142
|
-
// ],
|
|
143
|
-
// };
|
|
144
|
-
// }
|
|
145
116
|
stream.length = 0;
|
|
146
|
-
|
|
117
|
+
for (const token of trimArray(tokens)) {
|
|
118
|
+
stream.push(token);
|
|
119
|
+
}
|
|
147
120
|
return { success, errors };
|
|
148
121
|
}
|
|
149
122
|
|
|
@@ -7,24 +7,6 @@ function matchAtRuleSyntax(atRule, stream, options) {
|
|
|
7
7
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
8
8
|
trimArray(stream);
|
|
9
9
|
if (syntax.length === 0) {
|
|
10
|
-
// const filtered = stream.filter(
|
|
11
|
-
// (token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType,
|
|
12
|
-
// );
|
|
13
|
-
// if (filtered.length > 0) {
|
|
14
|
-
// return {
|
|
15
|
-
// success: false,
|
|
16
|
-
// errors: [
|
|
17
|
-
// {
|
|
18
|
-
// action: "drop",
|
|
19
|
-
// message: `unexpected token ${EnumToken[filtered[0].typ]} at ${filtered[0][LOC]!.src}:${
|
|
20
|
-
// filtered[0][LOC]!.sta.lin
|
|
21
|
-
// }:${filtered[0][LOC]!.sta.col}`,
|
|
22
|
-
// node: filtered[0],
|
|
23
|
-
// location: filtered[0][LOC]!,
|
|
24
|
-
// },
|
|
25
|
-
// ],
|
|
26
|
-
// };
|
|
27
|
-
// }
|
|
28
10
|
return { success: true, errors: [] };
|
|
29
11
|
}
|
|
30
12
|
const { success, errors } = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumToken, EnumAstNodeStatus, ColorType, ValidationLevel } from '../../ast/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { LOCEND, STATE, ERRORS, LOCSTA, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace, LOCSRCID } from '../../syntax/constants.js';
|
|
3
3
|
import { renamedStandardProperties, isColor, parseColor, isWhiteSpace } from '../../syntax/syntax.js';
|
|
4
4
|
import { getSyntaxRule, getParsedSyntax } from '../../validation/config.js';
|
|
5
5
|
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
@@ -70,16 +70,15 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
70
70
|
}
|
|
71
71
|
if ((name.typ !== EnumToken.IdenTokenType && name.typ !== EnumToken.DashedIdenTokenType) ||
|
|
72
72
|
tokens[i]?.typ !== EnumToken.ColonTokenType) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
73
|
+
if (tokens[tokens.length - 1]?.[LOCEND] != null) {
|
|
74
|
+
name[LOCEND] = tokens[tokens.length - 1]?.[LOCEND];
|
|
75
|
+
}
|
|
77
76
|
name[STATE] = EnumAstNodeStatus.Unparsed;
|
|
78
77
|
name[ERRORS] = [
|
|
79
78
|
{
|
|
80
79
|
action: "drop",
|
|
81
80
|
node: name,
|
|
82
|
-
location: name[
|
|
81
|
+
location: options.source.getSourceLocation(name[LOCSTA]),
|
|
83
82
|
message: "invalid declaration",
|
|
84
83
|
},
|
|
85
84
|
];
|
|
@@ -109,39 +108,6 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
109
108
|
rules.acceptAnyDeclaration && rules.acceptAnyRule
|
|
110
109
|
? getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase())
|
|
111
110
|
: rules.getBlockRules();
|
|
112
|
-
// if (syntaxRules == null) {
|
|
113
|
-
// // check rule in nested context
|
|
114
|
-
// let pr = parent[PARENT] as AstNode | null;
|
|
115
|
-
// while (pr != null && pr.typ !== EnumToken.RuleNodeType) {
|
|
116
|
-
// pr = pr[PARENT];
|
|
117
|
-
// }
|
|
118
|
-
// if (pr != null) {
|
|
119
|
-
// syntaxRules = getParsedSyntax(
|
|
120
|
-
// ValidationSyntaxGroupEnum.Declarations,
|
|
121
|
-
// name.val.toLowerCase(),
|
|
122
|
-
// );
|
|
123
|
-
// }
|
|
124
|
-
// if (syntaxRules == null) {
|
|
125
|
-
// errors.push({
|
|
126
|
-
// action: "drop",
|
|
127
|
-
// message: "declaration not allowed in context",
|
|
128
|
-
// node: name,
|
|
129
|
-
// location: name[LOC],
|
|
130
|
-
// });
|
|
131
|
-
// name[LOC] = {
|
|
132
|
-
// ...name[LOC],
|
|
133
|
-
// end: tokens[tokens.length - 1][LOC]!.end,
|
|
134
|
-
// } as Location;
|
|
135
|
-
// name[STATE] = EnumAstNodeStatus.Disallowed;
|
|
136
|
-
// name[ERRORS] = [errors[errors.length - 1]];
|
|
137
|
-
// // @ts-expect-error
|
|
138
|
-
// return Object.assign(name, {
|
|
139
|
-
// typ: EnumToken.DeclarationNodeType,
|
|
140
|
-
// nam: name.val,
|
|
141
|
-
// val: tokens,
|
|
142
|
-
// }) as AstDeclaration;
|
|
143
|
-
// }
|
|
144
|
-
// }
|
|
145
111
|
}
|
|
146
112
|
}
|
|
147
113
|
}
|
|
@@ -179,12 +145,11 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
179
145
|
action: "drop",
|
|
180
146
|
message: "declaration value missing",
|
|
181
147
|
node: name,
|
|
182
|
-
location: options.source.getSourceLocation(name[
|
|
148
|
+
location: options.source.getSourceLocation(name[LOCSTA]),
|
|
183
149
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
};
|
|
150
|
+
if (tokens[tokens.length - 1]?.[LOCEND] != null) {
|
|
151
|
+
name[LOCEND] = tokens[tokens.length - 1][LOCEND];
|
|
152
|
+
}
|
|
188
153
|
name[STATE] = EnumAstNodeStatus.Invalid;
|
|
189
154
|
name[ERRORS] = [errors[errors.length - 1]];
|
|
190
155
|
// @ts-expect-error
|
|
@@ -216,7 +181,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
216
181
|
}
|
|
217
182
|
}
|
|
218
183
|
if (!doNotValidate && !result?.success && result.errors.length > 0) {
|
|
219
|
-
|
|
184
|
+
for (index = 0; index < result.errors.length; index++) {
|
|
185
|
+
errors.push(result.errors[index]);
|
|
186
|
+
}
|
|
220
187
|
}
|
|
221
188
|
}
|
|
222
189
|
}
|
|
@@ -234,7 +201,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
234
201
|
// Object.assign(token, {
|
|
235
202
|
// typ: EnumToken.FunctionTokenDefType,
|
|
236
203
|
// });
|
|
237
|
-
// token[
|
|
204
|
+
// token[LOCEND] = tokens[i + 1][LOCEND];
|
|
238
205
|
// tokens.splice(i + 1, 1);
|
|
239
206
|
// stack.push(token);
|
|
240
207
|
// }
|
|
@@ -272,26 +239,6 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
272
239
|
}
|
|
273
240
|
break;
|
|
274
241
|
case EnumToken.EndParensTokenType:
|
|
275
|
-
// if (stack.length == 0) {
|
|
276
|
-
// errors.push({
|
|
277
|
-
// action: "drop",
|
|
278
|
-
// message: "unbalanced parentheses",
|
|
279
|
-
// node: token,
|
|
280
|
-
// location: token[LOC],
|
|
281
|
-
// });
|
|
282
|
-
// name[LOC] = {
|
|
283
|
-
// ...name[LOC],
|
|
284
|
-
// end: tokens[tokens.length - 1]?.[LOC]!.end ?? name[LOC]!.end,
|
|
285
|
-
// } as Location;
|
|
286
|
-
// name[STATE] = EnumAstNodeStatus.Invalid;
|
|
287
|
-
// name[ERRORS] = [errors[errors.length - 1]];
|
|
288
|
-
// // @ts-expect-error
|
|
289
|
-
// return Object.assign(name, {
|
|
290
|
-
// typ: EnumToken.DeclarationNodeType,
|
|
291
|
-
// nam: name.val,
|
|
292
|
-
// val: tokens,
|
|
293
|
-
// }) as AstDeclaration;
|
|
294
|
-
// }
|
|
295
242
|
if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
296
243
|
index = tokens.indexOf(stack.at(-1));
|
|
297
244
|
tokens.splice(i, 1);
|
|
@@ -364,9 +311,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
364
311
|
// ((tokens[index] as FunctionToken).chi[l] as IdentToken | UrlToken).val +
|
|
365
312
|
// ((tokens[index] as FunctionToken).chi[m] as ClassSelectorToken).val,
|
|
366
313
|
// });
|
|
367
|
-
// (tokens[index] as FunctionToken).chi[l][
|
|
314
|
+
// (tokens[index] as FunctionToken).chi[l][LOCEND] = (
|
|
368
315
|
// tokens[index] as FunctionToken
|
|
369
|
-
// ).chi[m][
|
|
316
|
+
// ).chi[m][LOCEND];
|
|
370
317
|
// (tokens[index] as FunctionToken).chi.splice(m, 1);
|
|
371
318
|
// }
|
|
372
319
|
// break;
|
|
@@ -396,7 +343,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
396
343
|
action: "drop",
|
|
397
344
|
message: `invalid color`,
|
|
398
345
|
node: tokens[index],
|
|
399
|
-
location: options.source.getSourceLocation(tokens[index][
|
|
346
|
+
location: options.source.getSourceLocation(tokens[index][LOCSTA]),
|
|
400
347
|
});
|
|
401
348
|
}
|
|
402
349
|
}
|
|
@@ -436,10 +383,19 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
436
383
|
}
|
|
437
384
|
if (trimTokenSpace.has(token.typ)) {
|
|
438
385
|
if (tokens[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
|
|
439
|
-
|
|
386
|
+
for (let index = i + 1; index < tokens.length - 1; index++) {
|
|
387
|
+
tokens[index] = tokens[index + 1];
|
|
388
|
+
}
|
|
389
|
+
tokens.length--;
|
|
390
|
+
i--;
|
|
391
|
+
continue;
|
|
440
392
|
}
|
|
441
393
|
if (tokens[i - 1]?.typ == EnumToken.WhitespaceTokenType) {
|
|
442
|
-
|
|
394
|
+
for (let index = i - 1; index < tokens.length - 1; index++) {
|
|
395
|
+
tokens[index] = tokens[index + 1];
|
|
396
|
+
}
|
|
397
|
+
tokens.length--;
|
|
398
|
+
i--;
|
|
443
399
|
}
|
|
444
400
|
}
|
|
445
401
|
}
|
|
@@ -448,12 +404,11 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
448
404
|
action: "drop",
|
|
449
405
|
message: "unbalanced token",
|
|
450
406
|
node: stack[stack.length - 1],
|
|
451
|
-
location: options.source.getSourceLocation(stack[stack.length - 1][
|
|
407
|
+
location: options.source.getSourceLocation(stack[stack.length - 1][LOCSTA]),
|
|
452
408
|
});
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
};
|
|
409
|
+
if (tokens[tokens.length - 1][LOCEND] != null) {
|
|
410
|
+
name[LOCEND] = tokens[tokens.length - 1][LOCEND];
|
|
411
|
+
}
|
|
457
412
|
name[STATE] = EnumAstNodeStatus.Invalid;
|
|
458
413
|
name[ERRORS] = result?.errors ?? [];
|
|
459
414
|
//@ts-expect-error
|
|
@@ -486,10 +441,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
486
441
|
}
|
|
487
442
|
}
|
|
488
443
|
if (validate && syntaxRules == null && name.typ === EnumToken.IdenTokenType) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
};
|
|
444
|
+
if (tokens[tokens.length - 1]?.[LOCEND] != null) {
|
|
445
|
+
name[LOCEND] = tokens[tokens.length - 1][LOCEND];
|
|
446
|
+
}
|
|
493
447
|
name[STATE] = EnumAstNodeStatus.Unknown;
|
|
494
448
|
name[ERRORS] = result?.errors ?? [];
|
|
495
449
|
// @ts-expect-error
|
|
@@ -498,14 +452,6 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
498
452
|
nam: name.val,
|
|
499
453
|
val: tokens,
|
|
500
454
|
});
|
|
501
|
-
// if ((options.validation as ValidationLevel) & ValidationLevel.Declaration) {
|
|
502
|
-
// errors.push({
|
|
503
|
-
// action: "drop",
|
|
504
|
-
// message: "unknown declaration",
|
|
505
|
-
// node: node,
|
|
506
|
-
// location: node[LOC],
|
|
507
|
-
// });
|
|
508
|
-
// }
|
|
509
455
|
return node;
|
|
510
456
|
}
|
|
511
457
|
if (equalsIgnoreCase("composes", name.val)) {
|
|
@@ -523,18 +469,15 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
523
469
|
typ: EnumToken.ComposesSelectorNodeType,
|
|
524
470
|
l: left,
|
|
525
471
|
r: right?.[0] ?? null,
|
|
526
|
-
[
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
end: index != -1 ? right[right.length - 1]?.[LOC]?.end : left[left.length - 1][LOC].end,
|
|
530
|
-
},
|
|
472
|
+
[LOCSRCID]: tokens[0][LOCSRCID],
|
|
473
|
+
[LOCSTA]: tokens[0][LOCSTA],
|
|
474
|
+
[LOCEND]: index != -1 ? right[right.length - 1]?.[LOCEND] : left[left.length - 1][LOCEND],
|
|
531
475
|
},
|
|
532
476
|
];
|
|
533
477
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
};
|
|
478
|
+
if (tokens[tokens.length - 1]?.[LOCEND] != null) {
|
|
479
|
+
name[LOCEND] = tokens[tokens.length - 1][LOCEND];
|
|
480
|
+
}
|
|
538
481
|
name[STATE] = success
|
|
539
482
|
? result == null
|
|
540
483
|
? EnumAstNodeStatus.Unvalidated
|
|
@@ -29,7 +29,7 @@ function hashId(input, length = 6) {
|
|
|
29
29
|
chars.push(FIRST_ALPHABET[n % FIRST_ALPHABET.length]);
|
|
30
30
|
// Remaining characters
|
|
31
31
|
for (let i = 1; i < length; i++) {
|
|
32
|
-
n = (n + chars.length
|
|
32
|
+
n = (n + chars.length * i) % FULL_ALPHABET.length;
|
|
33
33
|
chars.push(FULL_ALPHABET[n]);
|
|
34
34
|
}
|
|
35
35
|
return chars.join("");
|
|
@@ -60,13 +60,13 @@ function toSortedString(input) {
|
|
|
60
60
|
* @returns
|
|
61
61
|
*/
|
|
62
62
|
function objectHash(object) {
|
|
63
|
-
return
|
|
63
|
+
return hashCode(toSortedString(object)).toString(16);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* convert input to hex
|
|
67
67
|
* @param input
|
|
68
68
|
*/
|
|
69
|
-
function toHex(input) {
|
|
69
|
+
function toHex(input, length) {
|
|
70
70
|
let result = "";
|
|
71
71
|
if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {
|
|
72
72
|
for (const byte of Array.from(new Uint8Array(input))) {
|
|
@@ -136,4 +136,4 @@ function syncHash(input, length = 6, algo) {
|
|
|
136
136
|
return hashId(input, length);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
export { DIGITS, FIRST_ALPHABET, FULL_ALPHABET, LOWER, hash, hashAlgorithms, hashId, objectHash, syncHash };
|
|
139
|
+
export { DIGITS, FIRST_ALPHABET, FULL_ALPHABET, LOWER, hash, hashAlgorithms, hashId, objectHash, syncHash, toSortedString };
|