vscode-css-languageservice 5.4.2 → 6.1.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 +7 -1
- package/SECURITY.md +41 -0
- package/lib/esm/beautify/beautify-css.js +11 -4
- package/lib/esm/cssLanguageService.d.ts +2 -1
- package/lib/esm/cssLanguageService.js +15 -17
- package/lib/esm/cssLanguageTypes.js +2 -2
- package/lib/esm/data/webCustomData.js +356 -232
- package/lib/esm/languageFacts/builtinData.js +15 -15
- package/lib/esm/languageFacts/colors.js +66 -69
- package/lib/esm/languageFacts/dataManager.js +38 -42
- package/lib/esm/languageFacts/dataProvider.js +17 -23
- package/lib/esm/languageFacts/entry.js +22 -23
- package/lib/esm/parser/cssErrors.js +5 -7
- package/lib/esm/parser/cssNodes.js +869 -1377
- package/lib/esm/parser/cssParser.js +419 -376
- package/lib/esm/parser/cssScanner.js +168 -175
- package/lib/esm/parser/cssSymbolScope.js +107 -137
- package/lib/esm/parser/lessParser.js +177 -202
- package/lib/esm/parser/lessScanner.js +22 -43
- package/lib/esm/parser/scssErrors.js +5 -7
- package/lib/esm/parser/scssParser.js +196 -208
- package/lib/esm/parser/scssScanner.js +33 -54
- package/lib/esm/services/cssCodeActions.js +36 -40
- package/lib/esm/services/cssCompletion.js +300 -395
- package/lib/esm/services/cssFolding.js +32 -35
- package/lib/esm/services/cssFormatter.js +22 -22
- package/lib/esm/services/cssHover.js +30 -33
- package/lib/esm/services/cssNavigation.js +260 -289
- package/lib/esm/services/cssSelectionRange.js +6 -6
- package/lib/esm/services/cssValidation.js +13 -16
- package/lib/esm/services/lessCompletion.js +351 -370
- package/lib/esm/services/lint.js +161 -175
- package/lib/esm/services/lintRules.js +20 -27
- package/lib/esm/services/lintUtil.js +19 -28
- package/lib/esm/services/pathCompletion.js +84 -158
- package/lib/esm/services/scssCompletion.js +283 -307
- package/lib/esm/services/scssNavigation.js +65 -137
- package/lib/esm/services/selectorPrinting.js +131 -175
- package/lib/esm/utils/arrays.js +6 -12
- package/lib/esm/utils/objects.js +1 -1
- package/lib/esm/utils/resources.js +3 -16
- package/lib/esm/utils/strings.js +10 -12
- package/lib/umd/beautify/beautify-css.js +11 -4
- package/lib/umd/cssLanguageService.d.ts +2 -1
- package/lib/umd/cssLanguageService.js +34 -32
- package/lib/umd/cssLanguageTypes.js +4 -3
- package/lib/umd/data/webCustomData.js +355 -231
- package/lib/umd/languageFacts/colors.js +65 -68
- package/lib/umd/languageFacts/dataManager.js +41 -44
- package/lib/umd/languageFacts/dataProvider.js +17 -22
- package/lib/umd/languageFacts/entry.js +22 -23
- package/lib/umd/languageFacts/facts.js +5 -1
- package/lib/umd/parser/cssErrors.js +5 -6
- package/lib/umd/parser/cssNodes.js +870 -1307
- package/lib/umd/parser/cssParser.js +424 -380
- package/lib/umd/parser/cssScanner.js +168 -173
- package/lib/umd/parser/cssSymbolScope.js +109 -134
- package/lib/umd/parser/lessParser.js +182 -206
- package/lib/umd/parser/lessScanner.js +22 -42
- package/lib/umd/parser/scssErrors.js +5 -6
- package/lib/umd/parser/scssParser.js +202 -213
- package/lib/umd/parser/scssScanner.js +25 -45
- package/lib/umd/services/cssCodeActions.js +41 -44
- package/lib/umd/services/cssCompletion.js +308 -402
- package/lib/umd/services/cssFolding.js +35 -38
- package/lib/umd/services/cssFormatter.js +25 -25
- package/lib/umd/services/cssHover.js +36 -38
- package/lib/umd/services/cssNavigation.js +267 -295
- package/lib/umd/services/cssSelectionRange.js +8 -8
- package/lib/umd/services/cssValidation.js +17 -19
- package/lib/umd/services/lessCompletion.js +354 -372
- package/lib/umd/services/lint.js +167 -180
- package/lib/umd/services/lintRules.js +20 -24
- package/lib/umd/services/lintUtil.js +20 -28
- package/lib/umd/services/pathCompletion.js +87 -160
- package/lib/umd/services/scssCompletion.js +287 -310
- package/lib/umd/services/scssNavigation.js +69 -140
- package/lib/umd/services/selectorPrinting.js +134 -174
- package/lib/umd/utils/arrays.js +6 -12
- package/lib/umd/utils/objects.js +1 -1
- package/lib/umd/utils/resources.js +4 -17
- package/lib/umd/utils/strings.js +10 -12
- package/package.json +16 -15
|
@@ -49,54 +49,51 @@ export var TokenType;
|
|
|
49
49
|
TokenType[TokenType["EOF"] = 41] = "EOF";
|
|
50
50
|
TokenType[TokenType["CustomToken"] = 42] = "CustomToken";
|
|
51
51
|
})(TokenType || (TokenType = {}));
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
export class MultiLineStream {
|
|
53
|
+
constructor(source) {
|
|
54
54
|
this.source = source;
|
|
55
55
|
this.len = source.length;
|
|
56
56
|
this.position = 0;
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
if (to === void 0) { to = this.position; }
|
|
58
|
+
substring(from, to = this.position) {
|
|
60
59
|
return this.source.substring(from, to);
|
|
61
|
-
}
|
|
62
|
-
|
|
60
|
+
}
|
|
61
|
+
eos() {
|
|
63
62
|
return this.len <= this.position;
|
|
64
|
-
}
|
|
65
|
-
|
|
63
|
+
}
|
|
64
|
+
pos() {
|
|
66
65
|
return this.position;
|
|
67
|
-
}
|
|
68
|
-
|
|
66
|
+
}
|
|
67
|
+
goBackTo(pos) {
|
|
69
68
|
this.position = pos;
|
|
70
|
-
}
|
|
71
|
-
|
|
69
|
+
}
|
|
70
|
+
goBack(n) {
|
|
72
71
|
this.position -= n;
|
|
73
|
-
}
|
|
74
|
-
|
|
72
|
+
}
|
|
73
|
+
advance(n) {
|
|
75
74
|
this.position += n;
|
|
76
|
-
}
|
|
77
|
-
|
|
75
|
+
}
|
|
76
|
+
nextChar() {
|
|
78
77
|
return this.source.charCodeAt(this.position++) || 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (n === void 0) { n = 0; }
|
|
78
|
+
}
|
|
79
|
+
peekChar(n = 0) {
|
|
82
80
|
return this.source.charCodeAt(this.position + n) || 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (n === void 0) { n = 0; }
|
|
81
|
+
}
|
|
82
|
+
lookbackChar(n = 0) {
|
|
86
83
|
return this.source.charCodeAt(this.position - n) || 0;
|
|
87
|
-
}
|
|
88
|
-
|
|
84
|
+
}
|
|
85
|
+
advanceIfChar(ch) {
|
|
89
86
|
if (ch === this.source.charCodeAt(this.position)) {
|
|
90
87
|
this.position++;
|
|
91
88
|
return true;
|
|
92
89
|
}
|
|
93
90
|
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
91
|
+
}
|
|
92
|
+
advanceIfChars(ch) {
|
|
96
93
|
if (this.position + ch.length > this.source.length) {
|
|
97
94
|
return false;
|
|
98
95
|
}
|
|
99
|
-
|
|
96
|
+
let i = 0;
|
|
100
97
|
for (; i < ch.length; i++) {
|
|
101
98
|
if (this.source.charCodeAt(this.position + i) !== ch[i]) {
|
|
102
99
|
return false;
|
|
@@ -104,62 +101,60 @@ var MultiLineStream = /** @class */ (function () {
|
|
|
104
101
|
}
|
|
105
102
|
this.advance(i);
|
|
106
103
|
return true;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
}
|
|
105
|
+
advanceWhileChar(condition) {
|
|
106
|
+
const posNow = this.position;
|
|
110
107
|
while (this.position < this.len && condition(this.source.charCodeAt(this.position))) {
|
|
111
108
|
this.position++;
|
|
112
109
|
}
|
|
113
110
|
return this.position - posNow;
|
|
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
|
-
var _PLS = '+'.charCodeAt(0);
|
|
162
|
-
var staticTokenTable = {};
|
|
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 = {};
|
|
163
158
|
staticTokenTable[_SEM] = TokenType.SemiColon;
|
|
164
159
|
staticTokenTable[_COL] = TokenType.Colon;
|
|
165
160
|
staticTokenTable[_CUL] = TokenType.CurlyL;
|
|
@@ -169,7 +164,7 @@ staticTokenTable[_BRL] = TokenType.BracketL;
|
|
|
169
164
|
staticTokenTable[_LPA] = TokenType.ParenthesisL;
|
|
170
165
|
staticTokenTable[_RPA] = TokenType.ParenthesisR;
|
|
171
166
|
staticTokenTable[_CMA] = TokenType.Comma;
|
|
172
|
-
|
|
167
|
+
const staticUnitTable = {};
|
|
173
168
|
staticUnitTable['em'] = TokenType.EMS;
|
|
174
169
|
staticUnitTable['ex'] = TokenType.EXS;
|
|
175
170
|
staticUnitTable['px'] = TokenType.Length;
|
|
@@ -189,68 +184,68 @@ staticUnitTable['%'] = TokenType.Percentage;
|
|
|
189
184
|
staticUnitTable['fr'] = TokenType.Percentage;
|
|
190
185
|
staticUnitTable['dpi'] = TokenType.Resolution;
|
|
191
186
|
staticUnitTable['dpcm'] = TokenType.Resolution;
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
export class Scanner {
|
|
188
|
+
constructor() {
|
|
194
189
|
this.stream = new MultiLineStream('');
|
|
195
190
|
this.ignoreComment = true;
|
|
196
191
|
this.ignoreWhitespace = true;
|
|
197
192
|
this.inURL = false;
|
|
198
193
|
}
|
|
199
|
-
|
|
194
|
+
setSource(input) {
|
|
200
195
|
this.stream = new MultiLineStream(input);
|
|
201
|
-
}
|
|
202
|
-
|
|
196
|
+
}
|
|
197
|
+
finishToken(offset, type, text) {
|
|
203
198
|
return {
|
|
204
199
|
offset: offset,
|
|
205
200
|
len: this.stream.pos() - offset,
|
|
206
201
|
type: type,
|
|
207
202
|
text: text || this.stream.substring(offset)
|
|
208
203
|
};
|
|
209
|
-
}
|
|
210
|
-
|
|
204
|
+
}
|
|
205
|
+
substring(offset, len) {
|
|
211
206
|
return this.stream.substring(offset, offset + len);
|
|
212
|
-
}
|
|
213
|
-
|
|
207
|
+
}
|
|
208
|
+
pos() {
|
|
214
209
|
return this.stream.pos();
|
|
215
|
-
}
|
|
216
|
-
|
|
210
|
+
}
|
|
211
|
+
goBackTo(pos) {
|
|
217
212
|
this.stream.goBackTo(pos);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
}
|
|
214
|
+
scanUnquotedString() {
|
|
215
|
+
const offset = this.stream.pos();
|
|
216
|
+
const content = [];
|
|
222
217
|
if (this._unquotedString(content)) {
|
|
223
218
|
return this.finishToken(offset, TokenType.UnquotedString, content.join(''));
|
|
224
219
|
}
|
|
225
220
|
return null;
|
|
226
|
-
}
|
|
227
|
-
|
|
221
|
+
}
|
|
222
|
+
scan() {
|
|
228
223
|
// processes all whitespaces and comments
|
|
229
|
-
|
|
224
|
+
const triviaToken = this.trivia();
|
|
230
225
|
if (triviaToken !== null) {
|
|
231
226
|
return triviaToken;
|
|
232
227
|
}
|
|
233
|
-
|
|
228
|
+
const offset = this.stream.pos();
|
|
234
229
|
// End of file/input
|
|
235
230
|
if (this.stream.eos()) {
|
|
236
231
|
return this.finishToken(offset, TokenType.EOF);
|
|
237
232
|
}
|
|
238
233
|
return this.scanNext(offset);
|
|
239
|
-
}
|
|
234
|
+
}
|
|
240
235
|
/**
|
|
241
236
|
* Read the range as described in https://www.w3.org/TR/CSS21/syndata.html#tokenization
|
|
242
237
|
* Assume the `u` has aleady been consumed
|
|
243
238
|
* @returns if reading the unicode was successful
|
|
244
239
|
*/
|
|
245
|
-
|
|
246
|
-
|
|
240
|
+
tryScanUnicode() {
|
|
241
|
+
const offset = this.stream.pos();
|
|
247
242
|
if (!this.stream.eos() && this._unicodeRange()) {
|
|
248
243
|
return this.finishToken(offset, TokenType.UnicodeRange);
|
|
249
244
|
}
|
|
250
245
|
this.stream.goBackTo(offset);
|
|
251
246
|
return undefined;
|
|
252
|
-
}
|
|
253
|
-
|
|
247
|
+
}
|
|
248
|
+
scanNext(offset) {
|
|
254
249
|
// CDO <!--
|
|
255
250
|
if (this.stream.advanceIfChars([_LAN, _BNG, _MIN, _MIN])) {
|
|
256
251
|
return this.finishToken(offset, TokenType.CDO);
|
|
@@ -259,7 +254,7 @@ var Scanner = /** @class */ (function () {
|
|
|
259
254
|
if (this.stream.advanceIfChars([_MIN, _MIN, _RAN])) {
|
|
260
255
|
return this.finishToken(offset, TokenType.CDC);
|
|
261
256
|
}
|
|
262
|
-
|
|
257
|
+
let content = [];
|
|
263
258
|
if (this.ident(content)) {
|
|
264
259
|
return this.finishToken(offset, TokenType.Ident, content.join(''));
|
|
265
260
|
}
|
|
@@ -267,7 +262,7 @@ var Scanner = /** @class */ (function () {
|
|
|
267
262
|
if (this.stream.advanceIfChar(_ATS)) {
|
|
268
263
|
content = ['@'];
|
|
269
264
|
if (this._name(content)) {
|
|
270
|
-
|
|
265
|
+
const keywordText = content.join('');
|
|
271
266
|
if (keywordText === '@charset') {
|
|
272
267
|
return this.finishToken(offset, TokenType.Charset, keywordText);
|
|
273
268
|
}
|
|
@@ -293,18 +288,18 @@ var Scanner = /** @class */ (function () {
|
|
|
293
288
|
}
|
|
294
289
|
// Numbers
|
|
295
290
|
if (this._number()) {
|
|
296
|
-
|
|
291
|
+
const pos = this.stream.pos();
|
|
297
292
|
content = [this.stream.substring(offset, pos)];
|
|
298
293
|
if (this.stream.advanceIfChar(_PRC)) {
|
|
299
294
|
// Percentage 43%
|
|
300
295
|
return this.finishToken(offset, TokenType.Percentage);
|
|
301
296
|
}
|
|
302
297
|
else if (this.ident(content)) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (typeof
|
|
298
|
+
const dim = this.stream.substring(pos).toLowerCase();
|
|
299
|
+
const tokenType = staticUnitTable[dim];
|
|
300
|
+
if (typeof tokenType !== 'undefined') {
|
|
306
301
|
// Known dimension 43px
|
|
307
|
-
return this.finishToken(offset,
|
|
302
|
+
return this.finishToken(offset, tokenType, content.join(''));
|
|
308
303
|
}
|
|
309
304
|
else {
|
|
310
305
|
// Unknown dimension 43ft
|
|
@@ -315,7 +310,7 @@ var Scanner = /** @class */ (function () {
|
|
|
315
310
|
}
|
|
316
311
|
// String, BadString
|
|
317
312
|
content = [];
|
|
318
|
-
|
|
313
|
+
let tokenType = this._string(content);
|
|
319
314
|
if (tokenType !== null) {
|
|
320
315
|
return this.finishToken(offset, tokenType, content.join(''));
|
|
321
316
|
}
|
|
@@ -353,10 +348,10 @@ var Scanner = /** @class */ (function () {
|
|
|
353
348
|
// Delim
|
|
354
349
|
this.stream.nextChar();
|
|
355
350
|
return this.finishToken(offset, TokenType.Delim);
|
|
356
|
-
}
|
|
357
|
-
|
|
351
|
+
}
|
|
352
|
+
trivia() {
|
|
358
353
|
while (true) {
|
|
359
|
-
|
|
354
|
+
const offset = this.stream.pos();
|
|
360
355
|
if (this._whitespace()) {
|
|
361
356
|
if (!this.ignoreWhitespace) {
|
|
362
357
|
return this.finishToken(offset, TokenType.Whitespace);
|
|
@@ -371,42 +366,42 @@ var Scanner = /** @class */ (function () {
|
|
|
371
366
|
return null;
|
|
372
367
|
}
|
|
373
368
|
}
|
|
374
|
-
}
|
|
375
|
-
|
|
369
|
+
}
|
|
370
|
+
comment() {
|
|
376
371
|
if (this.stream.advanceIfChars([_FSL, _MUL])) {
|
|
377
|
-
|
|
378
|
-
this.stream.advanceWhileChar(
|
|
379
|
-
if (
|
|
380
|
-
|
|
372
|
+
let success = false, hot = false;
|
|
373
|
+
this.stream.advanceWhileChar((ch) => {
|
|
374
|
+
if (hot && ch === _FSL) {
|
|
375
|
+
success = true;
|
|
381
376
|
return false;
|
|
382
377
|
}
|
|
383
|
-
|
|
378
|
+
hot = ch === _MUL;
|
|
384
379
|
return true;
|
|
385
380
|
});
|
|
386
|
-
if (
|
|
381
|
+
if (success) {
|
|
387
382
|
this.stream.advance(1);
|
|
388
383
|
}
|
|
389
384
|
return true;
|
|
390
385
|
}
|
|
391
386
|
return false;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
387
|
+
}
|
|
388
|
+
_number() {
|
|
389
|
+
let npeek = 0, ch;
|
|
395
390
|
if (this.stream.peekChar() === _DOT) {
|
|
396
391
|
npeek = 1;
|
|
397
392
|
}
|
|
398
393
|
ch = this.stream.peekChar(npeek);
|
|
399
394
|
if (ch >= _0 && ch <= _9) {
|
|
400
395
|
this.stream.advance(npeek + 1);
|
|
401
|
-
this.stream.advanceWhileChar(
|
|
396
|
+
this.stream.advanceWhileChar((ch) => {
|
|
402
397
|
return ch >= _0 && ch <= _9 || npeek === 0 && ch === _DOT;
|
|
403
398
|
});
|
|
404
399
|
return true;
|
|
405
400
|
}
|
|
406
401
|
return false;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
402
|
+
}
|
|
403
|
+
_newline(result) {
|
|
404
|
+
const ch = this.stream.peekChar();
|
|
410
405
|
switch (ch) {
|
|
411
406
|
case _CAR:
|
|
412
407
|
case _LFD:
|
|
@@ -419,13 +414,13 @@ var Scanner = /** @class */ (function () {
|
|
|
419
414
|
return true;
|
|
420
415
|
}
|
|
421
416
|
return false;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
417
|
+
}
|
|
418
|
+
_escape(result, includeNewLines) {
|
|
419
|
+
let ch = this.stream.peekChar();
|
|
425
420
|
if (ch === _BSL) {
|
|
426
421
|
this.stream.advance(1);
|
|
427
422
|
ch = this.stream.peekChar();
|
|
428
|
-
|
|
423
|
+
let hexNumCount = 0;
|
|
429
424
|
while (hexNumCount < 6 && (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F)) {
|
|
430
425
|
this.stream.advance(1);
|
|
431
426
|
ch = this.stream.peekChar();
|
|
@@ -433,7 +428,7 @@ var Scanner = /** @class */ (function () {
|
|
|
433
428
|
}
|
|
434
429
|
if (hexNumCount > 0) {
|
|
435
430
|
try {
|
|
436
|
-
|
|
431
|
+
const hexVal = parseInt(this.stream.substring(this.stream.pos() - hexNumCount), 16);
|
|
437
432
|
if (hexVal) {
|
|
438
433
|
result.push(String.fromCharCode(hexVal));
|
|
439
434
|
}
|
|
@@ -460,20 +455,20 @@ var Scanner = /** @class */ (function () {
|
|
|
460
455
|
}
|
|
461
456
|
}
|
|
462
457
|
return false;
|
|
463
|
-
}
|
|
464
|
-
|
|
458
|
+
}
|
|
459
|
+
_stringChar(closeQuote, result) {
|
|
465
460
|
// not closeQuote, not backslash, not newline
|
|
466
|
-
|
|
461
|
+
const ch = this.stream.peekChar();
|
|
467
462
|
if (ch !== 0 && ch !== closeQuote && ch !== _BSL && ch !== _CAR && ch !== _LFD && ch !== _NWL) {
|
|
468
463
|
this.stream.advance(1);
|
|
469
464
|
result.push(String.fromCharCode(ch));
|
|
470
465
|
return true;
|
|
471
466
|
}
|
|
472
467
|
return false;
|
|
473
|
-
}
|
|
474
|
-
|
|
468
|
+
}
|
|
469
|
+
_string(result) {
|
|
475
470
|
if (this.stream.peekChar() === _SQO || this.stream.peekChar() === _DQO) {
|
|
476
|
-
|
|
471
|
+
const closeQuote = this.stream.nextChar();
|
|
477
472
|
result.push(String.fromCharCode(closeQuote));
|
|
478
473
|
while (this._stringChar(closeQuote, result) || this._escape(result, true)) {
|
|
479
474
|
// loop
|
|
@@ -488,40 +483,40 @@ var Scanner = /** @class */ (function () {
|
|
|
488
483
|
}
|
|
489
484
|
}
|
|
490
485
|
return null;
|
|
491
|
-
}
|
|
492
|
-
|
|
486
|
+
}
|
|
487
|
+
_unquotedChar(result) {
|
|
493
488
|
// not closeQuote, not backslash, not newline
|
|
494
|
-
|
|
489
|
+
const ch = this.stream.peekChar();
|
|
495
490
|
if (ch !== 0 && ch !== _BSL && ch !== _SQO && ch !== _DQO && ch !== _LPA && ch !== _RPA && ch !== _WSP && ch !== _TAB && ch !== _NWL && ch !== _LFD && ch !== _CAR) {
|
|
496
491
|
this.stream.advance(1);
|
|
497
492
|
result.push(String.fromCharCode(ch));
|
|
498
493
|
return true;
|
|
499
494
|
}
|
|
500
495
|
return false;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
496
|
+
}
|
|
497
|
+
_unquotedString(result) {
|
|
498
|
+
let hasContent = false;
|
|
504
499
|
while (this._unquotedChar(result) || this._escape(result)) {
|
|
505
500
|
hasContent = true;
|
|
506
501
|
}
|
|
507
502
|
return hasContent;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
503
|
+
}
|
|
504
|
+
_whitespace() {
|
|
505
|
+
const n = this.stream.advanceWhileChar((ch) => {
|
|
511
506
|
return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR;
|
|
512
507
|
});
|
|
513
508
|
return n > 0;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
|
|
509
|
+
}
|
|
510
|
+
_name(result) {
|
|
511
|
+
let matched = false;
|
|
517
512
|
while (this._identChar(result) || this._escape(result)) {
|
|
518
513
|
matched = true;
|
|
519
514
|
}
|
|
520
515
|
return matched;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
516
|
+
}
|
|
517
|
+
ident(result) {
|
|
518
|
+
const pos = this.stream.pos();
|
|
519
|
+
const hasMinus = this._minus(result);
|
|
525
520
|
if (hasMinus) {
|
|
526
521
|
if (this._minus(result) /* -- */ || this._identFirstChar(result) || this._escape(result)) {
|
|
527
522
|
while (this._identChar(result) || this._escape(result)) {
|
|
@@ -538,9 +533,9 @@ var Scanner = /** @class */ (function () {
|
|
|
538
533
|
}
|
|
539
534
|
this.stream.goBackTo(pos);
|
|
540
535
|
return false;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
536
|
+
}
|
|
537
|
+
_identFirstChar(result) {
|
|
538
|
+
const ch = this.stream.peekChar();
|
|
544
539
|
if (ch === _USC || // _
|
|
545
540
|
ch >= _a && ch <= _z || // a-z
|
|
546
541
|
ch >= _A && ch <= _Z || // A-Z
|
|
@@ -550,18 +545,18 @@ var Scanner = /** @class */ (function () {
|
|
|
550
545
|
return true;
|
|
551
546
|
}
|
|
552
547
|
return false;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
|
|
548
|
+
}
|
|
549
|
+
_minus(result) {
|
|
550
|
+
const ch = this.stream.peekChar();
|
|
556
551
|
if (ch === _MIN) {
|
|
557
552
|
this.stream.advance(1);
|
|
558
553
|
result.push(String.fromCharCode(ch));
|
|
559
554
|
return true;
|
|
560
555
|
}
|
|
561
556
|
return false;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
557
|
+
}
|
|
558
|
+
_identChar(result) {
|
|
559
|
+
const ch = this.stream.peekChar();
|
|
565
560
|
if (ch === _USC || // _
|
|
566
561
|
ch === _MIN || // -
|
|
567
562
|
ch >= _a && ch <= _z || // a-z
|
|
@@ -573,16 +568,16 @@ var Scanner = /** @class */ (function () {
|
|
|
573
568
|
return true;
|
|
574
569
|
}
|
|
575
570
|
return false;
|
|
576
|
-
}
|
|
577
|
-
|
|
571
|
+
}
|
|
572
|
+
_unicodeRange() {
|
|
578
573
|
// follow https://www.w3.org/TR/CSS21/syndata.html#tokenization and https://www.w3.org/TR/css-syntax-3/#urange-syntax
|
|
579
574
|
// assume u has already been parsed
|
|
580
575
|
if (this.stream.advanceIfChar(_PLS)) {
|
|
581
|
-
|
|
582
|
-
|
|
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);
|
|
583
578
|
if (codePoints >= 1 && codePoints <= 6) {
|
|
584
579
|
if (this.stream.advanceIfChar(_MIN)) {
|
|
585
|
-
|
|
580
|
+
const digits = this.stream.advanceWhileChar(isHexDigit);
|
|
586
581
|
if (digits >= 1 && digits <= 6) {
|
|
587
582
|
return true;
|
|
588
583
|
}
|
|
@@ -593,7 +588,5 @@ var Scanner = /** @class */ (function () {
|
|
|
593
588
|
}
|
|
594
589
|
}
|
|
595
590
|
return false;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
}());
|
|
599
|
-
export { Scanner };
|
|
591
|
+
}
|
|
592
|
+
}
|