vscode-css-languageservice 6.0.1 → 6.1.0

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