@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,17 +1,9 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { renderValue } from '../../renderer/render.js';
|
|
3
2
|
import { trimArray } from '../../validation/match.js';
|
|
4
|
-
import { tokensfuncDefMap,
|
|
3
|
+
import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
|
|
5
4
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
6
5
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
7
|
-
import { equalsIgnoreCase } from './text.js';
|
|
8
6
|
|
|
9
|
-
const validChildTypes = new Set([
|
|
10
|
-
EnumToken.WhenElseFunctionTokenDefType,
|
|
11
|
-
EnumToken.WhenElseFunctionTokenType,
|
|
12
|
-
EnumToken.WhenElseQueryConditionTokenType,
|
|
13
|
-
EnumToken.WhenElseUnaryConditionTokenType,
|
|
14
|
-
]);
|
|
15
7
|
function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
16
8
|
const tokens = [];
|
|
17
9
|
const stack = [];
|
|
@@ -20,53 +12,59 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
20
12
|
let expectAndOr = false;
|
|
21
13
|
let scope = new Set();
|
|
22
14
|
const errors = [];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
15
|
+
// while (
|
|
16
|
+
// i < stream.length &&
|
|
17
|
+
// (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)
|
|
18
|
+
// ) {
|
|
19
|
+
// tokens.push(stream[i]);
|
|
20
|
+
// i++;
|
|
21
|
+
// }
|
|
22
|
+
// if (i >= stream.length) {
|
|
23
|
+
// success = "else" === context.nam;
|
|
24
|
+
// return {
|
|
25
|
+
// success,
|
|
26
|
+
// errors: success
|
|
27
|
+
// ? []
|
|
28
|
+
// : [
|
|
29
|
+
// {
|
|
30
|
+
// action: "drop",
|
|
31
|
+
// node: stream[i],
|
|
32
|
+
// location: stream[i]?.[LOC],
|
|
33
|
+
// message: `expecting '<boolean-condition>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
34
|
+
// },
|
|
35
|
+
// ],
|
|
36
|
+
// };
|
|
37
|
+
// }
|
|
38
|
+
// if (
|
|
39
|
+
// stream[i]?.typ !== EnumToken.WhenElseFunctionTokenDefType &&
|
|
40
|
+
// stream[i]?.typ !== EnumToken.SupportsFunctionTokenDefType &&
|
|
41
|
+
// stream[i]?.typ !== EnumToken.StartParensTokenType &&
|
|
42
|
+
// "val" in stream[i] &&
|
|
43
|
+
// !(
|
|
44
|
+
// stream[i]?.typ === EnumToken.IdenTokenType &&
|
|
45
|
+
// (equalsIgnoreCase((stream[i] as IdentToken).val, "not") ||
|
|
46
|
+
// equalsIgnoreCase((stream[i] as IdentToken).val, "only"))
|
|
47
|
+
// )
|
|
48
|
+
// ) {
|
|
49
|
+
// return {
|
|
50
|
+
// success: false,
|
|
51
|
+
// errors: [
|
|
52
|
+
// {
|
|
53
|
+
// action: "drop",
|
|
54
|
+
// node: stream[i],
|
|
55
|
+
// location: stream[i]?.[LOC],
|
|
56
|
+
// message: `expecting '<boolean-condition>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
57
|
+
// },
|
|
58
|
+
// ],
|
|
59
|
+
// };
|
|
60
|
+
// }
|
|
63
61
|
for (; i < stream.length; i++) {
|
|
64
62
|
tokens.push(stream[i]);
|
|
65
|
-
if (stream[i].typ === EnumToken.StartParensTokenType) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
63
|
+
// if (stream[i].typ === EnumToken.StartParensTokenType) {
|
|
64
|
+
// stack.push(stream[i]);
|
|
65
|
+
// scopes.push((scope = new Set()));
|
|
66
|
+
// continue;
|
|
67
|
+
// }
|
|
70
68
|
if (expectAndOr) {
|
|
71
69
|
let k = i;
|
|
72
70
|
while (k < stream.length &&
|
|
@@ -74,171 +72,179 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
74
72
|
tokens.push(stream[k]);
|
|
75
73
|
k++;
|
|
76
74
|
}
|
|
77
|
-
if (k < stream.length) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
// if (k < stream.length) {
|
|
76
|
+
// if (
|
|
77
|
+
// stream[k].typ !== EnumToken.EndParensTokenType &&
|
|
78
|
+
// !(
|
|
79
|
+
// stream[k].typ === EnumToken.IdenTokenType &&
|
|
80
|
+
// (equalsIgnoreCase((stream[k] as IdentToken).val, "and") ||
|
|
81
|
+
// equalsIgnoreCase((stream[k] as IdentToken).val, "or"))
|
|
82
|
+
// )
|
|
83
|
+
// ) {
|
|
84
|
+
// return {
|
|
85
|
+
// success: false,
|
|
86
|
+
// errors: [
|
|
87
|
+
// {
|
|
88
|
+
// action: "drop",
|
|
89
|
+
// node: stream[k],
|
|
90
|
+
// message: `expecting 'and' or 'or' at ${stream[k]?.[LOC]?.src}:${stream[k]?.[LOC]?.sta.lin}:${stream[k]?.[LOC]?.sta.col}`,
|
|
91
|
+
// location: stream[k][LOC],
|
|
92
|
+
// },
|
|
93
|
+
// ],
|
|
94
|
+
// };
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
94
97
|
expectAndOr = false;
|
|
95
98
|
}
|
|
96
99
|
switch (stream[i].typ) {
|
|
97
|
-
case EnumToken.EndParensTokenType:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
100
|
+
// case EnumToken.EndParensTokenType:
|
|
101
|
+
// {
|
|
102
|
+
// if (stack.length === 0) {
|
|
103
|
+
// return {
|
|
104
|
+
// success: false,
|
|
105
|
+
// errors: [
|
|
106
|
+
// {
|
|
107
|
+
// action: "drop",
|
|
108
|
+
// node: stream[i],
|
|
109
|
+
// message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
110
|
+
// },
|
|
111
|
+
// ],
|
|
112
|
+
// };
|
|
113
|
+
// }
|
|
114
|
+
// if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
|
|
115
|
+
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
116
|
+
// const slice: Token[] = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
117
|
+
// const filtered: Token[] = slice.filter((token) => {
|
|
118
|
+
// return (
|
|
119
|
+
// token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType
|
|
120
|
+
// );
|
|
121
|
+
// });
|
|
122
|
+
// if (
|
|
123
|
+
// filtered.length !== 1 ||
|
|
124
|
+
// !(
|
|
125
|
+
// validChildTypes.has(filtered[0].typ) ||
|
|
126
|
+
// tokensfuncDefMap.has(filtered[0].typ) ||
|
|
127
|
+
// tokensfuncSet.has(filtered[0].typ)
|
|
128
|
+
// )
|
|
129
|
+
// ) {
|
|
130
|
+
// const token = filtered[0] ?? slice[0] ?? stream[i];
|
|
131
|
+
// return {
|
|
132
|
+
// success: false,
|
|
133
|
+
// errors: [
|
|
134
|
+
// {
|
|
135
|
+
// action: "drop",
|
|
136
|
+
// node: token,
|
|
137
|
+
// location: token[LOC],
|
|
138
|
+
// message: `expecting '<boolean-condition"}>' at ${token?.[LOC]?.src}:${token?.[LOC]?.sta.lin}:${token?.[LOC]?.sta.col}`,
|
|
139
|
+
// },
|
|
140
|
+
// ],
|
|
141
|
+
// };
|
|
142
|
+
// }
|
|
143
|
+
// tokens[index] = {
|
|
144
|
+
// typ: EnumToken.ParensTokenType,
|
|
145
|
+
// chi: slice,
|
|
146
|
+
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } } as Location,
|
|
147
|
+
// };
|
|
148
|
+
// stack.pop();
|
|
149
|
+
// tokens.pop();
|
|
150
|
+
// scopes.pop();
|
|
151
|
+
// scope = scopes[scopes.length - 1];
|
|
152
|
+
// expectAndOr = true;
|
|
153
|
+
// }
|
|
154
|
+
// if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
|
|
155
|
+
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
156
|
+
// tokens[index] = {
|
|
157
|
+
// typ: EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
158
|
+
// l: stack.at(-1),
|
|
159
|
+
// r: trimArray(tokens.splice(index + 1, i - index - 1)),
|
|
160
|
+
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
161
|
+
// } as SupportsQueryUnaryConditionToken;
|
|
162
|
+
// stack.pop();
|
|
163
|
+
// }
|
|
164
|
+
// if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
165
|
+
// if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
|
|
166
|
+
// return {
|
|
167
|
+
// success: false,
|
|
168
|
+
// errors: [
|
|
169
|
+
// {
|
|
170
|
+
// action: "drop",
|
|
171
|
+
// node: stack.at(-2),
|
|
172
|
+
// message: `expecting '(' at ${stack.at(-2)?.[LOC]?.src}:${stack.at(-2)?.[LOC]?.sta.lin}:${stack.at(-2)?.[LOC]?.sta.col}`,
|
|
173
|
+
// },
|
|
174
|
+
// ],
|
|
175
|
+
// };
|
|
176
|
+
// }
|
|
177
|
+
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
178
|
+
// const index2: number = stack.length > 1 ? tokens.indexOf(stack.at(-2)!) + 1 : 0;
|
|
179
|
+
// const left: Token[] = trimArray(tokens.slice(index2, index));
|
|
180
|
+
// const notToken = left.find(
|
|
181
|
+
// (t) =>
|
|
182
|
+
// t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
|
|
183
|
+
// (t as SupportsQueryUnaryConditionToken).l.typ === EnumToken.NotTokenType,
|
|
184
|
+
// );
|
|
185
|
+
// if (notToken != null) {
|
|
186
|
+
// return {
|
|
187
|
+
// success: false,
|
|
188
|
+
// errors: [
|
|
189
|
+
// {
|
|
190
|
+
// action: "drop",
|
|
191
|
+
// node: stack.at(-1),
|
|
192
|
+
// message: `unexpected token after 'not' expression at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
193
|
+
// },
|
|
194
|
+
// ],
|
|
195
|
+
// };
|
|
196
|
+
// }
|
|
197
|
+
// tokens[index2] = {
|
|
198
|
+
// typ: EnumToken.SupportsQueryConditionTokenType,
|
|
199
|
+
// op: stack.at(-1)!,
|
|
200
|
+
// l: left,
|
|
201
|
+
// r: trimArray(tokens.slice(index + 1)),
|
|
202
|
+
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
203
|
+
// } as SupportsQueryConditionToken;
|
|
204
|
+
// tokens.length = index2 + 1;
|
|
205
|
+
// stack.pop();
|
|
206
|
+
// }
|
|
207
|
+
// }
|
|
208
|
+
// break;
|
|
203
209
|
case EnumToken.IdenTokenType:
|
|
204
210
|
{
|
|
205
211
|
const val = stream[i].val.toLowerCase();
|
|
206
|
-
if ("not" === val || "only" === val) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
212
|
+
// if ("not" === val || "only" === val) {
|
|
213
|
+
// stack.push(stream[i]);
|
|
214
|
+
// Object.assign(stream[i], {
|
|
215
|
+
// typ: "only" === val ? EnumToken.OnlyTokenType : EnumToken.NotTokenType,
|
|
216
|
+
// });
|
|
217
|
+
// break;
|
|
218
|
+
// }
|
|
213
219
|
if ("and" === val || "or" === val) {
|
|
214
|
-
if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
if ("or" === val && scopes.length === 1) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
220
|
+
// if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
221
|
+
// return {
|
|
222
|
+
// success: false,
|
|
223
|
+
// errors: [
|
|
224
|
+
// {
|
|
225
|
+
// action: "drop",
|
|
226
|
+
// message: `mixing <and> and <or> at the same level is not allowed at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
227
|
+
// },
|
|
228
|
+
// ],
|
|
229
|
+
// };
|
|
230
|
+
// }
|
|
231
|
+
// if ("or" === val && scopes.length === 1) {
|
|
232
|
+
// return {
|
|
233
|
+
// success: false,
|
|
234
|
+
// errors: [
|
|
235
|
+
// {
|
|
236
|
+
// action: "drop",
|
|
237
|
+
// message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
238
|
+
// },
|
|
239
|
+
// ],
|
|
240
|
+
// };
|
|
241
|
+
// }
|
|
236
242
|
Object.assign(stream[i], {
|
|
237
243
|
typ: "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType,
|
|
238
244
|
});
|
|
239
245
|
scope.add(stream[i].typ);
|
|
240
246
|
stack.push(stream[i]);
|
|
241
|
-
break;
|
|
247
|
+
// break;
|
|
242
248
|
}
|
|
243
249
|
}
|
|
244
250
|
break;
|
|
@@ -262,10 +268,11 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
262
268
|
const slice = stream.slice(i, j + 1);
|
|
263
269
|
const funcName = stream[i].val.toLowerCase();
|
|
264
270
|
const tokenList = [
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
271
|
+
{
|
|
272
|
+
typ: EnumToken.StartParensTokenType,
|
|
273
|
+
[LOC]: { ...stream[i][LOC], end: { ...stream[j]?.[LOC]?.end } },
|
|
274
|
+
},
|
|
275
|
+
// @ts-expect-error
|
|
269
276
|
].concat(slice.slice(1));
|
|
270
277
|
if ("media" === funcName) {
|
|
271
278
|
const result = parseMediaqueryList(tokenList, options);
|
|
@@ -286,48 +293,42 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
286
293
|
return result;
|
|
287
294
|
}
|
|
288
295
|
}
|
|
289
|
-
else {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
296
|
+
// else {
|
|
297
|
+
// errors.push({
|
|
298
|
+
// action: "ignore",
|
|
299
|
+
// message: `unknown <boolean-condition> function '${funcName}' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
300
|
+
// node: stream[i],
|
|
301
|
+
// location: stream[i][LOC],
|
|
302
|
+
// });
|
|
303
|
+
// }
|
|
304
|
+
stream[i][LOC] = { ...stream[i][LOC], end: { ...stream[j]?.[LOC]?.end } };
|
|
305
|
+
Object.assign(stream[i], {
|
|
298
306
|
typ: tokensfuncDefMap.get(stream[i].typ),
|
|
299
307
|
chi: stream[i].typ === EnumToken.SupportsFunctionTokenDefType
|
|
300
308
|
? trimArray(slice.slice(1, -1))
|
|
301
309
|
: tokenList[0].chi,
|
|
302
|
-
}), "loc", {
|
|
303
|
-
...definedPropertySettings,
|
|
304
|
-
value: { ...stream[i].loc, end: { ...stream[j]?.loc?.end } },
|
|
305
310
|
});
|
|
306
|
-
if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
stack.pop();
|
|
318
|
-
}
|
|
311
|
+
// if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
|
|
312
|
+
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
313
|
+
// tokens[index] = {
|
|
314
|
+
// typ: EnumToken.WhenElseUnaryConditionTokenType,
|
|
315
|
+
// l: stack.at(-1)!,
|
|
316
|
+
// r: trimArray(tokens.slice(index + 1)),
|
|
317
|
+
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
318
|
+
// } as WhenElseUnaryConditionToken;
|
|
319
|
+
// tokens.length = index + 1;
|
|
320
|
+
// stack.pop();
|
|
321
|
+
// }
|
|
319
322
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
320
323
|
const index = tokens.indexOf(stack.at(-1));
|
|
321
324
|
const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
|
|
322
|
-
tokens[index2] =
|
|
325
|
+
tokens[index2] = {
|
|
323
326
|
typ: EnumToken.WhenElseQueryConditionTokenType,
|
|
324
327
|
op: stack.at(-1),
|
|
325
328
|
l: trimArray(tokens.slice(index2, index)),
|
|
326
329
|
r: trimArray(tokens.slice(index + 1)),
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
|
|
330
|
-
});
|
|
330
|
+
[LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
331
|
+
};
|
|
331
332
|
tokens.length = index2 + 1;
|
|
332
333
|
stack.pop();
|
|
333
334
|
}
|
|
@@ -335,26 +336,22 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
335
336
|
expectAndOr = true;
|
|
336
337
|
}
|
|
337
338
|
break;
|
|
338
|
-
default:
|
|
339
|
-
if (tokensfuncDefMap.has(stream[i].typ)) {
|
|
340
|
-
stack.push(stream[i]);
|
|
341
|
-
expectAndOr = true;
|
|
342
|
-
}
|
|
343
|
-
break;
|
|
344
339
|
}
|
|
345
340
|
}
|
|
346
|
-
if (stack.length > 0) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
341
|
+
// if (stack.length > 0) {
|
|
342
|
+
// return {
|
|
343
|
+
// success: false,
|
|
344
|
+
// errors: [
|
|
345
|
+
// {
|
|
346
|
+
// action: "drop",
|
|
347
|
+
// node: stack.at(-1),
|
|
348
|
+
// message: `unmatched token '${renderValue(stack.at(-1) as Token)}' at ${stack.at(-1)![LOC]!.src}:${
|
|
349
|
+
// stack.at(-1)![LOC]!.sta.lin
|
|
350
|
+
// }:${stack.at(-1)![LOC]!.sta.col}`,
|
|
351
|
+
// },
|
|
352
|
+
// ],
|
|
353
|
+
// };
|
|
354
|
+
// }
|
|
358
355
|
stream.length = 0;
|
|
359
356
|
stream.push(...trimArray(tokens));
|
|
360
357
|
return { success, errors };
|