@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,5 +1,5 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { tokensfuncDefMap,
|
|
2
|
+
import { tokensfuncDefMap, LOCSTA, mFGT, mFLT, LOCEND, LOCSRCID } from '../../syntax/constants.js';
|
|
3
3
|
import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
|
|
4
4
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
5
5
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
@@ -28,7 +28,9 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
28
28
|
}, [[]]);
|
|
29
29
|
const result = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
30
30
|
if (!result.success) {
|
|
31
|
-
|
|
31
|
+
for (const error of result.errors) {
|
|
32
|
+
errors.push(error);
|
|
33
|
+
}
|
|
32
34
|
return {
|
|
33
35
|
success: false,
|
|
34
36
|
errors,
|
|
@@ -48,19 +50,6 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
48
50
|
(stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
|
|
49
51
|
tokens.push(stream[i++]);
|
|
50
52
|
}
|
|
51
|
-
// if (i >= stream.length) {
|
|
52
|
-
// return {
|
|
53
|
-
// success: false,
|
|
54
|
-
// errors: [
|
|
55
|
-
// {
|
|
56
|
-
// action: "drop",
|
|
57
|
-
// node: context,
|
|
58
|
-
// location: context[LOC],
|
|
59
|
-
// message: `expecting <container-condition> at ${context[LOC]?.src}:${context?.[LOC]?.sta.lin}:${context[LOC]?.sta.col}`,
|
|
60
|
-
// },
|
|
61
|
-
// ],
|
|
62
|
-
// };
|
|
63
|
-
// }
|
|
64
53
|
if (stream[i].typ === EnumToken.IdenTokenType) {
|
|
65
54
|
tokens.push(stream[i++]);
|
|
66
55
|
}
|
|
@@ -76,7 +65,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
76
65
|
{
|
|
77
66
|
action: "drop",
|
|
78
67
|
node: stream[i],
|
|
79
|
-
location: options.source.getSourceLocation(stream[i]?.[
|
|
68
|
+
location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
|
|
80
69
|
message: `expecting <container-condition>`,
|
|
81
70
|
},
|
|
82
71
|
],
|
|
@@ -101,11 +90,10 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
101
90
|
action: "drop",
|
|
102
91
|
node: stream[i],
|
|
103
92
|
message: `expecting <and>, <or> or comma`,
|
|
104
|
-
location: options.source.getSourceLocation(stream[i]?.[
|
|
93
|
+
location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
|
|
105
94
|
});
|
|
106
95
|
break;
|
|
107
96
|
}
|
|
108
|
-
// expectAndOr = false;
|
|
109
97
|
}
|
|
110
98
|
if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
|
|
111
99
|
scopes.push((currentScope = new Set()));
|
|
@@ -139,174 +127,34 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
139
127
|
errors.push({
|
|
140
128
|
action: "drop",
|
|
141
129
|
node: stream[i],
|
|
142
|
-
location: options.source.getSourceLocation(stream[i][
|
|
130
|
+
location: options.source.getSourceLocation(stream[i][LOCSTA]),
|
|
143
131
|
message: `<or> is not allowed outside of parentheses`,
|
|
144
132
|
});
|
|
145
133
|
break;
|
|
146
134
|
}
|
|
147
|
-
// if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
148
|
-
// success = false;
|
|
149
|
-
// errors.push({
|
|
150
|
-
// action: "drop",
|
|
151
|
-
// node: stream[i],
|
|
152
|
-
// message: `cannot mix <and> and <or> at the same level at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
153
|
-
// });
|
|
154
|
-
// break;
|
|
155
|
-
// }
|
|
156
135
|
currentScope.add(stream[i].typ);
|
|
157
136
|
stack.push(stream[i]);
|
|
158
137
|
}
|
|
159
|
-
// else if (scopes.length === 0) {
|
|
160
|
-
// success = false;
|
|
161
|
-
// errors.push({
|
|
162
|
-
// action: "drop",
|
|
163
|
-
// node: stream[i],
|
|
164
|
-
// location: stream[i]?.[LOC],
|
|
165
|
-
// message: `unexpected <ident> at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
166
|
-
// });
|
|
167
|
-
// return {
|
|
168
|
-
// success,
|
|
169
|
-
// errors,
|
|
170
|
-
// };
|
|
171
|
-
// }
|
|
172
138
|
}
|
|
173
139
|
break;
|
|
174
140
|
case EnumToken.EndParensTokenType:
|
|
175
|
-
// feature
|
|
176
|
-
// if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
|
|
177
|
-
// // <mf-lt> | <mf-gt>
|
|
178
|
-
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
179
|
-
// const prevToken: Token = stack[stack.length - 2];
|
|
180
|
-
// if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
|
|
181
|
-
// if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
|
|
182
|
-
// success = false;
|
|
183
|
-
// errors.push({
|
|
184
|
-
// action: "drop",
|
|
185
|
-
// node: stream[i],
|
|
186
|
-
// message: `unmatched '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
187
|
-
// });
|
|
188
|
-
// break;
|
|
189
|
-
// }
|
|
190
|
-
// if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
|
|
191
|
-
// success = false;
|
|
192
|
-
// errors.push({
|
|
193
|
-
// action: "drop",
|
|
194
|
-
// node: stack.at(-1),
|
|
195
|
-
// message: `expected <mf-lt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
196
|
-
// });
|
|
197
|
-
// break;
|
|
198
|
-
// } else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
|
|
199
|
-
// success = false;
|
|
200
|
-
// errors.push({
|
|
201
|
-
// action: "drop",
|
|
202
|
-
// node: stream[i],
|
|
203
|
-
// message: `expected <mf-gt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
204
|
-
// });
|
|
205
|
-
// break;
|
|
206
|
-
// }
|
|
207
|
-
// // <style-range>
|
|
208
|
-
// // const index: number = tokens.indexOf(stack.at(-1)!);
|
|
209
|
-
// // <mf-lt> | <mf-gt>
|
|
210
|
-
// const index2: number = tokens.indexOf(prevToken);
|
|
211
|
-
// // '('
|
|
212
|
-
// const index3: number = tokens.indexOf(stack.at(-3)!);
|
|
213
|
-
// const left: Token[] = trimArray(tokens.slice(index3 + 1, index2));
|
|
214
|
-
// const right: Token[] = trimArray(tokens.slice(index + 1, tokens.length - 1));
|
|
215
|
-
// const names: Token[] = trimArray(tokens.slice(index2 + 1, index));
|
|
216
|
-
// if (!isStyleFeatureValue(left)) {
|
|
217
|
-
// success = false;
|
|
218
|
-
// errors.push({
|
|
219
|
-
// action: "drop",
|
|
220
|
-
// node: left[0],
|
|
221
|
-
// message: `expected <style-feature-value> at ${left[0]?.[LOC]?.src}:${left[0]?.[LOC]?.sta.lin}:${left[0]?.[LOC]?.sta.col}`,
|
|
222
|
-
// });
|
|
223
|
-
// break;
|
|
224
|
-
// }
|
|
225
|
-
// if (!isStyleFeatureValue(right)) {
|
|
226
|
-
// success = false;
|
|
227
|
-
// errors.push({
|
|
228
|
-
// action: "drop",
|
|
229
|
-
// node: right[0],
|
|
230
|
-
// message: `expected <style-feature-value> at ${right[0]?.[LOC]?.src}:${right[0]?.[LOC]?.sta.lin}:${right[0]?.[LOC]?.sta.col}`,
|
|
231
|
-
// });
|
|
232
|
-
// break;
|
|
233
|
-
// }
|
|
234
|
-
// if (!isStyleFeatureValue(names)) {
|
|
235
|
-
// success = false;
|
|
236
|
-
// errors.push({
|
|
237
|
-
// action: "drop",
|
|
238
|
-
// node: names[0],
|
|
239
|
-
// message: `expected <style-feature-value> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
|
|
240
|
-
// });
|
|
241
|
-
// break;
|
|
242
|
-
// }
|
|
243
|
-
// tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
244
|
-
// typ: EnumToken.ContainerStyleRangeTokenType,
|
|
245
|
-
// l: left,
|
|
246
|
-
// op: names,
|
|
247
|
-
// r: right,
|
|
248
|
-
// [LOC]: { ...left[0][LOC]!, end: right.at(-1)![LOC]!.end },
|
|
249
|
-
// } as ContainerStyleRangeToken);
|
|
250
|
-
// // check <style()> or <scroll-state()>
|
|
251
|
-
// stack.pop();
|
|
252
|
-
// stack.pop();
|
|
253
|
-
// } else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
254
|
-
// success = false;
|
|
255
|
-
// errors.push({
|
|
256
|
-
// action: "drop",
|
|
257
|
-
// node: stream[i],
|
|
258
|
-
// location: stream[i]?.[LOC],
|
|
259
|
-
// message: `expected '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
260
|
-
// });
|
|
261
|
-
// break;
|
|
262
|
-
// }
|
|
263
|
-
// }
|
|
264
141
|
if (mFGT.has(stack.at(-1)?.typ) ||
|
|
265
142
|
mFLT.has(stack.at(-1)?.typ) ||
|
|
266
143
|
stack.at(-1)?.typ === EnumToken.DelimTokenType ||
|
|
267
144
|
stack.at(-1)?.typ === EnumToken.ColonTokenType) {
|
|
268
145
|
stack[stack.length - 2].val?.toLowerCase?.();
|
|
269
|
-
// if (
|
|
270
|
-
// stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType &&
|
|
271
|
-
// !(
|
|
272
|
-
// stack[stack.length - 2]?.typ === EnumToken.ContainerFunctionTokenDefType &&
|
|
273
|
-
// ("style" === funcName || "scroll-state" === funcName)
|
|
274
|
-
// )
|
|
275
|
-
// ) {
|
|
276
|
-
// success = false;
|
|
277
|
-
// errors.push({
|
|
278
|
-
// action: "drop",
|
|
279
|
-
// node: stream[i],
|
|
280
|
-
// location: stream[i]?.[LOC],
|
|
281
|
-
// message: `unmatched2 ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
282
|
-
// });
|
|
283
|
-
// break;
|
|
284
|
-
// }
|
|
285
146
|
const index2 = tokens.indexOf(stack.at(-1));
|
|
286
147
|
const index3 = tokens.indexOf(stack.at(-2));
|
|
287
148
|
let names = trimArray(tokens.slice(index3 + 1, index2));
|
|
288
149
|
let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
|
|
289
|
-
// if (
|
|
290
|
-
// stack.at(-1)?.typ !== EnumToken.ColonTokenType &&
|
|
291
|
-
// stack.at(-1)?.typ !== EnumToken.DelimTokenType
|
|
292
|
-
// ) {
|
|
293
|
-
// const filteredNames = names.filter(
|
|
294
|
-
// (n) =>
|
|
295
|
-
// n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
|
|
296
|
-
// );
|
|
297
|
-
// if (
|
|
298
|
-
// filteredNames.length !== 1 ||
|
|
299
|
-
// (filteredNames[0].typ !== EnumToken.IdenTokenType &&
|
|
300
|
-
// filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
|
|
301
|
-
// ) {
|
|
302
|
-
// }
|
|
303
|
-
// }
|
|
304
150
|
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
305
151
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
306
152
|
l: names,
|
|
307
153
|
op: stack.pop(),
|
|
308
154
|
r: values,
|
|
309
|
-
[
|
|
155
|
+
[LOCSRCID]: names[0][LOCSRCID],
|
|
156
|
+
[LOCSTA]: names[0][LOCSTA],
|
|
157
|
+
[LOCEND]: values.at(-1)[LOCEND],
|
|
310
158
|
});
|
|
311
159
|
// check <style()> or <scroll-state()>
|
|
312
160
|
}
|
|
@@ -316,13 +164,15 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
316
164
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
317
165
|
chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
|
|
318
166
|
});
|
|
319
|
-
tokens[index][
|
|
167
|
+
tokens[index][LOCSRCID] = tokens[index][LOCSRCID];
|
|
168
|
+
tokens[index][LOCSTA] = tokens[index][LOCSTA];
|
|
169
|
+
tokens[index][LOCEND] = stream[i][LOCEND];
|
|
320
170
|
if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
|
|
321
171
|
success = false;
|
|
322
172
|
errors.push({
|
|
323
173
|
action: "drop",
|
|
324
174
|
node: stream[i],
|
|
325
|
-
location: options.source.getSourceLocation(stream[i]?.[
|
|
175
|
+
location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
|
|
326
176
|
message: `expecting '<${tokens[index].val}-query>'`,
|
|
327
177
|
});
|
|
328
178
|
break;
|
|
@@ -337,14 +187,16 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
337
187
|
tokens[index] = {
|
|
338
188
|
typ: EnumToken.ParensTokenType,
|
|
339
189
|
chi: tokens.slice(index + 1, tokens.length - 1),
|
|
340
|
-
[
|
|
190
|
+
[LOCSRCID]: tokens[index][LOCSRCID],
|
|
191
|
+
[LOCSTA]: tokens[index][LOCSTA],
|
|
192
|
+
[LOCEND]: stream[i][LOCEND],
|
|
341
193
|
};
|
|
342
194
|
if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
|
|
343
195
|
success = false;
|
|
344
196
|
errors.push({
|
|
345
197
|
action: "drop",
|
|
346
198
|
node: stream[i],
|
|
347
|
-
location: options.source.getSourceLocation(stream[i]?.[
|
|
199
|
+
location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
|
|
348
200
|
message: `expecting '<query-in-parens>'`,
|
|
349
201
|
});
|
|
350
202
|
break;
|
|
@@ -366,21 +218,12 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
366
218
|
errors.push({
|
|
367
219
|
action: "drop",
|
|
368
220
|
node: tokens[k],
|
|
369
|
-
location: options.source.getSourceLocation(tokens[k]?.[
|
|
221
|
+
location: options.source.getSourceLocation(tokens[k]?.[LOCSTA]),
|
|
370
222
|
message: `unexpected token 'not'`,
|
|
371
223
|
});
|
|
372
224
|
break;
|
|
373
225
|
}
|
|
374
226
|
}
|
|
375
|
-
// const index = tokens.indexOf(stack.at(-1)!);
|
|
376
|
-
// const slice = trimArray(tokens.slice(index + 1));
|
|
377
|
-
// tokens[index] = {
|
|
378
|
-
// typ: EnumToken.MediaQueryUnaryFeatureTokenType,
|
|
379
|
-
// l: stack.pop()!,
|
|
380
|
-
// r: slice,
|
|
381
|
-
// [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end },
|
|
382
|
-
// };
|
|
383
|
-
// tokens.length = index + 1;
|
|
384
227
|
}
|
|
385
228
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
|
|
386
229
|
stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
@@ -398,31 +241,19 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
398
241
|
op: stack.pop(),
|
|
399
242
|
l: left,
|
|
400
243
|
r: right,
|
|
401
|
-
[
|
|
244
|
+
[LOCSRCID]: left[0][LOCSRCID],
|
|
245
|
+
[LOCSTA]: left[0][LOCSTA],
|
|
246
|
+
[LOCEND]: right.at(-1)[LOCEND],
|
|
402
247
|
};
|
|
403
248
|
tokens.length = l + 1;
|
|
404
249
|
expectAndOr = true;
|
|
405
250
|
}
|
|
406
251
|
break;
|
|
407
|
-
// default:
|
|
408
|
-
// if (tokensfuncDefMap.has(stream[i]?.typ)) {
|
|
409
|
-
// stack.push(stream[i]);
|
|
410
|
-
// scopes.push((currentScope = new Set()));
|
|
411
|
-
// }
|
|
412
|
-
// break;
|
|
413
252
|
}
|
|
414
253
|
if (!success) {
|
|
415
254
|
break;
|
|
416
255
|
}
|
|
417
256
|
}
|
|
418
|
-
// if (success && stack.length > 0) {
|
|
419
|
-
// success = false;
|
|
420
|
-
// errors.push({
|
|
421
|
-
// action: "drop",
|
|
422
|
-
// node: stack.at(-1),
|
|
423
|
-
// message: `unmatched token '${EnumToken[stack.at(-1)?.typ]}' at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
424
|
-
// });
|
|
425
|
-
// }
|
|
426
257
|
if (!success) {
|
|
427
258
|
return {
|
|
428
259
|
success,
|
|
@@ -430,17 +261,18 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
430
261
|
};
|
|
431
262
|
}
|
|
432
263
|
stream.length = 0;
|
|
433
|
-
|
|
264
|
+
for (const token of trimArray(tokens)) {
|
|
265
|
+
stream.push(token);
|
|
266
|
+
}
|
|
434
267
|
}
|
|
435
268
|
}
|
|
436
269
|
stream.length = 0;
|
|
437
270
|
stream.push(...parts
|
|
438
271
|
.filter((p) => p.length > 0 && p[0].typ !== EnumToken.InvalidMediaQueryTokenType)
|
|
439
272
|
.reduce((acc, b) => {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
acc.push(...b);
|
|
273
|
+
for (const token of b) {
|
|
274
|
+
acc.push(token);
|
|
275
|
+
}
|
|
444
276
|
return acc;
|
|
445
277
|
}, []));
|
|
446
278
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { tokensfuncDefMap,
|
|
2
|
+
import { tokensfuncDefMap, LOCSTA } from '../../syntax/constants.js';
|
|
3
3
|
import { equalsIgnoreCase } from './text.js';
|
|
4
4
|
|
|
5
5
|
function matchGenericSyntax(stream, options) {
|
|
@@ -28,7 +28,7 @@ function matchGenericSyntax(stream, options) {
|
|
|
28
28
|
action: "drop",
|
|
29
29
|
message: `unexpected token ${EnumToken[token.typ]}`,
|
|
30
30
|
node: token,
|
|
31
|
-
location: options.source.getSourceLocation(token[
|
|
31
|
+
location: options.source.getSourceLocation(token[LOCSTA]),
|
|
32
32
|
});
|
|
33
33
|
success = false;
|
|
34
34
|
break;
|
|
@@ -43,7 +43,7 @@ function matchGenericSyntax(stream, options) {
|
|
|
43
43
|
action: "drop",
|
|
44
44
|
message: `unexpected token ${EnumToken[token.typ]}`,
|
|
45
45
|
node: token,
|
|
46
|
-
location: options.source.getSourceLocation(token[
|
|
46
|
+
location: options.source.getSourceLocation(token[LOCSTA]),
|
|
47
47
|
});
|
|
48
48
|
success = false;
|
|
49
49
|
break;
|
|
@@ -59,7 +59,7 @@ function matchGenericSyntax(stream, options) {
|
|
|
59
59
|
action: "drop",
|
|
60
60
|
message: `unexpected token ${EnumToken[token.typ]}`,
|
|
61
61
|
node: token,
|
|
62
|
-
location: options.source.getSourceLocation(token[
|
|
62
|
+
location: options.source.getSourceLocation(token[LOCSTA]),
|
|
63
63
|
});
|
|
64
64
|
success = false;
|
|
65
65
|
break;
|
|
@@ -75,7 +75,7 @@ function matchGenericSyntax(stream, options) {
|
|
|
75
75
|
action: "drop",
|
|
76
76
|
message: `unexpected token ${EnumToken[token.typ]}`,
|
|
77
77
|
node: token,
|
|
78
|
-
location: options.source.getSourceLocation(token[
|
|
78
|
+
location: options.source.getSourceLocation(token[LOCSTA]),
|
|
79
79
|
});
|
|
80
80
|
success = false;
|
|
81
81
|
break;
|
|
@@ -95,8 +95,7 @@ function matchGenericSyntax(stream, options) {
|
|
|
95
95
|
action: "drop",
|
|
96
96
|
message: `unexpected token ${EnumToken[stack.at(-1)?.typ]}`,
|
|
97
97
|
node: stack.at(-1),
|
|
98
|
-
|
|
99
|
-
location: options.source.getSourceLocation(stack.at(-1)?.[LOC].sta),
|
|
98
|
+
location: options.source.getSourceLocation(stack.at(-1)?.[LOCSTA]),
|
|
100
99
|
});
|
|
101
100
|
success = false;
|
|
102
101
|
}
|
|
@@ -2,7 +2,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
2
2
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
3
3
|
import { trimArray } from '../../validation/match.js';
|
|
4
4
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
5
|
-
import { tokensfuncDefMap,
|
|
5
|
+
import { tokensfuncDefMap, LOCEND, LOCSTA } from '../../syntax/constants.js';
|
|
6
6
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
7
7
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
8
8
|
|
|
@@ -38,11 +38,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
const slice = stream.slice(index + 1, k);
|
|
41
|
-
|
|
42
|
-
stream[0][LOC] = {
|
|
43
|
-
...stream[0][LOC],
|
|
44
|
-
end: stream[1][LOC].end,
|
|
45
|
-
};
|
|
41
|
+
stream[0][LOCEND] = stream[1][LOCEND];
|
|
46
42
|
tokens.push(Object.assign({
|
|
47
43
|
typ: tokensfuncDefMap.get(stream[0].typ),
|
|
48
44
|
chi: trimArray(slice),
|
|
@@ -58,7 +54,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
58
54
|
message: "Expected string or url()",
|
|
59
55
|
syntax: "@import",
|
|
60
56
|
node: stream[0],
|
|
61
|
-
location: stream[0]?.[
|
|
57
|
+
location: options.source.getSourceLocation(stream[0]?.[LOCSTA]),
|
|
62
58
|
},
|
|
63
59
|
],
|
|
64
60
|
};
|
|
@@ -88,7 +84,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
88
84
|
message: `Expected <layer-name>`,
|
|
89
85
|
syntax: "@import",
|
|
90
86
|
node: stream[index],
|
|
91
|
-
location: options.source.getSourceLocation(stream[index]?.[
|
|
87
|
+
location: options.source.getSourceLocation(stream[index]?.[LOCSTA]),
|
|
92
88
|
},
|
|
93
89
|
],
|
|
94
90
|
};
|
|
@@ -115,7 +111,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
115
111
|
message: `Expected <layer-name>`,
|
|
116
112
|
syntax: "@import",
|
|
117
113
|
node: stream[index],
|
|
118
|
-
location: options.source.getSourceLocation(stream[index]?.[
|
|
114
|
+
location: options.source.getSourceLocation(stream[index]?.[LOCSTA]),
|
|
119
115
|
},
|
|
120
116
|
],
|
|
121
117
|
};
|
|
@@ -157,7 +153,9 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
157
153
|
{
|
|
158
154
|
const result = parseAtRuleSupportSyntax(tokens[tokens.length - 1].chi, context, options);
|
|
159
155
|
if (!result.success && result.errors.length > 0) {
|
|
160
|
-
|
|
156
|
+
for (const error of result.errors) {
|
|
157
|
+
errors.push(error);
|
|
158
|
+
}
|
|
161
159
|
return {
|
|
162
160
|
success: false,
|
|
163
161
|
errors,
|
|
@@ -167,15 +165,21 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
167
165
|
}
|
|
168
166
|
const splice = stream.splice(index, stream.length - index);
|
|
169
167
|
const sliced = parseMediaqueryList(splice, options);
|
|
170
|
-
|
|
168
|
+
for (const sp of splice) {
|
|
169
|
+
tokens.push(sp);
|
|
170
|
+
}
|
|
171
171
|
if (sliced.errors.length > 0) {
|
|
172
|
-
|
|
172
|
+
for (const error of sliced.errors) {
|
|
173
|
+
errors.push(error);
|
|
174
|
+
}
|
|
173
175
|
}
|
|
174
176
|
if (!sliced.success) {
|
|
175
177
|
success = false;
|
|
176
178
|
}
|
|
177
179
|
stream.length = 0;
|
|
178
|
-
|
|
180
|
+
for (const token of trimArray(tokens)) {
|
|
181
|
+
stream.push(token);
|
|
182
|
+
}
|
|
179
183
|
return {
|
|
180
184
|
success,
|
|
181
185
|
errors,
|