@projectwallace/css-parser 0.18.9 → 0.18.12
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/README.md +186 -18
- package/dist/{arena-e9O_g2AN.js → arena-Bsf96CQK.js} +27 -19
- package/dist/{arena-BGvFdbj5.d.ts → arena-DvT75bvK.d.ts} +2 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/{css-node-DfJEsKN0.js → css-node-yoUdFtNg.js} +101 -100
- package/dist/index.d.ts +6 -20
- package/dist/index.js +9 -146
- package/dist/{node-types-YnOKcNfU.d.ts → node-types-CY0JK9_a.d.ts} +9 -55
- package/dist/node-types.d.ts +2 -0
- package/dist/node-types.js +142 -0
- package/dist/parse-anplusb.d.ts +2 -2
- package/dist/parse-anplusb.js +5 -4
- package/dist/parse-atrule-prelude.d.ts +2 -2
- package/dist/parse-atrule-prelude.js +62 -61
- package/dist/parse-declaration.d.ts +3 -3
- package/dist/parse-declaration.js +20 -19
- package/dist/parse-dimension.js +47 -1
- package/dist/{parse-selector-rTXB4IN2.js → parse-selector-CqIpnBrQ.js} +74 -81
- package/dist/parse-selector.d.ts +2 -2
- package/dist/parse-selector.js +1 -1
- package/dist/parse-value.d.ts +2 -2
- package/dist/parse-value.js +8 -8
- package/dist/parse.d.ts +3 -3
- package/dist/parse.js +67 -46
- package/dist/string-helpers-BMWJduts.d.ts +18 -0
- package/dist/string-helpers.d.ts +2 -0
- package/dist/string-helpers.js +1 -0
- package/dist/{parse-dimension-CIaPOmBc.js → string-utils-DiRRd28d.js} +5 -49
- package/dist/token-types-Bqsf5FX-.d.ts +38 -0
- package/dist/token-types.d.ts +2 -0
- package/dist/token-types.js +30 -0
- package/dist/{tokenize-0ADWAELW.js → tokenize-Ccg58Z_k.js} +67 -96
- package/dist/tokenize.d.ts +97 -2
- package/dist/tokenize.js +1 -1
- package/dist/{value-node-parser-DizbcN1a.js → value-node-parser-BBwBxFR_.js} +133 -135
- package/dist/walk.d.ts +3 -2
- package/dist/walk.js +2 -2
- package/package.json +17 -4
- package/dist/tokenize-CaWtrHw_.d.ts +0 -134
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { t as Lexer } from "./tokenize-Ccg58Z_k.js";
|
|
2
|
+
import "./token-types.js";
|
|
3
|
+
import "./arena-Bsf96CQK.js";
|
|
4
|
+
import { c as str_equals_range, t as is_and_or_not_range } from "./string-utils-DiRRd28d.js";
|
|
5
|
+
import { i as find_colon_at_depth_zero, o as skip_whitespace_and_comments_forward, s as trim_boundaries, t as SelectorParser } from "./parse-selector-CqIpnBrQ.js";
|
|
5
6
|
//#region src/parse-condition.ts
|
|
6
7
|
var ConditionParser = class {
|
|
7
8
|
lexer;
|
|
@@ -37,7 +38,7 @@ var ConditionParser = class {
|
|
|
37
38
|
let content_end = this.lexer.pos;
|
|
38
39
|
let close_end = this.lexer.token_end;
|
|
39
40
|
while (this.lexer.pos < this.end && depth > 0) {
|
|
40
|
-
|
|
41
|
+
const token_type = this.next_token();
|
|
41
42
|
if (token_type === 21 || token_type === 2) depth++;
|
|
42
43
|
else if (token_type === 22) {
|
|
43
44
|
depth--;
|
|
@@ -56,31 +57,31 @@ var ConditionParser = class {
|
|
|
56
57
|
}
|
|
57
58
|
wrap_ratio_value(first_node) {
|
|
58
59
|
if (this.arena.get_type(first_node) !== 11) return first_node;
|
|
59
|
-
|
|
60
|
+
const op_node = this.arena.get_next_sibling(first_node);
|
|
60
61
|
if (op_node === 0 || this.arena.get_type(op_node) !== 16) return first_node;
|
|
61
62
|
if (this.arena.get_length(op_node) !== 1) return first_node;
|
|
62
63
|
if (this.source.charCodeAt(this.arena.get_start_offset(op_node)) !== 47) return first_node;
|
|
63
|
-
|
|
64
|
+
const second_node = this.arena.get_next_sibling(op_node);
|
|
64
65
|
if (second_node === 0 || this.arena.get_type(second_node) !== 11) return first_node;
|
|
65
66
|
if (this.arena.get_next_sibling(second_node) !== 0) return first_node;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const start = this.arena.get_start_offset(first_node);
|
|
68
|
+
const end = this.arena.get_start_offset(second_node) + this.arena.get_length(second_node);
|
|
69
|
+
const ratio_node = this.arena.create_node(58, start, end - start, this.arena.get_start_line(first_node), this.arena.get_start_column(first_node));
|
|
69
70
|
this.arena.set_first_child(ratio_node, first_node);
|
|
70
71
|
this.arena.set_next_sibling(first_node, second_node);
|
|
71
72
|
return ratio_node;
|
|
72
73
|
}
|
|
73
74
|
create_supports_declaration(content_start, content_end, colon_pos) {
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const prop_trimmed = trim_boundaries(this.source, content_start, colon_pos);
|
|
76
|
+
const val_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
|
|
76
77
|
if (!prop_trimmed) return this.create_node(57, content_start, content_end);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const decl_start = prop_trimmed[0];
|
|
79
|
+
const decl_end = val_trimmed ? val_trimmed[1] : colon_pos + 1;
|
|
80
|
+
const decl = this.create_node(4, decl_start, decl_end);
|
|
80
81
|
this.arena.set_content_start_delta(decl, 0);
|
|
81
82
|
this.arena.set_content_length(decl, prop_trimmed[1] - prop_trimmed[0]);
|
|
82
83
|
if (val_trimmed) {
|
|
83
|
-
|
|
84
|
+
const value_first = this.parse_feature_value(val_trimmed[0], val_trimmed[1]);
|
|
84
85
|
let value_node;
|
|
85
86
|
if (value_first === 0) value_node = this.arena.create_node(50, val_trimmed[0], 0, this.lexer.token_line, this.lexer.token_column);
|
|
86
87
|
else {
|
|
@@ -89,14 +90,14 @@ var ConditionParser = class {
|
|
|
89
90
|
}
|
|
90
91
|
this.arena.set_first_child(decl, value_node);
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
const supports_decl = this.create_node(57, content_start, content_end);
|
|
93
94
|
this.arena.set_content_start_delta(supports_decl, prop_trimmed[0] - content_start);
|
|
94
95
|
this.arena.set_content_length(supports_decl, prop_trimmed[1] - prop_trimmed[0]);
|
|
95
96
|
this.arena.set_first_child(supports_decl, decl);
|
|
96
97
|
return supports_decl;
|
|
97
98
|
}
|
|
98
99
|
parse_feature_range(feature_start, feature_end, content_start, content_end) {
|
|
99
|
-
|
|
100
|
+
const range_node = this.create_node(39, feature_start, feature_end);
|
|
100
101
|
let first_child = 0;
|
|
101
102
|
let last_child = 0;
|
|
102
103
|
let feature_name_start = -1;
|
|
@@ -105,23 +106,26 @@ var ConditionParser = class {
|
|
|
105
106
|
while (pos < content_end) {
|
|
106
107
|
pos = skip_whitespace_and_comments_forward(this.source, pos, content_end);
|
|
107
108
|
if (pos >= content_end) break;
|
|
108
|
-
|
|
109
|
+
const ch = this.source.charCodeAt(pos);
|
|
109
110
|
if (ch === 60 || ch === 62 || ch === 61) {
|
|
110
|
-
|
|
111
|
-
if (pos < content_end && this.source.charCodeAt(pos) === 61) pos++;
|
|
112
|
-
|
|
111
|
+
const op_start = pos++;
|
|
112
|
+
if (ch !== 61 && pos < content_end && this.source.charCodeAt(pos) === 61) pos++;
|
|
113
|
+
const op = this.create_node(38, op_start, pos);
|
|
113
114
|
if (first_child === 0) first_child = op;
|
|
114
115
|
else this.arena.set_next_sibling(last_child, op);
|
|
115
116
|
last_child = op;
|
|
116
117
|
} else {
|
|
117
|
-
|
|
118
|
+
const saved = this.lexer.save_position();
|
|
118
119
|
this.lexer.pos = pos;
|
|
119
120
|
this.next_token();
|
|
120
121
|
if (this.lexer.token_type === 1) {
|
|
121
122
|
feature_name_start = this.lexer.token_start;
|
|
122
123
|
feature_name_end = this.lexer.token_end;
|
|
123
124
|
} else {
|
|
124
|
-
|
|
125
|
+
const value_start = this.lexer.token_start;
|
|
126
|
+
let value_end = this.lexer.token_end;
|
|
127
|
+
if (this.lexer.token_type === 2 && this.scan_matching_paren()) value_end = this.paren_close_end;
|
|
128
|
+
const value_first = this.parse_feature_value(value_start, value_end);
|
|
125
129
|
if (value_first !== 0) {
|
|
126
130
|
if (first_child === 0) first_child = value_first;
|
|
127
131
|
else this.arena.set_next_sibling(last_child, value_first);
|
|
@@ -146,7 +150,7 @@ var ConditionParser = class {
|
|
|
146
150
|
while (i < content_end) {
|
|
147
151
|
i = skip_whitespace_and_comments_forward(this.source, i, content_end);
|
|
148
152
|
if (i >= content_end) break;
|
|
149
|
-
|
|
153
|
+
const ch = this.source.charCodeAt(i);
|
|
150
154
|
if (ch === 60 || ch === 62 || ch === 61) {
|
|
151
155
|
has_comparison = true;
|
|
152
156
|
break;
|
|
@@ -154,7 +158,7 @@ var ConditionParser = class {
|
|
|
154
158
|
i++;
|
|
155
159
|
}
|
|
156
160
|
if (has_comparison) return this.parse_feature_range(feature_start, feature_end, content_start, content_end);
|
|
157
|
-
|
|
161
|
+
const feature = this.create_node(33, feature_start, feature_end);
|
|
158
162
|
let colon_pos = -1;
|
|
159
163
|
let j = content_start;
|
|
160
164
|
while (j < content_end) {
|
|
@@ -167,20 +171,20 @@ var ConditionParser = class {
|
|
|
167
171
|
j++;
|
|
168
172
|
}
|
|
169
173
|
if (colon_pos === -1) {
|
|
170
|
-
|
|
174
|
+
const trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
171
175
|
if (trimmed) {
|
|
172
176
|
this.arena.set_content_start_delta(feature, trimmed[0] - feature_start);
|
|
173
177
|
this.arena.set_content_length(feature, trimmed[1] - trimmed[0]);
|
|
174
178
|
}
|
|
175
179
|
} else {
|
|
176
|
-
|
|
180
|
+
const name_trimmed = trim_boundaries(this.source, content_start, colon_pos);
|
|
177
181
|
if (name_trimmed) {
|
|
178
182
|
this.arena.set_content_start_delta(feature, name_trimmed[0] - feature_start);
|
|
179
183
|
this.arena.set_content_length(feature, name_trimmed[1] - name_trimmed[0]);
|
|
180
184
|
}
|
|
181
|
-
|
|
185
|
+
const value_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
|
|
182
186
|
if (value_trimmed) {
|
|
183
|
-
|
|
187
|
+
const value_first = this.parse_feature_value(value_trimmed[0], value_trimmed[1]);
|
|
184
188
|
if (value_first !== 0) this.arena.set_first_child(feature, this.wrap_ratio_value(value_first));
|
|
185
189
|
}
|
|
186
190
|
}
|
|
@@ -190,11 +194,11 @@ var ConditionParser = class {
|
|
|
190
194
|
this.end = end;
|
|
191
195
|
this.lexer.seek(open_paren_start, line, column);
|
|
192
196
|
this.next_token();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
const feature_start = this.lexer.token_start;
|
|
198
|
+
const content_start = this.lexer.pos;
|
|
199
|
+
const matched = this.scan_matching_paren();
|
|
200
|
+
const content_end = this.paren_content_end;
|
|
201
|
+
const feature_end = this.paren_close_end;
|
|
198
202
|
if (!matched) return null;
|
|
199
203
|
return this.parse_media_feature_content(feature_start, feature_end, content_start, content_end);
|
|
200
204
|
}
|
|
@@ -202,63 +206,63 @@ var ConditionParser = class {
|
|
|
202
206
|
this.end = end;
|
|
203
207
|
this.lexer.seek(func_start, line, column);
|
|
204
208
|
this.next_token();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
const func_name_start = this.lexer.token_start;
|
|
210
|
+
const func_name_end = this.lexer.token_end - 1;
|
|
211
|
+
const content_start = this.lexer.token_end;
|
|
208
212
|
this.scan_matching_paren();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
const content_end = this.paren_content_end;
|
|
214
|
+
const func_end = this.paren_close_end;
|
|
215
|
+
const func_node = this.create_node(15, func_start, func_end);
|
|
212
216
|
this.arena.set_content_start_delta(func_node, 0);
|
|
213
217
|
this.arena.set_content_length(func_node, func_name_end - func_name_start);
|
|
214
218
|
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
215
219
|
this.arena.set_value_length(func_node, content_end - content_start);
|
|
216
220
|
if (str_equals_range(this.source, func_name_start, func_name_end, "selector")) {
|
|
217
|
-
|
|
221
|
+
const selector_list = this.selector_parser.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column);
|
|
218
222
|
if (selector_list !== null) this.arena.set_first_child(func_node, selector_list);
|
|
219
223
|
} else if (str_equals_range(this.source, func_name_start, func_name_end, "style")) {
|
|
220
|
-
|
|
224
|
+
const decl_child = this.parse_supports_declaration_content(content_start, content_end);
|
|
221
225
|
if (decl_child !== null) this.arena.set_first_child(func_node, decl_child);
|
|
222
226
|
}
|
|
223
227
|
return func_node;
|
|
224
228
|
}
|
|
225
229
|
parse_supports_declaration_content(content_start, content_end) {
|
|
226
|
-
|
|
230
|
+
const colon_pos = find_colon_at_depth_zero(this.source, content_start, content_end);
|
|
227
231
|
if (colon_pos === -1) return null;
|
|
228
232
|
return this.create_supports_declaration(content_start, content_end, colon_pos);
|
|
229
233
|
}
|
|
230
234
|
parse_supports_condition(start, end, line, column) {
|
|
231
|
-
|
|
235
|
+
const saved_end = this.end;
|
|
232
236
|
this.end = end;
|
|
233
237
|
this.lexer.seek(start, line, column);
|
|
234
|
-
|
|
238
|
+
const nodes = [];
|
|
235
239
|
while (this.lexer.pos < this.end) {
|
|
236
240
|
this.lexer.skip_whitespace_in_range(this.end);
|
|
237
241
|
if (this.lexer.pos >= this.end) break;
|
|
238
242
|
this.next_token();
|
|
239
|
-
|
|
243
|
+
const token_type = this.lexer.token_type;
|
|
240
244
|
if (token_type === 21) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
245
|
+
const feature_start = this.lexer.token_start;
|
|
246
|
+
const content_start = this.lexer.pos;
|
|
247
|
+
const matched = this.scan_matching_paren();
|
|
248
|
+
const content_end = this.paren_content_end;
|
|
249
|
+
const feature_end = this.paren_close_end;
|
|
246
250
|
if (matched) {
|
|
247
|
-
|
|
248
|
-
|
|
251
|
+
const query = this.create_node(36, feature_start, feature_end);
|
|
252
|
+
const trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
249
253
|
if (trimmed) {
|
|
250
254
|
this.arena.set_value_start_delta(query, trimmed[0] - feature_start);
|
|
251
255
|
this.arena.set_value_length(query, trimmed[1] - trimmed[0]);
|
|
252
|
-
|
|
256
|
+
const decl_child = this.parse_supports_declaration_content(trimmed[0], trimmed[1]);
|
|
253
257
|
if (decl_child !== null) this.arena.set_first_child(query, decl_child);
|
|
254
258
|
}
|
|
255
259
|
nodes.push(query);
|
|
256
260
|
}
|
|
257
261
|
} else if (token_type === 1) {
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
const token_start = this.lexer.token_start;
|
|
263
|
+
const token_end = this.lexer.token_end;
|
|
260
264
|
if (is_and_or_not_range(this.source, token_start, token_end)) {
|
|
261
|
-
|
|
265
|
+
const op = this.create_node(38, token_start, token_end);
|
|
262
266
|
nodes.push(op);
|
|
263
267
|
}
|
|
264
268
|
} else if (token_type === 2) nodes.push(this.parse_function_condition(this.lexer.token_start, this.end, this.lexer.token_line, this.lexer.token_column));
|
|
@@ -291,12 +295,10 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
291
295
|
let first_node = 0;
|
|
292
296
|
let last_node = 0;
|
|
293
297
|
while (this.lexer.pos < this.end) {
|
|
294
|
-
this.lexer.next_token_fast(
|
|
298
|
+
this.lexer.next_token_fast(true);
|
|
295
299
|
if (this.lexer.token_start >= this.end) break;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (token_type === 13) continue;
|
|
299
|
-
let node = this.parse_value_node();
|
|
300
|
+
if (this.lexer.token_type === 26) break;
|
|
301
|
+
const node = this.parse_value_node();
|
|
300
302
|
if (node !== null) {
|
|
301
303
|
if (first_node === 0) first_node = node;
|
|
302
304
|
else this.arena.set_next_sibling(last_node, node);
|
|
@@ -307,9 +309,9 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
307
309
|
return first_node;
|
|
308
310
|
}
|
|
309
311
|
parse_value_node() {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
312
|
+
const token_type = this.lexer.token_type;
|
|
313
|
+
const start = this.lexer.token_start;
|
|
314
|
+
const end = this.lexer.token_end;
|
|
313
315
|
switch (token_type) {
|
|
314
316
|
case 1: return this.create_node(10, start, end);
|
|
315
317
|
case 10: return this.create_node(11, start, end);
|
|
@@ -328,12 +330,12 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
328
330
|
}
|
|
329
331
|
}
|
|
330
332
|
create_node(node_type, start, end) {
|
|
331
|
-
|
|
333
|
+
const node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
332
334
|
this.arena.set_content_length(node, end - start);
|
|
333
335
|
return node;
|
|
334
336
|
}
|
|
335
337
|
parse_operator_node(start, end) {
|
|
336
|
-
|
|
338
|
+
const ch = this.source.charCodeAt(start);
|
|
337
339
|
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_node(16, start, end);
|
|
338
340
|
return null;
|
|
339
341
|
}
|
|
@@ -345,7 +347,7 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
345
347
|
let close_end = this.lexer.token_end;
|
|
346
348
|
while ((!bounded || this.lexer.pos < this.end) && depth > 0) {
|
|
347
349
|
this.lexer.next_token_fast(false);
|
|
348
|
-
|
|
350
|
+
const token_type = this.lexer.token_type;
|
|
349
351
|
if (token_type === 26) break;
|
|
350
352
|
if (bounded && this.lexer.token_start >= this.end) break;
|
|
351
353
|
if (token_type === 21 || token_type === 2) depth++;
|
|
@@ -362,25 +364,25 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
362
364
|
return depth === 0;
|
|
363
365
|
}
|
|
364
366
|
parse_function_node(start, end) {
|
|
365
|
-
|
|
367
|
+
const name_end = end - 1;
|
|
366
368
|
if (str_equals_range(this.source, start, name_end, "if")) return this.parse_if_function_node(start, end);
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
const is_url = str_equals_range(this.source, start, name_end, "url");
|
|
370
|
+
const node = this.arena.create_node(is_url ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
369
371
|
this.arena.set_content_start_delta(node, 0);
|
|
370
372
|
this.arena.set_content_length(node, name_end - start);
|
|
371
373
|
if (is_url || str_equals_range(this.source, start, name_end, "src")) {
|
|
372
|
-
|
|
374
|
+
const save_pos = this.lexer.save_position();
|
|
373
375
|
this.lexer.next_token_fast(false);
|
|
374
376
|
while (this.lexer.token_type === 13 && this.lexer.pos < this.end) this.lexer.next_token_fast(false);
|
|
375
|
-
|
|
377
|
+
const first_token_type = this.lexer.token_type;
|
|
376
378
|
this.lexer.restore_position(save_pos);
|
|
377
379
|
if (first_token_type === 5) {} else {
|
|
378
380
|
let func_end = end;
|
|
379
|
-
|
|
381
|
+
const content_start = end;
|
|
380
382
|
let content_end = end;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
383
|
+
const matched = this.scan_matching_paren(false);
|
|
384
|
+
const scanned_content_end = this.paren_content_end;
|
|
385
|
+
const scanned_func_end = this.paren_close_end;
|
|
384
386
|
if (matched) {
|
|
385
387
|
content_end = scanned_content_end;
|
|
386
388
|
func_end = scanned_func_end;
|
|
@@ -395,11 +397,11 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
395
397
|
let last_arg = 0;
|
|
396
398
|
let paren_depth = 1;
|
|
397
399
|
let func_end = end;
|
|
398
|
-
|
|
400
|
+
const content_start = end;
|
|
399
401
|
let content_end = end;
|
|
400
402
|
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
401
|
-
this.lexer.next_token_fast(
|
|
402
|
-
|
|
403
|
+
this.lexer.next_token_fast(true);
|
|
404
|
+
const token_type = this.lexer.token_type;
|
|
403
405
|
if (token_type === 26) break;
|
|
404
406
|
if (this.lexer.token_start >= this.end) break;
|
|
405
407
|
if (token_type === 22) {
|
|
@@ -410,8 +412,7 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
410
412
|
break;
|
|
411
413
|
}
|
|
412
414
|
}
|
|
413
|
-
|
|
414
|
-
let arg_node = this.parse_value_node();
|
|
415
|
+
const arg_node = this.parse_value_node();
|
|
415
416
|
if (arg_node !== null) {
|
|
416
417
|
if (first_arg === 0) first_arg = arg_node;
|
|
417
418
|
else this.arena.set_next_sibling(last_arg, arg_node);
|
|
@@ -425,20 +426,20 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
425
426
|
return node;
|
|
426
427
|
}
|
|
427
428
|
parse_if_function_node(start, end) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
429
|
+
const name_end = end - 1;
|
|
430
|
+
const save_line = this.lexer.token_line;
|
|
431
|
+
const save_col = this.lexer.token_column;
|
|
432
|
+
const node = this.arena.create_node(15, start, 0, save_line, save_col);
|
|
432
433
|
this.arena.set_content_start_delta(node, 0);
|
|
433
434
|
this.arena.set_content_length(node, name_end - start);
|
|
434
|
-
|
|
435
|
+
const branches = [];
|
|
435
436
|
let func_end = end;
|
|
436
|
-
|
|
437
|
+
const content_start = end;
|
|
437
438
|
let content_end = end;
|
|
438
439
|
let if_closed = false;
|
|
439
440
|
while (this.lexer.pos < this.end && !if_closed) {
|
|
440
441
|
this.lexer.next_token_fast(false);
|
|
441
|
-
|
|
442
|
+
const tt = this.lexer.token_type;
|
|
442
443
|
if (tt === 26) break;
|
|
443
444
|
if (this.lexer.token_start >= this.end) break;
|
|
444
445
|
if (tt === 22) {
|
|
@@ -447,16 +448,16 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
447
448
|
break;
|
|
448
449
|
}
|
|
449
450
|
if (tt === 13 || tt === 17 || tt === 16) continue;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
451
|
+
const branch_start = this.lexer.token_start;
|
|
452
|
+
const branch_line = this.lexer.token_line;
|
|
453
|
+
const branch_col = this.lexer.token_column;
|
|
454
|
+
const condition_node = this.parse_if_condition();
|
|
454
455
|
if (condition_node === null) continue;
|
|
455
|
-
|
|
456
|
+
const condition_end_pos = this.arena.get_start_offset(condition_node) + this.arena.get_length(condition_node);
|
|
456
457
|
let colon_found = false;
|
|
457
458
|
while (this.lexer.pos < this.end) {
|
|
458
459
|
this.lexer.next_token_fast(false);
|
|
459
|
-
|
|
460
|
+
const t = this.lexer.token_type;
|
|
460
461
|
if (t === 26) break;
|
|
461
462
|
if (this.lexer.token_start >= this.end) break;
|
|
462
463
|
if (t === 13) continue;
|
|
@@ -471,14 +472,14 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
471
472
|
break;
|
|
472
473
|
}
|
|
473
474
|
}
|
|
474
|
-
|
|
475
|
+
const value_tokens = [];
|
|
475
476
|
let value_start = -1;
|
|
476
477
|
let value_last_end = condition_end_pos;
|
|
477
478
|
let value_line = 0;
|
|
478
479
|
let value_col = 0;
|
|
479
480
|
if (colon_found && !if_closed) while (this.lexer.pos < this.end) {
|
|
480
481
|
this.lexer.next_token_fast(false);
|
|
481
|
-
|
|
482
|
+
const t = this.lexer.token_type;
|
|
482
483
|
if (t === 26) break;
|
|
483
484
|
if (this.lexer.token_start >= this.end) break;
|
|
484
485
|
if (t === 13) continue;
|
|
@@ -489,9 +490,9 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
489
490
|
if_closed = true;
|
|
490
491
|
break;
|
|
491
492
|
}
|
|
492
|
-
|
|
493
|
+
const vnode = this.parse_value_node();
|
|
493
494
|
if (vnode !== null) {
|
|
494
|
-
|
|
495
|
+
const ns = this.arena.get_start_offset(vnode);
|
|
495
496
|
if (value_start === -1) {
|
|
496
497
|
value_start = ns;
|
|
497
498
|
value_line = this.arena.get_start_line(vnode);
|
|
@@ -506,15 +507,15 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
506
507
|
value_node = this.arena.create_node(50, value_start, value_last_end - value_start, value_line, value_col);
|
|
507
508
|
this.arena.append_children(value_node, value_tokens);
|
|
508
509
|
}
|
|
509
|
-
|
|
510
|
-
|
|
510
|
+
const branch_end = value_node === null ? condition_end_pos : value_last_end;
|
|
511
|
+
const branch_node = this.arena.create_node(59, branch_start, branch_end - branch_start, branch_line, branch_col);
|
|
511
512
|
this.arena.set_content_start_delta(branch_node, 0);
|
|
512
513
|
this.arena.set_content_length(branch_node, condition_end_pos - branch_start);
|
|
513
514
|
if (value_start !== -1) {
|
|
514
515
|
this.arena.set_value_start_delta(branch_node, value_start - branch_start);
|
|
515
516
|
this.arena.set_value_length(branch_node, value_last_end - value_start);
|
|
516
517
|
}
|
|
517
|
-
|
|
518
|
+
const branch_children = [condition_node];
|
|
518
519
|
if (value_node !== null) branch_children.push(value_node);
|
|
519
520
|
this.arena.append_children(branch_node, branch_children);
|
|
520
521
|
branches.push(branch_node);
|
|
@@ -543,13 +544,13 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
543
544
|
let component_count = 0;
|
|
544
545
|
let compound = false;
|
|
545
546
|
for (;;) {
|
|
546
|
-
|
|
547
|
+
const tt = this.lexer.token_type;
|
|
547
548
|
let component = null;
|
|
548
549
|
let is_operator = false;
|
|
549
550
|
if (tt === 2) component = this.parse_if_condition_function(this.lexer.token_start, this.lexer.token_end);
|
|
550
551
|
else if (tt === 1) {
|
|
551
|
-
|
|
552
|
-
|
|
552
|
+
const token_start = this.lexer.token_start;
|
|
553
|
+
const token_end = this.lexer.token_end;
|
|
553
554
|
if (is_and_or_not_range(this.source, token_start, token_end)) {
|
|
554
555
|
is_operator = true;
|
|
555
556
|
component = this.arena.create_node(38, token_start, token_end - token_start, this.lexer.token_line, this.lexer.token_column);
|
|
@@ -562,8 +563,8 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
562
563
|
last = component;
|
|
563
564
|
}
|
|
564
565
|
if (tt !== 2 && !is_operator) break;
|
|
565
|
-
|
|
566
|
-
|
|
566
|
+
const saved = this.lexer.save_position();
|
|
567
|
+
const next_tt = this.next_significant_token();
|
|
567
568
|
if (next_tt === 2) {
|
|
568
569
|
compound = true;
|
|
569
570
|
continue;
|
|
@@ -579,39 +580,39 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
579
580
|
}
|
|
580
581
|
if (first === 0) return null;
|
|
581
582
|
if (component_count === 1 && !compound) return first;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
583
|
+
const wrapper_start = this.arena.get_start_offset(first);
|
|
584
|
+
const last_sibling = this.arena.get_last_sibling(first);
|
|
585
|
+
const wrapper_end = this.arena.get_start_offset(last_sibling) + this.arena.get_length(last_sibling);
|
|
586
|
+
const wrapper = this.arena.create_node(60, wrapper_start, wrapper_end - wrapper_start, this.arena.get_start_line(first), this.arena.get_start_column(first));
|
|
586
587
|
this.arena.set_first_child(wrapper, first);
|
|
587
588
|
return wrapper;
|
|
588
589
|
}
|
|
589
590
|
parse_if_condition_function(func_start, token_end) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
591
|
+
const func_name_end = token_end - 1;
|
|
592
|
+
const func_line = this.lexer.token_line;
|
|
593
|
+
const func_col = this.lexer.token_column;
|
|
594
|
+
const content_start = token_end;
|
|
594
595
|
let content_end = content_start;
|
|
595
596
|
let func_end = content_start;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
597
|
+
const matched = this.scan_matching_paren(true);
|
|
598
|
+
const scanned_content_end = this.paren_content_end;
|
|
599
|
+
const scanned_func_end = this.paren_close_end;
|
|
599
600
|
if (matched) {
|
|
600
601
|
content_end = scanned_content_end;
|
|
601
602
|
func_end = scanned_func_end;
|
|
602
603
|
}
|
|
603
|
-
|
|
604
|
+
const func_node = this.arena.create_node(15, func_start, func_end - func_start, func_line, func_col);
|
|
604
605
|
this.arena.set_content_start_delta(func_node, 0);
|
|
605
606
|
this.arena.set_content_length(func_node, func_name_end - func_start);
|
|
606
607
|
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
607
608
|
this.arena.set_value_length(func_node, content_end - content_start);
|
|
608
609
|
let child_nodes = [];
|
|
609
610
|
if (str_equals_range(this.source, func_start, func_name_end, "style")) {
|
|
610
|
-
|
|
611
|
+
const decl = this.condition_parser.parse_supports_declaration_content(content_start, content_end);
|
|
611
612
|
if (decl === null) child_nodes = this.condition_parser.parse_supports_condition(content_start, content_end, func_line, func_col);
|
|
612
613
|
else child_nodes = [decl];
|
|
613
614
|
} else if (str_equals_range(this.source, func_start, func_name_end, "supports")) {
|
|
614
|
-
|
|
615
|
+
const decl = this.condition_parser.parse_supports_declaration_content(content_start, content_end);
|
|
615
616
|
if (decl === null) child_nodes = this.condition_parser.parse_supports_condition(content_start, content_end, func_line, func_col);
|
|
616
617
|
else child_nodes = [decl];
|
|
617
618
|
} else if (str_equals_range(this.source, func_start, func_name_end, "media")) child_nodes = [this.condition_parser.parse_media_feature_content(content_start, content_end, content_start, content_end)];
|
|
@@ -620,18 +621,16 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
620
621
|
return func_node;
|
|
621
622
|
}
|
|
622
623
|
parse_value_nodes_in_range(start, end) {
|
|
623
|
-
|
|
624
|
-
|
|
624
|
+
const saved_end = this.end;
|
|
625
|
+
const saved_pos = this.lexer.save_position();
|
|
625
626
|
this.end = end;
|
|
626
627
|
this.lexer.seek(start, this.lexer.line, this.lexer.column);
|
|
627
|
-
|
|
628
|
+
const nodes = [];
|
|
628
629
|
while (this.lexer.pos < this.end) {
|
|
629
|
-
this.lexer.next_token_fast(
|
|
630
|
+
this.lexer.next_token_fast(true);
|
|
630
631
|
if (this.lexer.token_start >= this.end) break;
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (token_type === 13) continue;
|
|
634
|
-
let node = this.parse_value_node();
|
|
632
|
+
if (this.lexer.token_type === 26) break;
|
|
633
|
+
const node = this.parse_value_node();
|
|
635
634
|
if (node !== null) nodes.push(node);
|
|
636
635
|
}
|
|
637
636
|
this.lexer.restore_position(saved_pos);
|
|
@@ -639,14 +638,14 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
639
638
|
return nodes;
|
|
640
639
|
}
|
|
641
640
|
parse_parenthesis_node(start, end) {
|
|
642
|
-
|
|
641
|
+
const node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
643
642
|
let first_child = 0;
|
|
644
643
|
let last_child = 0;
|
|
645
644
|
let paren_depth = 1;
|
|
646
645
|
let paren_end = end;
|
|
647
646
|
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
648
|
-
this.lexer.next_token_fast(
|
|
649
|
-
|
|
647
|
+
this.lexer.next_token_fast(true);
|
|
648
|
+
const token_type = this.lexer.token_type;
|
|
650
649
|
if (token_type === 26) break;
|
|
651
650
|
if (this.lexer.token_start >= this.end) break;
|
|
652
651
|
if (token_type === 22) {
|
|
@@ -656,8 +655,7 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
656
655
|
break;
|
|
657
656
|
}
|
|
658
657
|
}
|
|
659
|
-
|
|
660
|
-
let child_node = this.parse_value_node();
|
|
658
|
+
const child_node = this.parse_value_node();
|
|
661
659
|
if (child_node !== null) {
|
|
662
660
|
if (first_child === 0) first_child = child_node;
|
|
663
661
|
else this.arena.set_next_sibling(last_child, child_node);
|
package/dist/walk.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as CSSNode, t as AnyNode } from "./node-types-CY0JK9_a.js";
|
|
2
2
|
//#region src/walk.d.ts
|
|
3
3
|
export declare const SKIP: unique symbol;
|
|
4
4
|
export declare const BREAK: unique symbol;
|
|
@@ -19,4 +19,5 @@ interface WalkEnterLeaveOptions {
|
|
|
19
19
|
* SKIP in enter skips children (leave still runs); BREAK stops (leave doesn't run).
|
|
20
20
|
*/
|
|
21
21
|
export declare function traverse(node: CSSNode, { enter, leave }?: WalkEnterLeaveOptions): boolean;
|
|
22
|
-
//#endregion
|
|
22
|
+
//#endregion
|
|
23
|
+
export {};
|
package/dist/walk.js
CHANGED