@tbela99/css-parser 1.4.3 → 1.4.4
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 +192 -2
- package/README.md +69 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +17226 -15037
- package/dist/index.cjs +16889 -14705
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +22 -16
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +528 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EnumToken, ColorType } from '../ast/types.js';
|
|
2
2
|
import { definedPropertySettings, wildCardFuncs, whenElseFunc, transformFunctions, mathFuncs, colorsFunc, timingFunc, supportFunc, generalEnclosedFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc } from '../syntax/constants.js';
|
|
3
|
-
import { isDigit, isPseudo, isIdent,
|
|
3
|
+
import { isDigit, isPseudo, isIdent, isWhiteSpace, isNumber, isNewLine, isHexColor, isHash, isPercentage, parseDimension } from '../syntax/syntax.js';
|
|
4
|
+
import { equalsIgnoreCase } from './utils/text.js';
|
|
4
5
|
|
|
5
6
|
const SymbolsMapTokens = {
|
|
6
7
|
"+": EnumToken.Plus,
|
|
@@ -140,6 +141,10 @@ function consumeString(quoteStr, buffer, parseInfo) {
|
|
|
140
141
|
buffer += quoteStr;
|
|
141
142
|
while ((value = parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset + 1))) {
|
|
142
143
|
if (value == "\\") {
|
|
144
|
+
if ("\\" == parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset + 2)) {
|
|
145
|
+
buffer += next(parseInfo, 2);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
143
148
|
const sequence = peek(parseInfo, 6);
|
|
144
149
|
let escapeSequence = "";
|
|
145
150
|
let codepoint;
|
|
@@ -205,6 +210,51 @@ function getTokenType(val, hint) {
|
|
|
205
210
|
let token = null;
|
|
206
211
|
let dimension;
|
|
207
212
|
if (hint != null) {
|
|
213
|
+
let searchArray = null;
|
|
214
|
+
switch (hint) {
|
|
215
|
+
case EnumToken.TransformFunctionTokenDefType:
|
|
216
|
+
searchArray = transformFunctions;
|
|
217
|
+
break;
|
|
218
|
+
case EnumToken.ColorFunctionTokenDefType:
|
|
219
|
+
searchArray = colorsFunc;
|
|
220
|
+
break;
|
|
221
|
+
case EnumToken.ContainerFunctionTokenDefType:
|
|
222
|
+
searchArray = containerFunc;
|
|
223
|
+
break;
|
|
224
|
+
case EnumToken.UrlFunctionTokenDefType:
|
|
225
|
+
searchArray = urlFunc;
|
|
226
|
+
break;
|
|
227
|
+
case EnumToken.GridTemplateFuncTokenDefType:
|
|
228
|
+
searchArray = gridTemplateFunc;
|
|
229
|
+
break;
|
|
230
|
+
case EnumToken.ImageFunctionTokenDefType:
|
|
231
|
+
searchArray = imageFunc;
|
|
232
|
+
break;
|
|
233
|
+
case EnumToken.TimelineFunctionTokenDefType:
|
|
234
|
+
searchArray = timelineFunc;
|
|
235
|
+
break;
|
|
236
|
+
case EnumToken.GeneralEnclosedFunctionTokenDefType:
|
|
237
|
+
searchArray = generalEnclosedFunc;
|
|
238
|
+
break;
|
|
239
|
+
case EnumToken.SupportsFunctionTokenDefType:
|
|
240
|
+
searchArray = supportFunc;
|
|
241
|
+
break;
|
|
242
|
+
case EnumToken.TimingFunctionTokenDefType:
|
|
243
|
+
searchArray = timingFunc;
|
|
244
|
+
break;
|
|
245
|
+
case EnumToken.MathFunctionTokenDefType:
|
|
246
|
+
searchArray = mathFuncs;
|
|
247
|
+
break;
|
|
248
|
+
case EnumToken.WhenElseFunctionTokenDefType:
|
|
249
|
+
searchArray = whenElseFunc;
|
|
250
|
+
break;
|
|
251
|
+
case EnumToken.WildCardFunctionTokenDefType:
|
|
252
|
+
searchArray = wildCardFuncs;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
if (searchArray != null) {
|
|
256
|
+
val = searchArray.find((v) => equalsIgnoreCase(v, val));
|
|
257
|
+
}
|
|
208
258
|
token = hintsEnum.has(hint) ? { typ: hint } : { typ: hint, val };
|
|
209
259
|
}
|
|
210
260
|
else {
|
|
@@ -334,7 +384,7 @@ function next(parseInfo, count = 1) {
|
|
|
334
384
|
return char;
|
|
335
385
|
}
|
|
336
386
|
/**
|
|
337
|
-
*
|
|
387
|
+
* Tokenize css string
|
|
338
388
|
* @param parseInfo
|
|
339
389
|
* @param yieldEOFToken
|
|
340
390
|
*/
|
|
@@ -408,10 +458,66 @@ function tokenize(parseInfo, yieldEOFToken = true) {
|
|
|
408
458
|
break;
|
|
409
459
|
}
|
|
410
460
|
else if (isIdent(buffer)) {
|
|
411
|
-
|
|
461
|
+
const hint = buffer.startsWith("--")
|
|
412
462
|
? EnumToken.CustomFunctionTokenDefType
|
|
413
|
-
: (SymbolsMapTokens[buffer.toLowerCase() + "("] ?? EnumToken.FunctionTokenDefType)
|
|
463
|
+
: (SymbolsMapTokens[buffer.toLowerCase() + "("] ?? EnumToken.FunctionTokenDefType);
|
|
464
|
+
result.push(yieldResult(buffer, parseInfo, hint));
|
|
414
465
|
buffer = "";
|
|
466
|
+
if (hint === EnumToken.UrlFunctionTokenDefType) {
|
|
467
|
+
value = peek(parseInfo);
|
|
468
|
+
// consume an <url>
|
|
469
|
+
while (isWhiteSpace((charCode = value.charCodeAt(0)))) {
|
|
470
|
+
buffer += next(parseInfo);
|
|
471
|
+
value = peek(parseInfo);
|
|
472
|
+
charCode = value.charCodeAt(0);
|
|
473
|
+
if (value === "/" && match(parseInfo, "/*")) {
|
|
474
|
+
if (buffer.length > 0) {
|
|
475
|
+
result.push(yieldResult(buffer, parseInfo));
|
|
476
|
+
buffer = "";
|
|
477
|
+
}
|
|
478
|
+
buffer += next(parseInfo, 2);
|
|
479
|
+
while ((value = next(parseInfo))) {
|
|
480
|
+
if (value == "*") {
|
|
481
|
+
buffer += value;
|
|
482
|
+
if (match(parseInfo, "/")) {
|
|
483
|
+
result.push(yieldResult(buffer + next(parseInfo), parseInfo, EnumToken.CommentTokenType));
|
|
484
|
+
buffer = "";
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
buffer += value;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (buffer.length > 0) {
|
|
493
|
+
result.push(yieldResult(buffer, parseInfo, EnumToken.BadCommentTokenType));
|
|
494
|
+
buffer = "";
|
|
495
|
+
}
|
|
496
|
+
value = peek(parseInfo);
|
|
497
|
+
charCode = value.charCodeAt(0);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (buffer.length > 0) {
|
|
501
|
+
result.push(yieldResult(buffer, parseInfo, EnumToken.WhitespaceTokenType));
|
|
502
|
+
buffer = "";
|
|
503
|
+
}
|
|
504
|
+
if (value === ")" || value === '"' || value === "'") {
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
do {
|
|
508
|
+
buffer += next(parseInfo);
|
|
509
|
+
value = peek(parseInfo);
|
|
510
|
+
charCode = value.charCodeAt(0);
|
|
511
|
+
} while (value !== ")" &&
|
|
512
|
+
!isWhiteSpace(charCode) &&
|
|
513
|
+
!(value === "/" && match(parseInfo, "/*")));
|
|
514
|
+
if (buffer.length > 0) {
|
|
515
|
+
result.push(yieldResult(buffer, parseInfo, peek(parseInfo) === ""
|
|
516
|
+
? EnumToken.BadUrlTokenType
|
|
517
|
+
: EnumToken.UrlTokenTokenType));
|
|
518
|
+
buffer = "";
|
|
519
|
+
}
|
|
520
|
+
}
|
|
415
521
|
break;
|
|
416
522
|
}
|
|
417
523
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* convert angle to degrees
|
|
3
|
+
* @param angle
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
function toDegrees(angle) {
|
|
7
|
+
switch (angle.unit) {
|
|
8
|
+
// case "deg":
|
|
9
|
+
// return angle;
|
|
10
|
+
case "rad":
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
angle.val *= 180 / Math.PI;
|
|
13
|
+
angle.unit = "deg";
|
|
14
|
+
return angle;
|
|
15
|
+
case "grad":
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
angle.val *= 0.9;
|
|
18
|
+
angle.unit = "deg";
|
|
19
|
+
return angle;
|
|
20
|
+
case "turn":
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
angle.val *= 360;
|
|
23
|
+
angle.unit = "deg";
|
|
24
|
+
return angle;
|
|
25
|
+
}
|
|
26
|
+
return angle;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { toDegrees };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
2
|
import { tokensfuncDefMap, mFLT, mFGT, definedPropertySettings } from '../../syntax/constants.js';
|
|
3
|
-
import {
|
|
3
|
+
import { matchAllSyntaxes, createValidationContext, trimArray, isStyleRangeValue } from '../../validation/match.js';
|
|
4
4
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
5
5
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
6
6
|
import { parseColor } from '../../syntax/syntax.js';
|
|
@@ -27,7 +27,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
27
27
|
}
|
|
28
28
|
return acc;
|
|
29
29
|
}, [[]]);
|
|
30
|
-
const result =
|
|
30
|
+
const result = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
31
31
|
if (!result.success) {
|
|
32
32
|
errors.push(...result.errors);
|
|
33
33
|
return {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
2
|
-
import { trimArray,
|
|
2
|
+
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
3
3
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
4
4
|
|
|
5
5
|
function parseAtRuleFontFeatureValues(stream, context, options = {}) {
|
|
6
6
|
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
|
|
7
7
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
8
8
|
trimArray(stream);
|
|
9
|
-
const { success, errors} =
|
|
9
|
+
const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
10
10
|
return { success, errors };
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -2,7 +2,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
2
2
|
import { tokensfuncDefMap } from '../../syntax/constants.js';
|
|
3
3
|
import { equalsIgnoreCase } from './text.js';
|
|
4
4
|
|
|
5
|
-
function matchGenericSyntax(
|
|
5
|
+
function matchGenericSyntax(stream) {
|
|
6
6
|
const stack = [];
|
|
7
7
|
let i = 0;
|
|
8
8
|
let success = true;
|
|
@@ -2,7 +2,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
2
2
|
import { evaluate } from '../../ast/math/expression.js';
|
|
3
3
|
import { gcd } from '../../ast/math/math.js';
|
|
4
4
|
import { tokensfuncDefMap, mediaTypes, definedPropertySettings, mFLT, mFGT } from '../../syntax/constants.js';
|
|
5
|
-
import { trimArray,
|
|
5
|
+
import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue, isMFName } from '../../validation/match.js';
|
|
6
6
|
import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
|
|
7
7
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
8
8
|
|
|
@@ -222,7 +222,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
222
222
|
value: { ...tokens[index].loc, end: stream[i].loc.end },
|
|
223
223
|
});
|
|
224
224
|
tokens.length = index + 1;
|
|
225
|
-
const result =
|
|
225
|
+
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
|
|
226
226
|
stack.pop();
|
|
227
227
|
scopes.pop();
|
|
228
228
|
currentScope = scopes.at(-1);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { EnumToken, ValidationLevel } from '../../ast/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { renderValue } from '../../renderer/render.js';
|
|
3
3
|
import { tokensfuncDefMap, trimTokenSpace, tokensfuncSet, definedPropertySettings } from '../../syntax/constants.js';
|
|
4
|
-
import { getParsedSyntax } from '../../validation/config.js';
|
|
5
|
-
import {
|
|
4
|
+
import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
|
|
5
|
+
import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
|
|
6
6
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
7
7
|
import { parseDeclaration } from './declaration.js';
|
|
8
8
|
import { equalsIgnoreCase } from './text.js';
|
|
9
|
+
import { pseudoElements } from '../../syntax/syntax.js';
|
|
9
10
|
|
|
10
11
|
function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
11
12
|
const tokens = [];
|
|
@@ -14,6 +15,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
14
15
|
let success = true;
|
|
15
16
|
let expectAndOr = false;
|
|
16
17
|
let scope = new Set();
|
|
18
|
+
let val;
|
|
17
19
|
const errors = [];
|
|
18
20
|
const scopes = [scope];
|
|
19
21
|
const trimWhiteSpace = new Set([
|
|
@@ -33,7 +35,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
33
35
|
stream[i]?.typ !== EnumToken.StartParensTokenType &&
|
|
34
36
|
!(stream[i]?.typ === EnumToken.IdenTokenType && "not" === stream[i]?.val.toLowerCase())) {
|
|
35
37
|
return {
|
|
36
|
-
success,
|
|
38
|
+
success: false,
|
|
37
39
|
errors: [
|
|
38
40
|
{
|
|
39
41
|
action: "drop",
|
|
@@ -45,6 +47,55 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
45
47
|
}
|
|
46
48
|
for (; i < stream.length; i++) {
|
|
47
49
|
tokens.push(stream[i]);
|
|
50
|
+
if (stream[i].typ == EnumToken.ColonTokenType) {
|
|
51
|
+
if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
|
|
52
|
+
Object.assign(stream[i], {
|
|
53
|
+
typ: EnumToken.PseudoElementTokenType,
|
|
54
|
+
val: ":" + stream[i + 1].val,
|
|
55
|
+
});
|
|
56
|
+
stream[i].loc.end = stream[i + 1].loc.end;
|
|
57
|
+
stream.splice(i + 1, 1);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
|
|
61
|
+
val = ":" + stream[i + 1].val;
|
|
62
|
+
Object.assign(stream[i], {
|
|
63
|
+
typ: val + "()" in getSyntaxConfig().selectors
|
|
64
|
+
? EnumToken.PseudoClassFunctionTokenDefType
|
|
65
|
+
: stream[i + 1].typ,
|
|
66
|
+
val,
|
|
67
|
+
});
|
|
68
|
+
stack.push(stream[i]);
|
|
69
|
+
stream[i].loc.end = stream[i + 1].loc.end;
|
|
70
|
+
stream.splice(i + 1, 1);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (stream[i].typ == EnumToken.DoubleColonTokenType) {
|
|
75
|
+
val = ":" + stream[i + 1].val;
|
|
76
|
+
if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
|
|
77
|
+
Object.assign(stream[i], {
|
|
78
|
+
typ: EnumToken.PseudoClassTokenType,
|
|
79
|
+
val: (pseudoElements.includes(val) ? "" : ":") + val,
|
|
80
|
+
});
|
|
81
|
+
stream[i].loc.end = stream[i + 1].loc.end;
|
|
82
|
+
stream.splice(i + 1, 1);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
|
|
86
|
+
val = "::" + stream[i + 1].val;
|
|
87
|
+
Object.assign(stream[i], {
|
|
88
|
+
typ: val + "()" in getSyntaxConfig().selectors
|
|
89
|
+
? EnumToken.PseudoClassFunctionTokenDefType
|
|
90
|
+
: EnumToken.FunctionTokenDefType,
|
|
91
|
+
val,
|
|
92
|
+
});
|
|
93
|
+
stack.push(stream[i]);
|
|
94
|
+
stream[i].loc.end = stream[i + 1].loc.end;
|
|
95
|
+
stream.splice(i + 1, 1);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
48
99
|
if (trimWhiteSpace.has(stream[i].typ)) {
|
|
49
100
|
if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
|
|
50
101
|
tokens.splice(tokens.length - 2, 1);
|
|
@@ -114,7 +165,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
114
165
|
tokens.splice(index + 1, 1);
|
|
115
166
|
stack.pop();
|
|
116
167
|
const index2 = tokens.indexOf(stack[stack.length - 1]);
|
|
117
|
-
const result =
|
|
168
|
+
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index2].val + "()")[0]?.chi, createValidationContext(tokens.slice(index2 + 1, -1)), options);
|
|
118
169
|
if (!result.success) {
|
|
119
170
|
return {
|
|
120
171
|
success: false,
|
|
@@ -209,13 +260,27 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
209
260
|
...definedPropertySettings,
|
|
210
261
|
value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
|
|
211
262
|
});
|
|
263
|
+
if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
|
|
264
|
+
// not a declaration
|
|
265
|
+
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
|
|
266
|
+
if (!result.success) {
|
|
267
|
+
return {
|
|
268
|
+
success: false,
|
|
269
|
+
errors: result.errors,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
stack.pop();
|
|
273
|
+
tokens.pop();
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
212
276
|
//
|
|
213
277
|
let k = stack.length - 1;
|
|
214
278
|
while (tokensfuncDefMap.has(stack[k]?.typ)) {
|
|
215
279
|
k--;
|
|
216
280
|
}
|
|
217
281
|
if (stack[k]?.typ !== EnumToken.ColonTokenType) {
|
|
218
|
-
if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
|
|
282
|
+
if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
|
|
283
|
+
!equalsIgnoreCase("env", tokens[index].val)) {
|
|
219
284
|
errors.push({
|
|
220
285
|
action: "ignore",
|
|
221
286
|
node: tokens[index],
|
|
@@ -224,7 +289,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
224
289
|
}
|
|
225
290
|
else {
|
|
226
291
|
// not a declaration
|
|
227
|
-
const result =
|
|
292
|
+
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
|
|
228
293
|
if (!result.valid) {
|
|
229
294
|
errors.push(...result.errors, {
|
|
230
295
|
action: "ignore",
|
|
@@ -353,7 +418,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
353
418
|
{
|
|
354
419
|
action: "drop",
|
|
355
420
|
node: stack.at(-1),
|
|
356
|
-
message: `unmatched token '${
|
|
421
|
+
message: `unmatched token '${renderValue(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
|
|
357
422
|
},
|
|
358
423
|
],
|
|
359
424
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { renderValue } from '../../renderer/render.js';
|
|
3
3
|
import { trimArray } from '../../validation/match.js';
|
|
4
4
|
import { tokensfuncDefMap, definedPropertySettings, tokensfuncSet } from '../../syntax/constants.js';
|
|
5
5
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
@@ -350,7 +350,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
350
350
|
{
|
|
351
351
|
action: "drop",
|
|
352
352
|
node: stack.at(-1),
|
|
353
|
-
message: `unmatched token '${
|
|
353
|
+
message: `unmatched token '${renderValue(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
|
|
354
354
|
},
|
|
355
355
|
],
|
|
356
356
|
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
2
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
3
3
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
4
|
-
import { trimArray,
|
|
4
|
+
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
5
5
|
|
|
6
|
-
// export const mediaQueryConditionEnum: Set<EnumToken> = new Set([
|
|
7
|
-
// EnumToken.ParensTokenType,
|
|
8
|
-
// EnumToken.IdenTokenType,
|
|
9
|
-
// EnumToken.MediaQueryConditionTokenType,
|
|
10
|
-
// EnumToken.MediaQueryUnaryFeatureTokenType,
|
|
11
|
-
// ]);
|
|
12
6
|
function matchAtRuleSyntax(atRule, stream, options) {
|
|
13
7
|
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + atRule.nam);
|
|
14
8
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
@@ -30,7 +24,7 @@ function matchAtRuleSyntax(atRule, stream, options) {
|
|
|
30
24
|
}
|
|
31
25
|
return { success: true, errors: [] };
|
|
32
26
|
}
|
|
33
|
-
const { success, errors} =
|
|
27
|
+
const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
34
28
|
return { success, errors };
|
|
35
29
|
}
|
|
36
30
|
|