vscode-css-languageservice 6.3.10 → 7.0.0-next.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 (74) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/esm/beautify/beautify-css.js +1437 -1606
  3. package/lib/esm/cssLanguageService.d.ts +2 -2
  4. package/lib/esm/cssLanguageService.js +18 -18
  5. package/lib/esm/languageFacts/colors.js +1 -1
  6. package/lib/esm/languageFacts/dataManager.js +3 -3
  7. package/lib/esm/languageFacts/entry.js +1 -1
  8. package/lib/esm/languageFacts/facts.js +3 -3
  9. package/lib/esm/parser/cssNodes.js +1 -1
  10. package/lib/esm/parser/cssParser.js +5 -5
  11. package/lib/esm/parser/cssSymbolScope.js +2 -2
  12. package/lib/esm/parser/lessParser.js +5 -5
  13. package/lib/esm/parser/lessScanner.js +1 -1
  14. package/lib/esm/parser/scssParser.js +6 -6
  15. package/lib/esm/parser/scssScanner.js +1 -1
  16. package/lib/esm/services/cssCodeActions.js +4 -4
  17. package/lib/esm/services/cssCompletion.js +7 -7
  18. package/lib/esm/services/cssFolding.js +3 -3
  19. package/lib/esm/services/cssFormatter.js +3 -3
  20. package/lib/esm/services/cssHover.js +6 -6
  21. package/lib/esm/services/cssNavigation.js +6 -6
  22. package/lib/esm/services/cssSelectionRange.js +2 -2
  23. package/lib/esm/services/cssValidation.js +4 -4
  24. package/lib/esm/services/lessCompletion.js +2 -2
  25. package/lib/esm/services/lint.js +5 -5
  26. package/lib/esm/services/lintRules.js +1 -1
  27. package/lib/esm/services/lintUtil.js +1 -1
  28. package/lib/esm/services/pathCompletion.js +3 -3
  29. package/lib/esm/services/scssCompletion.js +3 -3
  30. package/lib/esm/services/scssNavigation.js +4 -4
  31. package/lib/esm/services/selectorPrinting.js +3 -3
  32. package/package.json +15 -15
  33. package/lib/umd/beautify/beautify-css.js +0 -1695
  34. package/lib/umd/cssLanguageService.d.ts +0 -39
  35. package/lib/umd/cssLanguageService.js +0 -105
  36. package/lib/umd/cssLanguageTypes.d.ts +0 -267
  37. package/lib/umd/cssLanguageTypes.js +0 -89
  38. package/lib/umd/data/webCustomData.js +0 -44613
  39. package/lib/umd/languageFacts/builtinData.js +0 -155
  40. package/lib/umd/languageFacts/colors.js +0 -949
  41. package/lib/umd/languageFacts/dataManager.js +0 -101
  42. package/lib/umd/languageFacts/dataProvider.js +0 -86
  43. package/lib/umd/languageFacts/entry.js +0 -217
  44. package/lib/umd/languageFacts/facts.js +0 -33
  45. package/lib/umd/parser/cssErrors.js +0 -61
  46. package/lib/umd/parser/cssNodes.js +0 -1676
  47. package/lib/umd/parser/cssParser.js +0 -2035
  48. package/lib/umd/parser/cssScanner.js +0 -619
  49. package/lib/umd/parser/cssSymbolScope.js +0 -328
  50. package/lib/umd/parser/lessParser.js +0 -732
  51. package/lib/umd/parser/lessScanner.js +0 -70
  52. package/lib/umd/parser/scssErrors.js +0 -30
  53. package/lib/umd/parser/scssParser.js +0 -874
  54. package/lib/umd/parser/scssScanner.js +0 -108
  55. package/lib/umd/services/cssCodeActions.js +0 -89
  56. package/lib/umd/services/cssCompletion.js +0 -1109
  57. package/lib/umd/services/cssFolding.js +0 -202
  58. package/lib/umd/services/cssFormatter.js +0 -149
  59. package/lib/umd/services/cssHover.js +0 -174
  60. package/lib/umd/services/cssNavigation.js +0 -539
  61. package/lib/umd/services/cssSelectionRange.js +0 -59
  62. package/lib/umd/services/cssValidation.js +0 -54
  63. package/lib/umd/services/lessCompletion.js +0 -390
  64. package/lib/umd/services/lint.js +0 -577
  65. package/lib/umd/services/lintRules.js +0 -90
  66. package/lib/umd/services/lintUtil.js +0 -210
  67. package/lib/umd/services/pathCompletion.js +0 -171
  68. package/lib/umd/services/scssCompletion.js +0 -367
  69. package/lib/umd/services/scssNavigation.js +0 -169
  70. package/lib/umd/services/selectorPrinting.js +0 -575
  71. package/lib/umd/utils/arrays.js +0 -54
  72. package/lib/umd/utils/objects.js +0 -24
  73. package/lib/umd/utils/resources.js +0 -25
  74. package/lib/umd/utils/strings.js +0 -123
@@ -1,874 +0,0 @@
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
- return this._completeParseImport(node);
61
- }
62
- // scss variables: $font-size: 12px;
63
- _parseVariableDeclaration(panic = []) {
64
- if (!this.peek(scssScanner.VariableName)) {
65
- return null;
66
- }
67
- const node = this.create(nodes.VariableDeclaration);
68
- if (!node.setVariable(this._parseVariable())) {
69
- return null;
70
- }
71
- if (!this.accept(cssScanner_1.TokenType.Colon)) {
72
- return this.finish(node, cssErrors_1.ParseError.ColonExpected);
73
- }
74
- if (this.prevToken) {
75
- node.colonPosition = this.prevToken.offset;
76
- }
77
- if (!node.setValue(this._parseExpr())) {
78
- return this.finish(node, cssErrors_1.ParseError.VariableValueExpected, [], panic);
79
- }
80
- while (this.peek(cssScanner_1.TokenType.Exclamation)) {
81
- if (node.addChild(this._tryParsePrio())) {
82
- // !important
83
- }
84
- else {
85
- this.consumeToken();
86
- if (!this.peekRegExp(cssScanner_1.TokenType.Ident, /^(default|global)$/)) {
87
- return this.finish(node, cssErrors_1.ParseError.UnknownKeyword);
88
- }
89
- this.consumeToken();
90
- }
91
- }
92
- if (this.peek(cssScanner_1.TokenType.SemiColon)) {
93
- node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
94
- }
95
- return this.finish(node);
96
- }
97
- _parseMediaCondition() {
98
- return this._parseInterpolation() || super._parseMediaCondition();
99
- }
100
- _parseMediaFeatureRangeOperator() {
101
- return this.accept(scssScanner.SmallerEqualsOperator) || this.accept(scssScanner.GreaterEqualsOperator) || super._parseMediaFeatureRangeOperator();
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._parseWarnAndDebug() // @warn, @debug and @error statements
113
- || this._parseMixinReference() // @include
114
- || this._parseFunctionDeclaration() // @function
115
- || this._parseVariableDeclaration()
116
- || this._parseMixinContent();
117
- }
118
- _parseVariable() {
119
- if (!this.peek(scssScanner.VariableName)) {
120
- return null;
121
- }
122
- const node = this.create(nodes.Variable);
123
- this.consumeToken();
124
- return node;
125
- }
126
- _parseModuleMember() {
127
- const pos = this.mark();
128
- const node = this.create(nodes.Module);
129
- if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Module]))) {
130
- return null;
131
- }
132
- if (this.hasWhitespace()
133
- || !this.acceptDelim('.')
134
- || this.hasWhitespace()) {
135
- this.restoreAtMark(pos);
136
- return null;
137
- }
138
- if (!node.addChild(this._parseVariable() || this._parseFunction())) {
139
- return this.finish(node, cssErrors_1.ParseError.IdentifierOrVariableExpected);
140
- }
141
- return node;
142
- }
143
- _parseIdent(referenceTypes) {
144
- if (!this.peek(cssScanner_1.TokenType.Ident) && !this.peek(scssScanner.InterpolationFunction) && !this.peekDelim('-')) {
145
- return null;
146
- }
147
- const node = this.create(nodes.Identifier);
148
- node.referenceTypes = referenceTypes;
149
- node.isCustomProperty = this.peekRegExp(cssScanner_1.TokenType.Ident, /^--/);
150
- let hasContent = false;
151
- const indentInterpolation = () => {
152
- const pos = this.mark();
153
- if (this.acceptDelim('-')) {
154
- if (!this.hasWhitespace()) {
155
- this.acceptDelim('-');
156
- }
157
- if (this.hasWhitespace()) {
158
- this.restoreAtMark(pos);
159
- return null;
160
- }
161
- }
162
- return this._parseInterpolation();
163
- };
164
- while (this.accept(cssScanner_1.TokenType.Ident) || node.addChild(indentInterpolation()) || (hasContent && this.acceptRegexp(/^[\w-]/))) {
165
- hasContent = true;
166
- if (this.hasWhitespace()) {
167
- break;
168
- }
169
- }
170
- return hasContent ? this.finish(node) : null;
171
- }
172
- _parseTermExpression() {
173
- return this._parseModuleMember() ||
174
- this._parseVariable() ||
175
- this._parseNestingSelector() ||
176
- //this._tryParsePrio() ||
177
- super._parseTermExpression();
178
- }
179
- _parseInterpolation() {
180
- if (this.peek(scssScanner.InterpolationFunction)) {
181
- const node = this.create(nodes.Interpolation);
182
- this.consumeToken();
183
- if (!node.addChild(this._parseExpr()) && !this._parseNestingSelector()) {
184
- if (this.accept(cssScanner_1.TokenType.CurlyR)) {
185
- return this.finish(node);
186
- }
187
- return this.finish(node, cssErrors_1.ParseError.ExpressionExpected);
188
- }
189
- if (!this.accept(cssScanner_1.TokenType.CurlyR)) {
190
- return this.finish(node, cssErrors_1.ParseError.RightCurlyExpected);
191
- }
192
- return this.finish(node);
193
- }
194
- return null;
195
- }
196
- _parseOperator() {
197
- if (this.peek(scssScanner.EqualsOperator) || this.peek(scssScanner.NotEqualsOperator)
198
- || this.peek(scssScanner.GreaterEqualsOperator) || this.peek(scssScanner.SmallerEqualsOperator)
199
- || this.peekDelim('>') || this.peekDelim('<')
200
- || this.peekIdent('and') || this.peekIdent('or')
201
- || this.peekDelim('%')) {
202
- const node = this.createNode(nodes.NodeType.Operator);
203
- this.consumeToken();
204
- return this.finish(node);
205
- }
206
- return super._parseOperator();
207
- }
208
- _parseUnaryOperator() {
209
- if (this.peekIdent('not')) {
210
- const node = this.create(nodes.Node);
211
- this.consumeToken();
212
- return this.finish(node);
213
- }
214
- return super._parseUnaryOperator();
215
- }
216
- _parseRuleSetDeclaration() {
217
- if (this.peek(cssScanner_1.TokenType.AtKeyword)) {
218
- return this._parseKeyframe() // nested @keyframe
219
- || this._parseImport() // nested @import
220
- || this._parseMedia(true) // nested @media
221
- || this._parseFontFace() // nested @font-face
222
- || this._parseWarnAndDebug() // @warn, @debug and @error statements
223
- || this._parseControlStatement() // @if, @while, @for, @each
224
- || this._parseFunctionDeclaration() // @function
225
- || this._parseExtends() // @extends
226
- || this._parseMixinReference() // @include
227
- || this._parseMixinContent() // @content
228
- || this._parseMixinDeclaration() // nested @mixin
229
- || this._parseRuleset(true) // @at-rule
230
- || this._parseSupports(true) // @supports
231
- || this._parseLayer() // @layer
232
- || this._parsePropertyAtRule() // @property
233
- || this._parseContainer(true) // nested @container
234
- || this._parseRuleSetDeclarationAtStatement();
235
- }
236
- return this._parseVariableDeclaration() // variable declaration
237
- || this._tryParseRuleset(true) // nested ruleset
238
- || this._parseDeclaration(); // try css ruleset declaration as last so in the error case, the ast will contain a declaration
239
- }
240
- _parseDeclaration(stopTokens) {
241
- const custonProperty = this._tryParseCustomPropertyDeclaration(stopTokens);
242
- if (custonProperty) {
243
- return custonProperty;
244
- }
245
- const node = this.create(nodes.Declaration);
246
- if (!node.setProperty(this._parseProperty())) {
247
- return null;
248
- }
249
- if (!this.accept(cssScanner_1.TokenType.Colon)) {
250
- return this.finish(node, cssErrors_1.ParseError.ColonExpected, [cssScanner_1.TokenType.Colon], stopTokens || [cssScanner_1.TokenType.SemiColon]);
251
- }
252
- if (this.prevToken) {
253
- node.colonPosition = this.prevToken.offset;
254
- }
255
- let hasContent = false;
256
- if (node.setValue(this._parseExpr())) {
257
- hasContent = true;
258
- node.addChild(this._parsePrio());
259
- }
260
- if (this.peek(cssScanner_1.TokenType.CurlyL)) {
261
- node.setNestedProperties(this._parseNestedProperties());
262
- }
263
- else {
264
- if (!hasContent) {
265
- return this.finish(node, cssErrors_1.ParseError.PropertyValueExpected);
266
- }
267
- }
268
- if (this.peek(cssScanner_1.TokenType.SemiColon)) {
269
- node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
270
- }
271
- return this.finish(node);
272
- }
273
- _parseNestedProperties() {
274
- const node = this.create(nodes.NestedProperties);
275
- return this._parseBody(node, this._parseDeclaration.bind(this));
276
- }
277
- _parseExtends() {
278
- if (this.peekKeyword('@extend')) {
279
- const node = this.create(nodes.ExtendsReference);
280
- this.consumeToken();
281
- if (!node.getSelectors().addChild(this._parseSimpleSelector())) {
282
- return this.finish(node, cssErrors_1.ParseError.SelectorExpected);
283
- }
284
- while (this.accept(cssScanner_1.TokenType.Comma)) {
285
- node.getSelectors().addChild(this._parseSimpleSelector());
286
- }
287
- if (this.accept(cssScanner_1.TokenType.Exclamation)) {
288
- if (!this.acceptIdent('optional')) {
289
- return this.finish(node, cssErrors_1.ParseError.UnknownKeyword);
290
- }
291
- }
292
- return this.finish(node);
293
- }
294
- return null;
295
- }
296
- _parseSimpleSelectorBody() {
297
- return this._parseSelectorPlaceholder() || super._parseSimpleSelectorBody();
298
- }
299
- _parseNestingSelector() {
300
- if (this.peekDelim('&')) {
301
- const node = this.createNode(nodes.NodeType.SelectorCombinator);
302
- this.consumeToken();
303
- while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(cssScanner_1.TokenType.Num) || this.accept(cssScanner_1.TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) {
304
- // support &-foo-1
305
- }
306
- return this.finish(node);
307
- }
308
- return null;
309
- }
310
- _parseSelectorPlaceholder() {
311
- if (this.peekDelim('%')) {
312
- const node = this.createNode(nodes.NodeType.SelectorPlaceholder);
313
- this.consumeToken();
314
- this._parseIdent();
315
- return this.finish(node);
316
- }
317
- else if (this.peekKeyword('@at-root')) {
318
- const node = this.createNode(nodes.NodeType.SelectorPlaceholder);
319
- this.consumeToken();
320
- if (this.accept(cssScanner_1.TokenType.ParenthesisL)) {
321
- if (!this.acceptIdent('with') && !this.acceptIdent('without')) {
322
- return this.finish(node, cssErrors_1.ParseError.IdentifierExpected);
323
- }
324
- if (!this.accept(cssScanner_1.TokenType.Colon)) {
325
- return this.finish(node, cssErrors_1.ParseError.ColonExpected);
326
- }
327
- if (!node.addChild(this._parseIdent())) {
328
- return this.finish(node, cssErrors_1.ParseError.IdentifierExpected);
329
- }
330
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
331
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected, [cssScanner_1.TokenType.CurlyR]);
332
- }
333
- }
334
- return this.finish(node);
335
- }
336
- return null;
337
- }
338
- _parseElementName() {
339
- const pos = this.mark();
340
- const node = super._parseElementName();
341
- if (node && !this.hasWhitespace() && this.peek(cssScanner_1.TokenType.ParenthesisL)) { // for #49589
342
- this.restoreAtMark(pos);
343
- return null;
344
- }
345
- return node;
346
- }
347
- _tryParsePseudoIdentifier() {
348
- return this._parseInterpolation() || super._tryParsePseudoIdentifier(); // for #49589
349
- }
350
- _parseWarnAndDebug() {
351
- if (!this.peekKeyword('@debug')
352
- && !this.peekKeyword('@warn')
353
- && !this.peekKeyword('@error')) {
354
- return null;
355
- }
356
- const node = this.createNode(nodes.NodeType.Debug);
357
- this.consumeToken(); // @debug, @warn or @error
358
- node.addChild(this._parseExpr()); // optional
359
- return this.finish(node);
360
- }
361
- _parseControlStatement(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
- _parseIfStatement(parseStatement) {
369
- if (!this.peekKeyword('@if')) {
370
- return null;
371
- }
372
- return this._internalParseIfStatement(parseStatement);
373
- }
374
- _internalParseIfStatement(parseStatement) {
375
- const 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
- const elseNode = this.create(nodes.ElseStatement);
387
- this._parseBody(elseNode, parseStatement);
388
- node.setElseClause(elseNode);
389
- }
390
- }
391
- return this.finish(node);
392
- }
393
- _parseForStatement(parseStatement) {
394
- if (!this.peekKeyword('@for')) {
395
- return null;
396
- }
397
- const 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
- _parseEachStatement(parseStatement) {
417
- if (!this.peekKeyword('@each')) {
418
- return null;
419
- }
420
- const node = this.create(nodes.EachStatement);
421
- this.consumeToken(); // @each
422
- const 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
- _parseWhileStatement(parseStatement) {
441
- if (!this.peekKeyword('@while')) {
442
- return null;
443
- }
444
- const 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
- _parseFunctionBodyDeclaration() {
452
- return this._parseVariableDeclaration() || this._parseReturnStatement() || this._parseWarnAndDebug()
453
- || this._parseControlStatement(this._parseFunctionBodyDeclaration.bind(this));
454
- }
455
- _parseFunctionDeclaration() {
456
- if (!this.peekKeyword('@function')) {
457
- return null;
458
- }
459
- const 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
- _parseReturnStatement() {
483
- if (!this.peekKeyword('@return')) {
484
- return null;
485
- }
486
- const 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
- _parseMixinDeclaration() {
494
- if (!this.peekKeyword('@mixin')) {
495
- return null;
496
- }
497
- const 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
- _parseParameterDeclaration() {
520
- const 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
- _parseMixinContent() {
535
- if (!this.peekKeyword('@content')) {
536
- return null;
537
- }
538
- const 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
- _parseMixinReference() {
558
- if (!this.peekKeyword('@include')) {
559
- return null;
560
- }
561
- const node = this.create(nodes.MixinReference);
562
- this.consumeToken();
563
- // Could be module or mixin identifier, set as mixin as default.
564
- const 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
- const secondIdent = this._parseIdent([nodes.ReferenceType.Mixin]);
571
- if (!secondIdent) {
572
- return this.finish(node, cssErrors_1.ParseError.IdentifierExpected, [cssScanner_1.TokenType.CurlyR]);
573
- }
574
- const 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
- _parseMixinContentDeclaration() {
603
- const 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
- _parseMixinReferenceBodyStatement() {
628
- return this._tryParseKeyframeSelector() || this._parseRuleSetDeclaration();
629
- }
630
- _parseIfTest() {
631
- const node = this.create(nodes.Node);
632
- if (this.acceptIdent('sass')) {
633
- if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.ParenthesisL)) {
634
- return this.finish(node, cssErrors_1.ParseError.LeftParenthesisExpected, [], [cssScanner_1.TokenType.CurlyL]);
635
- }
636
- node.addChild(this._parseExpr());
637
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
638
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected, [], [cssScanner_1.TokenType.CurlyL]);
639
- }
640
- return this.finish(node);
641
- }
642
- return super._parseIfTest();
643
- }
644
- _parseFunction() {
645
- const pos = this.mark();
646
- const node = this.create(nodes.Function);
647
- let isIf = this.peekIdent('if');
648
- if (!node.setIdentifier(this._parseFunctionIdentifier())) {
649
- return null;
650
- }
651
- if (this.hasWhitespace() || !this.accept(cssScanner_1.TokenType.ParenthesisL)) {
652
- this.restoreAtMark(pos);
653
- return null;
654
- }
655
- let firstArgument;
656
- let parseArgument = this._parseFunctionArgument.bind(this);
657
- let separator = cssScanner_1.TokenType.Comma;
658
- if (!isIf) {
659
- firstArgument = this._parseFunctionArgument();
660
- }
661
- else {
662
- const pos = this.mark();
663
- firstArgument = this._parseIfBranch();
664
- if (firstArgument && !firstArgument.isErroneous()) {
665
- parseArgument = this._parseIfBranch.bind(this);
666
- separator = cssScanner_1.TokenType.SemiColon;
667
- }
668
- else {
669
- this.restoreAtMark(pos);
670
- firstArgument = this._parseFunctionArgument();
671
- }
672
- }
673
- if (node.getArguments().addChild(firstArgument)) {
674
- while (this.accept(separator)) {
675
- if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
676
- break;
677
- }
678
- if (!node.getArguments().addChild(parseArgument())) {
679
- this.markError(node, cssErrors_1.ParseError.ExpressionExpected);
680
- }
681
- }
682
- }
683
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
684
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
685
- }
686
- return this.finish(node);
687
- }
688
- _parseFunctionArgument() {
689
- // [variableName ':'] expression | variableName '...'
690
- const node = this.create(nodes.FunctionArgument);
691
- const pos = this.mark();
692
- const argument = this._parseVariable();
693
- if (argument) {
694
- if (!this.accept(cssScanner_1.TokenType.Colon)) {
695
- if (this.accept(scssScanner.Ellipsis)) { // optional
696
- node.setValue(argument);
697
- return this.finish(node);
698
- }
699
- else {
700
- this.restoreAtMark(pos);
701
- }
702
- }
703
- else {
704
- node.setIdentifier(argument);
705
- }
706
- }
707
- if (node.setValue(this._parseExpr(true))) {
708
- this.accept(scssScanner.Ellipsis); // #43746
709
- node.addChild(this._parsePrio()); // #9859
710
- return this.finish(node);
711
- }
712
- else if (node.setValue(this._tryParsePrio())) {
713
- return this.finish(node);
714
- }
715
- return null;
716
- }
717
- _parseURLArgument() {
718
- const pos = this.mark();
719
- const node = super._parseURLArgument();
720
- if (!node || !this.peek(cssScanner_1.TokenType.ParenthesisR)) {
721
- this.restoreAtMark(pos);
722
- const node = this.create(nodes.Node);
723
- node.addChild(this._parseBinaryExpr());
724
- return this.finish(node);
725
- }
726
- return node;
727
- }
728
- _parseOperation() {
729
- if (!this.peek(cssScanner_1.TokenType.ParenthesisL)) {
730
- return null;
731
- }
732
- const node = this.create(nodes.Node);
733
- this.consumeToken();
734
- while (node.addChild(this._parseListElement())) {
735
- this.accept(cssScanner_1.TokenType.Comma); // optional
736
- }
737
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
738
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
739
- }
740
- return this.finish(node);
741
- }
742
- _parseListElement() {
743
- const node = this.create(nodes.ListEntry);
744
- const child = this._parseBinaryExpr();
745
- if (!child) {
746
- return null;
747
- }
748
- if (this.accept(cssScanner_1.TokenType.Colon)) {
749
- node.setKey(child);
750
- if (!node.setValue(this._parseBinaryExpr())) {
751
- return this.finish(node, cssErrors_1.ParseError.ExpressionExpected);
752
- }
753
- }
754
- else {
755
- node.setValue(child);
756
- }
757
- return this.finish(node);
758
- }
759
- _parseUse() {
760
- if (!this.peekKeyword('@use')) {
761
- return null;
762
- }
763
- const node = this.create(nodes.Use);
764
- this.consumeToken(); // @use
765
- if (!node.addChild(this._parseStringLiteral())) {
766
- return this.finish(node, cssErrors_1.ParseError.StringLiteralExpected);
767
- }
768
- if (!this.peek(cssScanner_1.TokenType.SemiColon) && !this.peek(cssScanner_1.TokenType.EOF)) {
769
- if (!this.peekRegExp(cssScanner_1.TokenType.Ident, /as|with/)) {
770
- return this.finish(node, cssErrors_1.ParseError.UnknownKeyword);
771
- }
772
- if (this.acceptIdent('as') &&
773
- (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Module])) && !this.acceptDelim('*'))) {
774
- return this.finish(node, cssErrors_1.ParseError.IdentifierOrWildcardExpected);
775
- }
776
- if (this.acceptIdent('with')) {
777
- if (!node.setParameters(this._parseModuleConfig())) {
778
- return this.finish(node, cssErrors_1.ParseError.LeftParenthesisExpected, [cssScanner_1.TokenType.ParenthesisR]);
779
- }
780
- }
781
- }
782
- if (!this.accept(cssScanner_1.TokenType.SemiColon) && !this.accept(cssScanner_1.TokenType.EOF)) {
783
- return this.finish(node, cssErrors_1.ParseError.SemiColonExpected);
784
- }
785
- return this.finish(node);
786
- }
787
- _parseModuleConfig() {
788
- const node = this.createNode(nodes.NodeType.ModuleConfig);
789
- if (!this.accept(cssScanner_1.TokenType.ParenthesisL)) {
790
- return null;
791
- }
792
- // First variable statement, no comma.
793
- if (!node.addChild(this._parseModuleConfigDeclaration())) {
794
- return this.finish(node, cssErrors_1.ParseError.VariableNameExpected);
795
- }
796
- while (this.accept(cssScanner_1.TokenType.Comma)) {
797
- if (this.peek(cssScanner_1.TokenType.ParenthesisR)) {
798
- break;
799
- }
800
- if (!node.addChild(this._parseModuleConfigDeclaration())) {
801
- return this.finish(node, cssErrors_1.ParseError.VariableNameExpected);
802
- }
803
- }
804
- if (!this.accept(cssScanner_1.TokenType.ParenthesisR)) {
805
- return this.finish(node, cssErrors_1.ParseError.RightParenthesisExpected);
806
- }
807
- return this.finish(node);
808
- }
809
- _parseModuleConfigDeclaration() {
810
- const node = this.create(nodes.ModuleConfiguration);
811
- if (!node.setIdentifier(this._parseVariable())) {
812
- return null;
813
- }
814
- if (!this.accept(cssScanner_1.TokenType.Colon) || !node.setValue(this._parseExpr(true))) {
815
- return this.finish(node, cssErrors_1.ParseError.VariableValueExpected, [], [cssScanner_1.TokenType.Comma, cssScanner_1.TokenType.ParenthesisR]);
816
- }
817
- if (this.accept(cssScanner_1.TokenType.Exclamation)) {
818
- if (this.hasWhitespace() || !this.acceptIdent('default')) {
819
- return this.finish(node, cssErrors_1.ParseError.UnknownKeyword);
820
- }
821
- }
822
- return this.finish(node);
823
- }
824
- _parseForward() {
825
- if (!this.peekKeyword('@forward')) {
826
- return null;
827
- }
828
- const node = this.create(nodes.Forward);
829
- this.consumeToken();
830
- if (!node.addChild(this._parseStringLiteral())) {
831
- return this.finish(node, cssErrors_1.ParseError.StringLiteralExpected);
832
- }
833
- if (this.acceptIdent('as')) {
834
- const identifier = this._parseIdent([nodes.ReferenceType.Forward]);
835
- if (!node.setIdentifier(identifier)) {
836
- return this.finish(node, cssErrors_1.ParseError.IdentifierExpected);
837
- }
838
- // Wildcard must be the next character after the identifier string.
839
- if (this.hasWhitespace() || !this.acceptDelim('*')) {
840
- return this.finish(node, cssErrors_1.ParseError.WildcardExpected);
841
- }
842
- }
843
- if (this.acceptIdent('with')) {
844
- if (!node.setParameters(this._parseModuleConfig())) {
845
- return this.finish(node, cssErrors_1.ParseError.LeftParenthesisExpected, [cssScanner_1.TokenType.ParenthesisR]);
846
- }
847
- }
848
- else if (this.peekIdent('hide') || this.peekIdent('show')) {
849
- if (!node.addChild(this._parseForwardVisibility())) {
850
- return this.finish(node, cssErrors_1.ParseError.IdentifierOrVariableExpected);
851
- }
852
- }
853
- if (!this.accept(cssScanner_1.TokenType.SemiColon) && !this.accept(cssScanner_1.TokenType.EOF)) {
854
- return this.finish(node, cssErrors_1.ParseError.SemiColonExpected);
855
- }
856
- return this.finish(node);
857
- }
858
- _parseForwardVisibility() {
859
- const node = this.create(nodes.ForwardVisibility);
860
- // Assume to be "hide" or "show".
861
- node.setIdentifier(this._parseIdent());
862
- while (node.addChild(this._parseVariable() || this._parseIdent())) {
863
- // Consume all variables and idents ahead.
864
- this.accept(cssScanner_1.TokenType.Comma);
865
- }
866
- // More than just identifier
867
- return node.getChildren().length > 1 ? node : null;
868
- }
869
- _parseSupportsCondition() {
870
- return this._parseInterpolation() || super._parseSupportsCondition();
871
- }
872
- }
873
- exports.SCSSParser = SCSSParser;
874
- });