@projectwallace/css-parser 0.18.1 → 0.18.4
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/{arena-CFwM4uQs.js → arena-C-ZXJe7F.js} +2 -1
- package/dist/{arena-Bx5vp6Sl.d.ts → arena-C-uRgG5-.d.ts} +2 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +4 -3
- package/dist/{css-node-Cf8K9nWd.js → css-node-Briho45Z.js} +21 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -4
- package/dist/{node-types-D41wr72y.d.ts → node-types-Dh1wEDRK.d.ts} +15 -6
- package/dist/parse-anplusb.d.ts +2 -2
- package/dist/parse-anplusb.js +3 -3
- package/dist/parse-atrule-prelude.d.ts +4 -2
- package/dist/parse-atrule-prelude.js +59 -84
- package/dist/parse-declaration.d.ts +3 -3
- package/dist/parse-declaration.js +56 -22
- package/dist/parse-selector.d.ts +2 -3
- package/dist/parse-selector.js +15 -34
- package/dist/parse-value.d.ts +2 -2
- package/dist/parse-value.js +5 -4
- package/dist/parse.d.ts +4 -3
- package/dist/parse.js +34 -60
- 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-B0WfJCvC.js} +3 -6
- package/dist/walk.d.ts +1 -1
- package/dist/walk.js +5 -31
- package/package.json +3 -3
|
@@ -22,9 +22,6 @@ function is_hex_digit(ch) {
|
|
|
22
22
|
function is_alpha(ch) {
|
|
23
23
|
return ch < 128 && (char_types[ch] & CHAR_ALPHA) !== 0;
|
|
24
24
|
}
|
|
25
|
-
function is_whitespace(ch) {
|
|
26
|
-
return ch < 128 && (char_types[ch] & 8) !== 0;
|
|
27
|
-
}
|
|
28
25
|
function is_ident_start(ch) {
|
|
29
26
|
if (ch >= 128) return true;
|
|
30
27
|
if (ch === 95) return true;
|
|
@@ -95,6 +92,20 @@ const CHAR_QUESTION_MARK = 63;
|
|
|
95
92
|
const CHAR_CARRIAGE_RETURN = 13;
|
|
96
93
|
const CHAR_LINE_FEED = 10;
|
|
97
94
|
const CHAR_FORM_FEED = 12;
|
|
95
|
+
const SKIP_SCAN_INTERESTING = /* @__PURE__ */ new Uint8Array(128);
|
|
96
|
+
SKIP_SCAN_INTERESTING[CHAR_DOUBLE_QUOTE] = 1;
|
|
97
|
+
SKIP_SCAN_INTERESTING[CHAR_SINGLE_QUOTE] = 1;
|
|
98
|
+
SKIP_SCAN_INTERESTING[CHAR_FORWARD_SLASH] = 1;
|
|
99
|
+
SKIP_SCAN_INTERESTING[CHAR_LINE_FEED] = 1;
|
|
100
|
+
SKIP_SCAN_INTERESTING[CHAR_CARRIAGE_RETURN] = 1;
|
|
101
|
+
SKIP_SCAN_INTERESTING[CHAR_FORM_FEED] = 1;
|
|
102
|
+
const DECL_VALUE_STOP = /* @__PURE__ */ new Uint8Array(128);
|
|
103
|
+
DECL_VALUE_STOP[CHAR_SEMICOLON] = 1;
|
|
104
|
+
DECL_VALUE_STOP[CHAR_LEFT_BRACE] = 1;
|
|
105
|
+
DECL_VALUE_STOP[CHAR_RIGHT_BRACE] = 1;
|
|
106
|
+
DECL_VALUE_STOP[CHAR_LEFT_PAREN] = 1;
|
|
107
|
+
DECL_VALUE_STOP[CHAR_RIGHT_PAREN] = 1;
|
|
108
|
+
DECL_VALUE_STOP[CHAR_EXCLAMATION] = 1;
|
|
98
109
|
/** @internal */
|
|
99
110
|
var Lexer = class {
|
|
100
111
|
source;
|
|
@@ -134,15 +145,23 @@ var Lexer = class {
|
|
|
134
145
|
const source = this.source;
|
|
135
146
|
const source_length = source.length;
|
|
136
147
|
while (true) {
|
|
137
|
-
if (skip_whitespace)
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
this.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
if (skip_whitespace) {
|
|
149
|
+
let pos = this.pos;
|
|
150
|
+
let line = this._line;
|
|
151
|
+
let line_offset = this._line_offset;
|
|
152
|
+
while (pos < source_length) {
|
|
153
|
+
let ch = source.charCodeAt(pos);
|
|
154
|
+
if (ch >= 128 || (char_types[ch] & 24) === 0) break;
|
|
155
|
+
pos++;
|
|
156
|
+
if ((char_types[ch] & 16) !== 0) {
|
|
157
|
+
if (ch === CHAR_CARRIAGE_RETURN && pos < source_length && source.charCodeAt(pos) === CHAR_LINE_FEED) pos++;
|
|
158
|
+
line++;
|
|
159
|
+
line_offset = pos;
|
|
160
|
+
}
|
|
145
161
|
}
|
|
162
|
+
this.pos = pos;
|
|
163
|
+
this._line = line;
|
|
164
|
+
this._line_offset = line_offset;
|
|
146
165
|
}
|
|
147
166
|
if (this.pos >= source_length) return this.make_token(26, this.pos, this.pos);
|
|
148
167
|
let ch = source.charCodeAt(this.pos);
|
|
@@ -180,57 +199,33 @@ var Lexer = class {
|
|
|
180
199
|
}
|
|
181
200
|
if (ch < 128 && (char_types[ch] & 24) !== 0) return this.consume_whitespace(start_line, start_column);
|
|
182
201
|
if (ch === CHAR_FORWARD_SLASH && this.pos + 1 < source_length && source.charCodeAt(this.pos + 1) === CHAR_ASTERISK) {
|
|
183
|
-
|
|
184
|
-
let comment_line = start_line;
|
|
185
|
-
let comment_column = start_column;
|
|
186
|
-
this.pos += 2;
|
|
187
|
-
let end_idx = source.indexOf("*/", this.pos);
|
|
188
|
-
if (end_idx < 0) {
|
|
189
|
-
this._scan_newlines(this.pos, source_length);
|
|
190
|
-
this.pos = source_length;
|
|
191
|
-
} else {
|
|
192
|
-
this._scan_newlines(this.pos, end_idx);
|
|
193
|
-
this.pos = end_idx + 2;
|
|
194
|
-
}
|
|
195
|
-
if (this.on_comment) this.on_comment({
|
|
196
|
-
start: comment_start,
|
|
197
|
-
end: this.pos,
|
|
198
|
-
length: this.pos - comment_start,
|
|
199
|
-
line: comment_line,
|
|
200
|
-
column: comment_column
|
|
201
|
-
});
|
|
202
|
+
this._skip_comment();
|
|
202
203
|
continue;
|
|
203
204
|
}
|
|
204
|
-
if (ch
|
|
205
|
-
if (ch
|
|
206
|
-
if (ch === CHAR_DOT) {
|
|
205
|
+
if (is_ident_start(ch)) return this.consume_ident_or_function(start_line, start_column);
|
|
206
|
+
if (ch === CHAR_HYPHEN) {
|
|
207
207
|
let next = this.pos + 1 < source_length ? source.charCodeAt(this.pos + 1) : 0;
|
|
208
|
-
if (next
|
|
209
|
-
}
|
|
210
|
-
if (ch === CHAR_LESS_THAN && this.pos + 3 < source_length) {
|
|
211
|
-
if (source.charCodeAt(this.pos + 1) === CHAR_EXCLAMATION && source.charCodeAt(this.pos + 2) === CHAR_HYPHEN && source.charCodeAt(this.pos + 3) === CHAR_HYPHEN) {
|
|
212
|
-
this.pos += 4;
|
|
213
|
-
return this.make_token(14, start, this.pos, start_line, start_column);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (ch === CHAR_HYPHEN && this.pos + 2 < source_length) {
|
|
217
|
-
if (source.charCodeAt(this.pos + 1) === CHAR_HYPHEN && source.charCodeAt(this.pos + 2) === CHAR_GREATER_THAN) {
|
|
208
|
+
if (next === CHAR_HYPHEN && this.pos + 2 < source_length && source.charCodeAt(this.pos + 2) === CHAR_GREATER_THAN) {
|
|
218
209
|
this.pos += 3;
|
|
219
210
|
return this.make_token(15, start, this.pos, start_line, start_column);
|
|
220
211
|
}
|
|
221
|
-
}
|
|
222
|
-
if (ch === CHAR_AT_SIGN) return this.consume_at_keyword(start_line, start_column);
|
|
223
|
-
if (ch === CHAR_HASH) return this.consume_hash(start_line, start_column);
|
|
224
|
-
if (is_ident_start(ch)) return this.consume_ident_or_function(start_line, start_column);
|
|
225
|
-
if (ch === CHAR_HYPHEN) {
|
|
226
|
-
let next = this.pos + 1 < source_length ? source.charCodeAt(this.pos + 1) : 0;
|
|
227
212
|
if (is_ident_start(next) || next === CHAR_HYPHEN) return this.consume_ident_or_function(start_line, start_column);
|
|
213
|
+
if (next < 128 && (char_types[next] & 2) !== 0) return this.consume_number(start_line, start_column);
|
|
214
|
+
if (next === CHAR_DOT) {
|
|
215
|
+
let next2 = this.pos + 2 < source_length ? source.charCodeAt(this.pos + 2) : 0;
|
|
216
|
+
if (next2 < 128 && (char_types[next2] & 2) !== 0) return this.consume_number(start_line, start_column);
|
|
217
|
+
}
|
|
228
218
|
}
|
|
229
219
|
if (ch === CHAR_BACKSLASH) {
|
|
230
220
|
let next = this.pos + 1 < source_length ? source.charCodeAt(this.pos + 1) : 0;
|
|
231
221
|
if (next !== 0 && !is_newline(next)) return this.consume_ident_or_function(start_line, start_column);
|
|
232
222
|
}
|
|
233
|
-
if (ch
|
|
223
|
+
if (ch < 128 && (char_types[ch] & 2) !== 0) return this.consume_number(start_line, start_column);
|
|
224
|
+
if (ch === CHAR_DOT) {
|
|
225
|
+
let next = this.pos + 1 < source_length ? source.charCodeAt(this.pos + 1) : 0;
|
|
226
|
+
if (next < 128 && (char_types[next] & 2) !== 0) return this.consume_number(start_line, start_column);
|
|
227
|
+
}
|
|
228
|
+
if (ch === CHAR_PLUS) {
|
|
234
229
|
let next = this.pos + 1 < source_length ? source.charCodeAt(this.pos + 1) : 0;
|
|
235
230
|
if (next < 128 && (char_types[next] & 2) !== 0) return this.consume_number(start_line, start_column);
|
|
236
231
|
if (next === CHAR_DOT) {
|
|
@@ -238,6 +233,15 @@ var Lexer = class {
|
|
|
238
233
|
if (next2 < 128 && (char_types[next2] & 2) !== 0) return this.consume_number(start_line, start_column);
|
|
239
234
|
}
|
|
240
235
|
}
|
|
236
|
+
if (ch === CHAR_DOUBLE_QUOTE || ch === CHAR_SINGLE_QUOTE) return this.consume_string(ch, start_line, start_column);
|
|
237
|
+
if (ch === CHAR_AT_SIGN) return this.consume_at_keyword(start_line, start_column);
|
|
238
|
+
if (ch === CHAR_HASH) return this.consume_hash(start_line, start_column);
|
|
239
|
+
if (ch === CHAR_LESS_THAN && this.pos + 3 < source_length) {
|
|
240
|
+
if (source.charCodeAt(this.pos + 1) === CHAR_EXCLAMATION && source.charCodeAt(this.pos + 2) === CHAR_HYPHEN && source.charCodeAt(this.pos + 3) === CHAR_HYPHEN) {
|
|
241
|
+
this.pos += 4;
|
|
242
|
+
return this.make_token(14, start, this.pos, start_line, start_column);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
241
245
|
this.pos++;
|
|
242
246
|
return this.make_token(9, start, this.pos, start_line, start_column);
|
|
243
247
|
}
|
|
@@ -259,21 +263,140 @@ var Lexer = class {
|
|
|
259
263
|
}
|
|
260
264
|
}
|
|
261
265
|
}
|
|
266
|
+
_skip_comment() {
|
|
267
|
+
const source = this.source;
|
|
268
|
+
const source_length = source.length;
|
|
269
|
+
let comment_start = this.pos;
|
|
270
|
+
let comment_line = this._line;
|
|
271
|
+
let comment_column = this.pos - this._line_offset + 1;
|
|
272
|
+
this.pos += 2;
|
|
273
|
+
let end_idx = source.indexOf("*/", this.pos);
|
|
274
|
+
if (end_idx < 0) {
|
|
275
|
+
this._scan_newlines(this.pos, source_length);
|
|
276
|
+
this.pos = source_length;
|
|
277
|
+
} else {
|
|
278
|
+
this._scan_newlines(this.pos, end_idx);
|
|
279
|
+
this.pos = end_idx + 2;
|
|
280
|
+
}
|
|
281
|
+
if (this.on_comment) this.on_comment({
|
|
282
|
+
start: comment_start,
|
|
283
|
+
end: this.pos,
|
|
284
|
+
length: this.pos - comment_start,
|
|
285
|
+
line: comment_line,
|
|
286
|
+
column: comment_column
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Fast-forward to the next `target` char that isn't inside a string or comment, without
|
|
291
|
+
* fully tokenizing what's in between — used by callers that only need to know *where a
|
|
292
|
+
* construct ends* (e.g. a selector's `{`), since the sub-parser for that construct
|
|
293
|
+
* re-tokenizes the span properly afterward.
|
|
294
|
+
*
|
|
295
|
+
* Strings go through consume_string and comments through _skip_comment, so escapes and
|
|
296
|
+
* on_comment callbacks behave identically to real tokenization. Ordinary characters cost
|
|
297
|
+
* one SKIP_SCAN_INTERESTING lookup each, same as consume_ident_or_function's inner loop.
|
|
298
|
+
*
|
|
299
|
+
* Returns true with this.pos at target, or false with this.pos at source_length.
|
|
300
|
+
*/
|
|
301
|
+
skip_to_unquoted(target) {
|
|
302
|
+
const source = this.source;
|
|
303
|
+
const source_length = source.length;
|
|
304
|
+
let pos = this.pos;
|
|
305
|
+
while (pos < source_length) {
|
|
306
|
+
let ch = source.charCodeAt(pos);
|
|
307
|
+
if (ch === target) {
|
|
308
|
+
this.pos = pos;
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
if (ch >= 128 || SKIP_SCAN_INTERESTING[ch] === 0) {
|
|
312
|
+
pos++;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (ch === CHAR_DOUBLE_QUOTE || ch === CHAR_SINGLE_QUOTE) {
|
|
316
|
+
this.pos = pos;
|
|
317
|
+
this.consume_string(ch, this._line, 1);
|
|
318
|
+
pos = this.pos;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (ch === CHAR_FORWARD_SLASH) {
|
|
322
|
+
if (pos + 1 < source_length && source.charCodeAt(pos + 1) === CHAR_ASTERISK) {
|
|
323
|
+
this.pos = pos;
|
|
324
|
+
this._skip_comment();
|
|
325
|
+
pos = this.pos;
|
|
326
|
+
} else pos++;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
pos++;
|
|
330
|
+
if (ch === CHAR_CARRIAGE_RETURN && pos < source_length && source.charCodeAt(pos) === CHAR_LINE_FEED) pos++;
|
|
331
|
+
this._line++;
|
|
332
|
+
this._line_offset = pos;
|
|
333
|
+
}
|
|
334
|
+
this.pos = pos;
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Same approach as skip_to_unquoted, but stops at any of `; { } ( ) !` — the stop
|
|
339
|
+
* characters parse-declaration.ts's value scan needs (paren depth, statement end,
|
|
340
|
+
* !important). The caller decides what each one means; this only locates the next one.
|
|
341
|
+
*
|
|
342
|
+
* Returns the stop character's code (this.pos left at it), or 0 at `end` if none found.
|
|
343
|
+
*/
|
|
344
|
+
skip_to_declaration_stop(end) {
|
|
345
|
+
const source = this.source;
|
|
346
|
+
let pos = this.pos;
|
|
347
|
+
while (pos < end) {
|
|
348
|
+
let ch = source.charCodeAt(pos);
|
|
349
|
+
if (ch < 128 && DECL_VALUE_STOP[ch] !== 0) {
|
|
350
|
+
this.pos = pos;
|
|
351
|
+
return ch;
|
|
352
|
+
}
|
|
353
|
+
if (ch >= 128 || SKIP_SCAN_INTERESTING[ch] === 0) {
|
|
354
|
+
pos++;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (ch === CHAR_DOUBLE_QUOTE || ch === CHAR_SINGLE_QUOTE) {
|
|
358
|
+
this.pos = pos;
|
|
359
|
+
this.consume_string(ch, this._line, 1);
|
|
360
|
+
pos = this.pos;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (ch === CHAR_FORWARD_SLASH) {
|
|
364
|
+
if (pos + 1 < end && source.charCodeAt(pos + 1) === CHAR_ASTERISK) {
|
|
365
|
+
this.pos = pos;
|
|
366
|
+
this._skip_comment();
|
|
367
|
+
pos = this.pos;
|
|
368
|
+
} else pos++;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
pos++;
|
|
372
|
+
if (ch === CHAR_CARRIAGE_RETURN && pos < end && source.charCodeAt(pos) === CHAR_LINE_FEED) pos++;
|
|
373
|
+
this._line++;
|
|
374
|
+
this._line_offset = pos;
|
|
375
|
+
}
|
|
376
|
+
this.pos = pos;
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
262
379
|
consume_whitespace(start_line, start_column) {
|
|
263
380
|
const source = this.source;
|
|
264
381
|
const source_length = source.length;
|
|
265
382
|
let start = this.pos;
|
|
266
|
-
|
|
267
|
-
|
|
383
|
+
let pos = start;
|
|
384
|
+
let line = this._line;
|
|
385
|
+
let line_offset = this._line_offset;
|
|
386
|
+
while (pos < source_length) {
|
|
387
|
+
let ch = source.charCodeAt(pos);
|
|
268
388
|
if (ch >= 128 || (char_types[ch] & 24) === 0) break;
|
|
269
|
-
|
|
389
|
+
pos++;
|
|
270
390
|
if ((char_types[ch] & 16) !== 0) {
|
|
271
|
-
if (ch === CHAR_CARRIAGE_RETURN &&
|
|
272
|
-
|
|
273
|
-
|
|
391
|
+
if (ch === CHAR_CARRIAGE_RETURN && pos < source_length && source.charCodeAt(pos) === CHAR_LINE_FEED) pos++;
|
|
392
|
+
line++;
|
|
393
|
+
line_offset = pos;
|
|
274
394
|
}
|
|
275
395
|
}
|
|
276
|
-
|
|
396
|
+
this.pos = pos;
|
|
397
|
+
this._line = line;
|
|
398
|
+
this._line_offset = line_offset;
|
|
399
|
+
return this.make_token(13, start, pos, start_line, start_column);
|
|
277
400
|
}
|
|
278
401
|
consume_string(quote, start_line, start_column) {
|
|
279
402
|
const source = this.source;
|
|
@@ -330,69 +453,75 @@ var Lexer = class {
|
|
|
330
453
|
const source = this.source;
|
|
331
454
|
const source_length = source.length;
|
|
332
455
|
let start = this.pos;
|
|
333
|
-
let
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
456
|
+
let pos = start;
|
|
457
|
+
let ch = source.charCodeAt(pos);
|
|
458
|
+
if (ch === CHAR_PLUS || ch === CHAR_HYPHEN) pos++;
|
|
459
|
+
while (pos < source_length) {
|
|
460
|
+
let ch = source.charCodeAt(pos);
|
|
337
461
|
if (ch >= 128 || (char_types[ch] & 2) === 0) break;
|
|
338
|
-
|
|
462
|
+
pos++;
|
|
339
463
|
}
|
|
340
|
-
if (
|
|
341
|
-
let next = source.charCodeAt(
|
|
464
|
+
if (pos < source_length && source.charCodeAt(pos) === CHAR_DOT && pos + 1 < source_length) {
|
|
465
|
+
let next = source.charCodeAt(pos + 1);
|
|
342
466
|
if (next < 128 && (char_types[next] & 2) !== 0) {
|
|
343
|
-
|
|
344
|
-
while (
|
|
345
|
-
let ch = source.charCodeAt(
|
|
467
|
+
pos++;
|
|
468
|
+
while (pos < source_length) {
|
|
469
|
+
let ch = source.charCodeAt(pos);
|
|
346
470
|
if (ch >= 128 || (char_types[ch] & 2) === 0) break;
|
|
347
|
-
|
|
471
|
+
pos++;
|
|
348
472
|
}
|
|
349
473
|
}
|
|
350
474
|
}
|
|
351
|
-
if (
|
|
352
|
-
let ch = source.charCodeAt(
|
|
475
|
+
if (pos < source_length) {
|
|
476
|
+
let ch = source.charCodeAt(pos);
|
|
353
477
|
if (ch === CHAR_LOWERCASE_E || ch === CHAR_UPPERCASE_E) {
|
|
354
|
-
let next =
|
|
478
|
+
let next = pos + 1 < source_length ? source.charCodeAt(pos + 1) : 0;
|
|
355
479
|
let is_next_digit = next < 128 && (char_types[next] & 2) !== 0;
|
|
356
|
-
let next2 =
|
|
480
|
+
let next2 = pos + 2 < source_length ? source.charCodeAt(pos + 2) : 0;
|
|
357
481
|
let is_next2_digit = next2 < 128 && (char_types[next2] & 2) !== 0;
|
|
358
482
|
if (is_next_digit || (next === CHAR_PLUS || next === CHAR_HYPHEN) && is_next2_digit) {
|
|
359
|
-
|
|
360
|
-
if (
|
|
361
|
-
let sign = source.charCodeAt(
|
|
362
|
-
if (sign === CHAR_PLUS || sign === CHAR_HYPHEN)
|
|
483
|
+
pos++;
|
|
484
|
+
if (pos < source_length) {
|
|
485
|
+
let sign = source.charCodeAt(pos);
|
|
486
|
+
if (sign === CHAR_PLUS || sign === CHAR_HYPHEN) pos++;
|
|
363
487
|
}
|
|
364
|
-
while (
|
|
365
|
-
let ch = source.charCodeAt(
|
|
488
|
+
while (pos < source_length) {
|
|
489
|
+
let ch = source.charCodeAt(pos);
|
|
366
490
|
if (ch >= 128 || (char_types[ch] & 2) === 0) break;
|
|
367
|
-
|
|
491
|
+
pos++;
|
|
368
492
|
}
|
|
369
493
|
}
|
|
370
494
|
}
|
|
371
495
|
}
|
|
372
|
-
if (
|
|
373
|
-
let ch = source.charCodeAt(
|
|
496
|
+
if (pos < source_length) {
|
|
497
|
+
let ch = source.charCodeAt(pos);
|
|
374
498
|
if (ch === CHAR_PERCENT) {
|
|
375
|
-
|
|
376
|
-
|
|
499
|
+
pos++;
|
|
500
|
+
this.pos = pos;
|
|
501
|
+
return this.make_token(11, start, pos, start_line, start_column);
|
|
377
502
|
}
|
|
378
|
-
if (is_ident_start(ch) || ch === CHAR_HYPHEN && is_ident_start(
|
|
379
|
-
while (
|
|
380
|
-
let ch = source.charCodeAt(
|
|
503
|
+
if (is_ident_start(ch) || ch === CHAR_HYPHEN && is_ident_start(pos + 1 < source_length ? source.charCodeAt(pos + 1) : 0)) {
|
|
504
|
+
while (pos < source_length) {
|
|
505
|
+
let ch = source.charCodeAt(pos);
|
|
381
506
|
if (ch < 128 && (char_types[ch] & 32) === 0) break;
|
|
382
|
-
|
|
507
|
+
pos++;
|
|
383
508
|
}
|
|
384
|
-
|
|
509
|
+
this.pos = pos;
|
|
510
|
+
return this.make_token(12, start, pos, start_line, start_column);
|
|
385
511
|
}
|
|
386
512
|
}
|
|
387
|
-
|
|
513
|
+
this.pos = pos;
|
|
514
|
+
return this.make_token(10, start, pos, start_line, start_column);
|
|
388
515
|
}
|
|
389
516
|
consume_ident_or_function(start_line, start_column) {
|
|
390
517
|
const source = this.source;
|
|
391
518
|
const source_length = source.length;
|
|
392
519
|
let start = this.pos;
|
|
393
|
-
|
|
394
|
-
|
|
520
|
+
let pos = start;
|
|
521
|
+
while (pos < source_length) {
|
|
522
|
+
let ch = source.charCodeAt(pos);
|
|
395
523
|
if (ch === CHAR_BACKSLASH) {
|
|
524
|
+
this.pos = pos;
|
|
396
525
|
if (this.pos + 1 >= source_length) break;
|
|
397
526
|
let next = source.charCodeAt(this.pos + 1);
|
|
398
527
|
if (is_newline(next)) break;
|
|
@@ -408,9 +537,11 @@ var Lexer = class {
|
|
|
408
537
|
if (ws < 128 && (char_types[ws] & 24) !== 0) this.advance();
|
|
409
538
|
}
|
|
410
539
|
} else this.pos++;
|
|
411
|
-
|
|
540
|
+
pos = this.pos;
|
|
541
|
+
} else if (ch >= 128 || (char_types[ch] & 32) !== 0) pos++;
|
|
412
542
|
else break;
|
|
413
543
|
}
|
|
544
|
+
this.pos = pos;
|
|
414
545
|
if (this.pos - start === 1) {
|
|
415
546
|
let first_ch = source.charCodeAt(start);
|
|
416
547
|
if ((first_ch === CHAR_LOWERCASE_U || first_ch === CHAR_UPPERCASE_U) && this.pos < source_length && source.charCodeAt(this.pos) === CHAR_PLUS) return this.consume_unicode_range(start, start_line, start_column);
|
|
@@ -456,25 +587,27 @@ var Lexer = class {
|
|
|
456
587
|
const source = this.source;
|
|
457
588
|
const source_length = source.length;
|
|
458
589
|
let start = this.pos;
|
|
459
|
-
|
|
460
|
-
while (
|
|
461
|
-
let ch = source.charCodeAt(
|
|
590
|
+
let pos = start + 1;
|
|
591
|
+
while (pos < source_length) {
|
|
592
|
+
let ch = source.charCodeAt(pos);
|
|
462
593
|
if (ch < 128 && (char_types[ch] & 32) === 0) break;
|
|
463
|
-
|
|
594
|
+
pos++;
|
|
464
595
|
}
|
|
465
|
-
|
|
596
|
+
this.pos = pos;
|
|
597
|
+
return this.make_token(3, start, pos, start_line, start_column);
|
|
466
598
|
}
|
|
467
599
|
consume_hash(start_line, start_column) {
|
|
468
600
|
const source = this.source;
|
|
469
601
|
const source_length = source.length;
|
|
470
602
|
let start = this.pos;
|
|
471
|
-
|
|
472
|
-
while (
|
|
473
|
-
let ch = source.charCodeAt(
|
|
603
|
+
let pos = start + 1;
|
|
604
|
+
while (pos < source_length) {
|
|
605
|
+
let ch = source.charCodeAt(pos);
|
|
474
606
|
if (ch < 128 && (char_types[ch] & 32) === 0) break;
|
|
475
|
-
|
|
607
|
+
pos++;
|
|
476
608
|
}
|
|
477
|
-
|
|
609
|
+
this.pos = pos;
|
|
610
|
+
return this.make_token(4, start, pos, start_line, start_column);
|
|
478
611
|
}
|
|
479
612
|
advance(count = 1) {
|
|
480
613
|
if (count === 1) {
|
|
@@ -563,7 +696,7 @@ var Lexer = class {
|
|
|
563
696
|
skip_whitespace_in_range(end) {
|
|
564
697
|
while (this.pos < end) {
|
|
565
698
|
let ch = this.source.charCodeAt(this.pos);
|
|
566
|
-
if (
|
|
699
|
+
if (ch < 128 && (char_types[ch] & 24) !== 0) {
|
|
567
700
|
this.advance();
|
|
568
701
|
continue;
|
|
569
702
|
}
|
package/dist/tokenize.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as tokenize, n as Lexer, r as LexerPosition, t as CommentInfo } from "./tokenize-
|
|
1
|
+
import { i as tokenize, n as Lexer, r as LexerPosition, t as CommentInfo } from "./tokenize-CDEnYcVG.js";
|
|
2
2
|
export { CommentInfo, Lexer, LexerPosition, tokenize };
|
package/dist/tokenize.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as tokenize, t as Lexer } from "./tokenize-
|
|
1
|
+
import { n as tokenize, t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
2
|
export { Lexer, tokenize };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
2
|
-
import "./arena-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
|
+
import "./arena-C-ZXJe7F.js";
|
|
3
3
|
import { a as is_whitespace, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
4
|
//#region src/value-node-parser.ts
|
|
5
5
|
/** @internal */
|
|
@@ -63,12 +63,9 @@ var ValueNodeParser = class {
|
|
|
63
63
|
this.arena.set_content_length(node, end - start);
|
|
64
64
|
return node;
|
|
65
65
|
}
|
|
66
|
-
create_operator_node(start, end) {
|
|
67
|
-
return this.create_node(16, start, end);
|
|
68
|
-
}
|
|
69
66
|
parse_operator_node(start, end) {
|
|
70
67
|
let ch = this.source.charCodeAt(start);
|
|
71
|
-
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.
|
|
68
|
+
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_node(16, start, end);
|
|
72
69
|
return null;
|
|
73
70
|
}
|
|
74
71
|
parse_function_node(start, end) {
|
package/dist/walk.d.ts
CHANGED
package/dist/walk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./arena-
|
|
2
|
-
import { t as CSSNode } from "./css-node-
|
|
1
|
+
import "./arena-C-ZXJe7F.js";
|
|
2
|
+
import { t as CSSNode } from "./css-node-Briho45Z.js";
|
|
3
3
|
import "./constants.js";
|
|
4
4
|
//#region src/walk.ts
|
|
5
5
|
const SKIP = Symbol("SKIP");
|
|
@@ -10,21 +10,8 @@ const BREAK = Symbol("BREAK");
|
|
|
10
10
|
* not tree depth.
|
|
11
11
|
*/
|
|
12
12
|
function walk(node, callback, depth = 0) {
|
|
13
|
-
const result = callback(node, depth);
|
|
14
|
-
if (result === BREAK) return false;
|
|
15
|
-
if (result === SKIP) return true;
|
|
16
13
|
const impl = node;
|
|
17
|
-
|
|
18
|
-
const source = impl.__get_source();
|
|
19
|
-
const index = impl.__get_index();
|
|
20
|
-
const type = arena.get_type(index);
|
|
21
|
-
const child_depth = type === 2 || type === 3 ? depth + 1 : depth;
|
|
22
|
-
let child = arena.get_first_child(index);
|
|
23
|
-
while (child !== 0) {
|
|
24
|
-
if (!_walk(arena, source, child, callback, child_depth)) return false;
|
|
25
|
-
child = arena.get_next_sibling(child);
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
14
|
+
return _walk(impl.__get_arena(), impl.__get_source(), impl.__get_index(), callback, depth);
|
|
28
15
|
}
|
|
29
16
|
function _walk(arena, source, index, callback, depth) {
|
|
30
17
|
const result = callback(new CSSNode(arena, source, index), depth);
|
|
@@ -45,21 +32,8 @@ const NOOP = function() {};
|
|
|
45
32
|
* SKIP in enter skips children (leave still runs); BREAK stops (leave doesn't run).
|
|
46
33
|
*/
|
|
47
34
|
function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
if (enter_result !== SKIP) {
|
|
51
|
-
const impl = node;
|
|
52
|
-
const arena = impl.__get_arena();
|
|
53
|
-
const source = impl.__get_source();
|
|
54
|
-
const index = impl.__get_index();
|
|
55
|
-
let child = arena.get_first_child(index);
|
|
56
|
-
while (child !== 0) {
|
|
57
|
-
if (!_traverse(arena, source, child, enter, leave)) return false;
|
|
58
|
-
child = arena.get_next_sibling(child);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (leave(node) === BREAK) return false;
|
|
62
|
-
return true;
|
|
35
|
+
const impl = node;
|
|
36
|
+
return _traverse(impl.__get_arena(), impl.__get_source(), impl.__get_index(), enter, leave);
|
|
63
37
|
}
|
|
64
38
|
function _traverse(arena, source, index, enter, leave) {
|
|
65
39
|
const node = new CSSNode(arena, source, index);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-parser",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4",
|
|
4
4
|
"description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"bootstrap": "^5.3.8",
|
|
83
83
|
"css-tree": "^3.1.0",
|
|
84
84
|
"knip": "^6.18.0",
|
|
85
|
-
"oxfmt": "^0.
|
|
85
|
+
"oxfmt": "^0.60.0",
|
|
86
86
|
"oxlint": "^1.71.0",
|
|
87
87
|
"postcss": "^8.5.15",
|
|
88
88
|
"publint": "^0.3.21",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"test-build": "pnpm run build && vitest run --config vitest.config.build.ts",
|
|
104
104
|
"build": "tsdown",
|
|
105
105
|
"benchmark": "pnpm run build && node --expose-gc benchmark/index.ts",
|
|
106
|
-
"lint": "oxlint --config .oxlintrc.json
|
|
106
|
+
"lint": "oxlint --config .oxlintrc.json; oxfmt --check",
|
|
107
107
|
"check": "tsc --noEmit",
|
|
108
108
|
"knip": "knip",
|
|
109
109
|
"precommit": "pnpm run test --run; pnpm run lint; pnpm run check"
|