@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,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,132 @@ 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
|
-
if (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
376
|
+
if (stack.length > 0 &&
|
|
377
|
+
(mFGT.has(stack.at(-1)?.typ) ||
|
|
378
|
+
mFLT.has(stack.at(-1)?.typ) ||
|
|
379
|
+
stack.at(-1)?.typ === EnumToken.DelimTokenType ||
|
|
380
|
+
stack.at(-1)?.typ === EnumToken.ColonTokenType)) {
|
|
381
|
+
// if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
382
|
+
// success = false;
|
|
383
|
+
// errors.push({
|
|
384
|
+
// action: "drop",
|
|
385
|
+
// node: stream[i],
|
|
386
|
+
// location: stream[i]?.[LOC],
|
|
387
|
+
// 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}`,
|
|
388
|
+
// });
|
|
389
|
+
// break;
|
|
390
|
+
// }
|
|
394
391
|
const index2 = tokens.indexOf(stack.at(-1));
|
|
395
392
|
const index3 = tokens.indexOf(stack.at(-2));
|
|
396
393
|
let names = trimArray(tokens.slice(index3 + 1, index2));
|
|
397
394
|
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
|
-
|
|
395
|
+
// if (stack.at(-1)?.typ !== EnumToken.ColonTokenType) {
|
|
396
|
+
// const filteredNames = names.filter(
|
|
397
|
+
// (n) =>
|
|
398
|
+
// n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
|
|
399
|
+
// );
|
|
400
|
+
// if (
|
|
401
|
+
// filteredNames.length !== 1 ||
|
|
402
|
+
// (filteredNames[0].typ !== EnumToken.IdenTokenType &&
|
|
403
|
+
// filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
|
|
404
|
+
// ) {
|
|
405
|
+
// swapped = true;
|
|
406
|
+
// }
|
|
407
|
+
// }
|
|
408
|
+
const filteredNames = (names).filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
|
|
409
|
+
// if (
|
|
410
|
+
// filteredNames.length !== 1 ||
|
|
411
|
+
// (filteredNames[0].typ !== EnumToken.IdenTokenType &&
|
|
412
|
+
// filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
|
|
413
|
+
// ) {
|
|
414
|
+
// success = false;
|
|
415
|
+
// errors.push({
|
|
416
|
+
// action: "drop",
|
|
417
|
+
// node: names[0] ?? stack.at(-1),
|
|
418
|
+
// location: names[0]?.[LOC],
|
|
419
|
+
// 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}`,
|
|
420
|
+
// });
|
|
421
|
+
// break;
|
|
422
|
+
// }
|
|
420
423
|
const name = filteredNames[0].val;
|
|
421
|
-
if (!isMFName(name)) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
424
|
+
// if (!isMFName(name)) {
|
|
425
|
+
// success = false;
|
|
426
|
+
// errors.push({
|
|
427
|
+
// action: "drop",
|
|
428
|
+
// node: names[0] ?? stack.at(-1),
|
|
429
|
+
// location: names[0]?.[LOC] ?? stack.at(-1)?.[LOC],
|
|
430
|
+
// message: `expected <mf-name> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
|
|
431
|
+
// });
|
|
432
|
+
// break;
|
|
433
|
+
// }
|
|
431
434
|
const mfInfo = getMFInfo(name);
|
|
432
435
|
if (options.computeCalcExpression) {
|
|
433
436
|
if (mfInfo == null ||
|
|
434
437
|
(mfInfo.type != MediaFeatureType.KeywordType &&
|
|
435
438
|
mfInfo.type != MediaFeatureType.StringType)) {
|
|
436
|
-
const val =
|
|
439
|
+
const val = values;
|
|
437
440
|
for (let l = 0; l < val.length; l++) {
|
|
438
441
|
if (val[l].typ === EnumToken.MathFunctionTokenType &&
|
|
439
442
|
val[l].val === "calc") {
|
|
440
443
|
const value = evaluate([val[l]]);
|
|
441
444
|
if (value.length == 1) {
|
|
442
|
-
if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
445
|
+
// if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
446
|
+
// if (
|
|
447
|
+
// value[0].typ !== EnumToken.NumberTokenType ||
|
|
448
|
+
// !(
|
|
449
|
+
// ((value[0] as NumberToken).val as FractionToken)?.typ ===
|
|
450
|
+
// EnumToken.FractionTokenType
|
|
451
|
+
// )
|
|
452
|
+
// ) {
|
|
453
|
+
// continue;
|
|
454
|
+
// }
|
|
455
|
+
// }
|
|
456
|
+
value[0][LOC] = val[l][LOC];
|
|
453
457
|
val[l] = value[0];
|
|
454
458
|
}
|
|
455
459
|
}
|
|
456
460
|
}
|
|
457
461
|
}
|
|
458
462
|
}
|
|
459
|
-
const mfValue = isMFValue(name,
|
|
463
|
+
const mfValue = isMFValue(name, values, mFGT.has(stack.at(-1)?.typ) ||
|
|
460
464
|
mFLT.has(stack.at(-1)?.typ) ||
|
|
461
465
|
stack.at(-1)?.typ === EnumToken.DelimTokenType);
|
|
462
466
|
if (!mfValue.success) {
|
|
463
467
|
success = false;
|
|
464
|
-
const arr =
|
|
468
|
+
const arr = values;
|
|
465
469
|
errors.push({
|
|
466
470
|
action: "drop",
|
|
467
471
|
node: arr[0],
|
|
468
|
-
location: arr[0]?.
|
|
469
|
-
message: `${mfValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${arr[0]?.
|
|
472
|
+
location: arr[0]?.[LOC],
|
|
473
|
+
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
474
|
});
|
|
471
475
|
break;
|
|
472
476
|
}
|
|
473
477
|
if (mfInfo?.type === MediaFeatureType.RatioType) {
|
|
474
|
-
const val =
|
|
478
|
+
const val = values;
|
|
475
479
|
const filteredValues = val.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
|
|
476
480
|
if (filteredValues.length === 3) {
|
|
477
481
|
if (options.computeCalcExpression) {
|
|
@@ -486,53 +490,52 @@ function parseMediaqueryList(stream, options) {
|
|
|
486
490
|
val.splice(0, val.length, ...filteredValues);
|
|
487
491
|
}
|
|
488
492
|
}
|
|
489
|
-
tokens.splice(index3 + 1, tokens.length - index3 - 2,
|
|
493
|
+
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
490
494
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
491
495
|
l: names,
|
|
492
496
|
op: stack.pop(),
|
|
493
497
|
r: values,
|
|
494
|
-
|
|
495
|
-
...
|
|
496
|
-
|
|
497
|
-
}));
|
|
498
|
+
// @ts-expect-error
|
|
499
|
+
[LOC]: { ...names[0][LOC], end: values.at(-1)[LOC].end },
|
|
500
|
+
});
|
|
498
501
|
}
|
|
499
502
|
if (stack.length === 0) {
|
|
500
503
|
success = false;
|
|
501
504
|
errors.push({
|
|
502
505
|
action: "drop",
|
|
503
506
|
node: stream[i],
|
|
504
|
-
location: stream[i]?.
|
|
505
|
-
message: `unmatched ')' at ${stream[i]?.
|
|
507
|
+
location: stream[i]?.[LOC],
|
|
508
|
+
message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
506
509
|
});
|
|
507
510
|
break;
|
|
508
511
|
}
|
|
509
512
|
{
|
|
510
513
|
const index = tokens.indexOf(stack.at(-1));
|
|
511
|
-
tokens[index] =
|
|
514
|
+
tokens[index] = {
|
|
512
515
|
typ: EnumToken.ParensTokenType,
|
|
513
516
|
chi: tokens.slice(index + 1, tokens.length - 1),
|
|
514
|
-
|
|
515
|
-
...
|
|
516
|
-
|
|
517
|
-
});
|
|
517
|
+
// @ts-expect-error
|
|
518
|
+
[LOC]: { ...tokens[index][LOC], end: stream[i][LOC].end },
|
|
519
|
+
};
|
|
518
520
|
tokens.length = index + 1;
|
|
519
521
|
scopes.pop();
|
|
520
522
|
currentScope = scopes.at(-1);
|
|
521
523
|
stack.pop();
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
524
|
+
// if (
|
|
525
|
+
// stack.at(-1)?.typ === EnumToken.NotTokenType ||
|
|
526
|
+
// stack.at(-1)?.typ === EnumToken.OnlyTokenType
|
|
527
|
+
// ) {
|
|
528
|
+
// const index = tokens.indexOf(stack.at(-1)!);
|
|
529
|
+
// const slice = trimArray(tokens.slice(index + 1));
|
|
530
|
+
// tokens[index] = {
|
|
531
|
+
// typ: EnumToken.MediaQueryUnaryFeatureTokenType,
|
|
532
|
+
// l: stack.pop()!,
|
|
533
|
+
// r: slice,
|
|
534
|
+
// // @ts-expect-error
|
|
535
|
+
// [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end } as Location,
|
|
536
|
+
// };
|
|
537
|
+
// tokens.length = index + 1;
|
|
538
|
+
// }
|
|
536
539
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
|
|
537
540
|
stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
538
541
|
const index = tokens.indexOf(stack.at(-1));
|
|
@@ -544,15 +547,13 @@ function parseMediaqueryList(stream, options) {
|
|
|
544
547
|
}
|
|
545
548
|
const left = trimArray(tokens.slice(l, index));
|
|
546
549
|
const right = trimArray(tokens.slice(index + 1));
|
|
547
|
-
tokens[l] =
|
|
550
|
+
tokens[l] = {
|
|
548
551
|
typ: EnumToken.MediaQueryConditionTokenType,
|
|
549
552
|
op: stack.pop(),
|
|
550
553
|
l: left,
|
|
551
554
|
r: right,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
value: { ...left[0].loc, end: right.at(-1).loc.end },
|
|
555
|
-
});
|
|
555
|
+
[LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
|
|
556
|
+
};
|
|
556
557
|
tokens.length = l + 1;
|
|
557
558
|
expectAndOrComma = true;
|
|
558
559
|
}
|
|
@@ -563,15 +564,15 @@ function parseMediaqueryList(stream, options) {
|
|
|
563
564
|
break;
|
|
564
565
|
}
|
|
565
566
|
}
|
|
566
|
-
if (success && stack.length > 0) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
567
|
+
// if (success && stack.length > 0) {
|
|
568
|
+
// success = false;
|
|
569
|
+
// errors.push({
|
|
570
|
+
// action: "drop",
|
|
571
|
+
// node: stack.at(-1),
|
|
572
|
+
// location: stack.at(-1)?.[LOC],
|
|
573
|
+
// 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}`,
|
|
574
|
+
// });
|
|
575
|
+
// }
|
|
575
576
|
if (!success) {
|
|
576
577
|
hasErrors = true;
|
|
577
578
|
parts.splice(parts.indexOf(stream), 1);
|