@tbela99/css-parser 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -2
- package/README.md +2 -0
- package/dist/index-umd-web.js +6546 -6987
- package/dist/index.cjs +7784 -8223
- package/dist/index.d.ts +919 -51
- package/dist/lib/ast/clone.js +16 -23
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/if.js +88 -87
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +26 -22
- package/dist/lib/ast/features/transform.js +3 -3
- package/dist/lib/ast/find.js +17 -14
- package/dist/lib/ast/minify.js +97 -94
- package/dist/lib/ast/types.js +6 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +46 -44
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/parse.js +331 -506
- package/dist/lib/parser/tokenize.js +39 -33
- package/dist/lib/parser/utils/at-rule-container.js +244 -247
- package/dist/lib/parser/utils/at-rule-generic.js +25 -25
- package/dist/lib/parser/utils/at-rule-import.js +194 -234
- package/dist/lib/parser/utils/at-rule-media.js +286 -286
- package/dist/lib/parser/utils/at-rule-support.js +279 -251
- package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
- package/dist/lib/parser/utils/at-rule.js +19 -16
- package/dist/lib/parser/utils/cache.js +33 -5
- package/dist/lib/parser/utils/declaration.js +260 -322
- package/dist/lib/parser/utils/hash.js +15 -15
- package/dist/lib/parser/utils/selector.js +182 -222
- package/dist/lib/parser/utils/token.js +4 -7
- package/dist/lib/renderer/render.js +150 -120
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color.js +5 -5
- package/dist/lib/syntax/color/utils/colorspace.js +3 -3
- package/dist/lib/syntax/color/utils/components.js +21 -22
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +22 -3
- package/dist/lib/syntax/syntax.js +252 -311
- package/dist/lib/validation/config.js +16 -17
- package/dist/lib/validation/match.js +1118 -1131
- package/dist/lib/validation/parser/parse.js +130 -286
- package/dist/node.js +16 -12
- package/dist/web.js +10 -8
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { tokensfuncDefMap,
|
|
3
|
-
import { matchAllSyntaxes, createValidationContext, trimArray
|
|
2
|
+
import { tokensfuncDefMap, LOC, mFGT, mFLT } from '../../syntax/constants.js';
|
|
3
|
+
import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
|
|
4
4
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
5
5
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
6
|
-
import { parseColor } from '../../syntax/syntax.js';
|
|
7
6
|
|
|
8
7
|
function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
9
8
|
let matchCount = 0;
|
|
@@ -49,19 +48,19 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
49
48
|
(stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
|
|
50
49
|
tokens.push(stream[i++]);
|
|
51
50
|
}
|
|
52
|
-
if (i >= stream.length) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
51
|
+
// if (i >= stream.length) {
|
|
52
|
+
// return {
|
|
53
|
+
// success: false,
|
|
54
|
+
// errors: [
|
|
55
|
+
// {
|
|
56
|
+
// action: "drop",
|
|
57
|
+
// node: context,
|
|
58
|
+
// location: context[LOC],
|
|
59
|
+
// message: `expecting <container-condition> at ${context[LOC]?.src}:${context?.[LOC]?.sta.lin}:${context[LOC]?.sta.col}`,
|
|
60
|
+
// },
|
|
61
|
+
// ],
|
|
62
|
+
// };
|
|
63
|
+
// }
|
|
65
64
|
if (stream[i].typ === EnumToken.IdenTokenType) {
|
|
66
65
|
tokens.push(stream[i++]);
|
|
67
66
|
}
|
|
@@ -77,36 +76,34 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
77
76
|
{
|
|
78
77
|
action: "drop",
|
|
79
78
|
node: stream[i],
|
|
80
|
-
location: stream[i]?.
|
|
81
|
-
message: `expecting <container-condition> at ${
|
|
79
|
+
location: stream[i]?.[LOC], // ?? context[LOC],
|
|
80
|
+
message: `expecting <container-condition> at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
82
81
|
},
|
|
83
82
|
],
|
|
84
83
|
};
|
|
85
84
|
}
|
|
86
|
-
if (stream[i]?.typ === EnumToken.IdenTokenType) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
}
|
|
85
|
+
// if (stream[i]?.typ === EnumToken.IdenTokenType) {
|
|
86
|
+
// const val: string = (stream[i] as IdentToken).val.toLowerCase();
|
|
87
|
+
// if ("not" === val) {
|
|
88
|
+
// tokens.push(stream[i]);
|
|
89
|
+
// stack.push(Object.assign(stream[i], { typ: EnumToken.NotTokenType }));
|
|
90
|
+
// i++;
|
|
91
|
+
// } else if ("and" === val || "or" === val) {
|
|
92
|
+
// return {
|
|
93
|
+
// success: false,
|
|
94
|
+
// errors: [
|
|
95
|
+
// {
|
|
96
|
+
// action: "drop",
|
|
97
|
+
// node: stream[i],
|
|
98
|
+
// location: stream[i]?.[LOC],
|
|
99
|
+
// message: `unexpected token at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
100
|
+
// },
|
|
101
|
+
// ],
|
|
102
|
+
// };
|
|
103
|
+
// } else {
|
|
104
|
+
// tokens.push(stream[i++]);
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
110
107
|
for (; i < stream.length; i++) {
|
|
111
108
|
tokens.push(stream[i]);
|
|
112
109
|
if (stream[i].typ === EnumToken.WhitespaceTokenType || stream[i].typ === EnumToken.CommentTokenType) {
|
|
@@ -114,23 +111,22 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
114
111
|
}
|
|
115
112
|
if (expectAndOr) {
|
|
116
113
|
let valid = true;
|
|
117
|
-
if (stream[i].typ === EnumToken.IdenTokenType) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
114
|
+
// if (stream[i].typ === EnumToken.IdenTokenType) {
|
|
115
|
+
// const val: string = (stream[i] as IdentToken).val.toLowerCase();
|
|
116
|
+
// valid = val === "and" || val === "or";
|
|
117
|
+
// } else {
|
|
118
|
+
valid = stream[i].typ !== EnumToken.CommaTokenType;
|
|
119
|
+
// }
|
|
124
120
|
if (!valid) {
|
|
125
121
|
success = false;
|
|
126
122
|
errors.push({
|
|
127
123
|
action: "drop",
|
|
128
124
|
node: stream[i],
|
|
129
|
-
message: `expecting <and>, <or> or comma at ${stream[i]?.
|
|
125
|
+
message: `expecting <and>, <or> or comma at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
130
126
|
});
|
|
131
127
|
break;
|
|
132
128
|
}
|
|
133
|
-
expectAndOr = false;
|
|
129
|
+
// expectAndOr = false;
|
|
134
130
|
}
|
|
135
131
|
if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
|
|
136
132
|
scopes.push((currentScope = new Set()));
|
|
@@ -138,14 +134,14 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
138
134
|
continue;
|
|
139
135
|
}
|
|
140
136
|
switch (stream[i].typ) {
|
|
141
|
-
case EnumToken.LiteralTokenType:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
// case EnumToken.LiteralTokenType:
|
|
138
|
+
// if ((stream[i] as LiteralToken).val === "<") {
|
|
139
|
+
// stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
|
|
140
|
+
// }
|
|
141
|
+
// if ((stream[i] as LiteralToken).val === ">") {
|
|
142
|
+
// stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
|
|
143
|
+
// }
|
|
144
|
+
// break;
|
|
149
145
|
case EnumToken.ColonTokenType:
|
|
150
146
|
case EnumToken.LtTokenType:
|
|
151
147
|
case EnumToken.LteTokenType:
|
|
@@ -172,210 +168,215 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
172
168
|
errors.push({
|
|
173
169
|
action: "drop",
|
|
174
170
|
node: stream[i],
|
|
175
|
-
message: `<or> is not allowed outside of parentheses ${stream[i]?.
|
|
176
|
-
});
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
180
|
-
success = false;
|
|
181
|
-
errors.push({
|
|
182
|
-
action: "drop",
|
|
183
|
-
node: stream[i],
|
|
184
|
-
message: `cannot mix <and> and <or> at the same level at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
|
|
171
|
+
message: `<or> is not allowed outside of parentheses ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
185
172
|
});
|
|
186
173
|
break;
|
|
187
174
|
}
|
|
175
|
+
// if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
176
|
+
// success = false;
|
|
177
|
+
// errors.push({
|
|
178
|
+
// action: "drop",
|
|
179
|
+
// node: stream[i],
|
|
180
|
+
// message: `cannot mix <and> and <or> at the same level at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
181
|
+
// });
|
|
182
|
+
// break;
|
|
183
|
+
// }
|
|
188
184
|
currentScope.add(stream[i].typ);
|
|
189
185
|
stack.push(stream[i]);
|
|
190
186
|
}
|
|
191
|
-
else if (scopes.length === 0) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
187
|
+
// else if (scopes.length === 0) {
|
|
188
|
+
// success = false;
|
|
189
|
+
// errors.push({
|
|
190
|
+
// action: "drop",
|
|
191
|
+
// node: stream[i],
|
|
192
|
+
// location: stream[i]?.[LOC],
|
|
193
|
+
// message: `unexpected <ident> at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
194
|
+
// });
|
|
195
|
+
// return {
|
|
196
|
+
// success,
|
|
197
|
+
// errors,
|
|
198
|
+
// };
|
|
199
|
+
// }
|
|
204
200
|
}
|
|
205
201
|
break;
|
|
206
202
|
case EnumToken.EndParensTokenType:
|
|
207
203
|
// feature
|
|
208
|
-
if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
});
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
204
|
+
// if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
|
|
205
|
+
// // <mf-lt> | <mf-gt>
|
|
206
|
+
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
207
|
+
// const prevToken: Token = stack[stack.length - 2];
|
|
208
|
+
// if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
|
|
209
|
+
// if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
|
|
210
|
+
// success = false;
|
|
211
|
+
// errors.push({
|
|
212
|
+
// action: "drop",
|
|
213
|
+
// node: stream[i],
|
|
214
|
+
// message: `unmatched '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
215
|
+
// });
|
|
216
|
+
// break;
|
|
217
|
+
// }
|
|
218
|
+
// if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
|
|
219
|
+
// success = false;
|
|
220
|
+
// errors.push({
|
|
221
|
+
// action: "drop",
|
|
222
|
+
// node: stack.at(-1),
|
|
223
|
+
// message: `expected <mf-lt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
224
|
+
// });
|
|
225
|
+
// break;
|
|
226
|
+
// } else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
|
|
227
|
+
// success = false;
|
|
228
|
+
// errors.push({
|
|
229
|
+
// action: "drop",
|
|
230
|
+
// node: stream[i],
|
|
231
|
+
// message: `expected <mf-gt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
232
|
+
// });
|
|
233
|
+
// break;
|
|
234
|
+
// }
|
|
235
|
+
// // <style-range>
|
|
236
|
+
// // const index: number = tokens.indexOf(stack.at(-1)!);
|
|
237
|
+
// // <mf-lt> | <mf-gt>
|
|
238
|
+
// const index2: number = tokens.indexOf(prevToken);
|
|
239
|
+
// // '('
|
|
240
|
+
// const index3: number = tokens.indexOf(stack.at(-3)!);
|
|
241
|
+
// const left: Token[] = trimArray(tokens.slice(index3 + 1, index2));
|
|
242
|
+
// const right: Token[] = trimArray(tokens.slice(index + 1, tokens.length - 1));
|
|
243
|
+
// const names: Token[] = trimArray(tokens.slice(index2 + 1, index));
|
|
244
|
+
// if (!isStyleFeatureValue(left)) {
|
|
245
|
+
// success = false;
|
|
246
|
+
// errors.push({
|
|
247
|
+
// action: "drop",
|
|
248
|
+
// node: left[0],
|
|
249
|
+
// message: `expected <style-feature-value> at ${left[0]?.[LOC]?.src}:${left[0]?.[LOC]?.sta.lin}:${left[0]?.[LOC]?.sta.col}`,
|
|
250
|
+
// });
|
|
251
|
+
// break;
|
|
252
|
+
// }
|
|
253
|
+
// if (!isStyleFeatureValue(right)) {
|
|
254
|
+
// success = false;
|
|
255
|
+
// errors.push({
|
|
256
|
+
// action: "drop",
|
|
257
|
+
// node: right[0],
|
|
258
|
+
// message: `expected <style-feature-value> at ${right[0]?.[LOC]?.src}:${right[0]?.[LOC]?.sta.lin}:${right[0]?.[LOC]?.sta.col}`,
|
|
259
|
+
// });
|
|
260
|
+
// break;
|
|
261
|
+
// }
|
|
262
|
+
// if (!isStyleFeatureValue(names)) {
|
|
263
|
+
// success = false;
|
|
264
|
+
// errors.push({
|
|
265
|
+
// action: "drop",
|
|
266
|
+
// node: names[0],
|
|
267
|
+
// message: `expected <style-feature-value> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
|
|
268
|
+
// });
|
|
269
|
+
// break;
|
|
270
|
+
// }
|
|
271
|
+
// tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
272
|
+
// typ: EnumToken.ContainerStyleRangeTokenType,
|
|
273
|
+
// l: left,
|
|
274
|
+
// op: names,
|
|
275
|
+
// r: right,
|
|
276
|
+
// [LOC]: { ...left[0][LOC]!, end: right.at(-1)![LOC]!.end },
|
|
277
|
+
// } as ContainerStyleRangeToken);
|
|
278
|
+
// // check <style()> or <scroll-state()>
|
|
279
|
+
// stack.pop();
|
|
280
|
+
// stack.pop();
|
|
281
|
+
// } else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
282
|
+
// success = false;
|
|
283
|
+
// errors.push({
|
|
284
|
+
// action: "drop",
|
|
285
|
+
// node: stream[i],
|
|
286
|
+
// location: stream[i]?.[LOC],
|
|
287
|
+
// message: `expected '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
288
|
+
// });
|
|
289
|
+
// break;
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
300
292
|
if (mFGT.has(stack.at(-1)?.typ) ||
|
|
301
293
|
mFLT.has(stack.at(-1)?.typ) ||
|
|
302
294
|
stack.at(-1)?.typ === EnumToken.DelimTokenType ||
|
|
303
295
|
stack.at(-1)?.typ === EnumToken.ColonTokenType) {
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
296
|
+
stack[stack.length - 2].val?.toLowerCase?.();
|
|
297
|
+
// if (
|
|
298
|
+
// stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType &&
|
|
299
|
+
// !(
|
|
300
|
+
// stack[stack.length - 2]?.typ === EnumToken.ContainerFunctionTokenDefType &&
|
|
301
|
+
// ("style" === funcName || "scroll-state" === funcName)
|
|
302
|
+
// )
|
|
303
|
+
// ) {
|
|
304
|
+
// success = false;
|
|
305
|
+
// errors.push({
|
|
306
|
+
// action: "drop",
|
|
307
|
+
// node: stream[i],
|
|
308
|
+
// location: stream[i]?.[LOC],
|
|
309
|
+
// message: `unmatched2 ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
310
|
+
// });
|
|
311
|
+
// break;
|
|
312
|
+
// }
|
|
317
313
|
const index2 = tokens.indexOf(stack.at(-1));
|
|
318
314
|
const index3 = tokens.indexOf(stack.at(-2));
|
|
319
315
|
let names = trimArray(tokens.slice(index3 + 1, index2));
|
|
320
316
|
let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
317
|
+
// if (
|
|
318
|
+
// stack.at(-1)?.typ !== EnumToken.ColonTokenType &&
|
|
319
|
+
// stack.at(-1)?.typ !== EnumToken.DelimTokenType
|
|
320
|
+
// ) {
|
|
321
|
+
// const filteredNames = names.filter(
|
|
322
|
+
// (n) =>
|
|
323
|
+
// n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
|
|
324
|
+
// );
|
|
325
|
+
// if (
|
|
326
|
+
// filteredNames.length !== 1 ||
|
|
327
|
+
// (filteredNames[0].typ !== EnumToken.IdenTokenType &&
|
|
328
|
+
// filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
|
|
329
|
+
// ) {
|
|
330
|
+
// }
|
|
331
|
+
// }
|
|
332
|
+
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
326
333
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
327
334
|
l: names,
|
|
328
335
|
op: stack.pop(),
|
|
329
336
|
r: values,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
value: { ...names[0].loc, end: values.at(-1).loc.end },
|
|
333
|
-
}));
|
|
337
|
+
[LOC]: { ...names[0][LOC], end: values.at(-1)[LOC].end },
|
|
338
|
+
});
|
|
334
339
|
// check <style()> or <scroll-state()>
|
|
335
340
|
}
|
|
336
341
|
if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
337
342
|
const index = tokens.indexOf(stack.at(-1));
|
|
338
|
-
Object.
|
|
343
|
+
Object.assign(tokens[index], {
|
|
339
344
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
340
345
|
chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
|
|
341
|
-
}), "loc", {
|
|
342
|
-
...definedPropertySettings,
|
|
343
|
-
value: { ...tokens[index].loc, end: stream[i].loc.end },
|
|
344
346
|
});
|
|
347
|
+
tokens[index][LOC] = { ...tokens[index][LOC], end: stream[i][LOC].end };
|
|
345
348
|
if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
|
|
346
349
|
success = false;
|
|
347
350
|
errors.push({
|
|
348
351
|
action: "drop",
|
|
349
352
|
node: stream[i],
|
|
350
|
-
location: stream[i]?.
|
|
351
|
-
message: `expecting '<${tokens[index].val}-query>' at ${stream[i]?.
|
|
353
|
+
location: stream[i]?.[LOC],
|
|
354
|
+
message: `expecting '<${tokens[index].val}-query>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
352
355
|
});
|
|
353
356
|
break;
|
|
354
357
|
}
|
|
355
358
|
tokens.length = index + 1;
|
|
356
|
-
if (EnumToken.ColorTokenType === tokens[index].typ) {
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
+
// if (EnumToken.ColorTokenType === tokens[index].typ) {
|
|
360
|
+
// parseColor(tokens[index]);
|
|
361
|
+
// }
|
|
359
362
|
stack.pop();
|
|
360
363
|
scopes.pop();
|
|
361
364
|
currentScope = scopes.at(-1);
|
|
362
365
|
}
|
|
363
366
|
else {
|
|
364
367
|
const index = tokens.indexOf(stack.at(-1));
|
|
365
|
-
tokens[index] =
|
|
368
|
+
tokens[index] = {
|
|
366
369
|
typ: EnumToken.ParensTokenType,
|
|
367
370
|
chi: tokens.slice(index + 1, tokens.length - 1),
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
value: { ...tokens[index].loc, end: stream[i].loc.end },
|
|
371
|
-
});
|
|
371
|
+
[LOC]: { ...tokens[index][LOC], end: stream[i][LOC].end },
|
|
372
|
+
};
|
|
372
373
|
if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
|
|
373
374
|
success = false;
|
|
374
375
|
errors.push({
|
|
375
376
|
action: "drop",
|
|
376
377
|
node: stream[i],
|
|
377
|
-
location: stream[i]?.
|
|
378
|
-
message: `expecting '<query-in-parens>' at ${stream[i]?.
|
|
378
|
+
location: stream[i]?.[LOC],
|
|
379
|
+
message: `expecting '<query-in-parens>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
379
380
|
});
|
|
380
381
|
break;
|
|
381
382
|
}
|
|
@@ -396,23 +397,21 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
396
397
|
errors.push({
|
|
397
398
|
action: "drop",
|
|
398
399
|
node: tokens[k],
|
|
399
|
-
location: tokens[k]?.
|
|
400
|
-
message: `unexpected token 'not' at ${tokens[k]?.
|
|
400
|
+
location: tokens[k]?.[LOC],
|
|
401
|
+
message: `unexpected token 'not' at ${tokens[k]?.[LOC]?.src}:${tokens[k]?.[LOC]?.sta.lin}:${tokens[k]?.[LOC]?.sta.col}`,
|
|
401
402
|
});
|
|
402
403
|
break;
|
|
403
404
|
}
|
|
404
405
|
}
|
|
405
|
-
const index = tokens.indexOf(stack.at(-1));
|
|
406
|
-
const slice = trimArray(tokens.slice(index + 1));
|
|
407
|
-
tokens[index] =
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
},
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
});
|
|
415
|
-
tokens.length = index + 1;
|
|
406
|
+
// const index = tokens.indexOf(stack.at(-1)!);
|
|
407
|
+
// const slice = trimArray(tokens.slice(index + 1));
|
|
408
|
+
// tokens[index] = {
|
|
409
|
+
// typ: EnumToken.MediaQueryUnaryFeatureTokenType,
|
|
410
|
+
// l: stack.pop()!,
|
|
411
|
+
// r: slice,
|
|
412
|
+
// [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end },
|
|
413
|
+
// };
|
|
414
|
+
// tokens.length = index + 1;
|
|
416
415
|
}
|
|
417
416
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
|
|
418
417
|
stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
@@ -425,38 +424,36 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
425
424
|
}
|
|
426
425
|
const left = trimArray(tokens.slice(l, index));
|
|
427
426
|
const right = trimArray(tokens.slice(index + 1));
|
|
428
|
-
tokens[l] =
|
|
427
|
+
tokens[l] = {
|
|
429
428
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
430
429
|
op: stack.pop(),
|
|
431
430
|
l: left,
|
|
432
431
|
r: right,
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
value: { ...left[0].loc, end: right.at(-1).loc.end },
|
|
436
|
-
});
|
|
432
|
+
[LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
|
|
433
|
+
};
|
|
437
434
|
tokens.length = l + 1;
|
|
438
435
|
expectAndOr = true;
|
|
439
436
|
}
|
|
440
437
|
break;
|
|
441
|
-
default:
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
438
|
+
// default:
|
|
439
|
+
// if (tokensfuncDefMap.has(stream[i]?.typ)) {
|
|
440
|
+
// stack.push(stream[i]);
|
|
441
|
+
// scopes.push((currentScope = new Set()));
|
|
442
|
+
// }
|
|
443
|
+
// break;
|
|
447
444
|
}
|
|
448
445
|
if (!success) {
|
|
449
446
|
break;
|
|
450
447
|
}
|
|
451
448
|
}
|
|
452
|
-
if (success && stack.length > 0) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
449
|
+
// if (success && stack.length > 0) {
|
|
450
|
+
// success = false;
|
|
451
|
+
// errors.push({
|
|
452
|
+
// action: "drop",
|
|
453
|
+
// node: stack.at(-1),
|
|
454
|
+
// message: `unmatched token '${EnumToken[stack.at(-1)?.typ]}' at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
455
|
+
// });
|
|
456
|
+
// }
|
|
460
457
|
if (!success) {
|
|
461
458
|
return {
|
|
462
459
|
success,
|
|
@@ -471,9 +468,9 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
|
|
|
471
468
|
stream.push(...parts
|
|
472
469
|
.filter((p) => p.length > 0 && p[0].typ !== EnumToken.InvalidMediaQueryTokenType)
|
|
473
470
|
.reduce((acc, b) => {
|
|
474
|
-
if (acc.length > 0) {
|
|
475
|
-
|
|
476
|
-
}
|
|
471
|
+
// if (acc.length > 0) {
|
|
472
|
+
// acc.push({ typ: EnumToken.CommaTokenType });
|
|
473
|
+
// }
|
|
477
474
|
acc.push(...b);
|
|
478
475
|
return acc;
|
|
479
476
|
}, []));
|