@tbela99/css-parser 1.4.6 → 1.4.8
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 +23 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6578 -6969
- package/dist/index.cjs +7808 -8197
- package/dist/index.d.ts +923 -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 +10 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +47 -45
- package/dist/lib/parser/arena.js +206 -0
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/linemap.js +62 -0
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/source.js +72 -0
- 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 +284 -283
- 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 +152 -121
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color-mix.js +8 -1
- package/dist/lib/syntax/color/color.js +17 -9
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/p3.js +9 -1
- 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/distance.js +6 -1
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +25 -3
- package/dist/lib/syntax/syntax.js +240 -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 +18 -14
- package/dist/web.js +12 -10
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
- /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { tokensfuncDefMap } from '../../syntax/constants.js';
|
|
2
|
+
import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
|
|
3
3
|
import { equalsIgnoreCase } from './text.js';
|
|
4
4
|
|
|
5
5
|
function matchGenericSyntax(stream) {
|
|
@@ -23,40 +23,40 @@ function matchGenericSyntax(stream) {
|
|
|
23
23
|
}
|
|
24
24
|
if (token.typ === EnumToken.EndParensTokenType) {
|
|
25
25
|
if (stack.length === 0 ||
|
|
26
|
-
(stack.at(-1)?.typ !== EnumToken.
|
|
26
|
+
(stack.at(-1)?.typ !== EnumToken.StartParensTokenType && !tokensfuncDefMap.has(stack.at(-1)?.typ))) {
|
|
27
27
|
errors.push({
|
|
28
28
|
action: "drop",
|
|
29
|
-
message: `unexpected token ${EnumToken[token.typ]} at ${token.
|
|
29
|
+
message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
30
30
|
node: token,
|
|
31
|
-
location: token
|
|
31
|
+
location: token[LOC],
|
|
32
32
|
});
|
|
33
33
|
success = false;
|
|
34
34
|
break;
|
|
35
35
|
}
|
|
36
36
|
stack.pop();
|
|
37
37
|
scopes.pop();
|
|
38
|
-
if (scopes.length === 0) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
38
|
+
// if (scopes.length === 0) {
|
|
39
|
+
// return {
|
|
40
|
+
// success: false,
|
|
41
|
+
// errors: [
|
|
42
|
+
// {
|
|
43
|
+
// action: "drop",
|
|
44
|
+
// node: token,
|
|
45
|
+
// message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${token[LOC]!.sta.col}`,
|
|
46
|
+
// location: token[LOC]!,
|
|
47
|
+
// },
|
|
48
|
+
// ],
|
|
49
|
+
// };
|
|
50
|
+
// }
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
53
|
if (token.typ === EnumToken.IdenTokenType && equalsIgnoreCase("and", token.val)) {
|
|
54
54
|
if (!expectAndOr || scopes.at(-1)?.has(EnumToken.OrTokenType)) {
|
|
55
55
|
errors.push({
|
|
56
56
|
action: "drop",
|
|
57
|
-
message: `unexpected token ${EnumToken[token.typ]} at ${token.
|
|
57
|
+
message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
58
58
|
node: token,
|
|
59
|
-
location: token
|
|
59
|
+
location: token[LOC],
|
|
60
60
|
});
|
|
61
61
|
success = false;
|
|
62
62
|
break;
|
|
@@ -70,9 +70,9 @@ function matchGenericSyntax(stream) {
|
|
|
70
70
|
if (!expectAndOr || scopes.at(-1)?.has(EnumToken.AndTokenType)) {
|
|
71
71
|
errors.push({
|
|
72
72
|
action: "drop",
|
|
73
|
-
message: `unexpected token ${EnumToken[token.typ]} at ${token.
|
|
73
|
+
message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
74
74
|
node: token,
|
|
75
|
-
location: token
|
|
75
|
+
location: token[LOC],
|
|
76
76
|
});
|
|
77
77
|
success = false;
|
|
78
78
|
break;
|
|
@@ -86,9 +86,9 @@ function matchGenericSyntax(stream) {
|
|
|
86
86
|
if (!expectComma) {
|
|
87
87
|
errors.push({
|
|
88
88
|
action: "drop",
|
|
89
|
-
message: `unexpected token ${EnumToken[token.typ]} at ${token.
|
|
89
|
+
message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
|
|
90
90
|
node: token,
|
|
91
|
-
location: token
|
|
91
|
+
location: token[LOC],
|
|
92
92
|
});
|
|
93
93
|
success = false;
|
|
94
94
|
break;
|
|
@@ -106,9 +106,9 @@ function matchGenericSyntax(stream) {
|
|
|
106
106
|
if (stack.length > 0) {
|
|
107
107
|
errors.push({
|
|
108
108
|
action: "drop",
|
|
109
|
-
message: `unexpected token ${EnumToken[stack.at(-1)?.typ]} at ${stack.at(-1)?.
|
|
109
|
+
message: `unexpected token ${EnumToken[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
110
110
|
node: stack.at(-1),
|
|
111
|
-
location: stack.at(-1)?.
|
|
111
|
+
location: stack.at(-1)?.[LOC],
|
|
112
112
|
});
|
|
113
113
|
success = false;
|
|
114
114
|
}
|
|
@@ -2,8 +2,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
2
2
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
3
3
|
import { trimArray } from '../../validation/match.js';
|
|
4
4
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
5
|
-
import { tokensfuncDefMap,
|
|
6
|
-
import { isColor, parseColor } from '../../syntax/syntax.js';
|
|
5
|
+
import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
|
|
7
6
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
8
7
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
9
8
|
|
|
@@ -27,8 +26,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
27
26
|
// match ending ')'
|
|
28
27
|
let matchCount = 0;
|
|
29
28
|
let k = 0;
|
|
30
|
-
let stringCount = 0;
|
|
31
|
-
let urlTokenCount = 0;
|
|
29
|
+
// let stringCount = 0;
|
|
32
30
|
for (; k < stream.length; k++) {
|
|
33
31
|
if (stream[k]?.typ === EnumToken.EndParensTokenType) {
|
|
34
32
|
matchCount--;
|
|
@@ -36,56 +34,54 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
36
34
|
else if (stream[k]?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[k]?.typ)) {
|
|
37
35
|
matchCount++;
|
|
38
36
|
}
|
|
39
|
-
else if (stream[k]?.typ === EnumToken.StringTokenType) {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
else if (stream[k]?.typ === EnumToken.UrlFunctionTokenDefType) {
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
37
|
+
// else if (stream[k]?.typ === EnumToken.StringTokenType) {
|
|
38
|
+
// stringCount++;
|
|
39
|
+
// }
|
|
40
|
+
// else if (stream[k]?.typ === EnumToken.UrlFunctionTokenDefType) {
|
|
41
|
+
// urlTokenCount++;
|
|
42
|
+
// } else if (
|
|
43
|
+
// !(stream[k]?.typ === EnumToken.WhitespaceTokenType || stream[k]?.typ === EnumToken.CommentTokenType)
|
|
44
|
+
// ) {
|
|
45
|
+
// return {
|
|
46
|
+
// success: false,
|
|
47
|
+
// errors: [
|
|
48
|
+
// {
|
|
49
|
+
// action: "drop",
|
|
50
|
+
// message: "Expected string or <url-token>",
|
|
51
|
+
// syntax: "@import",
|
|
52
|
+
// node: stream[k],
|
|
53
|
+
// location: stream[k]?.[LOC],
|
|
54
|
+
// } as ErrorDescription,
|
|
55
|
+
// ],
|
|
56
|
+
// };
|
|
57
|
+
// }
|
|
59
58
|
if (matchCount === 0) {
|
|
60
59
|
break;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
if (stringCount + urlTokenCount != 1) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
62
|
+
// if (stringCount + urlTokenCount != 1) {
|
|
63
|
+
// return {
|
|
64
|
+
// success: false,
|
|
65
|
+
// errors: [
|
|
66
|
+
// {
|
|
67
|
+
// action: "drop",
|
|
68
|
+
// syntax: "@import",
|
|
69
|
+
// message: "could not match syntax <url>",
|
|
70
|
+
// node: stream[0],
|
|
71
|
+
// location: stream[0][LOC],
|
|
72
|
+
// },
|
|
73
|
+
// ],
|
|
74
|
+
// };
|
|
75
|
+
// }
|
|
77
76
|
const slice = stream.slice(index + 1, k);
|
|
78
|
-
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
stream[0][LOC] = {
|
|
79
|
+
...stream[0][LOC],
|
|
80
|
+
end: stream[1][LOC].end,
|
|
81
|
+
};
|
|
82
|
+
tokens.push(Object.assign({
|
|
79
83
|
typ: tokensfuncDefMap.get(stream[0].typ),
|
|
80
84
|
chi: trimArray(slice),
|
|
81
|
-
}), {
|
|
82
|
-
loc: {
|
|
83
|
-
...definedPropertySettings,
|
|
84
|
-
value: {
|
|
85
|
-
...stream[0].loc,
|
|
86
|
-
end: stream[1].loc.end,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
85
|
}));
|
|
90
86
|
index = k + 1;
|
|
91
87
|
}
|
|
@@ -98,7 +94,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
98
94
|
message: "Expected string or url()",
|
|
99
95
|
syntax: "@import",
|
|
100
96
|
node: stream[0],
|
|
101
|
-
location: stream[0]?.
|
|
97
|
+
location: stream[0]?.[LOC],
|
|
102
98
|
},
|
|
103
99
|
],
|
|
104
100
|
};
|
|
@@ -116,10 +112,12 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
116
112
|
"layer".localeCompare(stream[index].val) === 0) {
|
|
117
113
|
stack.push(stream[index]);
|
|
118
114
|
tokens.push(stream[index++]);
|
|
119
|
-
while (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
// while (
|
|
116
|
+
// stream[index]?.typ === EnumToken.WhitespaceTokenType ||
|
|
117
|
+
// stream[index]?.typ === EnumToken.CommentTokenType
|
|
118
|
+
// ) {
|
|
119
|
+
// tokens.push(stream[index++] as Token);
|
|
120
|
+
// }
|
|
123
121
|
// <layer-name">
|
|
124
122
|
if (stream[index]?.typ === EnumToken.EndParensTokenType) {
|
|
125
123
|
i = tokens.indexOf(stack.at(-1));
|
|
@@ -129,10 +127,10 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
129
127
|
errors: [
|
|
130
128
|
{
|
|
131
129
|
action: "drop",
|
|
132
|
-
message: `Expected <layer-name> at ${stream[index]?.
|
|
130
|
+
message: `Expected <layer-name> at ${stream[index]?.[LOC]?.src}:${stream[index]?.[LOC]?.sta.lin}:${stream[index]?.[LOC]?.sta.col}`,
|
|
133
131
|
syntax: "@import",
|
|
134
132
|
node: stream[index],
|
|
135
|
-
location: stream[index]?.
|
|
133
|
+
location: stream[index]?.[LOC],
|
|
136
134
|
},
|
|
137
135
|
],
|
|
138
136
|
};
|
|
@@ -142,24 +140,26 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
142
140
|
while (stream[index]?.typ == EnumToken.ClassSelectorTokenType) {
|
|
143
141
|
tokens.push(stream[index++]);
|
|
144
142
|
}
|
|
145
|
-
while (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
143
|
+
// while (
|
|
144
|
+
// stream[index]?.typ == EnumToken.WhitespaceTokenType ||
|
|
145
|
+
// stream[index]?.typ == EnumToken.CommentTokenType
|
|
146
|
+
// ) {
|
|
147
|
+
// tokens.push(stream[index++] as Token);
|
|
148
|
+
// }
|
|
149
|
+
// if (stream[index]?.typ !== EnumToken.EndParensTokenType) {
|
|
150
|
+
// return {
|
|
151
|
+
// success: false,
|
|
152
|
+
// errors: [
|
|
153
|
+
// {
|
|
154
|
+
// action: "drop",
|
|
155
|
+
// message: "Expected ')'",
|
|
156
|
+
// syntax: "@import",
|
|
157
|
+
// node: stream[index],
|
|
158
|
+
// location: stream[index]?.[LOC],
|
|
159
|
+
// } as ErrorDescription,
|
|
160
|
+
// ],
|
|
161
|
+
// };
|
|
162
|
+
// }
|
|
163
163
|
i = tokens.indexOf(stack.at(-1));
|
|
164
164
|
tokens.splice(index, 1);
|
|
165
165
|
Object.assign(stack.at(-1), {
|
|
@@ -174,10 +174,10 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
174
174
|
errors: [
|
|
175
175
|
{
|
|
176
176
|
action: "drop",
|
|
177
|
-
message: `Expected <layer-name> at ${stream[index]?.
|
|
177
|
+
message: `Expected <layer-name> at ${stream[index]?.[LOC]?.src}:${stream[index]?.[LOC]?.sta.lin}:${stream[index]?.[LOC]?.sta.col}`,
|
|
178
178
|
syntax: "@import",
|
|
179
179
|
node: stream[index],
|
|
180
|
-
location: stream[index]?.
|
|
180
|
+
location: stream[index]?.[LOC],
|
|
181
181
|
},
|
|
182
182
|
],
|
|
183
183
|
};
|
|
@@ -193,176 +193,136 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
|
|
|
193
193
|
stack.push(stream[index]);
|
|
194
194
|
tokens.push(stream[index++]);
|
|
195
195
|
matchCount = 1;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
196
|
+
// while (
|
|
197
|
+
// stream[index]?.typ === EnumToken.WhitespaceTokenType ||
|
|
198
|
+
// stream[index]?.typ === EnumToken.CommentTokenType
|
|
199
|
+
// ) {
|
|
200
|
+
// tokens.push(stream[index++] as Token);
|
|
201
|
+
// }
|
|
201
202
|
// <declaration>
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
203
|
+
// if (
|
|
204
|
+
// stream[index]?.typ === EnumToken.IdenTokenType &&
|
|
205
|
+
// !["and", "or", "not", "only"].includes((stream[index] as IdentToken).val.toLowerCase())
|
|
206
|
+
// ) {
|
|
207
|
+
// tokens.push(stream[index++] as Token);
|
|
208
|
+
// while (
|
|
209
|
+
// stream[index]?.typ === EnumToken.WhitespaceTokenType ||
|
|
210
|
+
// stream[index]?.typ === EnumToken.CommentTokenType
|
|
211
|
+
// ) {
|
|
212
|
+
// tokens.push(stream[index++] as Token);
|
|
213
|
+
// }
|
|
214
|
+
// if (stream[index]?.typ !== EnumToken.ColonTokenType) {
|
|
215
|
+
// return {
|
|
216
|
+
// success: false,
|
|
217
|
+
// errors: [
|
|
218
|
+
// {
|
|
219
|
+
// action: "drop",
|
|
220
|
+
// message: "Expected ':'",
|
|
221
|
+
// syntax: "@import",
|
|
222
|
+
// node: stream[index],
|
|
223
|
+
// location: stream[index]?.[LOC],
|
|
224
|
+
// } as ErrorDescription,
|
|
225
|
+
// ],
|
|
226
|
+
// };
|
|
227
|
+
// } else {
|
|
228
|
+
// isDecl = true;
|
|
229
|
+
// tokens.push(stream[index++] as Token);
|
|
230
|
+
// // match the next ')'
|
|
231
|
+
// while (index < stream.length && matchCount > 0) {
|
|
232
|
+
// if (
|
|
233
|
+
// stream[index]?.typ === EnumToken.StartParensTokenType ||
|
|
234
|
+
// tokensfuncDefMap.has(stream[index]?.typ)
|
|
235
|
+
// ) {
|
|
236
|
+
// matchCount++;
|
|
237
|
+
// // stack.push(stream[index] as Token);
|
|
238
|
+
// } else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
|
|
239
|
+
// matchCount--;
|
|
240
|
+
// if (matchCount === 0) {
|
|
241
|
+
// i = tokens.indexOf(stack.at(-1) as Token);
|
|
242
|
+
// tokens.splice(index, 1);
|
|
243
|
+
// Object.assign(stack.at(-1) as Token, {
|
|
244
|
+
// typ: tokensfuncDefMap.get((stack.at(-1) as Token).typ),
|
|
245
|
+
// chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
|
|
246
|
+
// });
|
|
247
|
+
// stack.pop();
|
|
248
|
+
// break;
|
|
249
|
+
// }
|
|
250
|
+
// } else if (stream[index]?.typ === EnumToken.ImportantTokenType) {
|
|
251
|
+
// tokens.push(stream[index++] as Token);
|
|
252
|
+
// while (
|
|
253
|
+
// stream[index]?.typ === EnumToken.WhitespaceTokenType ||
|
|
254
|
+
// stream[index]?.typ === EnumToken.CommentTokenType
|
|
255
|
+
// ) {
|
|
256
|
+
// tokens.push(stream[index++] as Token);
|
|
257
|
+
// }
|
|
258
|
+
// // next token is ')'
|
|
259
|
+
// if (stream[index]?.typ !== EnumToken.EndParensTokenType) {
|
|
260
|
+
// return {
|
|
261
|
+
// success: false,
|
|
262
|
+
// errors: [
|
|
263
|
+
// {
|
|
264
|
+
// action: "drop",
|
|
265
|
+
// message: "Expected ')'",
|
|
266
|
+
// syntax: "@import",
|
|
267
|
+
// node: stream[index],
|
|
268
|
+
// location: stream[index]?.[LOC],
|
|
269
|
+
// } as ErrorDescription,
|
|
270
|
+
// ],
|
|
271
|
+
// };
|
|
272
|
+
// }
|
|
273
|
+
// matchCount--;
|
|
274
|
+
// i = tokens.indexOf(stack.at(-1) as Token);
|
|
275
|
+
// tokens.splice(index, 1);
|
|
276
|
+
// Object.assign(stack.at(-1) as Token, {
|
|
277
|
+
// typ: tokensfuncDefMap.get((stack.at(-1) as Token).typ),
|
|
278
|
+
// chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
|
|
279
|
+
// });
|
|
280
|
+
// stack.pop();
|
|
281
|
+
// break;
|
|
282
|
+
// }
|
|
283
|
+
// tokens.push(stream[index++] as Token);
|
|
284
|
+
// }
|
|
285
|
+
// }
|
|
286
|
+
// }
|
|
281
287
|
// <supports-condition>
|
|
282
|
-
else {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
|
|
289
|
-
matchCount--;
|
|
290
|
-
if (matchCount === 0) {
|
|
291
|
-
tokens.splice(index, 1);
|
|
292
|
-
i = tokens.indexOf(stack.at(-1));
|
|
293
|
-
Object.assign(stack.at(-1), {
|
|
294
|
-
typ: tokensfuncDefMap.get(stack.at(-1).typ),
|
|
295
|
-
chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
|
|
296
|
-
});
|
|
297
|
-
stack.pop();
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
tokens.push(stream[index++]);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (matchCount > 0) {
|
|
305
|
-
return {
|
|
306
|
-
success: false,
|
|
307
|
-
errors: [
|
|
308
|
-
{
|
|
309
|
-
action: "drop",
|
|
310
|
-
message: "unmatched ')'",
|
|
311
|
-
syntax: "@import",
|
|
312
|
-
node: stack.at(-1),
|
|
313
|
-
location: stack.at(-1)?.loc,
|
|
314
|
-
},
|
|
315
|
-
],
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
// support() is the last item in tokens array
|
|
319
|
-
if (isDecl) {
|
|
320
|
-
const supports = tokens.at(-1);
|
|
321
|
-
for (i = 0; i < supports.chi.length; i++) {
|
|
322
|
-
if (supports.chi[i].typ === EnumToken.IdenTokenType) {
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
let j = i + 1;
|
|
327
|
-
while (j < supports.chi.length && supports.chi[j].typ !== EnumToken.ColonTokenType) {
|
|
328
|
-
j++;
|
|
288
|
+
// else {
|
|
289
|
+
// match the next ')'
|
|
290
|
+
while (index < stream.length && matchCount > 0) {
|
|
291
|
+
if (stream[index]?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[index]?.typ)) {
|
|
292
|
+
matchCount++;
|
|
329
293
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}, {
|
|
336
|
-
loc: {
|
|
337
|
-
...definedPropertySettings,
|
|
338
|
-
value: {
|
|
339
|
-
...supports.chi[i].loc,
|
|
340
|
-
end: { ...(val.at(-1) ?? supports.chi.at(-1)).loc?.end },
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
supports.chi.splice(i + 1, j - i + 1 + val.length);
|
|
345
|
-
const stack = [];
|
|
346
|
-
for (i = 0; i < val.length; i++) {
|
|
347
|
-
if (val[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(val[i].typ)) {
|
|
348
|
-
stack.push(val[i]);
|
|
349
|
-
}
|
|
350
|
-
else if (val[i].typ === EnumToken.EndParensTokenType) {
|
|
351
|
-
const index = val.indexOf(stack.at(-1));
|
|
352
|
-
val.splice(i, 1);
|
|
294
|
+
else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
|
|
295
|
+
matchCount--;
|
|
296
|
+
if (matchCount === 0) {
|
|
297
|
+
tokens.splice(index, 1);
|
|
298
|
+
i = tokens.indexOf(stack.at(-1));
|
|
353
299
|
Object.assign(stack.at(-1), {
|
|
354
300
|
typ: tokensfuncDefMap.get(stack.at(-1).typ),
|
|
355
|
-
chi: trimArray(
|
|
301
|
+
chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
|
|
356
302
|
});
|
|
357
|
-
i = index;
|
|
358
303
|
stack.pop();
|
|
359
|
-
|
|
360
|
-
if (isColor(val[i])) {
|
|
361
|
-
val[i] = parseColor(val[i]);
|
|
304
|
+
break;
|
|
362
305
|
}
|
|
363
306
|
}
|
|
307
|
+
tokens.push(stream[index++]);
|
|
364
308
|
}
|
|
365
|
-
|
|
309
|
+
// }
|
|
310
|
+
// if (matchCount > 0) {
|
|
311
|
+
// return {
|
|
312
|
+
// success: false,
|
|
313
|
+
// errors: [
|
|
314
|
+
// {
|
|
315
|
+
// action: "drop",
|
|
316
|
+
// message: "unmatched ')'",
|
|
317
|
+
// syntax: "@import",
|
|
318
|
+
// node: stack.at(-1),
|
|
319
|
+
// location: stack.at(-1)?.[LOC],
|
|
320
|
+
// } as ErrorDescription,
|
|
321
|
+
// ],
|
|
322
|
+
// };
|
|
323
|
+
// }
|
|
324
|
+
// support() is the last item in tokens array
|
|
325
|
+
{
|
|
366
326
|
const result = parseAtRuleSupportSyntax(tokens[tokens.length - 1].chi, context, options);
|
|
367
327
|
if (!result.success && result.errors.length > 0) {
|
|
368
328
|
errors.push(...result.errors);
|