@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,10 +1,11 @@
|
|
|
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 { validateSelector } from './selector.js';
|
|
9
10
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
11
|
import { splitTokenList } from '../utils/list.js';
|
|
@@ -14,31 +15,29 @@ function validateComplexSelectorList(tokens, root, options) {
|
|
|
14
15
|
consumeWhitespace(tokens);
|
|
15
16
|
if (tokens.length == 0) {
|
|
16
17
|
return {
|
|
17
|
-
valid:
|
|
18
|
-
|
|
18
|
+
valid: SyntaxValidationResult.Drop,
|
|
19
|
+
context: [],
|
|
19
20
|
// @ts-ignore
|
|
20
21
|
node: root,
|
|
21
22
|
syntax: null,
|
|
22
|
-
error: 'expecting complex selector list'
|
|
23
|
-
tokens
|
|
23
|
+
error: 'expecting complex selector list'
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
let result = null;
|
|
27
27
|
for (const t of splitTokenList(tokens)) {
|
|
28
28
|
result = validateSelector(t, root, options);
|
|
29
|
-
if (result.valid ==
|
|
29
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
30
30
|
return result;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
// @ts-ignore
|
|
34
34
|
return result ?? {
|
|
35
|
-
valid:
|
|
36
|
-
|
|
35
|
+
valid: SyntaxValidationResult.Drop,
|
|
36
|
+
context: [],
|
|
37
37
|
// @ts-ignore
|
|
38
38
|
node: root,
|
|
39
39
|
syntax: null,
|
|
40
|
-
error: 'expecting complex selector list'
|
|
41
|
-
tokens
|
|
40
|
+
error: 'expecting complex selector list'
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
43
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
2
|
import { splitTokenList } from '../utils/list.js';
|
|
3
|
-
import { EnumToken,
|
|
3
|
+
import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
5
|
import '../../ast/walk.js';
|
|
6
6
|
import '../../parser/parse.js';
|
|
7
|
+
import '../../parser/tokenize.js';
|
|
8
|
+
import '../../parser/utils/config.js';
|
|
7
9
|
import '../../renderer/color/utils/constants.js';
|
|
8
10
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import '../../parser/utils/config.js';
|
|
10
11
|
import { validateCompoundSelector } from './compound-selector.js';
|
|
11
12
|
|
|
12
13
|
const combinatorsTokens = [EnumToken.ChildCombinatorTokenType, EnumToken.ColumnCombinatorTokenType,
|
|
@@ -19,13 +20,12 @@ function validateComplexSelector(tokens, root, options) {
|
|
|
19
20
|
consumeWhitespace(tokens);
|
|
20
21
|
if (tokens.length == 0) {
|
|
21
22
|
return {
|
|
22
|
-
valid:
|
|
23
|
-
|
|
23
|
+
valid: SyntaxValidationResult.Drop,
|
|
24
|
+
context: [],
|
|
24
25
|
// @ts-ignore
|
|
25
26
|
node: root,
|
|
26
27
|
syntax: null,
|
|
27
|
-
error: 'expected selector'
|
|
28
|
-
tokens
|
|
28
|
+
error: 'expected selector'
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
// const config = getSyntaxConfig();
|
|
@@ -35,18 +35,17 @@ function validateComplexSelector(tokens, root, options) {
|
|
|
35
35
|
// const combinators: EnumToken[] = combinatorsTokens.filter((t: EnumToken) => t != EnumToken.DescendantCombinatorTokenType);
|
|
36
36
|
for (const t of splitTokenList(tokens, combinatorsTokens)) {
|
|
37
37
|
result = validateCompoundSelector(t, root, options);
|
|
38
|
-
if (result.valid ==
|
|
38
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
39
39
|
return result;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
// @ts-ignore
|
|
43
43
|
return result ?? {
|
|
44
|
-
valid:
|
|
45
|
-
|
|
44
|
+
valid: SyntaxValidationResult.Drop,
|
|
45
|
+
context: [],
|
|
46
46
|
node: root,
|
|
47
47
|
syntax: null,
|
|
48
|
-
error: 'expecting compound-selector'
|
|
49
|
-
tokens
|
|
48
|
+
error: 'expecting compound-selector'
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -1,9 +1,10 @@
|
|
|
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
|
|
5
|
+
import '../../parser/tokenize.js';
|
|
6
6
|
import '../../parser/utils/config.js';
|
|
7
|
+
import { mozExtensions, webkitExtensions } from '../../syntax/syntax.js';
|
|
7
8
|
import '../../renderer/color/utils/constants.js';
|
|
8
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
10
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
@@ -13,8 +14,8 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
13
14
|
if (tokens.length == 0) {
|
|
14
15
|
// @ts-ignore
|
|
15
16
|
return {
|
|
16
|
-
valid:
|
|
17
|
-
|
|
17
|
+
valid: SyntaxValidationResult.Drop,
|
|
18
|
+
context: [],
|
|
18
19
|
// @ts-ignore
|
|
19
20
|
node: root,
|
|
20
21
|
// @ts-ignore
|
|
@@ -33,13 +34,12 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
33
34
|
if (!options?.nestedSelector) {
|
|
34
35
|
// @ts-ignore
|
|
35
36
|
return {
|
|
36
|
-
valid:
|
|
37
|
-
|
|
37
|
+
valid: SyntaxValidationResult.Drop,
|
|
38
|
+
context: [],
|
|
38
39
|
// @ts-ignore
|
|
39
40
|
node: tokens[0],
|
|
40
41
|
syntax: null,
|
|
41
|
-
error: 'nested selector not allowed'
|
|
42
|
-
tokens
|
|
42
|
+
error: 'nested selector not allowed'
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
match++;
|
|
@@ -66,13 +66,12 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
66
66
|
if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
|
|
67
67
|
// @ts-ignore
|
|
68
68
|
return {
|
|
69
|
-
valid:
|
|
70
|
-
|
|
69
|
+
valid: SyntaxValidationResult.Drop,
|
|
70
|
+
context: [],
|
|
71
71
|
// @ts-ignore
|
|
72
72
|
node: tokens[0],
|
|
73
73
|
syntax: null,
|
|
74
|
-
error: 'unknown pseudo-class: ' + tokens[0].val + '()'
|
|
75
|
-
tokens
|
|
74
|
+
error: 'unknown pseudo-class: ' + tokens[0].val + '()'
|
|
76
75
|
};
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -93,13 +92,12 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
93
92
|
if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
|
|
94
93
|
// @ts-ignore
|
|
95
94
|
return {
|
|
96
|
-
valid:
|
|
97
|
-
|
|
95
|
+
valid: SyntaxValidationResult.Drop,
|
|
96
|
+
context: [],
|
|
98
97
|
// @ts-ignore
|
|
99
98
|
node: tokens[0],
|
|
100
99
|
syntax: null,
|
|
101
|
-
error: 'unknown pseudo-class: ' + tokens[0].val
|
|
102
|
-
tokens
|
|
100
|
+
error: 'unknown pseudo-class: ' + tokens[0].val
|
|
103
101
|
};
|
|
104
102
|
}
|
|
105
103
|
}
|
|
@@ -113,12 +111,11 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
113
111
|
if (children.length == 0) {
|
|
114
112
|
// @ts-ignore
|
|
115
113
|
return {
|
|
116
|
-
valid:
|
|
117
|
-
|
|
114
|
+
valid: SyntaxValidationResult.Drop,
|
|
115
|
+
context: [],
|
|
118
116
|
node: tokens[0],
|
|
119
117
|
syntax: null,
|
|
120
|
-
error: 'invalid attribute selector'
|
|
121
|
-
tokens
|
|
118
|
+
error: 'invalid attribute selector'
|
|
122
119
|
};
|
|
123
120
|
}
|
|
124
121
|
if (![
|
|
@@ -128,23 +125,21 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
128
125
|
].includes(children[0].typ)) {
|
|
129
126
|
// @ts-ignore
|
|
130
127
|
return {
|
|
131
|
-
valid:
|
|
132
|
-
|
|
128
|
+
valid: SyntaxValidationResult.Drop,
|
|
129
|
+
context: [],
|
|
133
130
|
node: tokens[0],
|
|
134
131
|
syntax: null,
|
|
135
|
-
error: 'invalid attribute selector'
|
|
136
|
-
tokens
|
|
132
|
+
error: 'invalid attribute selector'
|
|
137
133
|
};
|
|
138
134
|
}
|
|
139
135
|
if (children[0].typ == EnumToken.MatchExpressionTokenType) {
|
|
140
136
|
if (children.length != 1) {
|
|
141
137
|
return {
|
|
142
|
-
valid:
|
|
143
|
-
|
|
138
|
+
valid: SyntaxValidationResult.Drop,
|
|
139
|
+
context: [],
|
|
144
140
|
node: tokens[0],
|
|
145
141
|
syntax: null,
|
|
146
|
-
error: 'invalid <attribute-selector>'
|
|
147
|
-
tokens
|
|
142
|
+
error: 'invalid <attribute-selector>'
|
|
148
143
|
};
|
|
149
144
|
}
|
|
150
145
|
if (![
|
|
@@ -156,29 +151,27 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
156
151
|
EnumToken.StartMatchTokenType, EnumToken.ContainMatchTokenType,
|
|
157
152
|
EnumToken.EndMatchTokenType, EnumToken.IncludeMatchTokenType
|
|
158
153
|
].includes(children[0].op.typ) ||
|
|
159
|
-
![
|
|
154
|
+
!([
|
|
160
155
|
EnumToken.StringTokenType,
|
|
161
156
|
EnumToken.IdenTokenType
|
|
162
|
-
].includes(children[0].r.typ)) {
|
|
157
|
+
].includes(children[0].r.typ))) {
|
|
163
158
|
// @ts-ignore
|
|
164
159
|
return {
|
|
165
|
-
valid:
|
|
166
|
-
|
|
160
|
+
valid: SyntaxValidationResult.Drop,
|
|
161
|
+
context: [],
|
|
167
162
|
node: tokens[0],
|
|
168
163
|
syntax: null,
|
|
169
|
-
error: 'invalid attribute selector'
|
|
170
|
-
tokens
|
|
164
|
+
error: 'invalid attribute selector'
|
|
171
165
|
};
|
|
172
166
|
}
|
|
173
167
|
if (children[0].attr != null && !['i', 's'].includes(children[0].attr)) {
|
|
174
168
|
// @ts-ignore
|
|
175
169
|
return {
|
|
176
|
-
valid:
|
|
177
|
-
|
|
170
|
+
valid: SyntaxValidationResult.Drop,
|
|
171
|
+
context: [],
|
|
178
172
|
node: tokens[0],
|
|
179
173
|
syntax: null,
|
|
180
|
-
error: 'invalid attribute selector'
|
|
181
|
-
tokens
|
|
174
|
+
error: 'invalid attribute selector'
|
|
182
175
|
};
|
|
183
176
|
}
|
|
184
177
|
}
|
|
@@ -188,38 +181,35 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
188
181
|
}
|
|
189
182
|
if (length == tokens.length) {
|
|
190
183
|
return {
|
|
191
|
-
valid:
|
|
192
|
-
|
|
184
|
+
valid: SyntaxValidationResult.Drop,
|
|
185
|
+
context: [],
|
|
193
186
|
// @ts-ignore
|
|
194
187
|
node: tokens[0],
|
|
195
188
|
// @ts-ignore
|
|
196
189
|
syntax: null,
|
|
197
|
-
error: 'expected compound selector'
|
|
198
|
-
tokens
|
|
190
|
+
error: 'expected compound selector'
|
|
199
191
|
};
|
|
200
192
|
}
|
|
201
193
|
length = tokens.length;
|
|
202
194
|
}
|
|
203
195
|
return match == 0 ? {
|
|
204
|
-
valid:
|
|
205
|
-
|
|
196
|
+
valid: SyntaxValidationResult.Drop,
|
|
197
|
+
context: [],
|
|
206
198
|
// @ts-ignore
|
|
207
199
|
node: root,
|
|
208
200
|
// @ts-ignore
|
|
209
201
|
syntax: null,
|
|
210
|
-
error: 'expected compound selector'
|
|
211
|
-
tokens
|
|
202
|
+
error: 'expected compound selector'
|
|
212
203
|
} :
|
|
213
204
|
// @ts-ignore
|
|
214
205
|
{
|
|
215
|
-
valid:
|
|
216
|
-
|
|
206
|
+
valid: SyntaxValidationResult.Valid,
|
|
207
|
+
context: [],
|
|
217
208
|
// @ts-ignore
|
|
218
209
|
node: root,
|
|
219
210
|
// @ts-ignore
|
|
220
211
|
syntax: null,
|
|
221
|
-
error: null
|
|
222
|
-
tokens
|
|
212
|
+
error: null
|
|
223
213
|
};
|
|
224
214
|
}
|
|
225
215
|
|
|
@@ -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
|
|
|
10
11
|
function validateFamilyName(tokens, atRule) {
|
|
@@ -14,7 +15,7 @@ function validateFamilyName(tokens, atRule) {
|
|
|
14
15
|
if (tokens.length == 0) {
|
|
15
16
|
// @ts-ignore
|
|
16
17
|
return {
|
|
17
|
-
valid:
|
|
18
|
+
valid: SyntaxValidationResult.Drop,
|
|
18
19
|
matches: [],
|
|
19
20
|
node: atRule,
|
|
20
21
|
syntax: null,
|
|
@@ -25,7 +26,7 @@ function validateFamilyName(tokens, atRule) {
|
|
|
25
26
|
if (tokens[0].typ == EnumToken.CommaTokenType) {
|
|
26
27
|
// @ts-ignore
|
|
27
28
|
return {
|
|
28
|
-
valid:
|
|
29
|
+
valid: SyntaxValidationResult.Drop,
|
|
29
30
|
matches: [],
|
|
30
31
|
node: tokens[0],
|
|
31
32
|
syntax: null,
|
|
@@ -41,7 +42,7 @@ function validateFamilyName(tokens, atRule) {
|
|
|
41
42
|
if (tokens.length == 0) {
|
|
42
43
|
// @ts-ignore
|
|
43
44
|
return {
|
|
44
|
-
valid:
|
|
45
|
+
valid: SyntaxValidationResult.Drop,
|
|
45
46
|
matches: [],
|
|
46
47
|
node,
|
|
47
48
|
syntax: null,
|
|
@@ -54,7 +55,7 @@ function validateFamilyName(tokens, atRule) {
|
|
|
54
55
|
if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
|
|
55
56
|
// @ts-ignore
|
|
56
57
|
return {
|
|
57
|
-
valid:
|
|
58
|
+
valid: SyntaxValidationResult.Drop,
|
|
58
59
|
matches: [],
|
|
59
60
|
node,
|
|
60
61
|
syntax: null,
|
|
@@ -68,7 +69,7 @@ function validateFamilyName(tokens, atRule) {
|
|
|
68
69
|
if (tokens.length > 0 && node.typ == EnumToken.BadStringTokenType && tokens[0].typ != EnumToken.CommaTokenType) {
|
|
69
70
|
// @ts-ignore
|
|
70
71
|
return {
|
|
71
|
-
valid:
|
|
72
|
+
valid: SyntaxValidationResult.Drop,
|
|
72
73
|
matches: [],
|
|
73
74
|
node: tokens[0],
|
|
74
75
|
syntax: null,
|
|
@@ -79,7 +80,7 @@ function validateFamilyName(tokens, atRule) {
|
|
|
79
80
|
}
|
|
80
81
|
// @ts-ignore
|
|
81
82
|
return {
|
|
82
|
-
valid:
|
|
83
|
+
valid: SyntaxValidationResult.Valid,
|
|
83
84
|
matches: [],
|
|
84
85
|
node: null,
|
|
85
86
|
syntax: null,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { EnumToken,
|
|
1
|
+
import { EnumToken, 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 { validateKeyframeSelector } from './keyframe-selector.js';
|
|
9
10
|
|
|
10
11
|
function validateKeyframeBlockList(tokens, atRule, options) {
|
|
@@ -14,7 +15,7 @@ function validateKeyframeBlockList(tokens, atRule, options) {
|
|
|
14
15
|
while (i + 1 < tokens.length) {
|
|
15
16
|
if (tokens[++i].typ == EnumToken.CommaTokenType) {
|
|
16
17
|
result = validateKeyframeSelector(tokens.slice(j, i));
|
|
17
|
-
if (result.valid ==
|
|
18
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
18
19
|
return result;
|
|
19
20
|
}
|
|
20
21
|
j = i + 1;
|
|
@@ -1,57 +1,54 @@
|
|
|
1
1
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
2
|
import { splitTokenList } from '../utils/list.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
5
|
import '../../ast/walk.js';
|
|
6
6
|
import '../../parser/parse.js';
|
|
7
|
+
import '../../parser/tokenize.js';
|
|
8
|
+
import '../../parser/utils/config.js';
|
|
7
9
|
import '../../renderer/color/utils/constants.js';
|
|
8
10
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import '../../parser/utils/config.js';
|
|
10
11
|
|
|
11
12
|
function validateKeyframeSelector(tokens, options) {
|
|
12
13
|
consumeWhitespace(tokens);
|
|
13
14
|
if (tokens.length == 0) {
|
|
14
15
|
// @ts-ignore
|
|
15
16
|
return {
|
|
16
|
-
valid:
|
|
17
|
-
|
|
17
|
+
valid: SyntaxValidationResult.Drop,
|
|
18
|
+
context: [],
|
|
18
19
|
node: null,
|
|
19
20
|
syntax: null,
|
|
20
|
-
error: 'expected keyframe selector'
|
|
21
|
-
tokens
|
|
21
|
+
error: 'expected keyframe selector'
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
for (const t of splitTokenList(tokens)) {
|
|
25
25
|
if (t.length != 1) {
|
|
26
26
|
return {
|
|
27
|
-
valid:
|
|
28
|
-
|
|
27
|
+
valid: SyntaxValidationResult.Drop,
|
|
28
|
+
context: [],
|
|
29
29
|
node: t[0] ?? null,
|
|
30
30
|
syntax: null,
|
|
31
|
-
error: 'unexpected token'
|
|
32
|
-
tokens
|
|
31
|
+
error: 'unexpected token'
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
if (t[0].typ != EnumToken.PercentageTokenType && !(t[0].typ == EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val))) {
|
|
36
35
|
return {
|
|
37
|
-
valid:
|
|
38
|
-
|
|
36
|
+
valid: SyntaxValidationResult.Drop,
|
|
37
|
+
context: [],
|
|
39
38
|
node: t[0],
|
|
40
39
|
syntax: null,
|
|
41
|
-
error: 'expected keyframe selector'
|
|
42
|
-
tokens
|
|
40
|
+
error: 'expected keyframe selector'
|
|
43
41
|
};
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
// @ts-ignore
|
|
47
45
|
return {
|
|
48
|
-
valid:
|
|
49
|
-
|
|
46
|
+
valid: SyntaxValidationResult.Valid,
|
|
47
|
+
context: [],
|
|
50
48
|
node: null,
|
|
51
49
|
// @ts-ignore
|
|
52
50
|
syntax: null,
|
|
53
|
-
error: ''
|
|
54
|
-
tokens
|
|
51
|
+
error: ''
|
|
55
52
|
};
|
|
56
53
|
}
|
|
57
54
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { EnumToken,
|
|
1
|
+
import { EnumToken, 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
|
|
|
9
10
|
function validateLayerName(tokens) {
|
|
10
11
|
const slice = tokens.reduce((acc, curr) => {
|
|
@@ -20,7 +21,7 @@ function validateLayerName(tokens) {
|
|
|
20
21
|
if (slice[i].length == 0) {
|
|
21
22
|
// @ts-ignore
|
|
22
23
|
return {
|
|
23
|
-
valid:
|
|
24
|
+
valid: SyntaxValidationResult.Drop,
|
|
24
25
|
matches: tokens,
|
|
25
26
|
node: null,
|
|
26
27
|
syntax: null,
|
|
@@ -32,7 +33,7 @@ function validateLayerName(tokens) {
|
|
|
32
33
|
if (slice[i][j].typ != EnumToken.IdenTokenType && slice[i][j].typ != EnumToken.ClassSelectorTokenType) {
|
|
33
34
|
// @ts-ignore
|
|
34
35
|
return {
|
|
35
|
-
valid:
|
|
36
|
+
valid: SyntaxValidationResult.Drop,
|
|
36
37
|
matches: tokens,
|
|
37
38
|
node: slice[i][j],
|
|
38
39
|
syntax: '<layer-name>',
|
|
@@ -44,7 +45,7 @@ function validateLayerName(tokens) {
|
|
|
44
45
|
}
|
|
45
46
|
// @ts-ignore
|
|
46
47
|
return {
|
|
47
|
-
valid:
|
|
48
|
+
valid: SyntaxValidationResult.Valid,
|
|
48
49
|
matches: tokens,
|
|
49
50
|
node: null,
|
|
50
51
|
syntax: null,
|
|
@@ -1,10 +1,11 @@
|
|
|
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 { validateRelativeSelector } from './relative-selector.js';
|
|
9
10
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
11
|
import { splitTokenList } from '../utils/list.js';
|
|
@@ -14,7 +15,7 @@ function validateRelativeSelectorList(tokens, root, options) {
|
|
|
14
15
|
consumeWhitespace(tokens);
|
|
15
16
|
if (tokens.length == 0) {
|
|
16
17
|
return {
|
|
17
|
-
valid:
|
|
18
|
+
valid: SyntaxValidationResult.Drop,
|
|
18
19
|
matches: [],
|
|
19
20
|
// @ts-ignore
|
|
20
21
|
node: root,
|
|
@@ -27,7 +28,7 @@ function validateRelativeSelectorList(tokens, root, options) {
|
|
|
27
28
|
for (const t of splitTokenList(tokens)) {
|
|
28
29
|
if (t.length == 0) {
|
|
29
30
|
return {
|
|
30
|
-
valid:
|
|
31
|
+
valid: SyntaxValidationResult.Drop,
|
|
31
32
|
matches: [],
|
|
32
33
|
// @ts-ignore
|
|
33
34
|
node: root,
|
|
@@ -38,12 +39,12 @@ function validateRelativeSelectorList(tokens, root, options) {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
const result = validateRelativeSelector(t, root, options);
|
|
41
|
-
if (result.valid ==
|
|
42
|
+
if (result.valid == SyntaxValidationResult.Drop) {
|
|
42
43
|
return result;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
return {
|
|
46
|
-
valid:
|
|
47
|
+
valid: SyntaxValidationResult.Valid,
|
|
47
48
|
matches: [],
|
|
48
49
|
// @ts-ignore
|
|
49
50
|
node: root,
|
|
@@ -3,9 +3,10 @@ import '../../ast/types.js';
|
|
|
3
3
|
import '../../ast/minify.js';
|
|
4
4
|
import '../../ast/walk.js';
|
|
5
5
|
import '../../parser/parse.js';
|
|
6
|
+
import '../../parser/tokenize.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
6
8
|
import '../../renderer/color/utils/constants.js';
|
|
7
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
8
|
-
import '../../parser/utils/config.js';
|
|
9
10
|
import { validateSelector } from './selector.js';
|
|
10
11
|
import { combinatorsTokens } from './complex-selector.js';
|
|
11
12
|
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import { EnumToken,
|
|
1
|
+
import { EnumToken, 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 { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
10
|
|
|
10
11
|
function validateURL(token) {
|
|
11
12
|
if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
12
13
|
// @ts-ignore
|
|
13
14
|
return {
|
|
14
|
-
valid:
|
|
15
|
-
|
|
15
|
+
valid: SyntaxValidationResult.Valid,
|
|
16
|
+
context: [],
|
|
16
17
|
node: token,
|
|
17
18
|
// @ts-ignore
|
|
18
19
|
syntax: 'url()',
|
|
19
|
-
error: ''
|
|
20
|
-
tokens: []
|
|
20
|
+
error: ''
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
if (token.typ != EnumToken.UrlFunctionTokenType) {
|
|
24
24
|
// @ts-ignore
|
|
25
25
|
return {
|
|
26
|
-
valid:
|
|
27
|
-
|
|
26
|
+
valid: SyntaxValidationResult.Drop,
|
|
27
|
+
context: [],
|
|
28
28
|
node: token,
|
|
29
29
|
// @ts-ignore
|
|
30
30
|
syntax: 'url()',
|
|
31
|
-
error: 'expected url()'
|
|
32
|
-
tokens: []
|
|
31
|
+
error: 'expected url()'
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
const children = token.chi.slice();
|
|
@@ -37,13 +36,12 @@ function validateURL(token) {
|
|
|
37
36
|
if (children.length == 0 || ![EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
|
|
38
37
|
// @ts-ignore
|
|
39
38
|
return {
|
|
40
|
-
valid:
|
|
41
|
-
|
|
39
|
+
valid: SyntaxValidationResult.Drop,
|
|
40
|
+
context: [],
|
|
42
41
|
node: children[0] ?? token,
|
|
43
42
|
// @ts-ignore
|
|
44
43
|
syntax: 'url()',
|
|
45
|
-
error: 'expected url-token'
|
|
46
|
-
tokens: children
|
|
44
|
+
error: 'expected url-token'
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
47
|
children.shift();
|
|
@@ -51,24 +49,22 @@ function validateURL(token) {
|
|
|
51
49
|
if (children.length > 0) {
|
|
52
50
|
// @ts-ignore
|
|
53
51
|
return {
|
|
54
|
-
valid:
|
|
55
|
-
|
|
52
|
+
valid: SyntaxValidationResult.Drop,
|
|
53
|
+
context: [],
|
|
56
54
|
node: children[0] ?? token,
|
|
57
55
|
// @ts-ignore
|
|
58
56
|
syntax: 'url()',
|
|
59
|
-
error: 'unexpected token'
|
|
60
|
-
tokens: children
|
|
57
|
+
error: 'unexpected token'
|
|
61
58
|
};
|
|
62
59
|
}
|
|
63
60
|
// @ts-ignore
|
|
64
61
|
return {
|
|
65
|
-
valid:
|
|
66
|
-
|
|
62
|
+
valid: SyntaxValidationResult.Valid,
|
|
63
|
+
context: [],
|
|
67
64
|
node: token,
|
|
68
65
|
// @ts-ignore
|
|
69
66
|
syntax: 'url()',
|
|
70
|
-
error: ''
|
|
71
|
-
tokens: []
|
|
67
|
+
error: ''
|
|
72
68
|
};
|
|
73
69
|
}
|
|
74
70
|
|