@projectwallace/css-parser 0.13.5 → 0.13.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/dist/css-node-DqyvMXBN.d.ts +313 -0
- package/dist/css-node-Uj4oBgaw.js +647 -0
- package/dist/index.d.ts +150 -16
- package/dist/index.js +103 -13
- package/dist/parse-anplusb.d.ts +26 -2
- package/dist/parse-anplusb.js +191 -207
- package/dist/parse-atrule-prelude.d.ts +40 -2
- package/dist/parse-atrule-prelude.js +556 -652
- package/dist/parse-declaration.d.ts +16 -2
- package/dist/parse-declaration.js +140 -167
- package/dist/parse-dimension-CCn_XRDe.js +177 -0
- package/dist/parse-dimension.d.ts +6 -3
- package/dist/parse-dimension.js +1 -35
- package/dist/parse-selector.d.ts +37 -2
- package/dist/parse-selector.js +508 -635
- package/dist/parse-utils-DnsZRpfd.js +98 -0
- package/dist/parse-value.d.ts +23 -2
- package/dist/parse-value.js +176 -224
- package/dist/parse.d.ts +37 -8
- package/dist/parse.js +252 -353
- package/dist/tokenize-BQFB1jXg.js +540 -0
- package/dist/tokenize-odLrcjj2.d.ts +110 -0
- package/dist/tokenize.d.ts +2 -26
- package/dist/tokenize.js +1 -545
- package/package.json +20 -26
- package/dist/arena.d.ts +0 -60
- package/dist/arena.js +0 -291
- package/dist/char-types.d.ts +0 -14
- package/dist/char-types.js +0 -53
- package/dist/constants.d.ts +0 -44
- package/dist/constants.js +0 -51
- package/dist/css-node.d.ts +0 -203
- package/dist/css-node.js +0 -498
- package/dist/parse-utils.d.ts +0 -1
- package/dist/parse-utils.js +0 -60
- package/dist/string-utils.d.ts +0 -99
- package/dist/string-utils.js +0 -129
- package/dist/token-types.d.ts +0 -35
- package/dist/token-types.js +0 -29
- package/dist/walk.d.ts +0 -28
- package/dist/walk.js +0 -51
package/dist/parse.js
CHANGED
|
@@ -1,356 +1,255 @@
|
|
|
1
|
-
import { Lexer } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SelectorParser } from
|
|
5
|
-
import { AtRulePreludeParser } from
|
|
6
|
-
import { DeclarationParser } from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
let block_column = this.lexer.token_column;
|
|
252
|
-
let block_node = this.arena.create_node(
|
|
253
|
-
BLOCK,
|
|
254
|
-
block_start,
|
|
255
|
-
0,
|
|
256
|
-
// length unknown yet
|
|
257
|
-
block_line,
|
|
258
|
-
block_column
|
|
259
|
-
);
|
|
260
|
-
let has_declarations = this.atrule_has_declarations(at_rule_name);
|
|
261
|
-
let is_conditional = this.atrule_is_conditional(at_rule_name);
|
|
262
|
-
let block_children = [];
|
|
263
|
-
if (has_declarations) {
|
|
264
|
-
while (!this.is_eof()) {
|
|
265
|
-
let token_type = this.peek_type();
|
|
266
|
-
if (token_type === TOKEN_RIGHT_BRACE) break;
|
|
267
|
-
let declaration = this.parse_declaration();
|
|
268
|
-
if (declaration !== null) {
|
|
269
|
-
block_children.push(declaration);
|
|
270
|
-
} else {
|
|
271
|
-
this.next_token();
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
} else if (is_conditional) {
|
|
275
|
-
while (!this.is_eof()) {
|
|
276
|
-
let token_type = this.peek_type();
|
|
277
|
-
if (token_type === TOKEN_RIGHT_BRACE) break;
|
|
278
|
-
if (token_type === TOKEN_AT_KEYWORD) {
|
|
279
|
-
let nested_at_rule = this.parse_atrule();
|
|
280
|
-
if (nested_at_rule !== null) {
|
|
281
|
-
block_children.push(nested_at_rule);
|
|
282
|
-
} else {
|
|
283
|
-
this.next_token();
|
|
284
|
-
}
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
let declaration = this.parse_declaration();
|
|
288
|
-
if (declaration !== null) {
|
|
289
|
-
block_children.push(declaration);
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
let nested_rule = this.parse_style_rule();
|
|
293
|
-
if (nested_rule !== null) {
|
|
294
|
-
block_children.push(nested_rule);
|
|
295
|
-
} else {
|
|
296
|
-
this.next_token();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
} else {
|
|
300
|
-
while (!this.is_eof()) {
|
|
301
|
-
let token_type = this.peek_type();
|
|
302
|
-
if (token_type === TOKEN_RIGHT_BRACE) break;
|
|
303
|
-
let rule = this.parse_rule();
|
|
304
|
-
if (rule !== null) {
|
|
305
|
-
block_children.push(rule);
|
|
306
|
-
} else {
|
|
307
|
-
this.next_token();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
if (this.peek_type() === TOKEN_RIGHT_BRACE) {
|
|
312
|
-
let block_end = this.lexer.token_start;
|
|
313
|
-
last_end = this.lexer.token_end;
|
|
314
|
-
this.next_token();
|
|
315
|
-
this.arena.set_length(block_node, block_end - block_start);
|
|
316
|
-
} else {
|
|
317
|
-
this.arena.set_length(block_node, last_end - block_start);
|
|
318
|
-
}
|
|
319
|
-
this.arena.append_children(block_node, block_children);
|
|
320
|
-
let at_rule_children = [];
|
|
321
|
-
if (prelude_wrapper !== null) {
|
|
322
|
-
at_rule_children.push(prelude_wrapper);
|
|
323
|
-
}
|
|
324
|
-
at_rule_children.push(block_node);
|
|
325
|
-
this.arena.set_length(at_rule, last_end - at_rule_start);
|
|
326
|
-
this.arena.append_children(at_rule, at_rule_children);
|
|
327
|
-
} else if (this.peek_type() === TOKEN_SEMICOLON) {
|
|
328
|
-
last_end = this.lexer.token_end;
|
|
329
|
-
this.next_token();
|
|
330
|
-
this.arena.set_length(at_rule, last_end - at_rule_start);
|
|
331
|
-
if (prelude_wrapper !== null) {
|
|
332
|
-
this.arena.append_children(at_rule, [prelude_wrapper]);
|
|
333
|
-
}
|
|
334
|
-
} else {
|
|
335
|
-
this.arena.set_length(at_rule, last_end - at_rule_start);
|
|
336
|
-
if (prelude_wrapper !== null) {
|
|
337
|
-
this.arena.append_children(at_rule, [prelude_wrapper]);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return at_rule;
|
|
341
|
-
}
|
|
342
|
-
// Determine if an at-rule contains declarations or nested rules
|
|
343
|
-
atrule_has_declarations(name) {
|
|
344
|
-
return DECLARATION_AT_RULES.has(name.toLowerCase());
|
|
345
|
-
}
|
|
346
|
-
// Determine if an at-rule is conditional (can contain both declarations and rules in CSS Nesting)
|
|
347
|
-
atrule_is_conditional(name) {
|
|
348
|
-
return CONDITIONAL_AT_RULES.has(name.toLowerCase());
|
|
349
|
-
}
|
|
350
|
-
}
|
|
1
|
+
import { t as Lexer } from "./tokenize-BQFB1jXg.js";
|
|
2
|
+
import { C as CSSDataArena, r as CSSNode } from "./css-node-Uj4oBgaw.js";
|
|
3
|
+
import { i as trim_boundaries } from "./parse-utils-DnsZRpfd.js";
|
|
4
|
+
import { SelectorParser } from "./parse-selector.js";
|
|
5
|
+
import { AtRulePreludeParser } from "./parse-atrule-prelude.js";
|
|
6
|
+
import { DeclarationParser } from "./parse-declaration.js";
|
|
7
|
+
//#region src/parse.ts
|
|
8
|
+
let DECLARATION_AT_RULES = new Set([
|
|
9
|
+
"font-face",
|
|
10
|
+
"font-feature-values",
|
|
11
|
+
"page",
|
|
12
|
+
"property",
|
|
13
|
+
"counter-style",
|
|
14
|
+
"color-profile",
|
|
15
|
+
"font-palette-values",
|
|
16
|
+
"position-try",
|
|
17
|
+
"view-transition"
|
|
18
|
+
]);
|
|
19
|
+
/** @internal */
|
|
20
|
+
var Parser = class {
|
|
21
|
+
source;
|
|
22
|
+
lexer;
|
|
23
|
+
arena;
|
|
24
|
+
selector_parser;
|
|
25
|
+
prelude_parser;
|
|
26
|
+
declaration_parser;
|
|
27
|
+
parse_values_enabled;
|
|
28
|
+
parse_selectors_enabled;
|
|
29
|
+
parse_atrule_preludes_enabled;
|
|
30
|
+
constructor(source, options) {
|
|
31
|
+
this.source = source;
|
|
32
|
+
let opts = options || {};
|
|
33
|
+
this.parse_values_enabled = opts.parse_values ?? true;
|
|
34
|
+
this.parse_selectors_enabled = opts.parse_selectors ?? true;
|
|
35
|
+
this.parse_atrule_preludes_enabled = opts.parse_atrule_preludes ?? true;
|
|
36
|
+
this.lexer = new Lexer(source, opts.on_comment);
|
|
37
|
+
this.arena = new CSSDataArena(CSSDataArena.capacity_for_source(source.length));
|
|
38
|
+
this.selector_parser = this.parse_selectors_enabled ? new SelectorParser(this.arena, source) : null;
|
|
39
|
+
this.prelude_parser = this.parse_atrule_preludes_enabled ? new AtRulePreludeParser(this.arena, source) : null;
|
|
40
|
+
this.declaration_parser = new DeclarationParser(this.arena, source, this.parse_values_enabled);
|
|
41
|
+
}
|
|
42
|
+
get_arena() {
|
|
43
|
+
return this.arena;
|
|
44
|
+
}
|
|
45
|
+
get_source() {
|
|
46
|
+
return this.source;
|
|
47
|
+
}
|
|
48
|
+
next_token() {
|
|
49
|
+
this.lexer.next_token_fast(true);
|
|
50
|
+
}
|
|
51
|
+
peek_type() {
|
|
52
|
+
return this.lexer.token_type;
|
|
53
|
+
}
|
|
54
|
+
is_eof() {
|
|
55
|
+
return this.peek_type() === 26;
|
|
56
|
+
}
|
|
57
|
+
parse() {
|
|
58
|
+
this.next_token();
|
|
59
|
+
let stylesheet = this.arena.create_node(1, 0, this.source.length, 1, 1);
|
|
60
|
+
let rules = [];
|
|
61
|
+
while (!this.is_eof()) {
|
|
62
|
+
let rule = this.parse_rule();
|
|
63
|
+
if (rule !== null) rules.push(rule);
|
|
64
|
+
else this.next_token();
|
|
65
|
+
}
|
|
66
|
+
this.arena.append_children(stylesheet, rules);
|
|
67
|
+
return new CSSNode(this.arena, this.source, stylesheet);
|
|
68
|
+
}
|
|
69
|
+
parse_rule() {
|
|
70
|
+
if (this.is_eof()) return null;
|
|
71
|
+
if (this.peek_type() === 3) return this.parse_atrule();
|
|
72
|
+
return this.parse_style_rule();
|
|
73
|
+
}
|
|
74
|
+
parse_style_rule() {
|
|
75
|
+
if (this.is_eof()) return null;
|
|
76
|
+
let rule_start = this.lexer.token_start;
|
|
77
|
+
let rule_line = this.lexer.token_line;
|
|
78
|
+
let rule_column = this.lexer.token_column;
|
|
79
|
+
let style_rule = this.arena.create_node(2, rule_start, 0, rule_line, rule_column);
|
|
80
|
+
let selector = this.parse_selector();
|
|
81
|
+
if (this.peek_type() !== 23) return null;
|
|
82
|
+
let block_start = this.lexer.token_end;
|
|
83
|
+
this.next_token();
|
|
84
|
+
this.arena.set_flag(style_rule, 8);
|
|
85
|
+
let block_line = this.lexer.token_line;
|
|
86
|
+
let block_column = this.lexer.token_column;
|
|
87
|
+
let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
|
|
88
|
+
let block_children = [];
|
|
89
|
+
while (!this.is_eof()) {
|
|
90
|
+
let token_type = this.peek_type();
|
|
91
|
+
if (token_type === 24) break;
|
|
92
|
+
if (token_type === 3) {
|
|
93
|
+
let nested_at_rule = this.parse_atrule();
|
|
94
|
+
if (nested_at_rule !== null) block_children.push(nested_at_rule);
|
|
95
|
+
else this.next_token();
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
let declaration = this.parse_declaration();
|
|
99
|
+
if (declaration !== null) {
|
|
100
|
+
this.arena.set_flag(style_rule, 32);
|
|
101
|
+
block_children.push(declaration);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let nested_rule = this.parse_style_rule();
|
|
105
|
+
if (nested_rule !== null) block_children.push(nested_rule);
|
|
106
|
+
else this.next_token();
|
|
107
|
+
}
|
|
108
|
+
let block_end = this.lexer.token_start;
|
|
109
|
+
let rule_end = this.lexer.token_end;
|
|
110
|
+
if (this.peek_type() === 24) {
|
|
111
|
+
block_end = this.lexer.token_start;
|
|
112
|
+
rule_end = this.lexer.token_end;
|
|
113
|
+
this.next_token();
|
|
114
|
+
}
|
|
115
|
+
this.arena.set_length(block_node, block_end - block_start);
|
|
116
|
+
this.arena.append_children(block_node, block_children);
|
|
117
|
+
this.arena.set_length(style_rule, rule_end - rule_start);
|
|
118
|
+
let style_rule_children = [];
|
|
119
|
+
if (selector !== null) style_rule_children.push(selector);
|
|
120
|
+
style_rule_children.push(block_node);
|
|
121
|
+
this.arena.append_children(style_rule, style_rule_children);
|
|
122
|
+
return style_rule;
|
|
123
|
+
}
|
|
124
|
+
parse_selector() {
|
|
125
|
+
if (this.is_eof()) return null;
|
|
126
|
+
let selector_start = this.lexer.token_start;
|
|
127
|
+
let selector_line = this.lexer.token_line;
|
|
128
|
+
let selector_column = this.lexer.token_column;
|
|
129
|
+
let last_end = this.lexer.token_end;
|
|
130
|
+
while (!this.is_eof() && this.peek_type() !== 23) {
|
|
131
|
+
last_end = this.lexer.token_end;
|
|
132
|
+
this.next_token();
|
|
133
|
+
}
|
|
134
|
+
if (this.parse_selectors_enabled && this.selector_parser) {
|
|
135
|
+
let selector = this.selector_parser.parse_selector(selector_start, last_end, selector_line, selector_column);
|
|
136
|
+
if (selector !== null) return selector;
|
|
137
|
+
}
|
|
138
|
+
let node_type = this.parse_selectors_enabled ? 20 : 8;
|
|
139
|
+
return this.arena.create_node(node_type, selector_start, last_end - selector_start, selector_line, selector_column);
|
|
140
|
+
}
|
|
141
|
+
parse_declaration() {
|
|
142
|
+
const token_type = this.peek_type();
|
|
143
|
+
if (token_type === 1 || token_type === 3 || token_type === 4) return this.declaration_parser.parse_declaration_with_lexer(this.lexer, this.source.length);
|
|
144
|
+
if (token_type === 9 || token_type === 21 || token_type === 22 || token_type === 19 || token_type === 20 || token_type === 18 || token_type === 16) {
|
|
145
|
+
const char_code = this.source.charCodeAt(this.lexer.token_start);
|
|
146
|
+
if (char_code === 46 || char_code === 62 || char_code === 43 || char_code === 126 || char_code === 38) return null;
|
|
147
|
+
return this.declaration_parser.parse_declaration_with_lexer(this.lexer, this.source.length);
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
parse_atrule() {
|
|
152
|
+
if (this.peek_type() !== 3) return null;
|
|
153
|
+
let at_rule_start = this.lexer.token_start;
|
|
154
|
+
let at_rule_line = this.lexer.token_line;
|
|
155
|
+
let at_rule_column = this.lexer.token_column;
|
|
156
|
+
let name_start = this.lexer.token_start + 1;
|
|
157
|
+
let name_length = this.lexer.token_end - name_start;
|
|
158
|
+
let at_rule_name = this.source.substring(name_start, this.lexer.token_end);
|
|
159
|
+
this.next_token();
|
|
160
|
+
let at_rule = this.arena.create_node(3, at_rule_start, 0, at_rule_line, at_rule_column);
|
|
161
|
+
this.arena.set_content_start_delta(at_rule, name_start - at_rule_start);
|
|
162
|
+
this.arena.set_content_length(at_rule, name_length);
|
|
163
|
+
let prelude_start = this.lexer.token_start;
|
|
164
|
+
let prelude_end = prelude_start;
|
|
165
|
+
let paren_depth = 0;
|
|
166
|
+
while (!this.is_eof()) {
|
|
167
|
+
let token_type = this.peek_type();
|
|
168
|
+
if (token_type === 21 || token_type === 2) paren_depth++;
|
|
169
|
+
else if (token_type === 22) paren_depth--;
|
|
170
|
+
if (token_type === 23 && paren_depth === 0) break;
|
|
171
|
+
if (token_type === 17 && paren_depth === 0) break;
|
|
172
|
+
prelude_end = this.lexer.token_end;
|
|
173
|
+
this.next_token();
|
|
174
|
+
}
|
|
175
|
+
let trimmed = trim_boundaries(this.source, prelude_start, prelude_end);
|
|
176
|
+
let prelude_wrapper = null;
|
|
177
|
+
if (trimmed) if (this.prelude_parser) {
|
|
178
|
+
let prelude_nodes = this.prelude_parser.parse_prelude(at_rule_name, trimmed[0], trimmed[1], at_rule_line, at_rule_column);
|
|
179
|
+
if (prelude_nodes.length > 0) {
|
|
180
|
+
prelude_wrapper = this.arena.create_node(40, trimmed[0], trimmed[1] - trimmed[0], at_rule_line, at_rule_column);
|
|
181
|
+
this.arena.append_children(prelude_wrapper, prelude_nodes);
|
|
182
|
+
} else prelude_wrapper = this.arena.create_node(8, trimmed[0], trimmed[1] - trimmed[0], at_rule_line, at_rule_column);
|
|
183
|
+
} else prelude_wrapper = this.arena.create_node(8, trimmed[0], trimmed[1] - trimmed[0], at_rule_line, at_rule_column);
|
|
184
|
+
let last_end = this.lexer.token_end;
|
|
185
|
+
if (this.peek_type() === 23) {
|
|
186
|
+
let block_start = this.lexer.token_end;
|
|
187
|
+
this.next_token();
|
|
188
|
+
this.arena.set_flag(at_rule, 8);
|
|
189
|
+
let block_line = this.lexer.token_line;
|
|
190
|
+
let block_column = this.lexer.token_column;
|
|
191
|
+
let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
|
|
192
|
+
let has_declarations = this.atrule_has_declarations(at_rule_name);
|
|
193
|
+
let block_children = [];
|
|
194
|
+
if (has_declarations) while (!this.is_eof()) {
|
|
195
|
+
if (this.peek_type() === 24) break;
|
|
196
|
+
let declaration = this.parse_declaration();
|
|
197
|
+
if (declaration !== null) block_children.push(declaration);
|
|
198
|
+
else this.next_token();
|
|
199
|
+
}
|
|
200
|
+
else while (!this.is_eof()) {
|
|
201
|
+
let token_type = this.peek_type();
|
|
202
|
+
if (token_type === 24) break;
|
|
203
|
+
if (token_type === 3) {
|
|
204
|
+
let nested_at_rule = this.parse_atrule();
|
|
205
|
+
if (nested_at_rule !== null) block_children.push(nested_at_rule);
|
|
206
|
+
else this.next_token();
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
let declaration = this.parse_declaration();
|
|
210
|
+
if (declaration !== null) {
|
|
211
|
+
block_children.push(declaration);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
let nested_rule = this.parse_style_rule();
|
|
215
|
+
if (nested_rule !== null) block_children.push(nested_rule);
|
|
216
|
+
else this.next_token();
|
|
217
|
+
}
|
|
218
|
+
if (this.peek_type() === 24) {
|
|
219
|
+
let block_end = this.lexer.token_start;
|
|
220
|
+
last_end = this.lexer.token_end;
|
|
221
|
+
this.next_token();
|
|
222
|
+
this.arena.set_length(block_node, block_end - block_start);
|
|
223
|
+
} else this.arena.set_length(block_node, last_end - block_start);
|
|
224
|
+
this.arena.append_children(block_node, block_children);
|
|
225
|
+
let at_rule_children = [];
|
|
226
|
+
if (prelude_wrapper !== null) at_rule_children.push(prelude_wrapper);
|
|
227
|
+
at_rule_children.push(block_node);
|
|
228
|
+
this.arena.set_length(at_rule, last_end - at_rule_start);
|
|
229
|
+
this.arena.append_children(at_rule, at_rule_children);
|
|
230
|
+
} else if (this.peek_type() === 17) {
|
|
231
|
+
last_end = this.lexer.token_end;
|
|
232
|
+
this.next_token();
|
|
233
|
+
this.arena.set_length(at_rule, last_end - at_rule_start);
|
|
234
|
+
if (prelude_wrapper !== null) this.arena.append_children(at_rule, [prelude_wrapper]);
|
|
235
|
+
} else {
|
|
236
|
+
this.arena.set_length(at_rule, last_end - at_rule_start);
|
|
237
|
+
if (prelude_wrapper !== null) this.arena.append_children(at_rule, [prelude_wrapper]);
|
|
238
|
+
}
|
|
239
|
+
return at_rule;
|
|
240
|
+
}
|
|
241
|
+
atrule_has_declarations(name) {
|
|
242
|
+
return DECLARATION_AT_RULES.has(name.toLowerCase());
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Parse CSS and return an AST
|
|
247
|
+
* @param source - The CSS source code to parse
|
|
248
|
+
* @param options - Parser options
|
|
249
|
+
* @returns The root CSSNode of the AST
|
|
250
|
+
*/
|
|
351
251
|
function parse(source, options) {
|
|
352
|
-
|
|
353
|
-
return parser.parse();
|
|
252
|
+
return new Parser(source, options).parse();
|
|
354
253
|
}
|
|
355
|
-
|
|
254
|
+
//#endregion
|
|
356
255
|
export { Parser, parse };
|