@tbela99/css-parser 1.4.6 → 1.4.7
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 +17 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6548 -6964
- package/dist/index.cjs +7784 -8198
- package/dist/index.d.ts +919 -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 +6 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +46 -44
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/parse.js +331 -504
- 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 +286 -286
- 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 +150 -120
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color.js +5 -5
- 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/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +22 -3
- package/dist/lib/syntax/syntax.js +252 -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 +16 -12
- package/dist/web.js +10 -8
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { getParsedSyntax, getSyntaxConfig } from './config.js';
|
|
2
|
-
import { EnumToken
|
|
2
|
+
import { EnumToken } from '../ast/types.js';
|
|
3
3
|
import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js';
|
|
4
|
-
import { tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
|
|
5
|
-
import {
|
|
6
|
-
import { isDeclarationValue } from '../parser/utils/declaration.js';
|
|
7
|
-
import { renderSyntax } from './parser/parse.js';
|
|
4
|
+
import { LOC, tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
|
|
5
|
+
import { isColor } from '../syntax/syntax.js';
|
|
8
6
|
import { equalsIgnoreCase } from '../parser/utils/text.js';
|
|
9
7
|
import { cloneNode } from '../ast/clone.js';
|
|
10
8
|
import { parseTokens } from '../parser/parse.js';
|
|
@@ -26,9 +24,6 @@ function trimArray(tokens) {
|
|
|
26
24
|
}
|
|
27
25
|
return tokens;
|
|
28
26
|
}
|
|
29
|
-
function isMFName(featureName) {
|
|
30
|
-
return featureName.startsWith("--") || featureName.toLowerCase() in config.mediaFeatures;
|
|
31
|
-
}
|
|
32
27
|
/**
|
|
33
28
|
*
|
|
34
29
|
* @param featureName
|
|
@@ -36,7 +31,7 @@ function isMFName(featureName) {
|
|
|
36
31
|
*/
|
|
37
32
|
function getMFInfo(featureName) {
|
|
38
33
|
// @ts-expect-error
|
|
39
|
-
return config.mediaFeatures[featureName.toLowerCase()]
|
|
34
|
+
return config.mediaFeatures[featureName.toLowerCase()];
|
|
40
35
|
}
|
|
41
36
|
/**
|
|
42
37
|
*
|
|
@@ -49,9 +44,9 @@ function getMFInfo(featureName) {
|
|
|
49
44
|
function isMFValue(featureName, tokens, isMFRange) {
|
|
50
45
|
// mf-value: <number> | <dimension> | <ident> | <ratio>
|
|
51
46
|
tokens = tokens.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
52
|
-
if (tokens.length === 0) {
|
|
53
|
-
|
|
54
|
-
}
|
|
47
|
+
// if (tokens.length === 0) {
|
|
48
|
+
// return { valid: true, success: false };
|
|
49
|
+
// }
|
|
55
50
|
// https://www.w3.org/TR/mediaqueries-5/#:~:text=Attempting%20to%20evaluate%20a%20min%2Fmax%20prefixed
|
|
56
51
|
// https://www.w3.org/TR/mediaqueries-5/#custom-mq
|
|
57
52
|
if (featureName.startsWith("--") || (isMFRange && /^((min)|(max))-/g.test(featureName))) {
|
|
@@ -63,16 +58,19 @@ function isMFValue(featureName, tokens, isMFRange) {
|
|
|
63
58
|
}
|
|
64
59
|
// @ts-expect-error
|
|
65
60
|
const mediaFeature = config.mediaFeatures[featureName];
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
// if (
|
|
62
|
+
// tokens.length === 1 &&
|
|
63
|
+
// tokens[0].typ === EnumToken.MathFunctionTokenType &&
|
|
64
|
+
// (tokens[0] as FunctionToken).val === "calc"
|
|
65
|
+
// ) {
|
|
66
|
+
// // todo: check calc tokens are of compatible types : resolution, ratio, length, integer, number?
|
|
67
|
+
// // https://github.com/web-platform-tests/wpt/blob/master/css/mediaqueries/mq-calc-sign-function-003.html
|
|
68
|
+
// return {
|
|
69
|
+
// valid: true,
|
|
70
|
+
// success:
|
|
71
|
+
// mediaFeature.type !== MediaFeatureType.KeywordType && mediaFeature.type !== MediaFeatureType.StringType,
|
|
72
|
+
// };
|
|
73
|
+
// }
|
|
76
74
|
switch (mediaFeature.type) {
|
|
77
75
|
case MediaFeatureType.BooleanType:
|
|
78
76
|
return {
|
|
@@ -130,14 +128,16 @@ function isMFValue(featureName, tokens, isMFRange) {
|
|
|
130
128
|
success: true,
|
|
131
129
|
};
|
|
132
130
|
}
|
|
133
|
-
function isStyleRangeValue(tokens) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
131
|
+
// export function isStyleRangeValue(tokens: Token[]): { success: boolean; errors: ErrorDescription[] } {
|
|
132
|
+
// const filtered: Token[] = tokens.filter(
|
|
133
|
+
// (token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType,
|
|
134
|
+
// );
|
|
135
|
+
// const result = isDeclarationValue(tokens);
|
|
136
|
+
// if (result.success) {
|
|
137
|
+
// result.success = filtered.length > 0;
|
|
138
|
+
// }
|
|
139
|
+
// return result;
|
|
140
|
+
// }
|
|
141
141
|
function createValidationContext(tokens) {
|
|
142
142
|
tokens = trimArray(tokens.filter((t) => t.typ !== EnumToken.CommentTokenType));
|
|
143
143
|
if (tokens.at(-1)?.typ === EnumToken.ImportantTokenType) {
|
|
@@ -151,29 +151,31 @@ function createValidationContext(tokens) {
|
|
|
151
151
|
if (this.index < 0) {
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
|
-
while (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
// while (
|
|
155
|
+
// this.tokens[this.index]?.typ == EnumToken.WhitespaceTokenType ||
|
|
156
|
+
// this.tokens[this.index]?.typ == EnumToken.CommentTokenType ||
|
|
157
|
+
// this.tokens[this.index]?.typ == EnumToken.CDOCOMMTokenType
|
|
158
|
+
// ) {
|
|
159
|
+
// this.index++;
|
|
160
|
+
// }
|
|
159
161
|
return this.tokens[this.index];
|
|
160
162
|
},
|
|
161
|
-
peek(offset = 0
|
|
163
|
+
peek(offset = 0) {
|
|
162
164
|
let index = this.index;
|
|
163
165
|
let token = this.tokens[++index];
|
|
164
|
-
if (!skipWhitespace) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
166
|
+
// if (!skipWhitespace) {
|
|
167
|
+
// while (offset >= 0 && index < this.tokens.length) {
|
|
168
|
+
// while (token != null && token.typ === EnumToken.CommentTokenType) {
|
|
169
|
+
// token = this.tokens[++index];
|
|
170
|
+
// }
|
|
171
|
+
// if (offset === 0 || token == null) {
|
|
172
|
+
// return token;
|
|
173
|
+
// }
|
|
174
|
+
// offset--;
|
|
175
|
+
// token = this.tokens[++index];
|
|
176
|
+
// }
|
|
177
|
+
// return token;
|
|
178
|
+
// }
|
|
177
179
|
while (offset >= 0 && index < this.tokens.length) {
|
|
178
180
|
while (token?.typ == EnumToken.WhitespaceTokenType ||
|
|
179
181
|
token?.typ == EnumToken.CommentTokenType ||
|
|
@@ -218,17 +220,17 @@ function createValidationContext(tokens) {
|
|
|
218
220
|
if (close !== EnumToken.EndParensTokenType && token?.typ === close) {
|
|
219
221
|
counter--;
|
|
220
222
|
}
|
|
221
|
-
else if (open !== EnumToken.StartParensTokenType && token?.typ === open) {
|
|
222
|
-
|
|
223
|
-
}
|
|
223
|
+
// else if (open !== EnumToken.StartParensTokenType && token?.typ === open) {
|
|
224
|
+
// counter++;
|
|
225
|
+
// }
|
|
224
226
|
}
|
|
225
227
|
if (matchCount <= 0 && counter <= 0) {
|
|
226
228
|
break;
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
|
-
if (tokens[0]?.typ === EnumToken.WhitespaceTokenType) {
|
|
230
|
-
|
|
231
|
-
}
|
|
231
|
+
// if (tokens[0]?.typ === EnumToken.WhitespaceTokenType) {
|
|
232
|
+
// tokens.shift();
|
|
233
|
+
// }
|
|
232
234
|
return tokens;
|
|
233
235
|
},
|
|
234
236
|
// 2
|
|
@@ -259,22 +261,24 @@ function createValidationContext(tokens) {
|
|
|
259
261
|
getRemainingTokens() {
|
|
260
262
|
return this.tokens.slice(this.index + 1);
|
|
261
263
|
},
|
|
262
|
-
last() {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
264
|
+
// last() {
|
|
265
|
+
// let index: number = this.tokens.length - 1;
|
|
266
|
+
// let token: Token = this.tokens[index];
|
|
267
|
+
// while (
|
|
268
|
+
// (this.index >= 0 && token?.typ === EnumToken.WhitespaceTokenType) ||
|
|
269
|
+
// token?.typ === EnumToken.CommentTokenType ||
|
|
270
|
+
// token?.typ === EnumToken.CDOCOMMTokenType ||
|
|
271
|
+
// token?.typ === EnumToken.InvalidCommentTokenType ||
|
|
272
|
+
// token?.typ === EnumToken.BadCommentTokenType ||
|
|
273
|
+
// token?.typ === EnumToken.BadStringTokenType
|
|
274
|
+
// ) {
|
|
275
|
+
// token = this.tokens[--index];
|
|
276
|
+
// if (token == null) {
|
|
277
|
+
// break;
|
|
278
|
+
// }
|
|
279
|
+
// }
|
|
280
|
+
// return token;
|
|
281
|
+
// },
|
|
278
282
|
end() {
|
|
279
283
|
this.index = this.tokens.length + 1;
|
|
280
284
|
return this;
|
|
@@ -361,9 +365,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
361
365
|
errors: [
|
|
362
366
|
{
|
|
363
367
|
action: "drop",
|
|
364
|
-
message: `Unexpected token ${EnumToken[stream[i].typ]} at ${stream[i].
|
|
368
|
+
message: `Unexpected token ${EnumToken[stream[i].typ]} at ${stream[i][LOC].src}:${stream[i][LOC].sta.lin}:${stream[i][LOC].sta.col}`,
|
|
365
369
|
node: stream[i],
|
|
366
|
-
location: stream[i]
|
|
370
|
+
location: stream[i][LOC],
|
|
367
371
|
},
|
|
368
372
|
],
|
|
369
373
|
};
|
|
@@ -372,9 +376,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
372
376
|
}
|
|
373
377
|
for (; i < stream.length; i++) {
|
|
374
378
|
token = stream[i];
|
|
375
|
-
if (token.typ === EnumToken.EOF) {
|
|
376
|
-
|
|
377
|
-
}
|
|
379
|
+
// if (token.typ === EnumToken.EOF) {
|
|
380
|
+
// break;
|
|
381
|
+
// }
|
|
378
382
|
if (token.typ === EnumToken.Star) {
|
|
379
383
|
token.typ = EnumToken.UniversalSelectorTokenType;
|
|
380
384
|
}
|
|
@@ -394,24 +398,26 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
394
398
|
token.typ !== EnumToken.CDOCOMMTokenType) {
|
|
395
399
|
stack.pop();
|
|
396
400
|
}
|
|
397
|
-
if (token.typ === EnumToken.LiteralTokenType && "+" === token.val) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
+
// if (token.typ === EnumToken.LiteralTokenType && "+" === (token as LiteralToken).val) {
|
|
402
|
+
// Object.assign(token, { typ: EnumToken.NextSiblingCombinatorTokenType });
|
|
403
|
+
// continue;
|
|
404
|
+
// }
|
|
401
405
|
switch (token.typ) {
|
|
402
|
-
case EnumToken.InvalidCommentTokenType:
|
|
403
|
-
case EnumToken.BadCommentTokenType:
|
|
404
|
-
case EnumToken.BadStringTokenType:
|
|
405
|
-
|
|
406
|
-
case EnumToken.PseudoClassFuncTokenType:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
success
|
|
410
|
-
|
|
411
|
-
|
|
406
|
+
// case EnumToken.InvalidCommentTokenType:
|
|
407
|
+
// case EnumToken.BadCommentTokenType:
|
|
408
|
+
// case EnumToken.BadStringTokenType:
|
|
409
|
+
// break;
|
|
410
|
+
case EnumToken.PseudoClassFuncTokenType:
|
|
411
|
+
{
|
|
412
|
+
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(token.chi), options);
|
|
413
|
+
if (!result.success) {
|
|
414
|
+
success = false;
|
|
415
|
+
if (result.errors.length > 0) {
|
|
416
|
+
errors.push(...result.errors);
|
|
417
|
+
}
|
|
412
418
|
}
|
|
413
419
|
}
|
|
414
|
-
|
|
420
|
+
break;
|
|
415
421
|
case EnumToken.WhitespaceTokenType:
|
|
416
422
|
case EnumToken.CommentTokenType:
|
|
417
423
|
case EnumToken.CDOCOMMTokenType:
|
|
@@ -423,9 +429,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
423
429
|
errors: [
|
|
424
430
|
{
|
|
425
431
|
action: "drop",
|
|
426
|
-
message: `Nesting selector is not allowed at ${token.
|
|
432
|
+
message: `Nesting selector is not allowed at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
427
433
|
node: token,
|
|
428
|
-
location: token
|
|
434
|
+
location: token[LOC],
|
|
429
435
|
},
|
|
430
436
|
],
|
|
431
437
|
};
|
|
@@ -433,19 +439,21 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
433
439
|
break;
|
|
434
440
|
case EnumToken.Plus:
|
|
435
441
|
Object.assign(token, { typ: EnumToken.NextSiblingCombinatorTokenType });
|
|
436
|
-
if (stack.length > 0 && nodes.includes(stack.at(-1)?.typ)) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
442
|
+
// if (stack.length > 0 && nodes.includes(stack.at(-1)?.typ)) {
|
|
443
|
+
// return {
|
|
444
|
+
// success: false,
|
|
445
|
+
// errors: [
|
|
446
|
+
// {
|
|
447
|
+
// action: "drop",
|
|
448
|
+
// message: `Unexpected combinator ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
449
|
+
// token[LOC]!.sta.col
|
|
450
|
+
// }`,
|
|
451
|
+
// node: token,
|
|
452
|
+
// location: token[LOC],
|
|
453
|
+
// },
|
|
454
|
+
// ],
|
|
455
|
+
// };
|
|
456
|
+
// }
|
|
449
457
|
stack.push(token);
|
|
450
458
|
break;
|
|
451
459
|
case EnumToken.Tilda:
|
|
@@ -457,9 +465,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
457
465
|
case EnumToken.DescendantCombinatorTokenType:
|
|
458
466
|
case EnumToken.NextSiblingCombinatorTokenType:
|
|
459
467
|
case EnumToken.SubsequentSiblingCombinatorTokenType:
|
|
460
|
-
if (tokens.at(-1)?.typ === EnumToken.WhitespaceTokenType) {
|
|
461
|
-
|
|
462
|
-
}
|
|
468
|
+
// if (tokens.at(-1)?.typ === EnumToken.WhitespaceTokenType) {
|
|
469
|
+
// tokens.pop();
|
|
470
|
+
// }
|
|
463
471
|
if (stream[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
|
|
464
472
|
i++;
|
|
465
473
|
}
|
|
@@ -472,9 +480,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
472
480
|
errors: [
|
|
473
481
|
{
|
|
474
482
|
action: "drop",
|
|
475
|
-
message: `Unexpected combinator ${EnumToken[token.typ]} at ${token.
|
|
483
|
+
message: `Unexpected combinator ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
476
484
|
node: token,
|
|
477
|
-
location: token
|
|
485
|
+
location: token[LOC],
|
|
478
486
|
},
|
|
479
487
|
],
|
|
480
488
|
};
|
|
@@ -485,51 +493,22 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
485
493
|
if (stack.length > 0 && stack.at(-1).typ === EnumToken.UniversalSelectorTokenType) {
|
|
486
494
|
stack.pop();
|
|
487
495
|
}
|
|
488
|
-
if (tokens.length === 0 || stack.at(-1)?.typ == EnumToken.CommaTokenType) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
496
|
+
// if (tokens.length === 0 || stack.at(-1)?.typ == EnumToken.CommaTokenType) {
|
|
497
|
+
// return {
|
|
498
|
+
// success: false,
|
|
499
|
+
// errors: [
|
|
500
|
+
// {
|
|
501
|
+
// action: "drop",
|
|
502
|
+
// message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
503
|
+
// token[LOC]!.sta.col
|
|
504
|
+
// }`,
|
|
505
|
+
// node: token,
|
|
506
|
+
// location: token[LOC],
|
|
507
|
+
// },
|
|
508
|
+
// ],
|
|
509
|
+
// };
|
|
510
|
+
// }
|
|
501
511
|
stack.push(token);
|
|
502
|
-
if (!nested) {
|
|
503
|
-
let k = i + 1;
|
|
504
|
-
while (k < stream.length &&
|
|
505
|
-
(stream[k].typ === EnumToken.WhitespaceTokenType ||
|
|
506
|
-
stream[k].typ === EnumToken.CommentTokenType)) {
|
|
507
|
-
k++;
|
|
508
|
-
}
|
|
509
|
-
// :has(> a, ~b, +c)
|
|
510
|
-
if (!tokensfuncDefMap.has(stack.at(-2)?.typ) && k < stream.length) {
|
|
511
|
-
switch (stream[k].typ) {
|
|
512
|
-
case EnumToken.Plus:
|
|
513
|
-
case EnumToken.Tilda:
|
|
514
|
-
case EnumToken.GtTokenType:
|
|
515
|
-
case EnumToken.ColumnCombinatorTokenType:
|
|
516
|
-
case EnumToken.ChildCombinatorTokenType:
|
|
517
|
-
case EnumToken.NextSiblingCombinatorTokenType:
|
|
518
|
-
case EnumToken.SubsequentSiblingCombinatorTokenType:
|
|
519
|
-
return {
|
|
520
|
-
success: false,
|
|
521
|
-
errors: [
|
|
522
|
-
{
|
|
523
|
-
action: "drop",
|
|
524
|
-
message: `Unexpected token ${EnumToken[stream[k].typ]} at ${stream[k].loc.src}:${stream[k].loc.sta.lin}:${stream[k].loc.sta.col}`,
|
|
525
|
-
node: stream[k],
|
|
526
|
-
location: stream[k].loc,
|
|
527
|
-
},
|
|
528
|
-
],
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
512
|
break;
|
|
534
513
|
case EnumToken.Pipe:
|
|
535
514
|
case EnumToken.DelimTokenType:
|
|
@@ -539,21 +518,27 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
539
518
|
case EnumToken.StartMatchTokenType:
|
|
540
519
|
case EnumToken.EndMatchTokenType:
|
|
541
520
|
case EnumToken.DashMatchTokenType:
|
|
542
|
-
if (
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
521
|
+
// if (
|
|
522
|
+
// stack.at(-1)?.typ !== EnumToken.AttrStartTokenType &&
|
|
523
|
+
// !(
|
|
524
|
+
// stack.at(-1)?.typ === EnumToken.UniversalSelectorTokenType &&
|
|
525
|
+
// stack.at(-2)?.typ === EnumToken.AttrStartTokenType
|
|
526
|
+
// )
|
|
527
|
+
// ) {
|
|
528
|
+
// return {
|
|
529
|
+
// success: false,
|
|
530
|
+
// errors: [
|
|
531
|
+
// {
|
|
532
|
+
// action: "drop",
|
|
533
|
+
// message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
534
|
+
// token[LOC]!.sta.col
|
|
535
|
+
// }`,
|
|
536
|
+
// node: token,
|
|
537
|
+
// location: token[LOC],
|
|
538
|
+
// },
|
|
539
|
+
// ],
|
|
540
|
+
// };
|
|
541
|
+
// }
|
|
557
542
|
break;
|
|
558
543
|
// case EnumToken.Star:
|
|
559
544
|
// Object.assign(token, { typ: EnumToken.UniversalSelectorTokenType });
|
|
@@ -563,14 +548,14 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
563
548
|
case EnumToken.PseudoElementTokenType:
|
|
564
549
|
case EnumToken.PseudoClassTokenType:
|
|
565
550
|
case EnumToken.ClassSelectorTokenType:
|
|
566
|
-
if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
567
|
-
|
|
568
|
-
}
|
|
551
|
+
// if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
552
|
+
// stack.pop();
|
|
553
|
+
// }
|
|
569
554
|
break;
|
|
570
555
|
case EnumToken.AttrStartTokenType:
|
|
571
|
-
if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
572
|
-
|
|
573
|
-
}
|
|
556
|
+
// if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
557
|
+
// stack.pop();
|
|
558
|
+
// }
|
|
574
559
|
stack.push(token);
|
|
575
560
|
break;
|
|
576
561
|
case EnumToken.AttrEndTokenType:
|
|
@@ -583,9 +568,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
583
568
|
errors: [
|
|
584
569
|
{
|
|
585
570
|
action: "drop",
|
|
586
|
-
message: `Unexpected token ${EnumToken[token.typ]} at ${token.
|
|
571
|
+
message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
587
572
|
node: token,
|
|
588
|
-
location: token
|
|
573
|
+
location: token[LOC],
|
|
589
574
|
},
|
|
590
575
|
],
|
|
591
576
|
};
|
|
@@ -602,130 +587,150 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
602
587
|
}
|
|
603
588
|
slice.push(tokens[n]);
|
|
604
589
|
}
|
|
605
|
-
if (slice.length === 0) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
590
|
+
// if (slice.length === 0) {
|
|
591
|
+
// return {
|
|
592
|
+
// success: false,
|
|
593
|
+
// errors: [
|
|
594
|
+
// {
|
|
595
|
+
// action: "drop",
|
|
596
|
+
// message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
597
|
+
// token[LOC]!.sta.col
|
|
598
|
+
// }`,
|
|
599
|
+
// node: token,
|
|
600
|
+
// location: token[LOC],
|
|
601
|
+
// },
|
|
602
|
+
// ],
|
|
603
|
+
// };
|
|
604
|
+
// }
|
|
618
605
|
if (slice[1]?.typ === EnumToken.Pipe) {
|
|
619
|
-
if (
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
606
|
+
// if (
|
|
607
|
+
// slice[0].typ !== EnumToken.UniversalSelectorTokenType &&
|
|
608
|
+
// slice[0].typ !== EnumToken.Star &&
|
|
609
|
+
// slice[0].typ !== EnumToken.IdenTokenType
|
|
610
|
+
// ) {
|
|
611
|
+
// return {
|
|
612
|
+
// success: false,
|
|
613
|
+
// errors: [
|
|
614
|
+
// {
|
|
615
|
+
// action: "drop",
|
|
616
|
+
// message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
617
|
+
// token[LOC]!.sta.col
|
|
618
|
+
// }`,
|
|
619
|
+
// node: token,
|
|
620
|
+
// location: token[LOC],
|
|
621
|
+
// },
|
|
622
|
+
// ],
|
|
623
|
+
// };
|
|
624
|
+
// }
|
|
634
625
|
slice.shift();
|
|
635
626
|
}
|
|
636
627
|
if (slice[0].typ === EnumToken.Pipe) {
|
|
637
|
-
if (slice.length === 1) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
628
|
+
// if (slice.length === 1) {
|
|
629
|
+
// return {
|
|
630
|
+
// success: false,
|
|
631
|
+
// errors: [
|
|
632
|
+
// {
|
|
633
|
+
// action: "drop",
|
|
634
|
+
// message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
635
|
+
// token[LOC]!.sta.col
|
|
636
|
+
// }`,
|
|
637
|
+
// node: token,
|
|
638
|
+
// location: token[LOC],
|
|
639
|
+
// },
|
|
640
|
+
// ],
|
|
641
|
+
// };
|
|
642
|
+
// }
|
|
643
|
+
// if (slice[1]?.typ !== EnumToken.IdenTokenType) {
|
|
644
|
+
// return {
|
|
645
|
+
// success: false,
|
|
646
|
+
// errors: [
|
|
647
|
+
// {
|
|
648
|
+
// action: "drop",
|
|
649
|
+
// message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
650
|
+
// token[LOC]!.sta.col
|
|
651
|
+
// }`,
|
|
652
|
+
// node: token,
|
|
653
|
+
// location: token[LOC],
|
|
654
|
+
// },
|
|
655
|
+
// ],
|
|
656
|
+
// };
|
|
657
|
+
// }
|
|
663
658
|
slice.shift();
|
|
664
659
|
}
|
|
665
660
|
if (slice.length === 1) {
|
|
666
|
-
if (slice[0].typ !== EnumToken.IdenTokenType) {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
661
|
+
// if (slice[0].typ !== EnumToken.IdenTokenType) {
|
|
662
|
+
// return {
|
|
663
|
+
// success: false,
|
|
664
|
+
// errors: [
|
|
665
|
+
// {
|
|
666
|
+
// action: "drop",
|
|
667
|
+
// message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
668
|
+
// token[LOC]!.sta.col
|
|
669
|
+
// }`,
|
|
670
|
+
// node: token,
|
|
671
|
+
// location: token[LOC],
|
|
672
|
+
// },
|
|
673
|
+
// ],
|
|
674
|
+
// };
|
|
675
|
+
// }
|
|
679
676
|
stack.pop();
|
|
680
677
|
break;
|
|
681
678
|
}
|
|
682
679
|
slice.shift();
|
|
683
|
-
if (
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
680
|
+
// if (
|
|
681
|
+
// slice[0].typ != EnumToken.DelimTokenType &&
|
|
682
|
+
// slice[0].typ !== EnumToken.DashMatchTokenType &&
|
|
683
|
+
// slice[0].typ !== EnumToken.EndMatchTokenType &&
|
|
684
|
+
// slice[0].typ !== EnumToken.IncludeMatchTokenType &&
|
|
685
|
+
// slice[0].typ !== EnumToken.StartMatchTokenType &&
|
|
686
|
+
// slice[0].typ !== EnumToken.ContainMatchTokenType
|
|
687
|
+
// ) {
|
|
688
|
+
// return {
|
|
689
|
+
// success: false,
|
|
690
|
+
// errors: [
|
|
691
|
+
// {
|
|
692
|
+
// action: "drop",
|
|
693
|
+
// message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
|
|
694
|
+
// slice[0][LOC]!.sta.col
|
|
695
|
+
// }`,
|
|
696
|
+
// node: slice[0],
|
|
697
|
+
// location: slice[0][LOC],
|
|
698
|
+
// },
|
|
699
|
+
// ],
|
|
700
|
+
// };
|
|
701
|
+
// }
|
|
701
702
|
slice.shift();
|
|
702
|
-
if (slice.length === 0) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
703
|
+
// if (slice.length === 0) {
|
|
704
|
+
// // expect iden or string
|
|
705
|
+
// return {
|
|
706
|
+
// success: false,
|
|
707
|
+
// errors: [
|
|
708
|
+
// {
|
|
709
|
+
// action: "drop",
|
|
710
|
+
// message: `Invalid selector attribute at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
|
|
711
|
+
// slice[0][LOC]!.sta.col
|
|
712
|
+
// }`,
|
|
713
|
+
// node: slice[0],
|
|
714
|
+
// location: slice[0][LOC],
|
|
715
|
+
// },
|
|
716
|
+
// ],
|
|
717
|
+
// };
|
|
718
|
+
// }
|
|
719
|
+
// if (slice[0].typ !== EnumToken.IdenTokenType && slice[0].typ !== EnumToken.StringTokenType) {
|
|
720
|
+
// return {
|
|
721
|
+
// success: false,
|
|
722
|
+
// errors: [
|
|
723
|
+
// {
|
|
724
|
+
// action: "drop",
|
|
725
|
+
// message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
|
|
726
|
+
// slice[0][LOC]!.sta.col
|
|
727
|
+
// }`,
|
|
728
|
+
// node: slice[0],
|
|
729
|
+
// location: slice[0][LOC],
|
|
730
|
+
// },
|
|
731
|
+
// ],
|
|
732
|
+
// };
|
|
733
|
+
// }
|
|
729
734
|
if (slice[0]?.typ === EnumToken.StringTokenType &&
|
|
730
735
|
/^[a-zA-Z0-9_-]+$/.test(slice[0].val.slice(1, -1))) {
|
|
731
736
|
Object.assign(slice[0], {
|
|
@@ -745,112 +750,122 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
745
750
|
errors: [
|
|
746
751
|
{
|
|
747
752
|
action: "drop",
|
|
748
|
-
message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0].
|
|
753
|
+
message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC].src}:${slice[0][LOC].sta.lin}:${slice[0][LOC].sta.col}`,
|
|
749
754
|
node: slice[0],
|
|
750
|
-
location: slice[0]
|
|
755
|
+
location: slice[0][LOC],
|
|
751
756
|
},
|
|
752
757
|
],
|
|
753
758
|
};
|
|
754
759
|
}
|
|
755
760
|
slice.shift();
|
|
756
|
-
if (slice.length > 0) {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
761
|
+
// if (slice.length > 0) {
|
|
762
|
+
// return {
|
|
763
|
+
// success: false,
|
|
764
|
+
// errors: [
|
|
765
|
+
// {
|
|
766
|
+
// action: "drop",
|
|
767
|
+
// message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
|
|
768
|
+
// slice[0][LOC]!.sta.col
|
|
769
|
+
// }`,
|
|
770
|
+
// node: slice[0],
|
|
771
|
+
// location: slice[0][LOC],
|
|
772
|
+
// },
|
|
773
|
+
// ],
|
|
774
|
+
// };
|
|
775
|
+
// }
|
|
769
776
|
stack.pop();
|
|
770
777
|
break;
|
|
771
778
|
}
|
|
772
|
-
case EnumToken.ColonTokenType:
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
779
|
+
// case EnumToken.ColonTokenType:
|
|
780
|
+
// if (stream[i + 1]?.typ === EnumToken.IdenTokenType) {
|
|
781
|
+
// Object.assign(token, {
|
|
782
|
+
// typ:
|
|
783
|
+
// (stream[i + 1] as IdentToken).val === "page"
|
|
784
|
+
// ? EnumToken.PseudoPageTokenType
|
|
785
|
+
// : pseudoElements.includes((token as PseudoElementToken).val)
|
|
786
|
+
// ? EnumToken.PseudoElementTokenType
|
|
787
|
+
// : EnumToken.PseudoClassTokenType,
|
|
788
|
+
// val: ":" + (stream[i + 1] as IdentToken).val,
|
|
789
|
+
// });
|
|
790
|
+
// token[LOC]!.end = stream[++i][LOC]!.end;
|
|
791
|
+
// break;
|
|
792
|
+
// } else if (stream[i + 1]?.typ === EnumToken.FunctionTokenDefType) {
|
|
793
|
+
// Object.assign(token, {
|
|
794
|
+
// typ: EnumToken.PseudoClassFunctionTokenDefType,
|
|
795
|
+
// val: ":" + (stream[i + 1] as IdentToken).val,
|
|
796
|
+
// });
|
|
797
|
+
// token[LOC]!.end = stream[++i][LOC]!.end;
|
|
798
|
+
// stack.push(token);
|
|
799
|
+
// break;
|
|
800
|
+
// }
|
|
801
|
+
// return {
|
|
802
|
+
// success: false,
|
|
803
|
+
// errors: [
|
|
804
|
+
// {
|
|
805
|
+
// action: "drop",
|
|
806
|
+
// message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
807
|
+
// token[LOC]!.sta.col
|
|
808
|
+
// }`,
|
|
809
|
+
// node: token,
|
|
810
|
+
// location: token[LOC],
|
|
811
|
+
// },
|
|
812
|
+
// ],
|
|
813
|
+
// };
|
|
814
|
+
// case EnumToken.DoubleColonTokenType:
|
|
815
|
+
// if (stream[i + 1]?.typ === EnumToken.IdenTokenType) {
|
|
816
|
+
// Object.assign(token, {
|
|
817
|
+
// typ:
|
|
818
|
+
// (stream[i + 1] as IdentToken).val === "page"
|
|
819
|
+
// ? EnumToken.PseudoPageTokenType
|
|
820
|
+
// : EnumToken.PseudoElementTokenType,
|
|
821
|
+
// val: "::" + (stream[i + 1] as IdentToken).val,
|
|
822
|
+
// });
|
|
823
|
+
// token[LOC]!.end = stream[++i][LOC]!.end;
|
|
824
|
+
// break;
|
|
825
|
+
// } else if (stream[i + 1]?.typ === EnumToken.FunctionTokenDefType) {
|
|
826
|
+
// Object.assign(token, {
|
|
827
|
+
// typ: EnumToken.PseudoClassFunctionTokenDefType,
|
|
828
|
+
// val: "::" + (stream[i + 1] as IdentToken).val,
|
|
829
|
+
// });
|
|
830
|
+
// token[LOC]!.end = stream[++i][LOC]!.end;
|
|
831
|
+
// stack.push(token);
|
|
832
|
+
// break;
|
|
833
|
+
// }
|
|
834
|
+
// return {
|
|
835
|
+
// success: false,
|
|
836
|
+
// errors: [
|
|
837
|
+
// {
|
|
838
|
+
// action: "drop",
|
|
839
|
+
// message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
|
|
840
|
+
// token[LOC]!.sta.col
|
|
841
|
+
// }`,
|
|
842
|
+
// node: token,
|
|
843
|
+
// location: token[LOC],
|
|
844
|
+
// },
|
|
845
|
+
// ],
|
|
846
|
+
// };
|
|
836
847
|
case EnumToken.StartParensTokenType:
|
|
837
|
-
if (
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}
|
|
848
|
+
// if (
|
|
849
|
+
// tokens.at(-2)?.typ === EnumToken.PseudoClassTokenType ||
|
|
850
|
+
// tokens.at(-2)?.typ === EnumToken.PseudoElementTokenType
|
|
851
|
+
// ) {
|
|
852
|
+
// stack.push(
|
|
853
|
+
// Object.assign(tokens.at(-2) as Token, {
|
|
854
|
+
// typ: EnumToken.PseudoClassFunctionTokenDefType,
|
|
855
|
+
// chi: [],
|
|
856
|
+
// }),
|
|
857
|
+
// );
|
|
858
|
+
// // tokens.pop();
|
|
859
|
+
// break;
|
|
860
|
+
// }
|
|
846
861
|
return {
|
|
847
862
|
success: false,
|
|
848
863
|
errors: [
|
|
849
864
|
{
|
|
850
865
|
action: "drop",
|
|
851
|
-
message: `Unexpected token ${EnumToken[token.typ]} at ${token.
|
|
866
|
+
message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
852
867
|
node: token,
|
|
853
|
-
location: token
|
|
868
|
+
location: token[LOC],
|
|
854
869
|
},
|
|
855
870
|
],
|
|
856
871
|
};
|
|
@@ -861,19 +876,19 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
861
876
|
if (stack.at(-1)?.typ === EnumToken.PseudoClassFunctionTokenDefType ||
|
|
862
877
|
stack.at(-1)?.typ === EnumToken.PseudoElementTokenType) {
|
|
863
878
|
const token = stack.at(-1);
|
|
864
|
-
if (!(stack.at(-1).val + "()" in config.selectors)) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
}
|
|
879
|
+
// if (!((stack.at(-1) as PseudoClassFunctionToken).val + "()" in config.selectors)) {
|
|
880
|
+
// return {
|
|
881
|
+
// errors: [
|
|
882
|
+
// {
|
|
883
|
+
// action: "drop",
|
|
884
|
+
// message: `Unknown class element ${(token as PseudoElementToken).val}`,
|
|
885
|
+
// node: token,
|
|
886
|
+
// location: token[LOC]!,
|
|
887
|
+
// },
|
|
888
|
+
// ],
|
|
889
|
+
// success: false,
|
|
890
|
+
// };
|
|
891
|
+
// }
|
|
877
892
|
const index = tokens.indexOf(token);
|
|
878
893
|
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(tokens.slice(index + 1, tokens.length - 1)), options);
|
|
879
894
|
if (!result.success) {
|
|
@@ -890,18 +905,18 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
890
905
|
errors: [
|
|
891
906
|
{
|
|
892
907
|
action: "drop",
|
|
893
|
-
message: `Unexpected token ${EnumToken[token.typ]} at ${token.
|
|
908
|
+
message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
894
909
|
node: token,
|
|
895
|
-
location: token
|
|
910
|
+
location: token[LOC],
|
|
896
911
|
},
|
|
897
912
|
],
|
|
898
913
|
};
|
|
899
914
|
case EnumToken.NumberTokenType:
|
|
900
915
|
case EnumToken.LiteralTokenType:
|
|
901
916
|
case EnumToken.DimensionTokenType:
|
|
902
|
-
if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
903
|
-
|
|
904
|
-
}
|
|
917
|
+
// if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
918
|
+
// stack.pop();
|
|
919
|
+
// }
|
|
905
920
|
if (stack.at(-1)?.typ === EnumToken.PseudoClassFunctionTokenDefType) {
|
|
906
921
|
break;
|
|
907
922
|
}
|
|
@@ -911,9 +926,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
911
926
|
errors: [
|
|
912
927
|
{
|
|
913
928
|
action: "drop",
|
|
914
|
-
message: `Unsupported selector token ${EnumToken[token.typ]} at ${token.
|
|
929
|
+
message: `Unsupported selector token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
915
930
|
node: token,
|
|
916
|
-
location: token
|
|
931
|
+
location: token[LOC],
|
|
917
932
|
},
|
|
918
933
|
],
|
|
919
934
|
};
|
|
@@ -936,23 +951,23 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
936
951
|
errors: [
|
|
937
952
|
{
|
|
938
953
|
action: "drop",
|
|
939
|
-
message: `Unmatched token ${EnumToken[stack.at(-1).typ]} at ${stack.at(-1).
|
|
954
|
+
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}`,
|
|
940
955
|
node: stack.at(-1),
|
|
941
|
-
location: stack.at(-1)
|
|
956
|
+
location: stack.at(-1)[LOC],
|
|
942
957
|
},
|
|
943
958
|
],
|
|
944
959
|
};
|
|
945
960
|
}
|
|
946
961
|
stream.length = 0;
|
|
947
962
|
stream.push(...tokens);
|
|
948
|
-
if (!success && errors.length === 0) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
}
|
|
963
|
+
// if (!success && errors.length === 0) {
|
|
964
|
+
// errors.push({
|
|
965
|
+
// action: "drop",
|
|
966
|
+
// message: "Invalid selector",
|
|
967
|
+
// node: tokens[0],
|
|
968
|
+
// location: tokens[0][LOC]!,
|
|
969
|
+
// });
|
|
970
|
+
// }
|
|
956
971
|
return { success, errors };
|
|
957
972
|
}
|
|
958
973
|
function matchAllSyntaxes(syntaxes, context, options) {
|
|
@@ -960,25 +975,28 @@ function matchAllSyntaxes(syntaxes, context, options) {
|
|
|
960
975
|
...options,
|
|
961
976
|
visited: new Map(),
|
|
962
977
|
});
|
|
963
|
-
if (result.success && !result.context.done()) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
}
|
|
978
|
+
// if (result.success && !result.context.done()) {
|
|
979
|
+
// const node = result.context.peek() as Token;
|
|
980
|
+
// return {
|
|
981
|
+
// ...result,
|
|
982
|
+
// success: false,
|
|
983
|
+
// token: context.peek(),
|
|
984
|
+
// errors: [
|
|
985
|
+
// ...result.errors,
|
|
986
|
+
// {
|
|
987
|
+
// action: "drop",
|
|
988
|
+
// message: `Unexpected token ${EnumToken[node?.typ]} at ${node![LOC]?.src}:${node![LOC]?.sta?.lin}:${
|
|
989
|
+
// node![LOC]?.sta?.col
|
|
990
|
+
// }`,
|
|
991
|
+
// node,
|
|
992
|
+
// syntax:
|
|
993
|
+
// result.syntaxToken ??
|
|
994
|
+
// syntaxes?.reduce?.((acc, b) => acc + renderSyntax(b), "")?.trim?.() ??
|
|
995
|
+
// null,
|
|
996
|
+
// },
|
|
997
|
+
// ],
|
|
998
|
+
// };
|
|
999
|
+
// }
|
|
982
1000
|
if (syntaxes != null && result.success && result.syntaxToken != null) {
|
|
983
1001
|
const index = syntaxes.indexOf(result.syntaxToken);
|
|
984
1002
|
if (index != -1) {
|
|
@@ -988,9 +1006,9 @@ function matchAllSyntaxes(syntaxes, context, options) {
|
|
|
988
1006
|
syntaxes[i].isRepeatable) {
|
|
989
1007
|
continue;
|
|
990
1008
|
}
|
|
991
|
-
if (syntaxes[i].typ == ValidationTokenEnum.SemiColon && i === syntaxes.length - 1) {
|
|
992
|
-
|
|
993
|
-
}
|
|
1009
|
+
// if (syntaxes[i].typ == ValidationTokenEnum.SemiColon && i === syntaxes.length - 1) {
|
|
1010
|
+
// continue;
|
|
1011
|
+
// }
|
|
994
1012
|
return {
|
|
995
1013
|
...result,
|
|
996
1014
|
success: false,
|
|
@@ -1008,7 +1026,7 @@ function matchAllSyntaxes(syntaxes, context, options) {
|
|
|
1008
1026
|
message: result.errors[0]?.message || "could not match syntax",
|
|
1009
1027
|
node: result.token,
|
|
1010
1028
|
syntax: result.syntaxToken,
|
|
1011
|
-
location: result.token?.
|
|
1029
|
+
location: result.token?.[LOC] ?? context.tokens.at(-1)?.[LOC],
|
|
1012
1030
|
},
|
|
1013
1031
|
]
|
|
1014
1032
|
: result.errors,
|
|
@@ -1043,22 +1061,22 @@ function matchListSyntax(syntax, context, options) {
|
|
|
1043
1061
|
}
|
|
1044
1062
|
}
|
|
1045
1063
|
} while (tmpResult.success && !context.done());
|
|
1046
|
-
if (result?.success && match != null) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}
|
|
1064
|
+
// if (result?.success && match != null) {
|
|
1065
|
+
// if (count < match.min!.val || (Number.isFinite(match.max) && count > (match.max!.val as number))) {
|
|
1066
|
+
// return {
|
|
1067
|
+
// ...result,
|
|
1068
|
+
// success: false,
|
|
1069
|
+
// errors: [
|
|
1070
|
+
// {
|
|
1071
|
+
// action: "drop",
|
|
1072
|
+
// message: "could not match syntax",
|
|
1073
|
+
// node: context.peek(),
|
|
1074
|
+
// location: context.peek()?.[LOC]!,
|
|
1075
|
+
// },
|
|
1076
|
+
// ],
|
|
1077
|
+
// };
|
|
1078
|
+
// }
|
|
1079
|
+
// }
|
|
1062
1080
|
return result == null
|
|
1063
1081
|
? {
|
|
1064
1082
|
success: false,
|
|
@@ -1095,8 +1113,9 @@ function matchOccurenceSyntax(syntax, context, options) {
|
|
|
1095
1113
|
}
|
|
1096
1114
|
}
|
|
1097
1115
|
} while (tmpResult.success && !context.done());
|
|
1098
|
-
if (
|
|
1099
|
-
(
|
|
1116
|
+
if (result == null ||
|
|
1117
|
+
(match != null &&
|
|
1118
|
+
(count < match.min.val || (Number.isFinite(match.max?.val) && count > match.max.val)))) {
|
|
1100
1119
|
return {
|
|
1101
1120
|
success: false,
|
|
1102
1121
|
errors: [
|
|
@@ -1104,7 +1123,7 @@ function matchOccurenceSyntax(syntax, context, options) {
|
|
|
1104
1123
|
action: "drop",
|
|
1105
1124
|
message: "could not match syntax",
|
|
1106
1125
|
node: context.peek(),
|
|
1107
|
-
location: context.peek()?.
|
|
1126
|
+
location: context.peek()?.[LOC],
|
|
1108
1127
|
},
|
|
1109
1128
|
],
|
|
1110
1129
|
syntaxToken: null,
|
|
@@ -1113,21 +1132,7 @@ function matchOccurenceSyntax(syntax, context, options) {
|
|
|
1113
1132
|
token: null,
|
|
1114
1133
|
};
|
|
1115
1134
|
}
|
|
1116
|
-
return
|
|
1117
|
-
success: false,
|
|
1118
|
-
errors: [
|
|
1119
|
-
{
|
|
1120
|
-
action: "drop",
|
|
1121
|
-
message: "could not match syntax",
|
|
1122
|
-
node: context.peek(),
|
|
1123
|
-
location: context.peek().loc,
|
|
1124
|
-
},
|
|
1125
|
-
],
|
|
1126
|
-
syntaxToken: syntax,
|
|
1127
|
-
valid: true,
|
|
1128
|
-
context,
|
|
1129
|
-
token: context.peek(),
|
|
1130
|
-
});
|
|
1135
|
+
return result;
|
|
1131
1136
|
}
|
|
1132
1137
|
function matchSyntax(syntaxes, context, options) {
|
|
1133
1138
|
if (syntaxes == null) {
|
|
@@ -1191,24 +1196,24 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1191
1196
|
}
|
|
1192
1197
|
if (token.typ === EnumToken.WildCardFunctionTokenType && token.val === "var") {
|
|
1193
1198
|
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(token.chi), options);
|
|
1194
|
-
if (
|
|
1199
|
+
if (result.success && result.context.done()) {
|
|
1195
1200
|
context.next();
|
|
1196
1201
|
continue;
|
|
1197
1202
|
}
|
|
1198
|
-
return {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
};
|
|
1203
|
+
// return {
|
|
1204
|
+
// ...result,
|
|
1205
|
+
// success: false,
|
|
1206
|
+
// token,
|
|
1207
|
+
// syntaxToken: syntaxes[i],
|
|
1208
|
+
// errors: [
|
|
1209
|
+
// {
|
|
1210
|
+
// action: "drop",
|
|
1211
|
+
// message: "could not match syntax",
|
|
1212
|
+
// node: context.peek(),
|
|
1213
|
+
// location: context.peek()![LOC]!,
|
|
1214
|
+
// },
|
|
1215
|
+
// ],
|
|
1216
|
+
// };
|
|
1212
1217
|
}
|
|
1213
1218
|
// custom function token
|
|
1214
1219
|
if (token.typ === EnumToken.CustomFunctionTokenDefType) {
|
|
@@ -1259,10 +1264,10 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1259
1264
|
}
|
|
1260
1265
|
continue;
|
|
1261
1266
|
}
|
|
1262
|
-
if (isOptional) {
|
|
1263
|
-
|
|
1264
|
-
}
|
|
1265
|
-
return result;
|
|
1267
|
+
// if (isOptional) {
|
|
1268
|
+
// continue;
|
|
1269
|
+
// }
|
|
1270
|
+
// return result;
|
|
1266
1271
|
}
|
|
1267
1272
|
if (syntaxes[i].isRepeatableAtLeastOnce || syntaxes[i].isRepeatable) {
|
|
1268
1273
|
result = matchRepeatableSyntax(syntaxes[i], context.slice(), options);
|
|
@@ -1274,9 +1279,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1274
1279
|
context.update(result.context.current());
|
|
1275
1280
|
continue;
|
|
1276
1281
|
}
|
|
1277
|
-
if (isOptional) {
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1282
|
+
// if (isOptional) {
|
|
1283
|
+
// continue;
|
|
1284
|
+
// }
|
|
1280
1285
|
return result;
|
|
1281
1286
|
}
|
|
1282
1287
|
if (syntaxes[i].isList) {
|
|
@@ -1295,25 +1300,27 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1295
1300
|
};
|
|
1296
1301
|
}
|
|
1297
1302
|
context.update(result.context.current());
|
|
1298
|
-
let k = i + 1;
|
|
1299
|
-
for (; k < syntaxes.length; k++) {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
}
|
|
1307
|
-
continue;
|
|
1308
|
-
}
|
|
1309
|
-
if (isOptional) {
|
|
1310
|
-
// eat the next ','
|
|
1311
|
-
if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace ||
|
|
1312
|
-
syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma) {
|
|
1313
|
-
i++;
|
|
1314
|
-
}
|
|
1303
|
+
// let k = i + 1;
|
|
1304
|
+
// for (; k < syntaxes.length; k++) {
|
|
1305
|
+
// if (syntaxes[k].typ !== ValidationTokenEnum.Whitespace) {
|
|
1306
|
+
// break;
|
|
1307
|
+
// }
|
|
1308
|
+
// if (syntaxes[k]?.typ === ValidationTokenEnum.Comma) {
|
|
1309
|
+
// i = k;
|
|
1310
|
+
// }
|
|
1311
|
+
// }
|
|
1315
1312
|
continue;
|
|
1316
1313
|
}
|
|
1314
|
+
// if (isOptional) {
|
|
1315
|
+
// // eat the next ','
|
|
1316
|
+
// if (
|
|
1317
|
+
// syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace ||
|
|
1318
|
+
// syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma
|
|
1319
|
+
// ) {
|
|
1320
|
+
// i++;
|
|
1321
|
+
// }
|
|
1322
|
+
// continue;
|
|
1323
|
+
// }
|
|
1317
1324
|
return {
|
|
1318
1325
|
success: false,
|
|
1319
1326
|
valid: true,
|
|
@@ -1338,16 +1345,16 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1338
1345
|
context.update(result.context.current());
|
|
1339
1346
|
continue;
|
|
1340
1347
|
}
|
|
1341
|
-
if (isOptional) {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
}
|
|
1348
|
+
// if (isOptional) {
|
|
1349
|
+
// // eat the next ','
|
|
1350
|
+
// if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace) {
|
|
1351
|
+
// i++;
|
|
1352
|
+
// }
|
|
1353
|
+
// if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma) {
|
|
1354
|
+
// i++;
|
|
1355
|
+
// }
|
|
1356
|
+
// continue;
|
|
1357
|
+
// }
|
|
1351
1358
|
return {
|
|
1352
1359
|
success: false,
|
|
1353
1360
|
valid: true,
|
|
@@ -1379,49 +1386,21 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1379
1386
|
success = true;
|
|
1380
1387
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1381
1388
|
context.next();
|
|
1382
|
-
if (context.done()) {
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
}
|
|
1392
|
-
break;
|
|
1393
|
-
}
|
|
1394
|
-
if (isOptional) {
|
|
1395
|
-
break;
|
|
1396
|
-
}
|
|
1397
|
-
return {
|
|
1398
|
-
success: false,
|
|
1399
|
-
valid: true,
|
|
1400
|
-
token,
|
|
1401
|
-
context,
|
|
1402
|
-
syntaxToken: syntaxes[i],
|
|
1403
|
-
errors: [],
|
|
1404
|
-
};
|
|
1405
|
-
case ValidationTokenEnum.Colon:
|
|
1406
|
-
if (token.typ == EnumToken.ColonTokenType) {
|
|
1407
|
-
success = true;
|
|
1408
|
-
options.visited.get(token).delete(syntaxes[i]);
|
|
1409
|
-
context.next();
|
|
1410
|
-
if (context.done()) {
|
|
1411
|
-
return {
|
|
1412
|
-
success: true,
|
|
1413
|
-
valid: true,
|
|
1414
|
-
token: null,
|
|
1415
|
-
context,
|
|
1416
|
-
syntaxToken: syntaxes[i + 1],
|
|
1417
|
-
errors: [],
|
|
1418
|
-
};
|
|
1419
|
-
}
|
|
1420
|
-
break;
|
|
1421
|
-
}
|
|
1422
|
-
if (isOptional) {
|
|
1389
|
+
// if (context.done()) {
|
|
1390
|
+
// return {
|
|
1391
|
+
// success: true,
|
|
1392
|
+
// valid: true,
|
|
1393
|
+
// token: null,
|
|
1394
|
+
// context,
|
|
1395
|
+
// syntaxToken: syntaxes[i + 1],
|
|
1396
|
+
// errors: [],
|
|
1397
|
+
// };
|
|
1398
|
+
// }
|
|
1423
1399
|
break;
|
|
1424
1400
|
}
|
|
1401
|
+
// if (isOptional) {
|
|
1402
|
+
// break;
|
|
1403
|
+
// }
|
|
1425
1404
|
return {
|
|
1426
1405
|
success: false,
|
|
1427
1406
|
valid: true,
|
|
@@ -1430,6 +1409,34 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1430
1409
|
syntaxToken: syntaxes[i],
|
|
1431
1410
|
errors: [],
|
|
1432
1411
|
};
|
|
1412
|
+
// case ValidationTokenEnum.Colon:
|
|
1413
|
+
// if (token.typ == EnumToken.ColonTokenType) {
|
|
1414
|
+
// success = true;
|
|
1415
|
+
// (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
|
|
1416
|
+
// context.next();
|
|
1417
|
+
// if (context.done()) {
|
|
1418
|
+
// return {
|
|
1419
|
+
// success: true,
|
|
1420
|
+
// valid: true,
|
|
1421
|
+
// token: null,
|
|
1422
|
+
// context,
|
|
1423
|
+
// syntaxToken: syntaxes[i + 1],
|
|
1424
|
+
// errors: [],
|
|
1425
|
+
// };
|
|
1426
|
+
// }
|
|
1427
|
+
// break;
|
|
1428
|
+
// }
|
|
1429
|
+
// if (isOptional) {
|
|
1430
|
+
// break;
|
|
1431
|
+
// }
|
|
1432
|
+
// return {
|
|
1433
|
+
// success: false,
|
|
1434
|
+
// valid: true,
|
|
1435
|
+
// token,
|
|
1436
|
+
// context,
|
|
1437
|
+
// syntaxToken: syntaxes[i],
|
|
1438
|
+
// errors: [],
|
|
1439
|
+
// };
|
|
1433
1440
|
case ValidationTokenEnum.Keyword:
|
|
1434
1441
|
if (token.typ == EnumToken.IdenTokenType &&
|
|
1435
1442
|
token.val.toLowerCase() ===
|
|
@@ -1497,40 +1504,38 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1497
1504
|
}
|
|
1498
1505
|
break;
|
|
1499
1506
|
}
|
|
1500
|
-
case ValidationTokenEnum.AtRule:
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1507
|
+
// case ValidationTokenEnum.AtRule:
|
|
1508
|
+
// if (token.typ == EnumToken.AtRuleTokenType) {
|
|
1509
|
+
// success = true;
|
|
1510
|
+
// (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
|
|
1511
|
+
// context.next();
|
|
1512
|
+
// break;
|
|
1513
|
+
// }
|
|
1514
|
+
// if (isOptional) {
|
|
1515
|
+
// break;
|
|
1516
|
+
// }
|
|
1517
|
+
// return {
|
|
1518
|
+
// success: false,
|
|
1519
|
+
// valid: true,
|
|
1520
|
+
// token,
|
|
1521
|
+
// context,
|
|
1522
|
+
// syntaxToken: syntaxes[i],
|
|
1523
|
+
// errors: [],
|
|
1524
|
+
// };
|
|
1518
1525
|
case ValidationTokenEnum.StringToken:
|
|
1519
|
-
if (token.typ == EnumToken.StringTokenType || token.typ == EnumToken.UrlFunctionTokenType) {
|
|
1520
|
-
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
else if (token.typ === EnumToken.Add) {
|
|
1526
|
+
// if (token.typ == EnumToken.StringTokenType || token.typ == EnumToken.UrlFunctionTokenType) {
|
|
1527
|
+
// success = true;
|
|
1528
|
+
// } else if (token.typ === EnumToken.StringTokenType) {
|
|
1529
|
+
// success = (token as StringToken).val === (syntaxes[i] as ValidationStringToken).val.slice(1, -1);
|
|
1530
|
+
// } else
|
|
1531
|
+
if (token.typ === EnumToken.Add) {
|
|
1526
1532
|
success = syntaxes[i].val.slice(1, -1) === "+";
|
|
1527
1533
|
}
|
|
1528
|
-
else if (token.typ === EnumToken.Mul) {
|
|
1529
|
-
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
}
|
|
1534
|
+
// else if (token.typ === EnumToken.Mul) {
|
|
1535
|
+
// success = (syntaxes[i] as ValidationStringToken).val.slice(1, -1) === "*";
|
|
1536
|
+
// } else if (token.typ === EnumToken.Div) {
|
|
1537
|
+
// success = (syntaxes[i] as ValidationStringToken).val.slice(1, -1) === "/";
|
|
1538
|
+
// }
|
|
1534
1539
|
else if (token.typ === EnumToken.Sub) {
|
|
1535
1540
|
success = syntaxes[i].val.slice(1, -1) === "-";
|
|
1536
1541
|
}
|
|
@@ -1555,24 +1560,24 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1555
1560
|
syntaxToken: syntaxes[i],
|
|
1556
1561
|
errors: [],
|
|
1557
1562
|
};
|
|
1558
|
-
case ValidationTokenEnum.SemiColon:
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1563
|
+
// case ValidationTokenEnum.SemiColon:
|
|
1564
|
+
// if (token.typ == EnumToken.SemiColonTokenType) {
|
|
1565
|
+
// success = true;
|
|
1566
|
+
// (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
|
|
1567
|
+
// context.next();
|
|
1568
|
+
// break;
|
|
1569
|
+
// }
|
|
1570
|
+
// if (isOptional) {
|
|
1571
|
+
// break;
|
|
1572
|
+
// }
|
|
1573
|
+
// return {
|
|
1574
|
+
// success: false,
|
|
1575
|
+
// valid: true,
|
|
1576
|
+
// token,
|
|
1577
|
+
// context,
|
|
1578
|
+
// syntaxToken: syntaxes[i],
|
|
1579
|
+
// errors: [],
|
|
1580
|
+
// };
|
|
1576
1581
|
case ValidationTokenEnum.PropertyType:
|
|
1577
1582
|
result = matchProperty(syntaxes[i], context, options);
|
|
1578
1583
|
if (!result.success) {
|
|
@@ -1626,26 +1631,25 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1626
1631
|
if (result?.success) {
|
|
1627
1632
|
success = true;
|
|
1628
1633
|
options.visited.get(token).delete(syntaxes[i]);
|
|
1629
|
-
if (result
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
}
|
|
1634
|
+
// if (result!.context.done()) {
|
|
1635
|
+
// context.end();
|
|
1636
|
+
// return {
|
|
1637
|
+
// success: true,
|
|
1638
|
+
// valid: true,
|
|
1639
|
+
// token: null,
|
|
1640
|
+
// context,
|
|
1641
|
+
// syntaxToken: syntaxes[i + 1],
|
|
1642
|
+
// errors: [],
|
|
1643
|
+
// };
|
|
1644
|
+
// } else {
|
|
1645
|
+
context.update(result.context.current());
|
|
1646
|
+
// }
|
|
1643
1647
|
break;
|
|
1644
1648
|
}
|
|
1645
1649
|
}
|
|
1646
|
-
if (isOptional) {
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1650
|
+
// if (isOptional) {
|
|
1651
|
+
// break;
|
|
1652
|
+
// }
|
|
1649
1653
|
return {
|
|
1650
1654
|
success: false,
|
|
1651
1655
|
valid: true,
|
|
@@ -1657,7 +1661,7 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1657
1661
|
action: "drop",
|
|
1658
1662
|
message: "could not match syntax",
|
|
1659
1663
|
node: token,
|
|
1660
|
-
location: token
|
|
1664
|
+
location: token[LOC],
|
|
1661
1665
|
syntax: syntaxes[i],
|
|
1662
1666
|
},
|
|
1663
1667
|
],
|
|
@@ -1715,9 +1719,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1715
1719
|
}
|
|
1716
1720
|
break;
|
|
1717
1721
|
}
|
|
1718
|
-
if (isOptional) {
|
|
1719
|
-
|
|
1720
|
-
}
|
|
1722
|
+
// if (isOptional) {
|
|
1723
|
+
// break;
|
|
1724
|
+
// }
|
|
1721
1725
|
return {
|
|
1722
1726
|
success: false,
|
|
1723
1727
|
valid: true,
|
|
@@ -1747,9 +1751,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1747
1751
|
}
|
|
1748
1752
|
break;
|
|
1749
1753
|
}
|
|
1750
|
-
if (isOptional) {
|
|
1751
|
-
|
|
1752
|
-
}
|
|
1754
|
+
// if (isOptional) {
|
|
1755
|
+
// break;
|
|
1756
|
+
// }
|
|
1753
1757
|
return {
|
|
1754
1758
|
success: false,
|
|
1755
1759
|
valid: true,
|
|
@@ -1758,38 +1762,47 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1758
1762
|
syntaxToken: syntaxes[i],
|
|
1759
1763
|
errors: [],
|
|
1760
1764
|
};
|
|
1761
|
-
case ValidationTokenEnum.PseudoClassFunctionToken:
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1765
|
+
// case ValidationTokenEnum.PseudoClassFunctionToken:
|
|
1766
|
+
// if (!((token as PseudoClassFunctionToken).val + "()" in config.selectors)) {
|
|
1767
|
+
// return {
|
|
1768
|
+
// success: false,
|
|
1769
|
+
// valid: true,
|
|
1770
|
+
// token,
|
|
1771
|
+
// context,
|
|
1772
|
+
// syntaxToken: syntaxes[i],
|
|
1773
|
+
// errors: [
|
|
1774
|
+
// {
|
|
1775
|
+
// action: "drop",
|
|
1776
|
+
// message: `Unknown pseudo-class selector ${(token as PseudoClassFunctionToken).val}()`,
|
|
1777
|
+
// node: token,
|
|
1778
|
+
// },
|
|
1779
|
+
// ],
|
|
1780
|
+
// };
|
|
1781
|
+
// }
|
|
1782
|
+
// result = matchSyntax(
|
|
1783
|
+
// ((
|
|
1784
|
+
// getParsedSyntax(
|
|
1785
|
+
// ValidationSyntaxGroupEnum.Selectors,
|
|
1786
|
+
// (token as PseudoClassFunctionToken).val + "()",
|
|
1787
|
+
// ) as [ValidationPseudoClassFunctionToken]
|
|
1788
|
+
// )?.[0]?.chi as ValidationToken[]) ?? [],
|
|
1789
|
+
// createValidationContext((token as PseudoClassFunctionToken).chi),
|
|
1790
|
+
// options,
|
|
1791
|
+
// );
|
|
1792
|
+
// if (result.success) {
|
|
1793
|
+
// success = true;
|
|
1794
|
+
// (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
|
|
1795
|
+
// context.next();
|
|
1796
|
+
// break;
|
|
1797
|
+
// }
|
|
1798
|
+
// return {
|
|
1799
|
+
// success: false,
|
|
1800
|
+
// valid: true,
|
|
1801
|
+
// token,
|
|
1802
|
+
// context,
|
|
1803
|
+
// syntaxToken: syntaxes[i],
|
|
1804
|
+
// errors: result.errors,
|
|
1805
|
+
// };
|
|
1793
1806
|
case ValidationTokenEnum.Function:
|
|
1794
1807
|
if ((!tokensfuncDefMap.has(token.typ) &&
|
|
1795
1808
|
!funcLike.includes(token.typ) &&
|
|
@@ -1813,23 +1826,23 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1813
1826
|
}
|
|
1814
1827
|
if (tokensfuncDefMap.has(token.typ)) {
|
|
1815
1828
|
const range = context.peekRange();
|
|
1816
|
-
if (range.at(-1)?.typ !== EnumToken.EndParensTokenType) {
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
}
|
|
1829
|
+
// if (range.at(-1)?.typ !== EnumToken.EndParensTokenType) {
|
|
1830
|
+
// const tk = range.at(-1) as Token;
|
|
1831
|
+
// return {
|
|
1832
|
+
// success: false,
|
|
1833
|
+
// valid: true,
|
|
1834
|
+
// token,
|
|
1835
|
+
// context,
|
|
1836
|
+
// syntaxToken: syntaxes[i],
|
|
1837
|
+
// errors: [
|
|
1838
|
+
// {
|
|
1839
|
+
// action: "drop",
|
|
1840
|
+
// message: `Expecting ')' at ${tk[LOC]?.src}:${tk[LOC]?.sta?.lin}:${tk[LOC]?.sta?.col}`,
|
|
1841
|
+
// node: token,
|
|
1842
|
+
// },
|
|
1843
|
+
// ],
|
|
1844
|
+
// };
|
|
1845
|
+
// }
|
|
1833
1846
|
result = matchSyntax(syntaxes[i].chi, createValidationContext(range.slice(1, -1)), options);
|
|
1834
1847
|
if (result.success && result.context.done()) {
|
|
1835
1848
|
context.update(range.at(-1));
|
|
@@ -1846,9 +1859,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1846
1859
|
break;
|
|
1847
1860
|
}
|
|
1848
1861
|
}
|
|
1849
|
-
if (isOptional) {
|
|
1850
|
-
|
|
1851
|
-
}
|
|
1862
|
+
// if (isOptional) {
|
|
1863
|
+
// break;
|
|
1864
|
+
// }
|
|
1852
1865
|
return {
|
|
1853
1866
|
success: false,
|
|
1854
1867
|
valid: true,
|
|
@@ -1857,20 +1870,20 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1857
1870
|
syntaxToken: syntaxes[i],
|
|
1858
1871
|
errors: result.errors,
|
|
1859
1872
|
};
|
|
1860
|
-
case ValidationTokenEnum.LessThan:
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1873
|
+
// case ValidationTokenEnum.LessThan:
|
|
1874
|
+
// if (token.typ === EnumToken.LtTokenType) {
|
|
1875
|
+
// (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
|
|
1876
|
+
// context.next();
|
|
1877
|
+
// break;
|
|
1878
|
+
// }
|
|
1879
|
+
// return {
|
|
1880
|
+
// success: false,
|
|
1881
|
+
// valid: true,
|
|
1882
|
+
// token,
|
|
1883
|
+
// context,
|
|
1884
|
+
// syntaxToken: syntaxes[i],
|
|
1885
|
+
// errors: [],
|
|
1886
|
+
// };
|
|
1874
1887
|
case ValidationTokenEnum.Separator:
|
|
1875
1888
|
if (token.typ === EnumToken.LiteralTokenType && token.val === "/") {
|
|
1876
1889
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1921,9 +1934,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1921
1934
|
context.next();
|
|
1922
1935
|
break;
|
|
1923
1936
|
}
|
|
1924
|
-
if (isOptional) {
|
|
1925
|
-
|
|
1926
|
-
}
|
|
1937
|
+
// if (isOptional) {
|
|
1938
|
+
// break;
|
|
1939
|
+
// }
|
|
1927
1940
|
return {
|
|
1928
1941
|
success: false,
|
|
1929
1942
|
valid: true,
|
|
@@ -1938,9 +1951,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1938
1951
|
context.next();
|
|
1939
1952
|
break;
|
|
1940
1953
|
}
|
|
1941
|
-
if (isOptional) {
|
|
1942
|
-
|
|
1943
|
-
}
|
|
1954
|
+
// if (isOptional) {
|
|
1955
|
+
// break;
|
|
1956
|
+
// }
|
|
1944
1957
|
return {
|
|
1945
1958
|
success: false,
|
|
1946
1959
|
valid: true,
|
|
@@ -1949,47 +1962,53 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1949
1962
|
syntaxToken: syntaxes[i],
|
|
1950
1963
|
errors: [],
|
|
1951
1964
|
};
|
|
1952
|
-
case ValidationTokenEnum.DeclarationNameToken:
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1965
|
+
// case ValidationTokenEnum.DeclarationNameToken:
|
|
1966
|
+
// result = matchSyntax(
|
|
1967
|
+
// (getParsedSyntax(
|
|
1968
|
+
// ValidationSyntaxGroupEnum.Declarations,
|
|
1969
|
+
// (syntaxes[i] as ValidationDeclarationToken).val,
|
|
1970
|
+
// ) as ValidationFunctionToken[] as ValidationToken[]) ?? [],
|
|
1971
|
+
// context.slice(),
|
|
1972
|
+
// options,
|
|
1973
|
+
// );
|
|
1974
|
+
// if (!result.success) {
|
|
1975
|
+
// return {
|
|
1976
|
+
// success: false,
|
|
1977
|
+
// valid: true,
|
|
1978
|
+
// token,
|
|
1979
|
+
// context,
|
|
1980
|
+
// syntaxToken: syntaxes[i],
|
|
1981
|
+
// errors: result.errors,
|
|
1982
|
+
// };
|
|
1983
|
+
// }
|
|
1984
|
+
// success = true;
|
|
1985
|
+
// (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
|
|
1986
|
+
// if (result.context.done()) {
|
|
1987
|
+
// context.end();
|
|
1988
|
+
// return {
|
|
1989
|
+
// success,
|
|
1990
|
+
// valid: true,
|
|
1991
|
+
// token: null,
|
|
1992
|
+
// context,
|
|
1993
|
+
// syntaxToken: syntaxes[1 + i],
|
|
1994
|
+
// errors: [],
|
|
1995
|
+
// };
|
|
1996
|
+
// } else {
|
|
1997
|
+
// context.update(result.context.current() as Token);
|
|
1998
|
+
// }
|
|
1999
|
+
// break;
|
|
2000
|
+
// case ValidationTokenEnum.DisallowWhitespace:
|
|
2001
|
+
// if (context.peek(0, false)?.typ === EnumToken.WhitespaceTokenType) {
|
|
2002
|
+
// return {
|
|
2003
|
+
// success: false,
|
|
2004
|
+
// valid: true,
|
|
2005
|
+
// token,
|
|
2006
|
+
// context,
|
|
2007
|
+
// syntaxToken: syntaxes[i],
|
|
2008
|
+
// errors: [],
|
|
2009
|
+
// };
|
|
2010
|
+
// }
|
|
2011
|
+
// break;
|
|
1993
2012
|
default:
|
|
1994
2013
|
throw new Error(`Unexpected syntax ${ValidationTokenEnum[syntaxes[i].typ]}`);
|
|
1995
2014
|
}
|
|
@@ -2080,11 +2099,9 @@ function matchAmpersandSyntax(syntax, context, options) {
|
|
|
2080
2099
|
const syntaxes = [syntax.l, syntax.r];
|
|
2081
2100
|
let result;
|
|
2082
2101
|
let i;
|
|
2083
|
-
let success = false;
|
|
2084
2102
|
for (i = 0; i < syntaxes.length; i++) {
|
|
2085
2103
|
result = matchSyntax(syntaxes[i], context.slice(), options);
|
|
2086
2104
|
if (result.success) {
|
|
2087
|
-
success = true;
|
|
2088
2105
|
if (result.context.done()) {
|
|
2089
2106
|
context.end();
|
|
2090
2107
|
break;
|
|
@@ -2094,15 +2111,7 @@ function matchAmpersandSyntax(syntax, context, options) {
|
|
|
2094
2111
|
i = -1;
|
|
2095
2112
|
}
|
|
2096
2113
|
}
|
|
2097
|
-
return
|
|
2098
|
-
/* syntaxes.length === 0 ? */ result ?? {
|
|
2099
|
-
success,
|
|
2100
|
-
valid: true,
|
|
2101
|
-
token: context.peek(),
|
|
2102
|
-
context,
|
|
2103
|
-
syntaxToken: syntax,
|
|
2104
|
-
errors: [],
|
|
2105
|
-
});
|
|
2114
|
+
return result;
|
|
2106
2115
|
}
|
|
2107
2116
|
function matchProperty(property, context, options) {
|
|
2108
2117
|
let success = false;
|
|
@@ -2165,17 +2174,17 @@ function matchProperty(property, context, options) {
|
|
|
2165
2174
|
};
|
|
2166
2175
|
}
|
|
2167
2176
|
switch (property.val) {
|
|
2168
|
-
case "combinator":
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2177
|
+
// case "combinator":
|
|
2178
|
+
// {
|
|
2179
|
+
// const token = context.peek() as Token;
|
|
2180
|
+
// success =
|
|
2181
|
+
// token != null &&
|
|
2182
|
+
// (token.typ == EnumToken.NextSiblingCombinatorTokenType ||
|
|
2183
|
+
// token.typ == EnumToken.ChildCombinatorTokenType ||
|
|
2184
|
+
// token.typ == EnumToken.SubsequentSiblingCombinatorTokenType ||
|
|
2185
|
+
// token.typ == EnumToken.ColumnCombinatorTokenType);
|
|
2186
|
+
// }
|
|
2187
|
+
// break;
|
|
2179
2188
|
case "declaration-value":
|
|
2180
2189
|
{
|
|
2181
2190
|
// consume a declaration value
|
|
@@ -2185,112 +2194,91 @@ function matchProperty(property, context, options) {
|
|
|
2185
2194
|
// if semicolon or end curly brace is encountered, stop
|
|
2186
2195
|
let expectToken = true;
|
|
2187
2196
|
let token;
|
|
2188
|
-
const stack = [];
|
|
2189
2197
|
token = context.peek();
|
|
2190
|
-
if (token?.typ == EnumToken.WhitespaceTokenType) {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
}
|
|
2194
|
-
if (token?.typ == EnumToken.CommentTokenType) {
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
}
|
|
2198
|
-
if (token?.typ == EnumToken.CommaTokenType) {
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
}
|
|
2198
|
+
// if (token?.typ == EnumToken.WhitespaceTokenType) {
|
|
2199
|
+
// context.next();
|
|
2200
|
+
// token = context.peek();
|
|
2201
|
+
// }
|
|
2202
|
+
// if (token?.typ == EnumToken.CommentTokenType) {
|
|
2203
|
+
// context.next();
|
|
2204
|
+
// token = context.peek();
|
|
2205
|
+
// }
|
|
2206
|
+
// if (token?.typ == EnumToken.CommaTokenType) {
|
|
2207
|
+
// context.next();
|
|
2208
|
+
// expectToken = true;
|
|
2209
|
+
// }
|
|
2202
2210
|
while ((token = context.peek()) != null) {
|
|
2203
|
-
if (token.typ == EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ))
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
context.next();
|
|
2208
|
-
}
|
|
2211
|
+
if (token.typ == EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) ;
|
|
2212
|
+
// if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
|
|
2213
|
+
// context.next();
|
|
2214
|
+
// }
|
|
2209
2215
|
if (expectToken) {
|
|
2210
|
-
if (token?.typ == EnumToken.CommaTokenType || token.typ == EnumToken.EndParensTokenType) {
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
}
|
|
2216
|
+
// if (token?.typ == EnumToken.CommaTokenType || token.typ == EnumToken.EndParensTokenType) {
|
|
2217
|
+
// return {
|
|
2218
|
+
// success: false,
|
|
2219
|
+
// valid: true,
|
|
2220
|
+
// token,
|
|
2221
|
+
// context,
|
|
2222
|
+
// syntaxToken: property,
|
|
2223
|
+
// errors: [
|
|
2224
|
+
// {
|
|
2225
|
+
// action: "drop",
|
|
2226
|
+
// message: `Unexpected token ${EnumToken[token?.typ]} at ${token![LOC]?.src}:${token![LOC]?.sta?.lin}:${token![LOC]?.sta?.col}`,
|
|
2227
|
+
// node: token,
|
|
2228
|
+
// location: token[LOC],
|
|
2229
|
+
// },
|
|
2230
|
+
// ],
|
|
2231
|
+
// };
|
|
2232
|
+
// }
|
|
2227
2233
|
expectToken = false;
|
|
2228
2234
|
}
|
|
2229
2235
|
if (token.typ == EnumToken.CommaTokenType) {
|
|
2230
2236
|
expectToken = true;
|
|
2231
2237
|
}
|
|
2232
|
-
if (token.typ == EnumToken.EndParensTokenType) {
|
|
2233
|
-
if (stack.length > 0) {
|
|
2234
|
-
stack.pop();
|
|
2235
|
-
}
|
|
2236
|
-
else {
|
|
2237
|
-
return {
|
|
2238
|
-
success: false,
|
|
2239
|
-
valid: true,
|
|
2240
|
-
token,
|
|
2241
|
-
context,
|
|
2242
|
-
syntaxToken: property,
|
|
2243
|
-
errors: [
|
|
2244
|
-
{
|
|
2245
|
-
action: "drop",
|
|
2246
|
-
message: `Unexpected token ${EnumToken[token?.typ]} at ${token.loc?.src}:${token.loc?.sta?.lin}:${token.loc?.sta?.col}`,
|
|
2247
|
-
node: token,
|
|
2248
|
-
location: token.loc,
|
|
2249
|
-
},
|
|
2250
|
-
],
|
|
2251
|
-
};
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
2238
|
context.next();
|
|
2255
2239
|
}
|
|
2256
|
-
if (stack.length > 0) {
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
}
|
|
2240
|
+
// if (stack.length > 0) {
|
|
2241
|
+
// token = stack.at(-1) as Token;
|
|
2242
|
+
// return {
|
|
2243
|
+
// success: false,
|
|
2244
|
+
// valid: true,
|
|
2245
|
+
// token,
|
|
2246
|
+
// context,
|
|
2247
|
+
// syntaxToken: property,
|
|
2248
|
+
// errors: [
|
|
2249
|
+
// {
|
|
2250
|
+
// action: "drop",
|
|
2251
|
+
// message: `unbalanced parentheses ${EnumToken[token?.typ]} at ${token![LOC]?.src}:${token![LOC]?.sta?.lin}:${token![LOC]?.sta?.col}`,
|
|
2252
|
+
// node: token,
|
|
2253
|
+
// location: token[LOC],
|
|
2254
|
+
// },
|
|
2255
|
+
// ],
|
|
2256
|
+
// };
|
|
2257
|
+
// }
|
|
2274
2258
|
success = !expectToken;
|
|
2275
|
-
if (!success) {
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
}
|
|
2259
|
+
// if (!success) {
|
|
2260
|
+
// return {
|
|
2261
|
+
// success: false,
|
|
2262
|
+
// valid: true,
|
|
2263
|
+
// token: token ?? context.current(),
|
|
2264
|
+
// context,
|
|
2265
|
+
// syntaxToken: property,
|
|
2266
|
+
// errors: [],
|
|
2267
|
+
// };
|
|
2268
|
+
// }
|
|
2285
2269
|
}
|
|
2286
2270
|
break;
|
|
2287
2271
|
case "calc-sum": {
|
|
2288
2272
|
const token = context.peek();
|
|
2289
|
-
if (token?.typ === EnumToken.ParensTokenType) {
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2273
|
+
// if (token?.typ === EnumToken.ParensTokenType) {
|
|
2274
|
+
// const result = matchSyntax(
|
|
2275
|
+
// (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()") as ValidationFunctionToken[])[0].chi,
|
|
2276
|
+
// createValidationContext((token as ParensToken).chi),
|
|
2277
|
+
// options,
|
|
2278
|
+
// );
|
|
2279
|
+
// success = result.success && result.context.done();
|
|
2280
|
+
// break;
|
|
2281
|
+
// }
|
|
2294
2282
|
if (token?.typ === EnumToken.BinaryExpressionTokenType) {
|
|
2295
2283
|
let result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), createValidationContext([token.l]), options);
|
|
2296
2284
|
if (result.success) {
|
|
@@ -2319,22 +2307,22 @@ function matchProperty(property, context, options) {
|
|
|
2319
2307
|
}
|
|
2320
2308
|
break;
|
|
2321
2309
|
}
|
|
2322
|
-
case "at-keyword-token":
|
|
2323
|
-
|
|
2324
|
-
|
|
2310
|
+
// case "at-keyword-token":
|
|
2311
|
+
// success = context.peek()?.typ === EnumToken.AtRuleTokenType;
|
|
2312
|
+
// break;
|
|
2325
2313
|
case "an+b":
|
|
2326
2314
|
{
|
|
2327
2315
|
let token = context.peek();
|
|
2328
|
-
if (token == null) {
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
}
|
|
2316
|
+
// if (token == null) {
|
|
2317
|
+
// return {
|
|
2318
|
+
// success: false,
|
|
2319
|
+
// valid: true,
|
|
2320
|
+
// token: null,
|
|
2321
|
+
// context,
|
|
2322
|
+
// syntaxToken: property,
|
|
2323
|
+
// errors: [],
|
|
2324
|
+
// };
|
|
2325
|
+
// }
|
|
2338
2326
|
if (token.typ === EnumToken.IdenTokenType &&
|
|
2339
2327
|
("even" === token.val || "odd" === token.val)) {
|
|
2340
2328
|
success = true;
|
|
@@ -2349,19 +2337,19 @@ function matchProperty(property, context, options) {
|
|
|
2349
2337
|
if (token.typ === EnumToken.LiteralTokenType || token.typ === EnumToken.IdenTokenType) {
|
|
2350
2338
|
let match = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(token.val);
|
|
2351
2339
|
success = match != null;
|
|
2352
|
-
if (!success) {
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2340
|
+
// if (!success) {
|
|
2341
|
+
// success = /^(([+-]?[0-9]*)?n)?([+-])?$/.test((token as LiteralToken).val);
|
|
2342
|
+
// if (success) {
|
|
2343
|
+
// token = context.peek(1) as Token;
|
|
2344
|
+
// success =
|
|
2345
|
+
// token?.typ === EnumToken.NumberTokenType &&
|
|
2346
|
+
// Number.isInteger((token as NumberToken).val) &&
|
|
2347
|
+
// !(token as NumberToken).toString().includes(".") &&
|
|
2348
|
+
// (token as NumberToken).sign == null;
|
|
2349
|
+
// context.next();
|
|
2350
|
+
// }
|
|
2351
|
+
// } else
|
|
2352
|
+
if (match?.[3] == null) {
|
|
2365
2353
|
token = context.peek(1);
|
|
2366
2354
|
if (token?.typ === EnumToken.Add ||
|
|
2367
2355
|
token?.typ === EnumToken.NextSiblingCombinatorTokenType ||
|
|
@@ -2373,12 +2361,12 @@ function matchProperty(property, context, options) {
|
|
|
2373
2361
|
!token.toString().includes(".") &&
|
|
2374
2362
|
token.sign == null;
|
|
2375
2363
|
}
|
|
2376
|
-
else if (token?.typ === EnumToken.NumberTokenType) {
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
}
|
|
2364
|
+
// else if (token?.typ === EnumToken.NumberTokenType) {
|
|
2365
|
+
// success =
|
|
2366
|
+
// Number.isInteger((token as NumberToken).val) &&
|
|
2367
|
+
// !(token as NumberToken).toString().includes(".") &&
|
|
2368
|
+
// (token as NumberToken).sign != null;
|
|
2369
|
+
// }
|
|
2382
2370
|
if (success) {
|
|
2383
2371
|
context.update(token);
|
|
2384
2372
|
return {
|
|
@@ -2397,26 +2385,26 @@ function matchProperty(property, context, options) {
|
|
|
2397
2385
|
success =
|
|
2398
2386
|
Number.isInteger(token.val) &&
|
|
2399
2387
|
!token.toString().includes(".");
|
|
2400
|
-
if (!success) {
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
}
|
|
2417
|
-
if (token == null) {
|
|
2418
|
-
|
|
2419
|
-
}
|
|
2388
|
+
// if (!success) {
|
|
2389
|
+
// return {
|
|
2390
|
+
// success: false,
|
|
2391
|
+
// valid: true,
|
|
2392
|
+
// token: null,
|
|
2393
|
+
// context,
|
|
2394
|
+
// syntaxToken: property,
|
|
2395
|
+
// errors: [
|
|
2396
|
+
// {
|
|
2397
|
+
// action: "drop",
|
|
2398
|
+
// message: `expecting <dimension-token>`,
|
|
2399
|
+
// node: token,
|
|
2400
|
+
// location: token[LOC],
|
|
2401
|
+
// },
|
|
2402
|
+
// ],
|
|
2403
|
+
// };
|
|
2404
|
+
// }
|
|
2405
|
+
// if (token == null) {
|
|
2406
|
+
// break;
|
|
2407
|
+
// }
|
|
2420
2408
|
token = context.peek(1);
|
|
2421
2409
|
if (token == null) {
|
|
2422
2410
|
break;
|
|
@@ -2434,9 +2422,9 @@ function matchProperty(property, context, options) {
|
|
|
2434
2422
|
Object.assign(token, { typ: EnumToken.Add });
|
|
2435
2423
|
}
|
|
2436
2424
|
token = context.peek(2);
|
|
2437
|
-
if (token == null) {
|
|
2438
|
-
|
|
2439
|
-
}
|
|
2425
|
+
// if (token == null) {
|
|
2426
|
+
// break;
|
|
2427
|
+
// }
|
|
2440
2428
|
if (token?.typ === EnumToken.NumberTokenType &&
|
|
2441
2429
|
Number.isInteger(token.val) &&
|
|
2442
2430
|
!token.toString().includes(".") &&
|
|
@@ -2449,33 +2437,33 @@ function matchProperty(property, context, options) {
|
|
|
2449
2437
|
}
|
|
2450
2438
|
}
|
|
2451
2439
|
break;
|
|
2452
|
-
case "number-token":
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
case "ndashdigit-ident":
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
case "dimension-token":
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2440
|
+
// case "number-token":
|
|
2441
|
+
// {
|
|
2442
|
+
// const token = context.peek();
|
|
2443
|
+
// success =
|
|
2444
|
+
// token?.typ === EnumToken.NumberTokenType &&
|
|
2445
|
+
// !(token as DimensionToken).val.toString().includes(".") &&
|
|
2446
|
+
// Number.isInteger((token as DimensionToken).val);
|
|
2447
|
+
// }
|
|
2448
|
+
// break;
|
|
2449
|
+
// case "ndashdigit-ident":
|
|
2450
|
+
// {
|
|
2451
|
+
// const token = context.peek();
|
|
2452
|
+
// success =
|
|
2453
|
+
// (token?.typ === EnumToken.IdenTokenType || token?.typ === EnumToken.LiteralTokenType) &&
|
|
2454
|
+
// /^-?n[-+]\d+$/.test((token as IdentToken | LiteralToken).val);
|
|
2455
|
+
// }
|
|
2456
|
+
// break;
|
|
2457
|
+
// case "dimension-token":
|
|
2458
|
+
// {
|
|
2459
|
+
// const token = context.peek();
|
|
2460
|
+
// success =
|
|
2461
|
+
// token?.typ === EnumToken.DimensionTokenType &&
|
|
2462
|
+
// (token as DimensionToken).unit === "n" &&
|
|
2463
|
+
// !(token as DimensionToken).val.toString().includes(".") &&
|
|
2464
|
+
// Number.isInteger((token as DimensionToken).val);
|
|
2465
|
+
// }
|
|
2466
|
+
// break;
|
|
2479
2467
|
case "quote":
|
|
2480
2468
|
case "display-box":
|
|
2481
2469
|
case "display-inside":
|
|
@@ -2498,29 +2486,29 @@ function matchProperty(property, context, options) {
|
|
|
2498
2486
|
token.val.toLowerCase() in config.mediaFeatures;
|
|
2499
2487
|
}
|
|
2500
2488
|
break;
|
|
2501
|
-
case "mf-comparison":
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
case "mf-gt":
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
case "mf-lt":
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2489
|
+
// case "mf-comparison":
|
|
2490
|
+
// {
|
|
2491
|
+
// const token = context.peek();
|
|
2492
|
+
// success =
|
|
2493
|
+
// token?.typ === EnumToken.LtTokenType ||
|
|
2494
|
+
// token?.typ === EnumToken.LteTokenType ||
|
|
2495
|
+
// token?.typ === EnumToken.GtTokenType ||
|
|
2496
|
+
// token?.typ === EnumToken.GteTokenType ||
|
|
2497
|
+
// token?.typ === EnumToken.DelimTokenType;
|
|
2498
|
+
// }
|
|
2499
|
+
// break;
|
|
2500
|
+
// case "mf-gt":
|
|
2501
|
+
// {
|
|
2502
|
+
// const token = context.peek();
|
|
2503
|
+
// success = token?.typ === EnumToken.GtTokenType || token?.typ === EnumToken.GteTokenType;
|
|
2504
|
+
// }
|
|
2505
|
+
// break;
|
|
2506
|
+
// case "mf-lt":
|
|
2507
|
+
// {
|
|
2508
|
+
// const token = context.peek();
|
|
2509
|
+
// success = token?.typ === EnumToken.LtTokenType || token?.typ === EnumToken.LteTokenType;
|
|
2510
|
+
// }
|
|
2511
|
+
// break;
|
|
2524
2512
|
case "dashed-ident":
|
|
2525
2513
|
case "extension-name":
|
|
2526
2514
|
case "custom-property-name":
|
|
@@ -2560,41 +2548,37 @@ function matchProperty(property, context, options) {
|
|
|
2560
2548
|
}
|
|
2561
2549
|
case "string": {
|
|
2562
2550
|
const token = context.peek();
|
|
2563
|
-
if (token == null) {
|
|
2564
|
-
|
|
2565
|
-
}
|
|
2566
|
-
success = token
|
|
2551
|
+
// if (token == null) {
|
|
2552
|
+
// break;
|
|
2553
|
+
// }
|
|
2554
|
+
success = token?.typ === EnumToken.StringTokenType;
|
|
2567
2555
|
break;
|
|
2568
2556
|
}
|
|
2569
|
-
case "wq-name":
|
|
2570
|
-
// wq-name matches
|
|
2571
|
-
// a
|
|
2572
|
-
// |a
|
|
2573
|
-
// *|a
|
|
2557
|
+
case "wq-name": // *|a // |a // a // wq-name matches
|
|
2574
2558
|
// a|b
|
|
2575
|
-
if (context.peek()?.typ == EnumToken.Pipe) {
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
}
|
|
2597
|
-
|
|
2559
|
+
// if (context.peek()?.typ == EnumToken.Pipe) {
|
|
2560
|
+
// const success = context.peek(1)?.typ == EnumToken.IdenTokenType;
|
|
2561
|
+
// return {
|
|
2562
|
+
// success,
|
|
2563
|
+
// valid: true,
|
|
2564
|
+
// token: success ? context.update(context.peek(1) as Token).current() : context.peek(),
|
|
2565
|
+
// context,
|
|
2566
|
+
// syntaxToken: property,
|
|
2567
|
+
// errors: [],
|
|
2568
|
+
// };
|
|
2569
|
+
// } else if (context.peek(1)?.typ == EnumToken.Pipe) {
|
|
2570
|
+
// const success =
|
|
2571
|
+
// context.peek()?.typ === EnumToken.Star && context.peek(2)?.typ === EnumToken.IdenTokenType;
|
|
2572
|
+
// return {
|
|
2573
|
+
// success,
|
|
2574
|
+
// valid: true,
|
|
2575
|
+
// token: success ? context.update(context.peek(2) as Token).current() : context.peek(),
|
|
2576
|
+
// context,
|
|
2577
|
+
// syntaxToken: property,
|
|
2578
|
+
// errors: [],
|
|
2579
|
+
// };
|
|
2580
|
+
// } else
|
|
2581
|
+
{
|
|
2598
2582
|
const success = context.peek()?.typ == EnumToken.IdenTokenType;
|
|
2599
2583
|
return {
|
|
2600
2584
|
success,
|
|
@@ -2605,28 +2589,28 @@ function matchProperty(property, context, options) {
|
|
|
2605
2589
|
errors: [],
|
|
2606
2590
|
};
|
|
2607
2591
|
}
|
|
2608
|
-
case "id-selector":
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
case "class-selector":
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
case "pseudo-class-selector":
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2592
|
+
// case "id-selector":
|
|
2593
|
+
// success = context.peek()?.typ == EnumToken.HashTokenType;
|
|
2594
|
+
// break;
|
|
2595
|
+
// case "class-selector":
|
|
2596
|
+
// success = context.peek()?.typ == EnumToken.ClassSelectorTokenType;
|
|
2597
|
+
// break;
|
|
2598
|
+
// case "pseudo-class-selector":
|
|
2599
|
+
// {
|
|
2600
|
+
// const token = context.peek();
|
|
2601
|
+
// success =
|
|
2602
|
+
// token?.typ == EnumToken.PseudoClassTokenType ||
|
|
2603
|
+
// token?.typ == EnumToken.PseudoClassFuncTokenType ||
|
|
2604
|
+
// token?.typ == EnumToken.PseudoElementTokenType;
|
|
2605
|
+
// }
|
|
2606
|
+
// break;
|
|
2623
2607
|
case "number":
|
|
2624
2608
|
{
|
|
2625
2609
|
const token = context.peek();
|
|
2626
|
-
if (token == null) {
|
|
2627
|
-
|
|
2628
|
-
}
|
|
2629
|
-
success = token
|
|
2610
|
+
// if (token == null) {
|
|
2611
|
+
// break;
|
|
2612
|
+
// }
|
|
2613
|
+
success = token?.typ == EnumToken.NumberTokenType;
|
|
2630
2614
|
}
|
|
2631
2615
|
break;
|
|
2632
2616
|
case "zero": {
|
|
@@ -2643,9 +2627,9 @@ function matchProperty(property, context, options) {
|
|
|
2643
2627
|
break;
|
|
2644
2628
|
case "dimension": {
|
|
2645
2629
|
const token = context.peek();
|
|
2646
|
-
if (token == null) {
|
|
2647
|
-
|
|
2648
|
-
}
|
|
2630
|
+
// if (token == null) {
|
|
2631
|
+
// break;
|
|
2632
|
+
// }
|
|
2649
2633
|
success =
|
|
2650
2634
|
token?.typ == EnumToken.DimensionTokenType ||
|
|
2651
2635
|
token?.typ == EnumToken.AngleTokenType ||
|
|
@@ -2660,19 +2644,19 @@ function matchProperty(property, context, options) {
|
|
|
2660
2644
|
case "angle":
|
|
2661
2645
|
{
|
|
2662
2646
|
const token = context.peek();
|
|
2663
|
-
if (token == null) {
|
|
2664
|
-
|
|
2665
|
-
}
|
|
2666
|
-
success = token
|
|
2647
|
+
// if (token == null) {
|
|
2648
|
+
// break;
|
|
2649
|
+
// }
|
|
2650
|
+
success = token?.typ === EnumToken.AngleTokenType;
|
|
2667
2651
|
}
|
|
2668
2652
|
break;
|
|
2669
2653
|
case "angle-percentage":
|
|
2670
2654
|
{
|
|
2671
2655
|
const token = context.peek();
|
|
2672
|
-
if (token == null) {
|
|
2673
|
-
|
|
2674
|
-
}
|
|
2675
|
-
success = token
|
|
2656
|
+
// if (token == null) {
|
|
2657
|
+
// break;
|
|
2658
|
+
// }
|
|
2659
|
+
success = token?.typ === EnumToken.AngleTokenType || token?.typ === EnumToken.PercentageTokenType;
|
|
2676
2660
|
}
|
|
2677
2661
|
break;
|
|
2678
2662
|
case "percentage":
|
|
@@ -2687,13 +2671,13 @@ function matchProperty(property, context, options) {
|
|
|
2687
2671
|
case "length-percentage":
|
|
2688
2672
|
{
|
|
2689
2673
|
const token = context.peek();
|
|
2690
|
-
if (token == null) {
|
|
2691
|
-
|
|
2692
|
-
}
|
|
2674
|
+
// if (token == null) {
|
|
2675
|
+
// break;
|
|
2676
|
+
// }
|
|
2693
2677
|
success =
|
|
2694
|
-
token
|
|
2695
|
-
token
|
|
2696
|
-
(token
|
|
2678
|
+
token?.typ == EnumToken.PercentageTokenType ||
|
|
2679
|
+
token?.typ == EnumToken.LengthTokenType ||
|
|
2680
|
+
(token?.typ == EnumToken.NumberTokenType && token?.val === 0);
|
|
2697
2681
|
}
|
|
2698
2682
|
break;
|
|
2699
2683
|
case "flex":
|
|
@@ -2701,12 +2685,12 @@ function matchProperty(property, context, options) {
|
|
|
2701
2685
|
break;
|
|
2702
2686
|
case "length": {
|
|
2703
2687
|
const token = context.peek();
|
|
2704
|
-
if (token == null) {
|
|
2705
|
-
|
|
2706
|
-
}
|
|
2688
|
+
// if (token == null) {
|
|
2689
|
+
// break;
|
|
2690
|
+
// }
|
|
2707
2691
|
success =
|
|
2708
|
-
token
|
|
2709
|
-
(token
|
|
2692
|
+
token?.typ == EnumToken.LengthTokenType ||
|
|
2693
|
+
(token?.typ == EnumToken.NumberTokenType && token?.val === 0);
|
|
2710
2694
|
break;
|
|
2711
2695
|
}
|
|
2712
2696
|
case "time":
|
|
@@ -2718,12 +2702,12 @@ function matchProperty(property, context, options) {
|
|
|
2718
2702
|
success = token.typ == EnumToken.TimeTokenType;
|
|
2719
2703
|
}
|
|
2720
2704
|
break;
|
|
2721
|
-
case "hex-color": {
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
}
|
|
2705
|
+
// case "hex-color": {
|
|
2706
|
+
// const token = context.peek();
|
|
2707
|
+
// success =
|
|
2708
|
+
// token != null && token.typ == EnumToken.ColorTokenType && (token as ColorToken).kin == ColorType.HEX;
|
|
2709
|
+
// break;
|
|
2710
|
+
// }
|
|
2727
2711
|
case "color":
|
|
2728
2712
|
case "color-function":
|
|
2729
2713
|
{
|
|
@@ -2799,10 +2783,10 @@ function matchProperty(property, context, options) {
|
|
|
2799
2783
|
}
|
|
2800
2784
|
}
|
|
2801
2785
|
break;
|
|
2802
|
-
case "url-token":
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2786
|
+
// case "url-token":
|
|
2787
|
+
// success =
|
|
2788
|
+
// context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
|
|
2789
|
+
// break;
|
|
2806
2790
|
case "type-selector":
|
|
2807
2791
|
case "compound-selector":
|
|
2808
2792
|
case "complex-selector":
|
|
@@ -2827,13 +2811,15 @@ function matchProperty(property, context, options) {
|
|
|
2827
2811
|
};
|
|
2828
2812
|
}
|
|
2829
2813
|
case "function-token":
|
|
2830
|
-
if (
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2814
|
+
// if (
|
|
2815
|
+
// context.peek()?.typ == EnumToken.IdenTokenType &&
|
|
2816
|
+
// context.peek(1, false)?.typ == EnumToken.StartParensTokenType
|
|
2817
|
+
// ) {
|
|
2818
|
+
// context.next();
|
|
2819
|
+
// context.next();
|
|
2820
|
+
// success = true;
|
|
2821
|
+
// break;
|
|
2822
|
+
// }
|
|
2837
2823
|
if (tokensfuncDefMap.has(context.peek()?.typ)) {
|
|
2838
2824
|
success = true;
|
|
2839
2825
|
context.next();
|
|
@@ -2855,17 +2841,17 @@ function matchProperty(property, context, options) {
|
|
|
2855
2841
|
config.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
|
|
2856
2842
|
break;
|
|
2857
2843
|
}
|
|
2858
|
-
case "named-color": {
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
}
|
|
2844
|
+
// case "named-color": {
|
|
2845
|
+
// const token = context.peek();
|
|
2846
|
+
// success =
|
|
2847
|
+
// token != null &&
|
|
2848
|
+
// token.typ == EnumToken.ColorTokenType &&
|
|
2849
|
+
// ((token as ColorToken).kin == ColorType.LIT ||
|
|
2850
|
+
// (token as ColorToken).kin == ColorType.SYS ||
|
|
2851
|
+
// (token as ColorToken).kin == ColorType.DPSYS ||
|
|
2852
|
+
// (token as ColorToken).kin == ColorType.NON_STD);
|
|
2853
|
+
// break;
|
|
2854
|
+
// }
|
|
2869
2855
|
case "size-feature": {
|
|
2870
2856
|
const range = context.peekRange();
|
|
2871
2857
|
const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
@@ -2896,20 +2882,20 @@ function matchProperty(property, context, options) {
|
|
|
2896
2882
|
errors: [],
|
|
2897
2883
|
};
|
|
2898
2884
|
}
|
|
2899
|
-
if (filteredRange.length === 3) {
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
}
|
|
2885
|
+
// if (filteredRange.length === 3) {
|
|
2886
|
+
// success = isValue(filteredRange[2]);
|
|
2887
|
+
// if (success) {
|
|
2888
|
+
// context.update(filteredRange[2]);
|
|
2889
|
+
// return {
|
|
2890
|
+
// success,
|
|
2891
|
+
// valid: true,
|
|
2892
|
+
// token: filteredRange[2],
|
|
2893
|
+
// context,
|
|
2894
|
+
// syntaxToken: property,
|
|
2895
|
+
// errors: [],
|
|
2896
|
+
// };
|
|
2897
|
+
// }
|
|
2898
|
+
// }
|
|
2913
2899
|
break;
|
|
2914
2900
|
}
|
|
2915
2901
|
case "style-feature": {
|
|
@@ -2919,16 +2905,16 @@ function matchProperty(property, context, options) {
|
|
|
2919
2905
|
// match <style-range>
|
|
2920
2906
|
const range = context.peekRange();
|
|
2921
2907
|
const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
2922
|
-
if (filteredRange.length === 0) {
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
}
|
|
2908
|
+
// if (filteredRange.length === 0) {
|
|
2909
|
+
// return {
|
|
2910
|
+
// success: false,
|
|
2911
|
+
// valid: true,
|
|
2912
|
+
// token: context.peek(),
|
|
2913
|
+
// context,
|
|
2914
|
+
// syntaxToken: property,
|
|
2915
|
+
// errors: [],
|
|
2916
|
+
// };
|
|
2917
|
+
// }
|
|
2932
2918
|
if (filteredRange.length === 1) {
|
|
2933
2919
|
success =
|
|
2934
2920
|
filteredRange[0].typ === EnumToken.IdenTokenType ||
|
|
@@ -2943,29 +2929,31 @@ function matchProperty(property, context, options) {
|
|
|
2943
2929
|
errors: [],
|
|
2944
2930
|
};
|
|
2945
2931
|
}
|
|
2946
|
-
if (
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2932
|
+
// if (
|
|
2933
|
+
// filteredRange[1]?.typ === EnumToken.ColonTokenType ||
|
|
2934
|
+
// filteredRange[1]?.typ === EnumToken.DelimTokenType
|
|
2935
|
+
// ) {
|
|
2936
|
+
// const result = isDeclarationValue(filteredRange.slice(2));
|
|
2937
|
+
// if (result.success) {
|
|
2938
|
+
// context.update(filteredRange.at(-1)!);
|
|
2939
|
+
// return {
|
|
2940
|
+
// success: true,
|
|
2941
|
+
// valid: true,
|
|
2942
|
+
// token: filteredRange.at(-1)!,
|
|
2943
|
+
// context,
|
|
2944
|
+
// syntaxToken: property,
|
|
2945
|
+
// errors: [],
|
|
2946
|
+
// };
|
|
2947
|
+
// }
|
|
2948
|
+
// return {
|
|
2949
|
+
// success: false,
|
|
2950
|
+
// valid: false,
|
|
2951
|
+
// token: context.peek(),
|
|
2952
|
+
// context,
|
|
2953
|
+
// syntaxToken: property,
|
|
2954
|
+
// errors: result.errors,
|
|
2955
|
+
// };
|
|
2956
|
+
// }
|
|
2969
2957
|
return {
|
|
2970
2958
|
success: false,
|
|
2971
2959
|
valid: false,
|
|
@@ -2977,12 +2965,12 @@ function matchProperty(property, context, options) {
|
|
|
2977
2965
|
}
|
|
2978
2966
|
case "url": {
|
|
2979
2967
|
const token = context.peek();
|
|
2980
|
-
if (token == null) {
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
}
|
|
2968
|
+
// if (token == null) {
|
|
2969
|
+
// success = false;
|
|
2970
|
+
// break;
|
|
2971
|
+
// }
|
|
2984
2972
|
let l;
|
|
2985
|
-
if (token
|
|
2973
|
+
if (token?.typ == EnumToken.UrlFunctionTokenDefType) {
|
|
2986
2974
|
l = 0;
|
|
2987
2975
|
let token;
|
|
2988
2976
|
while ((token = context.peek(++l))) {
|
|
@@ -2994,11 +2982,11 @@ function matchProperty(property, context, options) {
|
|
|
2994
2982
|
(token.typ == EnumToken.StringTokenType ||
|
|
2995
2983
|
token.typ == EnumToken.IdenTokenType ||
|
|
2996
2984
|
token.typ == EnumToken.UrlTokenTokenType)) {
|
|
2997
|
-
if (token.typ === EnumToken.IdenTokenType) {
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
}
|
|
2985
|
+
// if (token.typ === EnumToken.IdenTokenType) {
|
|
2986
|
+
// while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
|
|
2987
|
+
// l++;
|
|
2988
|
+
// }
|
|
2989
|
+
// }
|
|
3002
2990
|
while ((token = context.peek(++l))) {
|
|
3003
2991
|
if (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType) {
|
|
3004
2992
|
break;
|
|
@@ -3085,7 +3073,7 @@ function matchRepeatableSyntax(syntax, context, options) {
|
|
|
3085
3073
|
let result = null;
|
|
3086
3074
|
let tmpResult;
|
|
3087
3075
|
let success = !!isRepeatable;
|
|
3088
|
-
let index = context.index;
|
|
3076
|
+
// let index: number = context.index;
|
|
3089
3077
|
do {
|
|
3090
3078
|
tmpResult = matchSyntax([rest], context.slice(), options);
|
|
3091
3079
|
if (tmpResult.success) {
|
|
@@ -3095,16 +3083,15 @@ function matchRepeatableSyntax(syntax, context, options) {
|
|
|
3095
3083
|
context.end();
|
|
3096
3084
|
break;
|
|
3097
3085
|
}
|
|
3098
|
-
if (context.current() === tmpResult.context.current()) {
|
|
3099
|
-
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
index = context.index;
|
|
3086
|
+
// if (context.current() === tmpResult.context.current()) {
|
|
3087
|
+
// context.next();
|
|
3088
|
+
// } else {
|
|
3089
|
+
context.update(result.context.current());
|
|
3090
|
+
// }
|
|
3091
|
+
// if (index === context.index) {
|
|
3092
|
+
// break;
|
|
3093
|
+
// }
|
|
3094
|
+
// index = context.index;
|
|
3108
3095
|
}
|
|
3109
3096
|
} while (tmpResult.success && !context.done());
|
|
3110
3097
|
return {
|
|
@@ -3117,4 +3104,4 @@ function matchRepeatableSyntax(syntax, context, options) {
|
|
|
3117
3104
|
};
|
|
3118
3105
|
}
|
|
3119
3106
|
|
|
3120
|
-
export { createValidationContext, funcTypes, getMFInfo,
|
|
3107
|
+
export { createValidationContext, funcTypes, getMFInfo, isMFValue, matchAllSyntaxes, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
|