vscode-css-languageservice 6.0.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/beautify/beautify-css.js +11 -4
  4. package/lib/esm/cssLanguageService.d.ts +38 -37
  5. package/lib/esm/cssLanguageService.js +73 -72
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +22089 -21959
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -469
  11. package/lib/esm/languageFacts/dataManager.js +88 -88
  12. package/lib/esm/languageFacts/dataProvider.js +73 -73
  13. package/lib/esm/languageFacts/entry.js +137 -137
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -48
  16. package/lib/esm/parser/cssNodes.js +1511 -1502
  17. package/lib/esm/parser/cssParser.js +1606 -1534
  18. package/lib/esm/parser/cssScanner.js +592 -592
  19. package/lib/esm/parser/cssSymbolScope.js +311 -311
  20. package/lib/esm/parser/lessParser.js +715 -714
  21. package/lib/esm/parser/lessScanner.js +57 -57
  22. package/lib/esm/parser/scssErrors.js +18 -18
  23. package/lib/esm/parser/scssParser.js +806 -796
  24. package/lib/esm/parser/scssScanner.js +95 -95
  25. package/lib/esm/services/cssCodeActions.js +77 -77
  26. package/lib/esm/services/cssCompletion.js +1054 -1054
  27. package/lib/esm/services/cssFolding.js +190 -190
  28. package/lib/esm/services/cssFormatter.js +136 -136
  29. package/lib/esm/services/cssHover.js +148 -148
  30. package/lib/esm/services/cssNavigation.js +441 -378
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -41
  33. package/lib/esm/services/lessCompletion.js +378 -378
  34. package/lib/esm/services/lint.js +518 -518
  35. package/lib/esm/services/lintRules.js +76 -76
  36. package/lib/esm/services/lintUtil.js +196 -196
  37. package/lib/esm/services/pathCompletion.js +157 -157
  38. package/lib/esm/services/scssCompletion.js +354 -354
  39. package/lib/esm/services/scssNavigation.js +82 -82
  40. package/lib/esm/services/selectorPrinting.js +492 -492
  41. package/lib/esm/utils/arrays.js +40 -40
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -11
  44. package/lib/esm/utils/strings.js +102 -102
  45. package/lib/umd/beautify/beautify-css.js +11 -4
  46. package/lib/umd/cssLanguageService.d.ts +38 -37
  47. package/lib/umd/cssLanguageService.js +104 -99
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  49. package/lib/umd/cssLanguageTypes.js +89 -89
  50. package/lib/umd/data/webCustomData.js +22102 -21972
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -492
  53. package/lib/umd/languageFacts/dataManager.js +101 -101
  54. package/lib/umd/languageFacts/dataProvider.js +86 -86
  55. package/lib/umd/languageFacts/entry.js +152 -152
  56. package/lib/umd/languageFacts/facts.js +33 -29
  57. package/lib/umd/parser/cssErrors.js +61 -61
  58. package/lib/umd/parser/cssNodes.js +1597 -1587
  59. package/lib/umd/parser/cssParser.js +1619 -1547
  60. package/lib/umd/parser/cssScanner.js +606 -606
  61. package/lib/umd/parser/cssSymbolScope.js +328 -328
  62. package/lib/umd/parser/lessParser.js +728 -727
  63. package/lib/umd/parser/lessScanner.js +70 -70
  64. package/lib/umd/parser/scssErrors.js +31 -31
  65. package/lib/umd/parser/scssParser.js +819 -809
  66. package/lib/umd/parser/scssScanner.js +108 -108
  67. package/lib/umd/services/cssCodeActions.js +90 -90
  68. package/lib/umd/services/cssCompletion.js +1067 -1067
  69. package/lib/umd/services/cssFolding.js +203 -203
  70. package/lib/umd/services/cssFormatter.js +150 -150
  71. package/lib/umd/services/cssHover.js +161 -161
  72. package/lib/umd/services/cssNavigation.js +454 -391
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -54
  75. package/lib/umd/services/lessCompletion.js +391 -391
  76. package/lib/umd/services/lint.js +531 -531
  77. package/lib/umd/services/lintRules.js +91 -91
  78. package/lib/umd/services/lintUtil.js +210 -210
  79. package/lib/umd/services/pathCompletion.js +171 -171
  80. package/lib/umd/services/scssCompletion.js +367 -367
  81. package/lib/umd/services/scssNavigation.js +95 -95
  82. package/lib/umd/services/selectorPrinting.js +510 -510
  83. package/lib/umd/utils/arrays.js +55 -55
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -26
  86. package/lib/umd/utils/strings.js +120 -120
  87. package/package.json +13 -12
@@ -1,727 +1,728 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./lessScanner", "./cssScanner", "./cssParser", "./cssNodes", "./cssErrors"], factory);
8
- }
9
- })(function (require, exports) {
10
- /*---------------------------------------------------------------------------------------------
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License. See License.txt in the project root for license information.
13
- *--------------------------------------------------------------------------------------------*/
14
- 'use strict';
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.LESSParser = void 0;
17
- const lessScanner = require("./lessScanner");
18
- const cssScanner_1 = require("./cssScanner");
19
- const cssParser = require("./cssParser");
20
- const nodes = require("./cssNodes");
21
- const cssErrors_1 = require("./cssErrors");
22
- /// <summary>
23
- /// A parser for LESS
24
- /// http://lesscss.org/
25
- /// </summary>
26
- class LESSParser extends cssParser.Parser {
27
- constructor() {
28
- super(new lessScanner.LESSScanner());
29
- }
30
- _parseStylesheetStatement(isNested = false) {
31
- if (this.peek(cssScanner_1.TokenType.AtKeyword)) {
32
- return this._parseVariableDeclaration()
33
- || this._parsePlugin()
34
- || super._parseStylesheetAtStatement(isNested);
35
- }
36
- return this._tryParseMixinDeclaration()
37
- || this._tryParseMixinReference()
38
- || this._parseFunction()
39
- || this._parseRuleset(true);
40
- }
41
- _parseImport() {
42
- if (!this.peekKeyword('@import') && !this.peekKeyword('@import-once') /* deprecated in less 1.4.1 */) {
43
- return null;
44
- }
45
- const node = this.create(nodes.Import);
46
- this.consumeToken();
47
- // less 1.4.1: @import (css) "lib"
48
- if (this.accept(cssScanner_1.TokenType.ParenthesisL)) {
49
- if (!this.accept(cssScanner_1.TokenType.Ident)) {
50
- return this.finish(node, cssErrors_1.ParseError.IdentifierExpected, [cssScanner_1.TokenType.SemiColon]);
51
- }
52
- do {
53
- if (!this.accept(cssScanner_1.TokenType.Comma)) {
54
- break;
55
- }
56
- } while (this.accept(cssScanner_1.TokenType.Ident));
57
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
58
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected, [cssScanner_1.TokenType.SemiColon]);
59
- }
60
- }
61
- if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
62
- return this.finish(node, cssErrors_1.ParseError.URIOrStringExpected, [cssScanner_1.TokenType.SemiColon]);
63
- }
64
- if (!this.peek(cssScanner_1.TokenType.SemiColon) && !this.peek(cssScanner_1.TokenType.EOF)) {
65
- node.setMedialist(this._parseMediaQueryList());
66
- }
67
- return this.finish(node);
68
- }
69
- _parsePlugin() {
70
- if (!this.peekKeyword('@plugin')) {
71
- return null;
72
- }
73
- const node = this.createNode(nodes.NodeType.Plugin);
74
- this.consumeToken(); // @import
75
- if (!node.addChild(this._parseStringLiteral())) {
76
- return this.finish(node, cssErrors_1.ParseError.StringLiteralExpected);
77
- }
78
- if (!this.accept(cssScanner_1.TokenType.SemiColon)) {
79
- return this.finish(node, cssErrors_1.ParseError.SemiColonExpected);
80
- }
81
- return this.finish(node);
82
- }
83
- _parseMediaQuery() {
84
- const node = super._parseMediaQuery();
85
- if (!node) {
86
- const node = this.create(nodes.MediaQuery);
87
- if (node.addChild(this._parseVariable())) {
88
- return this.finish(node);
89
- }
90
- return null;
91
- }
92
- return node;
93
- }
94
- _parseMediaDeclaration(isNested = false) {
95
- return this._tryParseRuleset(isNested)
96
- || this._tryToParseDeclaration()
97
- || this._tryParseMixinDeclaration()
98
- || this._tryParseMixinReference()
99
- || this._parseDetachedRuleSetMixin()
100
- || this._parseStylesheetStatement(isNested);
101
- }
102
- _parseMediaFeatureName() {
103
- return this._parseIdent() || this._parseVariable();
104
- }
105
- _parseVariableDeclaration(panic = []) {
106
- const node = this.create(nodes.VariableDeclaration);
107
- const mark = this.mark();
108
- if (!node.setVariable(this._parseVariable(true))) {
109
- return null;
110
- }
111
- if (this.accept(cssScanner_1.TokenType.Colon)) {
112
- if (this.prevToken) {
113
- node.colonPosition = this.prevToken.offset;
114
- }
115
- if (node.setValue(this._parseDetachedRuleSet())) {
116
- node.needsSemicolon = false;
117
- }
118
- else if (!node.setValue(this._parseExpr())) {
119
- return this.finish(node, cssErrors_1.ParseError.VariableValueExpected, [], panic);
120
- }
121
- node.addChild(this._parsePrio());
122
- }
123
- else {
124
- this.restoreAtMark(mark);
125
- return null; // at keyword, but no ':', not a variable declaration but some at keyword
126
- }
127
- if (this.peek(cssScanner_1.TokenType.SemiColon)) {
128
- node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
129
- }
130
- return this.finish(node);
131
- }
132
- _parseDetachedRuleSet() {
133
- let mark = this.mark();
134
- // "Anonymous mixin" used in each() and possibly a generic type in the future
135
- if (this.peekDelim('#') || this.peekDelim('.')) {
136
- this.consumeToken();
137
- if (!this.hasWhitespace() && this.accept(cssScanner_1.TokenType.ParenthesisL)) {
138
- let node = this.create(nodes.MixinDeclaration);
139
- if (node.getParameters().addChild(this._parseMixinParameter())) {
140
- while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
141
- if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
142
- break;
143
- }
144
- if (!node.getParameters().addChild(this._parseMixinParameter())) {
145
- this.markError(node, cssErrors_1.ParseError.IdentifierExpected, [], [cssScanner_1.TokenType.ParenthesisR]);
146
- }
147
- }
148
- }
149
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
150
- this.restoreAtMark(mark);
151
- return null;
152
- }
153
- }
154
- else {
155
- this.restoreAtMark(mark);
156
- return null;
157
- }
158
- }
159
- if (!this.peek(cssScanner_1.TokenType.CurlyL)) {
160
- return null;
161
- }
162
- const content = this.create(nodes.BodyDeclaration);
163
- this._parseBody(content, this._parseDetachedRuleSetBody.bind(this));
164
- return this.finish(content);
165
- }
166
- _parseDetachedRuleSetBody() {
167
- return this._tryParseKeyframeSelector() || this._parseRuleSetDeclaration();
168
- }
169
- _addLookupChildren(node) {
170
- if (!node.addChild(this._parseLookupValue())) {
171
- return false;
172
- }
173
- let expectsValue = false;
174
- while (true) {
175
- if (this.peek(cssScanner_1.TokenType.BracketL)) {
176
- expectsValue = true;
177
- }
178
- if (!node.addChild(this._parseLookupValue())) {
179
- break;
180
- }
181
- expectsValue = false;
182
- }
183
- return !expectsValue;
184
- }
185
- _parseLookupValue() {
186
- const node = this.create(nodes.Node);
187
- const mark = this.mark();
188
- if (!this.accept(cssScanner_1.TokenType.BracketL)) {
189
- this.restoreAtMark(mark);
190
- return null;
191
- }
192
- if (((node.addChild(this._parseVariable(false, true)) ||
193
- node.addChild(this._parsePropertyIdentifier())) &&
194
- this.accept(cssScanner_1.TokenType.BracketR)) || this.accept(cssScanner_1.TokenType.BracketR)) {
195
- return node;
196
- }
197
- this.restoreAtMark(mark);
198
- return null;
199
- }
200
- _parseVariable(declaration = false, insideLookup = false) {
201
- const isPropertyReference = !declaration && this.peekDelim('$');
202
- if (!this.peekDelim('@') && !isPropertyReference && !this.peek(cssScanner_1.TokenType.AtKeyword)) {
203
- return null;
204
- }
205
- const node = this.create(nodes.Variable);
206
- const mark = this.mark();
207
- while (this.acceptDelim('@') || (!declaration && this.acceptDelim('$'))) {
208
- if (this.hasWhitespace()) {
209
- this.restoreAtMark(mark);
210
- return null;
211
- }
212
- }
213
- if (!this.accept(cssScanner_1.TokenType.AtKeyword) && !this.accept(cssScanner_1.TokenType.Ident)) {
214
- this.restoreAtMark(mark);
215
- return null;
216
- }
217
- if (!insideLookup && this.peek(cssScanner_1.TokenType.BracketL)) {
218
- if (!this._addLookupChildren(node)) {
219
- this.restoreAtMark(mark);
220
- return null;
221
- }
222
- }
223
- return node;
224
- }
225
- _parseTermExpression() {
226
- return this._parseVariable() ||
227
- this._parseEscaped() ||
228
- super._parseTermExpression() || // preference for colors before mixin references
229
- this._tryParseMixinReference(false);
230
- }
231
- _parseEscaped() {
232
- if (this.peek(cssScanner_1.TokenType.EscapedJavaScript) ||
233
- this.peek(cssScanner_1.TokenType.BadEscapedJavaScript)) {
234
- const node = this.createNode(nodes.NodeType.EscapedValue);
235
- this.consumeToken();
236
- return this.finish(node);
237
- }
238
- if (this.peekDelim('~')) {
239
- const node = this.createNode(nodes.NodeType.EscapedValue);
240
- this.consumeToken();
241
- if (this.accept(cssScanner_1.TokenType.String) || this.accept(cssScanner_1.TokenType.EscapedJavaScript)) {
242
- return this.finish(node);
243
- }
244
- else {
245
- return this.finish(node, cssErrors_1.ParseError.TermExpected);
246
- }
247
- }
248
- return null;
249
- }
250
- _parseOperator() {
251
- const node = this._parseGuardOperator();
252
- if (node) {
253
- return node;
254
- }
255
- else {
256
- return super._parseOperator();
257
- }
258
- }
259
- _parseGuardOperator() {
260
- if (this.peekDelim('>')) {
261
- const node = this.createNode(nodes.NodeType.Operator);
262
- this.consumeToken();
263
- this.acceptDelim('=');
264
- return node;
265
- }
266
- else if (this.peekDelim('=')) {
267
- const node = this.createNode(nodes.NodeType.Operator);
268
- this.consumeToken();
269
- this.acceptDelim('<');
270
- return node;
271
- }
272
- else if (this.peekDelim('<')) {
273
- const node = this.createNode(nodes.NodeType.Operator);
274
- this.consumeToken();
275
- this.acceptDelim('=');
276
- return node;
277
- }
278
- return null;
279
- }
280
- _parseRuleSetDeclaration() {
281
- if (this.peek(cssScanner_1.TokenType.AtKeyword)) {
282
- return this._parseKeyframe()
283
- || this._parseMedia(true)
284
- || this._parseImport()
285
- || this._parseSupports(true) // @supports
286
- || this._parseDetachedRuleSetMixin() // less detached ruleset mixin
287
- || this._parseVariableDeclaration() // Variable declarations
288
- || super._parseRuleSetDeclarationAtStatement();
289
- }
290
- return this._tryParseMixinDeclaration()
291
- || this._tryParseRuleset(true) // nested ruleset
292
- || this._tryParseMixinReference() // less mixin reference
293
- || this._parseFunction()
294
- || this._parseExtend() // less extend declaration
295
- || super._parseRuleSetDeclaration(); // try css ruleset declaration as the last option
296
- }
297
- _parseKeyframeIdent() {
298
- return this._parseIdent([nodes.ReferenceType.Keyframe]) || this._parseVariable();
299
- }
300
- _parseKeyframeSelector() {
301
- return this._parseDetachedRuleSetMixin() // less detached ruleset mixin
302
- || super._parseKeyframeSelector();
303
- }
304
- _parseSimpleSelectorBody() {
305
- return this._parseSelectorCombinator() || super._parseSimpleSelectorBody();
306
- }
307
- _parseSelector(isNested) {
308
- // CSS Guards
309
- const node = this.create(nodes.Selector);
310
- let hasContent = false;
311
- if (isNested) {
312
- // nested selectors can start with a combinator
313
- hasContent = node.addChild(this._parseCombinator());
314
- }
315
- while (node.addChild(this._parseSimpleSelector())) {
316
- hasContent = true;
317
- const mark = this.mark();
318
- if (node.addChild(this._parseGuard()) && this.peek(cssScanner_1.TokenType.CurlyL)) {
319
- break;
320
- }
321
- this.restoreAtMark(mark);
322
- node.addChild(this._parseCombinator()); // optional
323
- }
324
- return hasContent ? this.finish(node) : null;
325
- }
326
- _parseSelectorCombinator() {
327
- if (this.peekDelim('&')) {
328
- const node = this.createNode(nodes.NodeType.SelectorCombinator);
329
- this.consumeToken();
330
- while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(cssScanner_1.TokenType.Num) || this.accept(cssScanner_1.TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) {
331
- // support &-foo
332
- }
333
- return this.finish(node);
334
- }
335
- return null;
336
- }
337
- _parseSelectorIdent() {
338
- if (!this.peekInterpolatedIdent()) {
339
- return null;
340
- }
341
- const node = this.createNode(nodes.NodeType.SelectorInterpolation);
342
- const hasContent = this._acceptInterpolatedIdent(node);
343
- return hasContent ? this.finish(node) : null;
344
- }
345
- _parsePropertyIdentifier(inLookup = false) {
346
- const propertyRegex = /^[\w-]+/;
347
- if (!this.peekInterpolatedIdent() && !this.peekRegExp(this.token.type, propertyRegex)) {
348
- return null;
349
- }
350
- const mark = this.mark();
351
- const node = this.create(nodes.Identifier);
352
- node.isCustomProperty = this.acceptDelim('-') && this.acceptDelim('-');
353
- let childAdded = false;
354
- if (!inLookup) {
355
- if (node.isCustomProperty) {
356
- childAdded = this._acceptInterpolatedIdent(node);
357
- }
358
- else {
359
- childAdded = this._acceptInterpolatedIdent(node, propertyRegex);
360
- }
361
- }
362
- else {
363
- if (node.isCustomProperty) {
364
- childAdded = node.addChild(this._parseIdent());
365
- }
366
- else {
367
- childAdded = node.addChild(this._parseRegexp(propertyRegex));
368
- }
369
- }
370
- if (!childAdded) {
371
- this.restoreAtMark(mark);
372
- return null;
373
- }
374
- if (!inLookup && !this.hasWhitespace()) {
375
- this.acceptDelim('+');
376
- if (!this.hasWhitespace()) {
377
- this.acceptIdent('_');
378
- }
379
- }
380
- return this.finish(node);
381
- }
382
- peekInterpolatedIdent() {
383
- return this.peek(cssScanner_1.TokenType.Ident) ||
384
- this.peekDelim('@') ||
385
- this.peekDelim('$') ||
386
- this.peekDelim('-');
387
- }
388
- _acceptInterpolatedIdent(node, identRegex) {
389
- let hasContent = false;
390
- const indentInterpolation = () => {
391
- const pos = this.mark();
392
- if (this.acceptDelim('-')) {
393
- if (!this.hasWhitespace()) {
394
- this.acceptDelim('-');
395
- }
396
- if (this.hasWhitespace()) {
397
- this.restoreAtMark(pos);
398
- return null;
399
- }
400
- }
401
- return this._parseInterpolation();
402
- };
403
- const accept = identRegex ?
404
- () => this.acceptRegexp(identRegex) :
405
- () => this.accept(cssScanner_1.TokenType.Ident);
406
- while (accept() ||
407
- node.addChild(this._parseInterpolation() ||
408
- this.try(indentInterpolation))) {
409
- hasContent = true;
410
- if (this.hasWhitespace()) {
411
- break;
412
- }
413
- }
414
- return hasContent;
415
- }
416
- _parseInterpolation() {
417
- // @{name} Variable or
418
- // ${name} Property
419
- const mark = this.mark();
420
- if (this.peekDelim('@') || this.peekDelim('$')) {
421
- const node = this.createNode(nodes.NodeType.Interpolation);
422
- this.consumeToken();
423
- if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.CurlyL)) {
424
- this.restoreAtMark(mark);
425
- return null;
426
- }
427
- if (!node.addChild(this._parseIdent())) {
428
- return this.finish(node, cssErrors_1.ParseError.IdentifierExpected);
429
- }
430
- if (!this.accept(cssScanner_1.TokenType.CurlyR)) {
431
- return this.finish(node, cssErrors_1.ParseError.RightCurlyExpected);
432
- }
433
- return this.finish(node);
434
- }
435
- return null;
436
- }
437
- _tryParseMixinDeclaration() {
438
- const mark = this.mark();
439
- const node = this.create(nodes.MixinDeclaration);
440
- if (!node.setIdentifier(this._parseMixinDeclarationIdentifier()) || !this.accept(cssScanner_1.TokenType.ParenthesisL)) {
441
- this.restoreAtMark(mark);
442
- return null;
443
- }
444
- if (node.getParameters().addChild(this._parseMixinParameter())) {
445
- while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
446
- if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
447
- break;
448
- }
449
- if (!node.getParameters().addChild(this._parseMixinParameter())) {
450
- this.markError(node, cssErrors_1.ParseError.IdentifierExpected, [], [cssScanner_1.TokenType.ParenthesisR]);
451
- }
452
- }
453
- }
454
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
455
- this.restoreAtMark(mark);
456
- return null;
457
- }
458
- node.setGuard(this._parseGuard());
459
- if (!this.peek(cssScanner_1.TokenType.CurlyL)) {
460
- this.restoreAtMark(mark);
461
- return null;
462
- }
463
- return this._parseBody(node, this._parseMixInBodyDeclaration.bind(this));
464
- }
465
- _parseMixInBodyDeclaration() {
466
- return this._parseFontFace() || this._parseRuleSetDeclaration();
467
- }
468
- _parseMixinDeclarationIdentifier() {
469
- let identifier;
470
- if (this.peekDelim('#') || this.peekDelim('.')) {
471
- identifier = this.create(nodes.Identifier);
472
- this.consumeToken(); // # or .
473
- if (this.hasWhitespace() || !identifier.addChild(this._parseIdent())) {
474
- return null;
475
- }
476
- }
477
- else if (this.peek(cssScanner_1.TokenType.Hash)) {
478
- identifier = this.create(nodes.Identifier);
479
- this.consumeToken(); // TokenType.Hash
480
- }
481
- else {
482
- return null;
483
- }
484
- identifier.referenceTypes = [nodes.ReferenceType.Mixin];
485
- return this.finish(identifier);
486
- }
487
- _parsePseudo() {
488
- if (!this.peek(cssScanner_1.TokenType.Colon)) {
489
- return null;
490
- }
491
- const mark = this.mark();
492
- const node = this.create(nodes.ExtendsReference);
493
- this.consumeToken(); // :
494
- if (this.acceptIdent('extend')) {
495
- return this._completeExtends(node);
496
- }
497
- this.restoreAtMark(mark);
498
- return super._parsePseudo();
499
- }
500
- _parseExtend() {
501
- if (!this.peekDelim('&')) {
502
- return null;
503
- }
504
- const mark = this.mark();
505
- const node = this.create(nodes.ExtendsReference);
506
- this.consumeToken(); // &
507
- if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.Colon) || !this.acceptIdent('extend')) {
508
- this.restoreAtMark(mark);
509
- return null;
510
- }
511
- return this._completeExtends(node);
512
- }
513
- _completeExtends(node) {
514
- if (!this.accept(cssScanner_1.TokenType.ParenthesisL)) {
515
- return this.finish(node, cssErrors_1.ParseError.LeftParenthesisExpected);
516
- }
517
- const selectors = node.getSelectors();
518
- if (!selectors.addChild(this._parseSelector(true))) {
519
- return this.finish(node, cssErrors_1.ParseError.SelectorExpected);
520
- }
521
- while (this.accept(cssScanner_1.TokenType.Comma)) {
522
- if (!selectors.addChild(this._parseSelector(true))) {
523
- return this.finish(node, cssErrors_1.ParseError.SelectorExpected);
524
- }
525
- }
526
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
527
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
528
- }
529
- return this.finish(node);
530
- }
531
- _parseDetachedRuleSetMixin() {
532
- if (!this.peek(cssScanner_1.TokenType.AtKeyword)) {
533
- return null;
534
- }
535
- const mark = this.mark();
536
- const node = this.create(nodes.MixinReference);
537
- if (node.addChild(this._parseVariable(true)) && (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.ParenthesisL))) {
538
- this.restoreAtMark(mark);
539
- return null;
540
- }
541
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
542
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
543
- }
544
- return this.finish(node);
545
- }
546
- _tryParseMixinReference(atRoot = true) {
547
- const mark = this.mark();
548
- const node = this.create(nodes.MixinReference);
549
- let identifier = this._parseMixinDeclarationIdentifier();
550
- while (identifier) {
551
- this.acceptDelim('>');
552
- const nextId = this._parseMixinDeclarationIdentifier();
553
- if (nextId) {
554
- node.getNamespaces().addChild(identifier);
555
- identifier = nextId;
556
- }
557
- else {
558
- break;
559
- }
560
- }
561
- if (!node.setIdentifier(identifier)) {
562
- this.restoreAtMark(mark);
563
- return null;
564
- }
565
- let hasArguments = false;
566
- if (this.accept(cssScanner_1.TokenType.ParenthesisL)) {
567
- hasArguments = true;
568
- if (node.getArguments().addChild(this._parseMixinArgument())) {
569
- while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
570
- if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
571
- break;
572
- }
573
- if (!node.getArguments().addChild(this._parseMixinArgument())) {
574
- return this.finish(node, cssErrors_1.ParseError.ExpressionExpected);
575
- }
576
- }
577
- }
578
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
579
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
580
- }
581
- identifier.referenceTypes = [nodes.ReferenceType.Mixin];
582
- }
583
- else {
584
- identifier.referenceTypes = [nodes.ReferenceType.Mixin, nodes.ReferenceType.Rule];
585
- }
586
- if (this.peek(cssScanner_1.TokenType.BracketL)) {
587
- if (!atRoot) {
588
- this._addLookupChildren(node);
589
- }
590
- }
591
- else {
592
- node.addChild(this._parsePrio());
593
- }
594
- if (!hasArguments && !this.peek(cssScanner_1.TokenType.SemiColon) && !this.peek(cssScanner_1.TokenType.CurlyR) && !this.peek(cssScanner_1.TokenType.EOF)) {
595
- this.restoreAtMark(mark);
596
- return null;
597
- }
598
- return this.finish(node);
599
- }
600
- _parseMixinArgument() {
601
- // [variableName ':'] expression | variableName '...'
602
- const node = this.create(nodes.FunctionArgument);
603
- const pos = this.mark();
604
- const argument = this._parseVariable();
605
- if (argument) {
606
- if (!this.accept(cssScanner_1.TokenType.Colon)) {
607
- this.restoreAtMark(pos);
608
- }
609
- else {
610
- node.setIdentifier(argument);
611
- }
612
- }
613
- if (node.setValue(this._parseDetachedRuleSet() || this._parseExpr(true))) {
614
- return this.finish(node);
615
- }
616
- this.restoreAtMark(pos);
617
- return null;
618
- }
619
- _parseMixinParameter() {
620
- const node = this.create(nodes.FunctionParameter);
621
- // special rest variable: @rest...
622
- if (this.peekKeyword('@rest')) {
623
- const restNode = this.create(nodes.Node);
624
- this.consumeToken();
625
- if (!this.accept(lessScanner.Ellipsis)) {
626
- return this.finish(node, cssErrors_1.ParseError.DotExpected, [], [cssScanner_1.TokenType.Comma, cssScanner_1.TokenType.ParenthesisR]);
627
- }
628
- node.setIdentifier(this.finish(restNode));
629
- return this.finish(node);
630
- }
631
- // special const args: ...
632
- if (this.peek(lessScanner.Ellipsis)) {
633
- const varargsNode = this.create(nodes.Node);
634
- this.consumeToken();
635
- node.setIdentifier(this.finish(varargsNode));
636
- return this.finish(node);
637
- }
638
- let hasContent = false;
639
- // default variable declaration: @param: 12 or @name
640
- if (node.setIdentifier(this._parseVariable())) {
641
- this.accept(cssScanner_1.TokenType.Colon);
642
- hasContent = true;
643
- }
644
- if (!node.setDefaultValue(this._parseDetachedRuleSet() || this._parseExpr(true)) && !hasContent) {
645
- return null;
646
- }
647
- return this.finish(node);
648
- }
649
- _parseGuard() {
650
- if (!this.peekIdent('when')) {
651
- return null;
652
- }
653
- const node = this.create(nodes.LessGuard);
654
- this.consumeToken(); // when
655
- node.isNegated = this.acceptIdent('not');
656
- if (!node.getConditions().addChild(this._parseGuardCondition())) {
657
- return this.finish(node, cssErrors_1.ParseError.ConditionExpected);
658
- }
659
- while (this.acceptIdent('and') || this.accept(cssScanner_1.TokenType.Comma)) {
660
- if (!node.getConditions().addChild(this._parseGuardCondition())) {
661
- return this.finish(node, cssErrors_1.ParseError.ConditionExpected);
662
- }
663
- }
664
- return this.finish(node);
665
- }
666
- _parseGuardCondition() {
667
- if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) {
668
- return null;
669
- }
670
- const node = this.create(nodes.GuardCondition);
671
- this.consumeToken(); // ParenthesisL
672
- if (!node.addChild(this._parseExpr())) {
673
- // empty (?)
674
- }
675
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
676
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
677
- }
678
- return this.finish(node);
679
- }
680
- _parseFunction() {
681
- const pos = this.mark();
682
- const node = this.create(nodes.Function);
683
- if (!node.setIdentifier(this._parseFunctionIdentifier())) {
684
- return null;
685
- }
686
- if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.ParenthesisL)) {
687
- this.restoreAtMark(pos);
688
- return null;
689
- }
690
- if (node.getArguments().addChild(this._parseMixinArgument())) {
691
- while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
692
- if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
693
- break;
694
- }
695
- if (!node.getArguments().addChild(this._parseMixinArgument())) {
696
- return this.finish(node, cssErrors_1.ParseError.ExpressionExpected);
697
- }
698
- }
699
- }
700
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
701
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
702
- }
703
- return this.finish(node);
704
- }
705
- _parseFunctionIdentifier() {
706
- if (this.peekDelim('%')) {
707
- const node = this.create(nodes.Identifier);
708
- node.referenceTypes = [nodes.ReferenceType.Function];
709
- this.consumeToken();
710
- return this.finish(node);
711
- }
712
- return super._parseFunctionIdentifier();
713
- }
714
- _parseURLArgument() {
715
- const pos = this.mark();
716
- const node = super._parseURLArgument();
717
- if (!node || !this.peek(cssScanner_1.TokenType.ParenthesisR)) {
718
- this.restoreAtMark(pos);
719
- const node = this.create(nodes.Node);
720
- node.addChild(this._parseBinaryExpr());
721
- return this.finish(node);
722
- }
723
- return node;
724
- }
725
- }
726
- exports.LESSParser = LESSParser;
727
- });
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./lessScanner", "./cssScanner", "./cssParser", "./cssNodes", "./cssErrors"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ /*---------------------------------------------------------------------------------------------
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License. See License.txt in the project root for license information.
13
+ *--------------------------------------------------------------------------------------------*/
14
+ 'use strict';
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.LESSParser = void 0;
17
+ const lessScanner = require("./lessScanner");
18
+ const cssScanner_1 = require("./cssScanner");
19
+ const cssParser = require("./cssParser");
20
+ const nodes = require("./cssNodes");
21
+ const cssErrors_1 = require("./cssErrors");
22
+ /// <summary>
23
+ /// A parser for LESS
24
+ /// http://lesscss.org/
25
+ /// </summary>
26
+ class LESSParser extends cssParser.Parser {
27
+ constructor() {
28
+ super(new lessScanner.LESSScanner());
29
+ }
30
+ _parseStylesheetStatement(isNested = false) {
31
+ if (this.peek(cssScanner_1.TokenType.AtKeyword)) {
32
+ return this._parseVariableDeclaration()
33
+ || this._parsePlugin()
34
+ || super._parseStylesheetAtStatement(isNested);
35
+ }
36
+ return this._tryParseMixinDeclaration()
37
+ || this._tryParseMixinReference()
38
+ || this._parseFunction()
39
+ || this._parseRuleset(true);
40
+ }
41
+ _parseImport() {
42
+ if (!this.peekKeyword('@import') && !this.peekKeyword('@import-once') /* deprecated in less 1.4.1 */) {
43
+ return null;
44
+ }
45
+ const node = this.create(nodes.Import);
46
+ this.consumeToken();
47
+ // less 1.4.1: @import (css) "lib"
48
+ if (this.accept(cssScanner_1.TokenType.ParenthesisL)) {
49
+ if (!this.accept(cssScanner_1.TokenType.Ident)) {
50
+ return this.finish(node, cssErrors_1.ParseError.IdentifierExpected, [cssScanner_1.TokenType.SemiColon]);
51
+ }
52
+ do {
53
+ if (!this.accept(cssScanner_1.TokenType.Comma)) {
54
+ break;
55
+ }
56
+ } while (this.accept(cssScanner_1.TokenType.Ident));
57
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
58
+ return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected, [cssScanner_1.TokenType.SemiColon]);
59
+ }
60
+ }
61
+ if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
62
+ return this.finish(node, cssErrors_1.ParseError.URIOrStringExpected, [cssScanner_1.TokenType.SemiColon]);
63
+ }
64
+ if (!this.peek(cssScanner_1.TokenType.SemiColon) && !this.peek(cssScanner_1.TokenType.EOF)) {
65
+ node.setMedialist(this._parseMediaQueryList());
66
+ }
67
+ return this.finish(node);
68
+ }
69
+ _parsePlugin() {
70
+ if (!this.peekKeyword('@plugin')) {
71
+ return null;
72
+ }
73
+ const node = this.createNode(nodes.NodeType.Plugin);
74
+ this.consumeToken(); // @import
75
+ if (!node.addChild(this._parseStringLiteral())) {
76
+ return this.finish(node, cssErrors_1.ParseError.StringLiteralExpected);
77
+ }
78
+ if (!this.accept(cssScanner_1.TokenType.SemiColon)) {
79
+ return this.finish(node, cssErrors_1.ParseError.SemiColonExpected);
80
+ }
81
+ return this.finish(node);
82
+ }
83
+ _parseMediaQuery() {
84
+ const node = super._parseMediaQuery();
85
+ if (!node) {
86
+ const node = this.create(nodes.MediaQuery);
87
+ if (node.addChild(this._parseVariable())) {
88
+ return this.finish(node);
89
+ }
90
+ return null;
91
+ }
92
+ return node;
93
+ }
94
+ _parseMediaDeclaration(isNested = false) {
95
+ return this._tryParseRuleset(isNested)
96
+ || this._tryToParseDeclaration()
97
+ || this._tryParseMixinDeclaration()
98
+ || this._tryParseMixinReference()
99
+ || this._parseDetachedRuleSetMixin()
100
+ || this._parseStylesheetStatement(isNested);
101
+ }
102
+ _parseMediaFeatureName() {
103
+ return this._parseIdent() || this._parseVariable();
104
+ }
105
+ _parseVariableDeclaration(panic = []) {
106
+ const node = this.create(nodes.VariableDeclaration);
107
+ const mark = this.mark();
108
+ if (!node.setVariable(this._parseVariable(true))) {
109
+ return null;
110
+ }
111
+ if (this.accept(cssScanner_1.TokenType.Colon)) {
112
+ if (this.prevToken) {
113
+ node.colonPosition = this.prevToken.offset;
114
+ }
115
+ if (node.setValue(this._parseDetachedRuleSet())) {
116
+ node.needsSemicolon = false;
117
+ }
118
+ else if (!node.setValue(this._parseExpr())) {
119
+ return this.finish(node, cssErrors_1.ParseError.VariableValueExpected, [], panic);
120
+ }
121
+ node.addChild(this._parsePrio());
122
+ }
123
+ else {
124
+ this.restoreAtMark(mark);
125
+ return null; // at keyword, but no ':', not a variable declaration but some at keyword
126
+ }
127
+ if (this.peek(cssScanner_1.TokenType.SemiColon)) {
128
+ node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
129
+ }
130
+ return this.finish(node);
131
+ }
132
+ _parseDetachedRuleSet() {
133
+ let mark = this.mark();
134
+ // "Anonymous mixin" used in each() and possibly a generic type in the future
135
+ if (this.peekDelim('#') || this.peekDelim('.')) {
136
+ this.consumeToken();
137
+ if (!this.hasWhitespace() && this.accept(cssScanner_1.TokenType.ParenthesisL)) {
138
+ let node = this.create(nodes.MixinDeclaration);
139
+ if (node.getParameters().addChild(this._parseMixinParameter())) {
140
+ while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
141
+ if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
142
+ break;
143
+ }
144
+ if (!node.getParameters().addChild(this._parseMixinParameter())) {
145
+ this.markError(node, cssErrors_1.ParseError.IdentifierExpected, [], [cssScanner_1.TokenType.ParenthesisR]);
146
+ }
147
+ }
148
+ }
149
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
150
+ this.restoreAtMark(mark);
151
+ return null;
152
+ }
153
+ }
154
+ else {
155
+ this.restoreAtMark(mark);
156
+ return null;
157
+ }
158
+ }
159
+ if (!this.peek(cssScanner_1.TokenType.CurlyL)) {
160
+ return null;
161
+ }
162
+ const content = this.create(nodes.BodyDeclaration);
163
+ this._parseBody(content, this._parseDetachedRuleSetBody.bind(this));
164
+ return this.finish(content);
165
+ }
166
+ _parseDetachedRuleSetBody() {
167
+ return this._tryParseKeyframeSelector() || this._parseRuleSetDeclaration();
168
+ }
169
+ _addLookupChildren(node) {
170
+ if (!node.addChild(this._parseLookupValue())) {
171
+ return false;
172
+ }
173
+ let expectsValue = false;
174
+ while (true) {
175
+ if (this.peek(cssScanner_1.TokenType.BracketL)) {
176
+ expectsValue = true;
177
+ }
178
+ if (!node.addChild(this._parseLookupValue())) {
179
+ break;
180
+ }
181
+ expectsValue = false;
182
+ }
183
+ return !expectsValue;
184
+ }
185
+ _parseLookupValue() {
186
+ const node = this.create(nodes.Node);
187
+ const mark = this.mark();
188
+ if (!this.accept(cssScanner_1.TokenType.BracketL)) {
189
+ this.restoreAtMark(mark);
190
+ return null;
191
+ }
192
+ if (((node.addChild(this._parseVariable(false, true)) ||
193
+ node.addChild(this._parsePropertyIdentifier())) &&
194
+ this.accept(cssScanner_1.TokenType.BracketR)) || this.accept(cssScanner_1.TokenType.BracketR)) {
195
+ return node;
196
+ }
197
+ this.restoreAtMark(mark);
198
+ return null;
199
+ }
200
+ _parseVariable(declaration = false, insideLookup = false) {
201
+ const isPropertyReference = !declaration && this.peekDelim('$');
202
+ if (!this.peekDelim('@') && !isPropertyReference && !this.peek(cssScanner_1.TokenType.AtKeyword)) {
203
+ return null;
204
+ }
205
+ const node = this.create(nodes.Variable);
206
+ const mark = this.mark();
207
+ while (this.acceptDelim('@') || (!declaration && this.acceptDelim('$'))) {
208
+ if (this.hasWhitespace()) {
209
+ this.restoreAtMark(mark);
210
+ return null;
211
+ }
212
+ }
213
+ if (!this.accept(cssScanner_1.TokenType.AtKeyword) && !this.accept(cssScanner_1.TokenType.Ident)) {
214
+ this.restoreAtMark(mark);
215
+ return null;
216
+ }
217
+ if (!insideLookup && this.peek(cssScanner_1.TokenType.BracketL)) {
218
+ if (!this._addLookupChildren(node)) {
219
+ this.restoreAtMark(mark);
220
+ return null;
221
+ }
222
+ }
223
+ return node;
224
+ }
225
+ _parseTermExpression() {
226
+ return this._parseVariable() ||
227
+ this._parseEscaped() ||
228
+ super._parseTermExpression() || // preference for colors before mixin references
229
+ this._tryParseMixinReference(false);
230
+ }
231
+ _parseEscaped() {
232
+ if (this.peek(cssScanner_1.TokenType.EscapedJavaScript) ||
233
+ this.peek(cssScanner_1.TokenType.BadEscapedJavaScript)) {
234
+ const node = this.createNode(nodes.NodeType.EscapedValue);
235
+ this.consumeToken();
236
+ return this.finish(node);
237
+ }
238
+ if (this.peekDelim('~')) {
239
+ const node = this.createNode(nodes.NodeType.EscapedValue);
240
+ this.consumeToken();
241
+ if (this.accept(cssScanner_1.TokenType.String) || this.accept(cssScanner_1.TokenType.EscapedJavaScript)) {
242
+ return this.finish(node);
243
+ }
244
+ else {
245
+ return this.finish(node, cssErrors_1.ParseError.TermExpected);
246
+ }
247
+ }
248
+ return null;
249
+ }
250
+ _parseOperator() {
251
+ const node = this._parseGuardOperator();
252
+ if (node) {
253
+ return node;
254
+ }
255
+ else {
256
+ return super._parseOperator();
257
+ }
258
+ }
259
+ _parseGuardOperator() {
260
+ if (this.peekDelim('>')) {
261
+ const node = this.createNode(nodes.NodeType.Operator);
262
+ this.consumeToken();
263
+ this.acceptDelim('=');
264
+ return node;
265
+ }
266
+ else if (this.peekDelim('=')) {
267
+ const node = this.createNode(nodes.NodeType.Operator);
268
+ this.consumeToken();
269
+ this.acceptDelim('<');
270
+ return node;
271
+ }
272
+ else if (this.peekDelim('<')) {
273
+ const node = this.createNode(nodes.NodeType.Operator);
274
+ this.consumeToken();
275
+ this.acceptDelim('=');
276
+ return node;
277
+ }
278
+ return null;
279
+ }
280
+ _parseRuleSetDeclaration() {
281
+ if (this.peek(cssScanner_1.TokenType.AtKeyword)) {
282
+ return this._parseKeyframe()
283
+ || this._parseMedia(true)
284
+ || this._parseImport()
285
+ || this._parseSupports(true) // @supports
286
+ || this._parseLayer() // @layer
287
+ || this._parseDetachedRuleSetMixin() // less detached ruleset mixin
288
+ || this._parseVariableDeclaration() // Variable declarations
289
+ || super._parseRuleSetDeclarationAtStatement();
290
+ }
291
+ return this._tryParseMixinDeclaration()
292
+ || this._tryParseRuleset(true) // nested ruleset
293
+ || this._tryParseMixinReference() // less mixin reference
294
+ || this._parseFunction()
295
+ || this._parseExtend() // less extend declaration
296
+ || super._parseRuleSetDeclaration(); // try css ruleset declaration as the last option
297
+ }
298
+ _parseKeyframeIdent() {
299
+ return this._parseIdent([nodes.ReferenceType.Keyframe]) || this._parseVariable();
300
+ }
301
+ _parseKeyframeSelector() {
302
+ return this._parseDetachedRuleSetMixin() // less detached ruleset mixin
303
+ || super._parseKeyframeSelector();
304
+ }
305
+ _parseSimpleSelectorBody() {
306
+ return this._parseSelectorCombinator() || super._parseSimpleSelectorBody();
307
+ }
308
+ _parseSelector(isNested) {
309
+ // CSS Guards
310
+ const node = this.create(nodes.Selector);
311
+ let hasContent = false;
312
+ if (isNested) {
313
+ // nested selectors can start with a combinator
314
+ hasContent = node.addChild(this._parseCombinator());
315
+ }
316
+ while (node.addChild(this._parseSimpleSelector())) {
317
+ hasContent = true;
318
+ const mark = this.mark();
319
+ if (node.addChild(this._parseGuard()) && this.peek(cssScanner_1.TokenType.CurlyL)) {
320
+ break;
321
+ }
322
+ this.restoreAtMark(mark);
323
+ node.addChild(this._parseCombinator()); // optional
324
+ }
325
+ return hasContent ? this.finish(node) : null;
326
+ }
327
+ _parseSelectorCombinator() {
328
+ if (this.peekDelim('&')) {
329
+ const node = this.createNode(nodes.NodeType.SelectorCombinator);
330
+ this.consumeToken();
331
+ while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(cssScanner_1.TokenType.Num) || this.accept(cssScanner_1.TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) {
332
+ // support &-foo
333
+ }
334
+ return this.finish(node);
335
+ }
336
+ return null;
337
+ }
338
+ _parseSelectorIdent() {
339
+ if (!this.peekInterpolatedIdent()) {
340
+ return null;
341
+ }
342
+ const node = this.createNode(nodes.NodeType.SelectorInterpolation);
343
+ const hasContent = this._acceptInterpolatedIdent(node);
344
+ return hasContent ? this.finish(node) : null;
345
+ }
346
+ _parsePropertyIdentifier(inLookup = false) {
347
+ const propertyRegex = /^[\w-]+/;
348
+ if (!this.peekInterpolatedIdent() && !this.peekRegExp(this.token.type, propertyRegex)) {
349
+ return null;
350
+ }
351
+ const mark = this.mark();
352
+ const node = this.create(nodes.Identifier);
353
+ node.isCustomProperty = this.acceptDelim('-') && this.acceptDelim('-');
354
+ let childAdded = false;
355
+ if (!inLookup) {
356
+ if (node.isCustomProperty) {
357
+ childAdded = this._acceptInterpolatedIdent(node);
358
+ }
359
+ else {
360
+ childAdded = this._acceptInterpolatedIdent(node, propertyRegex);
361
+ }
362
+ }
363
+ else {
364
+ if (node.isCustomProperty) {
365
+ childAdded = node.addChild(this._parseIdent());
366
+ }
367
+ else {
368
+ childAdded = node.addChild(this._parseRegexp(propertyRegex));
369
+ }
370
+ }
371
+ if (!childAdded) {
372
+ this.restoreAtMark(mark);
373
+ return null;
374
+ }
375
+ if (!inLookup && !this.hasWhitespace()) {
376
+ this.acceptDelim('+');
377
+ if (!this.hasWhitespace()) {
378
+ this.acceptIdent('_');
379
+ }
380
+ }
381
+ return this.finish(node);
382
+ }
383
+ peekInterpolatedIdent() {
384
+ return this.peek(cssScanner_1.TokenType.Ident) ||
385
+ this.peekDelim('@') ||
386
+ this.peekDelim('$') ||
387
+ this.peekDelim('-');
388
+ }
389
+ _acceptInterpolatedIdent(node, identRegex) {
390
+ let hasContent = false;
391
+ const indentInterpolation = () => {
392
+ const pos = this.mark();
393
+ if (this.acceptDelim('-')) {
394
+ if (!this.hasWhitespace()) {
395
+ this.acceptDelim('-');
396
+ }
397
+ if (this.hasWhitespace()) {
398
+ this.restoreAtMark(pos);
399
+ return null;
400
+ }
401
+ }
402
+ return this._parseInterpolation();
403
+ };
404
+ const accept = identRegex ?
405
+ () => this.acceptRegexp(identRegex) :
406
+ () => this.accept(cssScanner_1.TokenType.Ident);
407
+ while (accept() ||
408
+ node.addChild(this._parseInterpolation() ||
409
+ this.try(indentInterpolation))) {
410
+ hasContent = true;
411
+ if (this.hasWhitespace()) {
412
+ break;
413
+ }
414
+ }
415
+ return hasContent;
416
+ }
417
+ _parseInterpolation() {
418
+ // @{name} Variable or
419
+ // ${name} Property
420
+ const mark = this.mark();
421
+ if (this.peekDelim('@') || this.peekDelim('$')) {
422
+ const node = this.createNode(nodes.NodeType.Interpolation);
423
+ this.consumeToken();
424
+ if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.CurlyL)) {
425
+ this.restoreAtMark(mark);
426
+ return null;
427
+ }
428
+ if (!node.addChild(this._parseIdent())) {
429
+ return this.finish(node, cssErrors_1.ParseError.IdentifierExpected);
430
+ }
431
+ if (!this.accept(cssScanner_1.TokenType.CurlyR)) {
432
+ return this.finish(node, cssErrors_1.ParseError.RightCurlyExpected);
433
+ }
434
+ return this.finish(node);
435
+ }
436
+ return null;
437
+ }
438
+ _tryParseMixinDeclaration() {
439
+ const mark = this.mark();
440
+ const node = this.create(nodes.MixinDeclaration);
441
+ if (!node.setIdentifier(this._parseMixinDeclarationIdentifier()) || !this.accept(cssScanner_1.TokenType.ParenthesisL)) {
442
+ this.restoreAtMark(mark);
443
+ return null;
444
+ }
445
+ if (node.getParameters().addChild(this._parseMixinParameter())) {
446
+ while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
447
+ if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
448
+ break;
449
+ }
450
+ if (!node.getParameters().addChild(this._parseMixinParameter())) {
451
+ this.markError(node, cssErrors_1.ParseError.IdentifierExpected, [], [cssScanner_1.TokenType.ParenthesisR]);
452
+ }
453
+ }
454
+ }
455
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
456
+ this.restoreAtMark(mark);
457
+ return null;
458
+ }
459
+ node.setGuard(this._parseGuard());
460
+ if (!this.peek(cssScanner_1.TokenType.CurlyL)) {
461
+ this.restoreAtMark(mark);
462
+ return null;
463
+ }
464
+ return this._parseBody(node, this._parseMixInBodyDeclaration.bind(this));
465
+ }
466
+ _parseMixInBodyDeclaration() {
467
+ return this._parseFontFace() || this._parseRuleSetDeclaration();
468
+ }
469
+ _parseMixinDeclarationIdentifier() {
470
+ let identifier;
471
+ if (this.peekDelim('#') || this.peekDelim('.')) {
472
+ identifier = this.create(nodes.Identifier);
473
+ this.consumeToken(); // # or .
474
+ if (this.hasWhitespace() || !identifier.addChild(this._parseIdent())) {
475
+ return null;
476
+ }
477
+ }
478
+ else if (this.peek(cssScanner_1.TokenType.Hash)) {
479
+ identifier = this.create(nodes.Identifier);
480
+ this.consumeToken(); // TokenType.Hash
481
+ }
482
+ else {
483
+ return null;
484
+ }
485
+ identifier.referenceTypes = [nodes.ReferenceType.Mixin];
486
+ return this.finish(identifier);
487
+ }
488
+ _parsePseudo() {
489
+ if (!this.peek(cssScanner_1.TokenType.Colon)) {
490
+ return null;
491
+ }
492
+ const mark = this.mark();
493
+ const node = this.create(nodes.ExtendsReference);
494
+ this.consumeToken(); // :
495
+ if (this.acceptIdent('extend')) {
496
+ return this._completeExtends(node);
497
+ }
498
+ this.restoreAtMark(mark);
499
+ return super._parsePseudo();
500
+ }
501
+ _parseExtend() {
502
+ if (!this.peekDelim('&')) {
503
+ return null;
504
+ }
505
+ const mark = this.mark();
506
+ const node = this.create(nodes.ExtendsReference);
507
+ this.consumeToken(); // &
508
+ if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.Colon) || !this.acceptIdent('extend')) {
509
+ this.restoreAtMark(mark);
510
+ return null;
511
+ }
512
+ return this._completeExtends(node);
513
+ }
514
+ _completeExtends(node) {
515
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisL)) {
516
+ return this.finish(node, cssErrors_1.ParseError.LeftParenthesisExpected);
517
+ }
518
+ const selectors = node.getSelectors();
519
+ if (!selectors.addChild(this._parseSelector(true))) {
520
+ return this.finish(node, cssErrors_1.ParseError.SelectorExpected);
521
+ }
522
+ while (this.accept(cssScanner_1.TokenType.Comma)) {
523
+ if (!selectors.addChild(this._parseSelector(true))) {
524
+ return this.finish(node, cssErrors_1.ParseError.SelectorExpected);
525
+ }
526
+ }
527
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
528
+ return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
529
+ }
530
+ return this.finish(node);
531
+ }
532
+ _parseDetachedRuleSetMixin() {
533
+ if (!this.peek(cssScanner_1.TokenType.AtKeyword)) {
534
+ return null;
535
+ }
536
+ const mark = this.mark();
537
+ const node = this.create(nodes.MixinReference);
538
+ if (node.addChild(this._parseVariable(true)) && (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.ParenthesisL))) {
539
+ this.restoreAtMark(mark);
540
+ return null;
541
+ }
542
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
543
+ return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
544
+ }
545
+ return this.finish(node);
546
+ }
547
+ _tryParseMixinReference(atRoot = true) {
548
+ const mark = this.mark();
549
+ const node = this.create(nodes.MixinReference);
550
+ let identifier = this._parseMixinDeclarationIdentifier();
551
+ while (identifier) {
552
+ this.acceptDelim('>');
553
+ const nextId = this._parseMixinDeclarationIdentifier();
554
+ if (nextId) {
555
+ node.getNamespaces().addChild(identifier);
556
+ identifier = nextId;
557
+ }
558
+ else {
559
+ break;
560
+ }
561
+ }
562
+ if (!node.setIdentifier(identifier)) {
563
+ this.restoreAtMark(mark);
564
+ return null;
565
+ }
566
+ let hasArguments = false;
567
+ if (this.accept(cssScanner_1.TokenType.ParenthesisL)) {
568
+ hasArguments = true;
569
+ if (node.getArguments().addChild(this._parseMixinArgument())) {
570
+ while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
571
+ if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
572
+ break;
573
+ }
574
+ if (!node.getArguments().addChild(this._parseMixinArgument())) {
575
+ return this.finish(node, cssErrors_1.ParseError.ExpressionExpected);
576
+ }
577
+ }
578
+ }
579
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
580
+ return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
581
+ }
582
+ identifier.referenceTypes = [nodes.ReferenceType.Mixin];
583
+ }
584
+ else {
585
+ identifier.referenceTypes = [nodes.ReferenceType.Mixin, nodes.ReferenceType.Rule];
586
+ }
587
+ if (this.peek(cssScanner_1.TokenType.BracketL)) {
588
+ if (!atRoot) {
589
+ this._addLookupChildren(node);
590
+ }
591
+ }
592
+ else {
593
+ node.addChild(this._parsePrio());
594
+ }
595
+ if (!hasArguments && !this.peek(cssScanner_1.TokenType.SemiColon) && !this.peek(cssScanner_1.TokenType.CurlyR) && !this.peek(cssScanner_1.TokenType.EOF)) {
596
+ this.restoreAtMark(mark);
597
+ return null;
598
+ }
599
+ return this.finish(node);
600
+ }
601
+ _parseMixinArgument() {
602
+ // [variableName ':'] expression | variableName '...'
603
+ const node = this.create(nodes.FunctionArgument);
604
+ const pos = this.mark();
605
+ const argument = this._parseVariable();
606
+ if (argument) {
607
+ if (!this.accept(cssScanner_1.TokenType.Colon)) {
608
+ this.restoreAtMark(pos);
609
+ }
610
+ else {
611
+ node.setIdentifier(argument);
612
+ }
613
+ }
614
+ if (node.setValue(this._parseDetachedRuleSet() || this._parseExpr(true))) {
615
+ return this.finish(node);
616
+ }
617
+ this.restoreAtMark(pos);
618
+ return null;
619
+ }
620
+ _parseMixinParameter() {
621
+ const node = this.create(nodes.FunctionParameter);
622
+ // special rest variable: @rest...
623
+ if (this.peekKeyword('@rest')) {
624
+ const restNode = this.create(nodes.Node);
625
+ this.consumeToken();
626
+ if (!this.accept(lessScanner.Ellipsis)) {
627
+ return this.finish(node, cssErrors_1.ParseError.DotExpected, [], [cssScanner_1.TokenType.Comma, cssScanner_1.TokenType.ParenthesisR]);
628
+ }
629
+ node.setIdentifier(this.finish(restNode));
630
+ return this.finish(node);
631
+ }
632
+ // special const args: ...
633
+ if (this.peek(lessScanner.Ellipsis)) {
634
+ const varargsNode = this.create(nodes.Node);
635
+ this.consumeToken();
636
+ node.setIdentifier(this.finish(varargsNode));
637
+ return this.finish(node);
638
+ }
639
+ let hasContent = false;
640
+ // default variable declaration: @param: 12 or @name
641
+ if (node.setIdentifier(this._parseVariable())) {
642
+ this.accept(cssScanner_1.TokenType.Colon);
643
+ hasContent = true;
644
+ }
645
+ if (!node.setDefaultValue(this._parseDetachedRuleSet() || this._parseExpr(true)) && !hasContent) {
646
+ return null;
647
+ }
648
+ return this.finish(node);
649
+ }
650
+ _parseGuard() {
651
+ if (!this.peekIdent('when')) {
652
+ return null;
653
+ }
654
+ const node = this.create(nodes.LessGuard);
655
+ this.consumeToken(); // when
656
+ node.isNegated = this.acceptIdent('not');
657
+ if (!node.getConditions().addChild(this._parseGuardCondition())) {
658
+ return this.finish(node, cssErrors_1.ParseError.ConditionExpected);
659
+ }
660
+ while (this.acceptIdent('and') || this.accept(cssScanner_1.TokenType.Comma)) {
661
+ if (!node.getConditions().addChild(this._parseGuardCondition())) {
662
+ return this.finish(node, cssErrors_1.ParseError.ConditionExpected);
663
+ }
664
+ }
665
+ return this.finish(node);
666
+ }
667
+ _parseGuardCondition() {
668
+ if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) {
669
+ return null;
670
+ }
671
+ const node = this.create(nodes.GuardCondition);
672
+ this.consumeToken(); // ParenthesisL
673
+ if (!node.addChild(this._parseExpr())) {
674
+ // empty (?)
675
+ }
676
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
677
+ return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
678
+ }
679
+ return this.finish(node);
680
+ }
681
+ _parseFunction() {
682
+ const pos = this.mark();
683
+ const node = this.create(nodes.Function);
684
+ if (!node.setIdentifier(this._parseFunctionIdentifier())) {
685
+ return null;
686
+ }
687
+ if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.ParenthesisL)) {
688
+ this.restoreAtMark(pos);
689
+ return null;
690
+ }
691
+ if (node.getArguments().addChild(this._parseMixinArgument())) {
692
+ while (this.accept(cssScanner_1.TokenType.Comma) || this.accept(cssScanner_1.TokenType.SemiColon)) {
693
+ if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
694
+ break;
695
+ }
696
+ if (!node.getArguments().addChild(this._parseMixinArgument())) {
697
+ return this.finish(node, cssErrors_1.ParseError.ExpressionExpected);
698
+ }
699
+ }
700
+ }
701
+ if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
702
+ return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
703
+ }
704
+ return this.finish(node);
705
+ }
706
+ _parseFunctionIdentifier() {
707
+ if (this.peekDelim('%')) {
708
+ const node = this.create(nodes.Identifier);
709
+ node.referenceTypes = [nodes.ReferenceType.Function];
710
+ this.consumeToken();
711
+ return this.finish(node);
712
+ }
713
+ return super._parseFunctionIdentifier();
714
+ }
715
+ _parseURLArgument() {
716
+ const pos = this.mark();
717
+ const node = super._parseURLArgument();
718
+ if (!node || !this.peek(cssScanner_1.TokenType.ParenthesisR)) {
719
+ this.restoreAtMark(pos);
720
+ const node = this.create(nodes.Node);
721
+ node.addChild(this._parseBinaryExpr());
722
+ return this.finish(node);
723
+ }
724
+ return node;
725
+ }
726
+ }
727
+ exports.LESSParser = LESSParser;
728
+ });