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