@tbela99/css-parser 1.4.6 → 1.4.8
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 +23 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6578 -6969
- package/dist/index.cjs +7808 -8197
- package/dist/index.d.ts +923 -51
- package/dist/lib/ast/clone.js +16 -23
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/if.js +88 -87
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +26 -22
- package/dist/lib/ast/features/transform.js +3 -3
- package/dist/lib/ast/find.js +17 -14
- package/dist/lib/ast/minify.js +97 -94
- package/dist/lib/ast/types.js +10 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +47 -45
- package/dist/lib/parser/arena.js +206 -0
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/linemap.js +62 -0
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/source.js +72 -0
- package/dist/lib/parser/tokenize.js +39 -33
- package/dist/lib/parser/utils/at-rule-container.js +244 -247
- package/dist/lib/parser/utils/at-rule-generic.js +25 -25
- package/dist/lib/parser/utils/at-rule-import.js +194 -234
- package/dist/lib/parser/utils/at-rule-media.js +284 -283
- package/dist/lib/parser/utils/at-rule-support.js +279 -251
- package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
- package/dist/lib/parser/utils/at-rule.js +19 -16
- package/dist/lib/parser/utils/cache.js +33 -5
- package/dist/lib/parser/utils/declaration.js +260 -298
- package/dist/lib/parser/utils/hash.js +15 -15
- package/dist/lib/parser/utils/selector.js +182 -222
- package/dist/lib/parser/utils/token.js +4 -7
- package/dist/lib/renderer/render.js +152 -121
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color-mix.js +8 -1
- package/dist/lib/syntax/color/color.js +17 -9
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/utils/colorspace.js +3 -3
- package/dist/lib/syntax/color/utils/components.js +21 -22
- package/dist/lib/syntax/color/utils/distance.js +6 -1
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +25 -3
- package/dist/lib/syntax/syntax.js +240 -311
- package/dist/lib/validation/config.js +16 -17
- package/dist/lib/validation/match.js +1118 -1131
- package/dist/lib/validation/parser/parse.js +130 -286
- package/dist/node.js +18 -14
- package/dist/web.js +12 -10
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
- /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EnumToken, EnumAstNodeStatus, ColorType, ValidationLevel } from '../../ast/types.js';
|
|
2
|
-
import {
|
|
3
|
-
import { renamedStandardProperties, isColor, parseColor, isWhiteSpace
|
|
2
|
+
import { LOC, STATE, ERRORS, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace } from '../../syntax/constants.js';
|
|
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';
|
|
6
6
|
import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
|
|
@@ -47,44 +47,41 @@ function parseGridTemplate(template) {
|
|
|
47
47
|
* @param tokens
|
|
48
48
|
* @returns
|
|
49
49
|
*/
|
|
50
|
-
function isDeclarationValue(tokens) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
: [],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
50
|
+
// export function isDeclarationValue(tokens: Token[]): { success: boolean; errors: ErrorDescription[] } {
|
|
51
|
+
// const stack: Token[] = [];
|
|
52
|
+
// let i: number = 0;
|
|
53
|
+
// for (; i < tokens.length; i++) {
|
|
54
|
+
// if (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType) {
|
|
55
|
+
// continue;
|
|
56
|
+
// } else if (tokensfuncDefMap.has(tokens[i].typ) || tokens[i].typ === EnumToken.StartParensTokenType) {
|
|
57
|
+
// stack.push(tokens[i]);
|
|
58
|
+
// } else if (tokens[i].typ === EnumToken.CommaTokenType || tokens[i].typ === EnumToken.LiteralTokenType) {
|
|
59
|
+
// stack.push(tokens[i]);
|
|
60
|
+
// } else if (isValue(tokens[i])) {
|
|
61
|
+
// if (stack.at(-1)?.typ === EnumToken.LiteralTokenType) {
|
|
62
|
+
// stack.pop();
|
|
63
|
+
// }
|
|
64
|
+
// } else if (tokens[i].typ === EnumToken.EndParensTokenType) {
|
|
65
|
+
// if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
66
|
+
// stack.pop();
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
// return {
|
|
71
|
+
// success: stack.length === 0,
|
|
72
|
+
// errors:
|
|
73
|
+
// stack.length > 0
|
|
74
|
+
// ? [
|
|
75
|
+
// {
|
|
76
|
+
// action: "drop",
|
|
77
|
+
// message: `unexpected declaration value at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
78
|
+
// node: stack.at(-1),
|
|
79
|
+
// location: stack.at(-1)?.[LOC],
|
|
80
|
+
// },
|
|
81
|
+
// ]
|
|
82
|
+
// : [],
|
|
83
|
+
// };
|
|
84
|
+
// }
|
|
88
85
|
/**
|
|
89
86
|
* Parse declaration
|
|
90
87
|
* @param tokens
|
|
@@ -98,9 +95,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
98
95
|
let rules = null;
|
|
99
96
|
let syntaxRules = null;
|
|
100
97
|
let success = true;
|
|
101
|
-
let validate = typeof options.validation === "boolean"
|
|
102
|
-
? options.validation
|
|
103
|
-
: !!options.validation;
|
|
98
|
+
let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
|
|
104
99
|
if (renamedStandardProperties.has(name.val)) {
|
|
105
100
|
name.val = renamedStandardProperties.get(name.val);
|
|
106
101
|
}
|
|
@@ -115,79 +110,77 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
115
110
|
}
|
|
116
111
|
if ((name.typ !== EnumToken.IdenTokenType && name.typ !== EnumToken.DashedIdenTokenType) ||
|
|
117
112
|
tokens[i]?.typ !== EnumToken.ColonTokenType) {
|
|
118
|
-
|
|
113
|
+
name[LOC] = {
|
|
114
|
+
...name[LOC],
|
|
115
|
+
end: tokens[tokens.length - 1]?.[LOC]?.end ?? name[LOC].end,
|
|
116
|
+
};
|
|
117
|
+
name[STATE] = EnumAstNodeStatus.Unparsed;
|
|
118
|
+
name[ERRORS] = [
|
|
119
|
+
{
|
|
120
|
+
action: "drop",
|
|
121
|
+
node: name,
|
|
122
|
+
location: name[LOC],
|
|
123
|
+
message: "invalid declaration",
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
return Object.assign({
|
|
119
127
|
typ: EnumToken.RawNodeTokenType,
|
|
120
128
|
val: tokens,
|
|
121
|
-
}), {
|
|
122
|
-
state: {
|
|
123
|
-
...definedPropertySettings,
|
|
124
|
-
value: EnumAstNodeStatus.Unparsed,
|
|
125
|
-
},
|
|
126
|
-
errors: {
|
|
127
|
-
...definedPropertySettings,
|
|
128
|
-
value: [
|
|
129
|
-
{
|
|
130
|
-
action: "drop",
|
|
131
|
-
node: name,
|
|
132
|
-
location: name.loc,
|
|
133
|
-
message: "invalid declaration",
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
},
|
|
137
|
-
loc: {
|
|
138
|
-
...definedPropertySettings,
|
|
139
|
-
value: {
|
|
140
|
-
...name.loc,
|
|
141
|
-
end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
129
|
});
|
|
145
130
|
}
|
|
146
131
|
tokens = trimArray(tokens.slice(i + 1));
|
|
147
|
-
for (i = 0; i < tokens.length; i++) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
132
|
+
// for (i = 0; i < tokens.length; i++) {
|
|
133
|
+
// const token = tokens[i];
|
|
134
|
+
// if (
|
|
135
|
+
// token.typ == EnumToken.WhitespaceTokenType ||
|
|
136
|
+
// token.typ == EnumToken.CommentTokenType ||
|
|
137
|
+
// token.typ == EnumToken.InvalidCommentTokenType
|
|
138
|
+
// ) {
|
|
139
|
+
// continue;
|
|
140
|
+
// }
|
|
141
|
+
// if (tokens[i].typ === EnumToken.UrlFunctionTokenDefType) {
|
|
142
|
+
// let k: number = i;
|
|
143
|
+
// while (k < tokens.length) {
|
|
144
|
+
// if (
|
|
145
|
+
// tokens[++k]?.typ === EnumToken.WhitespaceTokenType ||
|
|
146
|
+
// tokens[k]?.typ === EnumToken.CommentTokenType
|
|
147
|
+
// ) {
|
|
148
|
+
// continue;
|
|
149
|
+
// }
|
|
150
|
+
// if (tokens[k]?.typ !== EnumToken.EndParensTokenType) {
|
|
151
|
+
// break;
|
|
152
|
+
// }
|
|
153
|
+
// }
|
|
154
|
+
// if (
|
|
155
|
+
// tokens[k].typ === EnumToken.LiteralTokenType ||
|
|
156
|
+
// tokens[k].typ === EnumToken.IdenTokenType ||
|
|
157
|
+
// tokens[k].typ === EnumToken.DashedIdenTokenType ||
|
|
158
|
+
// tokens[k].typ === EnumToken.HashTokenType ||
|
|
159
|
+
// tokens[k].typ === EnumToken.ClassSelectorTokenType
|
|
160
|
+
// ) {
|
|
161
|
+
// let j: number = k;
|
|
162
|
+
// let val: string = (tokens[k] as LiteralToken | IdentToken | DashedIdentToken | HashToken).val;
|
|
163
|
+
// while (j + 1 < tokens.length) {
|
|
164
|
+
// if (
|
|
165
|
+
// tokens[++j].typ !== EnumToken.LiteralTokenType &&
|
|
166
|
+
// tokens[j].typ !== EnumToken.IdenTokenType &&
|
|
167
|
+
// tokens[j].typ !== EnumToken.DashedIdenTokenType &&
|
|
168
|
+
// tokens[j].typ !== EnumToken.HashTokenType &&
|
|
169
|
+
// tokens[j].typ !== EnumToken.ClassSelectorTokenType
|
|
170
|
+
// ) {
|
|
171
|
+
// break;
|
|
172
|
+
// }
|
|
173
|
+
// val += (tokens[j] as LiteralToken | IdentToken | DashedIdentToken | HashToken).val;
|
|
174
|
+
// }
|
|
175
|
+
// Object.assign(tokens[k] as LiteralToken | IdentToken | DashedIdentToken | HashToken, {
|
|
176
|
+
// typ: EnumToken.UrlTokenTokenType,
|
|
177
|
+
// val,
|
|
178
|
+
// });
|
|
179
|
+
// tokens[k][LOC]!.end = tokens[j][LOC]!.end;
|
|
180
|
+
// tokens.splice(k + 1, j - k - 1);
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
// }
|
|
191
184
|
if (validate && name.typ === EnumToken.IdenTokenType) {
|
|
192
185
|
if (parent != null &&
|
|
193
186
|
parent.typ === EnumToken.AtRuleNodeType &&
|
|
@@ -208,45 +201,39 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
208
201
|
rules.acceptAnyDeclaration && rules.acceptAnyRule
|
|
209
202
|
? getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase())
|
|
210
203
|
: rules.getBlockRules();
|
|
211
|
-
if (syntaxRules == null) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
end: tokens[tokens.length - 1].loc.end,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
204
|
+
// if (syntaxRules == null) {
|
|
205
|
+
// // check rule in nested context
|
|
206
|
+
// let pr = parent[PARENT] as AstNode | null;
|
|
207
|
+
// while (pr != null && pr.typ !== EnumToken.RuleNodeType) {
|
|
208
|
+
// pr = pr[PARENT];
|
|
209
|
+
// }
|
|
210
|
+
// if (pr != null) {
|
|
211
|
+
// syntaxRules = getParsedSyntax(
|
|
212
|
+
// ValidationSyntaxGroupEnum.Declarations,
|
|
213
|
+
// name.val.toLowerCase(),
|
|
214
|
+
// );
|
|
215
|
+
// }
|
|
216
|
+
// if (syntaxRules == null) {
|
|
217
|
+
// errors.push({
|
|
218
|
+
// action: "drop",
|
|
219
|
+
// message: "declaration not allowed in context",
|
|
220
|
+
// node: name,
|
|
221
|
+
// location: name[LOC],
|
|
222
|
+
// });
|
|
223
|
+
// name[LOC] = {
|
|
224
|
+
// ...name[LOC],
|
|
225
|
+
// end: tokens[tokens.length - 1][LOC]!.end,
|
|
226
|
+
// } as Location;
|
|
227
|
+
// name[STATE] = EnumAstNodeStatus.Disallowed;
|
|
228
|
+
// name[ERRORS] = [errors[errors.length - 1]];
|
|
229
|
+
// // @ts-expect-error
|
|
230
|
+
// return Object.assign(name, {
|
|
231
|
+
// typ: EnumToken.DeclarationNodeType,
|
|
232
|
+
// nam: name.val,
|
|
233
|
+
// val: tokens,
|
|
234
|
+
// }) as AstDeclaration;
|
|
235
|
+
// }
|
|
236
|
+
// }
|
|
250
237
|
}
|
|
251
238
|
}
|
|
252
239
|
}
|
|
@@ -284,28 +271,19 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
284
271
|
action: "drop",
|
|
285
272
|
message: "declaration value missing",
|
|
286
273
|
node: name,
|
|
287
|
-
location: name
|
|
274
|
+
location: name[LOC],
|
|
288
275
|
});
|
|
289
|
-
|
|
276
|
+
name[LOC] = {
|
|
277
|
+
...name[LOC],
|
|
278
|
+
end: tokens[tokens.length - 1]?.[LOC].end ?? name[LOC].end,
|
|
279
|
+
};
|
|
280
|
+
name[STATE] = EnumAstNodeStatus.Invalid;
|
|
281
|
+
name[ERRORS] = [errors[errors.length - 1]];
|
|
282
|
+
// @ts-expect-error
|
|
283
|
+
return Object.assign(name, {
|
|
290
284
|
typ: EnumToken.DeclarationNodeType,
|
|
291
285
|
nam: name.val,
|
|
292
286
|
val: tokens,
|
|
293
|
-
}), {
|
|
294
|
-
state: {
|
|
295
|
-
...definedPropertySettings,
|
|
296
|
-
value: EnumAstNodeStatus.Invalid,
|
|
297
|
-
},
|
|
298
|
-
errors: {
|
|
299
|
-
...definedPropertySettings,
|
|
300
|
-
value: [errors[errors.length - 1]],
|
|
301
|
-
},
|
|
302
|
-
loc: {
|
|
303
|
-
...definedPropertySettings,
|
|
304
|
-
value: {
|
|
305
|
-
...name.loc,
|
|
306
|
-
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
287
|
});
|
|
310
288
|
}
|
|
311
289
|
const stack = [];
|
|
@@ -336,21 +314,23 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
336
314
|
}
|
|
337
315
|
for (i = 0; i < tokens.length; i++) {
|
|
338
316
|
token = tokens[i];
|
|
339
|
-
if (tokensfuncDefMap.has(token.typ) ||
|
|
317
|
+
if (tokensfuncDefMap.has(token.typ) ||
|
|
318
|
+
token.typ == EnumToken.StartParensTokenType ||
|
|
319
|
+
token.typ == EnumToken.BlockStartTokenType) {
|
|
340
320
|
stack.push(token);
|
|
341
321
|
continue;
|
|
342
322
|
}
|
|
343
323
|
switch (token.typ) {
|
|
344
|
-
case EnumToken.IdenTokenType:
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
324
|
+
// case EnumToken.IdenTokenType:
|
|
325
|
+
// if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
|
|
326
|
+
// Object.assign(token, {
|
|
327
|
+
// typ: EnumToken.FunctionTokenDefType,
|
|
328
|
+
// });
|
|
329
|
+
// token[LOC]!.end = tokens[i + 1][LOC]!.end;
|
|
330
|
+
// tokens.splice(i + 1, 1);
|
|
331
|
+
// stack.push(token);
|
|
332
|
+
// }
|
|
333
|
+
// break;
|
|
354
334
|
case EnumToken.Literal:
|
|
355
335
|
if (token.val === "/" && stack.at(-1)?.typ == EnumToken.MathFunctionTokenDefType) {
|
|
356
336
|
Object.assign(token, {
|
|
@@ -370,36 +350,40 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
370
350
|
typ: tokensMap.get(token.typ),
|
|
371
351
|
});
|
|
372
352
|
break;
|
|
373
|
-
case EnumToken.
|
|
374
|
-
if (stack.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return Object.defineProperties(Object.assign(name, {
|
|
382
|
-
typ: EnumToken.DeclarationNodeType,
|
|
383
|
-
nam: name.val,
|
|
384
|
-
val: tokens,
|
|
385
|
-
}), {
|
|
386
|
-
state: {
|
|
387
|
-
...definedPropertySettings,
|
|
388
|
-
value: EnumAstNodeStatus.Invalid,
|
|
389
|
-
},
|
|
390
|
-
errors: {
|
|
391
|
-
...definedPropertySettings,
|
|
392
|
-
value: errors[errors.length - 1],
|
|
393
|
-
},
|
|
394
|
-
loc: {
|
|
395
|
-
...definedPropertySettings,
|
|
396
|
-
value: {
|
|
397
|
-
...name.loc,
|
|
398
|
-
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
|
|
399
|
-
},
|
|
400
|
-
},
|
|
353
|
+
case EnumToken.BlockEndTokenType:
|
|
354
|
+
if (stack.at(-1)?.typ === EnumToken.BlockStartTokenType) {
|
|
355
|
+
// stack.pop();index = tokens.indexOf(stack.at(-1)!);
|
|
356
|
+
index = tokens.indexOf(stack.at(-1));
|
|
357
|
+
tokens.splice(i, 1);
|
|
358
|
+
Object.assign(tokens[index], {
|
|
359
|
+
typ: EnumToken.WrappedValuesTokenType,
|
|
360
|
+
chi: trimArray(tokens.splice(index + 1, i - index - 1)),
|
|
401
361
|
});
|
|
362
|
+
i = index;
|
|
363
|
+
stack.pop();
|
|
402
364
|
}
|
|
365
|
+
break;
|
|
366
|
+
case EnumToken.EndParensTokenType:
|
|
367
|
+
// if (stack.length == 0) {
|
|
368
|
+
// errors.push({
|
|
369
|
+
// action: "drop",
|
|
370
|
+
// message: "unbalanced parentheses",
|
|
371
|
+
// node: token,
|
|
372
|
+
// location: token[LOC],
|
|
373
|
+
// });
|
|
374
|
+
// name[LOC] = {
|
|
375
|
+
// ...name[LOC],
|
|
376
|
+
// end: tokens[tokens.length - 1]?.[LOC]!.end ?? name[LOC]!.end,
|
|
377
|
+
// } as Location;
|
|
378
|
+
// name[STATE] = EnumAstNodeStatus.Invalid;
|
|
379
|
+
// name[ERRORS] = [errors[errors.length - 1]];
|
|
380
|
+
// // @ts-expect-error
|
|
381
|
+
// return Object.assign(name, {
|
|
382
|
+
// typ: EnumToken.DeclarationNodeType,
|
|
383
|
+
// nam: name.val,
|
|
384
|
+
// val: tokens,
|
|
385
|
+
// }) as AstDeclaration;
|
|
386
|
+
// }
|
|
403
387
|
if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
404
388
|
index = tokens.indexOf(stack.at(-1));
|
|
405
389
|
tokens.splice(i, 1);
|
|
@@ -439,7 +423,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
439
423
|
r: {
|
|
440
424
|
typ: EnumToken.IfConditionTokenType,
|
|
441
425
|
l: trimArray(curr.slice(0, index)),
|
|
442
|
-
r: trimArray(curr.
|
|
426
|
+
r: trimArray(curr.at(-1)?.typ === EnumToken.SemiColonTokenType
|
|
427
|
+
? curr.slice(index + 1, -1)
|
|
428
|
+
: curr.slice(index + 1)),
|
|
443
429
|
},
|
|
444
430
|
};
|
|
445
431
|
}
|
|
@@ -459,19 +445,24 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
459
445
|
if (tokens[index].chi[l].typ === EnumToken.StringTokenType) {
|
|
460
446
|
break;
|
|
461
447
|
}
|
|
462
|
-
else if (tokens[index].chi[l].typ === EnumToken.IdenTokenType) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
448
|
+
// else if ((tokens[index] as FunctionToken).chi[l].typ === EnumToken.IdenTokenType) {
|
|
449
|
+
// let m: number = l + 1;
|
|
450
|
+
// while (
|
|
451
|
+
// (tokens[index] as FunctionToken).chi[m]?.typ === EnumToken.ClassSelectorTokenType
|
|
452
|
+
// ) {
|
|
453
|
+
// Object.assign((tokens[index] as FunctionToken).chi[l], {
|
|
454
|
+
// typ: EnumToken.UrlTokenTokenType,
|
|
455
|
+
// val:
|
|
456
|
+
// ((tokens[index] as FunctionToken).chi[l] as IdentToken | UrlToken).val +
|
|
457
|
+
// ((tokens[index] as FunctionToken).chi[m] as ClassSelectorToken).val,
|
|
458
|
+
// });
|
|
459
|
+
// (tokens[index] as FunctionToken).chi[l][LOC]!.end = (
|
|
460
|
+
// tokens[index] as FunctionToken
|
|
461
|
+
// ).chi[m][LOC]!.end;
|
|
462
|
+
// (tokens[index] as FunctionToken).chi.splice(m, 1);
|
|
463
|
+
// }
|
|
464
|
+
// break;
|
|
465
|
+
// }
|
|
475
466
|
}
|
|
476
467
|
if (tokens[index].chi[l]?.typ === EnumToken.StringTokenType &&
|
|
477
468
|
/^[a-zA-Z0-0/_.-]+$/.test(tokens[index].chi[l].val.slice(1, -1))) {
|
|
@@ -495,12 +486,12 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
495
486
|
tokens[index].typ = EnumToken.FunctionTokenType;
|
|
496
487
|
errors.push({
|
|
497
488
|
action: "drop",
|
|
498
|
-
message: `invalid color at ${tokens[index]
|
|
489
|
+
message: `invalid color at ${tokens[index][LOC]?.src}:${tokens[index][LOC]?.sta.lin}:${tokens[index][LOC]?.sta.col}`,
|
|
499
490
|
});
|
|
500
491
|
}
|
|
501
492
|
}
|
|
493
|
+
stack.pop();
|
|
502
494
|
}
|
|
503
|
-
stack.pop();
|
|
504
495
|
break;
|
|
505
496
|
case EnumToken.IdenTokenType:
|
|
506
497
|
{
|
|
@@ -545,30 +536,21 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
545
536
|
if (stack.length > 0) {
|
|
546
537
|
errors.push({
|
|
547
538
|
action: "drop",
|
|
548
|
-
message: "unbalanced
|
|
539
|
+
message: "unbalanced token",
|
|
549
540
|
node: stack[stack.length - 1],
|
|
550
|
-
location: stack[stack.length - 1]
|
|
541
|
+
location: stack[stack.length - 1][LOC],
|
|
551
542
|
});
|
|
552
|
-
|
|
543
|
+
name[LOC] = {
|
|
544
|
+
...name[LOC],
|
|
545
|
+
end: tokens[tokens.length - 1][LOC].end,
|
|
546
|
+
};
|
|
547
|
+
name[STATE] = EnumAstNodeStatus.Invalid;
|
|
548
|
+
name[ERRORS] = result?.errors ?? [];
|
|
549
|
+
//@ts-expect-error
|
|
550
|
+
return Object.assign(name, {
|
|
553
551
|
typ: EnumToken.DeclarationNodeType,
|
|
554
552
|
nam: name.val,
|
|
555
553
|
val: tokens,
|
|
556
|
-
}), {
|
|
557
|
-
state: {
|
|
558
|
-
...definedPropertySettings,
|
|
559
|
-
value: EnumAstNodeStatus.Invalid,
|
|
560
|
-
},
|
|
561
|
-
errors: {
|
|
562
|
-
...definedPropertySettings,
|
|
563
|
-
value: result?.errors ?? [],
|
|
564
|
-
},
|
|
565
|
-
loc: {
|
|
566
|
-
...definedPropertySettings,
|
|
567
|
-
value: {
|
|
568
|
-
...name.loc,
|
|
569
|
-
end: tokens[tokens.length - 1].loc.end,
|
|
570
|
-
},
|
|
571
|
-
},
|
|
572
554
|
});
|
|
573
555
|
}
|
|
574
556
|
for (const { value } of walkValues(tokens)) {
|
|
@@ -594,35 +576,26 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
594
576
|
}
|
|
595
577
|
}
|
|
596
578
|
if (validate && syntaxRules == null && name.typ === EnumToken.IdenTokenType) {
|
|
597
|
-
|
|
579
|
+
name[LOC] = {
|
|
580
|
+
...name[LOC],
|
|
581
|
+
end: tokens[tokens.length - 1]?.[LOC]?.end ?? name[LOC].end,
|
|
582
|
+
};
|
|
583
|
+
name[STATE] = EnumAstNodeStatus.Unknown;
|
|
584
|
+
name[ERRORS] = result?.errors ?? [];
|
|
585
|
+
// @ts-expect-error
|
|
586
|
+
const node = Object.assign(name, {
|
|
598
587
|
typ: EnumToken.DeclarationNodeType,
|
|
599
588
|
nam: name.val,
|
|
600
589
|
val: tokens,
|
|
601
|
-
}), {
|
|
602
|
-
state: {
|
|
603
|
-
...definedPropertySettings,
|
|
604
|
-
value: EnumAstNodeStatus.Unknown,
|
|
605
|
-
},
|
|
606
|
-
errors: {
|
|
607
|
-
...definedPropertySettings,
|
|
608
|
-
value: result?.errors ?? [],
|
|
609
|
-
},
|
|
610
|
-
loc: {
|
|
611
|
-
...definedPropertySettings,
|
|
612
|
-
value: {
|
|
613
|
-
...name.loc,
|
|
614
|
-
end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
|
|
615
|
-
},
|
|
616
|
-
},
|
|
617
590
|
});
|
|
618
|
-
if (options.validation & ValidationLevel.Declaration) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
591
|
+
// if ((options.validation as ValidationLevel) & ValidationLevel.Declaration) {
|
|
592
|
+
// errors.push({
|
|
593
|
+
// action: "drop",
|
|
594
|
+
// message: "unknown declaration",
|
|
595
|
+
// node: node,
|
|
596
|
+
// location: node[LOC],
|
|
597
|
+
// });
|
|
598
|
+
// }
|
|
626
599
|
return node;
|
|
627
600
|
}
|
|
628
601
|
if (equalsIgnoreCase("composes", name.val)) {
|
|
@@ -636,45 +609,34 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
636
609
|
const left = trimArray(index == -1 ? tokens : tokens.slice(0, index));
|
|
637
610
|
const right = index == -1 ? null : trimArray(tokens.slice(index + 1));
|
|
638
611
|
tokens = [
|
|
639
|
-
|
|
612
|
+
{
|
|
640
613
|
typ: EnumToken.ComposesSelectorNodeType,
|
|
641
614
|
l: left,
|
|
642
615
|
r: right?.[0] ?? null,
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
sta: left[0]?.loc?.sta,
|
|
648
|
-
end: index != -1 ? right[right.length - 1]?.loc?.end : left[left.length - 1].loc.end,
|
|
616
|
+
[LOC]: {
|
|
617
|
+
...tokens[0][LOC],
|
|
618
|
+
sta: left[0]?.[LOC]?.sta,
|
|
619
|
+
end: index != -1 ? right[right.length - 1]?.[LOC]?.end : left[left.length - 1][LOC].end,
|
|
649
620
|
},
|
|
650
|
-
}
|
|
621
|
+
},
|
|
651
622
|
];
|
|
652
623
|
}
|
|
653
|
-
|
|
654
|
-
|
|
624
|
+
name[LOC] = {
|
|
625
|
+
...name[LOC],
|
|
626
|
+
end: (tokens[tokens.length - 1] ?? name)[LOC].end,
|
|
627
|
+
};
|
|
628
|
+
name[STATE] = success
|
|
629
|
+
? result == null
|
|
630
|
+
? EnumAstNodeStatus.Unvalidated
|
|
631
|
+
: EnumAstNodeStatus.Validated
|
|
632
|
+
: EnumAstNodeStatus.ValidationFailed;
|
|
633
|
+
name[ERRORS] = result?.errors ?? [];
|
|
634
|
+
// @ts-expect-error
|
|
635
|
+
return Object.assign(name, {
|
|
636
|
+
typ: EnumToken.DeclarationNodeType,
|
|
655
637
|
nam: name.val,
|
|
656
638
|
val: tokens,
|
|
657
|
-
}), {
|
|
658
|
-
state: {
|
|
659
|
-
...definedPropertySettings,
|
|
660
|
-
value: success
|
|
661
|
-
? result == null
|
|
662
|
-
? EnumAstNodeStatus.Unvalidated
|
|
663
|
-
: EnumAstNodeStatus.Validated
|
|
664
|
-
: EnumAstNodeStatus.ValidationFailed,
|
|
665
|
-
},
|
|
666
|
-
errors: {
|
|
667
|
-
...definedPropertySettings,
|
|
668
|
-
value: result?.errors ?? [],
|
|
669
|
-
},
|
|
670
|
-
loc: {
|
|
671
|
-
...definedPropertySettings,
|
|
672
|
-
value: {
|
|
673
|
-
...name.loc,
|
|
674
|
-
end: (tokens[tokens.length - 1] ?? name).loc.end,
|
|
675
|
-
},
|
|
676
|
-
},
|
|
677
639
|
});
|
|
678
640
|
}
|
|
679
641
|
|
|
680
|
-
export {
|
|
642
|
+
export { parseDeclaration };
|