vscode-css-languageservice 5.4.2 → 6.0.0

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