vscode-css-languageservice 5.4.1 → 6.0.1

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