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
@@ -3,129 +3,105 @@
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  'use strict';
6
- var __extends = (this && this.__extends) || (function () {
7
- var extendStatics = function (d, b) {
8
- extendStatics = Object.setPrototypeOf ||
9
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11
- return extendStatics(d, b);
12
- };
13
- return function (d, b) {
14
- if (typeof b !== "function" && b !== null)
15
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
- extendStatics(d, b);
17
- function __() { this.constructor = d; }
18
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
- };
20
- })();
21
6
  import * as nodes from './cssNodes';
22
7
  import { findFirst } from '../utils/arrays';
23
- var Scope = /** @class */ (function () {
24
- function Scope(offset, length) {
8
+ export class Scope {
9
+ constructor(offset, length) {
25
10
  this.offset = offset;
26
11
  this.length = length;
27
12
  this.symbols = [];
28
13
  this.parent = null;
29
14
  this.children = [];
30
15
  }
31
- Scope.prototype.addChild = function (scope) {
16
+ addChild(scope) {
32
17
  this.children.push(scope);
33
18
  scope.setParent(this);
34
- };
35
- Scope.prototype.setParent = function (scope) {
19
+ }
20
+ setParent(scope) {
36
21
  this.parent = scope;
37
- };
38
- Scope.prototype.findScope = function (offset, length) {
39
- if (length === void 0) { length = 0; }
22
+ }
23
+ findScope(offset, length = 0) {
40
24
  if (this.offset <= offset && this.offset + this.length > offset + length || this.offset === offset && this.length === length) {
41
25
  return this.findInScope(offset, length);
42
26
  }
43
27
  return null;
44
- };
45
- Scope.prototype.findInScope = function (offset, length) {
46
- if (length === void 0) { length = 0; }
28
+ }
29
+ findInScope(offset, length = 0) {
47
30
  // find the first scope child that has an offset larger than offset + length
48
- var end = offset + length;
49
- var idx = findFirst(this.children, function (s) { return s.offset > end; });
31
+ const end = offset + length;
32
+ const idx = findFirst(this.children, s => s.offset > end);
50
33
  if (idx === 0) {
51
34
  // all scopes have offsets larger than our end
52
35
  return this;
53
36
  }
54
- var res = this.children[idx - 1];
37
+ const res = this.children[idx - 1];
55
38
  if (res.offset <= offset && res.offset + res.length >= offset + length) {
56
39
  return res.findInScope(offset, length);
57
40
  }
58
41
  return this;
59
- };
60
- Scope.prototype.addSymbol = function (symbol) {
42
+ }
43
+ addSymbol(symbol) {
61
44
  this.symbols.push(symbol);
62
- };
63
- Scope.prototype.getSymbol = function (name, type) {
64
- for (var index = 0; index < this.symbols.length; index++) {
65
- var symbol = this.symbols[index];
45
+ }
46
+ getSymbol(name, type) {
47
+ for (let index = 0; index < this.symbols.length; index++) {
48
+ const symbol = this.symbols[index];
66
49
  if (symbol.name === name && symbol.type === type) {
67
50
  return symbol;
68
51
  }
69
52
  }
70
53
  return null;
71
- };
72
- Scope.prototype.getSymbols = function () {
54
+ }
55
+ getSymbols() {
73
56
  return this.symbols;
74
- };
75
- return Scope;
76
- }());
77
- export { Scope };
78
- var GlobalScope = /** @class */ (function (_super) {
79
- __extends(GlobalScope, _super);
80
- function GlobalScope() {
81
- return _super.call(this, 0, Number.MAX_VALUE) || this;
82
57
  }
83
- return GlobalScope;
84
- }(Scope));
85
- export { GlobalScope };
86
- var Symbol = /** @class */ (function () {
87
- function Symbol(name, value, node, type) {
58
+ }
59
+ export class GlobalScope extends Scope {
60
+ constructor() {
61
+ super(0, Number.MAX_VALUE);
62
+ }
63
+ }
64
+ export class Symbol {
65
+ constructor(name, value, node, type) {
88
66
  this.name = name;
89
67
  this.value = value;
90
68
  this.node = node;
91
69
  this.type = type;
92
70
  }
93
- return Symbol;
94
- }());
95
- export { Symbol };
96
- var ScopeBuilder = /** @class */ (function () {
97
- function ScopeBuilder(scope) {
71
+ }
72
+ export class ScopeBuilder {
73
+ constructor(scope) {
98
74
  this.scope = scope;
99
75
  }
100
- ScopeBuilder.prototype.addSymbol = function (node, name, value, type) {
76
+ addSymbol(node, name, value, type) {
101
77
  if (node.offset !== -1) {
102
- var current = this.scope.findScope(node.offset, node.length);
78
+ const current = this.scope.findScope(node.offset, node.length);
103
79
  if (current) {
104
80
  current.addSymbol(new Symbol(name, value, node, type));
105
81
  }
106
82
  }
107
- };
108
- ScopeBuilder.prototype.addScope = function (node) {
83
+ }
84
+ addScope(node) {
109
85
  if (node.offset !== -1) {
110
- var current = this.scope.findScope(node.offset, node.length);
86
+ const current = this.scope.findScope(node.offset, node.length);
111
87
  if (current && (current.offset !== node.offset || current.length !== node.length)) { // scope already known?
112
- var newScope = new Scope(node.offset, node.length);
88
+ const newScope = new Scope(node.offset, node.length);
113
89
  current.addChild(newScope);
114
90
  return newScope;
115
91
  }
116
92
  return current;
117
93
  }
118
94
  return null;
119
- };
120
- ScopeBuilder.prototype.addSymbolToChildScope = function (scopeNode, node, name, value, type) {
95
+ }
96
+ addSymbolToChildScope(scopeNode, node, name, value, type) {
121
97
  if (scopeNode && scopeNode.offset !== -1) {
122
- var current = this.addScope(scopeNode); // create the scope or gets the existing one
98
+ const current = this.addScope(scopeNode); // create the scope or gets the existing one
123
99
  if (current) {
124
100
  current.addSymbol(new Symbol(name, value, node, type));
125
101
  }
126
102
  }
127
- };
128
- ScopeBuilder.prototype.visitNode = function (node) {
103
+ }
104
+ visitNode(node) {
129
105
  switch (node.type) {
130
106
  case nodes.NodeType.Keyframe:
131
107
  this.addSymbol(node, node.getName(), void 0, nodes.ReferenceType.Keyframe);
@@ -149,32 +125,30 @@ var ScopeBuilder = /** @class */ (function () {
149
125
  this.addScope(node);
150
126
  return true;
151
127
  case nodes.NodeType.For:
152
- var forNode = node;
153
- var scopeNode = forNode.getDeclarations();
128
+ const forNode = node;
129
+ const scopeNode = forNode.getDeclarations();
154
130
  if (scopeNode && forNode.variable) {
155
131
  this.addSymbolToChildScope(scopeNode, forNode.variable, forNode.variable.getName(), void 0, nodes.ReferenceType.Variable);
156
132
  }
157
133
  return true;
158
134
  case nodes.NodeType.Each: {
159
- var eachNode = node;
160
- var scopeNode_1 = eachNode.getDeclarations();
161
- if (scopeNode_1) {
162
- var variables = eachNode.getVariables().getChildren();
163
- for (var _i = 0, variables_1 = variables; _i < variables_1.length; _i++) {
164
- var variable = variables_1[_i];
165
- this.addSymbolToChildScope(scopeNode_1, variable, variable.getName(), void 0, nodes.ReferenceType.Variable);
135
+ const eachNode = node;
136
+ const scopeNode = eachNode.getDeclarations();
137
+ if (scopeNode) {
138
+ const variables = eachNode.getVariables().getChildren();
139
+ for (const variable of variables) {
140
+ this.addSymbolToChildScope(scopeNode, variable, variable.getName(), void 0, nodes.ReferenceType.Variable);
166
141
  }
167
142
  }
168
143
  return true;
169
144
  }
170
145
  }
171
146
  return true;
172
- };
173
- ScopeBuilder.prototype.visitRuleSet = function (node) {
174
- var current = this.scope.findScope(node.offset, node.length);
147
+ }
148
+ visitRuleSet(node) {
149
+ const current = this.scope.findScope(node.offset, node.length);
175
150
  if (current) {
176
- for (var _i = 0, _a = node.getSelectors().getChildren(); _i < _a.length; _i++) {
177
- var child = _a[_i];
151
+ for (const child of node.getSelectors().getChildren()) {
178
152
  if (child instanceof nodes.Selector) {
179
153
  if (child.getChildren().length === 1) { // only selectors with a single element can be extended
180
154
  current.addSymbol(new Symbol(child.getChild(0).getText(), void 0, child, nodes.ReferenceType.Rule));
@@ -183,48 +157,46 @@ var ScopeBuilder = /** @class */ (function () {
183
157
  }
184
158
  }
185
159
  return true;
186
- };
187
- ScopeBuilder.prototype.visitVariableDeclarationNode = function (node) {
188
- var value = node.getValue() ? node.getValue().getText() : void 0;
160
+ }
161
+ visitVariableDeclarationNode(node) {
162
+ const value = node.getValue() ? node.getValue().getText() : void 0;
189
163
  this.addSymbol(node, node.getName(), value, nodes.ReferenceType.Variable);
190
164
  return true;
191
- };
192
- ScopeBuilder.prototype.visitFunctionParameterNode = function (node) {
165
+ }
166
+ visitFunctionParameterNode(node) {
193
167
  // parameters are part of the body scope
194
- var scopeNode = node.getParent().getDeclarations();
168
+ const scopeNode = node.getParent().getDeclarations();
195
169
  if (scopeNode) {
196
- var valueNode = node.getDefaultValue();
197
- var value = valueNode ? valueNode.getText() : void 0;
170
+ const valueNode = node.getDefaultValue();
171
+ const value = valueNode ? valueNode.getText() : void 0;
198
172
  this.addSymbolToChildScope(scopeNode, node, node.getName(), value, nodes.ReferenceType.Variable);
199
173
  }
200
174
  return true;
201
- };
202
- ScopeBuilder.prototype.visitCustomPropertyDeclarationNode = function (node) {
203
- var value = node.getValue() ? node.getValue().getText() : '';
175
+ }
176
+ visitCustomPropertyDeclarationNode(node) {
177
+ const value = node.getValue() ? node.getValue().getText() : '';
204
178
  this.addCSSVariable(node.getProperty(), node.getProperty().getName(), value, nodes.ReferenceType.Variable);
205
179
  return true;
206
- };
207
- ScopeBuilder.prototype.addCSSVariable = function (node, name, value, type) {
180
+ }
181
+ addCSSVariable(node, name, value, type) {
208
182
  if (node.offset !== -1) {
209
183
  this.scope.addSymbol(new Symbol(name, value, node, type));
210
184
  }
211
- };
212
- return ScopeBuilder;
213
- }());
214
- export { ScopeBuilder };
215
- var Symbols = /** @class */ (function () {
216
- function Symbols(node) {
185
+ }
186
+ }
187
+ export class Symbols {
188
+ constructor(node) {
217
189
  this.global = new GlobalScope();
218
190
  node.acceptVisitor(new ScopeBuilder(this.global));
219
191
  }
220
- Symbols.prototype.findSymbolsAtOffset = function (offset, referenceType) {
221
- var scope = this.global.findScope(offset, 0);
222
- var result = [];
223
- var names = {};
192
+ findSymbolsAtOffset(offset, referenceType) {
193
+ let scope = this.global.findScope(offset, 0);
194
+ const result = [];
195
+ const names = {};
224
196
  while (scope) {
225
- var symbols = scope.getSymbols();
226
- for (var i = 0; i < symbols.length; i++) {
227
- var symbol = symbols[i];
197
+ const symbols = scope.getSymbols();
198
+ for (let i = 0; i < symbols.length; i++) {
199
+ const symbol = symbols[i];
228
200
  if (symbol.type === referenceType && !names[symbol.name]) {
229
201
  result.push(symbol);
230
202
  names[symbol.name] = true;
@@ -233,16 +205,16 @@ var Symbols = /** @class */ (function () {
233
205
  scope = scope.parent;
234
206
  }
235
207
  return result;
236
- };
237
- Symbols.prototype.internalFindSymbol = function (node, referenceTypes) {
238
- var scopeNode = node;
208
+ }
209
+ internalFindSymbol(node, referenceTypes) {
210
+ let scopeNode = node;
239
211
  if (node.parent instanceof nodes.FunctionParameter && node.parent.getParent() instanceof nodes.BodyDeclaration) {
240
212
  scopeNode = node.parent.getParent().getDeclarations();
241
213
  }
242
214
  if (node.parent instanceof nodes.FunctionArgument && node.parent.getParent() instanceof nodes.Function) {
243
- var funcId = node.parent.getParent().getIdentifier();
215
+ const funcId = node.parent.getParent().getIdentifier();
244
216
  if (funcId) {
245
- var functionSymbol = this.internalFindSymbol(funcId, [nodes.ReferenceType.Function]);
217
+ const functionSymbol = this.internalFindSymbol(funcId, [nodes.ReferenceType.Function]);
246
218
  if (functionSymbol) {
247
219
  scopeNode = functionSymbol.node.getDeclarations();
248
220
  }
@@ -251,12 +223,12 @@ var Symbols = /** @class */ (function () {
251
223
  if (!scopeNode) {
252
224
  return null;
253
225
  }
254
- var name = node.getText();
255
- var scope = this.global.findScope(scopeNode.offset, scopeNode.length);
226
+ const name = node.getText();
227
+ let scope = this.global.findScope(scopeNode.offset, scopeNode.length);
256
228
  while (scope) {
257
- for (var index = 0; index < referenceTypes.length; index++) {
258
- var type = referenceTypes[index];
259
- var symbol = scope.getSymbol(name, type);
229
+ for (let index = 0; index < referenceTypes.length; index++) {
230
+ const type = referenceTypes[index];
231
+ const symbol = scope.getSymbol(name, type);
260
232
  if (symbol) {
261
233
  return symbol;
262
234
  }
@@ -264,10 +236,10 @@ var Symbols = /** @class */ (function () {
264
236
  scope = scope.parent;
265
237
  }
266
238
  return null;
267
- };
268
- Symbols.prototype.evaluateReferenceTypes = function (node) {
239
+ }
240
+ evaluateReferenceTypes(node) {
269
241
  if (node instanceof nodes.Identifier) {
270
- var referenceTypes = node.referenceTypes;
242
+ const referenceTypes = node.referenceTypes;
271
243
  if (referenceTypes) {
272
244
  return referenceTypes;
273
245
  }
@@ -276,9 +248,9 @@ var Symbols = /** @class */ (function () {
276
248
  return [nodes.ReferenceType.Variable];
277
249
  }
278
250
  // are a reference to a keyframe?
279
- var decl = nodes.getParentDeclaration(node);
251
+ const decl = nodes.getParentDeclaration(node);
280
252
  if (decl) {
281
- var propertyName = decl.getNonPrefixedPropertyName();
253
+ const propertyName = decl.getNonPrefixedPropertyName();
282
254
  if ((propertyName === 'animation' || propertyName === 'animation-name')
283
255
  && decl.getValue() && decl.getValue().offset === node.offset) {
284
256
  return [nodes.ReferenceType.Keyframe];
@@ -289,26 +261,26 @@ var Symbols = /** @class */ (function () {
289
261
  else if (node instanceof nodes.Variable) {
290
262
  return [nodes.ReferenceType.Variable];
291
263
  }
292
- var selector = node.findAParent(nodes.NodeType.Selector, nodes.NodeType.ExtendsReference);
264
+ const selector = node.findAParent(nodes.NodeType.Selector, nodes.NodeType.ExtendsReference);
293
265
  if (selector) {
294
266
  return [nodes.ReferenceType.Rule];
295
267
  }
296
268
  return null;
297
- };
298
- Symbols.prototype.findSymbolFromNode = function (node) {
269
+ }
270
+ findSymbolFromNode(node) {
299
271
  if (!node) {
300
272
  return null;
301
273
  }
302
274
  while (node.type === nodes.NodeType.Interpolation) {
303
275
  node = node.getParent();
304
276
  }
305
- var referenceTypes = this.evaluateReferenceTypes(node);
277
+ const referenceTypes = this.evaluateReferenceTypes(node);
306
278
  if (referenceTypes) {
307
279
  return this.internalFindSymbol(node, referenceTypes);
308
280
  }
309
281
  return null;
310
- };
311
- Symbols.prototype.matchesSymbol = function (node, symbol) {
282
+ }
283
+ matchesSymbol(node, symbol) {
312
284
  if (!node) {
313
285
  return false;
314
286
  }
@@ -318,24 +290,22 @@ var Symbols = /** @class */ (function () {
318
290
  if (!node.matches(symbol.name)) {
319
291
  return false;
320
292
  }
321
- var referenceTypes = this.evaluateReferenceTypes(node);
293
+ const referenceTypes = this.evaluateReferenceTypes(node);
322
294
  if (!referenceTypes || referenceTypes.indexOf(symbol.type) === -1) {
323
295
  return false;
324
296
  }
325
- var nodeSymbol = this.internalFindSymbol(node, referenceTypes);
297
+ const nodeSymbol = this.internalFindSymbol(node, referenceTypes);
326
298
  return nodeSymbol === symbol;
327
- };
328
- Symbols.prototype.findSymbol = function (name, type, offset) {
329
- var scope = this.global.findScope(offset);
299
+ }
300
+ findSymbol(name, type, offset) {
301
+ let scope = this.global.findScope(offset);
330
302
  while (scope) {
331
- var symbol = scope.getSymbol(name, type);
303
+ const symbol = scope.getSymbol(name, type);
332
304
  if (symbol) {
333
305
  return symbol;
334
306
  }
335
307
  scope = scope.parent;
336
308
  }
337
309
  return null;
338
- };
339
- return Symbols;
340
- }());
341
- export { Symbols };
310
+ }
311
+ }