@tbela99/css-parser 1.4.3 → 1.4.5
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 +196 -2
- package/README.md +68 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +18118 -15886
- package/dist/index.cjs +16838 -14611
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +64 -17
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +530 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { EnumToken, ColorType, ValidationLevel } from '../../ast/types.js';
|
|
1
|
+
import { EnumToken, EnumAstNodeStatus, ColorType, ValidationLevel } from '../../ast/types.js';
|
|
2
2
|
import { definedPropertySettings, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace } from '../../syntax/constants.js';
|
|
3
3
|
import { renamedStandardProperties, isColor, parseColor, isWhiteSpace, isValue } from '../../syntax/syntax.js';
|
|
4
4
|
import { getSyntaxRule, getParsedSyntax } from '../../validation/config.js';
|
|
5
|
-
import { trimArray,
|
|
5
|
+
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
6
6
|
import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
|
|
7
7
|
import { walkValues } from '../../ast/walk.js';
|
|
8
8
|
import { equalsIgnoreCase } from './text.js';
|
|
9
9
|
import { buildExpression } from '../../ast/math/expression.js';
|
|
10
10
|
import { splitTokenList } from '../../validation/utils/list.js';
|
|
11
|
+
import { parseTokens } from '../parse.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
@@ -86,7 +87,7 @@ function isDeclarationValue(tokens) {
|
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
|
-
*
|
|
90
|
+
* Parse declaration
|
|
90
91
|
* @param tokens
|
|
91
92
|
* @param parent
|
|
92
93
|
* @param options
|
|
@@ -100,7 +101,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
100
101
|
let success = true;
|
|
101
102
|
let validate = typeof options.validation === "boolean"
|
|
102
103
|
? options.validation
|
|
103
|
-
: options.validation
|
|
104
|
+
: !!options.validation;
|
|
104
105
|
if (renamedStandardProperties.has(name.val)) {
|
|
105
106
|
name.val = renamedStandardProperties.get(name.val);
|
|
106
107
|
}
|
|
@@ -115,14 +116,31 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
115
116
|
}
|
|
116
117
|
if ((name.typ !== EnumToken.IdenTokenType && name.typ !== EnumToken.DashedIdenTokenType) ||
|
|
117
118
|
tokens[i]?.typ !== EnumToken.ColonTokenType) {
|
|
118
|
-
return Object.
|
|
119
|
+
return Object.defineProperties(Object.assign({
|
|
119
120
|
typ: EnumToken.RawNodeTokenType,
|
|
120
|
-
|
|
121
|
-
}),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
val: tokens,
|
|
122
|
+
}), {
|
|
123
|
+
state: {
|
|
124
|
+
...definedPropertySettings,
|
|
125
|
+
value: EnumAstNodeStatus.Unparsed,
|
|
126
|
+
},
|
|
127
|
+
errors: {
|
|
128
|
+
...definedPropertySettings,
|
|
129
|
+
value: [
|
|
130
|
+
{
|
|
131
|
+
action: "drop",
|
|
132
|
+
node: name,
|
|
133
|
+
location: name.loc,
|
|
134
|
+
message: "invalid declaration",
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
loc: {
|
|
139
|
+
...definedPropertySettings,
|
|
140
|
+
value: {
|
|
141
|
+
...name.loc,
|
|
142
|
+
end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
|
|
143
|
+
},
|
|
126
144
|
},
|
|
127
145
|
});
|
|
128
146
|
}
|
|
@@ -173,7 +191,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
173
191
|
}
|
|
174
192
|
if (validate && name.typ === EnumToken.IdenTokenType) {
|
|
175
193
|
if (parent != null &&
|
|
176
|
-
|
|
194
|
+
parent.typ === EnumToken.AtRuleNodeType &&
|
|
177
195
|
parent.nam != "import" &&
|
|
178
196
|
parent.nam != "supports" &&
|
|
179
197
|
parent.nam != "media") {
|
|
@@ -188,31 +206,54 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
188
206
|
}
|
|
189
207
|
else {
|
|
190
208
|
syntaxRules =
|
|
191
|
-
rules.
|
|
209
|
+
rules.acceptAnyDeclaration && rules.acceptAnyRule
|
|
192
210
|
? getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase())
|
|
193
211
|
: rules.getBlockRules();
|
|
194
212
|
if (syntaxRules == null) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
// check rule in nested context
|
|
214
|
+
let pr = parent.parent;
|
|
215
|
+
while (pr != null && pr.typ !== EnumToken.RuleNodeType) {
|
|
216
|
+
pr = pr.parent;
|
|
217
|
+
}
|
|
218
|
+
if (pr != null) {
|
|
219
|
+
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase());
|
|
220
|
+
}
|
|
221
|
+
if (syntaxRules == null) {
|
|
222
|
+
errors.push({
|
|
223
|
+
action: "drop",
|
|
224
|
+
message: "declaration not allowed in context",
|
|
225
|
+
node: name,
|
|
226
|
+
location: name.loc,
|
|
227
|
+
});
|
|
228
|
+
return Object.defineProperties(Object.assign(name, {
|
|
229
|
+
typ: EnumToken.DeclarationNodeType,
|
|
230
|
+
nam: name.val,
|
|
231
|
+
val: tokens,
|
|
232
|
+
}), {
|
|
233
|
+
state: {
|
|
234
|
+
...definedPropertySettings,
|
|
235
|
+
value: EnumAstNodeStatus.Disallowed,
|
|
236
|
+
},
|
|
237
|
+
errors: {
|
|
238
|
+
...definedPropertySettings,
|
|
239
|
+
value: [errors[errors.length - 1]],
|
|
240
|
+
},
|
|
241
|
+
loc: {
|
|
242
|
+
...definedPropertySettings,
|
|
243
|
+
value: {
|
|
244
|
+
...name.loc,
|
|
245
|
+
end: tokens[tokens.length - 1].loc.end,
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
}
|
|
212
250
|
}
|
|
213
251
|
}
|
|
214
252
|
}
|
|
215
253
|
}
|
|
254
|
+
else {
|
|
255
|
+
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase());
|
|
256
|
+
}
|
|
216
257
|
// <declaration-list> or <declaration-rule-list>
|
|
217
258
|
// else
|
|
218
259
|
if (syntaxRules == null ||
|
|
@@ -246,15 +287,25 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
246
287
|
node: name,
|
|
247
288
|
location: name.loc,
|
|
248
289
|
});
|
|
249
|
-
return Object.
|
|
250
|
-
typ: EnumToken.
|
|
290
|
+
return Object.defineProperties(Object.assign(name, {
|
|
291
|
+
typ: EnumToken.DeclarationNodeType,
|
|
251
292
|
nam: name.val,
|
|
252
293
|
val: tokens,
|
|
253
|
-
}),
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
294
|
+
}), {
|
|
295
|
+
state: {
|
|
296
|
+
...definedPropertySettings,
|
|
297
|
+
value: EnumAstNodeStatus.Invalid,
|
|
298
|
+
},
|
|
299
|
+
errors: {
|
|
300
|
+
...definedPropertySettings,
|
|
301
|
+
value: [errors[errors.length - 1]],
|
|
302
|
+
},
|
|
303
|
+
loc: {
|
|
304
|
+
...definedPropertySettings,
|
|
305
|
+
value: {
|
|
306
|
+
...name.loc,
|
|
307
|
+
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
|
|
308
|
+
},
|
|
258
309
|
},
|
|
259
310
|
});
|
|
260
311
|
}
|
|
@@ -264,7 +315,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
264
315
|
let index;
|
|
265
316
|
if (syntaxRules != null) {
|
|
266
317
|
const doNotValidate = options.validation === false || options.validation === ValidationLevel.None;
|
|
267
|
-
result = doNotValidate ? null :
|
|
318
|
+
result = doNotValidate ? null : matchAllSyntaxes(syntaxRules, createValidationContext(tokens), options);
|
|
268
319
|
if (doNotValidate || result != null) {
|
|
269
320
|
success = doNotValidate || result?.success;
|
|
270
321
|
if (success) {
|
|
@@ -283,15 +334,25 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
283
334
|
errors.push(...result.errors);
|
|
284
335
|
}
|
|
285
336
|
if (!doNotValidate && !(success || result.success)) {
|
|
286
|
-
return Object.
|
|
287
|
-
typ: EnumToken.
|
|
337
|
+
return Object.defineProperties(Object.assign(name, {
|
|
338
|
+
typ: EnumToken.DeclarationNodeType,
|
|
288
339
|
nam: name.val,
|
|
289
|
-
val: tokens,
|
|
290
|
-
}),
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
340
|
+
val: parseTokens(tokens),
|
|
341
|
+
}), {
|
|
342
|
+
state: {
|
|
343
|
+
...definedPropertySettings,
|
|
344
|
+
value: EnumAstNodeStatus.ValidationFailed,
|
|
345
|
+
},
|
|
346
|
+
errors: {
|
|
347
|
+
...definedPropertySettings,
|
|
348
|
+
value: result?.errors ?? [],
|
|
349
|
+
},
|
|
350
|
+
loc: {
|
|
351
|
+
...definedPropertySettings,
|
|
352
|
+
value: {
|
|
353
|
+
...name.loc,
|
|
354
|
+
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
|
|
355
|
+
},
|
|
295
356
|
},
|
|
296
357
|
});
|
|
297
358
|
}
|
|
@@ -341,15 +402,25 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
341
402
|
node: token,
|
|
342
403
|
location: token.loc,
|
|
343
404
|
});
|
|
344
|
-
return Object.
|
|
345
|
-
typ: EnumToken.
|
|
405
|
+
return Object.defineProperties(Object.assign(name, {
|
|
406
|
+
typ: EnumToken.DeclarationNodeType,
|
|
346
407
|
nam: name.val,
|
|
347
408
|
val: tokens,
|
|
348
|
-
}),
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
409
|
+
}), {
|
|
410
|
+
state: {
|
|
411
|
+
...definedPropertySettings,
|
|
412
|
+
value: EnumAstNodeStatus.Invalid,
|
|
413
|
+
},
|
|
414
|
+
errors: {
|
|
415
|
+
...definedPropertySettings,
|
|
416
|
+
value: errors[errors.length - 1],
|
|
417
|
+
},
|
|
418
|
+
loc: {
|
|
419
|
+
...definedPropertySettings,
|
|
420
|
+
value: {
|
|
421
|
+
...name.loc,
|
|
422
|
+
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
|
|
423
|
+
},
|
|
353
424
|
},
|
|
354
425
|
});
|
|
355
426
|
}
|
|
@@ -502,15 +573,25 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
502
573
|
node: stack[stack.length - 1],
|
|
503
574
|
location: stack[stack.length - 1].loc,
|
|
504
575
|
});
|
|
505
|
-
return Object.
|
|
506
|
-
typ: EnumToken.
|
|
576
|
+
return Object.defineProperties(Object.assign(name, {
|
|
577
|
+
typ: EnumToken.DeclarationNodeType,
|
|
507
578
|
nam: name.val,
|
|
508
579
|
val: tokens,
|
|
509
|
-
}),
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
580
|
+
}), {
|
|
581
|
+
state: {
|
|
582
|
+
...definedPropertySettings,
|
|
583
|
+
value: EnumAstNodeStatus.Invalid,
|
|
584
|
+
},
|
|
585
|
+
errors: {
|
|
586
|
+
...definedPropertySettings,
|
|
587
|
+
value: result?.errors ?? [],
|
|
588
|
+
},
|
|
589
|
+
loc: {
|
|
590
|
+
...definedPropertySettings,
|
|
591
|
+
value: {
|
|
592
|
+
...name.loc,
|
|
593
|
+
end: tokens[tokens.length - 1].loc.end,
|
|
594
|
+
},
|
|
514
595
|
},
|
|
515
596
|
});
|
|
516
597
|
}
|
|
@@ -537,17 +618,25 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
537
618
|
}
|
|
538
619
|
}
|
|
539
620
|
if (validate && syntaxRules == null && name.typ === EnumToken.IdenTokenType) {
|
|
540
|
-
const node = Object.
|
|
541
|
-
typ:
|
|
542
|
-
? EnumToken.InvalidDeclarationNodeType
|
|
543
|
-
: EnumToken.DeclarationNodeType,
|
|
621
|
+
const node = Object.defineProperties(Object.assign(name, {
|
|
622
|
+
typ: EnumToken.DeclarationNodeType,
|
|
544
623
|
nam: name.val,
|
|
545
624
|
val: tokens,
|
|
546
|
-
}),
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
625
|
+
}), {
|
|
626
|
+
state: {
|
|
627
|
+
...definedPropertySettings,
|
|
628
|
+
value: EnumAstNodeStatus.Unknown,
|
|
629
|
+
},
|
|
630
|
+
errors: {
|
|
631
|
+
...definedPropertySettings,
|
|
632
|
+
value: result?.errors ?? [],
|
|
633
|
+
},
|
|
634
|
+
loc: {
|
|
635
|
+
...definedPropertySettings,
|
|
636
|
+
value: {
|
|
637
|
+
...name.loc,
|
|
638
|
+
end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
|
|
639
|
+
},
|
|
551
640
|
},
|
|
552
641
|
});
|
|
553
642
|
if (options.validation & ValidationLevel.Declaration) {
|
|
@@ -585,15 +674,29 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
585
674
|
}),
|
|
586
675
|
];
|
|
587
676
|
}
|
|
588
|
-
return Object.
|
|
589
|
-
typ: success ? EnumToken.DeclarationNodeType : EnumToken.
|
|
677
|
+
return Object.defineProperties(Object.assign(name, {
|
|
678
|
+
typ: success ? EnumToken.DeclarationNodeType : EnumToken.DeclarationNodeType,
|
|
590
679
|
nam: name.val,
|
|
591
680
|
val: tokens,
|
|
592
|
-
}),
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
681
|
+
}), {
|
|
682
|
+
state: {
|
|
683
|
+
...definedPropertySettings,
|
|
684
|
+
value: success
|
|
685
|
+
? result == null
|
|
686
|
+
? EnumAstNodeStatus.Unvalidated
|
|
687
|
+
: EnumAstNodeStatus.Validated
|
|
688
|
+
: EnumAstNodeStatus.ValidationFailed,
|
|
689
|
+
},
|
|
690
|
+
errors: {
|
|
691
|
+
...definedPropertySettings,
|
|
692
|
+
value: result?.errors ?? [],
|
|
693
|
+
},
|
|
694
|
+
loc: {
|
|
695
|
+
...definedPropertySettings,
|
|
696
|
+
value: {
|
|
697
|
+
...name.loc,
|
|
698
|
+
end: (tokens[tokens.length - 1] ?? name).loc.end,
|
|
699
|
+
},
|
|
597
700
|
},
|
|
598
701
|
});
|
|
599
702
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import {
|
|
1
|
+
import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
|
|
2
|
+
import { renderValue } from '../../renderer/render.js';
|
|
3
3
|
import { definedPropertySettings, tokensfuncDefMap, combinators } from '../../syntax/constants.js';
|
|
4
4
|
import { pseudoElements, isIdent, isHash } from '../../syntax/syntax.js';
|
|
5
|
-
import { getParsedSyntax, getSyntaxConfig } from '../../validation/config.js';
|
|
6
|
-
import {
|
|
7
|
-
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
5
|
+
import { getParsedSyntax, getSyntaxRule, getSyntaxConfig } from '../../validation/config.js';
|
|
6
|
+
import { matchAllSyntaxes, createValidationContext, trimArray, matchSelectorSyntax } from '../../validation/match.js';
|
|
7
|
+
import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
|
|
8
8
|
import { splitTokenList } from '../../validation/utils/list.js';
|
|
9
9
|
import { trimWhiteSpace } from '../parse.js';
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ import { trimWhiteSpace } from '../parse.js';
|
|
|
13
13
|
*/
|
|
14
14
|
function parseSelector(tokens, context, options, errors) {
|
|
15
15
|
if (context?.typ === EnumToken.KeyframesAtRuleNodeType) {
|
|
16
|
-
const result =
|
|
16
|
+
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "keyframe-selectors"), createValidationContext(tokens), options);
|
|
17
17
|
const parts = splitTokenList(tokens);
|
|
18
18
|
for (const part of parts) {
|
|
19
19
|
trimArray(part);
|
|
@@ -52,15 +52,23 @@ function parseSelector(tokens, context, options, errors) {
|
|
|
52
52
|
return acc;
|
|
53
53
|
}, []));
|
|
54
54
|
return Object.defineProperties({
|
|
55
|
-
typ:
|
|
55
|
+
typ: EnumToken.KeyFramesRuleNodeType,
|
|
56
56
|
sel: [
|
|
57
57
|
...splitTokenList(trimArray(tokens)).reduce((acc, curr) => {
|
|
58
|
-
acc.add(curr.reduce((acc, curr) => acc +
|
|
58
|
+
acc.add(curr.reduce((acc, curr) => acc + renderValue(curr, { minify: false }), ""));
|
|
59
59
|
return acc;
|
|
60
60
|
}, new Set()),
|
|
61
61
|
].join(),
|
|
62
62
|
chi: [],
|
|
63
63
|
}, {
|
|
64
|
+
state: {
|
|
65
|
+
...definedPropertySettings,
|
|
66
|
+
value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
|
|
67
|
+
},
|
|
68
|
+
errors: {
|
|
69
|
+
...definedPropertySettings,
|
|
70
|
+
value: result.errors,
|
|
71
|
+
},
|
|
64
72
|
tokens: { ...definedPropertySettings, value: tokens.length === 0 ? null : tokens },
|
|
65
73
|
loc: {
|
|
66
74
|
...definedPropertySettings,
|
|
@@ -73,11 +81,33 @@ function parseSelector(tokens, context, options, errors) {
|
|
|
73
81
|
}
|
|
74
82
|
const stack = [];
|
|
75
83
|
const uniq = new Map();
|
|
84
|
+
let allowed = true;
|
|
76
85
|
let i = 0;
|
|
77
86
|
let index;
|
|
78
87
|
let parent = context;
|
|
79
88
|
let nested = false;
|
|
80
89
|
let val;
|
|
90
|
+
if (context?.typ !== EnumToken.StyleSheetNodeType && context?.typ !== EnumToken.RuleNodeType) {
|
|
91
|
+
allowed = false;
|
|
92
|
+
if (context?.typ === EnumToken.AtRuleNodeType) {
|
|
93
|
+
const syntaxRule = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
|
|
94
|
+
allowed = syntaxRule?.acceptAnyRule ?? false;
|
|
95
|
+
if (!allowed) {
|
|
96
|
+
const rules = syntaxRule?.getBlockRules?.();
|
|
97
|
+
if (rules != null) {
|
|
98
|
+
for (const rule of rules) {
|
|
99
|
+
if (ValidationTokenEnum.PropertyType === rule.typ) {
|
|
100
|
+
if ("block-contents" === rule.val ||
|
|
101
|
+
"rule-list" === rule.val) {
|
|
102
|
+
allowed = true;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
81
111
|
do {
|
|
82
112
|
if (parent?.typ === EnumToken.AtRuleNodeType && "media" === parent.nam) {
|
|
83
113
|
parent = parent.parent;
|
|
@@ -190,7 +220,7 @@ function parseSelector(tokens, context, options, errors) {
|
|
|
190
220
|
if (tokensfuncDefMap.has(func.typ)) {
|
|
191
221
|
// @ts-expect-error
|
|
192
222
|
func.typ = tokensfuncDefMap.get(func.typ);
|
|
193
|
-
func.chi = tokens.splice(index + 1, i - index - 1);
|
|
223
|
+
func.chi = trimArray(tokens.splice(index + 1, i - index - 1));
|
|
194
224
|
}
|
|
195
225
|
if (result.success && options.minify) {
|
|
196
226
|
// parse an+b
|
|
@@ -419,7 +449,7 @@ function parseSelector(tokens, context, options, errors) {
|
|
|
419
449
|
}
|
|
420
450
|
}
|
|
421
451
|
return Object.defineProperties({
|
|
422
|
-
typ:
|
|
452
|
+
typ: EnumToken.RuleNodeType,
|
|
423
453
|
sel: [
|
|
424
454
|
...tokens
|
|
425
455
|
.reduce((acc, curr, index, array) => {
|
|
@@ -434,7 +464,7 @@ function parseSelector(tokens, context, options, errors) {
|
|
|
434
464
|
return acc;
|
|
435
465
|
}
|
|
436
466
|
}
|
|
437
|
-
let t =
|
|
467
|
+
let t = renderValue(curr, { minify: false });
|
|
438
468
|
if (t == ",") {
|
|
439
469
|
acc.push([]);
|
|
440
470
|
}
|
|
@@ -462,6 +492,18 @@ function parseSelector(tokens, context, options, errors) {
|
|
|
462
492
|
].join(","),
|
|
463
493
|
chi: [],
|
|
464
494
|
}, {
|
|
495
|
+
state: {
|
|
496
|
+
...definedPropertySettings,
|
|
497
|
+
value: result.success && allowed
|
|
498
|
+
? EnumAstNodeStatus.Validated
|
|
499
|
+
: allowed
|
|
500
|
+
? EnumAstNodeStatus.Invalid
|
|
501
|
+
: EnumAstNodeStatus.Disallowed,
|
|
502
|
+
},
|
|
503
|
+
errors: {
|
|
504
|
+
...definedPropertySettings,
|
|
505
|
+
value: result.success ? [] : result.errors,
|
|
506
|
+
},
|
|
465
507
|
tokens: { ...definedPropertySettings, value: tokens },
|
|
466
508
|
loc: {
|
|
467
509
|
...definedPropertySettings,
|
|
@@ -17,28 +17,30 @@ const trimSpaceAfter = new Set([
|
|
|
17
17
|
EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
18
18
|
]);
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Replace token in its parent node
|
|
21
21
|
* @param parent
|
|
22
|
-
* @param
|
|
22
|
+
* @param node
|
|
23
23
|
* @param replacement
|
|
24
|
+
* @throws TypeError replacement is null
|
|
25
|
+
* @throws ReferenceError node not found in parent
|
|
24
26
|
*/
|
|
25
|
-
function
|
|
27
|
+
function replaceNodeOrValue(parent, node, replacement) {
|
|
26
28
|
if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
|
|
27
29
|
throw new TypeError(`replacement is null`);
|
|
28
30
|
}
|
|
29
31
|
for (const node of Array.isArray(replacement) ? replacement : [replacement]) {
|
|
30
|
-
if ("parent" in
|
|
32
|
+
if ("parent" in node && node.parent != node.parent) {
|
|
31
33
|
Object.defineProperty(node, "parent", {
|
|
32
34
|
...definedPropertySettings,
|
|
33
|
-
value:
|
|
35
|
+
value: node.parent,
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
if (parent.typ == EnumToken.BinaryExpressionTokenType) {
|
|
38
|
-
if (parent.l ==
|
|
40
|
+
if (parent.l == node) {
|
|
39
41
|
parent.l = replacement;
|
|
40
42
|
}
|
|
41
|
-
else if (parent.r ==
|
|
43
|
+
else if (parent.r == node) {
|
|
42
44
|
parent.r = replacement;
|
|
43
45
|
}
|
|
44
46
|
else {
|
|
@@ -51,16 +53,16 @@ function replaceToken(parent, value, replacement) {
|
|
|
51
53
|
: (parent.chi ?? parent);
|
|
52
54
|
if (Array.isArray(target)) {
|
|
53
55
|
// @ts-ignore
|
|
54
|
-
const index = target.indexOf(
|
|
56
|
+
const index = target.indexOf(node);
|
|
55
57
|
if (index == -1) {
|
|
56
58
|
throw new ReferenceError("Node not found");
|
|
57
59
|
}
|
|
58
60
|
target.splice(index, 1, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
59
61
|
}
|
|
60
|
-
else if ("l" in target && target.l ==
|
|
62
|
+
else if ("l" in target && target.l == node) {
|
|
61
63
|
target.l = replacement;
|
|
62
64
|
}
|
|
63
|
-
else if ("r" in target && target.r ==
|
|
65
|
+
else if ("r" in target && target.r == node) {
|
|
64
66
|
target.r = replacement;
|
|
65
67
|
}
|
|
66
68
|
else {
|
|
@@ -99,4 +101,4 @@ function trimWhiteSpaceTokens(tokens) {
|
|
|
99
101
|
return tokens;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
export {
|
|
104
|
+
export { replaceNodeOrValue, trimWhiteSpaceTokens };
|