vscode-css-languageservice 6.3.9 → 7.0.0-next.1

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