@projectwallace/css-parser 0.18.9 → 0.18.11
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-DG8OKqPu.d.ts} +8 -54
- 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 +45 -44
- 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-D0qnA_bD.js} +129 -134
- 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,23 @@ 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
|
+
const op_start = pos++;
|
|
111
112
|
if (pos < content_end && this.source.charCodeAt(pos) === 61) pos++;
|
|
112
|
-
|
|
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_first = this.parse_feature_value(this.lexer.token_start, this.lexer.token_end);
|
|
125
126
|
if (value_first !== 0) {
|
|
126
127
|
if (first_child === 0) first_child = value_first;
|
|
127
128
|
else this.arena.set_next_sibling(last_child, value_first);
|
|
@@ -146,7 +147,7 @@ var ConditionParser = class {
|
|
|
146
147
|
while (i < content_end) {
|
|
147
148
|
i = skip_whitespace_and_comments_forward(this.source, i, content_end);
|
|
148
149
|
if (i >= content_end) break;
|
|
149
|
-
|
|
150
|
+
const ch = this.source.charCodeAt(i);
|
|
150
151
|
if (ch === 60 || ch === 62 || ch === 61) {
|
|
151
152
|
has_comparison = true;
|
|
152
153
|
break;
|
|
@@ -154,7 +155,7 @@ var ConditionParser = class {
|
|
|
154
155
|
i++;
|
|
155
156
|
}
|
|
156
157
|
if (has_comparison) return this.parse_feature_range(feature_start, feature_end, content_start, content_end);
|
|
157
|
-
|
|
158
|
+
const feature = this.create_node(33, feature_start, feature_end);
|
|
158
159
|
let colon_pos = -1;
|
|
159
160
|
let j = content_start;
|
|
160
161
|
while (j < content_end) {
|
|
@@ -167,20 +168,20 @@ var ConditionParser = class {
|
|
|
167
168
|
j++;
|
|
168
169
|
}
|
|
169
170
|
if (colon_pos === -1) {
|
|
170
|
-
|
|
171
|
+
const trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
171
172
|
if (trimmed) {
|
|
172
173
|
this.arena.set_content_start_delta(feature, trimmed[0] - feature_start);
|
|
173
174
|
this.arena.set_content_length(feature, trimmed[1] - trimmed[0]);
|
|
174
175
|
}
|
|
175
176
|
} else {
|
|
176
|
-
|
|
177
|
+
const name_trimmed = trim_boundaries(this.source, content_start, colon_pos);
|
|
177
178
|
if (name_trimmed) {
|
|
178
179
|
this.arena.set_content_start_delta(feature, name_trimmed[0] - feature_start);
|
|
179
180
|
this.arena.set_content_length(feature, name_trimmed[1] - name_trimmed[0]);
|
|
180
181
|
}
|
|
181
|
-
|
|
182
|
+
const value_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
|
|
182
183
|
if (value_trimmed) {
|
|
183
|
-
|
|
184
|
+
const value_first = this.parse_feature_value(value_trimmed[0], value_trimmed[1]);
|
|
184
185
|
if (value_first !== 0) this.arena.set_first_child(feature, this.wrap_ratio_value(value_first));
|
|
185
186
|
}
|
|
186
187
|
}
|
|
@@ -190,11 +191,11 @@ var ConditionParser = class {
|
|
|
190
191
|
this.end = end;
|
|
191
192
|
this.lexer.seek(open_paren_start, line, column);
|
|
192
193
|
this.next_token();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
const feature_start = this.lexer.token_start;
|
|
195
|
+
const content_start = this.lexer.pos;
|
|
196
|
+
const matched = this.scan_matching_paren();
|
|
197
|
+
const content_end = this.paren_content_end;
|
|
198
|
+
const feature_end = this.paren_close_end;
|
|
198
199
|
if (!matched) return null;
|
|
199
200
|
return this.parse_media_feature_content(feature_start, feature_end, content_start, content_end);
|
|
200
201
|
}
|
|
@@ -202,63 +203,63 @@ var ConditionParser = class {
|
|
|
202
203
|
this.end = end;
|
|
203
204
|
this.lexer.seek(func_start, line, column);
|
|
204
205
|
this.next_token();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
const func_name_start = this.lexer.token_start;
|
|
207
|
+
const func_name_end = this.lexer.token_end - 1;
|
|
208
|
+
const content_start = this.lexer.token_end;
|
|
208
209
|
this.scan_matching_paren();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
const content_end = this.paren_content_end;
|
|
211
|
+
const func_end = this.paren_close_end;
|
|
212
|
+
const func_node = this.create_node(15, func_start, func_end);
|
|
212
213
|
this.arena.set_content_start_delta(func_node, 0);
|
|
213
214
|
this.arena.set_content_length(func_node, func_name_end - func_name_start);
|
|
214
215
|
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
215
216
|
this.arena.set_value_length(func_node, content_end - content_start);
|
|
216
217
|
if (str_equals_range(this.source, func_name_start, func_name_end, "selector")) {
|
|
217
|
-
|
|
218
|
+
const selector_list = this.selector_parser.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column);
|
|
218
219
|
if (selector_list !== null) this.arena.set_first_child(func_node, selector_list);
|
|
219
220
|
} else if (str_equals_range(this.source, func_name_start, func_name_end, "style")) {
|
|
220
|
-
|
|
221
|
+
const decl_child = this.parse_supports_declaration_content(content_start, content_end);
|
|
221
222
|
if (decl_child !== null) this.arena.set_first_child(func_node, decl_child);
|
|
222
223
|
}
|
|
223
224
|
return func_node;
|
|
224
225
|
}
|
|
225
226
|
parse_supports_declaration_content(content_start, content_end) {
|
|
226
|
-
|
|
227
|
+
const colon_pos = find_colon_at_depth_zero(this.source, content_start, content_end);
|
|
227
228
|
if (colon_pos === -1) return null;
|
|
228
229
|
return this.create_supports_declaration(content_start, content_end, colon_pos);
|
|
229
230
|
}
|
|
230
231
|
parse_supports_condition(start, end, line, column) {
|
|
231
|
-
|
|
232
|
+
const saved_end = this.end;
|
|
232
233
|
this.end = end;
|
|
233
234
|
this.lexer.seek(start, line, column);
|
|
234
|
-
|
|
235
|
+
const nodes = [];
|
|
235
236
|
while (this.lexer.pos < this.end) {
|
|
236
237
|
this.lexer.skip_whitespace_in_range(this.end);
|
|
237
238
|
if (this.lexer.pos >= this.end) break;
|
|
238
239
|
this.next_token();
|
|
239
|
-
|
|
240
|
+
const token_type = this.lexer.token_type;
|
|
240
241
|
if (token_type === 21) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
const feature_start = this.lexer.token_start;
|
|
243
|
+
const content_start = this.lexer.pos;
|
|
244
|
+
const matched = this.scan_matching_paren();
|
|
245
|
+
const content_end = this.paren_content_end;
|
|
246
|
+
const feature_end = this.paren_close_end;
|
|
246
247
|
if (matched) {
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
const query = this.create_node(36, feature_start, feature_end);
|
|
249
|
+
const trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
249
250
|
if (trimmed) {
|
|
250
251
|
this.arena.set_value_start_delta(query, trimmed[0] - feature_start);
|
|
251
252
|
this.arena.set_value_length(query, trimmed[1] - trimmed[0]);
|
|
252
|
-
|
|
253
|
+
const decl_child = this.parse_supports_declaration_content(trimmed[0], trimmed[1]);
|
|
253
254
|
if (decl_child !== null) this.arena.set_first_child(query, decl_child);
|
|
254
255
|
}
|
|
255
256
|
nodes.push(query);
|
|
256
257
|
}
|
|
257
258
|
} else if (token_type === 1) {
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
const token_start = this.lexer.token_start;
|
|
260
|
+
const token_end = this.lexer.token_end;
|
|
260
261
|
if (is_and_or_not_range(this.source, token_start, token_end)) {
|
|
261
|
-
|
|
262
|
+
const op = this.create_node(38, token_start, token_end);
|
|
262
263
|
nodes.push(op);
|
|
263
264
|
}
|
|
264
265
|
} 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 +292,10 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
291
292
|
let first_node = 0;
|
|
292
293
|
let last_node = 0;
|
|
293
294
|
while (this.lexer.pos < this.end) {
|
|
294
|
-
this.lexer.next_token_fast(
|
|
295
|
+
this.lexer.next_token_fast(true);
|
|
295
296
|
if (this.lexer.token_start >= this.end) break;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (token_type === 13) continue;
|
|
299
|
-
let node = this.parse_value_node();
|
|
297
|
+
if (this.lexer.token_type === 26) break;
|
|
298
|
+
const node = this.parse_value_node();
|
|
300
299
|
if (node !== null) {
|
|
301
300
|
if (first_node === 0) first_node = node;
|
|
302
301
|
else this.arena.set_next_sibling(last_node, node);
|
|
@@ -307,9 +306,9 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
307
306
|
return first_node;
|
|
308
307
|
}
|
|
309
308
|
parse_value_node() {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
309
|
+
const token_type = this.lexer.token_type;
|
|
310
|
+
const start = this.lexer.token_start;
|
|
311
|
+
const end = this.lexer.token_end;
|
|
313
312
|
switch (token_type) {
|
|
314
313
|
case 1: return this.create_node(10, start, end);
|
|
315
314
|
case 10: return this.create_node(11, start, end);
|
|
@@ -328,12 +327,12 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
328
327
|
}
|
|
329
328
|
}
|
|
330
329
|
create_node(node_type, start, end) {
|
|
331
|
-
|
|
330
|
+
const node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
332
331
|
this.arena.set_content_length(node, end - start);
|
|
333
332
|
return node;
|
|
334
333
|
}
|
|
335
334
|
parse_operator_node(start, end) {
|
|
336
|
-
|
|
335
|
+
const ch = this.source.charCodeAt(start);
|
|
337
336
|
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_node(16, start, end);
|
|
338
337
|
return null;
|
|
339
338
|
}
|
|
@@ -345,7 +344,7 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
345
344
|
let close_end = this.lexer.token_end;
|
|
346
345
|
while ((!bounded || this.lexer.pos < this.end) && depth > 0) {
|
|
347
346
|
this.lexer.next_token_fast(false);
|
|
348
|
-
|
|
347
|
+
const token_type = this.lexer.token_type;
|
|
349
348
|
if (token_type === 26) break;
|
|
350
349
|
if (bounded && this.lexer.token_start >= this.end) break;
|
|
351
350
|
if (token_type === 21 || token_type === 2) depth++;
|
|
@@ -362,25 +361,25 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
362
361
|
return depth === 0;
|
|
363
362
|
}
|
|
364
363
|
parse_function_node(start, end) {
|
|
365
|
-
|
|
364
|
+
const name_end = end - 1;
|
|
366
365
|
if (str_equals_range(this.source, start, name_end, "if")) return this.parse_if_function_node(start, end);
|
|
367
|
-
|
|
368
|
-
|
|
366
|
+
const is_url = str_equals_range(this.source, start, name_end, "url");
|
|
367
|
+
const node = this.arena.create_node(is_url ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
369
368
|
this.arena.set_content_start_delta(node, 0);
|
|
370
369
|
this.arena.set_content_length(node, name_end - start);
|
|
371
370
|
if (is_url || str_equals_range(this.source, start, name_end, "src")) {
|
|
372
|
-
|
|
371
|
+
const save_pos = this.lexer.save_position();
|
|
373
372
|
this.lexer.next_token_fast(false);
|
|
374
373
|
while (this.lexer.token_type === 13 && this.lexer.pos < this.end) this.lexer.next_token_fast(false);
|
|
375
|
-
|
|
374
|
+
const first_token_type = this.lexer.token_type;
|
|
376
375
|
this.lexer.restore_position(save_pos);
|
|
377
376
|
if (first_token_type === 5) {} else {
|
|
378
377
|
let func_end = end;
|
|
379
|
-
|
|
378
|
+
const content_start = end;
|
|
380
379
|
let content_end = end;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
380
|
+
const matched = this.scan_matching_paren(false);
|
|
381
|
+
const scanned_content_end = this.paren_content_end;
|
|
382
|
+
const scanned_func_end = this.paren_close_end;
|
|
384
383
|
if (matched) {
|
|
385
384
|
content_end = scanned_content_end;
|
|
386
385
|
func_end = scanned_func_end;
|
|
@@ -395,11 +394,11 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
395
394
|
let last_arg = 0;
|
|
396
395
|
let paren_depth = 1;
|
|
397
396
|
let func_end = end;
|
|
398
|
-
|
|
397
|
+
const content_start = end;
|
|
399
398
|
let content_end = end;
|
|
400
399
|
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
401
|
-
this.lexer.next_token_fast(
|
|
402
|
-
|
|
400
|
+
this.lexer.next_token_fast(true);
|
|
401
|
+
const token_type = this.lexer.token_type;
|
|
403
402
|
if (token_type === 26) break;
|
|
404
403
|
if (this.lexer.token_start >= this.end) break;
|
|
405
404
|
if (token_type === 22) {
|
|
@@ -410,8 +409,7 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
410
409
|
break;
|
|
411
410
|
}
|
|
412
411
|
}
|
|
413
|
-
|
|
414
|
-
let arg_node = this.parse_value_node();
|
|
412
|
+
const arg_node = this.parse_value_node();
|
|
415
413
|
if (arg_node !== null) {
|
|
416
414
|
if (first_arg === 0) first_arg = arg_node;
|
|
417
415
|
else this.arena.set_next_sibling(last_arg, arg_node);
|
|
@@ -425,20 +423,20 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
425
423
|
return node;
|
|
426
424
|
}
|
|
427
425
|
parse_if_function_node(start, end) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
426
|
+
const name_end = end - 1;
|
|
427
|
+
const save_line = this.lexer.token_line;
|
|
428
|
+
const save_col = this.lexer.token_column;
|
|
429
|
+
const node = this.arena.create_node(15, start, 0, save_line, save_col);
|
|
432
430
|
this.arena.set_content_start_delta(node, 0);
|
|
433
431
|
this.arena.set_content_length(node, name_end - start);
|
|
434
|
-
|
|
432
|
+
const branches = [];
|
|
435
433
|
let func_end = end;
|
|
436
|
-
|
|
434
|
+
const content_start = end;
|
|
437
435
|
let content_end = end;
|
|
438
436
|
let if_closed = false;
|
|
439
437
|
while (this.lexer.pos < this.end && !if_closed) {
|
|
440
438
|
this.lexer.next_token_fast(false);
|
|
441
|
-
|
|
439
|
+
const tt = this.lexer.token_type;
|
|
442
440
|
if (tt === 26) break;
|
|
443
441
|
if (this.lexer.token_start >= this.end) break;
|
|
444
442
|
if (tt === 22) {
|
|
@@ -447,16 +445,16 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
447
445
|
break;
|
|
448
446
|
}
|
|
449
447
|
if (tt === 13 || tt === 17 || tt === 16) continue;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
448
|
+
const branch_start = this.lexer.token_start;
|
|
449
|
+
const branch_line = this.lexer.token_line;
|
|
450
|
+
const branch_col = this.lexer.token_column;
|
|
451
|
+
const condition_node = this.parse_if_condition();
|
|
454
452
|
if (condition_node === null) continue;
|
|
455
|
-
|
|
453
|
+
const condition_end_pos = this.arena.get_start_offset(condition_node) + this.arena.get_length(condition_node);
|
|
456
454
|
let colon_found = false;
|
|
457
455
|
while (this.lexer.pos < this.end) {
|
|
458
456
|
this.lexer.next_token_fast(false);
|
|
459
|
-
|
|
457
|
+
const t = this.lexer.token_type;
|
|
460
458
|
if (t === 26) break;
|
|
461
459
|
if (this.lexer.token_start >= this.end) break;
|
|
462
460
|
if (t === 13) continue;
|
|
@@ -471,14 +469,14 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
471
469
|
break;
|
|
472
470
|
}
|
|
473
471
|
}
|
|
474
|
-
|
|
472
|
+
const value_tokens = [];
|
|
475
473
|
let value_start = -1;
|
|
476
474
|
let value_last_end = condition_end_pos;
|
|
477
475
|
let value_line = 0;
|
|
478
476
|
let value_col = 0;
|
|
479
477
|
if (colon_found && !if_closed) while (this.lexer.pos < this.end) {
|
|
480
478
|
this.lexer.next_token_fast(false);
|
|
481
|
-
|
|
479
|
+
const t = this.lexer.token_type;
|
|
482
480
|
if (t === 26) break;
|
|
483
481
|
if (this.lexer.token_start >= this.end) break;
|
|
484
482
|
if (t === 13) continue;
|
|
@@ -489,9 +487,9 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
489
487
|
if_closed = true;
|
|
490
488
|
break;
|
|
491
489
|
}
|
|
492
|
-
|
|
490
|
+
const vnode = this.parse_value_node();
|
|
493
491
|
if (vnode !== null) {
|
|
494
|
-
|
|
492
|
+
const ns = this.arena.get_start_offset(vnode);
|
|
495
493
|
if (value_start === -1) {
|
|
496
494
|
value_start = ns;
|
|
497
495
|
value_line = this.arena.get_start_line(vnode);
|
|
@@ -506,15 +504,15 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
506
504
|
value_node = this.arena.create_node(50, value_start, value_last_end - value_start, value_line, value_col);
|
|
507
505
|
this.arena.append_children(value_node, value_tokens);
|
|
508
506
|
}
|
|
509
|
-
|
|
510
|
-
|
|
507
|
+
const branch_end = value_node === null ? condition_end_pos : value_last_end;
|
|
508
|
+
const branch_node = this.arena.create_node(59, branch_start, branch_end - branch_start, branch_line, branch_col);
|
|
511
509
|
this.arena.set_content_start_delta(branch_node, 0);
|
|
512
510
|
this.arena.set_content_length(branch_node, condition_end_pos - branch_start);
|
|
513
511
|
if (value_start !== -1) {
|
|
514
512
|
this.arena.set_value_start_delta(branch_node, value_start - branch_start);
|
|
515
513
|
this.arena.set_value_length(branch_node, value_last_end - value_start);
|
|
516
514
|
}
|
|
517
|
-
|
|
515
|
+
const branch_children = [condition_node];
|
|
518
516
|
if (value_node !== null) branch_children.push(value_node);
|
|
519
517
|
this.arena.append_children(branch_node, branch_children);
|
|
520
518
|
branches.push(branch_node);
|
|
@@ -543,13 +541,13 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
543
541
|
let component_count = 0;
|
|
544
542
|
let compound = false;
|
|
545
543
|
for (;;) {
|
|
546
|
-
|
|
544
|
+
const tt = this.lexer.token_type;
|
|
547
545
|
let component = null;
|
|
548
546
|
let is_operator = false;
|
|
549
547
|
if (tt === 2) component = this.parse_if_condition_function(this.lexer.token_start, this.lexer.token_end);
|
|
550
548
|
else if (tt === 1) {
|
|
551
|
-
|
|
552
|
-
|
|
549
|
+
const token_start = this.lexer.token_start;
|
|
550
|
+
const token_end = this.lexer.token_end;
|
|
553
551
|
if (is_and_or_not_range(this.source, token_start, token_end)) {
|
|
554
552
|
is_operator = true;
|
|
555
553
|
component = this.arena.create_node(38, token_start, token_end - token_start, this.lexer.token_line, this.lexer.token_column);
|
|
@@ -562,8 +560,8 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
562
560
|
last = component;
|
|
563
561
|
}
|
|
564
562
|
if (tt !== 2 && !is_operator) break;
|
|
565
|
-
|
|
566
|
-
|
|
563
|
+
const saved = this.lexer.save_position();
|
|
564
|
+
const next_tt = this.next_significant_token();
|
|
567
565
|
if (next_tt === 2) {
|
|
568
566
|
compound = true;
|
|
569
567
|
continue;
|
|
@@ -579,39 +577,39 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
579
577
|
}
|
|
580
578
|
if (first === 0) return null;
|
|
581
579
|
if (component_count === 1 && !compound) return first;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
580
|
+
const wrapper_start = this.arena.get_start_offset(first);
|
|
581
|
+
const last_sibling = this.arena.get_last_sibling(first);
|
|
582
|
+
const wrapper_end = this.arena.get_start_offset(last_sibling) + this.arena.get_length(last_sibling);
|
|
583
|
+
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
584
|
this.arena.set_first_child(wrapper, first);
|
|
587
585
|
return wrapper;
|
|
588
586
|
}
|
|
589
587
|
parse_if_condition_function(func_start, token_end) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
588
|
+
const func_name_end = token_end - 1;
|
|
589
|
+
const func_line = this.lexer.token_line;
|
|
590
|
+
const func_col = this.lexer.token_column;
|
|
591
|
+
const content_start = token_end;
|
|
594
592
|
let content_end = content_start;
|
|
595
593
|
let func_end = content_start;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
594
|
+
const matched = this.scan_matching_paren(true);
|
|
595
|
+
const scanned_content_end = this.paren_content_end;
|
|
596
|
+
const scanned_func_end = this.paren_close_end;
|
|
599
597
|
if (matched) {
|
|
600
598
|
content_end = scanned_content_end;
|
|
601
599
|
func_end = scanned_func_end;
|
|
602
600
|
}
|
|
603
|
-
|
|
601
|
+
const func_node = this.arena.create_node(15, func_start, func_end - func_start, func_line, func_col);
|
|
604
602
|
this.arena.set_content_start_delta(func_node, 0);
|
|
605
603
|
this.arena.set_content_length(func_node, func_name_end - func_start);
|
|
606
604
|
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
607
605
|
this.arena.set_value_length(func_node, content_end - content_start);
|
|
608
606
|
let child_nodes = [];
|
|
609
607
|
if (str_equals_range(this.source, func_start, func_name_end, "style")) {
|
|
610
|
-
|
|
608
|
+
const decl = this.condition_parser.parse_supports_declaration_content(content_start, content_end);
|
|
611
609
|
if (decl === null) child_nodes = this.condition_parser.parse_supports_condition(content_start, content_end, func_line, func_col);
|
|
612
610
|
else child_nodes = [decl];
|
|
613
611
|
} else if (str_equals_range(this.source, func_start, func_name_end, "supports")) {
|
|
614
|
-
|
|
612
|
+
const decl = this.condition_parser.parse_supports_declaration_content(content_start, content_end);
|
|
615
613
|
if (decl === null) child_nodes = this.condition_parser.parse_supports_condition(content_start, content_end, func_line, func_col);
|
|
616
614
|
else child_nodes = [decl];
|
|
617
615
|
} 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 +618,16 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
620
618
|
return func_node;
|
|
621
619
|
}
|
|
622
620
|
parse_value_nodes_in_range(start, end) {
|
|
623
|
-
|
|
624
|
-
|
|
621
|
+
const saved_end = this.end;
|
|
622
|
+
const saved_pos = this.lexer.save_position();
|
|
625
623
|
this.end = end;
|
|
626
624
|
this.lexer.seek(start, this.lexer.line, this.lexer.column);
|
|
627
|
-
|
|
625
|
+
const nodes = [];
|
|
628
626
|
while (this.lexer.pos < this.end) {
|
|
629
|
-
this.lexer.next_token_fast(
|
|
627
|
+
this.lexer.next_token_fast(true);
|
|
630
628
|
if (this.lexer.token_start >= this.end) break;
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (token_type === 13) continue;
|
|
634
|
-
let node = this.parse_value_node();
|
|
629
|
+
if (this.lexer.token_type === 26) break;
|
|
630
|
+
const node = this.parse_value_node();
|
|
635
631
|
if (node !== null) nodes.push(node);
|
|
636
632
|
}
|
|
637
633
|
this.lexer.restore_position(saved_pos);
|
|
@@ -639,14 +635,14 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
639
635
|
return nodes;
|
|
640
636
|
}
|
|
641
637
|
parse_parenthesis_node(start, end) {
|
|
642
|
-
|
|
638
|
+
const node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
643
639
|
let first_child = 0;
|
|
644
640
|
let last_child = 0;
|
|
645
641
|
let paren_depth = 1;
|
|
646
642
|
let paren_end = end;
|
|
647
643
|
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
648
|
-
this.lexer.next_token_fast(
|
|
649
|
-
|
|
644
|
+
this.lexer.next_token_fast(true);
|
|
645
|
+
const token_type = this.lexer.token_type;
|
|
650
646
|
if (token_type === 26) break;
|
|
651
647
|
if (this.lexer.token_start >= this.end) break;
|
|
652
648
|
if (token_type === 22) {
|
|
@@ -656,8 +652,7 @@ var ValueNodeParser = class ValueNodeParser {
|
|
|
656
652
|
break;
|
|
657
653
|
}
|
|
658
654
|
}
|
|
659
|
-
|
|
660
|
-
let child_node = this.parse_value_node();
|
|
655
|
+
const child_node = this.parse_value_node();
|
|
661
656
|
if (child_node !== null) {
|
|
662
657
|
if (first_child === 0) first_child = child_node;
|
|
663
658
|
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-DG8OKqPu.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