vscode-css-languageservice 5.4.2 → 6.1.0

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