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
|
@@ -60,54 +60,51 @@
|
|
|
60
60
|
TokenType[TokenType["EOF"] = 41] = "EOF";
|
|
61
61
|
TokenType[TokenType["CustomToken"] = 42] = "CustomToken";
|
|
62
62
|
})(TokenType = exports.TokenType || (exports.TokenType = {}));
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
class MultiLineStream {
|
|
64
|
+
constructor(source) {
|
|
65
65
|
this.source = source;
|
|
66
66
|
this.len = source.length;
|
|
67
67
|
this.position = 0;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
if (to === void 0) { to = this.position; }
|
|
69
|
+
substring(from, to = this.position) {
|
|
71
70
|
return this.source.substring(from, to);
|
|
72
|
-
}
|
|
73
|
-
|
|
71
|
+
}
|
|
72
|
+
eos() {
|
|
74
73
|
return this.len <= this.position;
|
|
75
|
-
}
|
|
76
|
-
|
|
74
|
+
}
|
|
75
|
+
pos() {
|
|
77
76
|
return this.position;
|
|
78
|
-
}
|
|
79
|
-
|
|
77
|
+
}
|
|
78
|
+
goBackTo(pos) {
|
|
80
79
|
this.position = pos;
|
|
81
|
-
}
|
|
82
|
-
|
|
80
|
+
}
|
|
81
|
+
goBack(n) {
|
|
83
82
|
this.position -= n;
|
|
84
|
-
}
|
|
85
|
-
|
|
83
|
+
}
|
|
84
|
+
advance(n) {
|
|
86
85
|
this.position += n;
|
|
87
|
-
}
|
|
88
|
-
|
|
86
|
+
}
|
|
87
|
+
nextChar() {
|
|
89
88
|
return this.source.charCodeAt(this.position++) || 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (n === void 0) { n = 0; }
|
|
89
|
+
}
|
|
90
|
+
peekChar(n = 0) {
|
|
93
91
|
return this.source.charCodeAt(this.position + n) || 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (n === void 0) { n = 0; }
|
|
92
|
+
}
|
|
93
|
+
lookbackChar(n = 0) {
|
|
97
94
|
return this.source.charCodeAt(this.position - n) || 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
95
|
+
}
|
|
96
|
+
advanceIfChar(ch) {
|
|
100
97
|
if (ch === this.source.charCodeAt(this.position)) {
|
|
101
98
|
this.position++;
|
|
102
99
|
return true;
|
|
103
100
|
}
|
|
104
101
|
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
102
|
+
}
|
|
103
|
+
advanceIfChars(ch) {
|
|
107
104
|
if (this.position + ch.length > this.source.length) {
|
|
108
105
|
return false;
|
|
109
106
|
}
|
|
110
|
-
|
|
107
|
+
let i = 0;
|
|
111
108
|
for (; i < ch.length; i++) {
|
|
112
109
|
if (this.source.charCodeAt(this.position + i) !== ch[i]) {
|
|
113
110
|
return false;
|
|
@@ -115,62 +112,61 @@
|
|
|
115
112
|
}
|
|
116
113
|
this.advance(i);
|
|
117
114
|
return true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
}
|
|
116
|
+
advanceWhileChar(condition) {
|
|
117
|
+
const posNow = this.position;
|
|
121
118
|
while (this.position < this.len && condition(this.source.charCodeAt(this.position))) {
|
|
122
119
|
this.position++;
|
|
123
120
|
}
|
|
124
121
|
return this.position - posNow;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
128
124
|
exports.MultiLineStream = MultiLineStream;
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
125
|
+
const _a = 'a'.charCodeAt(0);
|
|
126
|
+
const _f = 'f'.charCodeAt(0);
|
|
127
|
+
const _z = 'z'.charCodeAt(0);
|
|
128
|
+
const _u = 'u'.charCodeAt(0);
|
|
129
|
+
const _A = 'A'.charCodeAt(0);
|
|
130
|
+
const _F = 'F'.charCodeAt(0);
|
|
131
|
+
const _Z = 'Z'.charCodeAt(0);
|
|
132
|
+
const _0 = '0'.charCodeAt(0);
|
|
133
|
+
const _9 = '9'.charCodeAt(0);
|
|
134
|
+
const _TLD = '~'.charCodeAt(0);
|
|
135
|
+
const _HAT = '^'.charCodeAt(0);
|
|
136
|
+
const _EQS = '='.charCodeAt(0);
|
|
137
|
+
const _PIP = '|'.charCodeAt(0);
|
|
138
|
+
const _MIN = '-'.charCodeAt(0);
|
|
139
|
+
const _USC = '_'.charCodeAt(0);
|
|
140
|
+
const _PRC = '%'.charCodeAt(0);
|
|
141
|
+
const _MUL = '*'.charCodeAt(0);
|
|
142
|
+
const _LPA = '('.charCodeAt(0);
|
|
143
|
+
const _RPA = ')'.charCodeAt(0);
|
|
144
|
+
const _LAN = '<'.charCodeAt(0);
|
|
145
|
+
const _RAN = '>'.charCodeAt(0);
|
|
146
|
+
const _ATS = '@'.charCodeAt(0);
|
|
147
|
+
const _HSH = '#'.charCodeAt(0);
|
|
148
|
+
const _DLR = '$'.charCodeAt(0);
|
|
149
|
+
const _BSL = '\\'.charCodeAt(0);
|
|
150
|
+
const _FSL = '/'.charCodeAt(0);
|
|
151
|
+
const _NWL = '\n'.charCodeAt(0);
|
|
152
|
+
const _CAR = '\r'.charCodeAt(0);
|
|
153
|
+
const _LFD = '\f'.charCodeAt(0);
|
|
154
|
+
const _DQO = '"'.charCodeAt(0);
|
|
155
|
+
const _SQO = '\''.charCodeAt(0);
|
|
156
|
+
const _WSP = ' '.charCodeAt(0);
|
|
157
|
+
const _TAB = '\t'.charCodeAt(0);
|
|
158
|
+
const _SEM = ';'.charCodeAt(0);
|
|
159
|
+
const _COL = ':'.charCodeAt(0);
|
|
160
|
+
const _CUL = '{'.charCodeAt(0);
|
|
161
|
+
const _CUR = '}'.charCodeAt(0);
|
|
162
|
+
const _BRL = '['.charCodeAt(0);
|
|
163
|
+
const _BRR = ']'.charCodeAt(0);
|
|
164
|
+
const _CMA = ','.charCodeAt(0);
|
|
165
|
+
const _DOT = '.'.charCodeAt(0);
|
|
166
|
+
const _BNG = '!'.charCodeAt(0);
|
|
167
|
+
const _QSM = '?'.charCodeAt(0);
|
|
168
|
+
const _PLS = '+'.charCodeAt(0);
|
|
169
|
+
const staticTokenTable = {};
|
|
174
170
|
staticTokenTable[_SEM] = TokenType.SemiColon;
|
|
175
171
|
staticTokenTable[_COL] = TokenType.Colon;
|
|
176
172
|
staticTokenTable[_CUL] = TokenType.CurlyL;
|
|
@@ -180,7 +176,7 @@
|
|
|
180
176
|
staticTokenTable[_LPA] = TokenType.ParenthesisL;
|
|
181
177
|
staticTokenTable[_RPA] = TokenType.ParenthesisR;
|
|
182
178
|
staticTokenTable[_CMA] = TokenType.Comma;
|
|
183
|
-
|
|
179
|
+
const staticUnitTable = {};
|
|
184
180
|
staticUnitTable['em'] = TokenType.EMS;
|
|
185
181
|
staticUnitTable['ex'] = TokenType.EXS;
|
|
186
182
|
staticUnitTable['px'] = TokenType.Length;
|
|
@@ -200,68 +196,68 @@
|
|
|
200
196
|
staticUnitTable['fr'] = TokenType.Percentage;
|
|
201
197
|
staticUnitTable['dpi'] = TokenType.Resolution;
|
|
202
198
|
staticUnitTable['dpcm'] = TokenType.Resolution;
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
class Scanner {
|
|
200
|
+
constructor() {
|
|
205
201
|
this.stream = new MultiLineStream('');
|
|
206
202
|
this.ignoreComment = true;
|
|
207
203
|
this.ignoreWhitespace = true;
|
|
208
204
|
this.inURL = false;
|
|
209
205
|
}
|
|
210
|
-
|
|
206
|
+
setSource(input) {
|
|
211
207
|
this.stream = new MultiLineStream(input);
|
|
212
|
-
}
|
|
213
|
-
|
|
208
|
+
}
|
|
209
|
+
finishToken(offset, type, text) {
|
|
214
210
|
return {
|
|
215
211
|
offset: offset,
|
|
216
212
|
len: this.stream.pos() - offset,
|
|
217
213
|
type: type,
|
|
218
214
|
text: text || this.stream.substring(offset)
|
|
219
215
|
};
|
|
220
|
-
}
|
|
221
|
-
|
|
216
|
+
}
|
|
217
|
+
substring(offset, len) {
|
|
222
218
|
return this.stream.substring(offset, offset + len);
|
|
223
|
-
}
|
|
224
|
-
|
|
219
|
+
}
|
|
220
|
+
pos() {
|
|
225
221
|
return this.stream.pos();
|
|
226
|
-
}
|
|
227
|
-
|
|
222
|
+
}
|
|
223
|
+
goBackTo(pos) {
|
|
228
224
|
this.stream.goBackTo(pos);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
}
|
|
226
|
+
scanUnquotedString() {
|
|
227
|
+
const offset = this.stream.pos();
|
|
228
|
+
const content = [];
|
|
233
229
|
if (this._unquotedString(content)) {
|
|
234
230
|
return this.finishToken(offset, TokenType.UnquotedString, content.join(''));
|
|
235
231
|
}
|
|
236
232
|
return null;
|
|
237
|
-
}
|
|
238
|
-
|
|
233
|
+
}
|
|
234
|
+
scan() {
|
|
239
235
|
// processes all whitespaces and comments
|
|
240
|
-
|
|
236
|
+
const triviaToken = this.trivia();
|
|
241
237
|
if (triviaToken !== null) {
|
|
242
238
|
return triviaToken;
|
|
243
239
|
}
|
|
244
|
-
|
|
240
|
+
const offset = this.stream.pos();
|
|
245
241
|
// End of file/input
|
|
246
242
|
if (this.stream.eos()) {
|
|
247
243
|
return this.finishToken(offset, TokenType.EOF);
|
|
248
244
|
}
|
|
249
245
|
return this.scanNext(offset);
|
|
250
|
-
}
|
|
246
|
+
}
|
|
251
247
|
/**
|
|
252
248
|
* Read the range as described in https://www.w3.org/TR/CSS21/syndata.html#tokenization
|
|
253
249
|
* Assume the `u` has aleady been consumed
|
|
254
250
|
* @returns if reading the unicode was successful
|
|
255
251
|
*/
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
tryScanUnicode() {
|
|
253
|
+
const offset = this.stream.pos();
|
|
258
254
|
if (!this.stream.eos() && this._unicodeRange()) {
|
|
259
255
|
return this.finishToken(offset, TokenType.UnicodeRange);
|
|
260
256
|
}
|
|
261
257
|
this.stream.goBackTo(offset);
|
|
262
258
|
return undefined;
|
|
263
|
-
}
|
|
264
|
-
|
|
259
|
+
}
|
|
260
|
+
scanNext(offset) {
|
|
265
261
|
// CDO <!--
|
|
266
262
|
if (this.stream.advanceIfChars([_LAN, _BNG, _MIN, _MIN])) {
|
|
267
263
|
return this.finishToken(offset, TokenType.CDO);
|
|
@@ -270,7 +266,7 @@
|
|
|
270
266
|
if (this.stream.advanceIfChars([_MIN, _MIN, _RAN])) {
|
|
271
267
|
return this.finishToken(offset, TokenType.CDC);
|
|
272
268
|
}
|
|
273
|
-
|
|
269
|
+
let content = [];
|
|
274
270
|
if (this.ident(content)) {
|
|
275
271
|
return this.finishToken(offset, TokenType.Ident, content.join(''));
|
|
276
272
|
}
|
|
@@ -278,7 +274,7 @@
|
|
|
278
274
|
if (this.stream.advanceIfChar(_ATS)) {
|
|
279
275
|
content = ['@'];
|
|
280
276
|
if (this._name(content)) {
|
|
281
|
-
|
|
277
|
+
const keywordText = content.join('');
|
|
282
278
|
if (keywordText === '@charset') {
|
|
283
279
|
return this.finishToken(offset, TokenType.Charset, keywordText);
|
|
284
280
|
}
|
|
@@ -304,18 +300,18 @@
|
|
|
304
300
|
}
|
|
305
301
|
// Numbers
|
|
306
302
|
if (this._number()) {
|
|
307
|
-
|
|
303
|
+
const pos = this.stream.pos();
|
|
308
304
|
content = [this.stream.substring(offset, pos)];
|
|
309
305
|
if (this.stream.advanceIfChar(_PRC)) {
|
|
310
306
|
// Percentage 43%
|
|
311
307
|
return this.finishToken(offset, TokenType.Percentage);
|
|
312
308
|
}
|
|
313
309
|
else if (this.ident(content)) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (typeof
|
|
310
|
+
const dim = this.stream.substring(pos).toLowerCase();
|
|
311
|
+
const tokenType = staticUnitTable[dim];
|
|
312
|
+
if (typeof tokenType !== 'undefined') {
|
|
317
313
|
// Known dimension 43px
|
|
318
|
-
return this.finishToken(offset,
|
|
314
|
+
return this.finishToken(offset, tokenType, content.join(''));
|
|
319
315
|
}
|
|
320
316
|
else {
|
|
321
317
|
// Unknown dimension 43ft
|
|
@@ -326,7 +322,7 @@
|
|
|
326
322
|
}
|
|
327
323
|
// String, BadString
|
|
328
324
|
content = [];
|
|
329
|
-
|
|
325
|
+
let tokenType = this._string(content);
|
|
330
326
|
if (tokenType !== null) {
|
|
331
327
|
return this.finishToken(offset, tokenType, content.join(''));
|
|
332
328
|
}
|
|
@@ -364,10 +360,10 @@
|
|
|
364
360
|
// Delim
|
|
365
361
|
this.stream.nextChar();
|
|
366
362
|
return this.finishToken(offset, TokenType.Delim);
|
|
367
|
-
}
|
|
368
|
-
|
|
363
|
+
}
|
|
364
|
+
trivia() {
|
|
369
365
|
while (true) {
|
|
370
|
-
|
|
366
|
+
const offset = this.stream.pos();
|
|
371
367
|
if (this._whitespace()) {
|
|
372
368
|
if (!this.ignoreWhitespace) {
|
|
373
369
|
return this.finishToken(offset, TokenType.Whitespace);
|
|
@@ -382,42 +378,42 @@
|
|
|
382
378
|
return null;
|
|
383
379
|
}
|
|
384
380
|
}
|
|
385
|
-
}
|
|
386
|
-
|
|
381
|
+
}
|
|
382
|
+
comment() {
|
|
387
383
|
if (this.stream.advanceIfChars([_FSL, _MUL])) {
|
|
388
|
-
|
|
389
|
-
this.stream.advanceWhileChar(
|
|
390
|
-
if (
|
|
391
|
-
|
|
384
|
+
let success = false, hot = false;
|
|
385
|
+
this.stream.advanceWhileChar((ch) => {
|
|
386
|
+
if (hot && ch === _FSL) {
|
|
387
|
+
success = true;
|
|
392
388
|
return false;
|
|
393
389
|
}
|
|
394
|
-
|
|
390
|
+
hot = ch === _MUL;
|
|
395
391
|
return true;
|
|
396
392
|
});
|
|
397
|
-
if (
|
|
393
|
+
if (success) {
|
|
398
394
|
this.stream.advance(1);
|
|
399
395
|
}
|
|
400
396
|
return true;
|
|
401
397
|
}
|
|
402
398
|
return false;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
399
|
+
}
|
|
400
|
+
_number() {
|
|
401
|
+
let npeek = 0, ch;
|
|
406
402
|
if (this.stream.peekChar() === _DOT) {
|
|
407
403
|
npeek = 1;
|
|
408
404
|
}
|
|
409
405
|
ch = this.stream.peekChar(npeek);
|
|
410
406
|
if (ch >= _0 && ch <= _9) {
|
|
411
407
|
this.stream.advance(npeek + 1);
|
|
412
|
-
this.stream.advanceWhileChar(
|
|
408
|
+
this.stream.advanceWhileChar((ch) => {
|
|
413
409
|
return ch >= _0 && ch <= _9 || npeek === 0 && ch === _DOT;
|
|
414
410
|
});
|
|
415
411
|
return true;
|
|
416
412
|
}
|
|
417
413
|
return false;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
414
|
+
}
|
|
415
|
+
_newline(result) {
|
|
416
|
+
const ch = this.stream.peekChar();
|
|
421
417
|
switch (ch) {
|
|
422
418
|
case _CAR:
|
|
423
419
|
case _LFD:
|
|
@@ -430,13 +426,13 @@
|
|
|
430
426
|
return true;
|
|
431
427
|
}
|
|
432
428
|
return false;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
429
|
+
}
|
|
430
|
+
_escape(result, includeNewLines) {
|
|
431
|
+
let ch = this.stream.peekChar();
|
|
436
432
|
if (ch === _BSL) {
|
|
437
433
|
this.stream.advance(1);
|
|
438
434
|
ch = this.stream.peekChar();
|
|
439
|
-
|
|
435
|
+
let hexNumCount = 0;
|
|
440
436
|
while (hexNumCount < 6 && (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F)) {
|
|
441
437
|
this.stream.advance(1);
|
|
442
438
|
ch = this.stream.peekChar();
|
|
@@ -444,7 +440,7 @@
|
|
|
444
440
|
}
|
|
445
441
|
if (hexNumCount > 0) {
|
|
446
442
|
try {
|
|
447
|
-
|
|
443
|
+
const hexVal = parseInt(this.stream.substring(this.stream.pos() - hexNumCount), 16);
|
|
448
444
|
if (hexVal) {
|
|
449
445
|
result.push(String.fromCharCode(hexVal));
|
|
450
446
|
}
|
|
@@ -471,20 +467,20 @@
|
|
|
471
467
|
}
|
|
472
468
|
}
|
|
473
469
|
return false;
|
|
474
|
-
}
|
|
475
|
-
|
|
470
|
+
}
|
|
471
|
+
_stringChar(closeQuote, result) {
|
|
476
472
|
// not closeQuote, not backslash, not newline
|
|
477
|
-
|
|
473
|
+
const ch = this.stream.peekChar();
|
|
478
474
|
if (ch !== 0 && ch !== closeQuote && ch !== _BSL && ch !== _CAR && ch !== _LFD && ch !== _NWL) {
|
|
479
475
|
this.stream.advance(1);
|
|
480
476
|
result.push(String.fromCharCode(ch));
|
|
481
477
|
return true;
|
|
482
478
|
}
|
|
483
479
|
return false;
|
|
484
|
-
}
|
|
485
|
-
|
|
480
|
+
}
|
|
481
|
+
_string(result) {
|
|
486
482
|
if (this.stream.peekChar() === _SQO || this.stream.peekChar() === _DQO) {
|
|
487
|
-
|
|
483
|
+
const closeQuote = this.stream.nextChar();
|
|
488
484
|
result.push(String.fromCharCode(closeQuote));
|
|
489
485
|
while (this._stringChar(closeQuote, result) || this._escape(result, true)) {
|
|
490
486
|
// loop
|
|
@@ -499,40 +495,40 @@
|
|
|
499
495
|
}
|
|
500
496
|
}
|
|
501
497
|
return null;
|
|
502
|
-
}
|
|
503
|
-
|
|
498
|
+
}
|
|
499
|
+
_unquotedChar(result) {
|
|
504
500
|
// not closeQuote, not backslash, not newline
|
|
505
|
-
|
|
501
|
+
const ch = this.stream.peekChar();
|
|
506
502
|
if (ch !== 0 && ch !== _BSL && ch !== _SQO && ch !== _DQO && ch !== _LPA && ch !== _RPA && ch !== _WSP && ch !== _TAB && ch !== _NWL && ch !== _LFD && ch !== _CAR) {
|
|
507
503
|
this.stream.advance(1);
|
|
508
504
|
result.push(String.fromCharCode(ch));
|
|
509
505
|
return true;
|
|
510
506
|
}
|
|
511
507
|
return false;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
508
|
+
}
|
|
509
|
+
_unquotedString(result) {
|
|
510
|
+
let hasContent = false;
|
|
515
511
|
while (this._unquotedChar(result) || this._escape(result)) {
|
|
516
512
|
hasContent = true;
|
|
517
513
|
}
|
|
518
514
|
return hasContent;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
515
|
+
}
|
|
516
|
+
_whitespace() {
|
|
517
|
+
const n = this.stream.advanceWhileChar((ch) => {
|
|
522
518
|
return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR;
|
|
523
519
|
});
|
|
524
520
|
return n > 0;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
521
|
+
}
|
|
522
|
+
_name(result) {
|
|
523
|
+
let matched = false;
|
|
528
524
|
while (this._identChar(result) || this._escape(result)) {
|
|
529
525
|
matched = true;
|
|
530
526
|
}
|
|
531
527
|
return matched;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
528
|
+
}
|
|
529
|
+
ident(result) {
|
|
530
|
+
const pos = this.stream.pos();
|
|
531
|
+
const hasMinus = this._minus(result);
|
|
536
532
|
if (hasMinus) {
|
|
537
533
|
if (this._minus(result) /* -- */ || this._identFirstChar(result) || this._escape(result)) {
|
|
538
534
|
while (this._identChar(result) || this._escape(result)) {
|
|
@@ -549,9 +545,9 @@
|
|
|
549
545
|
}
|
|
550
546
|
this.stream.goBackTo(pos);
|
|
551
547
|
return false;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
|
|
548
|
+
}
|
|
549
|
+
_identFirstChar(result) {
|
|
550
|
+
const ch = this.stream.peekChar();
|
|
555
551
|
if (ch === _USC || // _
|
|
556
552
|
ch >= _a && ch <= _z || // a-z
|
|
557
553
|
ch >= _A && ch <= _Z || // A-Z
|
|
@@ -561,18 +557,18 @@
|
|
|
561
557
|
return true;
|
|
562
558
|
}
|
|
563
559
|
return false;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
560
|
+
}
|
|
561
|
+
_minus(result) {
|
|
562
|
+
const ch = this.stream.peekChar();
|
|
567
563
|
if (ch === _MIN) {
|
|
568
564
|
this.stream.advance(1);
|
|
569
565
|
result.push(String.fromCharCode(ch));
|
|
570
566
|
return true;
|
|
571
567
|
}
|
|
572
568
|
return false;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
569
|
+
}
|
|
570
|
+
_identChar(result) {
|
|
571
|
+
const ch = this.stream.peekChar();
|
|
576
572
|
if (ch === _USC || // _
|
|
577
573
|
ch === _MIN || // -
|
|
578
574
|
ch >= _a && ch <= _z || // a-z
|
|
@@ -584,16 +580,16 @@
|
|
|
584
580
|
return true;
|
|
585
581
|
}
|
|
586
582
|
return false;
|
|
587
|
-
}
|
|
588
|
-
|
|
583
|
+
}
|
|
584
|
+
_unicodeRange() {
|
|
589
585
|
// follow https://www.w3.org/TR/CSS21/syndata.html#tokenization and https://www.w3.org/TR/css-syntax-3/#urange-syntax
|
|
590
586
|
// assume u has already been parsed
|
|
591
587
|
if (this.stream.advanceIfChar(_PLS)) {
|
|
592
|
-
|
|
593
|
-
|
|
588
|
+
const isHexDigit = (ch) => (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F);
|
|
589
|
+
const codePoints = this.stream.advanceWhileChar(isHexDigit) + this.stream.advanceWhileChar(ch => ch === _QSM);
|
|
594
590
|
if (codePoints >= 1 && codePoints <= 6) {
|
|
595
591
|
if (this.stream.advanceIfChar(_MIN)) {
|
|
596
|
-
|
|
592
|
+
const digits = this.stream.advanceWhileChar(isHexDigit);
|
|
597
593
|
if (digits >= 1 && digits <= 6) {
|
|
598
594
|
return true;
|
|
599
595
|
}
|
|
@@ -604,8 +600,7 @@
|
|
|
604
600
|
}
|
|
605
601
|
}
|
|
606
602
|
return false;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
}());
|
|
603
|
+
}
|
|
604
|
+
}
|
|
610
605
|
exports.Scanner = Scanner;
|
|
611
606
|
});
|