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