@projectwallace/css-parser 0.18.0 → 0.18.2
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-B3EzCweR.js → css-node-Cf8K9nWd.js} +2 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{node-types-BRnQyc9B.d.ts → node-types-D41wr72y.d.ts} +8 -4
- package/dist/parse-anplusb.d.ts +1 -1
- package/dist/parse-anplusb.js +2 -2
- package/dist/parse-atrule-prelude.d.ts +4 -1
- package/dist/parse-atrule-prelude.js +82 -97
- package/dist/parse-declaration.d.ts +2 -2
- package/dist/parse-declaration.js +55 -21
- package/dist/parse-selector.d.ts +1 -2
- package/dist/parse-selector.js +14 -33
- package/dist/parse-value.d.ts +1 -1
- package/dist/parse-value.js +4 -3
- package/dist/parse.d.ts +3 -2
- package/dist/parse.js +33 -59
- package/dist/{tokenize-DeZYFa9R.d.ts → tokenize-CDEnYcVG.d.ts} +22 -0
- package/dist/{tokenize-BiRLfVbm.js → tokenize-DK24ACbY.js} +236 -103
- package/dist/tokenize.d.ts +1 -1
- package/dist/tokenize.js +1 -1
- package/dist/{value-node-parser-CZ47v3hp.js → value-node-parser-jRoWXgOr.js} +2 -5
- package/dist/walk.d.ts +1 -1
- package/dist/walk.js +4 -30
- package/package.json +3 -3
package/dist/parse-selector.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
3
|
import { a as is_whitespace, n as is_combinator, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
4
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
5
5
|
import { n as skip_whitespace_and_comments_forward, r as skip_whitespace_forward, t as skip_whitespace_and_comments_backward } from "./parse-utils-D7srNG13.js";
|
|
6
6
|
import { ANplusBParser } from "./parse-anplusb.js";
|
|
7
7
|
//#region src/parse-selector.ts
|
|
@@ -69,7 +69,7 @@ var SelectorParser = class {
|
|
|
69
69
|
if (this.lexer.token_type === 9) {
|
|
70
70
|
let ch = this.source.charCodeAt(this.lexer.token_start);
|
|
71
71
|
if (ch === 62 || ch === 43 || ch === 126) {
|
|
72
|
-
let combinator = this.
|
|
72
|
+
let combinator = this.create_node(27, this.lexer.token_start, this.lexer.token_end);
|
|
73
73
|
first_component = combinator;
|
|
74
74
|
chain_tail = combinator;
|
|
75
75
|
this.skip_whitespace();
|
|
@@ -205,12 +205,13 @@ var SelectorParser = class {
|
|
|
205
205
|
}
|
|
206
206
|
this.lexer.next_token_fast(false);
|
|
207
207
|
if (this.lexer.token_type === 9) {
|
|
208
|
-
|
|
208
|
+
let ch = this.source.charCodeAt(this.lexer.token_start);
|
|
209
|
+
if (is_combinator(ch)) return this.create_node(27, this.lexer.token_start, this.lexer.token_end);
|
|
209
210
|
}
|
|
210
211
|
if (has_whitespace) {
|
|
211
212
|
this.lexer.restore_position(saved_whitespace_start);
|
|
212
213
|
this.skip_whitespace();
|
|
213
|
-
return this.
|
|
214
|
+
return this.create_node(27, saved_whitespace_start.pos, this.lexer.pos, saved_whitespace_start.line, saved_whitespace_start.column);
|
|
214
215
|
}
|
|
215
216
|
this.lexer.restore_position(saved_whitespace_start);
|
|
216
217
|
return null;
|
|
@@ -293,7 +294,8 @@ var SelectorParser = class {
|
|
|
293
294
|
else pos++;
|
|
294
295
|
}
|
|
295
296
|
} else while (pos < end) {
|
|
296
|
-
|
|
297
|
+
let c = this.source.charCodeAt(pos);
|
|
298
|
+
if (is_whitespace(c)) break;
|
|
297
299
|
pos++;
|
|
298
300
|
}
|
|
299
301
|
value_end = pos;
|
|
@@ -433,44 +435,23 @@ var SelectorParser = class {
|
|
|
433
435
|
}
|
|
434
436
|
return -1;
|
|
435
437
|
}
|
|
436
|
-
create_node(type, start, end) {
|
|
437
|
-
let node = this.arena.create_node(type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
438
|
-
this.arena.set_content_start_delta(node, 0);
|
|
439
|
-
this.arena.set_content_length(node, end - start);
|
|
440
|
-
return node;
|
|
441
|
-
}
|
|
442
|
-
create_node_at(type, start, end, line, column) {
|
|
438
|
+
create_node(type, start, end, line = this.lexer.token_line, column = this.lexer.token_column) {
|
|
443
439
|
let node = this.arena.create_node(type, start, end - start, line, column);
|
|
444
440
|
this.arena.set_content_start_delta(node, 0);
|
|
445
441
|
this.arena.set_content_length(node, end - start);
|
|
446
442
|
return node;
|
|
447
443
|
}
|
|
448
444
|
skip_whitespace() {
|
|
449
|
-
|
|
450
|
-
let ch = this.source.charCodeAt(this.lexer.pos);
|
|
451
|
-
if (is_whitespace(ch)) {
|
|
452
|
-
this.lexer.advance();
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
if (ch === 47 && this.lexer.pos + 1 < this.selector_end && this.source.charCodeAt(this.lexer.pos + 1) === 42) {
|
|
456
|
-
this.lexer.advance(2);
|
|
457
|
-
while (this.lexer.pos < this.selector_end) {
|
|
458
|
-
if (this.source.charCodeAt(this.lexer.pos) === 42 && this.lexer.pos + 1 < this.selector_end && this.source.charCodeAt(this.lexer.pos + 1) === 47) {
|
|
459
|
-
this.lexer.advance(2);
|
|
460
|
-
break;
|
|
461
|
-
}
|
|
462
|
-
this.lexer.advance();
|
|
463
|
-
}
|
|
464
|
-
continue;
|
|
465
|
-
}
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
445
|
+
this.lexer.skip_whitespace_in_range(this.selector_end);
|
|
468
446
|
}
|
|
469
447
|
};
|
|
470
448
|
function parse_selector_list(source) {
|
|
471
449
|
const arena = new CSSDataArena(CSSDataArena.capacity_for_source(source.length));
|
|
472
450
|
const selector_index = new SelectorParser(arena, source).parse_selector(0, source.length);
|
|
473
|
-
if (selector_index === null)
|
|
451
|
+
if (selector_index === null) {
|
|
452
|
+
const empty = arena.create_node(20, 0, 0, 1, 1);
|
|
453
|
+
return new CSSNode(arena, source, empty);
|
|
454
|
+
}
|
|
474
455
|
return new CSSNode(arena, source, selector_index);
|
|
475
456
|
}
|
|
476
457
|
function parse_selector(source) {
|
package/dist/parse-value.d.ts
CHANGED
package/dist/parse-value.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
2
|
-
import { t as CSSNode } from "./css-node-
|
|
3
|
-
import { t as ValueNodeParser } from "./value-node-parser-
|
|
2
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
3
|
+
import { t as ValueNodeParser } from "./value-node-parser-jRoWXgOr.js";
|
|
4
4
|
//#region src/parse-value.ts
|
|
5
5
|
/** @internal */
|
|
6
6
|
var ValueParser = class {
|
|
@@ -28,7 +28,8 @@ var ValueParser = class {
|
|
|
28
28
|
*/
|
|
29
29
|
function parse_value(value_string) {
|
|
30
30
|
const arena = new CSSDataArena(CSSDataArena.capacity_for_source(value_string.length));
|
|
31
|
-
|
|
31
|
+
const value_node_index = new ValueParser(arena, value_string).parse_value(0, value_string.length, 1, 1);
|
|
32
|
+
return new CSSNode(arena, value_string, value_node_index);
|
|
32
33
|
}
|
|
33
34
|
//#endregion
|
|
34
35
|
export { ValueParser, parse_value };
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
|
-
import { t as CommentInfo } from "./tokenize-
|
|
3
|
-
import { z as StyleSheet } from "./node-types-
|
|
2
|
+
import { t as CommentInfo } from "./tokenize-CDEnYcVG.js";
|
|
3
|
+
import { z as StyleSheet } from "./node-types-D41wr72y.js";
|
|
4
4
|
//#region src/parse.d.ts
|
|
5
5
|
interface ParserOptions {
|
|
6
6
|
parse_values?: boolean;
|
|
@@ -27,6 +27,7 @@ declare class Parser {
|
|
|
27
27
|
private is_eof;
|
|
28
28
|
parse(): StyleSheet;
|
|
29
29
|
private parse_rule;
|
|
30
|
+
private parse_block_children;
|
|
30
31
|
private parse_style_rule;
|
|
31
32
|
private parse_selector;
|
|
32
33
|
private parse_declaration;
|
package/dist/parse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
|
-
import { t as CSSNode } from "./css-node-
|
|
4
|
-
import { i as trim_boundaries } from "./parse-utils-D7srNG13.js";
|
|
3
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
4
|
+
import { i as trim_boundaries, t as skip_whitespace_and_comments_backward } from "./parse-utils-D7srNG13.js";
|
|
5
5
|
import { SelectorParser } from "./parse-selector.js";
|
|
6
6
|
import { AtRulePreludeParser } from "./parse-atrule-prelude.js";
|
|
7
7
|
import { DeclarationParser } from "./parse-declaration.js";
|
|
@@ -79,35 +79,24 @@ var Parser = class {
|
|
|
79
79
|
if (this.peek_type() === 3) return this.parse_atrule();
|
|
80
80
|
return this.parse_style_rule();
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
if (this.is_eof()) return null;
|
|
84
|
-
let rule_start = this.lexer.token_start;
|
|
85
|
-
let rule_line = this.lexer.token_line;
|
|
86
|
-
let rule_column = this.lexer.token_column;
|
|
87
|
-
let style_rule = this.arena.create_node(2, rule_start, 0, rule_line, rule_column);
|
|
88
|
-
let selector = this.parse_selector();
|
|
89
|
-
if (this.peek_type() !== 23) return null;
|
|
90
|
-
let block_start = this.lexer.token_end;
|
|
91
|
-
this.next_token();
|
|
92
|
-
this.arena.set_flag(style_rule, 8);
|
|
93
|
-
let block_line = this.lexer.token_line;
|
|
94
|
-
let block_column = this.lexer.token_column;
|
|
95
|
-
let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
|
|
82
|
+
parse_block_children(owner, declarations_only) {
|
|
96
83
|
let first_child = 0;
|
|
97
84
|
let last_child = 0;
|
|
98
85
|
while (!this.is_eof()) {
|
|
99
86
|
let token_type = this.peek_type();
|
|
100
87
|
if (token_type === 24) break;
|
|
101
88
|
let child = null;
|
|
102
|
-
if (token_type === 3) {
|
|
89
|
+
if (!declarations_only && token_type === 3) {
|
|
103
90
|
child = this.parse_atrule();
|
|
104
91
|
if (child === null) this.next_token();
|
|
105
92
|
} else {
|
|
106
93
|
child = this.parse_declaration();
|
|
107
|
-
if (child
|
|
94
|
+
if (child !== null) this.arena.set_flag(owner, 32);
|
|
95
|
+
else if (declarations_only) this.next_token();
|
|
96
|
+
else {
|
|
108
97
|
child = this.parse_style_rule();
|
|
109
98
|
if (child === null) this.next_token();
|
|
110
|
-
}
|
|
99
|
+
}
|
|
111
100
|
}
|
|
112
101
|
if (child !== null) {
|
|
113
102
|
if (first_child === 0) first_child = child;
|
|
@@ -115,6 +104,23 @@ var Parser = class {
|
|
|
115
104
|
last_child = child;
|
|
116
105
|
}
|
|
117
106
|
}
|
|
107
|
+
return first_child;
|
|
108
|
+
}
|
|
109
|
+
parse_style_rule() {
|
|
110
|
+
if (this.is_eof()) return null;
|
|
111
|
+
let rule_start = this.lexer.token_start;
|
|
112
|
+
let rule_line = this.lexer.token_line;
|
|
113
|
+
let rule_column = this.lexer.token_column;
|
|
114
|
+
let style_rule = this.arena.create_node(2, rule_start, 0, rule_line, rule_column);
|
|
115
|
+
let selector = this.parse_selector();
|
|
116
|
+
if (this.peek_type() !== 23) return null;
|
|
117
|
+
let block_start = this.lexer.token_end;
|
|
118
|
+
this.next_token();
|
|
119
|
+
this.arena.set_flag(style_rule, 8);
|
|
120
|
+
let block_line = this.lexer.token_line;
|
|
121
|
+
let block_column = this.lexer.token_column;
|
|
122
|
+
let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
|
|
123
|
+
let first_child = this.parse_block_children(style_rule, false);
|
|
118
124
|
let block_end = this.lexer.token_start;
|
|
119
125
|
let rule_end = this.lexer.token_end;
|
|
120
126
|
if (this.peek_type() === 24) {
|
|
@@ -138,8 +144,9 @@ var Parser = class {
|
|
|
138
144
|
let selector_line = this.lexer.token_line;
|
|
139
145
|
let selector_column = this.lexer.token_column;
|
|
140
146
|
let last_end = this.lexer.token_end;
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
if (this.peek_type() !== 23) {
|
|
148
|
+
this.lexer.skip_to_unquoted(123);
|
|
149
|
+
last_end = skip_whitespace_and_comments_backward(this.source, this.lexer.pos, selector_start);
|
|
143
150
|
this.next_token();
|
|
144
151
|
}
|
|
145
152
|
if (this.parse_selectors_enabled && this.selector_parser) {
|
|
@@ -151,13 +158,11 @@ var Parser = class {
|
|
|
151
158
|
}
|
|
152
159
|
parse_declaration() {
|
|
153
160
|
const token_type = this.peek_type();
|
|
154
|
-
if (token_type === 1 || token_type === 3 || token_type === 4) return this.declaration_parser.parse_declaration_with_lexer(this.lexer, this.source.length);
|
|
155
161
|
if (token_type === 9 || token_type === 21 || token_type === 22 || token_type === 19 || token_type === 20 || token_type === 18 || token_type === 16) {
|
|
156
162
|
const char_code = this.source.charCodeAt(this.lexer.token_start);
|
|
157
163
|
if (char_code === 46 || char_code === 62 || char_code === 43 || char_code === 126 || char_code === 38) return null;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return null;
|
|
164
|
+
} else if (token_type !== 1 && token_type !== 3 && token_type !== 4) return null;
|
|
165
|
+
return this.declaration_parser.parse_declaration_with_lexer(this.lexer, this.source.length);
|
|
161
166
|
}
|
|
162
167
|
parse_atrule() {
|
|
163
168
|
if (this.peek_type() !== 3) return null;
|
|
@@ -200,39 +205,8 @@ var Parser = class {
|
|
|
200
205
|
let block_line = this.lexer.token_line;
|
|
201
206
|
let block_column = this.lexer.token_column;
|
|
202
207
|
let block_node = this.arena.create_node(7, block_start, 0, block_line, block_column);
|
|
203
|
-
let
|
|
204
|
-
let first_child =
|
|
205
|
-
let last_child = 0;
|
|
206
|
-
if (has_declarations) while (!this.is_eof()) {
|
|
207
|
-
if (this.peek_type() === 24) break;
|
|
208
|
-
let declaration = this.parse_declaration();
|
|
209
|
-
if (declaration === null) this.next_token();
|
|
210
|
-
else {
|
|
211
|
-
if (first_child === 0) first_child = declaration;
|
|
212
|
-
else this.arena.set_next_sibling(last_child, declaration);
|
|
213
|
-
last_child = declaration;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else while (!this.is_eof()) {
|
|
217
|
-
let token_type = this.peek_type();
|
|
218
|
-
if (token_type === 24) break;
|
|
219
|
-
let child = null;
|
|
220
|
-
if (token_type === 3) {
|
|
221
|
-
child = this.parse_atrule();
|
|
222
|
-
if (child === null) this.next_token();
|
|
223
|
-
} else {
|
|
224
|
-
child = this.parse_declaration();
|
|
225
|
-
if (child === null) {
|
|
226
|
-
child = this.parse_style_rule();
|
|
227
|
-
if (child === null) this.next_token();
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (child !== null) {
|
|
231
|
-
if (first_child === 0) first_child = child;
|
|
232
|
-
else this.arena.set_next_sibling(last_child, child);
|
|
233
|
-
last_child = child;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
208
|
+
let declarations_only = this.atrule_has_declarations(at_rule_name);
|
|
209
|
+
let first_child = this.parse_block_children(at_rule, declarations_only);
|
|
236
210
|
if (this.peek_type() === 24) {
|
|
237
211
|
let block_end = this.lexer.token_start;
|
|
238
212
|
last_end = this.lexer.token_end;
|
|
@@ -72,6 +72,28 @@ declare class Lexer {
|
|
|
72
72
|
seek(pos: number, line: number, column?: number): void;
|
|
73
73
|
next_token_fast(skip_whitespace?: boolean): TokenType;
|
|
74
74
|
private _scan_newlines;
|
|
75
|
+
private _skip_comment;
|
|
76
|
+
/**
|
|
77
|
+
* Fast-forward to the next `target` char that isn't inside a string or comment, without
|
|
78
|
+
* fully tokenizing what's in between — used by callers that only need to know *where a
|
|
79
|
+
* construct ends* (e.g. a selector's `{`), since the sub-parser for that construct
|
|
80
|
+
* re-tokenizes the span properly afterward.
|
|
81
|
+
*
|
|
82
|
+
* Strings go through consume_string and comments through _skip_comment, so escapes and
|
|
83
|
+
* on_comment callbacks behave identically to real tokenization. Ordinary characters cost
|
|
84
|
+
* one SKIP_SCAN_INTERESTING lookup each, same as consume_ident_or_function's inner loop.
|
|
85
|
+
*
|
|
86
|
+
* Returns true with this.pos at target, or false with this.pos at source_length.
|
|
87
|
+
*/
|
|
88
|
+
skip_to_unquoted(target: number): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Same approach as skip_to_unquoted, but stops at any of `; { } ( ) !` — the stop
|
|
91
|
+
* characters parse-declaration.ts's value scan needs (paren depth, statement end,
|
|
92
|
+
* !important). The caller decides what each one means; this only locates the next one.
|
|
93
|
+
*
|
|
94
|
+
* Returns the stop character's code (this.pos left at it), or 0 at `end` if none found.
|
|
95
|
+
*/
|
|
96
|
+
skip_to_declaration_stop(end: number): number;
|
|
75
97
|
consume_whitespace(start_line: number, start_column: number): TokenType;
|
|
76
98
|
consume_string(quote: number, start_line: number, start_column: number): TokenType;
|
|
77
99
|
consume_hex_escape(): void;
|