vscode-css-languageservice 5.3.0 → 6.0.0
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/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/lib/esm/beautify/beautify-css.js +57 -15
- package/lib/esm/cssLanguageService.d.ts +37 -37
- package/lib/esm/cssLanguageService.js +72 -75
- package/lib/esm/cssLanguageTypes.d.ts +238 -228
- package/lib/esm/cssLanguageTypes.js +42 -42
- package/lib/esm/data/webCustomData.js +21965 -21959
- package/lib/esm/languageFacts/builtinData.js +142 -142
- package/lib/esm/languageFacts/colors.js +469 -472
- package/lib/esm/languageFacts/dataManager.js +88 -92
- package/lib/esm/languageFacts/dataProvider.js +73 -79
- package/lib/esm/languageFacts/entry.js +137 -138
- package/lib/esm/languageFacts/facts.js +8 -8
- package/lib/esm/parser/cssErrors.js +48 -50
- package/lib/esm/parser/cssNodes.js +1502 -2019
- package/lib/esm/parser/cssParser.js +1534 -1566
- package/lib/esm/parser/cssScanner.js +592 -599
- package/lib/esm/parser/cssSymbolScope.js +311 -341
- package/lib/esm/parser/lessParser.js +714 -740
- package/lib/esm/parser/lessScanner.js +57 -78
- package/lib/esm/parser/scssErrors.js +18 -20
- package/lib/esm/parser/scssParser.js +796 -818
- package/lib/esm/parser/scssScanner.js +95 -116
- package/lib/esm/services/cssCodeActions.js +77 -81
- package/lib/esm/services/cssCompletion.js +1054 -1149
- package/lib/esm/services/cssFolding.js +190 -193
- package/lib/esm/services/cssFormatter.js +136 -117
- package/lib/esm/services/cssHover.js +148 -151
- package/lib/esm/services/cssNavigation.js +378 -470
- package/lib/esm/services/cssSelectionRange.js +47 -47
- package/lib/esm/services/cssValidation.js +41 -44
- package/lib/esm/services/lessCompletion.js +378 -397
- package/lib/esm/services/lint.js +518 -532
- package/lib/esm/services/lintRules.js +76 -83
- package/lib/esm/services/lintUtil.js +196 -205
- package/lib/esm/services/pathCompletion.js +157 -231
- package/lib/esm/services/scssCompletion.js +354 -378
- package/lib/esm/services/scssNavigation.js +82 -154
- package/lib/esm/services/selectorPrinting.js +492 -536
- package/lib/esm/utils/arrays.js +40 -46
- package/lib/esm/utils/objects.js +11 -11
- package/lib/esm/utils/resources.js +11 -24
- package/lib/esm/utils/strings.js +102 -104
- package/lib/umd/beautify/beautify-css.js +57 -15
- package/lib/umd/cssLanguageService.d.ts +37 -37
- package/lib/umd/cssLanguageService.js +99 -102
- package/lib/umd/cssLanguageTypes.d.ts +238 -228
- package/lib/umd/cssLanguageTypes.js +89 -88
- package/lib/umd/data/webCustomData.js +21978 -21972
- package/lib/umd/languageFacts/builtinData.js +154 -154
- package/lib/umd/languageFacts/colors.js +492 -495
- package/lib/umd/languageFacts/dataManager.js +101 -104
- package/lib/umd/languageFacts/dataProvider.js +86 -91
- package/lib/umd/languageFacts/entry.js +152 -153
- package/lib/umd/languageFacts/facts.js +29 -29
- package/lib/umd/parser/cssErrors.js +61 -62
- package/lib/umd/parser/cssNodes.js +1587 -2034
- package/lib/umd/parser/cssParser.js +1547 -1578
- package/lib/umd/parser/cssScanner.js +606 -611
- package/lib/umd/parser/cssSymbolScope.js +328 -353
- package/lib/umd/parser/lessParser.js +727 -752
- package/lib/umd/parser/lessScanner.js +70 -90
- package/lib/umd/parser/scssErrors.js +31 -32
- package/lib/umd/parser/scssParser.js +809 -830
- package/lib/umd/parser/scssScanner.js +108 -128
- package/lib/umd/services/cssCodeActions.js +90 -93
- package/lib/umd/services/cssCompletion.js +1067 -1161
- package/lib/umd/services/cssFolding.js +203 -206
- package/lib/umd/services/cssFormatter.js +150 -131
- package/lib/umd/services/cssHover.js +161 -163
- package/lib/umd/services/cssNavigation.js +391 -482
- package/lib/umd/services/cssSelectionRange.js +60 -60
- package/lib/umd/services/cssValidation.js +54 -56
- package/lib/umd/services/lessCompletion.js +391 -409
- package/lib/umd/services/lint.js +531 -544
- package/lib/umd/services/lintRules.js +91 -95
- package/lib/umd/services/lintUtil.js +210 -218
- package/lib/umd/services/pathCompletion.js +171 -244
- package/lib/umd/services/scssCompletion.js +367 -390
- package/lib/umd/services/scssNavigation.js +95 -166
- package/lib/umd/services/selectorPrinting.js +510 -550
- package/lib/umd/utils/arrays.js +55 -61
- package/lib/umd/utils/objects.js +25 -25
- package/lib/umd/utils/resources.js +26 -39
- package/lib/umd/utils/strings.js +120 -122
- package/package.json +11 -11
|
@@ -1,599 +1,592 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
'use strict';
|
|
6
|
-
export var TokenType;
|
|
7
|
-
(function (TokenType) {
|
|
8
|
-
TokenType[TokenType["Ident"] = 0] = "Ident";
|
|
9
|
-
TokenType[TokenType["AtKeyword"] = 1] = "AtKeyword";
|
|
10
|
-
TokenType[TokenType["String"] = 2] = "String";
|
|
11
|
-
TokenType[TokenType["BadString"] = 3] = "BadString";
|
|
12
|
-
TokenType[TokenType["UnquotedString"] = 4] = "UnquotedString";
|
|
13
|
-
TokenType[TokenType["Hash"] = 5] = "Hash";
|
|
14
|
-
TokenType[TokenType["Num"] = 6] = "Num";
|
|
15
|
-
TokenType[TokenType["Percentage"] = 7] = "Percentage";
|
|
16
|
-
TokenType[TokenType["Dimension"] = 8] = "Dimension";
|
|
17
|
-
TokenType[TokenType["UnicodeRange"] = 9] = "UnicodeRange";
|
|
18
|
-
TokenType[TokenType["CDO"] = 10] = "CDO";
|
|
19
|
-
TokenType[TokenType["CDC"] = 11] = "CDC";
|
|
20
|
-
TokenType[TokenType["Colon"] = 12] = "Colon";
|
|
21
|
-
TokenType[TokenType["SemiColon"] = 13] = "SemiColon";
|
|
22
|
-
TokenType[TokenType["CurlyL"] = 14] = "CurlyL";
|
|
23
|
-
TokenType[TokenType["CurlyR"] = 15] = "CurlyR";
|
|
24
|
-
TokenType[TokenType["ParenthesisL"] = 16] = "ParenthesisL";
|
|
25
|
-
TokenType[TokenType["ParenthesisR"] = 17] = "ParenthesisR";
|
|
26
|
-
TokenType[TokenType["BracketL"] = 18] = "BracketL";
|
|
27
|
-
TokenType[TokenType["BracketR"] = 19] = "BracketR";
|
|
28
|
-
TokenType[TokenType["Whitespace"] = 20] = "Whitespace";
|
|
29
|
-
TokenType[TokenType["Includes"] = 21] = "Includes";
|
|
30
|
-
TokenType[TokenType["Dashmatch"] = 22] = "Dashmatch";
|
|
31
|
-
TokenType[TokenType["SubstringOperator"] = 23] = "SubstringOperator";
|
|
32
|
-
TokenType[TokenType["PrefixOperator"] = 24] = "PrefixOperator";
|
|
33
|
-
TokenType[TokenType["SuffixOperator"] = 25] = "SuffixOperator";
|
|
34
|
-
TokenType[TokenType["Delim"] = 26] = "Delim";
|
|
35
|
-
TokenType[TokenType["EMS"] = 27] = "EMS";
|
|
36
|
-
TokenType[TokenType["EXS"] = 28] = "EXS";
|
|
37
|
-
TokenType[TokenType["Length"] = 29] = "Length";
|
|
38
|
-
TokenType[TokenType["Angle"] = 30] = "Angle";
|
|
39
|
-
TokenType[TokenType["Time"] = 31] = "Time";
|
|
40
|
-
TokenType[TokenType["Freq"] = 32] = "Freq";
|
|
41
|
-
TokenType[TokenType["Exclamation"] = 33] = "Exclamation";
|
|
42
|
-
TokenType[TokenType["Resolution"] = 34] = "Resolution";
|
|
43
|
-
TokenType[TokenType["Comma"] = 35] = "Comma";
|
|
44
|
-
TokenType[TokenType["Charset"] = 36] = "Charset";
|
|
45
|
-
TokenType[TokenType["EscapedJavaScript"] = 37] = "EscapedJavaScript";
|
|
46
|
-
TokenType[TokenType["BadEscapedJavaScript"] = 38] = "BadEscapedJavaScript";
|
|
47
|
-
TokenType[TokenType["Comment"] = 39] = "Comment";
|
|
48
|
-
TokenType[TokenType["SingleLineComment"] = 40] = "SingleLineComment";
|
|
49
|
-
TokenType[TokenType["EOF"] = 41] = "EOF";
|
|
50
|
-
TokenType[TokenType["CustomToken"] = 42] = "CustomToken";
|
|
51
|
-
})(TokenType || (TokenType = {}));
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.source = source;
|
|
55
|
-
this.len = source.length;
|
|
56
|
-
this.position = 0;
|
|
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
|
-
staticTokenTable[
|
|
164
|
-
staticTokenTable[
|
|
165
|
-
staticTokenTable[
|
|
166
|
-
staticTokenTable[
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
staticUnitTable['
|
|
174
|
-
staticUnitTable['
|
|
175
|
-
staticUnitTable['
|
|
176
|
-
staticUnitTable['
|
|
177
|
-
staticUnitTable['
|
|
178
|
-
staticUnitTable['
|
|
179
|
-
staticUnitTable['
|
|
180
|
-
staticUnitTable['
|
|
181
|
-
staticUnitTable['
|
|
182
|
-
staticUnitTable['
|
|
183
|
-
staticUnitTable['
|
|
184
|
-
staticUnitTable['
|
|
185
|
-
staticUnitTable['
|
|
186
|
-
staticUnitTable['
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
return
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
this.stream.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (tokenType !==
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
this.stream.advance(
|
|
326
|
-
return this.finishToken(offset,
|
|
327
|
-
}
|
|
328
|
-
//
|
|
329
|
-
if (this.stream.peekChar(0) ===
|
|
330
|
-
this.stream.advance(2);
|
|
331
|
-
return this.finishToken(offset, TokenType.
|
|
332
|
-
}
|
|
333
|
-
//
|
|
334
|
-
if (this.stream.peekChar(0) ===
|
|
335
|
-
this.stream.advance(2);
|
|
336
|
-
return this.finishToken(offset, TokenType.
|
|
337
|
-
}
|
|
338
|
-
// Substring operator
|
|
339
|
-
if (this.stream.peekChar(0) ===
|
|
340
|
-
this.stream.advance(2);
|
|
341
|
-
return this.finishToken(offset, TokenType.
|
|
342
|
-
}
|
|
343
|
-
// Substring operator
|
|
344
|
-
if (this.stream.peekChar(0) ===
|
|
345
|
-
this.stream.advance(2);
|
|
346
|
-
return this.finishToken(offset, TokenType.
|
|
347
|
-
}
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (this.
|
|
361
|
-
if (!this.
|
|
362
|
-
return this.finishToken(offset, TokenType.
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
else
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return true;
|
|
452
|
-
}
|
|
453
|
-
if (
|
|
454
|
-
this.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
ch
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return false;
|
|
596
|
-
};
|
|
597
|
-
return Scanner;
|
|
598
|
-
}());
|
|
599
|
-
export { Scanner };
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
'use strict';
|
|
6
|
+
export var TokenType;
|
|
7
|
+
(function (TokenType) {
|
|
8
|
+
TokenType[TokenType["Ident"] = 0] = "Ident";
|
|
9
|
+
TokenType[TokenType["AtKeyword"] = 1] = "AtKeyword";
|
|
10
|
+
TokenType[TokenType["String"] = 2] = "String";
|
|
11
|
+
TokenType[TokenType["BadString"] = 3] = "BadString";
|
|
12
|
+
TokenType[TokenType["UnquotedString"] = 4] = "UnquotedString";
|
|
13
|
+
TokenType[TokenType["Hash"] = 5] = "Hash";
|
|
14
|
+
TokenType[TokenType["Num"] = 6] = "Num";
|
|
15
|
+
TokenType[TokenType["Percentage"] = 7] = "Percentage";
|
|
16
|
+
TokenType[TokenType["Dimension"] = 8] = "Dimension";
|
|
17
|
+
TokenType[TokenType["UnicodeRange"] = 9] = "UnicodeRange";
|
|
18
|
+
TokenType[TokenType["CDO"] = 10] = "CDO";
|
|
19
|
+
TokenType[TokenType["CDC"] = 11] = "CDC";
|
|
20
|
+
TokenType[TokenType["Colon"] = 12] = "Colon";
|
|
21
|
+
TokenType[TokenType["SemiColon"] = 13] = "SemiColon";
|
|
22
|
+
TokenType[TokenType["CurlyL"] = 14] = "CurlyL";
|
|
23
|
+
TokenType[TokenType["CurlyR"] = 15] = "CurlyR";
|
|
24
|
+
TokenType[TokenType["ParenthesisL"] = 16] = "ParenthesisL";
|
|
25
|
+
TokenType[TokenType["ParenthesisR"] = 17] = "ParenthesisR";
|
|
26
|
+
TokenType[TokenType["BracketL"] = 18] = "BracketL";
|
|
27
|
+
TokenType[TokenType["BracketR"] = 19] = "BracketR";
|
|
28
|
+
TokenType[TokenType["Whitespace"] = 20] = "Whitespace";
|
|
29
|
+
TokenType[TokenType["Includes"] = 21] = "Includes";
|
|
30
|
+
TokenType[TokenType["Dashmatch"] = 22] = "Dashmatch";
|
|
31
|
+
TokenType[TokenType["SubstringOperator"] = 23] = "SubstringOperator";
|
|
32
|
+
TokenType[TokenType["PrefixOperator"] = 24] = "PrefixOperator";
|
|
33
|
+
TokenType[TokenType["SuffixOperator"] = 25] = "SuffixOperator";
|
|
34
|
+
TokenType[TokenType["Delim"] = 26] = "Delim";
|
|
35
|
+
TokenType[TokenType["EMS"] = 27] = "EMS";
|
|
36
|
+
TokenType[TokenType["EXS"] = 28] = "EXS";
|
|
37
|
+
TokenType[TokenType["Length"] = 29] = "Length";
|
|
38
|
+
TokenType[TokenType["Angle"] = 30] = "Angle";
|
|
39
|
+
TokenType[TokenType["Time"] = 31] = "Time";
|
|
40
|
+
TokenType[TokenType["Freq"] = 32] = "Freq";
|
|
41
|
+
TokenType[TokenType["Exclamation"] = 33] = "Exclamation";
|
|
42
|
+
TokenType[TokenType["Resolution"] = 34] = "Resolution";
|
|
43
|
+
TokenType[TokenType["Comma"] = 35] = "Comma";
|
|
44
|
+
TokenType[TokenType["Charset"] = 36] = "Charset";
|
|
45
|
+
TokenType[TokenType["EscapedJavaScript"] = 37] = "EscapedJavaScript";
|
|
46
|
+
TokenType[TokenType["BadEscapedJavaScript"] = 38] = "BadEscapedJavaScript";
|
|
47
|
+
TokenType[TokenType["Comment"] = 39] = "Comment";
|
|
48
|
+
TokenType[TokenType["SingleLineComment"] = 40] = "SingleLineComment";
|
|
49
|
+
TokenType[TokenType["EOF"] = 41] = "EOF";
|
|
50
|
+
TokenType[TokenType["CustomToken"] = 42] = "CustomToken";
|
|
51
|
+
})(TokenType || (TokenType = {}));
|
|
52
|
+
export class MultiLineStream {
|
|
53
|
+
constructor(source) {
|
|
54
|
+
this.source = source;
|
|
55
|
+
this.len = source.length;
|
|
56
|
+
this.position = 0;
|
|
57
|
+
}
|
|
58
|
+
substring(from, to = this.position) {
|
|
59
|
+
return this.source.substring(from, to);
|
|
60
|
+
}
|
|
61
|
+
eos() {
|
|
62
|
+
return this.len <= this.position;
|
|
63
|
+
}
|
|
64
|
+
pos() {
|
|
65
|
+
return this.position;
|
|
66
|
+
}
|
|
67
|
+
goBackTo(pos) {
|
|
68
|
+
this.position = pos;
|
|
69
|
+
}
|
|
70
|
+
goBack(n) {
|
|
71
|
+
this.position -= n;
|
|
72
|
+
}
|
|
73
|
+
advance(n) {
|
|
74
|
+
this.position += n;
|
|
75
|
+
}
|
|
76
|
+
nextChar() {
|
|
77
|
+
return this.source.charCodeAt(this.position++) || 0;
|
|
78
|
+
}
|
|
79
|
+
peekChar(n = 0) {
|
|
80
|
+
return this.source.charCodeAt(this.position + n) || 0;
|
|
81
|
+
}
|
|
82
|
+
lookbackChar(n = 0) {
|
|
83
|
+
return this.source.charCodeAt(this.position - n) || 0;
|
|
84
|
+
}
|
|
85
|
+
advanceIfChar(ch) {
|
|
86
|
+
if (ch === this.source.charCodeAt(this.position)) {
|
|
87
|
+
this.position++;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
advanceIfChars(ch) {
|
|
93
|
+
if (this.position + ch.length > this.source.length) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
let i = 0;
|
|
97
|
+
for (; i < ch.length; i++) {
|
|
98
|
+
if (this.source.charCodeAt(this.position + i) !== ch[i]) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
this.advance(i);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
advanceWhileChar(condition) {
|
|
106
|
+
const posNow = this.position;
|
|
107
|
+
while (this.position < this.len && condition(this.source.charCodeAt(this.position))) {
|
|
108
|
+
this.position++;
|
|
109
|
+
}
|
|
110
|
+
return this.position - posNow;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const _a = 'a'.charCodeAt(0);
|
|
114
|
+
const _f = 'f'.charCodeAt(0);
|
|
115
|
+
const _z = 'z'.charCodeAt(0);
|
|
116
|
+
const _u = 'u'.charCodeAt(0);
|
|
117
|
+
const _A = 'A'.charCodeAt(0);
|
|
118
|
+
const _F = 'F'.charCodeAt(0);
|
|
119
|
+
const _Z = 'Z'.charCodeAt(0);
|
|
120
|
+
const _0 = '0'.charCodeAt(0);
|
|
121
|
+
const _9 = '9'.charCodeAt(0);
|
|
122
|
+
const _TLD = '~'.charCodeAt(0);
|
|
123
|
+
const _HAT = '^'.charCodeAt(0);
|
|
124
|
+
const _EQS = '='.charCodeAt(0);
|
|
125
|
+
const _PIP = '|'.charCodeAt(0);
|
|
126
|
+
const _MIN = '-'.charCodeAt(0);
|
|
127
|
+
const _USC = '_'.charCodeAt(0);
|
|
128
|
+
const _PRC = '%'.charCodeAt(0);
|
|
129
|
+
const _MUL = '*'.charCodeAt(0);
|
|
130
|
+
const _LPA = '('.charCodeAt(0);
|
|
131
|
+
const _RPA = ')'.charCodeAt(0);
|
|
132
|
+
const _LAN = '<'.charCodeAt(0);
|
|
133
|
+
const _RAN = '>'.charCodeAt(0);
|
|
134
|
+
const _ATS = '@'.charCodeAt(0);
|
|
135
|
+
const _HSH = '#'.charCodeAt(0);
|
|
136
|
+
const _DLR = '$'.charCodeAt(0);
|
|
137
|
+
const _BSL = '\\'.charCodeAt(0);
|
|
138
|
+
const _FSL = '/'.charCodeAt(0);
|
|
139
|
+
const _NWL = '\n'.charCodeAt(0);
|
|
140
|
+
const _CAR = '\r'.charCodeAt(0);
|
|
141
|
+
const _LFD = '\f'.charCodeAt(0);
|
|
142
|
+
const _DQO = '"'.charCodeAt(0);
|
|
143
|
+
const _SQO = '\''.charCodeAt(0);
|
|
144
|
+
const _WSP = ' '.charCodeAt(0);
|
|
145
|
+
const _TAB = '\t'.charCodeAt(0);
|
|
146
|
+
const _SEM = ';'.charCodeAt(0);
|
|
147
|
+
const _COL = ':'.charCodeAt(0);
|
|
148
|
+
const _CUL = '{'.charCodeAt(0);
|
|
149
|
+
const _CUR = '}'.charCodeAt(0);
|
|
150
|
+
const _BRL = '['.charCodeAt(0);
|
|
151
|
+
const _BRR = ']'.charCodeAt(0);
|
|
152
|
+
const _CMA = ','.charCodeAt(0);
|
|
153
|
+
const _DOT = '.'.charCodeAt(0);
|
|
154
|
+
const _BNG = '!'.charCodeAt(0);
|
|
155
|
+
const _QSM = '?'.charCodeAt(0);
|
|
156
|
+
const _PLS = '+'.charCodeAt(0);
|
|
157
|
+
const staticTokenTable = {};
|
|
158
|
+
staticTokenTable[_SEM] = TokenType.SemiColon;
|
|
159
|
+
staticTokenTable[_COL] = TokenType.Colon;
|
|
160
|
+
staticTokenTable[_CUL] = TokenType.CurlyL;
|
|
161
|
+
staticTokenTable[_CUR] = TokenType.CurlyR;
|
|
162
|
+
staticTokenTable[_BRR] = TokenType.BracketR;
|
|
163
|
+
staticTokenTable[_BRL] = TokenType.BracketL;
|
|
164
|
+
staticTokenTable[_LPA] = TokenType.ParenthesisL;
|
|
165
|
+
staticTokenTable[_RPA] = TokenType.ParenthesisR;
|
|
166
|
+
staticTokenTable[_CMA] = TokenType.Comma;
|
|
167
|
+
const staticUnitTable = {};
|
|
168
|
+
staticUnitTable['em'] = TokenType.EMS;
|
|
169
|
+
staticUnitTable['ex'] = TokenType.EXS;
|
|
170
|
+
staticUnitTable['px'] = TokenType.Length;
|
|
171
|
+
staticUnitTable['cm'] = TokenType.Length;
|
|
172
|
+
staticUnitTable['mm'] = TokenType.Length;
|
|
173
|
+
staticUnitTable['in'] = TokenType.Length;
|
|
174
|
+
staticUnitTable['pt'] = TokenType.Length;
|
|
175
|
+
staticUnitTable['pc'] = TokenType.Length;
|
|
176
|
+
staticUnitTable['deg'] = TokenType.Angle;
|
|
177
|
+
staticUnitTable['rad'] = TokenType.Angle;
|
|
178
|
+
staticUnitTable['grad'] = TokenType.Angle;
|
|
179
|
+
staticUnitTable['ms'] = TokenType.Time;
|
|
180
|
+
staticUnitTable['s'] = TokenType.Time;
|
|
181
|
+
staticUnitTable['hz'] = TokenType.Freq;
|
|
182
|
+
staticUnitTable['khz'] = TokenType.Freq;
|
|
183
|
+
staticUnitTable['%'] = TokenType.Percentage;
|
|
184
|
+
staticUnitTable['fr'] = TokenType.Percentage;
|
|
185
|
+
staticUnitTable['dpi'] = TokenType.Resolution;
|
|
186
|
+
staticUnitTable['dpcm'] = TokenType.Resolution;
|
|
187
|
+
export class Scanner {
|
|
188
|
+
constructor() {
|
|
189
|
+
this.stream = new MultiLineStream('');
|
|
190
|
+
this.ignoreComment = true;
|
|
191
|
+
this.ignoreWhitespace = true;
|
|
192
|
+
this.inURL = false;
|
|
193
|
+
}
|
|
194
|
+
setSource(input) {
|
|
195
|
+
this.stream = new MultiLineStream(input);
|
|
196
|
+
}
|
|
197
|
+
finishToken(offset, type, text) {
|
|
198
|
+
return {
|
|
199
|
+
offset: offset,
|
|
200
|
+
len: this.stream.pos() - offset,
|
|
201
|
+
type: type,
|
|
202
|
+
text: text || this.stream.substring(offset)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
substring(offset, len) {
|
|
206
|
+
return this.stream.substring(offset, offset + len);
|
|
207
|
+
}
|
|
208
|
+
pos() {
|
|
209
|
+
return this.stream.pos();
|
|
210
|
+
}
|
|
211
|
+
goBackTo(pos) {
|
|
212
|
+
this.stream.goBackTo(pos);
|
|
213
|
+
}
|
|
214
|
+
scanUnquotedString() {
|
|
215
|
+
const offset = this.stream.pos();
|
|
216
|
+
const content = [];
|
|
217
|
+
if (this._unquotedString(content)) {
|
|
218
|
+
return this.finishToken(offset, TokenType.UnquotedString, content.join(''));
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
scan() {
|
|
223
|
+
// processes all whitespaces and comments
|
|
224
|
+
const triviaToken = this.trivia();
|
|
225
|
+
if (triviaToken !== null) {
|
|
226
|
+
return triviaToken;
|
|
227
|
+
}
|
|
228
|
+
const offset = this.stream.pos();
|
|
229
|
+
// End of file/input
|
|
230
|
+
if (this.stream.eos()) {
|
|
231
|
+
return this.finishToken(offset, TokenType.EOF);
|
|
232
|
+
}
|
|
233
|
+
return this.scanNext(offset);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Read the range as described in https://www.w3.org/TR/CSS21/syndata.html#tokenization
|
|
237
|
+
* Assume the `u` has aleady been consumed
|
|
238
|
+
* @returns if reading the unicode was successful
|
|
239
|
+
*/
|
|
240
|
+
tryScanUnicode() {
|
|
241
|
+
const offset = this.stream.pos();
|
|
242
|
+
if (!this.stream.eos() && this._unicodeRange()) {
|
|
243
|
+
return this.finishToken(offset, TokenType.UnicodeRange);
|
|
244
|
+
}
|
|
245
|
+
this.stream.goBackTo(offset);
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
scanNext(offset) {
|
|
249
|
+
// CDO <!--
|
|
250
|
+
if (this.stream.advanceIfChars([_LAN, _BNG, _MIN, _MIN])) {
|
|
251
|
+
return this.finishToken(offset, TokenType.CDO);
|
|
252
|
+
}
|
|
253
|
+
// CDC -->
|
|
254
|
+
if (this.stream.advanceIfChars([_MIN, _MIN, _RAN])) {
|
|
255
|
+
return this.finishToken(offset, TokenType.CDC);
|
|
256
|
+
}
|
|
257
|
+
let content = [];
|
|
258
|
+
if (this.ident(content)) {
|
|
259
|
+
return this.finishToken(offset, TokenType.Ident, content.join(''));
|
|
260
|
+
}
|
|
261
|
+
// at-keyword
|
|
262
|
+
if (this.stream.advanceIfChar(_ATS)) {
|
|
263
|
+
content = ['@'];
|
|
264
|
+
if (this._name(content)) {
|
|
265
|
+
const keywordText = content.join('');
|
|
266
|
+
if (keywordText === '@charset') {
|
|
267
|
+
return this.finishToken(offset, TokenType.Charset, keywordText);
|
|
268
|
+
}
|
|
269
|
+
return this.finishToken(offset, TokenType.AtKeyword, keywordText);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
return this.finishToken(offset, TokenType.Delim);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// hash
|
|
276
|
+
if (this.stream.advanceIfChar(_HSH)) {
|
|
277
|
+
content = ['#'];
|
|
278
|
+
if (this._name(content)) {
|
|
279
|
+
return this.finishToken(offset, TokenType.Hash, content.join(''));
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return this.finishToken(offset, TokenType.Delim);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// Important
|
|
286
|
+
if (this.stream.advanceIfChar(_BNG)) {
|
|
287
|
+
return this.finishToken(offset, TokenType.Exclamation);
|
|
288
|
+
}
|
|
289
|
+
// Numbers
|
|
290
|
+
if (this._number()) {
|
|
291
|
+
const pos = this.stream.pos();
|
|
292
|
+
content = [this.stream.substring(offset, pos)];
|
|
293
|
+
if (this.stream.advanceIfChar(_PRC)) {
|
|
294
|
+
// Percentage 43%
|
|
295
|
+
return this.finishToken(offset, TokenType.Percentage);
|
|
296
|
+
}
|
|
297
|
+
else if (this.ident(content)) {
|
|
298
|
+
const dim = this.stream.substring(pos).toLowerCase();
|
|
299
|
+
const tokenType = staticUnitTable[dim];
|
|
300
|
+
if (typeof tokenType !== 'undefined') {
|
|
301
|
+
// Known dimension 43px
|
|
302
|
+
return this.finishToken(offset, tokenType, content.join(''));
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
// Unknown dimension 43ft
|
|
306
|
+
return this.finishToken(offset, TokenType.Dimension, content.join(''));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return this.finishToken(offset, TokenType.Num);
|
|
310
|
+
}
|
|
311
|
+
// String, BadString
|
|
312
|
+
content = [];
|
|
313
|
+
let tokenType = this._string(content);
|
|
314
|
+
if (tokenType !== null) {
|
|
315
|
+
return this.finishToken(offset, tokenType, content.join(''));
|
|
316
|
+
}
|
|
317
|
+
// single character tokens
|
|
318
|
+
tokenType = staticTokenTable[this.stream.peekChar()];
|
|
319
|
+
if (typeof tokenType !== 'undefined') {
|
|
320
|
+
this.stream.advance(1);
|
|
321
|
+
return this.finishToken(offset, tokenType);
|
|
322
|
+
}
|
|
323
|
+
// includes ~=
|
|
324
|
+
if (this.stream.peekChar(0) === _TLD && this.stream.peekChar(1) === _EQS) {
|
|
325
|
+
this.stream.advance(2);
|
|
326
|
+
return this.finishToken(offset, TokenType.Includes);
|
|
327
|
+
}
|
|
328
|
+
// DashMatch |=
|
|
329
|
+
if (this.stream.peekChar(0) === _PIP && this.stream.peekChar(1) === _EQS) {
|
|
330
|
+
this.stream.advance(2);
|
|
331
|
+
return this.finishToken(offset, TokenType.Dashmatch);
|
|
332
|
+
}
|
|
333
|
+
// Substring operator *=
|
|
334
|
+
if (this.stream.peekChar(0) === _MUL && this.stream.peekChar(1) === _EQS) {
|
|
335
|
+
this.stream.advance(2);
|
|
336
|
+
return this.finishToken(offset, TokenType.SubstringOperator);
|
|
337
|
+
}
|
|
338
|
+
// Substring operator ^=
|
|
339
|
+
if (this.stream.peekChar(0) === _HAT && this.stream.peekChar(1) === _EQS) {
|
|
340
|
+
this.stream.advance(2);
|
|
341
|
+
return this.finishToken(offset, TokenType.PrefixOperator);
|
|
342
|
+
}
|
|
343
|
+
// Substring operator $=
|
|
344
|
+
if (this.stream.peekChar(0) === _DLR && this.stream.peekChar(1) === _EQS) {
|
|
345
|
+
this.stream.advance(2);
|
|
346
|
+
return this.finishToken(offset, TokenType.SuffixOperator);
|
|
347
|
+
}
|
|
348
|
+
// Delim
|
|
349
|
+
this.stream.nextChar();
|
|
350
|
+
return this.finishToken(offset, TokenType.Delim);
|
|
351
|
+
}
|
|
352
|
+
trivia() {
|
|
353
|
+
while (true) {
|
|
354
|
+
const offset = this.stream.pos();
|
|
355
|
+
if (this._whitespace()) {
|
|
356
|
+
if (!this.ignoreWhitespace) {
|
|
357
|
+
return this.finishToken(offset, TokenType.Whitespace);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (this.comment()) {
|
|
361
|
+
if (!this.ignoreComment) {
|
|
362
|
+
return this.finishToken(offset, TokenType.Comment);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
comment() {
|
|
371
|
+
if (this.stream.advanceIfChars([_FSL, _MUL])) {
|
|
372
|
+
let success = false, hot = false;
|
|
373
|
+
this.stream.advanceWhileChar((ch) => {
|
|
374
|
+
if (hot && ch === _FSL) {
|
|
375
|
+
success = true;
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
hot = ch === _MUL;
|
|
379
|
+
return true;
|
|
380
|
+
});
|
|
381
|
+
if (success) {
|
|
382
|
+
this.stream.advance(1);
|
|
383
|
+
}
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
_number() {
|
|
389
|
+
let npeek = 0, ch;
|
|
390
|
+
if (this.stream.peekChar() === _DOT) {
|
|
391
|
+
npeek = 1;
|
|
392
|
+
}
|
|
393
|
+
ch = this.stream.peekChar(npeek);
|
|
394
|
+
if (ch >= _0 && ch <= _9) {
|
|
395
|
+
this.stream.advance(npeek + 1);
|
|
396
|
+
this.stream.advanceWhileChar((ch) => {
|
|
397
|
+
return ch >= _0 && ch <= _9 || npeek === 0 && ch === _DOT;
|
|
398
|
+
});
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
_newline(result) {
|
|
404
|
+
const ch = this.stream.peekChar();
|
|
405
|
+
switch (ch) {
|
|
406
|
+
case _CAR:
|
|
407
|
+
case _LFD:
|
|
408
|
+
case _NWL:
|
|
409
|
+
this.stream.advance(1);
|
|
410
|
+
result.push(String.fromCharCode(ch));
|
|
411
|
+
if (ch === _CAR && this.stream.advanceIfChar(_NWL)) {
|
|
412
|
+
result.push('\n');
|
|
413
|
+
}
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
_escape(result, includeNewLines) {
|
|
419
|
+
let ch = this.stream.peekChar();
|
|
420
|
+
if (ch === _BSL) {
|
|
421
|
+
this.stream.advance(1);
|
|
422
|
+
ch = this.stream.peekChar();
|
|
423
|
+
let hexNumCount = 0;
|
|
424
|
+
while (hexNumCount < 6 && (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F)) {
|
|
425
|
+
this.stream.advance(1);
|
|
426
|
+
ch = this.stream.peekChar();
|
|
427
|
+
hexNumCount++;
|
|
428
|
+
}
|
|
429
|
+
if (hexNumCount > 0) {
|
|
430
|
+
try {
|
|
431
|
+
const hexVal = parseInt(this.stream.substring(this.stream.pos() - hexNumCount), 16);
|
|
432
|
+
if (hexVal) {
|
|
433
|
+
result.push(String.fromCharCode(hexVal));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
catch (e) {
|
|
437
|
+
// ignore
|
|
438
|
+
}
|
|
439
|
+
// optional whitespace or new line, not part of result text
|
|
440
|
+
if (ch === _WSP || ch === _TAB) {
|
|
441
|
+
this.stream.advance(1);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
this._newline([]);
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
if (ch !== _CAR && ch !== _LFD && ch !== _NWL) {
|
|
449
|
+
this.stream.advance(1);
|
|
450
|
+
result.push(String.fromCharCode(ch));
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
else if (includeNewLines) {
|
|
454
|
+
return this._newline(result);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
_stringChar(closeQuote, result) {
|
|
460
|
+
// not closeQuote, not backslash, not newline
|
|
461
|
+
const ch = this.stream.peekChar();
|
|
462
|
+
if (ch !== 0 && ch !== closeQuote && ch !== _BSL && ch !== _CAR && ch !== _LFD && ch !== _NWL) {
|
|
463
|
+
this.stream.advance(1);
|
|
464
|
+
result.push(String.fromCharCode(ch));
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
_string(result) {
|
|
470
|
+
if (this.stream.peekChar() === _SQO || this.stream.peekChar() === _DQO) {
|
|
471
|
+
const closeQuote = this.stream.nextChar();
|
|
472
|
+
result.push(String.fromCharCode(closeQuote));
|
|
473
|
+
while (this._stringChar(closeQuote, result) || this._escape(result, true)) {
|
|
474
|
+
// loop
|
|
475
|
+
}
|
|
476
|
+
if (this.stream.peekChar() === closeQuote) {
|
|
477
|
+
this.stream.nextChar();
|
|
478
|
+
result.push(String.fromCharCode(closeQuote));
|
|
479
|
+
return TokenType.String;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
return TokenType.BadString;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
_unquotedChar(result) {
|
|
488
|
+
// not closeQuote, not backslash, not newline
|
|
489
|
+
const ch = this.stream.peekChar();
|
|
490
|
+
if (ch !== 0 && ch !== _BSL && ch !== _SQO && ch !== _DQO && ch !== _LPA && ch !== _RPA && ch !== _WSP && ch !== _TAB && ch !== _NWL && ch !== _LFD && ch !== _CAR) {
|
|
491
|
+
this.stream.advance(1);
|
|
492
|
+
result.push(String.fromCharCode(ch));
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
_unquotedString(result) {
|
|
498
|
+
let hasContent = false;
|
|
499
|
+
while (this._unquotedChar(result) || this._escape(result)) {
|
|
500
|
+
hasContent = true;
|
|
501
|
+
}
|
|
502
|
+
return hasContent;
|
|
503
|
+
}
|
|
504
|
+
_whitespace() {
|
|
505
|
+
const n = this.stream.advanceWhileChar((ch) => {
|
|
506
|
+
return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR;
|
|
507
|
+
});
|
|
508
|
+
return n > 0;
|
|
509
|
+
}
|
|
510
|
+
_name(result) {
|
|
511
|
+
let matched = false;
|
|
512
|
+
while (this._identChar(result) || this._escape(result)) {
|
|
513
|
+
matched = true;
|
|
514
|
+
}
|
|
515
|
+
return matched;
|
|
516
|
+
}
|
|
517
|
+
ident(result) {
|
|
518
|
+
const pos = this.stream.pos();
|
|
519
|
+
const hasMinus = this._minus(result);
|
|
520
|
+
if (hasMinus) {
|
|
521
|
+
if (this._minus(result) /* -- */ || this._identFirstChar(result) || this._escape(result)) {
|
|
522
|
+
while (this._identChar(result) || this._escape(result)) {
|
|
523
|
+
// loop
|
|
524
|
+
}
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else if (this._identFirstChar(result) || this._escape(result)) {
|
|
529
|
+
while (this._identChar(result) || this._escape(result)) {
|
|
530
|
+
// loop
|
|
531
|
+
}
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
this.stream.goBackTo(pos);
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
_identFirstChar(result) {
|
|
538
|
+
const ch = this.stream.peekChar();
|
|
539
|
+
if (ch === _USC || // _
|
|
540
|
+
ch >= _a && ch <= _z || // a-z
|
|
541
|
+
ch >= _A && ch <= _Z || // A-Z
|
|
542
|
+
ch >= 0x80 && ch <= 0xFFFF) { // nonascii
|
|
543
|
+
this.stream.advance(1);
|
|
544
|
+
result.push(String.fromCharCode(ch));
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
_minus(result) {
|
|
550
|
+
const ch = this.stream.peekChar();
|
|
551
|
+
if (ch === _MIN) {
|
|
552
|
+
this.stream.advance(1);
|
|
553
|
+
result.push(String.fromCharCode(ch));
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
_identChar(result) {
|
|
559
|
+
const ch = this.stream.peekChar();
|
|
560
|
+
if (ch === _USC || // _
|
|
561
|
+
ch === _MIN || // -
|
|
562
|
+
ch >= _a && ch <= _z || // a-z
|
|
563
|
+
ch >= _A && ch <= _Z || // A-Z
|
|
564
|
+
ch >= _0 && ch <= _9 || // 0/9
|
|
565
|
+
ch >= 0x80 && ch <= 0xFFFF) { // nonascii
|
|
566
|
+
this.stream.advance(1);
|
|
567
|
+
result.push(String.fromCharCode(ch));
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
_unicodeRange() {
|
|
573
|
+
// follow https://www.w3.org/TR/CSS21/syndata.html#tokenization and https://www.w3.org/TR/css-syntax-3/#urange-syntax
|
|
574
|
+
// assume u has already been parsed
|
|
575
|
+
if (this.stream.advanceIfChar(_PLS)) {
|
|
576
|
+
const isHexDigit = (ch) => (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F);
|
|
577
|
+
const codePoints = this.stream.advanceWhileChar(isHexDigit) + this.stream.advanceWhileChar(ch => ch === _QSM);
|
|
578
|
+
if (codePoints >= 1 && codePoints <= 6) {
|
|
579
|
+
if (this.stream.advanceIfChar(_MIN)) {
|
|
580
|
+
const digits = this.stream.advanceWhileChar(isHexDigit);
|
|
581
|
+
if (digits >= 1 && digits <= 6) {
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
}
|