@projectwallace/css-parser 0.6.2 → 0.6.3
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.
|
@@ -8,6 +8,7 @@ export declare class AtRulePreludeParser {
|
|
|
8
8
|
constructor(arena: CSSDataArena, source: string);
|
|
9
9
|
parse_prelude(at_rule_name: string, start: number, end: number, line?: number, column?: number): number[];
|
|
10
10
|
private parse_media_query_list;
|
|
11
|
+
private create_node;
|
|
11
12
|
private is_and_or_not;
|
|
12
13
|
private parse_single_media_query;
|
|
13
14
|
private parse_media_feature;
|
|
@@ -52,6 +52,15 @@ class AtRulePreludeParser {
|
|
|
52
52
|
}
|
|
53
53
|
return nodes;
|
|
54
54
|
}
|
|
55
|
+
create_node(type, start, end) {
|
|
56
|
+
let node = this.arena.create_node();
|
|
57
|
+
this.arena.set_type(node, type);
|
|
58
|
+
this.arena.set_start_offset(node, start);
|
|
59
|
+
this.arena.set_length(node, end - start);
|
|
60
|
+
this.arena.set_start_line(node, this.lexer.token_line);
|
|
61
|
+
this.arena.set_start_column(node, this.lexer.token_column);
|
|
62
|
+
return node;
|
|
63
|
+
}
|
|
55
64
|
is_and_or_not(str) {
|
|
56
65
|
if (str.length > 3 || str.length < 2) return false;
|
|
57
66
|
return str_equals("and", str) || str_equals("or", str) || str_equals("not", str);
|
|
@@ -59,7 +68,7 @@ class AtRulePreludeParser {
|
|
|
59
68
|
// Parse a single media query: screen and (min-width: 768px)
|
|
60
69
|
parse_single_media_query() {
|
|
61
70
|
let query_start = this.lexer.pos;
|
|
62
|
-
|
|
71
|
+
this.lexer.line;
|
|
63
72
|
this.skip_whitespace();
|
|
64
73
|
if (this.lexer.pos >= this.prelude_end) return null;
|
|
65
74
|
let token_start = this.lexer.pos;
|
|
@@ -87,19 +96,10 @@ class AtRulePreludeParser {
|
|
|
87
96
|
} else if (token_type === TOKEN_IDENT) {
|
|
88
97
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
89
98
|
if (this.is_and_or_not(text)) {
|
|
90
|
-
let op = this.
|
|
91
|
-
this.arena.set_type(op, NODE_PRELUDE_OPERATOR);
|
|
92
|
-
this.arena.set_start_offset(op, this.lexer.token_start);
|
|
93
|
-
this.arena.set_length(op, this.lexer.token_end - this.lexer.token_start);
|
|
94
|
-
this.arena.set_start_line(op, this.lexer.token_line);
|
|
99
|
+
let op = this.create_node(NODE_PRELUDE_OPERATOR, this.lexer.token_start, this.lexer.token_end);
|
|
95
100
|
components.push(op);
|
|
96
101
|
} else {
|
|
97
|
-
let media_type = this.
|
|
98
|
-
this.arena.set_type(media_type, NODE_PRELUDE_MEDIA_TYPE);
|
|
99
|
-
this.arena.set_start_offset(media_type, this.lexer.token_start);
|
|
100
|
-
this.arena.set_length(media_type, this.lexer.token_end - this.lexer.token_start);
|
|
101
|
-
this.arena.set_start_line(media_type, this.lexer.token_line);
|
|
102
|
-
this.arena.set_start_column(media_type, this.lexer.token_column);
|
|
102
|
+
let media_type = this.create_node(NODE_PRELUDE_MEDIA_TYPE, this.lexer.token_start, this.lexer.token_end);
|
|
103
103
|
components.push(media_type);
|
|
104
104
|
}
|
|
105
105
|
} else {
|
|
@@ -107,11 +107,7 @@ class AtRulePreludeParser {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
if (components.length === 0) return null;
|
|
110
|
-
let query_node = this.
|
|
111
|
-
this.arena.set_type(query_node, NODE_PRELUDE_MEDIA_QUERY);
|
|
112
|
-
this.arena.set_start_offset(query_node, query_start);
|
|
113
|
-
this.arena.set_length(query_node, this.lexer.pos - query_start);
|
|
114
|
-
this.arena.set_start_line(query_node, query_line);
|
|
110
|
+
let query_node = this.create_node(NODE_PRELUDE_MEDIA_QUERY, query_start, this.lexer.pos);
|
|
115
111
|
for (let component of components) {
|
|
116
112
|
this.arena.append_child(query_node, component);
|
|
117
113
|
}
|
|
@@ -120,7 +116,7 @@ class AtRulePreludeParser {
|
|
|
120
116
|
// Parse media feature: (min-width: 768px)
|
|
121
117
|
parse_media_feature() {
|
|
122
118
|
let feature_start = this.lexer.token_start;
|
|
123
|
-
|
|
119
|
+
this.lexer.token_line;
|
|
124
120
|
let depth = 1;
|
|
125
121
|
let content_start = this.lexer.pos;
|
|
126
122
|
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
@@ -135,11 +131,7 @@ class AtRulePreludeParser {
|
|
|
135
131
|
if (depth !== 0) return null;
|
|
136
132
|
let content_end = this.lexer.token_start;
|
|
137
133
|
let feature_end = this.lexer.token_end;
|
|
138
|
-
let feature = this.
|
|
139
|
-
this.arena.set_type(feature, NODE_PRELUDE_MEDIA_FEATURE);
|
|
140
|
-
this.arena.set_start_offset(feature, feature_start);
|
|
141
|
-
this.arena.set_length(feature, feature_end - feature_start);
|
|
142
|
-
this.arena.set_start_line(feature, feature_line);
|
|
134
|
+
let feature = this.create_node(NODE_PRELUDE_MEDIA_FEATURE, feature_start, feature_end);
|
|
143
135
|
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
144
136
|
if (trimmed) {
|
|
145
137
|
this.arena.set_value_start(feature, trimmed[0]);
|
|
@@ -151,7 +143,7 @@ class AtRulePreludeParser {
|
|
|
151
143
|
parse_container_query() {
|
|
152
144
|
let nodes = [];
|
|
153
145
|
let query_start = this.lexer.pos;
|
|
154
|
-
|
|
146
|
+
this.lexer.line;
|
|
155
147
|
let components = [];
|
|
156
148
|
while (this.lexer.pos < this.prelude_end) {
|
|
157
149
|
this.skip_whitespace();
|
|
@@ -166,28 +158,16 @@ class AtRulePreludeParser {
|
|
|
166
158
|
} else if (token_type === TOKEN_IDENT) {
|
|
167
159
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
168
160
|
if (this.is_and_or_not(text)) {
|
|
169
|
-
let op = this.
|
|
170
|
-
this.arena.set_type(op, NODE_PRELUDE_OPERATOR);
|
|
171
|
-
this.arena.set_start_offset(op, this.lexer.token_start);
|
|
172
|
-
this.arena.set_length(op, this.lexer.token_end - this.lexer.token_start);
|
|
173
|
-
this.arena.set_start_line(op, this.lexer.token_line);
|
|
161
|
+
let op = this.create_node(NODE_PRELUDE_OPERATOR, this.lexer.token_start, this.lexer.token_end);
|
|
174
162
|
components.push(op);
|
|
175
163
|
} else {
|
|
176
|
-
let name = this.
|
|
177
|
-
this.arena.set_type(name, NODE_PRELUDE_IDENTIFIER);
|
|
178
|
-
this.arena.set_start_offset(name, this.lexer.token_start);
|
|
179
|
-
this.arena.set_length(name, this.lexer.token_end - this.lexer.token_start);
|
|
180
|
-
this.arena.set_start_line(name, this.lexer.token_line);
|
|
164
|
+
let name = this.create_node(NODE_PRELUDE_IDENTIFIER, this.lexer.token_start, this.lexer.token_end);
|
|
181
165
|
components.push(name);
|
|
182
166
|
}
|
|
183
167
|
}
|
|
184
168
|
}
|
|
185
169
|
if (components.length === 0) return [];
|
|
186
|
-
let query_node = this.
|
|
187
|
-
this.arena.set_type(query_node, NODE_PRELUDE_CONTAINER_QUERY);
|
|
188
|
-
this.arena.set_start_offset(query_node, query_start);
|
|
189
|
-
this.arena.set_length(query_node, this.lexer.pos - query_start);
|
|
190
|
-
this.arena.set_start_line(query_node, query_line);
|
|
170
|
+
let query_node = this.create_node(NODE_PRELUDE_CONTAINER_QUERY, query_start, this.lexer.pos);
|
|
191
171
|
for (let component of components) {
|
|
192
172
|
this.arena.append_child(query_node, component);
|
|
193
173
|
}
|
|
@@ -204,7 +184,7 @@ class AtRulePreludeParser {
|
|
|
204
184
|
let token_type = this.lexer.token_type;
|
|
205
185
|
if (token_type === TOKEN_LEFT_PAREN) {
|
|
206
186
|
let feature_start = this.lexer.token_start;
|
|
207
|
-
|
|
187
|
+
this.lexer.token_line;
|
|
208
188
|
let depth = 1;
|
|
209
189
|
let content_start = this.lexer.pos;
|
|
210
190
|
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
@@ -219,11 +199,7 @@ class AtRulePreludeParser {
|
|
|
219
199
|
if (depth === 0) {
|
|
220
200
|
let content_end = this.lexer.token_start;
|
|
221
201
|
let feature_end = this.lexer.token_end;
|
|
222
|
-
let query = this.
|
|
223
|
-
this.arena.set_type(query, NODE_PRELUDE_SUPPORTS_QUERY);
|
|
224
|
-
this.arena.set_start_offset(query, feature_start);
|
|
225
|
-
this.arena.set_length(query, feature_end - feature_start);
|
|
226
|
-
this.arena.set_start_line(query, feature_line);
|
|
202
|
+
let query = this.create_node(NODE_PRELUDE_SUPPORTS_QUERY, feature_start, feature_end);
|
|
227
203
|
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
228
204
|
if (trimmed) {
|
|
229
205
|
this.arena.set_value_start(query, trimmed[0]);
|
|
@@ -234,11 +210,7 @@ class AtRulePreludeParser {
|
|
|
234
210
|
} else if (token_type === TOKEN_IDENT) {
|
|
235
211
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
236
212
|
if (this.is_and_or_not(text)) {
|
|
237
|
-
let op = this.
|
|
238
|
-
this.arena.set_type(op, NODE_PRELUDE_OPERATOR);
|
|
239
|
-
this.arena.set_start_offset(op, this.lexer.token_start);
|
|
240
|
-
this.arena.set_length(op, this.lexer.token_end - this.lexer.token_start);
|
|
241
|
-
this.arena.set_start_line(op, this.lexer.token_line);
|
|
213
|
+
let op = this.create_node(NODE_PRELUDE_OPERATOR, this.lexer.token_start, this.lexer.token_end);
|
|
242
214
|
nodes.push(op);
|
|
243
215
|
}
|
|
244
216
|
}
|
|
@@ -254,11 +226,7 @@ class AtRulePreludeParser {
|
|
|
254
226
|
this.next_token();
|
|
255
227
|
let token_type = this.lexer.token_type;
|
|
256
228
|
if (token_type === TOKEN_IDENT) {
|
|
257
|
-
let layer = this.
|
|
258
|
-
this.arena.set_type(layer, NODE_PRELUDE_LAYER_NAME);
|
|
259
|
-
this.arena.set_start_offset(layer, this.lexer.token_start);
|
|
260
|
-
this.arena.set_length(layer, this.lexer.token_end - this.lexer.token_start);
|
|
261
|
-
this.arena.set_start_line(layer, this.lexer.token_line);
|
|
229
|
+
let layer = this.create_node(NODE_PRELUDE_LAYER_NAME, this.lexer.token_start, this.lexer.token_end);
|
|
262
230
|
nodes.push(layer);
|
|
263
231
|
} else if (token_type === TOKEN_COMMA) {
|
|
264
232
|
continue;
|
|
@@ -274,11 +242,7 @@ class AtRulePreludeParser {
|
|
|
274
242
|
if (this.lexer.pos >= this.prelude_end) return [];
|
|
275
243
|
this.next_token();
|
|
276
244
|
if (this.lexer.token_type !== TOKEN_IDENT) return [];
|
|
277
|
-
let ident = this.
|
|
278
|
-
this.arena.set_type(ident, NODE_PRELUDE_IDENTIFIER);
|
|
279
|
-
this.arena.set_start_offset(ident, this.lexer.token_start);
|
|
280
|
-
this.arena.set_length(ident, this.lexer.token_end - this.lexer.token_start);
|
|
281
|
-
this.arena.set_start_line(ident, this.lexer.token_line);
|
|
245
|
+
let ident = this.create_node(NODE_PRELUDE_IDENTIFIER, this.lexer.token_start, this.lexer.token_end);
|
|
282
246
|
return [ident];
|
|
283
247
|
}
|
|
284
248
|
// Parse @import prelude: url() [layer] [supports()] [media-query-list]
|
|
@@ -319,7 +283,7 @@ class AtRulePreludeParser {
|
|
|
319
283
|
}
|
|
320
284
|
let url_start = this.lexer.token_start;
|
|
321
285
|
let url_end = this.lexer.token_end;
|
|
322
|
-
|
|
286
|
+
this.lexer.token_line;
|
|
323
287
|
if (this.lexer.token_type === TOKEN_FUNCTION) {
|
|
324
288
|
let paren_depth = 1;
|
|
325
289
|
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
@@ -336,11 +300,7 @@ class AtRulePreludeParser {
|
|
|
336
300
|
}
|
|
337
301
|
}
|
|
338
302
|
}
|
|
339
|
-
let url_node = this.
|
|
340
|
-
this.arena.set_type(url_node, NODE_PRELUDE_IMPORT_URL);
|
|
341
|
-
this.arena.set_start_offset(url_node, url_start);
|
|
342
|
-
this.arena.set_length(url_node, url_end - url_start);
|
|
343
|
-
this.arena.set_start_line(url_node, url_line);
|
|
303
|
+
let url_node = this.create_node(NODE_PRELUDE_IMPORT_URL, url_start, url_end);
|
|
344
304
|
return url_node;
|
|
345
305
|
}
|
|
346
306
|
// Parse import layer: layer or layer(name)
|
|
@@ -355,7 +315,7 @@ class AtRulePreludeParser {
|
|
|
355
315
|
if (str_equals("layer", text)) {
|
|
356
316
|
let layer_start = this.lexer.token_start;
|
|
357
317
|
let layer_end = this.lexer.token_end;
|
|
358
|
-
|
|
318
|
+
this.lexer.token_line;
|
|
359
319
|
let content_start = 0;
|
|
360
320
|
let content_length = 0;
|
|
361
321
|
if (this.lexer.token_type === TOKEN_FUNCTION) {
|
|
@@ -376,11 +336,7 @@ class AtRulePreludeParser {
|
|
|
376
336
|
}
|
|
377
337
|
}
|
|
378
338
|
}
|
|
379
|
-
let layer_node = this.
|
|
380
|
-
this.arena.set_type(layer_node, NODE_PRELUDE_IMPORT_LAYER);
|
|
381
|
-
this.arena.set_start_offset(layer_node, layer_start);
|
|
382
|
-
this.arena.set_length(layer_node, layer_end - layer_start);
|
|
383
|
-
this.arena.set_start_line(layer_node, layer_line);
|
|
339
|
+
let layer_node = this.create_node(NODE_PRELUDE_IMPORT_LAYER, layer_start, layer_end);
|
|
384
340
|
if (content_length > 0) {
|
|
385
341
|
let trimmed = trim_boundaries(this.source, content_start, content_start + content_length);
|
|
386
342
|
if (trimmed) {
|
|
@@ -402,7 +358,7 @@ class AtRulePreludeParser {
|
|
|
402
358
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1);
|
|
403
359
|
if (str_equals("supports", text)) {
|
|
404
360
|
let supports_start = this.lexer.token_start;
|
|
405
|
-
|
|
361
|
+
this.lexer.token_line;
|
|
406
362
|
let paren_depth = 1;
|
|
407
363
|
let supports_end = this.lexer.token_end;
|
|
408
364
|
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
@@ -418,11 +374,7 @@ class AtRulePreludeParser {
|
|
|
418
374
|
break;
|
|
419
375
|
}
|
|
420
376
|
}
|
|
421
|
-
let supports_node = this.
|
|
422
|
-
this.arena.set_type(supports_node, NODE_PRELUDE_IMPORT_SUPPORTS);
|
|
423
|
-
this.arena.set_start_offset(supports_node, supports_start);
|
|
424
|
-
this.arena.set_length(supports_node, supports_end - supports_start);
|
|
425
|
-
this.arena.set_start_line(supports_node, supports_line);
|
|
377
|
+
let supports_node = this.create_node(NODE_PRELUDE_IMPORT_SUPPORTS, supports_start, supports_end);
|
|
426
378
|
return supports_node;
|
|
427
379
|
}
|
|
428
380
|
}
|
package/dist/parse-selector.d.ts
CHANGED
|
@@ -22,11 +22,7 @@ export declare class SelectorParser {
|
|
|
22
22
|
private parse_lang_identifiers;
|
|
23
23
|
private parse_nth_expression;
|
|
24
24
|
private find_of_keyword;
|
|
25
|
-
private
|
|
26
|
-
private create_id_selector;
|
|
27
|
-
private create_universal_selector;
|
|
28
|
-
private create_nesting_selector;
|
|
29
|
-
private create_combinator;
|
|
25
|
+
private create_node;
|
|
30
26
|
private skip_whitespace;
|
|
31
27
|
}
|
|
32
28
|
/**
|
package/dist/parse-selector.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as Lexer, q as TOKEN_COMMA, h as TOKEN_DELIM, y as TOKEN_EOF, l as TOKEN_WHITESPACE, a as TOKEN_FUNCTION, o as TOKEN_COLON, r as TOKEN_LEFT_BRACKET, c as TOKEN_HASH, T as TOKEN_IDENT, s as TOKEN_RIGHT_BRACKET, t as TOKEN_LEFT_PAREN, u as TOKEN_RIGHT_PAREN, d as TOKEN_STRING } from './lexer-CtBKgfVv.js';
|
|
2
|
-
import { Y as CSSDataArena, w as NODE_SELECTOR_LIST, C as CSSNode, m as NODE_SELECTOR, a3 as CHAR_GREATER_THAN, a4 as CHAR_PLUS, a5 as CHAR_TILDE, a6 as CHAR_PERIOD, a7 as CHAR_ASTERISK, a8 as CHAR_AMPERSAND, a9 as is_whitespace, aa as is_combinator, y as NODE_SELECTOR_CLASS, B as NODE_SELECTOR_ATTRIBUTE, ab as skip_whitespace_and_comments_forward, ac as skip_whitespace_and_comments_backward, ad as CHAR_EQUALS, ae as CHAR_PIPE, af as CHAR_CARET, ag as CHAR_DOLLAR, A as ATTR_OPERATOR_NONE, g as ATTR_FLAG_NONE, a as ATTR_OPERATOR_EQUAL, b as ATTR_OPERATOR_TILDE_EQUAL, c as ATTR_OPERATOR_PIPE_EQUAL, d as ATTR_OPERATOR_CARET_EQUAL, e as ATTR_OPERATOR_DOLLAR_EQUAL, f as ATTR_OPERATOR_STAR_EQUAL, ah as CHAR_SINGLE_QUOTE, ai as CHAR_DOUBLE_QUOTE, h as ATTR_FLAG_CASE_INSENSITIVE, i as ATTR_FLAG_CASE_SENSITIVE, aj as CHAR_COLON, E as NODE_SELECTOR_PSEUDO_ELEMENT, D as NODE_SELECTOR_PSEUDO_CLASS, a0 as is_vendor_prefixed, a1 as FLAG_VENDOR_PREFIXED, ak as FLAG_HAS_PARENS, K as NODE_SELECTOR_LANG, al as skip_whitespace_forward, J as NODE_SELECTOR_NTH_OF
|
|
2
|
+
import { Y as CSSDataArena, w as NODE_SELECTOR_LIST, C as CSSNode, m as NODE_SELECTOR, a3 as CHAR_GREATER_THAN, a4 as CHAR_PLUS, a5 as CHAR_TILDE, F as NODE_SELECTOR_COMBINATOR, a6 as CHAR_PERIOD, a7 as CHAR_ASTERISK, G as NODE_SELECTOR_UNIVERSAL, a8 as CHAR_AMPERSAND, H as NODE_SELECTOR_NESTING, z as NODE_SELECTOR_ID, x as NODE_SELECTOR_TYPE, a9 as is_whitespace, aa as is_combinator, y as NODE_SELECTOR_CLASS, B as NODE_SELECTOR_ATTRIBUTE, ab as skip_whitespace_and_comments_forward, ac as skip_whitespace_and_comments_backward, ad as CHAR_EQUALS, ae as CHAR_PIPE, af as CHAR_CARET, ag as CHAR_DOLLAR, A as ATTR_OPERATOR_NONE, g as ATTR_FLAG_NONE, a as ATTR_OPERATOR_EQUAL, b as ATTR_OPERATOR_TILDE_EQUAL, c as ATTR_OPERATOR_PIPE_EQUAL, d as ATTR_OPERATOR_CARET_EQUAL, e as ATTR_OPERATOR_DOLLAR_EQUAL, f as ATTR_OPERATOR_STAR_EQUAL, ah as CHAR_SINGLE_QUOTE, ai as CHAR_DOUBLE_QUOTE, h as ATTR_FLAG_CASE_INSENSITIVE, i as ATTR_FLAG_CASE_SENSITIVE, aj as CHAR_COLON, E as NODE_SELECTOR_PSEUDO_ELEMENT, D as NODE_SELECTOR_PSEUDO_CLASS, a0 as is_vendor_prefixed, a1 as FLAG_VENDOR_PREFIXED, ak as FLAG_HAS_PARENS, K as NODE_SELECTOR_LANG, al as skip_whitespace_forward, J as NODE_SELECTOR_NTH_OF } from './css-node-aIMm9_Cb.js';
|
|
3
3
|
import { ANplusBParser } from './parse-anplusb.js';
|
|
4
4
|
|
|
5
5
|
class SelectorParser {
|
|
@@ -30,16 +30,9 @@ class SelectorParser {
|
|
|
30
30
|
let list_column = this.lexer.column;
|
|
31
31
|
while (this.lexer.pos < this.selector_end) {
|
|
32
32
|
let selector_start = this.lexer.pos;
|
|
33
|
-
let selector_line = this.lexer.line;
|
|
34
|
-
let selector_column = this.lexer.column;
|
|
35
33
|
let complex_selector = this.parse_complex_selector(allow_relative);
|
|
36
34
|
if (complex_selector !== null) {
|
|
37
|
-
let selector_wrapper = this.
|
|
38
|
-
this.arena.set_type(selector_wrapper, NODE_SELECTOR);
|
|
39
|
-
this.arena.set_start_offset(selector_wrapper, selector_start);
|
|
40
|
-
this.arena.set_length(selector_wrapper, this.lexer.pos - selector_start);
|
|
41
|
-
this.arena.set_start_line(selector_wrapper, selector_line);
|
|
42
|
-
this.arena.set_start_column(selector_wrapper, selector_column);
|
|
35
|
+
let selector_wrapper = this.create_node(NODE_SELECTOR, selector_start, this.lexer.pos);
|
|
43
36
|
let last_component = complex_selector;
|
|
44
37
|
while (this.arena.get_next_sibling(last_component) !== 0) {
|
|
45
38
|
last_component = this.arena.get_next_sibling(last_component);
|
|
@@ -88,7 +81,7 @@ class SelectorParser {
|
|
|
88
81
|
if (token_type === TOKEN_DELIM) {
|
|
89
82
|
let ch = this.source.charCodeAt(this.lexer.token_start);
|
|
90
83
|
if (ch === CHAR_GREATER_THAN || ch === CHAR_PLUS || ch === CHAR_TILDE) {
|
|
91
|
-
let combinator = this.
|
|
84
|
+
let combinator = this.create_node(NODE_SELECTOR_COMBINATOR, this.lexer.token_start, this.lexer.token_end);
|
|
92
85
|
components.push(combinator);
|
|
93
86
|
this.skip_whitespace();
|
|
94
87
|
} else {
|
|
@@ -165,17 +158,17 @@ class SelectorParser {
|
|
|
165
158
|
let end = this.lexer.token_end;
|
|
166
159
|
switch (token_type) {
|
|
167
160
|
case TOKEN_IDENT:
|
|
168
|
-
return this.
|
|
161
|
+
return this.create_node(NODE_SELECTOR_TYPE, start, end);
|
|
169
162
|
case TOKEN_HASH:
|
|
170
|
-
return this.
|
|
163
|
+
return this.create_node(NODE_SELECTOR_ID, start, end);
|
|
171
164
|
case TOKEN_DELIM:
|
|
172
165
|
let ch = this.source.charCodeAt(start);
|
|
173
166
|
if (ch === CHAR_PERIOD) {
|
|
174
167
|
return this.parse_class_selector(start);
|
|
175
168
|
} else if (ch === CHAR_ASTERISK) {
|
|
176
|
-
return this.
|
|
169
|
+
return this.create_node(NODE_SELECTOR_UNIVERSAL, start, end);
|
|
177
170
|
} else if (ch === CHAR_AMPERSAND) {
|
|
178
|
-
return this.
|
|
171
|
+
return this.create_node(NODE_SELECTOR_NESTING, start, end);
|
|
179
172
|
}
|
|
180
173
|
return null;
|
|
181
174
|
case TOKEN_LEFT_BRACKET:
|
|
@@ -209,7 +202,7 @@ class SelectorParser {
|
|
|
209
202
|
if (this.lexer.token_type === TOKEN_DELIM) {
|
|
210
203
|
let ch = this.source.charCodeAt(this.lexer.token_start);
|
|
211
204
|
if (is_combinator(ch)) {
|
|
212
|
-
return this.
|
|
205
|
+
return this.create_node(NODE_SELECTOR_COMBINATOR, this.lexer.token_start, this.lexer.token_end);
|
|
213
206
|
}
|
|
214
207
|
}
|
|
215
208
|
if (has_whitespace) {
|
|
@@ -222,7 +215,7 @@ class SelectorParser {
|
|
|
222
215
|
break;
|
|
223
216
|
}
|
|
224
217
|
}
|
|
225
|
-
return this.
|
|
218
|
+
return this.create_node(NODE_SELECTOR_COMBINATOR, whitespace_start, this.lexer.pos);
|
|
226
219
|
}
|
|
227
220
|
this.lexer.pos = whitespace_start;
|
|
228
221
|
return null;
|
|
@@ -235,15 +228,7 @@ class SelectorParser {
|
|
|
235
228
|
this.lexer.restore_position(saved);
|
|
236
229
|
return null;
|
|
237
230
|
}
|
|
238
|
-
|
|
239
|
-
this.arena.set_type(node, NODE_SELECTOR_CLASS);
|
|
240
|
-
this.arena.set_start_offset(node, dot_pos);
|
|
241
|
-
this.arena.set_length(node, this.lexer.token_end - dot_pos);
|
|
242
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
243
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
244
|
-
this.arena.set_content_start(node, this.lexer.token_start);
|
|
245
|
-
this.arena.set_content_length(node, this.lexer.token_end - this.lexer.token_start);
|
|
246
|
-
return node;
|
|
231
|
+
return this.create_node(NODE_SELECTOR_CLASS, dot_pos, this.lexer.token_end);
|
|
247
232
|
}
|
|
248
233
|
// Parse attribute selector ([attr], [attr=value], etc.)
|
|
249
234
|
parse_attribute_selector(start) {
|
|
@@ -265,12 +250,7 @@ class SelectorParser {
|
|
|
265
250
|
}
|
|
266
251
|
}
|
|
267
252
|
}
|
|
268
|
-
let node = this.
|
|
269
|
-
this.arena.set_type(node, NODE_SELECTOR_ATTRIBUTE);
|
|
270
|
-
this.arena.set_start_offset(node, start);
|
|
271
|
-
this.arena.set_length(node, end - start);
|
|
272
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
273
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
253
|
+
let node = this.create_node(NODE_SELECTOR_ATTRIBUTE, start, end);
|
|
274
254
|
this.parse_attribute_content(node, content_start, content_end);
|
|
275
255
|
return node;
|
|
276
256
|
}
|
|
@@ -388,12 +368,11 @@ class SelectorParser {
|
|
|
388
368
|
this.lexer.next_token_fast(false);
|
|
389
369
|
let token_type = this.lexer.token_type;
|
|
390
370
|
if (token_type === TOKEN_IDENT) {
|
|
391
|
-
let node = this.
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
371
|
+
let node = this.create_node(
|
|
372
|
+
is_pseudo_element ? NODE_SELECTOR_PSEUDO_ELEMENT : NODE_SELECTOR_PSEUDO_CLASS,
|
|
373
|
+
start,
|
|
374
|
+
this.lexer.token_end
|
|
375
|
+
);
|
|
397
376
|
this.arena.set_content_start(node, this.lexer.token_start);
|
|
398
377
|
this.arena.set_content_length(node, this.lexer.token_end - this.lexer.token_start);
|
|
399
378
|
if (is_vendor_prefixed(this.source, this.lexer.token_start, this.lexer.token_end)) {
|
|
@@ -432,12 +411,7 @@ class SelectorParser {
|
|
|
432
411
|
}
|
|
433
412
|
}
|
|
434
413
|
}
|
|
435
|
-
let node = this.
|
|
436
|
-
this.arena.set_type(node, is_pseudo_element ? NODE_SELECTOR_PSEUDO_ELEMENT : NODE_SELECTOR_PSEUDO_CLASS);
|
|
437
|
-
this.arena.set_start_offset(node, start);
|
|
438
|
-
this.arena.set_length(node, end - start);
|
|
439
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
440
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
414
|
+
let node = this.create_node(is_pseudo_element ? NODE_SELECTOR_PSEUDO_ELEMENT : NODE_SELECTOR_PSEUDO_CLASS, start, end);
|
|
441
415
|
this.arena.set_content_start(node, func_name_start);
|
|
442
416
|
this.arena.set_content_length(node, func_name_end - func_name_start);
|
|
443
417
|
this.arena.set_flag(node, FLAG_HAS_PARENS);
|
|
@@ -494,12 +468,7 @@ class SelectorParser {
|
|
|
494
468
|
continue;
|
|
495
469
|
}
|
|
496
470
|
if (token_type === TOKEN_STRING || token_type === TOKEN_IDENT) {
|
|
497
|
-
let lang_node = this.
|
|
498
|
-
this.arena.set_type(lang_node, NODE_SELECTOR_LANG);
|
|
499
|
-
this.arena.set_start_offset(lang_node, token_start);
|
|
500
|
-
this.arena.set_length(lang_node, token_end - token_start);
|
|
501
|
-
this.arena.set_start_line(lang_node, this.lexer.line);
|
|
502
|
-
this.arena.set_start_column(lang_node, this.lexer.column);
|
|
471
|
+
let lang_node = this.create_node(NODE_SELECTOR_LANG, token_start, token_end);
|
|
503
472
|
if (first_child === null) {
|
|
504
473
|
first_child = lang_node;
|
|
505
474
|
}
|
|
@@ -569,54 +538,9 @@ class SelectorParser {
|
|
|
569
538
|
}
|
|
570
539
|
return -1;
|
|
571
540
|
}
|
|
572
|
-
|
|
573
|
-
create_type_selector(start, end) {
|
|
574
|
-
let node = this.arena.create_node();
|
|
575
|
-
this.arena.set_type(node, NODE_SELECTOR_TYPE);
|
|
576
|
-
this.arena.set_start_offset(node, start);
|
|
577
|
-
this.arena.set_length(node, end - start);
|
|
578
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
579
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
580
|
-
this.arena.set_content_start(node, start);
|
|
581
|
-
this.arena.set_content_length(node, end - start);
|
|
582
|
-
return node;
|
|
583
|
-
}
|
|
584
|
-
create_id_selector(start, end) {
|
|
585
|
-
let node = this.arena.create_node();
|
|
586
|
-
this.arena.set_type(node, NODE_SELECTOR_ID);
|
|
587
|
-
this.arena.set_start_offset(node, start);
|
|
588
|
-
this.arena.set_length(node, end - start);
|
|
589
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
590
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
591
|
-
this.arena.set_content_start(node, start + 1);
|
|
592
|
-
this.arena.set_content_length(node, end - start - 1);
|
|
593
|
-
return node;
|
|
594
|
-
}
|
|
595
|
-
create_universal_selector(start, end) {
|
|
596
|
-
let node = this.arena.create_node();
|
|
597
|
-
this.arena.set_type(node, NODE_SELECTOR_UNIVERSAL);
|
|
598
|
-
this.arena.set_start_offset(node, start);
|
|
599
|
-
this.arena.set_length(node, end - start);
|
|
600
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
601
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
602
|
-
this.arena.set_content_start(node, start);
|
|
603
|
-
this.arena.set_content_length(node, end - start);
|
|
604
|
-
return node;
|
|
605
|
-
}
|
|
606
|
-
create_nesting_selector(start, end) {
|
|
607
|
-
let node = this.arena.create_node();
|
|
608
|
-
this.arena.set_type(node, NODE_SELECTOR_NESTING);
|
|
609
|
-
this.arena.set_start_offset(node, start);
|
|
610
|
-
this.arena.set_length(node, end - start);
|
|
611
|
-
this.arena.set_start_line(node, this.lexer.line);
|
|
612
|
-
this.arena.set_start_column(node, this.lexer.column);
|
|
613
|
-
this.arena.set_content_start(node, start);
|
|
614
|
-
this.arena.set_content_length(node, end - start);
|
|
615
|
-
return node;
|
|
616
|
-
}
|
|
617
|
-
create_combinator(start, end) {
|
|
541
|
+
create_node(type, start, end) {
|
|
618
542
|
let node = this.arena.create_node();
|
|
619
|
-
this.arena.set_type(node,
|
|
543
|
+
this.arena.set_type(node, type);
|
|
620
544
|
this.arena.set_start_offset(node, start);
|
|
621
545
|
this.arena.set_length(node, end - start);
|
|
622
546
|
this.arena.set_start_line(node, this.lexer.line);
|
package/package.json
CHANGED