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,818 +1,796 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
if (
|
|
67
|
-
node.
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (this.
|
|
85
|
-
node.
|
|
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
|
-
|| this.
|
|
120
|
-
|| this.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
if (
|
|
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
|
-
return
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
while (this.accept(TokenType.
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
this.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
this.consumeToken(); // @
|
|
346
|
-
node.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
this.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (!this.
|
|
431
|
-
return
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this.
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
if (!
|
|
541
|
-
return this.finish(node, ParseError.
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
this.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
return
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (!
|
|
677
|
-
return
|
|
678
|
-
}
|
|
679
|
-
if (this.
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
if (
|
|
743
|
-
return this.finish(node, ParseError.
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
if (this.
|
|
758
|
-
if (!this.
|
|
759
|
-
return this.finish(node, ParseError.
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
if (!this.
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
|
|
798
|
-
return this.finish(node, ParseError.SemiColonExpected);
|
|
799
|
-
}
|
|
800
|
-
return this.finish(node);
|
|
801
|
-
};
|
|
802
|
-
SCSSParser.prototype._parseForwardVisibility = function () {
|
|
803
|
-
var node = this.create(nodes.ForwardVisibility);
|
|
804
|
-
// Assume to be "hide" or "show".
|
|
805
|
-
node.setIdentifier(this._parseIdent());
|
|
806
|
-
while (node.addChild(this._parseVariable() || this._parseIdent())) {
|
|
807
|
-
// Consume all variables and idents ahead.
|
|
808
|
-
this.accept(TokenType.Comma);
|
|
809
|
-
}
|
|
810
|
-
// More than just identifier
|
|
811
|
-
return node.getChildren().length > 1 ? node : null;
|
|
812
|
-
};
|
|
813
|
-
SCSSParser.prototype._parseSupportsCondition = function () {
|
|
814
|
-
return this._parseInterpolation() || _super.prototype._parseSupportsCondition.call(this);
|
|
815
|
-
};
|
|
816
|
-
return SCSSParser;
|
|
817
|
-
}(cssParser.Parser));
|
|
818
|
-
export { SCSSParser };
|
|
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
|
+
import * as scssScanner from './scssScanner';
|
|
7
|
+
import { TokenType } from './cssScanner';
|
|
8
|
+
import * as cssParser from './cssParser';
|
|
9
|
+
import * as nodes from './cssNodes';
|
|
10
|
+
import { SCSSParseError } from './scssErrors';
|
|
11
|
+
import { ParseError } from './cssErrors';
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// A parser for scss
|
|
14
|
+
/// http://sass-lang.com/documentation/file.SASS_REFERENCE.html
|
|
15
|
+
/// </summary>
|
|
16
|
+
export class SCSSParser extends cssParser.Parser {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(new scssScanner.SCSSScanner());
|
|
19
|
+
}
|
|
20
|
+
_parseStylesheetStatement(isNested = false) {
|
|
21
|
+
if (this.peek(TokenType.AtKeyword)) {
|
|
22
|
+
return this._parseWarnAndDebug() // @warn, @debug and @error statements
|
|
23
|
+
|| this._parseControlStatement() // @if, @while, @for, @each
|
|
24
|
+
|| this._parseMixinDeclaration() // @mixin
|
|
25
|
+
|| this._parseMixinContent() // @content
|
|
26
|
+
|| this._parseMixinReference() // @include
|
|
27
|
+
|| this._parseFunctionDeclaration() // @function
|
|
28
|
+
|| this._parseForward() // @forward
|
|
29
|
+
|| this._parseUse() // @use
|
|
30
|
+
|| this._parseRuleset(isNested) // @at-rule
|
|
31
|
+
|| super._parseStylesheetAtStatement(isNested);
|
|
32
|
+
}
|
|
33
|
+
return this._parseRuleset(true) || this._parseVariableDeclaration();
|
|
34
|
+
}
|
|
35
|
+
_parseImport() {
|
|
36
|
+
if (!this.peekKeyword('@import')) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const node = this.create(nodes.Import);
|
|
40
|
+
this.consumeToken();
|
|
41
|
+
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
|
|
42
|
+
return this.finish(node, ParseError.URIOrStringExpected);
|
|
43
|
+
}
|
|
44
|
+
while (this.accept(TokenType.Comma)) {
|
|
45
|
+
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
|
|
46
|
+
return this.finish(node, ParseError.URIOrStringExpected);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!this.peek(TokenType.SemiColon) && !this.peek(TokenType.EOF)) {
|
|
50
|
+
node.setMedialist(this._parseMediaQueryList());
|
|
51
|
+
}
|
|
52
|
+
return this.finish(node);
|
|
53
|
+
}
|
|
54
|
+
// scss variables: $font-size: 12px;
|
|
55
|
+
_parseVariableDeclaration(panic = []) {
|
|
56
|
+
if (!this.peek(scssScanner.VariableName)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const node = this.create(nodes.VariableDeclaration);
|
|
60
|
+
if (!node.setVariable(this._parseVariable())) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!this.accept(TokenType.Colon)) {
|
|
64
|
+
return this.finish(node, ParseError.ColonExpected);
|
|
65
|
+
}
|
|
66
|
+
if (this.prevToken) {
|
|
67
|
+
node.colonPosition = this.prevToken.offset;
|
|
68
|
+
}
|
|
69
|
+
if (!node.setValue(this._parseExpr())) {
|
|
70
|
+
return this.finish(node, ParseError.VariableValueExpected, [], panic);
|
|
71
|
+
}
|
|
72
|
+
while (this.peek(TokenType.Exclamation)) {
|
|
73
|
+
if (node.addChild(this._tryParsePrio())) {
|
|
74
|
+
// !important
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.consumeToken();
|
|
78
|
+
if (!this.peekRegExp(TokenType.Ident, /^(default|global)$/)) {
|
|
79
|
+
return this.finish(node, ParseError.UnknownKeyword);
|
|
80
|
+
}
|
|
81
|
+
this.consumeToken();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.peek(TokenType.SemiColon)) {
|
|
85
|
+
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
86
|
+
}
|
|
87
|
+
return this.finish(node);
|
|
88
|
+
}
|
|
89
|
+
_parseMediaCondition() {
|
|
90
|
+
return this._parseInterpolation() || super._parseMediaCondition();
|
|
91
|
+
}
|
|
92
|
+
_parseMediaFeatureName() {
|
|
93
|
+
return this._parseModuleMember()
|
|
94
|
+
|| this._parseFunction() // function before ident
|
|
95
|
+
|| this._parseIdent()
|
|
96
|
+
|| this._parseVariable();
|
|
97
|
+
}
|
|
98
|
+
_parseKeyframeSelector() {
|
|
99
|
+
return this._tryParseKeyframeSelector()
|
|
100
|
+
|| this._parseControlStatement(this._parseKeyframeSelector.bind(this))
|
|
101
|
+
|| this._parseVariableDeclaration()
|
|
102
|
+
|| this._parseMixinContent();
|
|
103
|
+
}
|
|
104
|
+
_parseVariable() {
|
|
105
|
+
if (!this.peek(scssScanner.VariableName)) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const node = this.create(nodes.Variable);
|
|
109
|
+
this.consumeToken();
|
|
110
|
+
return node;
|
|
111
|
+
}
|
|
112
|
+
_parseModuleMember() {
|
|
113
|
+
const pos = this.mark();
|
|
114
|
+
const node = this.create(nodes.Module);
|
|
115
|
+
if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Module]))) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (this.hasWhitespace()
|
|
119
|
+
|| !this.acceptDelim('.')
|
|
120
|
+
|| this.hasWhitespace()) {
|
|
121
|
+
this.restoreAtMark(pos);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (!node.addChild(this._parseVariable() || this._parseFunction())) {
|
|
125
|
+
return this.finish(node, ParseError.IdentifierOrVariableExpected);
|
|
126
|
+
}
|
|
127
|
+
return node;
|
|
128
|
+
}
|
|
129
|
+
_parseIdent(referenceTypes) {
|
|
130
|
+
if (!this.peek(TokenType.Ident) && !this.peek(scssScanner.InterpolationFunction) && !this.peekDelim('-')) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const node = this.create(nodes.Identifier);
|
|
134
|
+
node.referenceTypes = referenceTypes;
|
|
135
|
+
node.isCustomProperty = this.peekRegExp(TokenType.Ident, /^--/);
|
|
136
|
+
let hasContent = false;
|
|
137
|
+
const indentInterpolation = () => {
|
|
138
|
+
const pos = this.mark();
|
|
139
|
+
if (this.acceptDelim('-')) {
|
|
140
|
+
if (!this.hasWhitespace()) {
|
|
141
|
+
this.acceptDelim('-');
|
|
142
|
+
}
|
|
143
|
+
if (this.hasWhitespace()) {
|
|
144
|
+
this.restoreAtMark(pos);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return this._parseInterpolation();
|
|
149
|
+
};
|
|
150
|
+
while (this.accept(TokenType.Ident) || node.addChild(indentInterpolation()) || (hasContent && this.acceptRegexp(/^[\w-]/))) {
|
|
151
|
+
hasContent = true;
|
|
152
|
+
if (this.hasWhitespace()) {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return hasContent ? this.finish(node) : null;
|
|
157
|
+
}
|
|
158
|
+
_parseTermExpression() {
|
|
159
|
+
return this._parseModuleMember() ||
|
|
160
|
+
this._parseVariable() ||
|
|
161
|
+
this._parseSelectorCombinator() ||
|
|
162
|
+
//this._tryParsePrio() ||
|
|
163
|
+
super._parseTermExpression();
|
|
164
|
+
}
|
|
165
|
+
_parseInterpolation() {
|
|
166
|
+
if (this.peek(scssScanner.InterpolationFunction)) {
|
|
167
|
+
const node = this.create(nodes.Interpolation);
|
|
168
|
+
this.consumeToken();
|
|
169
|
+
if (!node.addChild(this._parseExpr()) && !this._parseSelectorCombinator()) {
|
|
170
|
+
if (this.accept(TokenType.CurlyR)) {
|
|
171
|
+
return this.finish(node);
|
|
172
|
+
}
|
|
173
|
+
return this.finish(node, ParseError.ExpressionExpected);
|
|
174
|
+
}
|
|
175
|
+
if (!this.accept(TokenType.CurlyR)) {
|
|
176
|
+
return this.finish(node, ParseError.RightCurlyExpected);
|
|
177
|
+
}
|
|
178
|
+
return this.finish(node);
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
_parseOperator() {
|
|
183
|
+
if (this.peek(scssScanner.EqualsOperator) || this.peek(scssScanner.NotEqualsOperator)
|
|
184
|
+
|| this.peek(scssScanner.GreaterEqualsOperator) || this.peek(scssScanner.SmallerEqualsOperator)
|
|
185
|
+
|| this.peekDelim('>') || this.peekDelim('<')
|
|
186
|
+
|| this.peekIdent('and') || this.peekIdent('or')
|
|
187
|
+
|| this.peekDelim('%')) {
|
|
188
|
+
const node = this.createNode(nodes.NodeType.Operator);
|
|
189
|
+
this.consumeToken();
|
|
190
|
+
return this.finish(node);
|
|
191
|
+
}
|
|
192
|
+
return super._parseOperator();
|
|
193
|
+
}
|
|
194
|
+
_parseUnaryOperator() {
|
|
195
|
+
if (this.peekIdent('not')) {
|
|
196
|
+
const node = this.create(nodes.Node);
|
|
197
|
+
this.consumeToken();
|
|
198
|
+
return this.finish(node);
|
|
199
|
+
}
|
|
200
|
+
return super._parseUnaryOperator();
|
|
201
|
+
}
|
|
202
|
+
_parseRuleSetDeclaration() {
|
|
203
|
+
if (this.peek(TokenType.AtKeyword)) {
|
|
204
|
+
return this._parseKeyframe() // nested @keyframe
|
|
205
|
+
|| this._parseImport() // nested @import
|
|
206
|
+
|| this._parseMedia(true) // nested @media
|
|
207
|
+
|| this._parseFontFace() // nested @font-face
|
|
208
|
+
|| this._parseWarnAndDebug() // @warn, @debug and @error statements
|
|
209
|
+
|| this._parseControlStatement() // @if, @while, @for, @each
|
|
210
|
+
|| this._parseFunctionDeclaration() // @function
|
|
211
|
+
|| this._parseExtends() // @extends
|
|
212
|
+
|| this._parseMixinReference() // @include
|
|
213
|
+
|| this._parseMixinContent() // @content
|
|
214
|
+
|| this._parseMixinDeclaration() // nested @mixin
|
|
215
|
+
|| this._parseRuleset(true) // @at-rule
|
|
216
|
+
|| this._parseSupports(true) // @supports
|
|
217
|
+
|| super._parseRuleSetDeclarationAtStatement();
|
|
218
|
+
}
|
|
219
|
+
return this._parseVariableDeclaration() // variable declaration
|
|
220
|
+
|| this._tryParseRuleset(true) // nested ruleset
|
|
221
|
+
|| super._parseRuleSetDeclaration(); // try css ruleset declaration as last so in the error case, the ast will contain a declaration
|
|
222
|
+
}
|
|
223
|
+
_parseDeclaration(stopTokens) {
|
|
224
|
+
const custonProperty = this._tryParseCustomPropertyDeclaration(stopTokens);
|
|
225
|
+
if (custonProperty) {
|
|
226
|
+
return custonProperty;
|
|
227
|
+
}
|
|
228
|
+
const node = this.create(nodes.Declaration);
|
|
229
|
+
if (!node.setProperty(this._parseProperty())) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
if (!this.accept(TokenType.Colon)) {
|
|
233
|
+
return this.finish(node, ParseError.ColonExpected, [TokenType.Colon], stopTokens || [TokenType.SemiColon]);
|
|
234
|
+
}
|
|
235
|
+
if (this.prevToken) {
|
|
236
|
+
node.colonPosition = this.prevToken.offset;
|
|
237
|
+
}
|
|
238
|
+
let hasContent = false;
|
|
239
|
+
if (node.setValue(this._parseExpr())) {
|
|
240
|
+
hasContent = true;
|
|
241
|
+
node.addChild(this._parsePrio());
|
|
242
|
+
}
|
|
243
|
+
if (this.peek(TokenType.CurlyL)) {
|
|
244
|
+
node.setNestedProperties(this._parseNestedProperties());
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
if (!hasContent) {
|
|
248
|
+
return this.finish(node, ParseError.PropertyValueExpected);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (this.peek(TokenType.SemiColon)) {
|
|
252
|
+
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
253
|
+
}
|
|
254
|
+
return this.finish(node);
|
|
255
|
+
}
|
|
256
|
+
_parseNestedProperties() {
|
|
257
|
+
const node = this.create(nodes.NestedProperties);
|
|
258
|
+
return this._parseBody(node, this._parseDeclaration.bind(this));
|
|
259
|
+
}
|
|
260
|
+
_parseExtends() {
|
|
261
|
+
if (this.peekKeyword('@extend')) {
|
|
262
|
+
const node = this.create(nodes.ExtendsReference);
|
|
263
|
+
this.consumeToken();
|
|
264
|
+
if (!node.getSelectors().addChild(this._parseSimpleSelector())) {
|
|
265
|
+
return this.finish(node, ParseError.SelectorExpected);
|
|
266
|
+
}
|
|
267
|
+
while (this.accept(TokenType.Comma)) {
|
|
268
|
+
node.getSelectors().addChild(this._parseSimpleSelector());
|
|
269
|
+
}
|
|
270
|
+
if (this.accept(TokenType.Exclamation)) {
|
|
271
|
+
if (!this.acceptIdent('optional')) {
|
|
272
|
+
return this.finish(node, ParseError.UnknownKeyword);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return this.finish(node);
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
_parseSimpleSelectorBody() {
|
|
280
|
+
return this._parseSelectorCombinator() || this._parseSelectorPlaceholder() || super._parseSimpleSelectorBody();
|
|
281
|
+
}
|
|
282
|
+
_parseSelectorCombinator() {
|
|
283
|
+
if (this.peekDelim('&')) {
|
|
284
|
+
const node = this.createNode(nodes.NodeType.SelectorCombinator);
|
|
285
|
+
this.consumeToken();
|
|
286
|
+
while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(TokenType.Num) || this.accept(TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) {
|
|
287
|
+
// support &-foo-1
|
|
288
|
+
}
|
|
289
|
+
return this.finish(node);
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
_parseSelectorPlaceholder() {
|
|
294
|
+
if (this.peekDelim('%')) {
|
|
295
|
+
const node = this.createNode(nodes.NodeType.SelectorPlaceholder);
|
|
296
|
+
this.consumeToken();
|
|
297
|
+
this._parseIdent();
|
|
298
|
+
return this.finish(node);
|
|
299
|
+
}
|
|
300
|
+
else if (this.peekKeyword('@at-root')) {
|
|
301
|
+
const node = this.createNode(nodes.NodeType.SelectorPlaceholder);
|
|
302
|
+
this.consumeToken();
|
|
303
|
+
return this.finish(node);
|
|
304
|
+
}
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
_parseElementName() {
|
|
308
|
+
const pos = this.mark();
|
|
309
|
+
const node = super._parseElementName();
|
|
310
|
+
if (node && !this.hasWhitespace() && this.peek(TokenType.ParenthesisL)) { // for #49589
|
|
311
|
+
this.restoreAtMark(pos);
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
return node;
|
|
315
|
+
}
|
|
316
|
+
_tryParsePseudoIdentifier() {
|
|
317
|
+
return this._parseInterpolation() || super._tryParsePseudoIdentifier(); // for #49589
|
|
318
|
+
}
|
|
319
|
+
_parseWarnAndDebug() {
|
|
320
|
+
if (!this.peekKeyword('@debug')
|
|
321
|
+
&& !this.peekKeyword('@warn')
|
|
322
|
+
&& !this.peekKeyword('@error')) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
const node = this.createNode(nodes.NodeType.Debug);
|
|
326
|
+
this.consumeToken(); // @debug, @warn or @error
|
|
327
|
+
node.addChild(this._parseExpr()); // optional
|
|
328
|
+
return this.finish(node);
|
|
329
|
+
}
|
|
330
|
+
_parseControlStatement(parseStatement = this._parseRuleSetDeclaration.bind(this)) {
|
|
331
|
+
if (!this.peek(TokenType.AtKeyword)) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
return this._parseIfStatement(parseStatement) || this._parseForStatement(parseStatement)
|
|
335
|
+
|| this._parseEachStatement(parseStatement) || this._parseWhileStatement(parseStatement);
|
|
336
|
+
}
|
|
337
|
+
_parseIfStatement(parseStatement) {
|
|
338
|
+
if (!this.peekKeyword('@if')) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
return this._internalParseIfStatement(parseStatement);
|
|
342
|
+
}
|
|
343
|
+
_internalParseIfStatement(parseStatement) {
|
|
344
|
+
const node = this.create(nodes.IfStatement);
|
|
345
|
+
this.consumeToken(); // @if or if
|
|
346
|
+
if (!node.setExpression(this._parseExpr(true))) {
|
|
347
|
+
return this.finish(node, ParseError.ExpressionExpected);
|
|
348
|
+
}
|
|
349
|
+
this._parseBody(node, parseStatement);
|
|
350
|
+
if (this.acceptKeyword('@else')) {
|
|
351
|
+
if (this.peekIdent('if')) {
|
|
352
|
+
node.setElseClause(this._internalParseIfStatement(parseStatement));
|
|
353
|
+
}
|
|
354
|
+
else if (this.peek(TokenType.CurlyL)) {
|
|
355
|
+
const elseNode = this.create(nodes.ElseStatement);
|
|
356
|
+
this._parseBody(elseNode, parseStatement);
|
|
357
|
+
node.setElseClause(elseNode);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return this.finish(node);
|
|
361
|
+
}
|
|
362
|
+
_parseForStatement(parseStatement) {
|
|
363
|
+
if (!this.peekKeyword('@for')) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
const node = this.create(nodes.ForStatement);
|
|
367
|
+
this.consumeToken(); // @for
|
|
368
|
+
if (!node.setVariable(this._parseVariable())) {
|
|
369
|
+
return this.finish(node, ParseError.VariableNameExpected, [TokenType.CurlyR]);
|
|
370
|
+
}
|
|
371
|
+
if (!this.acceptIdent('from')) {
|
|
372
|
+
return this.finish(node, SCSSParseError.FromExpected, [TokenType.CurlyR]);
|
|
373
|
+
}
|
|
374
|
+
if (!node.addChild(this._parseBinaryExpr())) {
|
|
375
|
+
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
376
|
+
}
|
|
377
|
+
if (!this.acceptIdent('to') && !this.acceptIdent('through')) {
|
|
378
|
+
return this.finish(node, SCSSParseError.ThroughOrToExpected, [TokenType.CurlyR]);
|
|
379
|
+
}
|
|
380
|
+
if (!node.addChild(this._parseBinaryExpr())) {
|
|
381
|
+
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
382
|
+
}
|
|
383
|
+
return this._parseBody(node, parseStatement);
|
|
384
|
+
}
|
|
385
|
+
_parseEachStatement(parseStatement) {
|
|
386
|
+
if (!this.peekKeyword('@each')) {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
const node = this.create(nodes.EachStatement);
|
|
390
|
+
this.consumeToken(); // @each
|
|
391
|
+
const variables = node.getVariables();
|
|
392
|
+
if (!variables.addChild(this._parseVariable())) {
|
|
393
|
+
return this.finish(node, ParseError.VariableNameExpected, [TokenType.CurlyR]);
|
|
394
|
+
}
|
|
395
|
+
while (this.accept(TokenType.Comma)) {
|
|
396
|
+
if (!variables.addChild(this._parseVariable())) {
|
|
397
|
+
return this.finish(node, ParseError.VariableNameExpected, [TokenType.CurlyR]);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
this.finish(variables);
|
|
401
|
+
if (!this.acceptIdent('in')) {
|
|
402
|
+
return this.finish(node, SCSSParseError.InExpected, [TokenType.CurlyR]);
|
|
403
|
+
}
|
|
404
|
+
if (!node.addChild(this._parseExpr())) {
|
|
405
|
+
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
406
|
+
}
|
|
407
|
+
return this._parseBody(node, parseStatement);
|
|
408
|
+
}
|
|
409
|
+
_parseWhileStatement(parseStatement) {
|
|
410
|
+
if (!this.peekKeyword('@while')) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
const node = this.create(nodes.WhileStatement);
|
|
414
|
+
this.consumeToken(); // @while
|
|
415
|
+
if (!node.addChild(this._parseBinaryExpr())) {
|
|
416
|
+
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
417
|
+
}
|
|
418
|
+
return this._parseBody(node, parseStatement);
|
|
419
|
+
}
|
|
420
|
+
_parseFunctionBodyDeclaration() {
|
|
421
|
+
return this._parseVariableDeclaration() || this._parseReturnStatement() || this._parseWarnAndDebug()
|
|
422
|
+
|| this._parseControlStatement(this._parseFunctionBodyDeclaration.bind(this));
|
|
423
|
+
}
|
|
424
|
+
_parseFunctionDeclaration() {
|
|
425
|
+
if (!this.peekKeyword('@function')) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
const node = this.create(nodes.FunctionDeclaration);
|
|
429
|
+
this.consumeToken(); // @function
|
|
430
|
+
if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Function]))) {
|
|
431
|
+
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
432
|
+
}
|
|
433
|
+
if (!this.accept(TokenType.ParenthesisL)) {
|
|
434
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.CurlyR]);
|
|
435
|
+
}
|
|
436
|
+
if (node.getParameters().addChild(this._parseParameterDeclaration())) {
|
|
437
|
+
while (this.accept(TokenType.Comma)) {
|
|
438
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
if (!node.getParameters().addChild(this._parseParameterDeclaration())) {
|
|
442
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
447
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [TokenType.CurlyR]);
|
|
448
|
+
}
|
|
449
|
+
return this._parseBody(node, this._parseFunctionBodyDeclaration.bind(this));
|
|
450
|
+
}
|
|
451
|
+
_parseReturnStatement() {
|
|
452
|
+
if (!this.peekKeyword('@return')) {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
const node = this.createNode(nodes.NodeType.ReturnStatement);
|
|
456
|
+
this.consumeToken(); // @function
|
|
457
|
+
if (!node.addChild(this._parseExpr())) {
|
|
458
|
+
return this.finish(node, ParseError.ExpressionExpected);
|
|
459
|
+
}
|
|
460
|
+
return this.finish(node);
|
|
461
|
+
}
|
|
462
|
+
_parseMixinDeclaration() {
|
|
463
|
+
if (!this.peekKeyword('@mixin')) {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
const node = this.create(nodes.MixinDeclaration);
|
|
467
|
+
this.consumeToken();
|
|
468
|
+
if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Mixin]))) {
|
|
469
|
+
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
470
|
+
}
|
|
471
|
+
if (this.accept(TokenType.ParenthesisL)) {
|
|
472
|
+
if (node.getParameters().addChild(this._parseParameterDeclaration())) {
|
|
473
|
+
while (this.accept(TokenType.Comma)) {
|
|
474
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
if (!node.getParameters().addChild(this._parseParameterDeclaration())) {
|
|
478
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
483
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [TokenType.CurlyR]);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
487
|
+
}
|
|
488
|
+
_parseParameterDeclaration() {
|
|
489
|
+
const node = this.create(nodes.FunctionParameter);
|
|
490
|
+
if (!node.setIdentifier(this._parseVariable())) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
if (this.accept(scssScanner.Ellipsis)) {
|
|
494
|
+
// ok
|
|
495
|
+
}
|
|
496
|
+
if (this.accept(TokenType.Colon)) {
|
|
497
|
+
if (!node.setDefaultValue(this._parseExpr(true))) {
|
|
498
|
+
return this.finish(node, ParseError.VariableValueExpected, [], [TokenType.Comma, TokenType.ParenthesisR]);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return this.finish(node);
|
|
502
|
+
}
|
|
503
|
+
_parseMixinContent() {
|
|
504
|
+
if (!this.peekKeyword('@content')) {
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
const node = this.create(nodes.MixinContentReference);
|
|
508
|
+
this.consumeToken();
|
|
509
|
+
if (this.accept(TokenType.ParenthesisL)) {
|
|
510
|
+
if (node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
511
|
+
while (this.accept(TokenType.Comma)) {
|
|
512
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
if (!node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
516
|
+
return this.finish(node, ParseError.ExpressionExpected);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
521
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return this.finish(node);
|
|
525
|
+
}
|
|
526
|
+
_parseMixinReference() {
|
|
527
|
+
if (!this.peekKeyword('@include')) {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
const node = this.create(nodes.MixinReference);
|
|
531
|
+
this.consumeToken();
|
|
532
|
+
// Could be module or mixin identifier, set as mixin as default.
|
|
533
|
+
const firstIdent = this._parseIdent([nodes.ReferenceType.Mixin]);
|
|
534
|
+
if (!node.setIdentifier(firstIdent)) {
|
|
535
|
+
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
536
|
+
}
|
|
537
|
+
// Is a module accessor.
|
|
538
|
+
if (!this.hasWhitespace() && this.acceptDelim('.') && !this.hasWhitespace()) {
|
|
539
|
+
const secondIdent = this._parseIdent([nodes.ReferenceType.Mixin]);
|
|
540
|
+
if (!secondIdent) {
|
|
541
|
+
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
542
|
+
}
|
|
543
|
+
const moduleToken = this.create(nodes.Module);
|
|
544
|
+
// Re-purpose first matched ident as identifier for module token.
|
|
545
|
+
firstIdent.referenceTypes = [nodes.ReferenceType.Module];
|
|
546
|
+
moduleToken.setIdentifier(firstIdent);
|
|
547
|
+
// Override identifier with second ident.
|
|
548
|
+
node.setIdentifier(secondIdent);
|
|
549
|
+
node.addChild(moduleToken);
|
|
550
|
+
}
|
|
551
|
+
if (this.accept(TokenType.ParenthesisL)) {
|
|
552
|
+
if (node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
553
|
+
while (this.accept(TokenType.Comma)) {
|
|
554
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
if (!node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
558
|
+
return this.finish(node, ParseError.ExpressionExpected);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
563
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (this.peekIdent('using') || this.peek(TokenType.CurlyL)) {
|
|
567
|
+
node.setContent(this._parseMixinContentDeclaration());
|
|
568
|
+
}
|
|
569
|
+
return this.finish(node);
|
|
570
|
+
}
|
|
571
|
+
_parseMixinContentDeclaration() {
|
|
572
|
+
const node = this.create(nodes.MixinContentDeclaration);
|
|
573
|
+
if (this.acceptIdent('using')) {
|
|
574
|
+
if (!this.accept(TokenType.ParenthesisL)) {
|
|
575
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.CurlyL]);
|
|
576
|
+
}
|
|
577
|
+
if (node.getParameters().addChild(this._parseParameterDeclaration())) {
|
|
578
|
+
while (this.accept(TokenType.Comma)) {
|
|
579
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
if (!node.getParameters().addChild(this._parseParameterDeclaration())) {
|
|
583
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
588
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [TokenType.CurlyL]);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (this.peek(TokenType.CurlyL)) {
|
|
592
|
+
this._parseBody(node, this._parseMixinReferenceBodyStatement.bind(this));
|
|
593
|
+
}
|
|
594
|
+
return this.finish(node);
|
|
595
|
+
}
|
|
596
|
+
_parseMixinReferenceBodyStatement() {
|
|
597
|
+
return this._tryParseKeyframeSelector() || this._parseRuleSetDeclaration();
|
|
598
|
+
}
|
|
599
|
+
_parseFunctionArgument() {
|
|
600
|
+
// [variableName ':'] expression | variableName '...'
|
|
601
|
+
const node = this.create(nodes.FunctionArgument);
|
|
602
|
+
const pos = this.mark();
|
|
603
|
+
const argument = this._parseVariable();
|
|
604
|
+
if (argument) {
|
|
605
|
+
if (!this.accept(TokenType.Colon)) {
|
|
606
|
+
if (this.accept(scssScanner.Ellipsis)) { // optional
|
|
607
|
+
node.setValue(argument);
|
|
608
|
+
return this.finish(node);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
this.restoreAtMark(pos);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
node.setIdentifier(argument);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (node.setValue(this._parseExpr(true))) {
|
|
619
|
+
this.accept(scssScanner.Ellipsis); // #43746
|
|
620
|
+
node.addChild(this._parsePrio()); // #9859
|
|
621
|
+
return this.finish(node);
|
|
622
|
+
}
|
|
623
|
+
else if (node.setValue(this._tryParsePrio())) {
|
|
624
|
+
return this.finish(node);
|
|
625
|
+
}
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
_parseURLArgument() {
|
|
629
|
+
const pos = this.mark();
|
|
630
|
+
const node = super._parseURLArgument();
|
|
631
|
+
if (!node || !this.peek(TokenType.ParenthesisR)) {
|
|
632
|
+
this.restoreAtMark(pos);
|
|
633
|
+
const node = this.create(nodes.Node);
|
|
634
|
+
node.addChild(this._parseBinaryExpr());
|
|
635
|
+
return this.finish(node);
|
|
636
|
+
}
|
|
637
|
+
return node;
|
|
638
|
+
}
|
|
639
|
+
_parseOperation() {
|
|
640
|
+
if (!this.peek(TokenType.ParenthesisL)) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
const node = this.create(nodes.Node);
|
|
644
|
+
this.consumeToken();
|
|
645
|
+
while (node.addChild(this._parseListElement())) {
|
|
646
|
+
this.accept(TokenType.Comma); // optional
|
|
647
|
+
}
|
|
648
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
649
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
650
|
+
}
|
|
651
|
+
return this.finish(node);
|
|
652
|
+
}
|
|
653
|
+
_parseListElement() {
|
|
654
|
+
const node = this.create(nodes.ListEntry);
|
|
655
|
+
const child = this._parseBinaryExpr();
|
|
656
|
+
if (!child) {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
if (this.accept(TokenType.Colon)) {
|
|
660
|
+
node.setKey(child);
|
|
661
|
+
if (!node.setValue(this._parseBinaryExpr())) {
|
|
662
|
+
return this.finish(node, ParseError.ExpressionExpected);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
node.setValue(child);
|
|
667
|
+
}
|
|
668
|
+
return this.finish(node);
|
|
669
|
+
}
|
|
670
|
+
_parseUse() {
|
|
671
|
+
if (!this.peekKeyword('@use')) {
|
|
672
|
+
return null;
|
|
673
|
+
}
|
|
674
|
+
const node = this.create(nodes.Use);
|
|
675
|
+
this.consumeToken(); // @use
|
|
676
|
+
if (!node.addChild(this._parseStringLiteral())) {
|
|
677
|
+
return this.finish(node, ParseError.StringLiteralExpected);
|
|
678
|
+
}
|
|
679
|
+
if (!this.peek(TokenType.SemiColon) && !this.peek(TokenType.EOF)) {
|
|
680
|
+
if (!this.peekRegExp(TokenType.Ident, /as|with/)) {
|
|
681
|
+
return this.finish(node, ParseError.UnknownKeyword);
|
|
682
|
+
}
|
|
683
|
+
if (this.acceptIdent('as') &&
|
|
684
|
+
(!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Module])) && !this.acceptDelim('*'))) {
|
|
685
|
+
return this.finish(node, ParseError.IdentifierOrWildcardExpected);
|
|
686
|
+
}
|
|
687
|
+
if (this.acceptIdent('with')) {
|
|
688
|
+
if (!this.accept(TokenType.ParenthesisL)) {
|
|
689
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.ParenthesisR]);
|
|
690
|
+
}
|
|
691
|
+
// First variable statement, no comma.
|
|
692
|
+
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
|
|
693
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
694
|
+
}
|
|
695
|
+
while (this.accept(TokenType.Comma)) {
|
|
696
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
|
|
700
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
704
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
|
|
709
|
+
return this.finish(node, ParseError.SemiColonExpected);
|
|
710
|
+
}
|
|
711
|
+
return this.finish(node);
|
|
712
|
+
}
|
|
713
|
+
_parseModuleConfigDeclaration() {
|
|
714
|
+
const node = this.create(nodes.ModuleConfiguration);
|
|
715
|
+
if (!node.setIdentifier(this._parseVariable())) {
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
if (!this.accept(TokenType.Colon) || !node.setValue(this._parseExpr(true))) {
|
|
719
|
+
return this.finish(node, ParseError.VariableValueExpected, [], [TokenType.Comma, TokenType.ParenthesisR]);
|
|
720
|
+
}
|
|
721
|
+
if (this.accept(TokenType.Exclamation)) {
|
|
722
|
+
if (this.hasWhitespace() || !this.acceptIdent('default')) {
|
|
723
|
+
return this.finish(node, ParseError.UnknownKeyword);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return this.finish(node);
|
|
727
|
+
}
|
|
728
|
+
_parseForward() {
|
|
729
|
+
if (!this.peekKeyword('@forward')) {
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
const node = this.create(nodes.Forward);
|
|
733
|
+
this.consumeToken();
|
|
734
|
+
if (!node.addChild(this._parseStringLiteral())) {
|
|
735
|
+
return this.finish(node, ParseError.StringLiteralExpected);
|
|
736
|
+
}
|
|
737
|
+
if (this.acceptIdent('with')) {
|
|
738
|
+
if (!this.accept(TokenType.ParenthesisL)) {
|
|
739
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.ParenthesisR]);
|
|
740
|
+
}
|
|
741
|
+
// First variable statement, no comma.
|
|
742
|
+
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
|
|
743
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
744
|
+
}
|
|
745
|
+
while (this.accept(TokenType.Comma)) {
|
|
746
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
747
|
+
break;
|
|
748
|
+
}
|
|
749
|
+
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
|
|
750
|
+
return this.finish(node, ParseError.VariableNameExpected);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
754
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (!this.peek(TokenType.SemiColon) && !this.peek(TokenType.EOF)) {
|
|
758
|
+
if (!this.peekRegExp(TokenType.Ident, /as|hide|show/)) {
|
|
759
|
+
return this.finish(node, ParseError.UnknownKeyword);
|
|
760
|
+
}
|
|
761
|
+
if (this.acceptIdent('as')) {
|
|
762
|
+
const identifier = this._parseIdent([nodes.ReferenceType.Forward]);
|
|
763
|
+
if (!node.setIdentifier(identifier)) {
|
|
764
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
765
|
+
}
|
|
766
|
+
// Wildcard must be the next character after the identifier string.
|
|
767
|
+
if (this.hasWhitespace() || !this.acceptDelim('*')) {
|
|
768
|
+
return this.finish(node, ParseError.WildcardExpected);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (this.peekIdent('hide') || this.peekIdent('show')) {
|
|
772
|
+
if (!node.addChild(this._parseForwardVisibility())) {
|
|
773
|
+
return this.finish(node, ParseError.IdentifierOrVariableExpected);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
|
|
778
|
+
return this.finish(node, ParseError.SemiColonExpected);
|
|
779
|
+
}
|
|
780
|
+
return this.finish(node);
|
|
781
|
+
}
|
|
782
|
+
_parseForwardVisibility() {
|
|
783
|
+
const node = this.create(nodes.ForwardVisibility);
|
|
784
|
+
// Assume to be "hide" or "show".
|
|
785
|
+
node.setIdentifier(this._parseIdent());
|
|
786
|
+
while (node.addChild(this._parseVariable() || this._parseIdent())) {
|
|
787
|
+
// Consume all variables and idents ahead.
|
|
788
|
+
this.accept(TokenType.Comma);
|
|
789
|
+
}
|
|
790
|
+
// More than just identifier
|
|
791
|
+
return node.getChildren().length > 1 ? node : null;
|
|
792
|
+
}
|
|
793
|
+
_parseSupportsCondition() {
|
|
794
|
+
return this._parseInterpolation() || super._parseSupportsCondition();
|
|
795
|
+
}
|
|
796
|
+
}
|