@tbela99/css-parser 1.4.6 → 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 +17 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6548 -6964
- package/dist/index.cjs +7784 -8198
- 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 -504
- 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 -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 +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,8 +1,8 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
2
|
import { evaluate } from '../../ast/math/expression.js';
|
|
3
3
|
import { gcd } from '../../ast/math/math.js';
|
|
4
|
-
import { tokensfuncDefMap, mediaTypes,
|
|
5
|
-
import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue
|
|
4
|
+
import { tokensfuncDefMap, mediaTypes, LOC, mFLT, mFGT } from '../../syntax/constants.js';
|
|
5
|
+
import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue } from '../../validation/match.js';
|
|
6
6
|
import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
|
|
7
7
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
8
8
|
|
|
@@ -51,61 +51,66 @@ function parseMediaqueryList(stream, options) {
|
|
|
51
51
|
if (i < stream.length) {
|
|
52
52
|
if (stream[i].typ === EnumToken.IdenTokenType) {
|
|
53
53
|
const val = stream[i].val.toLowerCase();
|
|
54
|
-
if ("not" === val || "only" === val) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
54
|
+
// if ("not" === val || "only" === val) {
|
|
55
|
+
// tokens.push(stream[i]);
|
|
56
|
+
// stack.push(stream[i]);
|
|
57
|
+
// i++;
|
|
58
|
+
// while (
|
|
59
|
+
// i < stream.length &&
|
|
60
|
+
// (stream[i]?.typ === EnumToken.WhitespaceTokenType ||
|
|
61
|
+
// stream[i]?.typ === EnumToken.CommentTokenType)
|
|
62
|
+
// ) {
|
|
63
|
+
// tokens.push(stream[i]);
|
|
64
|
+
// i++;
|
|
65
|
+
// }
|
|
66
|
+
// if (
|
|
67
|
+
// stream[i]?.typ !== EnumToken.IdenTokenType ||
|
|
68
|
+
// !mediaTypes.includes((stream[i] as IdentToken).val.toLowerCase())
|
|
69
|
+
// ) {
|
|
70
|
+
// errors.push({
|
|
71
|
+
// action: "drop",
|
|
72
|
+
// node: stream[i],
|
|
73
|
+
// message: `expecting '<media-type>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
74
|
+
// });
|
|
75
|
+
// continue;
|
|
76
|
+
// }
|
|
77
|
+
// const index: number = tokens.indexOf(stack[stack.length - 1]);
|
|
78
|
+
// tokens[index][LOC] = { ...tokens[index][LOC]!, end: stream[i][LOC]!.end };
|
|
79
|
+
// tokens[index] = Object.assign(tokens[index], {
|
|
80
|
+
// typ: val === "not" ? EnumToken.NotTokenType : EnumToken.OnlyTokenType,
|
|
81
|
+
// val: stream[i],
|
|
82
|
+
// });
|
|
83
|
+
// tokens.length = index + 1;
|
|
84
|
+
// i++;
|
|
85
|
+
// // expect end of stream | and | or | not
|
|
86
|
+
// while (
|
|
87
|
+
// i < stream.length &&
|
|
88
|
+
// (stream[i]?.typ === EnumToken.WhitespaceTokenType ||
|
|
89
|
+
// stream[i]?.typ === EnumToken.CommentTokenType)
|
|
90
|
+
// ) {
|
|
91
|
+
// tokens.push(stream[i]);
|
|
92
|
+
// i++;
|
|
93
|
+
// }
|
|
94
|
+
// if (i < stream.length) {
|
|
95
|
+
// if (stream[i].typ === EnumToken.AndTokenType) {
|
|
96
|
+
// tokens.push(Object.assign(stream[i], { typ: EnumToken.AndTokenType }));
|
|
97
|
+
// stack.push(stream[i]);
|
|
98
|
+
// i++;
|
|
99
|
+
// } else if (stream[i].typ === EnumToken.OrTokenType) {
|
|
100
|
+
// tokens.push(Object.assign(stream[i], { typ: EnumToken.OrTokenType }));
|
|
101
|
+
// stack.push(stream[i]);
|
|
102
|
+
// i++;
|
|
103
|
+
// } else {
|
|
104
|
+
// success = false;
|
|
105
|
+
// errors.push({
|
|
106
|
+
// action: "drop",
|
|
107
|
+
// node: stream[i],
|
|
108
|
+
// message: `expecting 'and' or 'or' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
109
|
+
// });
|
|
110
|
+
// }
|
|
111
|
+
// }
|
|
112
|
+
// } else
|
|
113
|
+
if (mediaTypes.includes(val)) {
|
|
109
114
|
tokens.push(stream[i]);
|
|
110
115
|
i++;
|
|
111
116
|
}
|
|
@@ -113,9 +118,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
113
118
|
success = false;
|
|
114
119
|
errors.push({
|
|
115
120
|
action: "drop",
|
|
116
|
-
message: `expecting '<media-type>' at ${stream[i]?.
|
|
121
|
+
message: `expecting '<media-type>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
117
122
|
node: stream[i],
|
|
118
|
-
location: stream[i]
|
|
123
|
+
location: stream[i][LOC],
|
|
119
124
|
});
|
|
120
125
|
}
|
|
121
126
|
}
|
|
@@ -123,9 +128,9 @@ function parseMediaqueryList(stream, options) {
|
|
|
123
128
|
success = false;
|
|
124
129
|
errors.push({
|
|
125
130
|
action: "drop",
|
|
126
|
-
message: `expecting '(' at ${stream[i]?.
|
|
131
|
+
message: `expecting '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
127
132
|
node: stream[i],
|
|
128
|
-
location: stream[i]
|
|
133
|
+
location: stream[i][LOC],
|
|
129
134
|
});
|
|
130
135
|
}
|
|
131
136
|
}
|
|
@@ -135,23 +140,18 @@ function parseMediaqueryList(stream, options) {
|
|
|
135
140
|
continue;
|
|
136
141
|
}
|
|
137
142
|
if (expectAndOrComma) {
|
|
138
|
-
let valid = true;
|
|
139
143
|
if (stream[i].typ === EnumToken.IdenTokenType) {
|
|
140
|
-
|
|
141
|
-
valid = val === "and" || val === "or";
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
valid = stream[i].typ !== EnumToken.CommaTokenType;
|
|
145
|
-
}
|
|
146
|
-
if (!valid) {
|
|
147
|
-
success = false;
|
|
148
|
-
errors.push({
|
|
149
|
-
action: "drop",
|
|
150
|
-
node: stream[i],
|
|
151
|
-
message: `expecting <and>, <or> or comma at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
|
|
152
|
-
});
|
|
153
|
-
break;
|
|
144
|
+
stream[i].val.toLowerCase();
|
|
154
145
|
}
|
|
146
|
+
// if (!valid) {
|
|
147
|
+
// success = false;
|
|
148
|
+
// errors.push({
|
|
149
|
+
// action: "drop",
|
|
150
|
+
// node: stream[i],
|
|
151
|
+
// message: `expecting <and>, <or> or comma at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
152
|
+
// });
|
|
153
|
+
// break;
|
|
154
|
+
// }
|
|
155
155
|
expectAndOrComma = false;
|
|
156
156
|
}
|
|
157
157
|
if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
|
|
@@ -160,14 +160,14 @@ function parseMediaqueryList(stream, options) {
|
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
162
|
switch (stream[i].typ) {
|
|
163
|
-
case EnumToken.LiteralTokenType:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
// case EnumToken.LiteralTokenType:
|
|
164
|
+
// if ((stream[i] as LiteralToken).val === "<") {
|
|
165
|
+
// stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
|
|
166
|
+
// }
|
|
167
|
+
// if ((stream[i] as LiteralToken).val === ">") {
|
|
168
|
+
// stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
|
|
169
|
+
// }
|
|
170
|
+
// break;
|
|
171
171
|
case EnumToken.ColonTokenType:
|
|
172
172
|
case EnumToken.LtTokenType:
|
|
173
173
|
case EnumToken.LteTokenType:
|
|
@@ -179,13 +179,13 @@ function parseMediaqueryList(stream, options) {
|
|
|
179
179
|
case EnumToken.IdenTokenType:
|
|
180
180
|
{
|
|
181
181
|
const val = stream[i].val.toLowerCase();
|
|
182
|
-
if (val === "not" || val === "only") {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
182
|
+
// if (val === "not" || val === "only") {
|
|
183
|
+
// Object.assign(stream[i], {
|
|
184
|
+
// typ: val === "not" ? EnumToken.NotTokenType : EnumToken.OnlyTokenType,
|
|
185
|
+
// });
|
|
186
|
+
// stack.push(stream[i]);
|
|
187
|
+
// } else
|
|
188
|
+
if (val === "and" || val === "or") {
|
|
189
189
|
Object.assign(stream[i], {
|
|
190
190
|
typ: val === "and" ? EnumToken.AndTokenType : EnumToken.OrTokenType,
|
|
191
191
|
});
|
|
@@ -194,7 +194,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
194
194
|
errors.push({
|
|
195
195
|
action: "drop",
|
|
196
196
|
node: stream[i],
|
|
197
|
-
message: `<or> is not allowed outside of parentheses ${stream[i]?.
|
|
197
|
+
message: `<or> is not allowed outside of parentheses ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
198
198
|
});
|
|
199
199
|
break;
|
|
200
200
|
}
|
|
@@ -203,7 +203,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
203
203
|
errors.push({
|
|
204
204
|
action: "drop",
|
|
205
205
|
node: stream[i],
|
|
206
|
-
message: `cannot mix <and> and <or> at the same level at ${stream[i]?.
|
|
206
|
+
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}`,
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
209
|
currentScope.add(stream[i].typ);
|
|
@@ -214,12 +214,10 @@ function parseMediaqueryList(stream, options) {
|
|
|
214
214
|
case EnumToken.EndParensTokenType:
|
|
215
215
|
if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
216
216
|
const index = tokens.indexOf(stack.at(-1));
|
|
217
|
-
|
|
217
|
+
tokens[index][LOC] = { ...tokens[index][LOC], end: stream[i][LOC].end };
|
|
218
|
+
Object.assign(tokens[index], {
|
|
218
219
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
219
220
|
chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
|
|
220
|
-
}), "loc", {
|
|
221
|
-
...definedPropertySettings,
|
|
222
|
-
value: { ...tokens[index].loc, end: stream[i].loc.end },
|
|
223
221
|
});
|
|
224
222
|
tokens.length = index + 1;
|
|
225
223
|
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
|
|
@@ -238,33 +236,32 @@ function parseMediaqueryList(stream, options) {
|
|
|
238
236
|
const index = tokens.indexOf(stack.at(-1));
|
|
239
237
|
const prevToken = stack[stack.length - 2];
|
|
240
238
|
if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
|
|
241
|
-
if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
239
|
+
// if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
|
|
240
|
+
// success = false;
|
|
241
|
+
// errors.push({
|
|
242
|
+
// action: "drop",
|
|
243
|
+
// node: stream[i],
|
|
244
|
+
// message: `unmatched '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
245
|
+
// });
|
|
246
|
+
// break;
|
|
247
|
+
// }
|
|
248
|
+
// if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
|
|
249
|
+
// success = false;
|
|
250
|
+
// errors.push({
|
|
251
|
+
// action: "drop",
|
|
252
|
+
// node: stack.at(-1),
|
|
253
|
+
// message: `expected <mf-lt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
254
|
+
// });
|
|
255
|
+
// break;
|
|
256
|
+
// } else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
|
|
257
|
+
// success = false;
|
|
258
|
+
// errors.push({
|
|
259
|
+
// action: "drop",
|
|
260
|
+
// node: stream[i],
|
|
261
|
+
// message: `expected <mf-gt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
262
|
+
// });
|
|
263
|
+
// break;
|
|
264
|
+
// }
|
|
268
265
|
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
269
266
|
// <mf-lt> | <mf-name>
|
|
270
267
|
const index2 = tokens.indexOf(prevToken);
|
|
@@ -274,15 +271,15 @@ function parseMediaqueryList(stream, options) {
|
|
|
274
271
|
const right = trimArray(tokens.slice(index + 1, tokens.length - 1));
|
|
275
272
|
const names = trimArray(tokens.slice(index2 + 1, index));
|
|
276
273
|
const filteredNames = names.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
|
|
277
|
-
if (filteredNames.length !== 1 || filteredNames[0].typ !== EnumToken.IdenTokenType) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
274
|
+
// if (filteredNames.length !== 1 || filteredNames[0].typ !== EnumToken.IdenTokenType) {
|
|
275
|
+
// success = false;
|
|
276
|
+
// errors.push({
|
|
277
|
+
// action: "drop",
|
|
278
|
+
// node: stream[i],
|
|
279
|
+
// message: `expected <mf-name>> at ${filteredNames[0]?.[LOC]?.src}:${filteredNames[0]?.[LOC]?.sta.lin}:${filteredNames[0]?.[LOC]?.sta.col}`,
|
|
280
|
+
// });
|
|
281
|
+
// break;
|
|
282
|
+
// }
|
|
286
283
|
const name = filteredNames[0].val;
|
|
287
284
|
const mfInfo = getMFInfo(name);
|
|
288
285
|
for (const val of [left, right]) {
|
|
@@ -295,17 +292,18 @@ function parseMediaqueryList(stream, options) {
|
|
|
295
292
|
val[l].val === "calc") {
|
|
296
293
|
const value = evaluate([val[l]]);
|
|
297
294
|
if (value.length == 1) {
|
|
298
|
-
if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
295
|
+
// if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
296
|
+
// if (
|
|
297
|
+
// value[0].typ !== EnumToken.NumberTokenType ||
|
|
298
|
+
// !(
|
|
299
|
+
// ((value[0] as NumberToken).val as FractionToken)
|
|
300
|
+
// ?.typ === EnumToken.FractionTokenType
|
|
301
|
+
// )
|
|
302
|
+
// ) {
|
|
303
|
+
// continue;
|
|
304
|
+
// }
|
|
305
|
+
// }
|
|
306
|
+
value[0][LOC] = val[l][LOC];
|
|
309
307
|
val[l] = value[0];
|
|
310
308
|
}
|
|
311
309
|
}
|
|
@@ -313,27 +311,27 @@ function parseMediaqueryList(stream, options) {
|
|
|
313
311
|
}
|
|
314
312
|
}
|
|
315
313
|
}
|
|
316
|
-
|
|
317
|
-
if (isValidMFValue.valid && !isValidMFValue.success) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (isValidMFValue.valid && !isValidMFValue.success) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
314
|
+
isMFValue(name, left, true);
|
|
315
|
+
// if (isValidMFValue.valid && !isValidMFValue.success) {
|
|
316
|
+
// success = false;
|
|
317
|
+
// errors.push({
|
|
318
|
+
// action: "drop",
|
|
319
|
+
// node: left[0] ?? prevToken,
|
|
320
|
+
// message: `${isValidMFValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${(left[0] ?? prevToken)?.[LOC]?.src}:${(left[0] ?? prevToken)?.[LOC]?.sta.lin}:${(left[0] ?? prevToken)?.[LOC]?.sta.col}`,
|
|
321
|
+
// });
|
|
322
|
+
// break;
|
|
323
|
+
// }
|
|
324
|
+
isMFValue(name, right, true);
|
|
325
|
+
// if (isValidMFValue.valid && !isValidMFValue.success) {
|
|
326
|
+
// success = false;
|
|
327
|
+
// errors.push({
|
|
328
|
+
// action: "drop",
|
|
329
|
+
// node: right[0] ?? stream[i],
|
|
330
|
+
// location: (right[0] ?? stream[i])?.[LOC],
|
|
331
|
+
// message: `${isValidMFValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${(right[0] ?? stream[i])?.[LOC]?.src}:${(right[0] ?? stream[i])?.[LOC]?.sta.lin}:${(left[0] ?? stream[i])?.[LOC]?.sta.col}`,
|
|
332
|
+
// });
|
|
333
|
+
// break;
|
|
334
|
+
// }
|
|
337
335
|
for (const val of [left, right]) {
|
|
338
336
|
if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
339
337
|
const filteredValues = val.filter((n) => n.typ !== EnumToken.WhitespaceTokenType &&
|
|
@@ -352,126 +350,131 @@ function parseMediaqueryList(stream, options) {
|
|
|
352
350
|
}
|
|
353
351
|
}
|
|
354
352
|
}
|
|
355
|
-
tokens.splice(index3 + 1, tokens.length - index3 - 2,
|
|
353
|
+
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
356
354
|
typ: EnumToken.MediaRangeQueryTokenType,
|
|
357
355
|
l: left,
|
|
358
356
|
val: filteredNames,
|
|
359
357
|
op1: prevToken,
|
|
360
358
|
op2: stack.at(-1),
|
|
361
359
|
r: right,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
value: { ...left[0].loc, end: right.at(-1).loc.end },
|
|
365
|
-
}));
|
|
360
|
+
[LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
|
|
361
|
+
});
|
|
366
362
|
stack.pop();
|
|
367
363
|
stack.pop();
|
|
368
364
|
}
|
|
369
|
-
else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
365
|
+
// else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
366
|
+
// success = false;
|
|
367
|
+
// errors.push({
|
|
368
|
+
// action: "drop",
|
|
369
|
+
// node: stream[i],
|
|
370
|
+
// location: stream[i]?.[LOC],
|
|
371
|
+
// message: `expected '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
372
|
+
// });
|
|
373
|
+
// break;
|
|
374
|
+
// }
|
|
379
375
|
}
|
|
380
376
|
if (mFGT.has(stack.at(-1)?.typ) ||
|
|
381
377
|
mFLT.has(stack.at(-1)?.typ) ||
|
|
382
378
|
stack.at(-1)?.typ === EnumToken.DelimTokenType ||
|
|
383
379
|
stack.at(-1)?.typ === EnumToken.ColonTokenType) {
|
|
384
|
-
if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
380
|
+
// if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
381
|
+
// success = false;
|
|
382
|
+
// errors.push({
|
|
383
|
+
// action: "drop",
|
|
384
|
+
// node: stream[i],
|
|
385
|
+
// location: stream[i]?.[LOC],
|
|
386
|
+
// message: `expected '(' at ${(stack[stack.length - 2] ?? tokens[0])?.[LOC]?.src}:${(stack[stack.length - 2] ?? tokens[0])?.[LOC]?.sta.lin}:${(stack[stack.length - 2] ?? tokens[0])?.[LOC]?.sta.col}`,
|
|
387
|
+
// });
|
|
388
|
+
// break;
|
|
389
|
+
// }
|
|
394
390
|
const index2 = tokens.indexOf(stack.at(-1));
|
|
395
391
|
const index3 = tokens.indexOf(stack.at(-2));
|
|
396
392
|
let names = trimArray(tokens.slice(index3 + 1, index2));
|
|
397
393
|
let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
394
|
+
// if (stack.at(-1)?.typ !== EnumToken.ColonTokenType) {
|
|
395
|
+
// const filteredNames = names.filter(
|
|
396
|
+
// (n) =>
|
|
397
|
+
// n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
|
|
398
|
+
// );
|
|
399
|
+
// if (
|
|
400
|
+
// filteredNames.length !== 1 ||
|
|
401
|
+
// (filteredNames[0].typ !== EnumToken.IdenTokenType &&
|
|
402
|
+
// filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
|
|
403
|
+
// ) {
|
|
404
|
+
// swapped = true;
|
|
405
|
+
// }
|
|
406
|
+
// }
|
|
407
|
+
const filteredNames = (names).filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
|
|
408
|
+
// if (
|
|
409
|
+
// filteredNames.length !== 1 ||
|
|
410
|
+
// (filteredNames[0].typ !== EnumToken.IdenTokenType &&
|
|
411
|
+
// filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
|
|
412
|
+
// ) {
|
|
413
|
+
// success = false;
|
|
414
|
+
// errors.push({
|
|
415
|
+
// action: "drop",
|
|
416
|
+
// node: names[0] ?? stack.at(-1),
|
|
417
|
+
// location: names[0]?.[LOC],
|
|
418
|
+
// message: `expected <mf-name> at ${(names[0] ?? stack.at(-1))?.[LOC]?.src}:${(names[0] ?? stack.at(-1))?.[LOC]?.sta.lin}:${(names[0] ?? stack.at(-1))?.[LOC]?.sta.col}`,
|
|
419
|
+
// });
|
|
420
|
+
// break;
|
|
421
|
+
// }
|
|
420
422
|
const name = filteredNames[0].val;
|
|
421
|
-
if (!isMFName(name)) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
423
|
+
// if (!isMFName(name)) {
|
|
424
|
+
// success = false;
|
|
425
|
+
// errors.push({
|
|
426
|
+
// action: "drop",
|
|
427
|
+
// node: names[0] ?? stack.at(-1),
|
|
428
|
+
// location: names[0]?.[LOC] ?? stack.at(-1)?.[LOC],
|
|
429
|
+
// message: `expected <mf-name> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
|
|
430
|
+
// });
|
|
431
|
+
// break;
|
|
432
|
+
// }
|
|
431
433
|
const mfInfo = getMFInfo(name);
|
|
432
434
|
if (options.computeCalcExpression) {
|
|
433
435
|
if (mfInfo == null ||
|
|
434
436
|
(mfInfo.type != MediaFeatureType.KeywordType &&
|
|
435
437
|
mfInfo.type != MediaFeatureType.StringType)) {
|
|
436
|
-
const val =
|
|
438
|
+
const val = values;
|
|
437
439
|
for (let l = 0; l < val.length; l++) {
|
|
438
440
|
if (val[l].typ === EnumToken.MathFunctionTokenType &&
|
|
439
441
|
val[l].val === "calc") {
|
|
440
442
|
const value = evaluate([val[l]]);
|
|
441
443
|
if (value.length == 1) {
|
|
442
|
-
if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
444
|
+
// if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
445
|
+
// if (
|
|
446
|
+
// value[0].typ !== EnumToken.NumberTokenType ||
|
|
447
|
+
// !(
|
|
448
|
+
// ((value[0] as NumberToken).val as FractionToken)?.typ ===
|
|
449
|
+
// EnumToken.FractionTokenType
|
|
450
|
+
// )
|
|
451
|
+
// ) {
|
|
452
|
+
// continue;
|
|
453
|
+
// }
|
|
454
|
+
// }
|
|
455
|
+
value[0][LOC] = val[l][LOC];
|
|
453
456
|
val[l] = value[0];
|
|
454
457
|
}
|
|
455
458
|
}
|
|
456
459
|
}
|
|
457
460
|
}
|
|
458
461
|
}
|
|
459
|
-
const mfValue = isMFValue(name,
|
|
462
|
+
const mfValue = isMFValue(name, values, mFGT.has(stack.at(-1)?.typ) ||
|
|
460
463
|
mFLT.has(stack.at(-1)?.typ) ||
|
|
461
464
|
stack.at(-1)?.typ === EnumToken.DelimTokenType);
|
|
462
465
|
if (!mfValue.success) {
|
|
463
466
|
success = false;
|
|
464
|
-
const arr =
|
|
467
|
+
const arr = values;
|
|
465
468
|
errors.push({
|
|
466
469
|
action: "drop",
|
|
467
470
|
node: arr[0],
|
|
468
|
-
location: arr[0]?.
|
|
469
|
-
message: `${mfValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${arr[0]?.
|
|
471
|
+
location: arr[0]?.[LOC],
|
|
472
|
+
message: `${mfValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${arr[0]?.[LOC]?.src}:${arr[0]?.[LOC]?.sta.lin}:${arr[0]?.[LOC]?.sta.col}`,
|
|
470
473
|
});
|
|
471
474
|
break;
|
|
472
475
|
}
|
|
473
476
|
if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
474
|
-
const val =
|
|
477
|
+
const val = values;
|
|
475
478
|
const filteredValues = val.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
|
|
476
479
|
if (filteredValues.length === 3) {
|
|
477
480
|
if (options.computeCalcExpression) {
|
|
@@ -486,53 +489,52 @@ function parseMediaqueryList(stream, options) {
|
|
|
486
489
|
val.splice(0, val.length, ...filteredValues);
|
|
487
490
|
}
|
|
488
491
|
}
|
|
489
|
-
tokens.splice(index3 + 1, tokens.length - index3 - 2,
|
|
492
|
+
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
490
493
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
491
494
|
l: names,
|
|
492
495
|
op: stack.pop(),
|
|
493
496
|
r: values,
|
|
494
|
-
|
|
495
|
-
...
|
|
496
|
-
value: { ...names[0].loc, end: values.at(-1).loc.end },
|
|
497
|
-
}));
|
|
498
|
-
}
|
|
499
|
-
if (stack.length === 0) {
|
|
500
|
-
success = false;
|
|
501
|
-
errors.push({
|
|
502
|
-
action: "drop",
|
|
503
|
-
node: stream[i],
|
|
504
|
-
location: stream[i]?.loc,
|
|
505
|
-
message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
|
|
497
|
+
// @ts-expect-error
|
|
498
|
+
[LOC]: { ...names[0][LOC], end: values.at(-1)[LOC].end },
|
|
506
499
|
});
|
|
507
|
-
break;
|
|
508
500
|
}
|
|
501
|
+
// if (stack.length === 0) {
|
|
502
|
+
// success = false;
|
|
503
|
+
// errors.push({
|
|
504
|
+
// action: "drop",
|
|
505
|
+
// node: stream[i],
|
|
506
|
+
// location: stream[i]?.[LOC],
|
|
507
|
+
// message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
508
|
+
// });
|
|
509
|
+
// break;
|
|
510
|
+
// }
|
|
509
511
|
{
|
|
510
512
|
const index = tokens.indexOf(stack.at(-1));
|
|
511
|
-
tokens[index] =
|
|
513
|
+
tokens[index] = {
|
|
512
514
|
typ: EnumToken.ParensTokenType,
|
|
513
515
|
chi: tokens.slice(index + 1, tokens.length - 1),
|
|
514
|
-
|
|
515
|
-
...
|
|
516
|
-
|
|
517
|
-
});
|
|
516
|
+
// @ts-expect-error
|
|
517
|
+
[LOC]: { ...tokens[index][LOC], end: stream[i][LOC].end },
|
|
518
|
+
};
|
|
518
519
|
tokens.length = index + 1;
|
|
519
520
|
scopes.pop();
|
|
520
521
|
currentScope = scopes.at(-1);
|
|
521
522
|
stack.pop();
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
523
|
+
// if (
|
|
524
|
+
// stack.at(-1)?.typ === EnumToken.NotTokenType ||
|
|
525
|
+
// stack.at(-1)?.typ === EnumToken.OnlyTokenType
|
|
526
|
+
// ) {
|
|
527
|
+
// const index = tokens.indexOf(stack.at(-1)!);
|
|
528
|
+
// const slice = trimArray(tokens.slice(index + 1));
|
|
529
|
+
// tokens[index] = {
|
|
530
|
+
// typ: EnumToken.MediaQueryUnaryFeatureTokenType,
|
|
531
|
+
// l: stack.pop()!,
|
|
532
|
+
// r: slice,
|
|
533
|
+
// // @ts-expect-error
|
|
534
|
+
// [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end } as Location,
|
|
535
|
+
// };
|
|
536
|
+
// tokens.length = index + 1;
|
|
537
|
+
// }
|
|
536
538
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
|
|
537
539
|
stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
538
540
|
const index = tokens.indexOf(stack.at(-1));
|
|
@@ -544,15 +546,13 @@ function parseMediaqueryList(stream, options) {
|
|
|
544
546
|
}
|
|
545
547
|
const left = trimArray(tokens.slice(l, index));
|
|
546
548
|
const right = trimArray(tokens.slice(index + 1));
|
|
547
|
-
tokens[l] =
|
|
549
|
+
tokens[l] = {
|
|
548
550
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
549
551
|
op: stack.pop(),
|
|
550
552
|
l: left,
|
|
551
553
|
r: right,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
value: { ...left[0].loc, end: right.at(-1).loc.end },
|
|
555
|
-
});
|
|
554
|
+
[LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
|
|
555
|
+
};
|
|
556
556
|
tokens.length = l + 1;
|
|
557
557
|
expectAndOrComma = true;
|
|
558
558
|
}
|
|
@@ -563,15 +563,15 @@ function parseMediaqueryList(stream, options) {
|
|
|
563
563
|
break;
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
if (success && stack.length > 0) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
566
|
+
// if (success && stack.length > 0) {
|
|
567
|
+
// success = false;
|
|
568
|
+
// errors.push({
|
|
569
|
+
// action: "drop",
|
|
570
|
+
// node: stack.at(-1),
|
|
571
|
+
// location: stack.at(-1)?.[LOC],
|
|
572
|
+
// 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}`,
|
|
573
|
+
// });
|
|
574
|
+
// }
|
|
575
575
|
if (!success) {
|
|
576
576
|
hasErrors = true;
|
|
577
577
|
parts.splice(parts.indexOf(stream), 1);
|