@tbela99/css-parser 1.0.0 → 1.1.0
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 +265 -0
- package/README.md +16 -11
- package/dist/index-umd-web.js +3613 -1829
- package/dist/index.cjs +3611 -1827
- package/dist/index.d.ts +160 -50
- package/dist/lib/ast/expand.js +2 -1
- package/dist/lib/ast/features/calc.js +12 -1
- package/dist/lib/ast/features/inlinecssvariables.js +47 -24
- package/dist/lib/ast/features/prefix.js +117 -86
- package/dist/lib/ast/features/shorthand.js +29 -6
- package/dist/lib/ast/features/transform.js +10 -3
- package/dist/lib/ast/features/type.js +7 -0
- package/dist/lib/ast/math/expression.js +7 -1
- package/dist/lib/ast/math/math.js +6 -0
- package/dist/lib/ast/minify.js +165 -77
- package/dist/lib/ast/transform/compute.js +1 -0
- package/dist/lib/ast/transform/matrix.js +1 -0
- package/dist/lib/ast/types.js +17 -15
- package/dist/lib/ast/walk.js +33 -7
- package/dist/lib/fs/resolve.js +10 -0
- package/dist/lib/parser/declaration/list.js +48 -45
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/declaration/set.js +2 -1
- package/dist/lib/parser/parse.js +364 -276
- package/dist/lib/parser/tokenize.js +147 -72
- package/dist/lib/parser/utils/declaration.js +4 -3
- package/dist/lib/parser/utils/type.js +2 -1
- package/dist/lib/renderer/color/a98rgb.js +2 -1
- package/dist/lib/renderer/color/color-mix.js +10 -7
- package/dist/lib/renderer/color/color.js +171 -153
- package/dist/lib/renderer/color/hex.js +2 -1
- package/dist/lib/renderer/color/hsl.js +2 -1
- package/dist/lib/renderer/color/hwb.js +2 -1
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/lch.js +2 -1
- package/dist/lib/renderer/color/oklab.js +2 -1
- package/dist/lib/renderer/color/oklch.js +2 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/rec2020.js +2 -1
- package/dist/lib/renderer/color/relativecolor.js +17 -11
- package/dist/lib/renderer/color/rgb.js +4 -3
- package/dist/lib/renderer/color/srgb.js +18 -17
- package/dist/lib/renderer/color/utils/components.js +6 -5
- package/dist/lib/renderer/color/utils/constants.js +47 -3
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +2 -1
- package/dist/lib/renderer/render.js +48 -20
- package/dist/lib/syntax/syntax.js +253 -140
- package/dist/lib/validation/at-rules/container.js +75 -97
- package/dist/lib/validation/at-rules/counter-style.js +9 -8
- package/dist/lib/validation/at-rules/custom-media.js +13 -15
- package/dist/lib/validation/at-rules/document.js +22 -27
- package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
- package/dist/lib/validation/at-rules/import.js +30 -81
- package/dist/lib/validation/at-rules/keyframes.js +18 -22
- package/dist/lib/validation/at-rules/layer.js +5 -5
- package/dist/lib/validation/at-rules/media.js +42 -52
- package/dist/lib/validation/at-rules/namespace.js +19 -23
- package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
- package/dist/lib/validation/at-rules/page.js +8 -7
- package/dist/lib/validation/at-rules/supports.js +73 -82
- package/dist/lib/validation/at-rules/when.js +32 -36
- package/dist/lib/validation/atrule.js +15 -14
- package/dist/lib/validation/config.js +24 -1
- package/dist/lib/validation/config.json.js +563 -63
- package/dist/lib/validation/parser/parse.js +196 -185
- package/dist/lib/validation/parser/types.js +1 -1
- package/dist/lib/validation/selector.js +3 -3
- package/dist/lib/validation/syntax.js +828 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
- package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
- package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
- package/dist/lib/validation/syntaxes/family-name.js +9 -8
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +4 -3
- package/dist/lib/validation/syntaxes/keyframe-selector.js +15 -18
- package/dist/lib/validation/syntaxes/layer-name.js +6 -5
- package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
- package/dist/lib/validation/syntaxes/relative-selector.js +2 -1
- package/dist/lib/validation/syntaxes/url.js +18 -22
- package/dist/lib/validation/utils/list.js +2 -1
- package/dist/lib/validation/utils/whitespace.js +2 -1
- package/dist/node/index.js +4 -2
- package/dist/node/load.js +5 -0
- package/dist/web/index.js +4 -2
- package/dist/web/load.js +5 -0
- package/package.json +12 -11
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
2
|
import '../../ast/minify.js';
|
|
3
3
|
import '../../ast/walk.js';
|
|
4
4
|
import '../../parser/parse.js';
|
|
5
|
+
import '../../parser/tokenize.js';
|
|
6
|
+
import '../../parser/utils/config.js';
|
|
5
7
|
import '../../renderer/color/utils/constants.js';
|
|
6
8
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
-
import '../../parser/utils/config.js';
|
|
8
9
|
import { validateAtRuleMediaQueryList } from './media.js';
|
|
9
10
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
11
|
import { validateLayerName } from '../syntaxes/layer-name.js';
|
|
11
12
|
import '../syntaxes/complex-selector.js';
|
|
12
|
-
import '../
|
|
13
|
-
import '../parser/parse.js';
|
|
13
|
+
import '../syntax.js';
|
|
14
14
|
import '../config.js';
|
|
15
15
|
import { validateAtRuleSupportsConditions } from './supports.js';
|
|
16
16
|
|
|
@@ -18,35 +18,32 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
18
18
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
19
19
|
// @ts-ignore
|
|
20
20
|
return {
|
|
21
|
-
valid:
|
|
22
|
-
|
|
21
|
+
valid: SyntaxValidationResult.Drop,
|
|
22
|
+
context: [],
|
|
23
23
|
node: null,
|
|
24
24
|
syntax: '@' + atRule.nam,
|
|
25
|
-
error: 'expected @import media query list'
|
|
26
|
-
tokens: []
|
|
25
|
+
error: 'expected @import media query list'
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
28
|
if ('chi' in atRule) {
|
|
30
29
|
// @ts-ignore
|
|
31
30
|
return {
|
|
32
|
-
valid:
|
|
33
|
-
|
|
31
|
+
valid: SyntaxValidationResult.Drop,
|
|
32
|
+
context: [],
|
|
34
33
|
node: null,
|
|
35
34
|
syntax: '@' + atRule.nam,
|
|
36
|
-
error: 'unexpected at-rule body'
|
|
37
|
-
tokens: []
|
|
35
|
+
error: 'unexpected at-rule body'
|
|
38
36
|
};
|
|
39
37
|
}
|
|
40
38
|
const tokens = atRule.tokens.filter((t) => ![EnumToken.CommentTokenType].includes(t.typ));
|
|
41
39
|
if (tokens.length == 0) {
|
|
42
40
|
// @ts-ignore
|
|
43
41
|
return {
|
|
44
|
-
valid:
|
|
45
|
-
|
|
42
|
+
valid: SyntaxValidationResult.Drop,
|
|
43
|
+
context: [],
|
|
46
44
|
node: null,
|
|
47
45
|
syntax: '@' + atRule.nam,
|
|
48
|
-
error: 'expected @import media query list'
|
|
49
|
-
tokens: []
|
|
46
|
+
error: 'expected @import media query list'
|
|
50
47
|
};
|
|
51
48
|
}
|
|
52
49
|
if (tokens[0].typ == EnumToken.StringTokenType) {
|
|
@@ -59,12 +56,11 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
59
56
|
if (slice.length != 1 || ![EnumToken.StringTokenType, EnumToken.UrlTokenTokenType].includes(slice[0].typ)) {
|
|
60
57
|
// @ts-ignore
|
|
61
58
|
return {
|
|
62
|
-
valid:
|
|
63
|
-
|
|
59
|
+
valid: SyntaxValidationResult.Drop,
|
|
60
|
+
context: [],
|
|
64
61
|
node: tokens[0],
|
|
65
62
|
syntax: '@' + atRule.nam,
|
|
66
|
-
error: 'invalid url()'
|
|
67
|
-
tokens
|
|
63
|
+
error: 'invalid url()'
|
|
68
64
|
};
|
|
69
65
|
}
|
|
70
66
|
else {
|
|
@@ -73,12 +69,11 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
73
69
|
if (!consumeWhitespace(tokens)) {
|
|
74
70
|
// @ts-ignore
|
|
75
71
|
return {
|
|
76
|
-
valid:
|
|
77
|
-
|
|
72
|
+
valid: SyntaxValidationResult.Drop,
|
|
73
|
+
context: [],
|
|
78
74
|
node: tokens[0],
|
|
79
75
|
syntax: '@' + atRule.nam,
|
|
80
|
-
error: 'expecting whitespace'
|
|
81
|
-
tokens
|
|
76
|
+
error: 'expecting whitespace'
|
|
82
77
|
};
|
|
83
78
|
}
|
|
84
79
|
}
|
|
@@ -89,12 +84,11 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
89
84
|
else {
|
|
90
85
|
// @ts-ignore
|
|
91
86
|
return {
|
|
92
|
-
valid:
|
|
93
|
-
|
|
87
|
+
valid: SyntaxValidationResult.Drop,
|
|
88
|
+
context: [],
|
|
94
89
|
node: tokens[0],
|
|
95
90
|
syntax: '@' + atRule.nam,
|
|
96
|
-
error: 'expecting url() or string'
|
|
97
|
-
tokens
|
|
91
|
+
error: 'expecting url() or string'
|
|
98
92
|
};
|
|
99
93
|
}
|
|
100
94
|
if (tokens.length > 0) {
|
|
@@ -107,12 +101,11 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
107
101
|
if (!consumeWhitespace(tokens)) {
|
|
108
102
|
// @ts-ignore
|
|
109
103
|
return {
|
|
110
|
-
valid:
|
|
111
|
-
|
|
104
|
+
valid: SyntaxValidationResult.Drop,
|
|
105
|
+
context: [],
|
|
112
106
|
node: tokens[0],
|
|
113
107
|
syntax: '@' + atRule.nam,
|
|
114
|
-
error: 'expecting whitespace'
|
|
115
|
-
tokens
|
|
108
|
+
error: 'expecting whitespace'
|
|
116
109
|
};
|
|
117
110
|
}
|
|
118
111
|
}
|
|
@@ -122,7 +115,7 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
122
115
|
// @ts-ignore
|
|
123
116
|
if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
|
|
124
117
|
const result = validateLayerName(tokens[0].chi);
|
|
125
|
-
if (result.valid ==
|
|
118
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
126
119
|
return result;
|
|
127
120
|
}
|
|
128
121
|
tokens.shift();
|
|
@@ -132,7 +125,7 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
132
125
|
// @ts-ignore
|
|
133
126
|
if ('supports'.localeCompare(tokens[0]?.val, undefined, { sensitivity: 'base' }) == 0) {
|
|
134
127
|
const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
|
|
135
|
-
if (result.valid ==
|
|
128
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
136
129
|
return result;
|
|
137
130
|
}
|
|
138
131
|
tokens.shift();
|
|
@@ -141,60 +134,16 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
136
|
}
|
|
144
|
-
// if (tokens.length > 0) {
|
|
145
|
-
//
|
|
146
|
-
// // @ts-ignore
|
|
147
|
-
// if (tokens[0].typ == EnumToken.AtRuleTokenType) {
|
|
148
|
-
//
|
|
149
|
-
// if ((tokens[0] as AstAtRule).nam != 'supports') {
|
|
150
|
-
//
|
|
151
|
-
// // @ts-ignore
|
|
152
|
-
// return {
|
|
153
|
-
// valid: ValidationLevel.Drop,
|
|
154
|
-
// matches: [],
|
|
155
|
-
// node: tokens[0],
|
|
156
|
-
// syntax: '@' + atRule.nam,
|
|
157
|
-
// error: 'expecting @supports or media query list',
|
|
158
|
-
// tokens
|
|
159
|
-
// }
|
|
160
|
-
// }
|
|
161
|
-
//
|
|
162
|
-
// // @ts-ignore
|
|
163
|
-
// const result: ValidationSyntaxResult = validateAtRuleSupports(tokens[0] as AstAtRule, options, atRule);
|
|
164
|
-
//
|
|
165
|
-
// if (result.valid == ValidationLevel.Drop) {
|
|
166
|
-
//
|
|
167
|
-
// return result;
|
|
168
|
-
// }
|
|
169
|
-
//
|
|
170
|
-
// tokens.shift();
|
|
171
|
-
//
|
|
172
|
-
// // @ts-ignore
|
|
173
|
-
// if (!consumeWhitespace(tokens)) {
|
|
174
|
-
//
|
|
175
|
-
// // @ts-ignore
|
|
176
|
-
// return {
|
|
177
|
-
// valid: ValidationLevel.Drop,
|
|
178
|
-
// matches: [],
|
|
179
|
-
// node: tokens[0],
|
|
180
|
-
// syntax: '@' + atRule.nam,
|
|
181
|
-
// error: 'expecting whitespace',
|
|
182
|
-
// tokens
|
|
183
|
-
// }
|
|
184
|
-
// }
|
|
185
|
-
// }
|
|
186
|
-
// }
|
|
187
137
|
if (tokens.length > 0) {
|
|
188
138
|
return validateAtRuleMediaQueryList(tokens, atRule);
|
|
189
139
|
}
|
|
190
140
|
// @ts-ignore
|
|
191
141
|
return {
|
|
192
|
-
valid:
|
|
193
|
-
|
|
142
|
+
valid: SyntaxValidationResult.Valid,
|
|
143
|
+
context: [],
|
|
194
144
|
node: null,
|
|
195
145
|
syntax: '@' + atRule.nam,
|
|
196
|
-
error: ''
|
|
197
|
-
tokens: []
|
|
146
|
+
error: ''
|
|
198
147
|
};
|
|
199
148
|
}
|
|
200
149
|
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
2
|
import '../../ast/minify.js';
|
|
3
3
|
import '../../ast/walk.js';
|
|
4
4
|
import '../../parser/parse.js';
|
|
5
|
+
import '../../parser/tokenize.js';
|
|
6
|
+
import '../../parser/utils/config.js';
|
|
5
7
|
import '../../renderer/color/utils/constants.js';
|
|
6
8
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
-
import '../../parser/utils/config.js';
|
|
8
9
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
10
|
|
|
10
11
|
function validateAtRuleKeyframes(atRule, options, root) {
|
|
11
12
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
12
13
|
// @ts-ignore
|
|
13
14
|
return {
|
|
14
|
-
valid:
|
|
15
|
-
|
|
15
|
+
valid: SyntaxValidationResult.Drop,
|
|
16
|
+
context: [],
|
|
16
17
|
node: atRule,
|
|
17
18
|
syntax: '@keyframes',
|
|
18
|
-
error: 'expecting at-rule prelude'
|
|
19
|
-
tokens: []
|
|
19
|
+
error: 'expecting at-rule prelude'
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
const tokens = atRule.tokens.slice();
|
|
@@ -24,23 +24,21 @@ function validateAtRuleKeyframes(atRule, options, root) {
|
|
|
24
24
|
if (tokens.length == 0) {
|
|
25
25
|
// @ts-ignore
|
|
26
26
|
return {
|
|
27
|
-
valid:
|
|
28
|
-
|
|
27
|
+
valid: SyntaxValidationResult.Drop,
|
|
28
|
+
context: [],
|
|
29
29
|
node: atRule,
|
|
30
30
|
syntax: '@keyframes',
|
|
31
|
-
error: 'expecting at-rule prelude'
|
|
32
|
-
tokens
|
|
31
|
+
error: 'expecting at-rule prelude'
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
if (![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
|
|
36
35
|
// @ts-ignore
|
|
37
36
|
return {
|
|
38
|
-
valid:
|
|
39
|
-
|
|
37
|
+
valid: SyntaxValidationResult.Drop,
|
|
38
|
+
context: [],
|
|
40
39
|
node: atRule,
|
|
41
40
|
syntax: '@keyframes',
|
|
42
|
-
error: 'expecting ident or string token'
|
|
43
|
-
tokens
|
|
41
|
+
error: 'expecting ident or string token'
|
|
44
42
|
};
|
|
45
43
|
}
|
|
46
44
|
tokens.shift();
|
|
@@ -48,22 +46,20 @@ function validateAtRuleKeyframes(atRule, options, root) {
|
|
|
48
46
|
if (tokens.length > 0) {
|
|
49
47
|
// @ts-ignore
|
|
50
48
|
return {
|
|
51
|
-
valid:
|
|
52
|
-
|
|
49
|
+
valid: SyntaxValidationResult.Drop,
|
|
50
|
+
context: [],
|
|
53
51
|
node: tokens[0],
|
|
54
52
|
syntax: '@keyframes',
|
|
55
|
-
error: 'unexpected token'
|
|
56
|
-
tokens
|
|
53
|
+
error: 'unexpected token'
|
|
57
54
|
};
|
|
58
55
|
}
|
|
59
56
|
// @ts-ignore
|
|
60
57
|
return {
|
|
61
|
-
valid:
|
|
62
|
-
|
|
58
|
+
valid: SyntaxValidationResult.Valid,
|
|
59
|
+
context: [],
|
|
63
60
|
node: atRule,
|
|
64
61
|
syntax: '@keyframes',
|
|
65
|
-
error: ''
|
|
66
|
-
tokens
|
|
62
|
+
error: ''
|
|
67
63
|
};
|
|
68
64
|
}
|
|
69
65
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxValidationResult } from '../../ast/types.js';
|
|
2
2
|
import '../../ast/minify.js';
|
|
3
3
|
import '../../ast/walk.js';
|
|
4
4
|
import '../../parser/parse.js';
|
|
5
|
+
import '../../parser/tokenize.js';
|
|
6
|
+
import '../../parser/utils/config.js';
|
|
5
7
|
import '../../renderer/color/utils/constants.js';
|
|
6
8
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
-
import '../../parser/utils/config.js';
|
|
8
9
|
import { validateLayerName } from '../syntaxes/layer-name.js';
|
|
9
10
|
import '../syntaxes/complex-selector.js';
|
|
10
|
-
import '../
|
|
11
|
-
import '../parser/parse.js';
|
|
11
|
+
import '../syntax.js';
|
|
12
12
|
import '../config.js';
|
|
13
13
|
|
|
14
14
|
function validateAtRuleLayer(atRule, options, root) {
|
|
@@ -16,7 +16,7 @@ function validateAtRuleLayer(atRule, options, root) {
|
|
|
16
16
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
17
17
|
// @ts-ignore
|
|
18
18
|
return {
|
|
19
|
-
valid:
|
|
19
|
+
valid: SyntaxValidationResult.Valid,
|
|
20
20
|
matches: [],
|
|
21
21
|
node: atRule,
|
|
22
22
|
syntax: '@layer',
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
2
|
import '../../ast/minify.js';
|
|
3
3
|
import '../../ast/walk.js';
|
|
4
4
|
import '../../parser/parse.js';
|
|
5
|
-
import '../../
|
|
6
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
5
|
+
import '../../parser/tokenize.js';
|
|
7
6
|
import '../../parser/utils/config.js';
|
|
7
|
+
import { generalEnclosedFunc } from '../../renderer/color/utils/constants.js';
|
|
8
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
8
9
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
10
|
import { splitTokenList } from '../utils/list.js';
|
|
10
11
|
|
|
@@ -13,8 +14,8 @@ function validateAtRuleMedia(atRule, options, root) {
|
|
|
13
14
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
14
15
|
// @ts-ignore
|
|
15
16
|
return {
|
|
16
|
-
valid:
|
|
17
|
-
|
|
17
|
+
valid: SyntaxValidationResult.Valid,
|
|
18
|
+
context: [],
|
|
18
19
|
node: null,
|
|
19
20
|
syntax: null,
|
|
20
21
|
error: '',
|
|
@@ -26,37 +27,34 @@ function validateAtRuleMedia(atRule, options, root) {
|
|
|
26
27
|
consumeWhitespace(slice);
|
|
27
28
|
if (slice.length == 0) {
|
|
28
29
|
return {
|
|
29
|
-
valid:
|
|
30
|
-
|
|
30
|
+
valid: SyntaxValidationResult.Valid,
|
|
31
|
+
context: [],
|
|
31
32
|
node: atRule,
|
|
32
33
|
syntax: '@media',
|
|
33
|
-
error: ''
|
|
34
|
-
tokens: []
|
|
34
|
+
error: ''
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
result = validateAtRuleMediaQueryList(atRule.tokens, atRule);
|
|
38
|
-
if (result.valid ==
|
|
38
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
39
39
|
return result;
|
|
40
40
|
}
|
|
41
41
|
if (!('chi' in atRule)) {
|
|
42
42
|
// @ts-ignore
|
|
43
43
|
return {
|
|
44
|
-
valid:
|
|
45
|
-
|
|
44
|
+
valid: SyntaxValidationResult.Drop,
|
|
45
|
+
context: [],
|
|
46
46
|
node: atRule,
|
|
47
47
|
syntax: '@media',
|
|
48
|
-
error: 'expected at-rule body'
|
|
49
|
-
tokens: []
|
|
48
|
+
error: 'expected at-rule body'
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
// @ts-ignore
|
|
53
52
|
return {
|
|
54
|
-
valid:
|
|
55
|
-
|
|
53
|
+
valid: SyntaxValidationResult.Valid,
|
|
54
|
+
context: [],
|
|
56
55
|
node: atRule,
|
|
57
56
|
syntax: '@media',
|
|
58
|
-
error: ''
|
|
59
|
-
tokens: []
|
|
57
|
+
error: ''
|
|
60
58
|
};
|
|
61
59
|
}
|
|
62
60
|
function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
@@ -74,12 +72,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
74
72
|
if (tokens.length == 0) {
|
|
75
73
|
// @ts-ignore
|
|
76
74
|
result = {
|
|
77
|
-
valid:
|
|
78
|
-
|
|
75
|
+
valid: SyntaxValidationResult.Drop,
|
|
76
|
+
context: [],
|
|
79
77
|
node: tokens[0] ?? atRule,
|
|
80
78
|
syntax: '@media',
|
|
81
|
-
error: 'unexpected token'
|
|
82
|
-
tokens: []
|
|
79
|
+
error: 'unexpected token'
|
|
83
80
|
};
|
|
84
81
|
continue;
|
|
85
82
|
}
|
|
@@ -92,15 +89,14 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
92
89
|
}
|
|
93
90
|
else {
|
|
94
91
|
result = {
|
|
95
|
-
valid:
|
|
96
|
-
|
|
92
|
+
valid: SyntaxValidationResult.Drop,
|
|
93
|
+
context: [],
|
|
97
94
|
node: tokens[0] ?? atRule,
|
|
98
95
|
syntax: '@media',
|
|
99
|
-
error: 'expecting media feature or media condition'
|
|
100
|
-
tokens: []
|
|
96
|
+
error: 'expecting media feature or media condition'
|
|
101
97
|
};
|
|
102
98
|
}
|
|
103
|
-
if (result.valid ==
|
|
99
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
104
100
|
break;
|
|
105
101
|
}
|
|
106
102
|
result = null;
|
|
@@ -113,12 +109,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
113
109
|
if (previousToken?.typ != EnumToken.ParensTokenType) {
|
|
114
110
|
// @ts-ignore
|
|
115
111
|
result = {
|
|
116
|
-
valid:
|
|
117
|
-
|
|
112
|
+
valid: SyntaxValidationResult.Drop,
|
|
113
|
+
context: [],
|
|
118
114
|
node: tokens[0] ?? atRule,
|
|
119
115
|
syntax: '@media',
|
|
120
|
-
error: 'expected media query list'
|
|
121
|
-
tokens: []
|
|
116
|
+
error: 'expected media query list'
|
|
122
117
|
};
|
|
123
118
|
break;
|
|
124
119
|
}
|
|
@@ -126,12 +121,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
126
121
|
else if (![EnumToken.MediaFeatureOrTokenType, EnumToken.MediaFeatureAndTokenType].includes(tokens[0].typ)) {
|
|
127
122
|
// @ts-ignore
|
|
128
123
|
result = {
|
|
129
|
-
valid:
|
|
130
|
-
|
|
124
|
+
valid: SyntaxValidationResult.Drop,
|
|
125
|
+
context: [],
|
|
131
126
|
node: tokens[0] ?? atRule,
|
|
132
127
|
syntax: '@media',
|
|
133
|
-
error: 'expected and/or'
|
|
134
|
-
tokens: []
|
|
128
|
+
error: 'expected and/or'
|
|
135
129
|
};
|
|
136
130
|
break;
|
|
137
131
|
}
|
|
@@ -141,12 +135,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
141
135
|
if (mediaFeatureType.typ != tokens[0].typ) {
|
|
142
136
|
// @ts-ignore
|
|
143
137
|
result = {
|
|
144
|
-
valid:
|
|
145
|
-
|
|
138
|
+
valid: SyntaxValidationResult.Drop,
|
|
139
|
+
context: [],
|
|
146
140
|
node: tokens[0] ?? atRule,
|
|
147
141
|
syntax: '@media',
|
|
148
|
-
error: 'mixing and/or not allowed at the same level'
|
|
149
|
-
tokens: []
|
|
142
|
+
error: 'mixing and/or not allowed at the same level'
|
|
150
143
|
};
|
|
151
144
|
break;
|
|
152
145
|
}
|
|
@@ -155,12 +148,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
155
148
|
if (tokens.length == 0) {
|
|
156
149
|
// @ts-ignore
|
|
157
150
|
result = {
|
|
158
|
-
valid:
|
|
159
|
-
|
|
151
|
+
valid: SyntaxValidationResult.Drop,
|
|
152
|
+
context: [],
|
|
160
153
|
node: tokens[0] ?? atRule,
|
|
161
154
|
syntax: '@media',
|
|
162
|
-
error: 'expected media-condition'
|
|
163
|
-
tokens: []
|
|
155
|
+
error: 'expected media-condition'
|
|
164
156
|
};
|
|
165
157
|
break;
|
|
166
158
|
}
|
|
@@ -175,12 +167,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
175
167
|
}
|
|
176
168
|
if (matched.length == 0) {
|
|
177
169
|
return {
|
|
178
|
-
valid:
|
|
179
|
-
|
|
170
|
+
valid: SyntaxValidationResult.Drop,
|
|
171
|
+
context: [],
|
|
180
172
|
node: atRule,
|
|
181
173
|
syntax: '@media',
|
|
182
|
-
error: 'expected media query list'
|
|
183
|
-
tokens: []
|
|
174
|
+
error: 'expected media query list'
|
|
184
175
|
};
|
|
185
176
|
}
|
|
186
177
|
tokenList.length = 0;
|
|
@@ -200,12 +191,11 @@ function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
|
200
191
|
}
|
|
201
192
|
// @ts-ignore
|
|
202
193
|
return {
|
|
203
|
-
valid:
|
|
204
|
-
|
|
194
|
+
valid: SyntaxValidationResult.Valid,
|
|
195
|
+
context: [],
|
|
205
196
|
node: atRule,
|
|
206
197
|
syntax: '@media',
|
|
207
|
-
error: ''
|
|
208
|
-
tokens: []
|
|
198
|
+
error: ''
|
|
209
199
|
};
|
|
210
200
|
}
|
|
211
201
|
function validateCustomMediaCondition(token, atRule) {
|
|
@@ -225,7 +215,7 @@ function validateMediaCondition(token, atRule) {
|
|
|
225
215
|
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
226
216
|
return validateMediaCondition(token.val, atRule);
|
|
227
217
|
}
|
|
228
|
-
if (token.typ != EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == EnumToken.FunctionTokenType &&
|
|
218
|
+
if (token.typ != EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == EnumToken.FunctionTokenType && generalEnclosedFunc.includes(token.val))) {
|
|
229
219
|
return false;
|
|
230
220
|
}
|
|
231
221
|
const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
2
|
import '../../ast/minify.js';
|
|
3
3
|
import '../../ast/walk.js';
|
|
4
4
|
import '../../parser/parse.js';
|
|
5
|
+
import '../../parser/tokenize.js';
|
|
6
|
+
import '../../parser/utils/config.js';
|
|
5
7
|
import '../../renderer/color/utils/constants.js';
|
|
6
8
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
7
|
-
import '../../parser/utils/config.js';
|
|
8
9
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
10
|
import { validateURL } from '../syntaxes/url.js';
|
|
10
11
|
|
|
@@ -12,23 +13,21 @@ function validateAtRuleNamespace(atRule, options, root) {
|
|
|
12
13
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
13
14
|
// @ts-ignore
|
|
14
15
|
return {
|
|
15
|
-
valid:
|
|
16
|
-
|
|
16
|
+
valid: SyntaxValidationResult.Drop,
|
|
17
|
+
context: [],
|
|
17
18
|
node: atRule,
|
|
18
19
|
syntax: '@namespace',
|
|
19
|
-
error: 'expected at-rule prelude'
|
|
20
|
-
tokens: []
|
|
20
|
+
error: 'expected at-rule prelude'
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
if ('chi' in atRule) {
|
|
24
24
|
// @ts-ignore
|
|
25
25
|
return {
|
|
26
|
-
valid:
|
|
27
|
-
|
|
26
|
+
valid: SyntaxValidationResult.Drop,
|
|
27
|
+
context: [],
|
|
28
28
|
node: atRule,
|
|
29
29
|
syntax: '@namespace',
|
|
30
|
-
error: 'unexpected at-rule body'
|
|
31
|
-
tokens: []
|
|
30
|
+
error: 'unexpected at-rule body'
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
33
|
const tokens = atRule.tokens.slice();
|
|
@@ -40,17 +39,16 @@ function validateAtRuleNamespace(atRule, options, root) {
|
|
|
40
39
|
if (tokens.length == 0) {
|
|
41
40
|
// @ts-ignore
|
|
42
41
|
return {
|
|
43
|
-
valid:
|
|
44
|
-
|
|
42
|
+
valid: SyntaxValidationResult.Drop,
|
|
43
|
+
context: [],
|
|
45
44
|
node: atRule,
|
|
46
45
|
syntax: '@namespace',
|
|
47
|
-
error: 'expected string or url()'
|
|
48
|
-
tokens
|
|
46
|
+
error: 'expected string or url()'
|
|
49
47
|
};
|
|
50
48
|
}
|
|
51
49
|
if (tokens[0].typ != EnumToken.StringTokenType) {
|
|
52
50
|
const result = validateURL(tokens[0]);
|
|
53
|
-
if (result.valid !=
|
|
51
|
+
if (result.valid != SyntaxValidationResult.Valid) {
|
|
54
52
|
return result;
|
|
55
53
|
}
|
|
56
54
|
tokens.shift();
|
|
@@ -63,22 +61,20 @@ function validateAtRuleNamespace(atRule, options, root) {
|
|
|
63
61
|
if (tokens.length > 0) {
|
|
64
62
|
// @ts-ignore
|
|
65
63
|
return {
|
|
66
|
-
valid:
|
|
67
|
-
|
|
64
|
+
valid: SyntaxValidationResult.Drop,
|
|
65
|
+
context: [],
|
|
68
66
|
node: tokens[0],
|
|
69
67
|
syntax: '@namespace',
|
|
70
|
-
error: 'unexpected token'
|
|
71
|
-
tokens
|
|
68
|
+
error: 'unexpected token'
|
|
72
69
|
};
|
|
73
70
|
}
|
|
74
71
|
// @ts-ignore
|
|
75
72
|
return {
|
|
76
|
-
valid:
|
|
77
|
-
|
|
73
|
+
valid: SyntaxValidationResult.Valid,
|
|
74
|
+
context: [],
|
|
78
75
|
node: atRule,
|
|
79
76
|
syntax: '@namespace',
|
|
80
|
-
error: ''
|
|
81
|
-
tokens
|
|
77
|
+
error: ''
|
|
82
78
|
};
|
|
83
79
|
}
|
|
84
80
|
|