vscode-css-languageservice 5.4.1 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/README.md +1 -0
- package/lib/esm/beautify/beautify-css.js +50 -8
- package/lib/esm/cssLanguageService.d.ts +37 -37
- package/lib/esm/cssLanguageService.js +72 -75
- package/lib/esm/cssLanguageTypes.d.ts +238 -238
- package/lib/esm/cssLanguageTypes.js +42 -42
- package/lib/esm/data/webCustomData.js +21959 -21965
- 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 -136
- 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 +50 -8
- package/lib/umd/cssLanguageService.d.ts +37 -37
- package/lib/umd/cssLanguageService.js +99 -102
- package/lib/umd/cssLanguageTypes.d.ts +238 -238
- package/lib/umd/cssLanguageTypes.js +89 -88
- package/lib/umd/data/webCustomData.js +21972 -21978
- 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 -150
- 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,1566 +1,1534 @@
|
|
|
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
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
this.
|
|
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
|
-
this.
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
this.
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
case nodes.NodeType.
|
|
337
|
-
case nodes.NodeType.
|
|
338
|
-
case nodes.NodeType.
|
|
339
|
-
|
|
340
|
-
case nodes.NodeType.
|
|
341
|
-
|
|
342
|
-
case nodes.NodeType.
|
|
343
|
-
|
|
344
|
-
case nodes.NodeType.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
node.
|
|
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
|
-
break;
|
|
515
|
-
case TokenType.
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
break;
|
|
538
|
-
case TokenType.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
if (!
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
this.
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
if (!this.
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
this.
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
if (!this.
|
|
669
|
-
return null;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
-
this.
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
return this.
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
//
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
this.
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
return this._parseBody(node, this.
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
return this.finish(node);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
break;
|
|
1068
|
-
case TokenType.
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
this.
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
this.
|
|
1126
|
-
this.
|
|
1127
|
-
this.
|
|
1128
|
-
this.
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
return
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
this.
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
return
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
this.
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
this.
|
|
1319
|
-
if (
|
|
1320
|
-
return
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
this.
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return this.
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
node = this.
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
this.
|
|
1420
|
-
this.
|
|
1421
|
-
this.
|
|
1422
|
-
this.
|
|
1423
|
-
this.
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
this.
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
this.
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
this.
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
this.
|
|
1477
|
-
this.
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
if (!this.accept(TokenType.
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
return
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
return null;
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
if (this.acceptIdent('progid')) {
|
|
1536
|
-
// support for IE7 specific filters: 'progid:DXImageTransform.Microsoft.MotionBlur(strength=13, direction=310)'
|
|
1537
|
-
if (this.accept(TokenType.Colon)) {
|
|
1538
|
-
while (this.accept(TokenType.Ident) && this.acceptDelim('.')) {
|
|
1539
|
-
// loop
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
return this.finish(node);
|
|
1543
|
-
}
|
|
1544
|
-
this.consumeToken();
|
|
1545
|
-
return this.finish(node);
|
|
1546
|
-
};
|
|
1547
|
-
Parser.prototype._parseFunctionArgument = function () {
|
|
1548
|
-
var node = this.create(nodes.FunctionArgument);
|
|
1549
|
-
if (node.setValue(this._parseExpr(true))) {
|
|
1550
|
-
return this.finish(node);
|
|
1551
|
-
}
|
|
1552
|
-
return null;
|
|
1553
|
-
};
|
|
1554
|
-
Parser.prototype._parseHexColor = function () {
|
|
1555
|
-
if (this.peekRegExp(TokenType.Hash, /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/g)) {
|
|
1556
|
-
var node = this.create(nodes.HexColorValue);
|
|
1557
|
-
this.consumeToken();
|
|
1558
|
-
return this.finish(node);
|
|
1559
|
-
}
|
|
1560
|
-
else {
|
|
1561
|
-
return null;
|
|
1562
|
-
}
|
|
1563
|
-
};
|
|
1564
|
-
return Parser;
|
|
1565
|
-
}());
|
|
1566
|
-
export { Parser };
|
|
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 { TokenType, Scanner } from './cssScanner';
|
|
7
|
+
import * as nodes from './cssNodes';
|
|
8
|
+
import { ParseError } from './cssErrors';
|
|
9
|
+
import * as languageFacts from '../languageFacts/facts';
|
|
10
|
+
import { isDefined } from '../utils/objects';
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// A parser for the css core specification. See for reference:
|
|
13
|
+
/// https://www.w3.org/TR/CSS21/grammar.html
|
|
14
|
+
/// http://www.w3.org/TR/CSS21/syndata.html#tokenization
|
|
15
|
+
/// </summary>
|
|
16
|
+
export class Parser {
|
|
17
|
+
constructor(scnr = new Scanner()) {
|
|
18
|
+
this.keyframeRegex = /^@(\-(webkit|ms|moz|o)\-)?keyframes$/i;
|
|
19
|
+
this.scanner = scnr;
|
|
20
|
+
this.token = { type: TokenType.EOF, offset: -1, len: 0, text: '' };
|
|
21
|
+
this.prevToken = undefined;
|
|
22
|
+
}
|
|
23
|
+
peekIdent(text) {
|
|
24
|
+
return TokenType.Ident === this.token.type && text.length === this.token.text.length && text === this.token.text.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
peekKeyword(text) {
|
|
27
|
+
return TokenType.AtKeyword === this.token.type && text.length === this.token.text.length && text === this.token.text.toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
peekDelim(text) {
|
|
30
|
+
return TokenType.Delim === this.token.type && text === this.token.text;
|
|
31
|
+
}
|
|
32
|
+
peek(type) {
|
|
33
|
+
return type === this.token.type;
|
|
34
|
+
}
|
|
35
|
+
peekOne(...types) {
|
|
36
|
+
return types.indexOf(this.token.type) !== -1;
|
|
37
|
+
}
|
|
38
|
+
peekRegExp(type, regEx) {
|
|
39
|
+
if (type !== this.token.type) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return regEx.test(this.token.text);
|
|
43
|
+
}
|
|
44
|
+
hasWhitespace() {
|
|
45
|
+
return !!this.prevToken && (this.prevToken.offset + this.prevToken.len !== this.token.offset);
|
|
46
|
+
}
|
|
47
|
+
consumeToken() {
|
|
48
|
+
this.prevToken = this.token;
|
|
49
|
+
this.token = this.scanner.scan();
|
|
50
|
+
}
|
|
51
|
+
acceptUnicodeRange() {
|
|
52
|
+
const token = this.scanner.tryScanUnicode();
|
|
53
|
+
if (token) {
|
|
54
|
+
this.prevToken = token;
|
|
55
|
+
this.token = this.scanner.scan();
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
mark() {
|
|
61
|
+
return {
|
|
62
|
+
prev: this.prevToken,
|
|
63
|
+
curr: this.token,
|
|
64
|
+
pos: this.scanner.pos()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
restoreAtMark(mark) {
|
|
68
|
+
this.prevToken = mark.prev;
|
|
69
|
+
this.token = mark.curr;
|
|
70
|
+
this.scanner.goBackTo(mark.pos);
|
|
71
|
+
}
|
|
72
|
+
try(func) {
|
|
73
|
+
const pos = this.mark();
|
|
74
|
+
const node = func();
|
|
75
|
+
if (!node) {
|
|
76
|
+
this.restoreAtMark(pos);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
acceptOneKeyword(keywords) {
|
|
82
|
+
if (TokenType.AtKeyword === this.token.type) {
|
|
83
|
+
for (const keyword of keywords) {
|
|
84
|
+
if (keyword.length === this.token.text.length && keyword === this.token.text.toLowerCase()) {
|
|
85
|
+
this.consumeToken();
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
accept(type) {
|
|
93
|
+
if (type === this.token.type) {
|
|
94
|
+
this.consumeToken();
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
acceptIdent(text) {
|
|
100
|
+
if (this.peekIdent(text)) {
|
|
101
|
+
this.consumeToken();
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
acceptKeyword(text) {
|
|
107
|
+
if (this.peekKeyword(text)) {
|
|
108
|
+
this.consumeToken();
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
acceptDelim(text) {
|
|
114
|
+
if (this.peekDelim(text)) {
|
|
115
|
+
this.consumeToken();
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
acceptRegexp(regEx) {
|
|
121
|
+
if (regEx.test(this.token.text)) {
|
|
122
|
+
this.consumeToken();
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
_parseRegexp(regEx) {
|
|
128
|
+
let node = this.createNode(nodes.NodeType.Identifier);
|
|
129
|
+
do { } while (this.acceptRegexp(regEx));
|
|
130
|
+
return this.finish(node);
|
|
131
|
+
}
|
|
132
|
+
acceptUnquotedString() {
|
|
133
|
+
const pos = this.scanner.pos();
|
|
134
|
+
this.scanner.goBackTo(this.token.offset);
|
|
135
|
+
const unquoted = this.scanner.scanUnquotedString();
|
|
136
|
+
if (unquoted) {
|
|
137
|
+
this.token = unquoted;
|
|
138
|
+
this.consumeToken();
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
this.scanner.goBackTo(pos);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
resync(resyncTokens, resyncStopTokens) {
|
|
145
|
+
while (true) {
|
|
146
|
+
if (resyncTokens && resyncTokens.indexOf(this.token.type) !== -1) {
|
|
147
|
+
this.consumeToken();
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
else if (resyncStopTokens && resyncStopTokens.indexOf(this.token.type) !== -1) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (this.token.type === TokenType.EOF) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
this.token = this.scanner.scan();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
createNode(nodeType) {
|
|
162
|
+
return new nodes.Node(this.token.offset, this.token.len, nodeType);
|
|
163
|
+
}
|
|
164
|
+
create(ctor) {
|
|
165
|
+
return new ctor(this.token.offset, this.token.len);
|
|
166
|
+
}
|
|
167
|
+
finish(node, error, resyncTokens, resyncStopTokens) {
|
|
168
|
+
// parseNumeric misuses error for boolean flagging (however the real error mustn't be a false)
|
|
169
|
+
// + nodelist offsets mustn't be modified, because there is a offset hack in rulesets for smartselection
|
|
170
|
+
if (!(node instanceof nodes.Nodelist)) {
|
|
171
|
+
if (error) {
|
|
172
|
+
this.markError(node, error, resyncTokens, resyncStopTokens);
|
|
173
|
+
}
|
|
174
|
+
// set the node end position
|
|
175
|
+
if (this.prevToken) {
|
|
176
|
+
// length with more elements belonging together
|
|
177
|
+
const prevEnd = this.prevToken.offset + this.prevToken.len;
|
|
178
|
+
node.length = prevEnd > node.offset ? prevEnd - node.offset : 0; // offset is taken from current token, end from previous: Use 0 for empty nodes
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return node;
|
|
182
|
+
}
|
|
183
|
+
markError(node, error, resyncTokens, resyncStopTokens) {
|
|
184
|
+
if (this.token !== this.lastErrorToken) { // do not report twice on the same token
|
|
185
|
+
node.addIssue(new nodes.Marker(node, error, nodes.Level.Error, undefined, this.token.offset, this.token.len));
|
|
186
|
+
this.lastErrorToken = this.token;
|
|
187
|
+
}
|
|
188
|
+
if (resyncTokens || resyncStopTokens) {
|
|
189
|
+
this.resync(resyncTokens, resyncStopTokens);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
parseStylesheet(textDocument) {
|
|
193
|
+
const versionId = textDocument.version;
|
|
194
|
+
const text = textDocument.getText();
|
|
195
|
+
const textProvider = (offset, length) => {
|
|
196
|
+
if (textDocument.version !== versionId) {
|
|
197
|
+
throw new Error('Underlying model has changed, AST is no longer valid');
|
|
198
|
+
}
|
|
199
|
+
return text.substr(offset, length);
|
|
200
|
+
};
|
|
201
|
+
return this.internalParse(text, this._parseStylesheet, textProvider);
|
|
202
|
+
}
|
|
203
|
+
internalParse(input, parseFunc, textProvider) {
|
|
204
|
+
this.scanner.setSource(input);
|
|
205
|
+
this.token = this.scanner.scan();
|
|
206
|
+
const node = parseFunc.bind(this)();
|
|
207
|
+
if (node) {
|
|
208
|
+
if (textProvider) {
|
|
209
|
+
node.textProvider = textProvider;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
node.textProvider = (offset, length) => { return input.substr(offset, length); };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return node;
|
|
216
|
+
}
|
|
217
|
+
_parseStylesheet() {
|
|
218
|
+
const node = this.create(nodes.Stylesheet);
|
|
219
|
+
while (node.addChild(this._parseStylesheetStart())) {
|
|
220
|
+
// Parse statements only valid at the beginning of stylesheets.
|
|
221
|
+
}
|
|
222
|
+
let inRecovery = false;
|
|
223
|
+
do {
|
|
224
|
+
let hasMatch = false;
|
|
225
|
+
do {
|
|
226
|
+
hasMatch = false;
|
|
227
|
+
const statement = this._parseStylesheetStatement();
|
|
228
|
+
if (statement) {
|
|
229
|
+
node.addChild(statement);
|
|
230
|
+
hasMatch = true;
|
|
231
|
+
inRecovery = false;
|
|
232
|
+
if (!this.peek(TokenType.EOF) && this._needsSemicolonAfter(statement) && !this.accept(TokenType.SemiColon)) {
|
|
233
|
+
this.markError(node, ParseError.SemiColonExpected);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
while (this.accept(TokenType.SemiColon) || this.accept(TokenType.CDO) || this.accept(TokenType.CDC)) {
|
|
237
|
+
// accept empty statements
|
|
238
|
+
hasMatch = true;
|
|
239
|
+
inRecovery = false;
|
|
240
|
+
}
|
|
241
|
+
} while (hasMatch);
|
|
242
|
+
if (this.peek(TokenType.EOF)) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
if (!inRecovery) {
|
|
246
|
+
if (this.peek(TokenType.AtKeyword)) {
|
|
247
|
+
this.markError(node, ParseError.UnknownAtRule);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.markError(node, ParseError.RuleOrSelectorExpected);
|
|
251
|
+
}
|
|
252
|
+
inRecovery = true;
|
|
253
|
+
}
|
|
254
|
+
this.consumeToken();
|
|
255
|
+
} while (!this.peek(TokenType.EOF));
|
|
256
|
+
return this.finish(node);
|
|
257
|
+
}
|
|
258
|
+
_parseStylesheetStart() {
|
|
259
|
+
return this._parseCharset();
|
|
260
|
+
}
|
|
261
|
+
_parseStylesheetStatement(isNested = false) {
|
|
262
|
+
if (this.peek(TokenType.AtKeyword)) {
|
|
263
|
+
return this._parseStylesheetAtStatement(isNested);
|
|
264
|
+
}
|
|
265
|
+
return this._parseRuleset(isNested);
|
|
266
|
+
}
|
|
267
|
+
_parseStylesheetAtStatement(isNested = false) {
|
|
268
|
+
return this._parseImport()
|
|
269
|
+
|| this._parseMedia(isNested)
|
|
270
|
+
|| this._parsePage()
|
|
271
|
+
|| this._parseFontFace()
|
|
272
|
+
|| this._parseKeyframe()
|
|
273
|
+
|| this._parseSupports(isNested)
|
|
274
|
+
|| this._parseViewPort()
|
|
275
|
+
|| this._parseNamespace()
|
|
276
|
+
|| this._parseDocument()
|
|
277
|
+
|| this._parseUnknownAtRule();
|
|
278
|
+
}
|
|
279
|
+
_tryParseRuleset(isNested) {
|
|
280
|
+
const mark = this.mark();
|
|
281
|
+
if (this._parseSelector(isNested)) {
|
|
282
|
+
while (this.accept(TokenType.Comma) && this._parseSelector(isNested)) {
|
|
283
|
+
// loop
|
|
284
|
+
}
|
|
285
|
+
if (this.accept(TokenType.CurlyL)) {
|
|
286
|
+
this.restoreAtMark(mark);
|
|
287
|
+
return this._parseRuleset(isNested);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
this.restoreAtMark(mark);
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
_parseRuleset(isNested = false) {
|
|
294
|
+
const node = this.create(nodes.RuleSet);
|
|
295
|
+
const selectors = node.getSelectors();
|
|
296
|
+
if (!selectors.addChild(this._parseSelector(isNested))) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
while (this.accept(TokenType.Comma)) {
|
|
300
|
+
if (!selectors.addChild(this._parseSelector(isNested))) {
|
|
301
|
+
return this.finish(node, ParseError.SelectorExpected);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
305
|
+
}
|
|
306
|
+
_parseRuleSetDeclarationAtStatement() {
|
|
307
|
+
return this._parseUnknownAtRule();
|
|
308
|
+
}
|
|
309
|
+
_parseRuleSetDeclaration() {
|
|
310
|
+
// https://www.w3.org/TR/css-syntax-3/#consume-a-list-of-declarations
|
|
311
|
+
if (this.peek(TokenType.AtKeyword)) {
|
|
312
|
+
return this._parseRuleSetDeclarationAtStatement();
|
|
313
|
+
}
|
|
314
|
+
return this._parseDeclaration();
|
|
315
|
+
}
|
|
316
|
+
_needsSemicolonAfter(node) {
|
|
317
|
+
switch (node.type) {
|
|
318
|
+
case nodes.NodeType.Keyframe:
|
|
319
|
+
case nodes.NodeType.ViewPort:
|
|
320
|
+
case nodes.NodeType.Media:
|
|
321
|
+
case nodes.NodeType.Ruleset:
|
|
322
|
+
case nodes.NodeType.Namespace:
|
|
323
|
+
case nodes.NodeType.If:
|
|
324
|
+
case nodes.NodeType.For:
|
|
325
|
+
case nodes.NodeType.Each:
|
|
326
|
+
case nodes.NodeType.While:
|
|
327
|
+
case nodes.NodeType.MixinDeclaration:
|
|
328
|
+
case nodes.NodeType.FunctionDeclaration:
|
|
329
|
+
case nodes.NodeType.MixinContentDeclaration:
|
|
330
|
+
return false;
|
|
331
|
+
case nodes.NodeType.ExtendsReference:
|
|
332
|
+
case nodes.NodeType.MixinContentReference:
|
|
333
|
+
case nodes.NodeType.ReturnStatement:
|
|
334
|
+
case nodes.NodeType.MediaQuery:
|
|
335
|
+
case nodes.NodeType.Debug:
|
|
336
|
+
case nodes.NodeType.Import:
|
|
337
|
+
case nodes.NodeType.AtApplyRule:
|
|
338
|
+
case nodes.NodeType.CustomPropertyDeclaration:
|
|
339
|
+
return true;
|
|
340
|
+
case nodes.NodeType.VariableDeclaration:
|
|
341
|
+
return node.needsSemicolon;
|
|
342
|
+
case nodes.NodeType.MixinReference:
|
|
343
|
+
return !node.getContent();
|
|
344
|
+
case nodes.NodeType.Declaration:
|
|
345
|
+
return !node.getNestedProperties();
|
|
346
|
+
}
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
_parseDeclarations(parseDeclaration) {
|
|
350
|
+
const node = this.create(nodes.Declarations);
|
|
351
|
+
if (!this.accept(TokenType.CurlyL)) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
let decl = parseDeclaration();
|
|
355
|
+
while (node.addChild(decl)) {
|
|
356
|
+
if (this.peek(TokenType.CurlyR)) {
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
if (this._needsSemicolonAfter(decl) && !this.accept(TokenType.SemiColon)) {
|
|
360
|
+
return this.finish(node, ParseError.SemiColonExpected, [TokenType.SemiColon, TokenType.CurlyR]);
|
|
361
|
+
}
|
|
362
|
+
// We accepted semicolon token. Link it to declaration.
|
|
363
|
+
if (decl && this.prevToken && this.prevToken.type === TokenType.SemiColon) {
|
|
364
|
+
decl.semicolonPosition = this.prevToken.offset;
|
|
365
|
+
}
|
|
366
|
+
while (this.accept(TokenType.SemiColon)) {
|
|
367
|
+
// accept empty statements
|
|
368
|
+
}
|
|
369
|
+
decl = parseDeclaration();
|
|
370
|
+
}
|
|
371
|
+
if (!this.accept(TokenType.CurlyR)) {
|
|
372
|
+
return this.finish(node, ParseError.RightCurlyExpected, [TokenType.CurlyR, TokenType.SemiColon]);
|
|
373
|
+
}
|
|
374
|
+
return this.finish(node);
|
|
375
|
+
}
|
|
376
|
+
_parseBody(node, parseDeclaration) {
|
|
377
|
+
if (!node.setDeclarations(this._parseDeclarations(parseDeclaration))) {
|
|
378
|
+
return this.finish(node, ParseError.LeftCurlyExpected, [TokenType.CurlyR, TokenType.SemiColon]);
|
|
379
|
+
}
|
|
380
|
+
return this.finish(node);
|
|
381
|
+
}
|
|
382
|
+
_parseSelector(isNested) {
|
|
383
|
+
const node = this.create(nodes.Selector);
|
|
384
|
+
let hasContent = false;
|
|
385
|
+
if (isNested) {
|
|
386
|
+
// nested selectors can start with a combinator
|
|
387
|
+
hasContent = node.addChild(this._parseCombinator());
|
|
388
|
+
}
|
|
389
|
+
while (node.addChild(this._parseSimpleSelector())) {
|
|
390
|
+
hasContent = true;
|
|
391
|
+
node.addChild(this._parseCombinator()); // optional
|
|
392
|
+
}
|
|
393
|
+
return hasContent ? this.finish(node) : null;
|
|
394
|
+
}
|
|
395
|
+
_parseDeclaration(stopTokens) {
|
|
396
|
+
const custonProperty = this._tryParseCustomPropertyDeclaration(stopTokens);
|
|
397
|
+
if (custonProperty) {
|
|
398
|
+
return custonProperty;
|
|
399
|
+
}
|
|
400
|
+
const node = this.create(nodes.Declaration);
|
|
401
|
+
if (!node.setProperty(this._parseProperty())) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (!this.accept(TokenType.Colon)) {
|
|
405
|
+
return this.finish(node, ParseError.ColonExpected, [TokenType.Colon], stopTokens || [TokenType.SemiColon]);
|
|
406
|
+
}
|
|
407
|
+
if (this.prevToken) {
|
|
408
|
+
node.colonPosition = this.prevToken.offset;
|
|
409
|
+
}
|
|
410
|
+
if (!node.setValue(this._parseExpr())) {
|
|
411
|
+
return this.finish(node, ParseError.PropertyValueExpected);
|
|
412
|
+
}
|
|
413
|
+
node.addChild(this._parsePrio());
|
|
414
|
+
if (this.peek(TokenType.SemiColon)) {
|
|
415
|
+
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
416
|
+
}
|
|
417
|
+
return this.finish(node);
|
|
418
|
+
}
|
|
419
|
+
_tryParseCustomPropertyDeclaration(stopTokens) {
|
|
420
|
+
if (!this.peekRegExp(TokenType.Ident, /^--/)) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
const node = this.create(nodes.CustomPropertyDeclaration);
|
|
424
|
+
if (!node.setProperty(this._parseProperty())) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
if (!this.accept(TokenType.Colon)) {
|
|
428
|
+
return this.finish(node, ParseError.ColonExpected, [TokenType.Colon]);
|
|
429
|
+
}
|
|
430
|
+
if (this.prevToken) {
|
|
431
|
+
node.colonPosition = this.prevToken.offset;
|
|
432
|
+
}
|
|
433
|
+
const mark = this.mark();
|
|
434
|
+
if (this.peek(TokenType.CurlyL)) {
|
|
435
|
+
// try to parse it as nested declaration
|
|
436
|
+
const propertySet = this.create(nodes.CustomPropertySet);
|
|
437
|
+
const declarations = this._parseDeclarations(this._parseRuleSetDeclaration.bind(this));
|
|
438
|
+
if (propertySet.setDeclarations(declarations) && !declarations.isErroneous(true)) {
|
|
439
|
+
propertySet.addChild(this._parsePrio());
|
|
440
|
+
if (this.peek(TokenType.SemiColon)) {
|
|
441
|
+
this.finish(propertySet);
|
|
442
|
+
node.setPropertySet(propertySet);
|
|
443
|
+
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
444
|
+
return this.finish(node);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
this.restoreAtMark(mark);
|
|
448
|
+
}
|
|
449
|
+
// try to parse as expression
|
|
450
|
+
const expression = this._parseExpr();
|
|
451
|
+
if (expression && !expression.isErroneous(true)) {
|
|
452
|
+
this._parsePrio();
|
|
453
|
+
if (this.peekOne(...(stopTokens || []), TokenType.SemiColon, TokenType.EOF)) {
|
|
454
|
+
node.setValue(expression);
|
|
455
|
+
if (this.peek(TokenType.SemiColon)) {
|
|
456
|
+
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
457
|
+
}
|
|
458
|
+
return this.finish(node);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
this.restoreAtMark(mark);
|
|
462
|
+
node.addChild(this._parseCustomPropertyValue(stopTokens));
|
|
463
|
+
node.addChild(this._parsePrio());
|
|
464
|
+
if (isDefined(node.colonPosition) && this.token.offset === node.colonPosition + 1) {
|
|
465
|
+
return this.finish(node, ParseError.PropertyValueExpected);
|
|
466
|
+
}
|
|
467
|
+
return this.finish(node);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Parse custom property values.
|
|
471
|
+
*
|
|
472
|
+
* Based on https://www.w3.org/TR/css-variables/#syntax
|
|
473
|
+
*
|
|
474
|
+
* This code is somewhat unusual, as the allowed syntax is incredibly broad,
|
|
475
|
+
* parsing almost any sequence of tokens, save for a small set of exceptions.
|
|
476
|
+
* Unbalanced delimitors, invalid tokens, and declaration
|
|
477
|
+
* terminators like semicolons and !important directives (when not inside
|
|
478
|
+
* of delimitors).
|
|
479
|
+
*/
|
|
480
|
+
_parseCustomPropertyValue(stopTokens = [TokenType.CurlyR]) {
|
|
481
|
+
const node = this.create(nodes.Node);
|
|
482
|
+
const isTopLevel = () => curlyDepth === 0 && parensDepth === 0 && bracketsDepth === 0;
|
|
483
|
+
const onStopToken = () => stopTokens.indexOf(this.token.type) !== -1;
|
|
484
|
+
let curlyDepth = 0;
|
|
485
|
+
let parensDepth = 0;
|
|
486
|
+
let bracketsDepth = 0;
|
|
487
|
+
done: while (true) {
|
|
488
|
+
switch (this.token.type) {
|
|
489
|
+
case TokenType.SemiColon:
|
|
490
|
+
// A semicolon only ends things if we're not inside a delimitor.
|
|
491
|
+
if (isTopLevel()) {
|
|
492
|
+
break done;
|
|
493
|
+
}
|
|
494
|
+
break;
|
|
495
|
+
case TokenType.Exclamation:
|
|
496
|
+
// An exclamation ends the value if we're not inside delims.
|
|
497
|
+
if (isTopLevel()) {
|
|
498
|
+
break done;
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
case TokenType.CurlyL:
|
|
502
|
+
curlyDepth++;
|
|
503
|
+
break;
|
|
504
|
+
case TokenType.CurlyR:
|
|
505
|
+
curlyDepth--;
|
|
506
|
+
if (curlyDepth < 0) {
|
|
507
|
+
// The property value has been terminated without a semicolon, and
|
|
508
|
+
// this is the last declaration in the ruleset.
|
|
509
|
+
if (onStopToken() && parensDepth === 0 && bracketsDepth === 0) {
|
|
510
|
+
break done;
|
|
511
|
+
}
|
|
512
|
+
return this.finish(node, ParseError.LeftCurlyExpected);
|
|
513
|
+
}
|
|
514
|
+
break;
|
|
515
|
+
case TokenType.ParenthesisL:
|
|
516
|
+
parensDepth++;
|
|
517
|
+
break;
|
|
518
|
+
case TokenType.ParenthesisR:
|
|
519
|
+
parensDepth--;
|
|
520
|
+
if (parensDepth < 0) {
|
|
521
|
+
if (onStopToken() && bracketsDepth === 0 && curlyDepth === 0) {
|
|
522
|
+
break done;
|
|
523
|
+
}
|
|
524
|
+
return this.finish(node, ParseError.LeftParenthesisExpected);
|
|
525
|
+
}
|
|
526
|
+
break;
|
|
527
|
+
case TokenType.BracketL:
|
|
528
|
+
bracketsDepth++;
|
|
529
|
+
break;
|
|
530
|
+
case TokenType.BracketR:
|
|
531
|
+
bracketsDepth--;
|
|
532
|
+
if (bracketsDepth < 0) {
|
|
533
|
+
return this.finish(node, ParseError.LeftSquareBracketExpected);
|
|
534
|
+
}
|
|
535
|
+
break;
|
|
536
|
+
case TokenType.BadString: // fall through
|
|
537
|
+
break done;
|
|
538
|
+
case TokenType.EOF:
|
|
539
|
+
// We shouldn't have reached the end of input, something is
|
|
540
|
+
// unterminated.
|
|
541
|
+
let error = ParseError.RightCurlyExpected;
|
|
542
|
+
if (bracketsDepth > 0) {
|
|
543
|
+
error = ParseError.RightSquareBracketExpected;
|
|
544
|
+
}
|
|
545
|
+
else if (parensDepth > 0) {
|
|
546
|
+
error = ParseError.RightParenthesisExpected;
|
|
547
|
+
}
|
|
548
|
+
return this.finish(node, error);
|
|
549
|
+
}
|
|
550
|
+
this.consumeToken();
|
|
551
|
+
}
|
|
552
|
+
return this.finish(node);
|
|
553
|
+
}
|
|
554
|
+
_tryToParseDeclaration(stopTokens) {
|
|
555
|
+
const mark = this.mark();
|
|
556
|
+
if (this._parseProperty() && this.accept(TokenType.Colon)) {
|
|
557
|
+
// looks like a declaration, go ahead
|
|
558
|
+
this.restoreAtMark(mark);
|
|
559
|
+
return this._parseDeclaration(stopTokens);
|
|
560
|
+
}
|
|
561
|
+
this.restoreAtMark(mark);
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
_parseProperty() {
|
|
565
|
+
const node = this.create(nodes.Property);
|
|
566
|
+
const mark = this.mark();
|
|
567
|
+
if (this.acceptDelim('*') || this.acceptDelim('_')) {
|
|
568
|
+
// support for IE 5.x, 6 and 7 star hack: see http://en.wikipedia.org/wiki/CSS_filter#Star_hack
|
|
569
|
+
if (this.hasWhitespace()) {
|
|
570
|
+
this.restoreAtMark(mark);
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (node.setIdentifier(this._parsePropertyIdentifier())) {
|
|
575
|
+
return this.finish(node);
|
|
576
|
+
}
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
_parsePropertyIdentifier() {
|
|
580
|
+
return this._parseIdent();
|
|
581
|
+
}
|
|
582
|
+
_parseCharset() {
|
|
583
|
+
if (!this.peek(TokenType.Charset)) {
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
const node = this.create(nodes.Node);
|
|
587
|
+
this.consumeToken(); // charset
|
|
588
|
+
if (!this.accept(TokenType.String)) {
|
|
589
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
590
|
+
}
|
|
591
|
+
if (!this.accept(TokenType.SemiColon)) {
|
|
592
|
+
return this.finish(node, ParseError.SemiColonExpected);
|
|
593
|
+
}
|
|
594
|
+
return this.finish(node);
|
|
595
|
+
}
|
|
596
|
+
_parseImport() {
|
|
597
|
+
if (!this.peekKeyword('@import')) {
|
|
598
|
+
return null;
|
|
599
|
+
}
|
|
600
|
+
const node = this.create(nodes.Import);
|
|
601
|
+
this.consumeToken(); // @import
|
|
602
|
+
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
|
|
603
|
+
return this.finish(node, ParseError.URIOrStringExpected);
|
|
604
|
+
}
|
|
605
|
+
if (!this.peek(TokenType.SemiColon) && !this.peek(TokenType.EOF)) {
|
|
606
|
+
node.setMedialist(this._parseMediaQueryList());
|
|
607
|
+
}
|
|
608
|
+
return this.finish(node);
|
|
609
|
+
}
|
|
610
|
+
_parseNamespace() {
|
|
611
|
+
// http://www.w3.org/TR/css3-namespace/
|
|
612
|
+
// namespace : NAMESPACE_SYM S* [IDENT S*]? [STRING|URI] S* ';' S*
|
|
613
|
+
if (!this.peekKeyword('@namespace')) {
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
const node = this.create(nodes.Namespace);
|
|
617
|
+
this.consumeToken(); // @namespace
|
|
618
|
+
if (!node.addChild(this._parseURILiteral())) { // url literal also starts with ident
|
|
619
|
+
node.addChild(this._parseIdent()); // optional prefix
|
|
620
|
+
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
|
|
621
|
+
return this.finish(node, ParseError.URIExpected, [TokenType.SemiColon]);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (!this.accept(TokenType.SemiColon)) {
|
|
625
|
+
return this.finish(node, ParseError.SemiColonExpected);
|
|
626
|
+
}
|
|
627
|
+
return this.finish(node);
|
|
628
|
+
}
|
|
629
|
+
_parseFontFace() {
|
|
630
|
+
if (!this.peekKeyword('@font-face')) {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
const node = this.create(nodes.FontFace);
|
|
634
|
+
this.consumeToken(); // @font-face
|
|
635
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
636
|
+
}
|
|
637
|
+
_parseViewPort() {
|
|
638
|
+
if (!this.peekKeyword('@-ms-viewport') &&
|
|
639
|
+
!this.peekKeyword('@-o-viewport') &&
|
|
640
|
+
!this.peekKeyword('@viewport')) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
const node = this.create(nodes.ViewPort);
|
|
644
|
+
this.consumeToken(); // @-ms-viewport
|
|
645
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
646
|
+
}
|
|
647
|
+
_parseKeyframe() {
|
|
648
|
+
if (!this.peekRegExp(TokenType.AtKeyword, this.keyframeRegex)) {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
const node = this.create(nodes.Keyframe);
|
|
652
|
+
const atNode = this.create(nodes.Node);
|
|
653
|
+
this.consumeToken(); // atkeyword
|
|
654
|
+
node.setKeyword(this.finish(atNode));
|
|
655
|
+
if (atNode.matches('@-ms-keyframes')) { // -ms-keyframes never existed
|
|
656
|
+
this.markError(atNode, ParseError.UnknownKeyword);
|
|
657
|
+
}
|
|
658
|
+
if (!node.setIdentifier(this._parseKeyframeIdent())) {
|
|
659
|
+
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
660
|
+
}
|
|
661
|
+
return this._parseBody(node, this._parseKeyframeSelector.bind(this));
|
|
662
|
+
}
|
|
663
|
+
_parseKeyframeIdent() {
|
|
664
|
+
return this._parseIdent([nodes.ReferenceType.Keyframe]);
|
|
665
|
+
}
|
|
666
|
+
_parseKeyframeSelector() {
|
|
667
|
+
const node = this.create(nodes.KeyframeSelector);
|
|
668
|
+
if (!node.addChild(this._parseIdent()) && !this.accept(TokenType.Percentage)) {
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
while (this.accept(TokenType.Comma)) {
|
|
672
|
+
if (!node.addChild(this._parseIdent()) && !this.accept(TokenType.Percentage)) {
|
|
673
|
+
return this.finish(node, ParseError.PercentageExpected);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
677
|
+
}
|
|
678
|
+
_tryParseKeyframeSelector() {
|
|
679
|
+
const node = this.create(nodes.KeyframeSelector);
|
|
680
|
+
const pos = this.mark();
|
|
681
|
+
if (!node.addChild(this._parseIdent()) && !this.accept(TokenType.Percentage)) {
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
684
|
+
while (this.accept(TokenType.Comma)) {
|
|
685
|
+
if (!node.addChild(this._parseIdent()) && !this.accept(TokenType.Percentage)) {
|
|
686
|
+
this.restoreAtMark(pos);
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (!this.peek(TokenType.CurlyL)) {
|
|
691
|
+
this.restoreAtMark(pos);
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
695
|
+
}
|
|
696
|
+
_parseSupports(isNested = false) {
|
|
697
|
+
// SUPPORTS_SYM S* supports_condition '{' S* ruleset* '}' S*
|
|
698
|
+
if (!this.peekKeyword('@supports')) {
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
const node = this.create(nodes.Supports);
|
|
702
|
+
this.consumeToken(); // @supports
|
|
703
|
+
node.addChild(this._parseSupportsCondition());
|
|
704
|
+
return this._parseBody(node, this._parseSupportsDeclaration.bind(this, isNested));
|
|
705
|
+
}
|
|
706
|
+
_parseSupportsDeclaration(isNested = false) {
|
|
707
|
+
if (isNested) {
|
|
708
|
+
// if nested, the body can contain rulesets, but also declarations
|
|
709
|
+
return this._tryParseRuleset(true)
|
|
710
|
+
|| this._tryToParseDeclaration()
|
|
711
|
+
|| this._parseStylesheetStatement(true);
|
|
712
|
+
}
|
|
713
|
+
return this._parseStylesheetStatement(false);
|
|
714
|
+
}
|
|
715
|
+
_parseSupportsCondition() {
|
|
716
|
+
// supports_condition : supports_negation | supports_conjunction | supports_disjunction | supports_condition_in_parens ;
|
|
717
|
+
// supports_condition_in_parens: ( '(' S* supports_condition S* ')' ) | supports_declaration_condition | general_enclosed ;
|
|
718
|
+
// supports_negation: NOT S+ supports_condition_in_parens ;
|
|
719
|
+
// supports_conjunction: supports_condition_in_parens ( S+ AND S+ supports_condition_in_parens )+;
|
|
720
|
+
// supports_disjunction: supports_condition_in_parens ( S+ OR S+ supports_condition_in_parens )+;
|
|
721
|
+
// supports_declaration_condition: '(' S* declaration ')';
|
|
722
|
+
// general_enclosed: ( FUNCTION | '(' ) ( any | unused )* ')' ;
|
|
723
|
+
const node = this.create(nodes.SupportsCondition);
|
|
724
|
+
if (this.acceptIdent('not')) {
|
|
725
|
+
node.addChild(this._parseSupportsConditionInParens());
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
node.addChild(this._parseSupportsConditionInParens());
|
|
729
|
+
if (this.peekRegExp(TokenType.Ident, /^(and|or)$/i)) {
|
|
730
|
+
const text = this.token.text.toLowerCase();
|
|
731
|
+
while (this.acceptIdent(text)) {
|
|
732
|
+
node.addChild(this._parseSupportsConditionInParens());
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return this.finish(node);
|
|
737
|
+
}
|
|
738
|
+
_parseSupportsConditionInParens() {
|
|
739
|
+
const node = this.create(nodes.SupportsCondition);
|
|
740
|
+
if (this.accept(TokenType.ParenthesisL)) {
|
|
741
|
+
if (this.prevToken) {
|
|
742
|
+
node.lParent = this.prevToken.offset;
|
|
743
|
+
}
|
|
744
|
+
if (!node.addChild(this._tryToParseDeclaration([TokenType.ParenthesisR]))) {
|
|
745
|
+
if (!this._parseSupportsCondition()) {
|
|
746
|
+
return this.finish(node, ParseError.ConditionExpected);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
750
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [TokenType.ParenthesisR], []);
|
|
751
|
+
}
|
|
752
|
+
if (this.prevToken) {
|
|
753
|
+
node.rParent = this.prevToken.offset;
|
|
754
|
+
}
|
|
755
|
+
return this.finish(node);
|
|
756
|
+
}
|
|
757
|
+
else if (this.peek(TokenType.Ident)) {
|
|
758
|
+
const pos = this.mark();
|
|
759
|
+
this.consumeToken();
|
|
760
|
+
if (!this.hasWhitespace() && this.accept(TokenType.ParenthesisL)) {
|
|
761
|
+
let openParentCount = 1;
|
|
762
|
+
while (this.token.type !== TokenType.EOF && openParentCount !== 0) {
|
|
763
|
+
if (this.token.type === TokenType.ParenthesisL) {
|
|
764
|
+
openParentCount++;
|
|
765
|
+
}
|
|
766
|
+
else if (this.token.type === TokenType.ParenthesisR) {
|
|
767
|
+
openParentCount--;
|
|
768
|
+
}
|
|
769
|
+
this.consumeToken();
|
|
770
|
+
}
|
|
771
|
+
return this.finish(node);
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
this.restoreAtMark(pos);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [], [TokenType.ParenthesisL]);
|
|
778
|
+
}
|
|
779
|
+
_parseMediaDeclaration(isNested = false) {
|
|
780
|
+
if (isNested) {
|
|
781
|
+
// if nested, the body can contain rulesets, but also declarations
|
|
782
|
+
return this._tryParseRuleset(true)
|
|
783
|
+
|| this._tryToParseDeclaration()
|
|
784
|
+
|| this._parseStylesheetStatement(true);
|
|
785
|
+
}
|
|
786
|
+
return this._parseStylesheetStatement(false);
|
|
787
|
+
}
|
|
788
|
+
_parseMedia(isNested = false) {
|
|
789
|
+
// MEDIA_SYM S* media_query_list '{' S* ruleset* '}' S*
|
|
790
|
+
// media_query_list : S* [media_query [ ',' S* media_query ]* ]?
|
|
791
|
+
if (!this.peekKeyword('@media')) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
const node = this.create(nodes.Media);
|
|
795
|
+
this.consumeToken(); // @media
|
|
796
|
+
if (!node.addChild(this._parseMediaQueryList())) {
|
|
797
|
+
return this.finish(node, ParseError.MediaQueryExpected);
|
|
798
|
+
}
|
|
799
|
+
return this._parseBody(node, this._parseMediaDeclaration.bind(this, isNested));
|
|
800
|
+
}
|
|
801
|
+
_parseMediaQueryList() {
|
|
802
|
+
const node = this.create(nodes.Medialist);
|
|
803
|
+
if (!node.addChild(this._parseMediaQuery())) {
|
|
804
|
+
return this.finish(node, ParseError.MediaQueryExpected);
|
|
805
|
+
}
|
|
806
|
+
while (this.accept(TokenType.Comma)) {
|
|
807
|
+
if (!node.addChild(this._parseMediaQuery())) {
|
|
808
|
+
return this.finish(node, ParseError.MediaQueryExpected);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return this.finish(node);
|
|
812
|
+
}
|
|
813
|
+
_parseMediaQuery() {
|
|
814
|
+
// <media-query> = <media-condition> | [ not | only ]? <media-type> [ and <media-condition-without-or> ]?
|
|
815
|
+
const node = this.create(nodes.MediaQuery);
|
|
816
|
+
const pos = this.mark();
|
|
817
|
+
this.acceptIdent('not');
|
|
818
|
+
if (!this.peek(TokenType.ParenthesisL)) {
|
|
819
|
+
if (this.acceptIdent('only')) {
|
|
820
|
+
// optional
|
|
821
|
+
}
|
|
822
|
+
if (!node.addChild(this._parseIdent())) {
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
if (this.acceptIdent('and')) {
|
|
826
|
+
node.addChild(this._parseMediaCondition());
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
this.restoreAtMark(pos); // 'not' is part of the MediaCondition
|
|
831
|
+
node.addChild(this._parseMediaCondition());
|
|
832
|
+
}
|
|
833
|
+
return this.finish(node);
|
|
834
|
+
}
|
|
835
|
+
_parseRatio() {
|
|
836
|
+
const pos = this.mark();
|
|
837
|
+
const node = this.create(nodes.RatioValue);
|
|
838
|
+
if (!this._parseNumeric()) {
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
if (!this.acceptDelim('/')) {
|
|
842
|
+
this.restoreAtMark(pos);
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
845
|
+
if (!this._parseNumeric()) {
|
|
846
|
+
return this.finish(node, ParseError.NumberExpected);
|
|
847
|
+
}
|
|
848
|
+
return this.finish(node);
|
|
849
|
+
}
|
|
850
|
+
_parseMediaCondition() {
|
|
851
|
+
// <media-condition> = <media-not> | <media-and> | <media-or> | <media-in-parens>
|
|
852
|
+
// <media-not> = not <media-in-parens>
|
|
853
|
+
// <media-and> = <media-in-parens> [ and <media-in-parens> ]+
|
|
854
|
+
// <media-or> = <media-in-parens> [ or <media-in-parens> ]+
|
|
855
|
+
// <media-in-parens> = ( <media-condition> ) | <media-feature> | <general-enclosed>
|
|
856
|
+
const node = this.create(nodes.MediaCondition);
|
|
857
|
+
this.acceptIdent('not');
|
|
858
|
+
let parseExpression = true;
|
|
859
|
+
while (parseExpression) {
|
|
860
|
+
if (!this.accept(TokenType.ParenthesisL)) {
|
|
861
|
+
return this.finish(node, ParseError.LeftParenthesisExpected, [], [TokenType.CurlyL]);
|
|
862
|
+
}
|
|
863
|
+
if (this.peek(TokenType.ParenthesisL) || this.peekIdent('not')) {
|
|
864
|
+
// <media-condition>
|
|
865
|
+
node.addChild(this._parseMediaCondition());
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
node.addChild(this._parseMediaFeature());
|
|
869
|
+
}
|
|
870
|
+
// not yet implemented: general enclosed
|
|
871
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
872
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [], [TokenType.CurlyL]);
|
|
873
|
+
}
|
|
874
|
+
parseExpression = this.acceptIdent('and') || this.acceptIdent('or');
|
|
875
|
+
}
|
|
876
|
+
return this.finish(node);
|
|
877
|
+
}
|
|
878
|
+
_parseMediaFeature() {
|
|
879
|
+
const resyncStopToken = [TokenType.ParenthesisR];
|
|
880
|
+
const node = this.create(nodes.MediaFeature);
|
|
881
|
+
// <media-feature> = ( [ <mf-plain> | <mf-boolean> | <mf-range> ] )
|
|
882
|
+
// <mf-plain> = <mf-name> : <mf-value>
|
|
883
|
+
// <mf-boolean> = <mf-name>
|
|
884
|
+
// <mf-range> = <mf-name> [ '<' | '>' ]? '='? <mf-value> | <mf-value> [ '<' | '>' ]? '='? <mf-name> | <mf-value> '<' '='? <mf-name> '<' '='? <mf-value> | <mf-value> '>' '='? <mf-name> '>' '='? <mf-value>
|
|
885
|
+
const parseRangeOperator = () => {
|
|
886
|
+
if (this.acceptDelim('<') || this.acceptDelim('>')) {
|
|
887
|
+
if (!this.hasWhitespace()) {
|
|
888
|
+
this.acceptDelim('=');
|
|
889
|
+
}
|
|
890
|
+
return true;
|
|
891
|
+
}
|
|
892
|
+
else if (this.acceptDelim('=')) {
|
|
893
|
+
return true;
|
|
894
|
+
}
|
|
895
|
+
return false;
|
|
896
|
+
};
|
|
897
|
+
if (node.addChild(this._parseMediaFeatureName())) {
|
|
898
|
+
if (this.accept(TokenType.Colon)) {
|
|
899
|
+
if (!node.addChild(this._parseMediaFeatureValue())) {
|
|
900
|
+
return this.finish(node, ParseError.TermExpected, [], resyncStopToken);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
else if (parseRangeOperator()) {
|
|
904
|
+
if (!node.addChild(this._parseMediaFeatureValue())) {
|
|
905
|
+
return this.finish(node, ParseError.TermExpected, [], resyncStopToken);
|
|
906
|
+
}
|
|
907
|
+
if (parseRangeOperator()) {
|
|
908
|
+
if (!node.addChild(this._parseMediaFeatureValue())) {
|
|
909
|
+
return this.finish(node, ParseError.TermExpected, [], resyncStopToken);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
// <mf-boolean> = <mf-name>
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
else if (node.addChild(this._parseMediaFeatureValue())) {
|
|
918
|
+
if (!parseRangeOperator()) {
|
|
919
|
+
return this.finish(node, ParseError.OperatorExpected, [], resyncStopToken);
|
|
920
|
+
}
|
|
921
|
+
if (!node.addChild(this._parseMediaFeatureName())) {
|
|
922
|
+
return this.finish(node, ParseError.IdentifierExpected, [], resyncStopToken);
|
|
923
|
+
}
|
|
924
|
+
if (parseRangeOperator()) {
|
|
925
|
+
if (!node.addChild(this._parseMediaFeatureValue())) {
|
|
926
|
+
return this.finish(node, ParseError.TermExpected, [], resyncStopToken);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
return this.finish(node, ParseError.IdentifierExpected, [], resyncStopToken);
|
|
932
|
+
}
|
|
933
|
+
return this.finish(node);
|
|
934
|
+
}
|
|
935
|
+
_parseMediaFeatureName() {
|
|
936
|
+
return this._parseIdent();
|
|
937
|
+
}
|
|
938
|
+
_parseMediaFeatureValue() {
|
|
939
|
+
return this._parseRatio() || this._parseTermExpression();
|
|
940
|
+
}
|
|
941
|
+
_parseMedium() {
|
|
942
|
+
const node = this.create(nodes.Node);
|
|
943
|
+
if (node.addChild(this._parseIdent())) {
|
|
944
|
+
return this.finish(node);
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
_parsePageDeclaration() {
|
|
951
|
+
return this._parsePageMarginBox() || this._parseRuleSetDeclaration();
|
|
952
|
+
}
|
|
953
|
+
_parsePage() {
|
|
954
|
+
// http://www.w3.org/TR/css3-page/
|
|
955
|
+
// page_rule : PAGE_SYM S* page_selector_list '{' S* page_body '}' S*
|
|
956
|
+
// page_body : /* Can be empty */ declaration? [ ';' S* page_body ]? | page_margin_box page_body
|
|
957
|
+
if (!this.peekKeyword('@page')) {
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
const node = this.create(nodes.Page);
|
|
961
|
+
this.consumeToken();
|
|
962
|
+
if (node.addChild(this._parsePageSelector())) {
|
|
963
|
+
while (this.accept(TokenType.Comma)) {
|
|
964
|
+
if (!node.addChild(this._parsePageSelector())) {
|
|
965
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return this._parseBody(node, this._parsePageDeclaration.bind(this));
|
|
970
|
+
}
|
|
971
|
+
_parsePageMarginBox() {
|
|
972
|
+
// page_margin_box : margin_sym S* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
|
|
973
|
+
if (!this.peek(TokenType.AtKeyword)) {
|
|
974
|
+
return null;
|
|
975
|
+
}
|
|
976
|
+
const node = this.create(nodes.PageBoxMarginBox);
|
|
977
|
+
if (!this.acceptOneKeyword(languageFacts.pageBoxDirectives)) {
|
|
978
|
+
this.markError(node, ParseError.UnknownAtRule, [], [TokenType.CurlyL]);
|
|
979
|
+
}
|
|
980
|
+
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
981
|
+
}
|
|
982
|
+
_parsePageSelector() {
|
|
983
|
+
// page_selector : pseudo_page+ | IDENT pseudo_page*
|
|
984
|
+
// pseudo_page : ':' [ "left" | "right" | "first" | "blank" ];
|
|
985
|
+
if (!this.peek(TokenType.Ident) && !this.peek(TokenType.Colon)) {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
const node = this.create(nodes.Node);
|
|
989
|
+
node.addChild(this._parseIdent()); // optional ident
|
|
990
|
+
if (this.accept(TokenType.Colon)) {
|
|
991
|
+
if (!node.addChild(this._parseIdent())) { // optional ident
|
|
992
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return this.finish(node);
|
|
996
|
+
}
|
|
997
|
+
_parseDocument() {
|
|
998
|
+
// -moz-document is experimental but has been pushed to css4
|
|
999
|
+
if (!this.peekKeyword('@-moz-document')) {
|
|
1000
|
+
return null;
|
|
1001
|
+
}
|
|
1002
|
+
const node = this.create(nodes.Document);
|
|
1003
|
+
this.consumeToken(); // @-moz-document
|
|
1004
|
+
this.resync([], [TokenType.CurlyL]); // ignore all the rules
|
|
1005
|
+
return this._parseBody(node, this._parseStylesheetStatement.bind(this));
|
|
1006
|
+
}
|
|
1007
|
+
// https://www.w3.org/TR/css-syntax-3/#consume-an-at-rule
|
|
1008
|
+
_parseUnknownAtRule() {
|
|
1009
|
+
if (!this.peek(TokenType.AtKeyword)) {
|
|
1010
|
+
return null;
|
|
1011
|
+
}
|
|
1012
|
+
const node = this.create(nodes.UnknownAtRule);
|
|
1013
|
+
node.addChild(this._parseUnknownAtRuleName());
|
|
1014
|
+
const isTopLevel = () => curlyDepth === 0 && parensDepth === 0 && bracketsDepth === 0;
|
|
1015
|
+
let curlyLCount = 0;
|
|
1016
|
+
let curlyDepth = 0;
|
|
1017
|
+
let parensDepth = 0;
|
|
1018
|
+
let bracketsDepth = 0;
|
|
1019
|
+
done: while (true) {
|
|
1020
|
+
switch (this.token.type) {
|
|
1021
|
+
case TokenType.SemiColon:
|
|
1022
|
+
if (isTopLevel()) {
|
|
1023
|
+
break done;
|
|
1024
|
+
}
|
|
1025
|
+
break;
|
|
1026
|
+
case TokenType.EOF:
|
|
1027
|
+
if (curlyDepth > 0) {
|
|
1028
|
+
return this.finish(node, ParseError.RightCurlyExpected);
|
|
1029
|
+
}
|
|
1030
|
+
else if (bracketsDepth > 0) {
|
|
1031
|
+
return this.finish(node, ParseError.RightSquareBracketExpected);
|
|
1032
|
+
}
|
|
1033
|
+
else if (parensDepth > 0) {
|
|
1034
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
1035
|
+
}
|
|
1036
|
+
else {
|
|
1037
|
+
return this.finish(node);
|
|
1038
|
+
}
|
|
1039
|
+
case TokenType.CurlyL:
|
|
1040
|
+
curlyLCount++;
|
|
1041
|
+
curlyDepth++;
|
|
1042
|
+
break;
|
|
1043
|
+
case TokenType.CurlyR:
|
|
1044
|
+
curlyDepth--;
|
|
1045
|
+
// End of at-rule, consume CurlyR and return node
|
|
1046
|
+
if (curlyLCount > 0 && curlyDepth === 0) {
|
|
1047
|
+
this.consumeToken();
|
|
1048
|
+
if (bracketsDepth > 0) {
|
|
1049
|
+
return this.finish(node, ParseError.RightSquareBracketExpected);
|
|
1050
|
+
}
|
|
1051
|
+
else if (parensDepth > 0) {
|
|
1052
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
1053
|
+
}
|
|
1054
|
+
break done;
|
|
1055
|
+
}
|
|
1056
|
+
if (curlyDepth < 0) {
|
|
1057
|
+
// The property value has been terminated without a semicolon, and
|
|
1058
|
+
// this is the last declaration in the ruleset.
|
|
1059
|
+
if (parensDepth === 0 && bracketsDepth === 0) {
|
|
1060
|
+
break done;
|
|
1061
|
+
}
|
|
1062
|
+
return this.finish(node, ParseError.LeftCurlyExpected);
|
|
1063
|
+
}
|
|
1064
|
+
break;
|
|
1065
|
+
case TokenType.ParenthesisL:
|
|
1066
|
+
parensDepth++;
|
|
1067
|
+
break;
|
|
1068
|
+
case TokenType.ParenthesisR:
|
|
1069
|
+
parensDepth--;
|
|
1070
|
+
if (parensDepth < 0) {
|
|
1071
|
+
return this.finish(node, ParseError.LeftParenthesisExpected);
|
|
1072
|
+
}
|
|
1073
|
+
break;
|
|
1074
|
+
case TokenType.BracketL:
|
|
1075
|
+
bracketsDepth++;
|
|
1076
|
+
break;
|
|
1077
|
+
case TokenType.BracketR:
|
|
1078
|
+
bracketsDepth--;
|
|
1079
|
+
if (bracketsDepth < 0) {
|
|
1080
|
+
return this.finish(node, ParseError.LeftSquareBracketExpected);
|
|
1081
|
+
}
|
|
1082
|
+
break;
|
|
1083
|
+
}
|
|
1084
|
+
this.consumeToken();
|
|
1085
|
+
}
|
|
1086
|
+
return node;
|
|
1087
|
+
}
|
|
1088
|
+
_parseUnknownAtRuleName() {
|
|
1089
|
+
const node = this.create(nodes.Node);
|
|
1090
|
+
if (this.accept(TokenType.AtKeyword)) {
|
|
1091
|
+
return this.finish(node);
|
|
1092
|
+
}
|
|
1093
|
+
return node;
|
|
1094
|
+
}
|
|
1095
|
+
_parseOperator() {
|
|
1096
|
+
// these are operators for binary expressions
|
|
1097
|
+
if (this.peekDelim('/') ||
|
|
1098
|
+
this.peekDelim('*') ||
|
|
1099
|
+
this.peekDelim('+') ||
|
|
1100
|
+
this.peekDelim('-') ||
|
|
1101
|
+
this.peek(TokenType.Dashmatch) ||
|
|
1102
|
+
this.peek(TokenType.Includes) ||
|
|
1103
|
+
this.peek(TokenType.SubstringOperator) ||
|
|
1104
|
+
this.peek(TokenType.PrefixOperator) ||
|
|
1105
|
+
this.peek(TokenType.SuffixOperator) ||
|
|
1106
|
+
this.peekDelim('=')) { // doesn't stick to the standard here
|
|
1107
|
+
const node = this.createNode(nodes.NodeType.Operator);
|
|
1108
|
+
this.consumeToken();
|
|
1109
|
+
return this.finish(node);
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
return null;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
_parseUnaryOperator() {
|
|
1116
|
+
if (!this.peekDelim('+') && !this.peekDelim('-')) {
|
|
1117
|
+
return null;
|
|
1118
|
+
}
|
|
1119
|
+
const node = this.create(nodes.Node);
|
|
1120
|
+
this.consumeToken();
|
|
1121
|
+
return this.finish(node);
|
|
1122
|
+
}
|
|
1123
|
+
_parseCombinator() {
|
|
1124
|
+
if (this.peekDelim('>')) {
|
|
1125
|
+
const node = this.create(nodes.Node);
|
|
1126
|
+
this.consumeToken();
|
|
1127
|
+
const mark = this.mark();
|
|
1128
|
+
if (!this.hasWhitespace() && this.acceptDelim('>')) {
|
|
1129
|
+
if (!this.hasWhitespace() && this.acceptDelim('>')) {
|
|
1130
|
+
node.type = nodes.NodeType.SelectorCombinatorShadowPiercingDescendant;
|
|
1131
|
+
return this.finish(node);
|
|
1132
|
+
}
|
|
1133
|
+
this.restoreAtMark(mark);
|
|
1134
|
+
}
|
|
1135
|
+
node.type = nodes.NodeType.SelectorCombinatorParent;
|
|
1136
|
+
return this.finish(node);
|
|
1137
|
+
}
|
|
1138
|
+
else if (this.peekDelim('+')) {
|
|
1139
|
+
const node = this.create(nodes.Node);
|
|
1140
|
+
this.consumeToken();
|
|
1141
|
+
node.type = nodes.NodeType.SelectorCombinatorSibling;
|
|
1142
|
+
return this.finish(node);
|
|
1143
|
+
}
|
|
1144
|
+
else if (this.peekDelim('~')) {
|
|
1145
|
+
const node = this.create(nodes.Node);
|
|
1146
|
+
this.consumeToken();
|
|
1147
|
+
node.type = nodes.NodeType.SelectorCombinatorAllSiblings;
|
|
1148
|
+
return this.finish(node);
|
|
1149
|
+
}
|
|
1150
|
+
else if (this.peekDelim('/')) {
|
|
1151
|
+
const node = this.create(nodes.Node);
|
|
1152
|
+
this.consumeToken();
|
|
1153
|
+
const mark = this.mark();
|
|
1154
|
+
if (!this.hasWhitespace() && this.acceptIdent('deep') && !this.hasWhitespace() && this.acceptDelim('/')) {
|
|
1155
|
+
node.type = nodes.NodeType.SelectorCombinatorShadowPiercingDescendant;
|
|
1156
|
+
return this.finish(node);
|
|
1157
|
+
}
|
|
1158
|
+
this.restoreAtMark(mark);
|
|
1159
|
+
}
|
|
1160
|
+
return null;
|
|
1161
|
+
}
|
|
1162
|
+
_parseSimpleSelector() {
|
|
1163
|
+
// simple_selector
|
|
1164
|
+
// : element_name [ HASH | class | attrib | pseudo ]* | [ HASH | class | attrib | pseudo ]+ ;
|
|
1165
|
+
const node = this.create(nodes.SimpleSelector);
|
|
1166
|
+
let c = 0;
|
|
1167
|
+
if (node.addChild(this._parseElementName())) {
|
|
1168
|
+
c++;
|
|
1169
|
+
}
|
|
1170
|
+
while ((c === 0 || !this.hasWhitespace()) && node.addChild(this._parseSimpleSelectorBody())) {
|
|
1171
|
+
c++;
|
|
1172
|
+
}
|
|
1173
|
+
return c > 0 ? this.finish(node) : null;
|
|
1174
|
+
}
|
|
1175
|
+
_parseSimpleSelectorBody() {
|
|
1176
|
+
return this._parsePseudo() || this._parseHash() || this._parseClass() || this._parseAttrib();
|
|
1177
|
+
}
|
|
1178
|
+
_parseSelectorIdent() {
|
|
1179
|
+
return this._parseIdent();
|
|
1180
|
+
}
|
|
1181
|
+
_parseHash() {
|
|
1182
|
+
if (!this.peek(TokenType.Hash) && !this.peekDelim('#')) {
|
|
1183
|
+
return null;
|
|
1184
|
+
}
|
|
1185
|
+
const node = this.createNode(nodes.NodeType.IdentifierSelector);
|
|
1186
|
+
if (this.acceptDelim('#')) {
|
|
1187
|
+
if (this.hasWhitespace() || !node.addChild(this._parseSelectorIdent())) {
|
|
1188
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
else {
|
|
1192
|
+
this.consumeToken(); // TokenType.Hash
|
|
1193
|
+
}
|
|
1194
|
+
return this.finish(node);
|
|
1195
|
+
}
|
|
1196
|
+
_parseClass() {
|
|
1197
|
+
// class: '.' IDENT ;
|
|
1198
|
+
if (!this.peekDelim('.')) {
|
|
1199
|
+
return null;
|
|
1200
|
+
}
|
|
1201
|
+
const node = this.createNode(nodes.NodeType.ClassSelector);
|
|
1202
|
+
this.consumeToken(); // '.'
|
|
1203
|
+
if (this.hasWhitespace() || !node.addChild(this._parseSelectorIdent())) {
|
|
1204
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
1205
|
+
}
|
|
1206
|
+
return this.finish(node);
|
|
1207
|
+
}
|
|
1208
|
+
_parseElementName() {
|
|
1209
|
+
// element_name: (ns? '|')? IDENT | '*';
|
|
1210
|
+
const pos = this.mark();
|
|
1211
|
+
const node = this.createNode(nodes.NodeType.ElementNameSelector);
|
|
1212
|
+
node.addChild(this._parseNamespacePrefix());
|
|
1213
|
+
if (!node.addChild(this._parseSelectorIdent()) && !this.acceptDelim('*')) {
|
|
1214
|
+
this.restoreAtMark(pos);
|
|
1215
|
+
return null;
|
|
1216
|
+
}
|
|
1217
|
+
return this.finish(node);
|
|
1218
|
+
}
|
|
1219
|
+
_parseNamespacePrefix() {
|
|
1220
|
+
const pos = this.mark();
|
|
1221
|
+
const node = this.createNode(nodes.NodeType.NamespacePrefix);
|
|
1222
|
+
if (!node.addChild(this._parseIdent()) && !this.acceptDelim('*')) {
|
|
1223
|
+
// ns is optional
|
|
1224
|
+
}
|
|
1225
|
+
if (!this.acceptDelim('|')) {
|
|
1226
|
+
this.restoreAtMark(pos);
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
1229
|
+
return this.finish(node);
|
|
1230
|
+
}
|
|
1231
|
+
_parseAttrib() {
|
|
1232
|
+
// attrib : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S* [ IDENT | STRING ] S* ]? ']'
|
|
1233
|
+
if (!this.peek(TokenType.BracketL)) {
|
|
1234
|
+
return null;
|
|
1235
|
+
}
|
|
1236
|
+
const node = this.create(nodes.AttributeSelector);
|
|
1237
|
+
this.consumeToken(); // BracketL
|
|
1238
|
+
// Optional attrib namespace
|
|
1239
|
+
node.setNamespacePrefix(this._parseNamespacePrefix());
|
|
1240
|
+
if (!node.setIdentifier(this._parseIdent())) {
|
|
1241
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
1242
|
+
}
|
|
1243
|
+
if (node.setOperator(this._parseOperator())) {
|
|
1244
|
+
node.setValue(this._parseBinaryExpr());
|
|
1245
|
+
this.acceptIdent('i'); // case insensitive matching
|
|
1246
|
+
this.acceptIdent('s'); // case sensitive matching
|
|
1247
|
+
}
|
|
1248
|
+
if (!this.accept(TokenType.BracketR)) {
|
|
1249
|
+
return this.finish(node, ParseError.RightSquareBracketExpected);
|
|
1250
|
+
}
|
|
1251
|
+
return this.finish(node);
|
|
1252
|
+
}
|
|
1253
|
+
_parsePseudo() {
|
|
1254
|
+
// pseudo: ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ]
|
|
1255
|
+
const node = this._tryParsePseudoIdentifier();
|
|
1256
|
+
if (node) {
|
|
1257
|
+
if (!this.hasWhitespace() && this.accept(TokenType.ParenthesisL)) {
|
|
1258
|
+
const tryAsSelector = () => {
|
|
1259
|
+
const selectors = this.create(nodes.Node);
|
|
1260
|
+
if (!selectors.addChild(this._parseSelector(false))) {
|
|
1261
|
+
return null;
|
|
1262
|
+
}
|
|
1263
|
+
while (this.accept(TokenType.Comma) && selectors.addChild(this._parseSelector(false))) {
|
|
1264
|
+
// loop
|
|
1265
|
+
}
|
|
1266
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
1267
|
+
return this.finish(selectors);
|
|
1268
|
+
}
|
|
1269
|
+
return null;
|
|
1270
|
+
};
|
|
1271
|
+
node.addChild(this.try(tryAsSelector) || this._parseBinaryExpr());
|
|
1272
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
1273
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return this.finish(node);
|
|
1277
|
+
}
|
|
1278
|
+
return null;
|
|
1279
|
+
}
|
|
1280
|
+
_tryParsePseudoIdentifier() {
|
|
1281
|
+
if (!this.peek(TokenType.Colon)) {
|
|
1282
|
+
return null;
|
|
1283
|
+
}
|
|
1284
|
+
const pos = this.mark();
|
|
1285
|
+
const node = this.createNode(nodes.NodeType.PseudoSelector);
|
|
1286
|
+
this.consumeToken(); // Colon
|
|
1287
|
+
if (this.hasWhitespace()) {
|
|
1288
|
+
this.restoreAtMark(pos);
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
// optional, support ::
|
|
1292
|
+
this.accept(TokenType.Colon);
|
|
1293
|
+
if (this.hasWhitespace() || !node.addChild(this._parseIdent())) {
|
|
1294
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
1295
|
+
}
|
|
1296
|
+
return this.finish(node);
|
|
1297
|
+
}
|
|
1298
|
+
_tryParsePrio() {
|
|
1299
|
+
const mark = this.mark();
|
|
1300
|
+
const prio = this._parsePrio();
|
|
1301
|
+
if (prio) {
|
|
1302
|
+
return prio;
|
|
1303
|
+
}
|
|
1304
|
+
this.restoreAtMark(mark);
|
|
1305
|
+
return null;
|
|
1306
|
+
}
|
|
1307
|
+
_parsePrio() {
|
|
1308
|
+
if (!this.peek(TokenType.Exclamation)) {
|
|
1309
|
+
return null;
|
|
1310
|
+
}
|
|
1311
|
+
const node = this.createNode(nodes.NodeType.Prio);
|
|
1312
|
+
if (this.accept(TokenType.Exclamation) && this.acceptIdent('important')) {
|
|
1313
|
+
return this.finish(node);
|
|
1314
|
+
}
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
_parseExpr(stopOnComma = false) {
|
|
1318
|
+
const node = this.create(nodes.Expression);
|
|
1319
|
+
if (!node.addChild(this._parseBinaryExpr())) {
|
|
1320
|
+
return null;
|
|
1321
|
+
}
|
|
1322
|
+
while (true) {
|
|
1323
|
+
if (this.peek(TokenType.Comma)) { // optional
|
|
1324
|
+
if (stopOnComma) {
|
|
1325
|
+
return this.finish(node);
|
|
1326
|
+
}
|
|
1327
|
+
this.consumeToken();
|
|
1328
|
+
}
|
|
1329
|
+
if (!node.addChild(this._parseBinaryExpr())) {
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
return this.finish(node);
|
|
1334
|
+
}
|
|
1335
|
+
_parseUnicodeRange() {
|
|
1336
|
+
if (!this.peekIdent('u')) {
|
|
1337
|
+
return null;
|
|
1338
|
+
}
|
|
1339
|
+
const node = this.create(nodes.UnicodeRange);
|
|
1340
|
+
if (!this.acceptUnicodeRange()) {
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
return this.finish(node);
|
|
1344
|
+
}
|
|
1345
|
+
_parseNamedLine() {
|
|
1346
|
+
// https://www.w3.org/TR/css-grid-1/#named-lines
|
|
1347
|
+
if (!this.peek(TokenType.BracketL)) {
|
|
1348
|
+
return null;
|
|
1349
|
+
}
|
|
1350
|
+
const node = this.createNode(nodes.NodeType.GridLine);
|
|
1351
|
+
this.consumeToken();
|
|
1352
|
+
while (node.addChild(this._parseIdent())) {
|
|
1353
|
+
// repeat
|
|
1354
|
+
}
|
|
1355
|
+
if (!this.accept(TokenType.BracketR)) {
|
|
1356
|
+
return this.finish(node, ParseError.RightSquareBracketExpected);
|
|
1357
|
+
}
|
|
1358
|
+
return this.finish(node);
|
|
1359
|
+
}
|
|
1360
|
+
_parseBinaryExpr(preparsedLeft, preparsedOper) {
|
|
1361
|
+
let node = this.create(nodes.BinaryExpression);
|
|
1362
|
+
if (!node.setLeft((preparsedLeft || this._parseTerm()))) {
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
if (!node.setOperator(preparsedOper || this._parseOperator())) {
|
|
1366
|
+
return this.finish(node);
|
|
1367
|
+
}
|
|
1368
|
+
if (!node.setRight(this._parseTerm())) {
|
|
1369
|
+
return this.finish(node, ParseError.TermExpected);
|
|
1370
|
+
}
|
|
1371
|
+
// things needed for multiple binary expressions
|
|
1372
|
+
node = this.finish(node);
|
|
1373
|
+
const operator = this._parseOperator();
|
|
1374
|
+
if (operator) {
|
|
1375
|
+
node = this._parseBinaryExpr(node, operator);
|
|
1376
|
+
}
|
|
1377
|
+
return this.finish(node);
|
|
1378
|
+
}
|
|
1379
|
+
_parseTerm() {
|
|
1380
|
+
let node = this.create(nodes.Term);
|
|
1381
|
+
node.setOperator(this._parseUnaryOperator()); // optional
|
|
1382
|
+
if (node.setExpression(this._parseTermExpression())) {
|
|
1383
|
+
return this.finish(node);
|
|
1384
|
+
}
|
|
1385
|
+
return null;
|
|
1386
|
+
}
|
|
1387
|
+
_parseTermExpression() {
|
|
1388
|
+
return this._parseURILiteral() || // url before function
|
|
1389
|
+
this._parseUnicodeRange() ||
|
|
1390
|
+
this._parseFunction() || // function before ident
|
|
1391
|
+
this._parseIdent() ||
|
|
1392
|
+
this._parseStringLiteral() ||
|
|
1393
|
+
this._parseNumeric() ||
|
|
1394
|
+
this._parseHexColor() ||
|
|
1395
|
+
this._parseOperation() ||
|
|
1396
|
+
this._parseNamedLine();
|
|
1397
|
+
}
|
|
1398
|
+
_parseOperation() {
|
|
1399
|
+
if (!this.peek(TokenType.ParenthesisL)) {
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
const node = this.create(nodes.Node);
|
|
1403
|
+
this.consumeToken(); // ParenthesisL
|
|
1404
|
+
node.addChild(this._parseExpr());
|
|
1405
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
1406
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
1407
|
+
}
|
|
1408
|
+
return this.finish(node);
|
|
1409
|
+
}
|
|
1410
|
+
_parseNumeric() {
|
|
1411
|
+
if (this.peek(TokenType.Num) ||
|
|
1412
|
+
this.peek(TokenType.Percentage) ||
|
|
1413
|
+
this.peek(TokenType.Resolution) ||
|
|
1414
|
+
this.peek(TokenType.Length) ||
|
|
1415
|
+
this.peek(TokenType.EMS) ||
|
|
1416
|
+
this.peek(TokenType.EXS) ||
|
|
1417
|
+
this.peek(TokenType.Angle) ||
|
|
1418
|
+
this.peek(TokenType.Time) ||
|
|
1419
|
+
this.peek(TokenType.Dimension) ||
|
|
1420
|
+
this.peek(TokenType.Freq)) {
|
|
1421
|
+
const node = this.create(nodes.NumericValue);
|
|
1422
|
+
this.consumeToken();
|
|
1423
|
+
return this.finish(node);
|
|
1424
|
+
}
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
_parseStringLiteral() {
|
|
1428
|
+
if (!this.peek(TokenType.String) && !this.peek(TokenType.BadString)) {
|
|
1429
|
+
return null;
|
|
1430
|
+
}
|
|
1431
|
+
const node = this.createNode(nodes.NodeType.StringLiteral);
|
|
1432
|
+
this.consumeToken();
|
|
1433
|
+
return this.finish(node);
|
|
1434
|
+
}
|
|
1435
|
+
_parseURILiteral() {
|
|
1436
|
+
if (!this.peekRegExp(TokenType.Ident, /^url(-prefix)?$/i)) {
|
|
1437
|
+
return null;
|
|
1438
|
+
}
|
|
1439
|
+
const pos = this.mark();
|
|
1440
|
+
const node = this.createNode(nodes.NodeType.URILiteral);
|
|
1441
|
+
this.accept(TokenType.Ident);
|
|
1442
|
+
if (this.hasWhitespace() || !this.peek(TokenType.ParenthesisL)) {
|
|
1443
|
+
this.restoreAtMark(pos);
|
|
1444
|
+
return null;
|
|
1445
|
+
}
|
|
1446
|
+
this.scanner.inURL = true;
|
|
1447
|
+
this.consumeToken(); // consume ()
|
|
1448
|
+
node.addChild(this._parseURLArgument()); // argument is optional
|
|
1449
|
+
this.scanner.inURL = false;
|
|
1450
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
1451
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
1452
|
+
}
|
|
1453
|
+
return this.finish(node);
|
|
1454
|
+
}
|
|
1455
|
+
_parseURLArgument() {
|
|
1456
|
+
const node = this.create(nodes.Node);
|
|
1457
|
+
if (!this.accept(TokenType.String) && !this.accept(TokenType.BadString) && !this.acceptUnquotedString()) {
|
|
1458
|
+
return null;
|
|
1459
|
+
}
|
|
1460
|
+
return this.finish(node);
|
|
1461
|
+
}
|
|
1462
|
+
_parseIdent(referenceTypes) {
|
|
1463
|
+
if (!this.peek(TokenType.Ident)) {
|
|
1464
|
+
return null;
|
|
1465
|
+
}
|
|
1466
|
+
const node = this.create(nodes.Identifier);
|
|
1467
|
+
if (referenceTypes) {
|
|
1468
|
+
node.referenceTypes = referenceTypes;
|
|
1469
|
+
}
|
|
1470
|
+
node.isCustomProperty = this.peekRegExp(TokenType.Ident, /^--/);
|
|
1471
|
+
this.consumeToken();
|
|
1472
|
+
return this.finish(node);
|
|
1473
|
+
}
|
|
1474
|
+
_parseFunction() {
|
|
1475
|
+
const pos = this.mark();
|
|
1476
|
+
const node = this.create(nodes.Function);
|
|
1477
|
+
if (!node.setIdentifier(this._parseFunctionIdentifier())) {
|
|
1478
|
+
return null;
|
|
1479
|
+
}
|
|
1480
|
+
if (this.hasWhitespace() || !this.accept(TokenType.ParenthesisL)) {
|
|
1481
|
+
this.restoreAtMark(pos);
|
|
1482
|
+
return null;
|
|
1483
|
+
}
|
|
1484
|
+
if (node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
1485
|
+
while (this.accept(TokenType.Comma)) {
|
|
1486
|
+
if (this.peek(TokenType.ParenthesisR)) {
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
if (!node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
1490
|
+
this.markError(node, ParseError.ExpressionExpected);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
1495
|
+
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
1496
|
+
}
|
|
1497
|
+
return this.finish(node);
|
|
1498
|
+
}
|
|
1499
|
+
_parseFunctionIdentifier() {
|
|
1500
|
+
if (!this.peek(TokenType.Ident)) {
|
|
1501
|
+
return null;
|
|
1502
|
+
}
|
|
1503
|
+
const node = this.create(nodes.Identifier);
|
|
1504
|
+
node.referenceTypes = [nodes.ReferenceType.Function];
|
|
1505
|
+
if (this.acceptIdent('progid')) {
|
|
1506
|
+
// support for IE7 specific filters: 'progid:DXImageTransform.Microsoft.MotionBlur(strength=13, direction=310)'
|
|
1507
|
+
if (this.accept(TokenType.Colon)) {
|
|
1508
|
+
while (this.accept(TokenType.Ident) && this.acceptDelim('.')) {
|
|
1509
|
+
// loop
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
return this.finish(node);
|
|
1513
|
+
}
|
|
1514
|
+
this.consumeToken();
|
|
1515
|
+
return this.finish(node);
|
|
1516
|
+
}
|
|
1517
|
+
_parseFunctionArgument() {
|
|
1518
|
+
const node = this.create(nodes.FunctionArgument);
|
|
1519
|
+
if (node.setValue(this._parseExpr(true))) {
|
|
1520
|
+
return this.finish(node);
|
|
1521
|
+
}
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1524
|
+
_parseHexColor() {
|
|
1525
|
+
if (this.peekRegExp(TokenType.Hash, /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/g)) {
|
|
1526
|
+
const node = this.create(nodes.HexColorValue);
|
|
1527
|
+
this.consumeToken();
|
|
1528
|
+
return this.finish(node);
|
|
1529
|
+
}
|
|
1530
|
+
else {
|
|
1531
|
+
return null;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|