vscode-css-languageservice 5.4.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/lib/esm/cssLanguageService.d.ts +37 -37
  3. package/lib/esm/cssLanguageService.js +72 -75
  4. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  5. package/lib/esm/cssLanguageTypes.js +42 -42
  6. package/lib/esm/data/webCustomData.js +21965 -21965
  7. package/lib/esm/languageFacts/builtinData.js +142 -142
  8. package/lib/esm/languageFacts/colors.js +469 -472
  9. package/lib/esm/languageFacts/dataManager.js +88 -92
  10. package/lib/esm/languageFacts/dataProvider.js +73 -79
  11. package/lib/esm/languageFacts/entry.js +137 -138
  12. package/lib/esm/languageFacts/facts.js +8 -8
  13. package/lib/esm/parser/cssErrors.js +48 -50
  14. package/lib/esm/parser/cssNodes.js +1502 -2019
  15. package/lib/esm/parser/cssParser.js +1534 -1563
  16. package/lib/esm/parser/cssScanner.js +592 -599
  17. package/lib/esm/parser/cssSymbolScope.js +311 -341
  18. package/lib/esm/parser/lessParser.js +714 -740
  19. package/lib/esm/parser/lessScanner.js +57 -78
  20. package/lib/esm/parser/scssErrors.js +18 -20
  21. package/lib/esm/parser/scssParser.js +796 -818
  22. package/lib/esm/parser/scssScanner.js +95 -116
  23. package/lib/esm/services/cssCodeActions.js +77 -81
  24. package/lib/esm/services/cssCompletion.js +1054 -1149
  25. package/lib/esm/services/cssFolding.js +190 -193
  26. package/lib/esm/services/cssFormatter.js +136 -136
  27. package/lib/esm/services/cssHover.js +148 -151
  28. package/lib/esm/services/cssNavigation.js +378 -470
  29. package/lib/esm/services/cssSelectionRange.js +47 -47
  30. package/lib/esm/services/cssValidation.js +41 -44
  31. package/lib/esm/services/lessCompletion.js +378 -397
  32. package/lib/esm/services/lint.js +518 -532
  33. package/lib/esm/services/lintRules.js +76 -83
  34. package/lib/esm/services/lintUtil.js +196 -205
  35. package/lib/esm/services/pathCompletion.js +157 -231
  36. package/lib/esm/services/scssCompletion.js +354 -378
  37. package/lib/esm/services/scssNavigation.js +82 -154
  38. package/lib/esm/services/selectorPrinting.js +492 -536
  39. package/lib/esm/utils/arrays.js +40 -46
  40. package/lib/esm/utils/objects.js +11 -11
  41. package/lib/esm/utils/resources.js +11 -24
  42. package/lib/esm/utils/strings.js +102 -104
  43. package/lib/umd/cssLanguageService.d.ts +37 -37
  44. package/lib/umd/cssLanguageService.js +99 -102
  45. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  46. package/lib/umd/cssLanguageTypes.js +89 -88
  47. package/lib/umd/data/webCustomData.js +21978 -21978
  48. package/lib/umd/languageFacts/builtinData.js +154 -154
  49. package/lib/umd/languageFacts/colors.js +492 -495
  50. package/lib/umd/languageFacts/dataManager.js +101 -104
  51. package/lib/umd/languageFacts/dataProvider.js +86 -91
  52. package/lib/umd/languageFacts/entry.js +152 -153
  53. package/lib/umd/languageFacts/facts.js +29 -29
  54. package/lib/umd/parser/cssErrors.js +61 -62
  55. package/lib/umd/parser/cssNodes.js +1587 -2034
  56. package/lib/umd/parser/cssParser.js +1547 -1575
  57. package/lib/umd/parser/cssScanner.js +606 -611
  58. package/lib/umd/parser/cssSymbolScope.js +328 -353
  59. package/lib/umd/parser/lessParser.js +727 -752
  60. package/lib/umd/parser/lessScanner.js +70 -90
  61. package/lib/umd/parser/scssErrors.js +31 -32
  62. package/lib/umd/parser/scssParser.js +809 -830
  63. package/lib/umd/parser/scssScanner.js +108 -128
  64. package/lib/umd/services/cssCodeActions.js +90 -93
  65. package/lib/umd/services/cssCompletion.js +1067 -1161
  66. package/lib/umd/services/cssFolding.js +203 -206
  67. package/lib/umd/services/cssFormatter.js +150 -150
  68. package/lib/umd/services/cssHover.js +161 -163
  69. package/lib/umd/services/cssNavigation.js +391 -482
  70. package/lib/umd/services/cssSelectionRange.js +60 -60
  71. package/lib/umd/services/cssValidation.js +54 -56
  72. package/lib/umd/services/lessCompletion.js +391 -409
  73. package/lib/umd/services/lint.js +531 -544
  74. package/lib/umd/services/lintRules.js +91 -95
  75. package/lib/umd/services/lintUtil.js +210 -218
  76. package/lib/umd/services/pathCompletion.js +171 -244
  77. package/lib/umd/services/scssCompletion.js +367 -390
  78. package/lib/umd/services/scssNavigation.js +95 -166
  79. package/lib/umd/services/selectorPrinting.js +510 -550
  80. package/lib/umd/utils/arrays.js +55 -61
  81. package/lib/umd/utils/objects.js +25 -25
  82. package/lib/umd/utils/resources.js +26 -39
  83. package/lib/umd/utils/strings.js +120 -122
  84. package/package.json +10 -10
@@ -1,353 +1,328 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- (function (factory) {
17
- if (typeof module === "object" && typeof module.exports === "object") {
18
- var v = factory(require, exports);
19
- if (v !== undefined) module.exports = v;
20
- }
21
- else if (typeof define === "function" && define.amd) {
22
- define(["require", "exports", "./cssNodes", "../utils/arrays"], factory);
23
- }
24
- })(function (require, exports) {
25
- /*---------------------------------------------------------------------------------------------
26
- * Copyright (c) Microsoft Corporation. All rights reserved.
27
- * Licensed under the MIT License. See License.txt in the project root for license information.
28
- *--------------------------------------------------------------------------------------------*/
29
- 'use strict';
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.Symbols = exports.ScopeBuilder = exports.Symbol = exports.GlobalScope = exports.Scope = void 0;
32
- var nodes = require("./cssNodes");
33
- var arrays_1 = require("../utils/arrays");
34
- var Scope = /** @class */ (function () {
35
- function Scope(offset, length) {
36
- this.offset = offset;
37
- this.length = length;
38
- this.symbols = [];
39
- this.parent = null;
40
- this.children = [];
41
- }
42
- Scope.prototype.addChild = function (scope) {
43
- this.children.push(scope);
44
- scope.setParent(this);
45
- };
46
- Scope.prototype.setParent = function (scope) {
47
- this.parent = scope;
48
- };
49
- Scope.prototype.findScope = function (offset, length) {
50
- if (length === void 0) { length = 0; }
51
- if (this.offset <= offset && this.offset + this.length > offset + length || this.offset === offset && this.length === length) {
52
- return this.findInScope(offset, length);
53
- }
54
- return null;
55
- };
56
- Scope.prototype.findInScope = function (offset, length) {
57
- if (length === void 0) { length = 0; }
58
- // find the first scope child that has an offset larger than offset + length
59
- var end = offset + length;
60
- var idx = (0, arrays_1.findFirst)(this.children, function (s) { return s.offset > end; });
61
- if (idx === 0) {
62
- // all scopes have offsets larger than our end
63
- return this;
64
- }
65
- var res = this.children[idx - 1];
66
- if (res.offset <= offset && res.offset + res.length >= offset + length) {
67
- return res.findInScope(offset, length);
68
- }
69
- return this;
70
- };
71
- Scope.prototype.addSymbol = function (symbol) {
72
- this.symbols.push(symbol);
73
- };
74
- Scope.prototype.getSymbol = function (name, type) {
75
- for (var index = 0; index < this.symbols.length; index++) {
76
- var symbol = this.symbols[index];
77
- if (symbol.name === name && symbol.type === type) {
78
- return symbol;
79
- }
80
- }
81
- return null;
82
- };
83
- Scope.prototype.getSymbols = function () {
84
- return this.symbols;
85
- };
86
- return Scope;
87
- }());
88
- exports.Scope = Scope;
89
- var GlobalScope = /** @class */ (function (_super) {
90
- __extends(GlobalScope, _super);
91
- function GlobalScope() {
92
- return _super.call(this, 0, Number.MAX_VALUE) || this;
93
- }
94
- return GlobalScope;
95
- }(Scope));
96
- exports.GlobalScope = GlobalScope;
97
- var Symbol = /** @class */ (function () {
98
- function Symbol(name, value, node, type) {
99
- this.name = name;
100
- this.value = value;
101
- this.node = node;
102
- this.type = type;
103
- }
104
- return Symbol;
105
- }());
106
- exports.Symbol = Symbol;
107
- var ScopeBuilder = /** @class */ (function () {
108
- function ScopeBuilder(scope) {
109
- this.scope = scope;
110
- }
111
- ScopeBuilder.prototype.addSymbol = function (node, name, value, type) {
112
- if (node.offset !== -1) {
113
- var current = this.scope.findScope(node.offset, node.length);
114
- if (current) {
115
- current.addSymbol(new Symbol(name, value, node, type));
116
- }
117
- }
118
- };
119
- ScopeBuilder.prototype.addScope = function (node) {
120
- if (node.offset !== -1) {
121
- var current = this.scope.findScope(node.offset, node.length);
122
- if (current && (current.offset !== node.offset || current.length !== node.length)) { // scope already known?
123
- var newScope = new Scope(node.offset, node.length);
124
- current.addChild(newScope);
125
- return newScope;
126
- }
127
- return current;
128
- }
129
- return null;
130
- };
131
- ScopeBuilder.prototype.addSymbolToChildScope = function (scopeNode, node, name, value, type) {
132
- if (scopeNode && scopeNode.offset !== -1) {
133
- var current = this.addScope(scopeNode); // create the scope or gets the existing one
134
- if (current) {
135
- current.addSymbol(new Symbol(name, value, node, type));
136
- }
137
- }
138
- };
139
- ScopeBuilder.prototype.visitNode = function (node) {
140
- switch (node.type) {
141
- case nodes.NodeType.Keyframe:
142
- this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Keyframe);
143
- return true;
144
- case nodes.NodeType.CustomPropertyDeclaration:
145
- return this.visitCustomPropertyDeclarationNode(node);
146
- case nodes.NodeType.VariableDeclaration:
147
- return this.visitVariableDeclarationNode(node);
148
- case nodes.NodeType.Ruleset:
149
- return this.visitRuleSet(node);
150
- case nodes.NodeType.MixinDeclaration:
151
- this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Mixin);
152
- return true;
153
- case nodes.NodeType.FunctionDeclaration:
154
- this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Function);
155
- return true;
156
- case nodes.NodeType.FunctionParameter: {
157
- return this.visitFunctionParameterNode(node);
158
- }
159
- case nodes.NodeType.Declarations:
160
- this.addScope(node);
161
- return true;
162
- case nodes.NodeType.For:
163
- var forNode = node;
164
- var scopeNode = forNode.getDeclarations();
165
- if (scopeNode && forNode.variable) {
166
- this.addSymbolToChildScope(scopeNode, forNode.variable, forNode.variable.getName(), void 0, nodes.ReferenceType.Variable);
167
- }
168
- return true;
169
- case nodes.NodeType.Each: {
170
- var eachNode = node;
171
- var scopeNode_1 = eachNode.getDeclarations();
172
- if (scopeNode_1) {
173
- var variables = eachNode.getVariables().getChildren();
174
- for (var _i = 0, variables_1 = variables; _i < variables_1.length; _i++) {
175
- var variable = variables_1[_i];
176
- this.addSymbolToChildScope(scopeNode_1, variable, variable.getName(), void 0, nodes.ReferenceType.Variable);
177
- }
178
- }
179
- return true;
180
- }
181
- }
182
- return true;
183
- };
184
- ScopeBuilder.prototype.visitRuleSet = function (node) {
185
- var current = this.scope.findScope(node.offset, node.length);
186
- if (current) {
187
- for (var _i = 0, _a = node.getSelectors().getChildren(); _i < _a.length; _i++) {
188
- var child = _a[_i];
189
- if (child instanceof nodes.Selector) {
190
- if (child.getChildren().length === 1) { // only selectors with a single element can be extended
191
- current.addSymbol(new Symbol(child.getChild(0).getText(), void 0, child, nodes.ReferenceType.Rule));
192
- }
193
- }
194
- }
195
- }
196
- return true;
197
- };
198
- ScopeBuilder.prototype.visitVariableDeclarationNode = function (node) {
199
- var value = node.getValue() ? node.getValue().getText() : void 0;
200
- this.addSymbol(node, node.getName(), value, nodes.ReferenceType.Variable);
201
- return true;
202
- };
203
- ScopeBuilder.prototype.visitFunctionParameterNode = function (node) {
204
- // parameters are part of the body scope
205
- var scopeNode = node.getParent().getDeclarations();
206
- if (scopeNode) {
207
- var valueNode = node.getDefaultValue();
208
- var value = valueNode ? valueNode.getText() : void 0;
209
- this.addSymbolToChildScope(scopeNode, node, node.getName(), value, nodes.ReferenceType.Variable);
210
- }
211
- return true;
212
- };
213
- ScopeBuilder.prototype.visitCustomPropertyDeclarationNode = function (node) {
214
- var value = node.getValue() ? node.getValue().getText() : '';
215
- this.addCSSVariable(node.getProperty(), node.getProperty().getName(), value, nodes.ReferenceType.Variable);
216
- return true;
217
- };
218
- ScopeBuilder.prototype.addCSSVariable = function (node, name, value, type) {
219
- if (node.offset !== -1) {
220
- this.scope.addSymbol(new Symbol(name, value, node, type));
221
- }
222
- };
223
- return ScopeBuilder;
224
- }());
225
- exports.ScopeBuilder = ScopeBuilder;
226
- var Symbols = /** @class */ (function () {
227
- function Symbols(node) {
228
- this.global = new GlobalScope();
229
- node.acceptVisitor(new ScopeBuilder(this.global));
230
- }
231
- Symbols.prototype.findSymbolsAtOffset = function (offset, referenceType) {
232
- var scope = this.global.findScope(offset, 0);
233
- var result = [];
234
- var names = {};
235
- while (scope) {
236
- var symbols = scope.getSymbols();
237
- for (var i = 0; i < symbols.length; i++) {
238
- var symbol = symbols[i];
239
- if (symbol.type === referenceType && !names[symbol.name]) {
240
- result.push(symbol);
241
- names[symbol.name] = true;
242
- }
243
- }
244
- scope = scope.parent;
245
- }
246
- return result;
247
- };
248
- Symbols.prototype.internalFindSymbol = function (node, referenceTypes) {
249
- var scopeNode = node;
250
- if (node.parent instanceof nodes.FunctionParameter && node.parent.getParent() instanceof nodes.BodyDeclaration) {
251
- scopeNode = node.parent.getParent().getDeclarations();
252
- }
253
- if (node.parent instanceof nodes.FunctionArgument && node.parent.getParent() instanceof nodes.Function) {
254
- var funcId = node.parent.getParent().getIdentifier();
255
- if (funcId) {
256
- var functionSymbol = this.internalFindSymbol(funcId, [nodes.ReferenceType.Function]);
257
- if (functionSymbol) {
258
- scopeNode = functionSymbol.node.getDeclarations();
259
- }
260
- }
261
- }
262
- if (!scopeNode) {
263
- return null;
264
- }
265
- var name = node.getText();
266
- var scope = this.global.findScope(scopeNode.offset, scopeNode.length);
267
- while (scope) {
268
- for (var index = 0; index < referenceTypes.length; index++) {
269
- var type = referenceTypes[index];
270
- var symbol = scope.getSymbol(name, type);
271
- if (symbol) {
272
- return symbol;
273
- }
274
- }
275
- scope = scope.parent;
276
- }
277
- return null;
278
- };
279
- Symbols.prototype.evaluateReferenceTypes = function (node) {
280
- if (node instanceof nodes.Identifier) {
281
- var referenceTypes = node.referenceTypes;
282
- if (referenceTypes) {
283
- return referenceTypes;
284
- }
285
- else {
286
- if (node.isCustomProperty) {
287
- return [nodes.ReferenceType.Variable];
288
- }
289
- // are a reference to a keyframe?
290
- var decl = nodes.getParentDeclaration(node);
291
- if (decl) {
292
- var propertyName = decl.getNonPrefixedPropertyName();
293
- if ((propertyName === 'animation' || propertyName === 'animation-name')
294
- && decl.getValue() && decl.getValue().offset === node.offset) {
295
- return [nodes.ReferenceType.Keyframe];
296
- }
297
- }
298
- }
299
- }
300
- else if (node instanceof nodes.Variable) {
301
- return [nodes.ReferenceType.Variable];
302
- }
303
- var selector = node.findAParent(nodes.NodeType.Selector, nodes.NodeType.ExtendsReference);
304
- if (selector) {
305
- return [nodes.ReferenceType.Rule];
306
- }
307
- return null;
308
- };
309
- Symbols.prototype.findSymbolFromNode = function (node) {
310
- if (!node) {
311
- return null;
312
- }
313
- while (node.type === nodes.NodeType.Interpolation) {
314
- node = node.getParent();
315
- }
316
- var referenceTypes = this.evaluateReferenceTypes(node);
317
- if (referenceTypes) {
318
- return this.internalFindSymbol(node, referenceTypes);
319
- }
320
- return null;
321
- };
322
- Symbols.prototype.matchesSymbol = function (node, symbol) {
323
- if (!node) {
324
- return false;
325
- }
326
- while (node.type === nodes.NodeType.Interpolation) {
327
- node = node.getParent();
328
- }
329
- if (!node.matches(symbol.name)) {
330
- return false;
331
- }
332
- var referenceTypes = this.evaluateReferenceTypes(node);
333
- if (!referenceTypes || referenceTypes.indexOf(symbol.type) === -1) {
334
- return false;
335
- }
336
- var nodeSymbol = this.internalFindSymbol(node, referenceTypes);
337
- return nodeSymbol === symbol;
338
- };
339
- Symbols.prototype.findSymbol = function (name, type, offset) {
340
- var scope = this.global.findScope(offset);
341
- while (scope) {
342
- var symbol = scope.getSymbol(name, type);
343
- if (symbol) {
344
- return symbol;
345
- }
346
- scope = scope.parent;
347
- }
348
- return null;
349
- };
350
- return Symbols;
351
- }());
352
- exports.Symbols = Symbols;
353
- });
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", "./cssNodes", "../utils/arrays"], 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.Symbols = exports.ScopeBuilder = exports.Symbol = exports.GlobalScope = exports.Scope = void 0;
17
+ const nodes = require("./cssNodes");
18
+ const arrays_1 = require("../utils/arrays");
19
+ class Scope {
20
+ constructor(offset, length) {
21
+ this.offset = offset;
22
+ this.length = length;
23
+ this.symbols = [];
24
+ this.parent = null;
25
+ this.children = [];
26
+ }
27
+ addChild(scope) {
28
+ this.children.push(scope);
29
+ scope.setParent(this);
30
+ }
31
+ setParent(scope) {
32
+ this.parent = scope;
33
+ }
34
+ findScope(offset, length = 0) {
35
+ if (this.offset <= offset && this.offset + this.length > offset + length || this.offset === offset && this.length === length) {
36
+ return this.findInScope(offset, length);
37
+ }
38
+ return null;
39
+ }
40
+ findInScope(offset, length = 0) {
41
+ // find the first scope child that has an offset larger than offset + length
42
+ const end = offset + length;
43
+ const idx = (0, arrays_1.findFirst)(this.children, s => s.offset > end);
44
+ if (idx === 0) {
45
+ // all scopes have offsets larger than our end
46
+ return this;
47
+ }
48
+ const res = this.children[idx - 1];
49
+ if (res.offset <= offset && res.offset + res.length >= offset + length) {
50
+ return res.findInScope(offset, length);
51
+ }
52
+ return this;
53
+ }
54
+ addSymbol(symbol) {
55
+ this.symbols.push(symbol);
56
+ }
57
+ getSymbol(name, type) {
58
+ for (let index = 0; index < this.symbols.length; index++) {
59
+ const symbol = this.symbols[index];
60
+ if (symbol.name === name && symbol.type === type) {
61
+ return symbol;
62
+ }
63
+ }
64
+ return null;
65
+ }
66
+ getSymbols() {
67
+ return this.symbols;
68
+ }
69
+ }
70
+ exports.Scope = Scope;
71
+ class GlobalScope extends Scope {
72
+ constructor() {
73
+ super(0, Number.MAX_VALUE);
74
+ }
75
+ }
76
+ exports.GlobalScope = GlobalScope;
77
+ class Symbol {
78
+ constructor(name, value, node, type) {
79
+ this.name = name;
80
+ this.value = value;
81
+ this.node = node;
82
+ this.type = type;
83
+ }
84
+ }
85
+ exports.Symbol = Symbol;
86
+ class ScopeBuilder {
87
+ constructor(scope) {
88
+ this.scope = scope;
89
+ }
90
+ addSymbol(node, name, value, type) {
91
+ if (node.offset !== -1) {
92
+ const current = this.scope.findScope(node.offset, node.length);
93
+ if (current) {
94
+ current.addSymbol(new Symbol(name, value, node, type));
95
+ }
96
+ }
97
+ }
98
+ addScope(node) {
99
+ if (node.offset !== -1) {
100
+ const current = this.scope.findScope(node.offset, node.length);
101
+ if (current && (current.offset !== node.offset || current.length !== node.length)) { // scope already known?
102
+ const newScope = new Scope(node.offset, node.length);
103
+ current.addChild(newScope);
104
+ return newScope;
105
+ }
106
+ return current;
107
+ }
108
+ return null;
109
+ }
110
+ addSymbolToChildScope(scopeNode, node, name, value, type) {
111
+ if (scopeNode && scopeNode.offset !== -1) {
112
+ const current = this.addScope(scopeNode); // create the scope or gets the existing one
113
+ if (current) {
114
+ current.addSymbol(new Symbol(name, value, node, type));
115
+ }
116
+ }
117
+ }
118
+ visitNode(node) {
119
+ switch (node.type) {
120
+ case nodes.NodeType.Keyframe:
121
+ this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Keyframe);
122
+ return true;
123
+ case nodes.NodeType.CustomPropertyDeclaration:
124
+ return this.visitCustomPropertyDeclarationNode(node);
125
+ case nodes.NodeType.VariableDeclaration:
126
+ return this.visitVariableDeclarationNode(node);
127
+ case nodes.NodeType.Ruleset:
128
+ return this.visitRuleSet(node);
129
+ case nodes.NodeType.MixinDeclaration:
130
+ this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Mixin);
131
+ return true;
132
+ case nodes.NodeType.FunctionDeclaration:
133
+ this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Function);
134
+ return true;
135
+ case nodes.NodeType.FunctionParameter: {
136
+ return this.visitFunctionParameterNode(node);
137
+ }
138
+ case nodes.NodeType.Declarations:
139
+ this.addScope(node);
140
+ return true;
141
+ case nodes.NodeType.For:
142
+ const forNode = node;
143
+ const scopeNode = forNode.getDeclarations();
144
+ if (scopeNode && forNode.variable) {
145
+ this.addSymbolToChildScope(scopeNode, forNode.variable, forNode.variable.getName(), void 0, nodes.ReferenceType.Variable);
146
+ }
147
+ return true;
148
+ case nodes.NodeType.Each: {
149
+ const eachNode = node;
150
+ const scopeNode = eachNode.getDeclarations();
151
+ if (scopeNode) {
152
+ const variables = eachNode.getVariables().getChildren();
153
+ for (const variable of variables) {
154
+ this.addSymbolToChildScope(scopeNode, variable, variable.getName(), void 0, nodes.ReferenceType.Variable);
155
+ }
156
+ }
157
+ return true;
158
+ }
159
+ }
160
+ return true;
161
+ }
162
+ visitRuleSet(node) {
163
+ const current = this.scope.findScope(node.offset, node.length);
164
+ if (current) {
165
+ for (const child of node.getSelectors().getChildren()) {
166
+ if (child instanceof nodes.Selector) {
167
+ if (child.getChildren().length === 1) { // only selectors with a single element can be extended
168
+ current.addSymbol(new Symbol(child.getChild(0).getText(), void 0, child, nodes.ReferenceType.Rule));
169
+ }
170
+ }
171
+ }
172
+ }
173
+ return true;
174
+ }
175
+ visitVariableDeclarationNode(node) {
176
+ const value = node.getValue() ? node.getValue().getText() : void 0;
177
+ this.addSymbol(node, node.getName(), value, nodes.ReferenceType.Variable);
178
+ return true;
179
+ }
180
+ visitFunctionParameterNode(node) {
181
+ // parameters are part of the body scope
182
+ const scopeNode = node.getParent().getDeclarations();
183
+ if (scopeNode) {
184
+ const valueNode = node.getDefaultValue();
185
+ const value = valueNode ? valueNode.getText() : void 0;
186
+ this.addSymbolToChildScope(scopeNode, node, node.getName(), value, nodes.ReferenceType.Variable);
187
+ }
188
+ return true;
189
+ }
190
+ visitCustomPropertyDeclarationNode(node) {
191
+ const value = node.getValue() ? node.getValue().getText() : '';
192
+ this.addCSSVariable(node.getProperty(), node.getProperty().getName(), value, nodes.ReferenceType.Variable);
193
+ return true;
194
+ }
195
+ addCSSVariable(node, name, value, type) {
196
+ if (node.offset !== -1) {
197
+ this.scope.addSymbol(new Symbol(name, value, node, type));
198
+ }
199
+ }
200
+ }
201
+ exports.ScopeBuilder = ScopeBuilder;
202
+ class Symbols {
203
+ constructor(node) {
204
+ this.global = new GlobalScope();
205
+ node.acceptVisitor(new ScopeBuilder(this.global));
206
+ }
207
+ findSymbolsAtOffset(offset, referenceType) {
208
+ let scope = this.global.findScope(offset, 0);
209
+ const result = [];
210
+ const names = {};
211
+ while (scope) {
212
+ const symbols = scope.getSymbols();
213
+ for (let i = 0; i < symbols.length; i++) {
214
+ const symbol = symbols[i];
215
+ if (symbol.type === referenceType && !names[symbol.name]) {
216
+ result.push(symbol);
217
+ names[symbol.name] = true;
218
+ }
219
+ }
220
+ scope = scope.parent;
221
+ }
222
+ return result;
223
+ }
224
+ internalFindSymbol(node, referenceTypes) {
225
+ let scopeNode = node;
226
+ if (node.parent instanceof nodes.FunctionParameter && node.parent.getParent() instanceof nodes.BodyDeclaration) {
227
+ scopeNode = node.parent.getParent().getDeclarations();
228
+ }
229
+ if (node.parent instanceof nodes.FunctionArgument && node.parent.getParent() instanceof nodes.Function) {
230
+ const funcId = node.parent.getParent().getIdentifier();
231
+ if (funcId) {
232
+ const functionSymbol = this.internalFindSymbol(funcId, [nodes.ReferenceType.Function]);
233
+ if (functionSymbol) {
234
+ scopeNode = functionSymbol.node.getDeclarations();
235
+ }
236
+ }
237
+ }
238
+ if (!scopeNode) {
239
+ return null;
240
+ }
241
+ const name = node.getText();
242
+ let scope = this.global.findScope(scopeNode.offset, scopeNode.length);
243
+ while (scope) {
244
+ for (let index = 0; index < referenceTypes.length; index++) {
245
+ const type = referenceTypes[index];
246
+ const symbol = scope.getSymbol(name, type);
247
+ if (symbol) {
248
+ return symbol;
249
+ }
250
+ }
251
+ scope = scope.parent;
252
+ }
253
+ return null;
254
+ }
255
+ evaluateReferenceTypes(node) {
256
+ if (node instanceof nodes.Identifier) {
257
+ const referenceTypes = node.referenceTypes;
258
+ if (referenceTypes) {
259
+ return referenceTypes;
260
+ }
261
+ else {
262
+ if (node.isCustomProperty) {
263
+ return [nodes.ReferenceType.Variable];
264
+ }
265
+ // are a reference to a keyframe?
266
+ const decl = nodes.getParentDeclaration(node);
267
+ if (decl) {
268
+ const propertyName = decl.getNonPrefixedPropertyName();
269
+ if ((propertyName === 'animation' || propertyName === 'animation-name')
270
+ && decl.getValue() && decl.getValue().offset === node.offset) {
271
+ return [nodes.ReferenceType.Keyframe];
272
+ }
273
+ }
274
+ }
275
+ }
276
+ else if (node instanceof nodes.Variable) {
277
+ return [nodes.ReferenceType.Variable];
278
+ }
279
+ const selector = node.findAParent(nodes.NodeType.Selector, nodes.NodeType.ExtendsReference);
280
+ if (selector) {
281
+ return [nodes.ReferenceType.Rule];
282
+ }
283
+ return null;
284
+ }
285
+ findSymbolFromNode(node) {
286
+ if (!node) {
287
+ return null;
288
+ }
289
+ while (node.type === nodes.NodeType.Interpolation) {
290
+ node = node.getParent();
291
+ }
292
+ const referenceTypes = this.evaluateReferenceTypes(node);
293
+ if (referenceTypes) {
294
+ return this.internalFindSymbol(node, referenceTypes);
295
+ }
296
+ return null;
297
+ }
298
+ matchesSymbol(node, symbol) {
299
+ if (!node) {
300
+ return false;
301
+ }
302
+ while (node.type === nodes.NodeType.Interpolation) {
303
+ node = node.getParent();
304
+ }
305
+ if (!node.matches(symbol.name)) {
306
+ return false;
307
+ }
308
+ const referenceTypes = this.evaluateReferenceTypes(node);
309
+ if (!referenceTypes || referenceTypes.indexOf(symbol.type) === -1) {
310
+ return false;
311
+ }
312
+ const nodeSymbol = this.internalFindSymbol(node, referenceTypes);
313
+ return nodeSymbol === symbol;
314
+ }
315
+ findSymbol(name, type, offset) {
316
+ let scope = this.global.findScope(offset);
317
+ while (scope) {
318
+ const symbol = scope.getSymbol(name, type);
319
+ if (symbol) {
320
+ return symbol;
321
+ }
322
+ scope = scope.parent;
323
+ }
324
+ return null;
325
+ }
326
+ }
327
+ exports.Symbols = Symbols;
328
+ });