vscode-css-languageservice 6.0.1 → 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 (87) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/beautify/beautify-css.js +11 -4
  4. package/lib/esm/cssLanguageService.d.ts +38 -37
  5. package/lib/esm/cssLanguageService.js +73 -72
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +22089 -21959
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -469
  11. package/lib/esm/languageFacts/dataManager.js +88 -88
  12. package/lib/esm/languageFacts/dataProvider.js +73 -73
  13. package/lib/esm/languageFacts/entry.js +137 -137
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -48
  16. package/lib/esm/parser/cssNodes.js +1511 -1502
  17. package/lib/esm/parser/cssParser.js +1606 -1534
  18. package/lib/esm/parser/cssScanner.js +592 -592
  19. package/lib/esm/parser/cssSymbolScope.js +311 -311
  20. package/lib/esm/parser/lessParser.js +715 -714
  21. package/lib/esm/parser/lessScanner.js +57 -57
  22. package/lib/esm/parser/scssErrors.js +18 -18
  23. package/lib/esm/parser/scssParser.js +806 -796
  24. package/lib/esm/parser/scssScanner.js +95 -95
  25. package/lib/esm/services/cssCodeActions.js +77 -77
  26. package/lib/esm/services/cssCompletion.js +1054 -1054
  27. package/lib/esm/services/cssFolding.js +190 -190
  28. package/lib/esm/services/cssFormatter.js +136 -136
  29. package/lib/esm/services/cssHover.js +148 -148
  30. package/lib/esm/services/cssNavigation.js +441 -378
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -41
  33. package/lib/esm/services/lessCompletion.js +378 -378
  34. package/lib/esm/services/lint.js +518 -518
  35. package/lib/esm/services/lintRules.js +76 -76
  36. package/lib/esm/services/lintUtil.js +196 -196
  37. package/lib/esm/services/pathCompletion.js +157 -157
  38. package/lib/esm/services/scssCompletion.js +354 -354
  39. package/lib/esm/services/scssNavigation.js +82 -82
  40. package/lib/esm/services/selectorPrinting.js +492 -492
  41. package/lib/esm/utils/arrays.js +40 -40
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -11
  44. package/lib/esm/utils/strings.js +102 -102
  45. package/lib/umd/beautify/beautify-css.js +11 -4
  46. package/lib/umd/cssLanguageService.d.ts +38 -37
  47. package/lib/umd/cssLanguageService.js +104 -99
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  49. package/lib/umd/cssLanguageTypes.js +89 -89
  50. package/lib/umd/data/webCustomData.js +22102 -21972
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -492
  53. package/lib/umd/languageFacts/dataManager.js +101 -101
  54. package/lib/umd/languageFacts/dataProvider.js +86 -86
  55. package/lib/umd/languageFacts/entry.js +152 -152
  56. package/lib/umd/languageFacts/facts.js +33 -29
  57. package/lib/umd/parser/cssErrors.js +61 -61
  58. package/lib/umd/parser/cssNodes.js +1597 -1587
  59. package/lib/umd/parser/cssParser.js +1619 -1547
  60. package/lib/umd/parser/cssScanner.js +606 -606
  61. package/lib/umd/parser/cssSymbolScope.js +328 -328
  62. package/lib/umd/parser/lessParser.js +728 -727
  63. package/lib/umd/parser/lessScanner.js +70 -70
  64. package/lib/umd/parser/scssErrors.js +31 -31
  65. package/lib/umd/parser/scssParser.js +819 -809
  66. package/lib/umd/parser/scssScanner.js +108 -108
  67. package/lib/umd/services/cssCodeActions.js +90 -90
  68. package/lib/umd/services/cssCompletion.js +1067 -1067
  69. package/lib/umd/services/cssFolding.js +203 -203
  70. package/lib/umd/services/cssFormatter.js +150 -150
  71. package/lib/umd/services/cssHover.js +161 -161
  72. package/lib/umd/services/cssNavigation.js +454 -391
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -54
  75. package/lib/umd/services/lessCompletion.js +391 -391
  76. package/lib/umd/services/lint.js +531 -531
  77. package/lib/umd/services/lintRules.js +91 -91
  78. package/lib/umd/services/lintUtil.js +210 -210
  79. package/lib/umd/services/pathCompletion.js +171 -171
  80. package/lib/umd/services/scssCompletion.js +367 -367
  81. package/lib/umd/services/scssNavigation.js +95 -95
  82. package/lib/umd/services/selectorPrinting.js +510 -510
  83. package/lib/umd/utils/arrays.js +55 -55
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -26
  86. package/lib/umd/utils/strings.js +120 -120
  87. package/package.json +13 -12
@@ -1,1587 +1,1597 @@
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", "../utils/strings"], 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.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
17
- const strings_1 = require("../utils/strings");
18
- /// <summary>
19
- /// Nodes for the css 2.1 specification. See for reference:
20
- /// http://www.w3.org/TR/CSS21/grammar.html#grammar
21
- /// </summary>
22
- var NodeType;
23
- (function (NodeType) {
24
- NodeType[NodeType["Undefined"] = 0] = "Undefined";
25
- NodeType[NodeType["Identifier"] = 1] = "Identifier";
26
- NodeType[NodeType["Stylesheet"] = 2] = "Stylesheet";
27
- NodeType[NodeType["Ruleset"] = 3] = "Ruleset";
28
- NodeType[NodeType["Selector"] = 4] = "Selector";
29
- NodeType[NodeType["SimpleSelector"] = 5] = "SimpleSelector";
30
- NodeType[NodeType["SelectorInterpolation"] = 6] = "SelectorInterpolation";
31
- NodeType[NodeType["SelectorCombinator"] = 7] = "SelectorCombinator";
32
- NodeType[NodeType["SelectorCombinatorParent"] = 8] = "SelectorCombinatorParent";
33
- NodeType[NodeType["SelectorCombinatorSibling"] = 9] = "SelectorCombinatorSibling";
34
- NodeType[NodeType["SelectorCombinatorAllSiblings"] = 10] = "SelectorCombinatorAllSiblings";
35
- NodeType[NodeType["SelectorCombinatorShadowPiercingDescendant"] = 11] = "SelectorCombinatorShadowPiercingDescendant";
36
- NodeType[NodeType["Page"] = 12] = "Page";
37
- NodeType[NodeType["PageBoxMarginBox"] = 13] = "PageBoxMarginBox";
38
- NodeType[NodeType["ClassSelector"] = 14] = "ClassSelector";
39
- NodeType[NodeType["IdentifierSelector"] = 15] = "IdentifierSelector";
40
- NodeType[NodeType["ElementNameSelector"] = 16] = "ElementNameSelector";
41
- NodeType[NodeType["PseudoSelector"] = 17] = "PseudoSelector";
42
- NodeType[NodeType["AttributeSelector"] = 18] = "AttributeSelector";
43
- NodeType[NodeType["Declaration"] = 19] = "Declaration";
44
- NodeType[NodeType["Declarations"] = 20] = "Declarations";
45
- NodeType[NodeType["Property"] = 21] = "Property";
46
- NodeType[NodeType["Expression"] = 22] = "Expression";
47
- NodeType[NodeType["BinaryExpression"] = 23] = "BinaryExpression";
48
- NodeType[NodeType["Term"] = 24] = "Term";
49
- NodeType[NodeType["Operator"] = 25] = "Operator";
50
- NodeType[NodeType["Value"] = 26] = "Value";
51
- NodeType[NodeType["StringLiteral"] = 27] = "StringLiteral";
52
- NodeType[NodeType["URILiteral"] = 28] = "URILiteral";
53
- NodeType[NodeType["EscapedValue"] = 29] = "EscapedValue";
54
- NodeType[NodeType["Function"] = 30] = "Function";
55
- NodeType[NodeType["NumericValue"] = 31] = "NumericValue";
56
- NodeType[NodeType["HexColorValue"] = 32] = "HexColorValue";
57
- NodeType[NodeType["RatioValue"] = 33] = "RatioValue";
58
- NodeType[NodeType["MixinDeclaration"] = 34] = "MixinDeclaration";
59
- NodeType[NodeType["MixinReference"] = 35] = "MixinReference";
60
- NodeType[NodeType["VariableName"] = 36] = "VariableName";
61
- NodeType[NodeType["VariableDeclaration"] = 37] = "VariableDeclaration";
62
- NodeType[NodeType["Prio"] = 38] = "Prio";
63
- NodeType[NodeType["Interpolation"] = 39] = "Interpolation";
64
- NodeType[NodeType["NestedProperties"] = 40] = "NestedProperties";
65
- NodeType[NodeType["ExtendsReference"] = 41] = "ExtendsReference";
66
- NodeType[NodeType["SelectorPlaceholder"] = 42] = "SelectorPlaceholder";
67
- NodeType[NodeType["Debug"] = 43] = "Debug";
68
- NodeType[NodeType["If"] = 44] = "If";
69
- NodeType[NodeType["Else"] = 45] = "Else";
70
- NodeType[NodeType["For"] = 46] = "For";
71
- NodeType[NodeType["Each"] = 47] = "Each";
72
- NodeType[NodeType["While"] = 48] = "While";
73
- NodeType[NodeType["MixinContentReference"] = 49] = "MixinContentReference";
74
- NodeType[NodeType["MixinContentDeclaration"] = 50] = "MixinContentDeclaration";
75
- NodeType[NodeType["Media"] = 51] = "Media";
76
- NodeType[NodeType["Keyframe"] = 52] = "Keyframe";
77
- NodeType[NodeType["FontFace"] = 53] = "FontFace";
78
- NodeType[NodeType["Import"] = 54] = "Import";
79
- NodeType[NodeType["Namespace"] = 55] = "Namespace";
80
- NodeType[NodeType["Invocation"] = 56] = "Invocation";
81
- NodeType[NodeType["FunctionDeclaration"] = 57] = "FunctionDeclaration";
82
- NodeType[NodeType["ReturnStatement"] = 58] = "ReturnStatement";
83
- NodeType[NodeType["MediaQuery"] = 59] = "MediaQuery";
84
- NodeType[NodeType["MediaCondition"] = 60] = "MediaCondition";
85
- NodeType[NodeType["MediaFeature"] = 61] = "MediaFeature";
86
- NodeType[NodeType["FunctionParameter"] = 62] = "FunctionParameter";
87
- NodeType[NodeType["FunctionArgument"] = 63] = "FunctionArgument";
88
- NodeType[NodeType["KeyframeSelector"] = 64] = "KeyframeSelector";
89
- NodeType[NodeType["ViewPort"] = 65] = "ViewPort";
90
- NodeType[NodeType["Document"] = 66] = "Document";
91
- NodeType[NodeType["AtApplyRule"] = 67] = "AtApplyRule";
92
- NodeType[NodeType["CustomPropertyDeclaration"] = 68] = "CustomPropertyDeclaration";
93
- NodeType[NodeType["CustomPropertySet"] = 69] = "CustomPropertySet";
94
- NodeType[NodeType["ListEntry"] = 70] = "ListEntry";
95
- NodeType[NodeType["Supports"] = 71] = "Supports";
96
- NodeType[NodeType["SupportsCondition"] = 72] = "SupportsCondition";
97
- NodeType[NodeType["NamespacePrefix"] = 73] = "NamespacePrefix";
98
- NodeType[NodeType["GridLine"] = 74] = "GridLine";
99
- NodeType[NodeType["Plugin"] = 75] = "Plugin";
100
- NodeType[NodeType["UnknownAtRule"] = 76] = "UnknownAtRule";
101
- NodeType[NodeType["Use"] = 77] = "Use";
102
- NodeType[NodeType["ModuleConfiguration"] = 78] = "ModuleConfiguration";
103
- NodeType[NodeType["Forward"] = 79] = "Forward";
104
- NodeType[NodeType["ForwardVisibility"] = 80] = "ForwardVisibility";
105
- NodeType[NodeType["Module"] = 81] = "Module";
106
- NodeType[NodeType["UnicodeRange"] = 82] = "UnicodeRange";
107
- })(NodeType = exports.NodeType || (exports.NodeType = {}));
108
- var ReferenceType;
109
- (function (ReferenceType) {
110
- ReferenceType[ReferenceType["Mixin"] = 0] = "Mixin";
111
- ReferenceType[ReferenceType["Rule"] = 1] = "Rule";
112
- ReferenceType[ReferenceType["Variable"] = 2] = "Variable";
113
- ReferenceType[ReferenceType["Function"] = 3] = "Function";
114
- ReferenceType[ReferenceType["Keyframe"] = 4] = "Keyframe";
115
- ReferenceType[ReferenceType["Unknown"] = 5] = "Unknown";
116
- ReferenceType[ReferenceType["Module"] = 6] = "Module";
117
- ReferenceType[ReferenceType["Forward"] = 7] = "Forward";
118
- ReferenceType[ReferenceType["ForwardVisibility"] = 8] = "ForwardVisibility";
119
- })(ReferenceType = exports.ReferenceType || (exports.ReferenceType = {}));
120
- function getNodeAtOffset(node, offset) {
121
- let candidate = null;
122
- if (!node || offset < node.offset || offset > node.end) {
123
- return null;
124
- }
125
- // Find the shortest node at the position
126
- node.accept((node) => {
127
- if (node.offset === -1 && node.length === -1) {
128
- return true;
129
- }
130
- if (node.offset <= offset && node.end >= offset) {
131
- if (!candidate) {
132
- candidate = node;
133
- }
134
- else if (node.length <= candidate.length) {
135
- candidate = node;
136
- }
137
- return true;
138
- }
139
- return false;
140
- });
141
- return candidate;
142
- }
143
- exports.getNodeAtOffset = getNodeAtOffset;
144
- function getNodePath(node, offset) {
145
- let candidate = getNodeAtOffset(node, offset);
146
- const path = [];
147
- while (candidate) {
148
- path.unshift(candidate);
149
- candidate = candidate.parent;
150
- }
151
- return path;
152
- }
153
- exports.getNodePath = getNodePath;
154
- function getParentDeclaration(node) {
155
- const decl = node.findParent(NodeType.Declaration);
156
- const value = decl && decl.getValue();
157
- if (value && value.encloses(node)) {
158
- return decl;
159
- }
160
- return null;
161
- }
162
- exports.getParentDeclaration = getParentDeclaration;
163
- class Node {
164
- constructor(offset = -1, len = -1, nodeType) {
165
- this.parent = null;
166
- this.offset = offset;
167
- this.length = len;
168
- if (nodeType) {
169
- this.nodeType = nodeType;
170
- }
171
- }
172
- get end() { return this.offset + this.length; }
173
- set type(type) {
174
- this.nodeType = type;
175
- }
176
- get type() {
177
- return this.nodeType || NodeType.Undefined;
178
- }
179
- getTextProvider() {
180
- let node = this;
181
- while (node && !node.textProvider) {
182
- node = node.parent;
183
- }
184
- if (node) {
185
- return node.textProvider;
186
- }
187
- return () => { return 'unknown'; };
188
- }
189
- getText() {
190
- return this.getTextProvider()(this.offset, this.length);
191
- }
192
- matches(str) {
193
- return this.length === str.length && this.getTextProvider()(this.offset, this.length) === str;
194
- }
195
- startsWith(str) {
196
- return this.length >= str.length && this.getTextProvider()(this.offset, str.length) === str;
197
- }
198
- endsWith(str) {
199
- return this.length >= str.length && this.getTextProvider()(this.end - str.length, str.length) === str;
200
- }
201
- accept(visitor) {
202
- if (visitor(this) && this.children) {
203
- for (const child of this.children) {
204
- child.accept(visitor);
205
- }
206
- }
207
- }
208
- acceptVisitor(visitor) {
209
- this.accept(visitor.visitNode.bind(visitor));
210
- }
211
- adoptChild(node, index = -1) {
212
- if (node.parent && node.parent.children) {
213
- const idx = node.parent.children.indexOf(node);
214
- if (idx >= 0) {
215
- node.parent.children.splice(idx, 1);
216
- }
217
- }
218
- node.parent = this;
219
- let children = this.children;
220
- if (!children) {
221
- children = this.children = [];
222
- }
223
- if (index !== -1) {
224
- children.splice(index, 0, node);
225
- }
226
- else {
227
- children.push(node);
228
- }
229
- return node;
230
- }
231
- attachTo(parent, index = -1) {
232
- if (parent) {
233
- parent.adoptChild(this, index);
234
- }
235
- return this;
236
- }
237
- collectIssues(results) {
238
- if (this.issues) {
239
- results.push.apply(results, this.issues);
240
- }
241
- }
242
- addIssue(issue) {
243
- if (!this.issues) {
244
- this.issues = [];
245
- }
246
- this.issues.push(issue);
247
- }
248
- hasIssue(rule) {
249
- return Array.isArray(this.issues) && this.issues.some(i => i.getRule() === rule);
250
- }
251
- isErroneous(recursive = false) {
252
- if (this.issues && this.issues.length > 0) {
253
- return true;
254
- }
255
- return recursive && Array.isArray(this.children) && this.children.some(c => c.isErroneous(true));
256
- }
257
- setNode(field, node, index = -1) {
258
- if (node) {
259
- node.attachTo(this, index);
260
- this[field] = node;
261
- return true;
262
- }
263
- return false;
264
- }
265
- addChild(node) {
266
- if (node) {
267
- if (!this.children) {
268
- this.children = [];
269
- }
270
- node.attachTo(this);
271
- this.updateOffsetAndLength(node);
272
- return true;
273
- }
274
- return false;
275
- }
276
- updateOffsetAndLength(node) {
277
- if (node.offset < this.offset || this.offset === -1) {
278
- this.offset = node.offset;
279
- }
280
- const nodeEnd = node.end;
281
- if ((nodeEnd > this.end) || this.length === -1) {
282
- this.length = nodeEnd - this.offset;
283
- }
284
- }
285
- hasChildren() {
286
- return !!this.children && this.children.length > 0;
287
- }
288
- getChildren() {
289
- return this.children ? this.children.slice(0) : [];
290
- }
291
- getChild(index) {
292
- if (this.children && index < this.children.length) {
293
- return this.children[index];
294
- }
295
- return null;
296
- }
297
- addChildren(nodes) {
298
- for (const node of nodes) {
299
- this.addChild(node);
300
- }
301
- }
302
- findFirstChildBeforeOffset(offset) {
303
- if (this.children) {
304
- let current = null;
305
- for (let i = this.children.length - 1; i >= 0; i--) {
306
- // iterate until we find a child that has a start offset smaller than the input offset
307
- current = this.children[i];
308
- if (current.offset <= offset) {
309
- return current;
310
- }
311
- }
312
- }
313
- return null;
314
- }
315
- findChildAtOffset(offset, goDeep) {
316
- const current = this.findFirstChildBeforeOffset(offset);
317
- if (current && current.end >= offset) {
318
- if (goDeep) {
319
- return current.findChildAtOffset(offset, true) || current;
320
- }
321
- return current;
322
- }
323
- return null;
324
- }
325
- encloses(candidate) {
326
- return this.offset <= candidate.offset && this.offset + this.length >= candidate.offset + candidate.length;
327
- }
328
- getParent() {
329
- let result = this.parent;
330
- while (result instanceof Nodelist) {
331
- result = result.parent;
332
- }
333
- return result;
334
- }
335
- findParent(type) {
336
- let result = this;
337
- while (result && result.type !== type) {
338
- result = result.parent;
339
- }
340
- return result;
341
- }
342
- findAParent(...types) {
343
- let result = this;
344
- while (result && !types.some(t => result.type === t)) {
345
- result = result.parent;
346
- }
347
- return result;
348
- }
349
- setData(key, value) {
350
- if (!this.options) {
351
- this.options = {};
352
- }
353
- this.options[key] = value;
354
- }
355
- getData(key) {
356
- if (!this.options || !this.options.hasOwnProperty(key)) {
357
- return null;
358
- }
359
- return this.options[key];
360
- }
361
- }
362
- exports.Node = Node;
363
- class Nodelist extends Node {
364
- constructor(parent, index = -1) {
365
- super(-1, -1);
366
- this.attachTo(parent, index);
367
- this.offset = -1;
368
- this.length = -1;
369
- }
370
- }
371
- exports.Nodelist = Nodelist;
372
- class UnicodeRange extends Node {
373
- constructor(offset, length) {
374
- super(offset, length);
375
- }
376
- get type() {
377
- return NodeType.UnicodeRange;
378
- }
379
- setRangeStart(rangeStart) {
380
- return this.setNode('rangeStart', rangeStart);
381
- }
382
- getRangeStart() {
383
- return this.rangeStart;
384
- }
385
- setRangeEnd(rangeEnd) {
386
- return this.setNode('rangeEnd', rangeEnd);
387
- }
388
- getRangeEnd() {
389
- return this.rangeEnd;
390
- }
391
- }
392
- exports.UnicodeRange = UnicodeRange;
393
- class Identifier extends Node {
394
- constructor(offset, length) {
395
- super(offset, length);
396
- this.isCustomProperty = false;
397
- }
398
- get type() {
399
- return NodeType.Identifier;
400
- }
401
- containsInterpolation() {
402
- return this.hasChildren();
403
- }
404
- }
405
- exports.Identifier = Identifier;
406
- class Stylesheet extends Node {
407
- constructor(offset, length) {
408
- super(offset, length);
409
- }
410
- get type() {
411
- return NodeType.Stylesheet;
412
- }
413
- }
414
- exports.Stylesheet = Stylesheet;
415
- class Declarations extends Node {
416
- constructor(offset, length) {
417
- super(offset, length);
418
- }
419
- get type() {
420
- return NodeType.Declarations;
421
- }
422
- }
423
- exports.Declarations = Declarations;
424
- class BodyDeclaration extends Node {
425
- constructor(offset, length) {
426
- super(offset, length);
427
- }
428
- getDeclarations() {
429
- return this.declarations;
430
- }
431
- setDeclarations(decls) {
432
- return this.setNode('declarations', decls);
433
- }
434
- }
435
- exports.BodyDeclaration = BodyDeclaration;
436
- class RuleSet extends BodyDeclaration {
437
- constructor(offset, length) {
438
- super(offset, length);
439
- }
440
- get type() {
441
- return NodeType.Ruleset;
442
- }
443
- getSelectors() {
444
- if (!this.selectors) {
445
- this.selectors = new Nodelist(this);
446
- }
447
- return this.selectors;
448
- }
449
- isNested() {
450
- return !!this.parent && this.parent.findParent(NodeType.Declarations) !== null;
451
- }
452
- }
453
- exports.RuleSet = RuleSet;
454
- class Selector extends Node {
455
- constructor(offset, length) {
456
- super(offset, length);
457
- }
458
- get type() {
459
- return NodeType.Selector;
460
- }
461
- }
462
- exports.Selector = Selector;
463
- class SimpleSelector extends Node {
464
- constructor(offset, length) {
465
- super(offset, length);
466
- }
467
- get type() {
468
- return NodeType.SimpleSelector;
469
- }
470
- }
471
- exports.SimpleSelector = SimpleSelector;
472
- class AtApplyRule extends Node {
473
- constructor(offset, length) {
474
- super(offset, length);
475
- }
476
- get type() {
477
- return NodeType.AtApplyRule;
478
- }
479
- setIdentifier(node) {
480
- return this.setNode('identifier', node, 0);
481
- }
482
- getIdentifier() {
483
- return this.identifier;
484
- }
485
- getName() {
486
- return this.identifier ? this.identifier.getText() : '';
487
- }
488
- }
489
- exports.AtApplyRule = AtApplyRule;
490
- class AbstractDeclaration extends Node {
491
- constructor(offset, length) {
492
- super(offset, length);
493
- }
494
- }
495
- exports.AbstractDeclaration = AbstractDeclaration;
496
- class CustomPropertySet extends BodyDeclaration {
497
- constructor(offset, length) {
498
- super(offset, length);
499
- }
500
- get type() {
501
- return NodeType.CustomPropertySet;
502
- }
503
- }
504
- exports.CustomPropertySet = CustomPropertySet;
505
- class Declaration extends AbstractDeclaration {
506
- constructor(offset, length) {
507
- super(offset, length);
508
- this.property = null;
509
- }
510
- get type() {
511
- return NodeType.Declaration;
512
- }
513
- setProperty(node) {
514
- return this.setNode('property', node);
515
- }
516
- getProperty() {
517
- return this.property;
518
- }
519
- getFullPropertyName() {
520
- const propertyName = this.property ? this.property.getName() : 'unknown';
521
- if (this.parent instanceof Declarations && this.parent.getParent() instanceof NestedProperties) {
522
- const parentDecl = this.parent.getParent().getParent();
523
- if (parentDecl instanceof Declaration) {
524
- return parentDecl.getFullPropertyName() + propertyName;
525
- }
526
- }
527
- return propertyName;
528
- }
529
- getNonPrefixedPropertyName() {
530
- const propertyName = this.getFullPropertyName();
531
- if (propertyName && propertyName.charAt(0) === '-') {
532
- const vendorPrefixEnd = propertyName.indexOf('-', 1);
533
- if (vendorPrefixEnd !== -1) {
534
- return propertyName.substring(vendorPrefixEnd + 1);
535
- }
536
- }
537
- return propertyName;
538
- }
539
- setValue(value) {
540
- return this.setNode('value', value);
541
- }
542
- getValue() {
543
- return this.value;
544
- }
545
- setNestedProperties(value) {
546
- return this.setNode('nestedProperties', value);
547
- }
548
- getNestedProperties() {
549
- return this.nestedProperties;
550
- }
551
- }
552
- exports.Declaration = Declaration;
553
- class CustomPropertyDeclaration extends Declaration {
554
- constructor(offset, length) {
555
- super(offset, length);
556
- }
557
- get type() {
558
- return NodeType.CustomPropertyDeclaration;
559
- }
560
- setPropertySet(value) {
561
- return this.setNode('propertySet', value);
562
- }
563
- getPropertySet() {
564
- return this.propertySet;
565
- }
566
- }
567
- exports.CustomPropertyDeclaration = CustomPropertyDeclaration;
568
- class Property extends Node {
569
- constructor(offset, length) {
570
- super(offset, length);
571
- }
572
- get type() {
573
- return NodeType.Property;
574
- }
575
- setIdentifier(value) {
576
- return this.setNode('identifier', value);
577
- }
578
- getIdentifier() {
579
- return this.identifier;
580
- }
581
- getName() {
582
- return (0, strings_1.trim)(this.getText(), /[_\+]+$/); /* +_: less merge */
583
- }
584
- isCustomProperty() {
585
- return !!this.identifier && this.identifier.isCustomProperty;
586
- }
587
- }
588
- exports.Property = Property;
589
- class Invocation extends Node {
590
- constructor(offset, length) {
591
- super(offset, length);
592
- }
593
- get type() {
594
- return NodeType.Invocation;
595
- }
596
- getArguments() {
597
- if (!this.arguments) {
598
- this.arguments = new Nodelist(this);
599
- }
600
- return this.arguments;
601
- }
602
- }
603
- exports.Invocation = Invocation;
604
- class Function extends Invocation {
605
- constructor(offset, length) {
606
- super(offset, length);
607
- }
608
- get type() {
609
- return NodeType.Function;
610
- }
611
- setIdentifier(node) {
612
- return this.setNode('identifier', node, 0);
613
- }
614
- getIdentifier() {
615
- return this.identifier;
616
- }
617
- getName() {
618
- return this.identifier ? this.identifier.getText() : '';
619
- }
620
- }
621
- exports.Function = Function;
622
- class FunctionParameter extends Node {
623
- constructor(offset, length) {
624
- super(offset, length);
625
- }
626
- get type() {
627
- return NodeType.FunctionParameter;
628
- }
629
- setIdentifier(node) {
630
- return this.setNode('identifier', node, 0);
631
- }
632
- getIdentifier() {
633
- return this.identifier;
634
- }
635
- getName() {
636
- return this.identifier ? this.identifier.getText() : '';
637
- }
638
- setDefaultValue(node) {
639
- return this.setNode('defaultValue', node, 0);
640
- }
641
- getDefaultValue() {
642
- return this.defaultValue;
643
- }
644
- }
645
- exports.FunctionParameter = FunctionParameter;
646
- class FunctionArgument extends Node {
647
- constructor(offset, length) {
648
- super(offset, length);
649
- }
650
- get type() {
651
- return NodeType.FunctionArgument;
652
- }
653
- setIdentifier(node) {
654
- return this.setNode('identifier', node, 0);
655
- }
656
- getIdentifier() {
657
- return this.identifier;
658
- }
659
- getName() {
660
- return this.identifier ? this.identifier.getText() : '';
661
- }
662
- setValue(node) {
663
- return this.setNode('value', node, 0);
664
- }
665
- getValue() {
666
- return this.value;
667
- }
668
- }
669
- exports.FunctionArgument = FunctionArgument;
670
- class IfStatement extends BodyDeclaration {
671
- constructor(offset, length) {
672
- super(offset, length);
673
- }
674
- get type() {
675
- return NodeType.If;
676
- }
677
- setExpression(node) {
678
- return this.setNode('expression', node, 0);
679
- }
680
- setElseClause(elseClause) {
681
- return this.setNode('elseClause', elseClause);
682
- }
683
- }
684
- exports.IfStatement = IfStatement;
685
- class ForStatement extends BodyDeclaration {
686
- constructor(offset, length) {
687
- super(offset, length);
688
- }
689
- get type() {
690
- return NodeType.For;
691
- }
692
- setVariable(node) {
693
- return this.setNode('variable', node, 0);
694
- }
695
- }
696
- exports.ForStatement = ForStatement;
697
- class EachStatement extends BodyDeclaration {
698
- constructor(offset, length) {
699
- super(offset, length);
700
- }
701
- get type() {
702
- return NodeType.Each;
703
- }
704
- getVariables() {
705
- if (!this.variables) {
706
- this.variables = new Nodelist(this);
707
- }
708
- return this.variables;
709
- }
710
- }
711
- exports.EachStatement = EachStatement;
712
- class WhileStatement extends BodyDeclaration {
713
- constructor(offset, length) {
714
- super(offset, length);
715
- }
716
- get type() {
717
- return NodeType.While;
718
- }
719
- }
720
- exports.WhileStatement = WhileStatement;
721
- class ElseStatement extends BodyDeclaration {
722
- constructor(offset, length) {
723
- super(offset, length);
724
- }
725
- get type() {
726
- return NodeType.Else;
727
- }
728
- }
729
- exports.ElseStatement = ElseStatement;
730
- class FunctionDeclaration extends BodyDeclaration {
731
- constructor(offset, length) {
732
- super(offset, length);
733
- }
734
- get type() {
735
- return NodeType.FunctionDeclaration;
736
- }
737
- setIdentifier(node) {
738
- return this.setNode('identifier', node, 0);
739
- }
740
- getIdentifier() {
741
- return this.identifier;
742
- }
743
- getName() {
744
- return this.identifier ? this.identifier.getText() : '';
745
- }
746
- getParameters() {
747
- if (!this.parameters) {
748
- this.parameters = new Nodelist(this);
749
- }
750
- return this.parameters;
751
- }
752
- }
753
- exports.FunctionDeclaration = FunctionDeclaration;
754
- class ViewPort extends BodyDeclaration {
755
- constructor(offset, length) {
756
- super(offset, length);
757
- }
758
- get type() {
759
- return NodeType.ViewPort;
760
- }
761
- }
762
- exports.ViewPort = ViewPort;
763
- class FontFace extends BodyDeclaration {
764
- constructor(offset, length) {
765
- super(offset, length);
766
- }
767
- get type() {
768
- return NodeType.FontFace;
769
- }
770
- }
771
- exports.FontFace = FontFace;
772
- class NestedProperties extends BodyDeclaration {
773
- constructor(offset, length) {
774
- super(offset, length);
775
- }
776
- get type() {
777
- return NodeType.NestedProperties;
778
- }
779
- }
780
- exports.NestedProperties = NestedProperties;
781
- class Keyframe extends BodyDeclaration {
782
- constructor(offset, length) {
783
- super(offset, length);
784
- }
785
- get type() {
786
- return NodeType.Keyframe;
787
- }
788
- setKeyword(keyword) {
789
- return this.setNode('keyword', keyword, 0);
790
- }
791
- getKeyword() {
792
- return this.keyword;
793
- }
794
- setIdentifier(node) {
795
- return this.setNode('identifier', node, 0);
796
- }
797
- getIdentifier() {
798
- return this.identifier;
799
- }
800
- getName() {
801
- return this.identifier ? this.identifier.getText() : '';
802
- }
803
- }
804
- exports.Keyframe = Keyframe;
805
- class KeyframeSelector extends BodyDeclaration {
806
- constructor(offset, length) {
807
- super(offset, length);
808
- }
809
- get type() {
810
- return NodeType.KeyframeSelector;
811
- }
812
- }
813
- exports.KeyframeSelector = KeyframeSelector;
814
- class Import extends Node {
815
- constructor(offset, length) {
816
- super(offset, length);
817
- }
818
- get type() {
819
- return NodeType.Import;
820
- }
821
- setMedialist(node) {
822
- if (node) {
823
- node.attachTo(this);
824
- return true;
825
- }
826
- return false;
827
- }
828
- }
829
- exports.Import = Import;
830
- class Use extends Node {
831
- get type() {
832
- return NodeType.Use;
833
- }
834
- getParameters() {
835
- if (!this.parameters) {
836
- this.parameters = new Nodelist(this);
837
- }
838
- return this.parameters;
839
- }
840
- setIdentifier(node) {
841
- return this.setNode('identifier', node, 0);
842
- }
843
- getIdentifier() {
844
- return this.identifier;
845
- }
846
- }
847
- exports.Use = Use;
848
- class ModuleConfiguration extends Node {
849
- get type() {
850
- return NodeType.ModuleConfiguration;
851
- }
852
- setIdentifier(node) {
853
- return this.setNode('identifier', node, 0);
854
- }
855
- getIdentifier() {
856
- return this.identifier;
857
- }
858
- getName() {
859
- return this.identifier ? this.identifier.getText() : '';
860
- }
861
- setValue(node) {
862
- return this.setNode('value', node, 0);
863
- }
864
- getValue() {
865
- return this.value;
866
- }
867
- }
868
- exports.ModuleConfiguration = ModuleConfiguration;
869
- class Forward extends Node {
870
- get type() {
871
- return NodeType.Forward;
872
- }
873
- setIdentifier(node) {
874
- return this.setNode('identifier', node, 0);
875
- }
876
- getIdentifier() {
877
- return this.identifier;
878
- }
879
- getMembers() {
880
- if (!this.members) {
881
- this.members = new Nodelist(this);
882
- }
883
- return this.members;
884
- }
885
- getParameters() {
886
- if (!this.parameters) {
887
- this.parameters = new Nodelist(this);
888
- }
889
- return this.parameters;
890
- }
891
- }
892
- exports.Forward = Forward;
893
- class ForwardVisibility extends Node {
894
- get type() {
895
- return NodeType.ForwardVisibility;
896
- }
897
- setIdentifier(node) {
898
- return this.setNode('identifier', node, 0);
899
- }
900
- getIdentifier() {
901
- return this.identifier;
902
- }
903
- }
904
- exports.ForwardVisibility = ForwardVisibility;
905
- class Namespace extends Node {
906
- constructor(offset, length) {
907
- super(offset, length);
908
- }
909
- get type() {
910
- return NodeType.Namespace;
911
- }
912
- }
913
- exports.Namespace = Namespace;
914
- class Media extends BodyDeclaration {
915
- constructor(offset, length) {
916
- super(offset, length);
917
- }
918
- get type() {
919
- return NodeType.Media;
920
- }
921
- }
922
- exports.Media = Media;
923
- class Supports extends BodyDeclaration {
924
- constructor(offset, length) {
925
- super(offset, length);
926
- }
927
- get type() {
928
- return NodeType.Supports;
929
- }
930
- }
931
- exports.Supports = Supports;
932
- class Document extends BodyDeclaration {
933
- constructor(offset, length) {
934
- super(offset, length);
935
- }
936
- get type() {
937
- return NodeType.Document;
938
- }
939
- }
940
- exports.Document = Document;
941
- class Medialist extends Node {
942
- constructor(offset, length) {
943
- super(offset, length);
944
- }
945
- getMediums() {
946
- if (!this.mediums) {
947
- this.mediums = new Nodelist(this);
948
- }
949
- return this.mediums;
950
- }
951
- }
952
- exports.Medialist = Medialist;
953
- class MediaQuery extends Node {
954
- constructor(offset, length) {
955
- super(offset, length);
956
- }
957
- get type() {
958
- return NodeType.MediaQuery;
959
- }
960
- }
961
- exports.MediaQuery = MediaQuery;
962
- class MediaCondition extends Node {
963
- constructor(offset, length) {
964
- super(offset, length);
965
- }
966
- get type() {
967
- return NodeType.MediaCondition;
968
- }
969
- }
970
- exports.MediaCondition = MediaCondition;
971
- class MediaFeature extends Node {
972
- constructor(offset, length) {
973
- super(offset, length);
974
- }
975
- get type() {
976
- return NodeType.MediaFeature;
977
- }
978
- }
979
- exports.MediaFeature = MediaFeature;
980
- class SupportsCondition extends Node {
981
- constructor(offset, length) {
982
- super(offset, length);
983
- }
984
- get type() {
985
- return NodeType.SupportsCondition;
986
- }
987
- }
988
- exports.SupportsCondition = SupportsCondition;
989
- class Page extends BodyDeclaration {
990
- constructor(offset, length) {
991
- super(offset, length);
992
- }
993
- get type() {
994
- return NodeType.Page;
995
- }
996
- }
997
- exports.Page = Page;
998
- class PageBoxMarginBox extends BodyDeclaration {
999
- constructor(offset, length) {
1000
- super(offset, length);
1001
- }
1002
- get type() {
1003
- return NodeType.PageBoxMarginBox;
1004
- }
1005
- }
1006
- exports.PageBoxMarginBox = PageBoxMarginBox;
1007
- class Expression extends Node {
1008
- constructor(offset, length) {
1009
- super(offset, length);
1010
- }
1011
- get type() {
1012
- return NodeType.Expression;
1013
- }
1014
- }
1015
- exports.Expression = Expression;
1016
- class BinaryExpression extends Node {
1017
- constructor(offset, length) {
1018
- super(offset, length);
1019
- }
1020
- get type() {
1021
- return NodeType.BinaryExpression;
1022
- }
1023
- setLeft(left) {
1024
- return this.setNode('left', left);
1025
- }
1026
- getLeft() {
1027
- return this.left;
1028
- }
1029
- setRight(right) {
1030
- return this.setNode('right', right);
1031
- }
1032
- getRight() {
1033
- return this.right;
1034
- }
1035
- setOperator(value) {
1036
- return this.setNode('operator', value);
1037
- }
1038
- getOperator() {
1039
- return this.operator;
1040
- }
1041
- }
1042
- exports.BinaryExpression = BinaryExpression;
1043
- class Term extends Node {
1044
- constructor(offset, length) {
1045
- super(offset, length);
1046
- }
1047
- get type() {
1048
- return NodeType.Term;
1049
- }
1050
- setOperator(value) {
1051
- return this.setNode('operator', value);
1052
- }
1053
- getOperator() {
1054
- return this.operator;
1055
- }
1056
- setExpression(value) {
1057
- return this.setNode('expression', value);
1058
- }
1059
- getExpression() {
1060
- return this.expression;
1061
- }
1062
- }
1063
- exports.Term = Term;
1064
- class AttributeSelector extends Node {
1065
- constructor(offset, length) {
1066
- super(offset, length);
1067
- }
1068
- get type() {
1069
- return NodeType.AttributeSelector;
1070
- }
1071
- setNamespacePrefix(value) {
1072
- return this.setNode('namespacePrefix', value);
1073
- }
1074
- getNamespacePrefix() {
1075
- return this.namespacePrefix;
1076
- }
1077
- setIdentifier(value) {
1078
- return this.setNode('identifier', value);
1079
- }
1080
- getIdentifier() {
1081
- return this.identifier;
1082
- }
1083
- setOperator(operator) {
1084
- return this.setNode('operator', operator);
1085
- }
1086
- getOperator() {
1087
- return this.operator;
1088
- }
1089
- setValue(value) {
1090
- return this.setNode('value', value);
1091
- }
1092
- getValue() {
1093
- return this.value;
1094
- }
1095
- }
1096
- exports.AttributeSelector = AttributeSelector;
1097
- class Operator extends Node {
1098
- constructor(offset, length) {
1099
- super(offset, length);
1100
- }
1101
- get type() {
1102
- return NodeType.Operator;
1103
- }
1104
- }
1105
- exports.Operator = Operator;
1106
- class HexColorValue extends Node {
1107
- constructor(offset, length) {
1108
- super(offset, length);
1109
- }
1110
- get type() {
1111
- return NodeType.HexColorValue;
1112
- }
1113
- }
1114
- exports.HexColorValue = HexColorValue;
1115
- class RatioValue extends Node {
1116
- constructor(offset, length) {
1117
- super(offset, length);
1118
- }
1119
- get type() {
1120
- return NodeType.RatioValue;
1121
- }
1122
- }
1123
- exports.RatioValue = RatioValue;
1124
- const _dot = '.'.charCodeAt(0), _0 = '0'.charCodeAt(0), _9 = '9'.charCodeAt(0);
1125
- class NumericValue extends Node {
1126
- constructor(offset, length) {
1127
- super(offset, length);
1128
- }
1129
- get type() {
1130
- return NodeType.NumericValue;
1131
- }
1132
- getValue() {
1133
- const raw = this.getText();
1134
- let unitIdx = 0;
1135
- let code;
1136
- for (let i = 0, len = raw.length; i < len; i++) {
1137
- code = raw.charCodeAt(i);
1138
- if (!(_0 <= code && code <= _9 || code === _dot)) {
1139
- break;
1140
- }
1141
- unitIdx += 1;
1142
- }
1143
- return {
1144
- value: raw.substring(0, unitIdx),
1145
- unit: unitIdx < raw.length ? raw.substring(unitIdx) : undefined
1146
- };
1147
- }
1148
- }
1149
- exports.NumericValue = NumericValue;
1150
- class VariableDeclaration extends AbstractDeclaration {
1151
- constructor(offset, length) {
1152
- super(offset, length);
1153
- this.variable = null;
1154
- this.value = null;
1155
- this.needsSemicolon = true;
1156
- }
1157
- get type() {
1158
- return NodeType.VariableDeclaration;
1159
- }
1160
- setVariable(node) {
1161
- if (node) {
1162
- node.attachTo(this);
1163
- this.variable = node;
1164
- return true;
1165
- }
1166
- return false;
1167
- }
1168
- getVariable() {
1169
- return this.variable;
1170
- }
1171
- getName() {
1172
- return this.variable ? this.variable.getName() : '';
1173
- }
1174
- setValue(node) {
1175
- if (node) {
1176
- node.attachTo(this);
1177
- this.value = node;
1178
- return true;
1179
- }
1180
- return false;
1181
- }
1182
- getValue() {
1183
- return this.value;
1184
- }
1185
- }
1186
- exports.VariableDeclaration = VariableDeclaration;
1187
- class Interpolation extends Node {
1188
- // private _interpolations: void; // workaround for https://github.com/Microsoft/TypeScript/issues/18276
1189
- constructor(offset, length) {
1190
- super(offset, length);
1191
- }
1192
- get type() {
1193
- return NodeType.Interpolation;
1194
- }
1195
- }
1196
- exports.Interpolation = Interpolation;
1197
- class Variable extends Node {
1198
- constructor(offset, length) {
1199
- super(offset, length);
1200
- }
1201
- get type() {
1202
- return NodeType.VariableName;
1203
- }
1204
- getName() {
1205
- return this.getText();
1206
- }
1207
- }
1208
- exports.Variable = Variable;
1209
- class ExtendsReference extends Node {
1210
- constructor(offset, length) {
1211
- super(offset, length);
1212
- }
1213
- get type() {
1214
- return NodeType.ExtendsReference;
1215
- }
1216
- getSelectors() {
1217
- if (!this.selectors) {
1218
- this.selectors = new Nodelist(this);
1219
- }
1220
- return this.selectors;
1221
- }
1222
- }
1223
- exports.ExtendsReference = ExtendsReference;
1224
- class MixinContentReference extends Node {
1225
- constructor(offset, length) {
1226
- super(offset, length);
1227
- }
1228
- get type() {
1229
- return NodeType.MixinContentReference;
1230
- }
1231
- getArguments() {
1232
- if (!this.arguments) {
1233
- this.arguments = new Nodelist(this);
1234
- }
1235
- return this.arguments;
1236
- }
1237
- }
1238
- exports.MixinContentReference = MixinContentReference;
1239
- class MixinContentDeclaration extends BodyDeclaration {
1240
- constructor(offset, length) {
1241
- super(offset, length);
1242
- }
1243
- get type() {
1244
- return NodeType.MixinContentReference;
1245
- }
1246
- getParameters() {
1247
- if (!this.parameters) {
1248
- this.parameters = new Nodelist(this);
1249
- }
1250
- return this.parameters;
1251
- }
1252
- }
1253
- exports.MixinContentDeclaration = MixinContentDeclaration;
1254
- class MixinReference extends Node {
1255
- constructor(offset, length) {
1256
- super(offset, length);
1257
- }
1258
- get type() {
1259
- return NodeType.MixinReference;
1260
- }
1261
- getNamespaces() {
1262
- if (!this.namespaces) {
1263
- this.namespaces = new Nodelist(this);
1264
- }
1265
- return this.namespaces;
1266
- }
1267
- setIdentifier(node) {
1268
- return this.setNode('identifier', node, 0);
1269
- }
1270
- getIdentifier() {
1271
- return this.identifier;
1272
- }
1273
- getName() {
1274
- return this.identifier ? this.identifier.getText() : '';
1275
- }
1276
- getArguments() {
1277
- if (!this.arguments) {
1278
- this.arguments = new Nodelist(this);
1279
- }
1280
- return this.arguments;
1281
- }
1282
- setContent(node) {
1283
- return this.setNode('content', node);
1284
- }
1285
- getContent() {
1286
- return this.content;
1287
- }
1288
- }
1289
- exports.MixinReference = MixinReference;
1290
- class MixinDeclaration extends BodyDeclaration {
1291
- constructor(offset, length) {
1292
- super(offset, length);
1293
- }
1294
- get type() {
1295
- return NodeType.MixinDeclaration;
1296
- }
1297
- setIdentifier(node) {
1298
- return this.setNode('identifier', node, 0);
1299
- }
1300
- getIdentifier() {
1301
- return this.identifier;
1302
- }
1303
- getName() {
1304
- return this.identifier ? this.identifier.getText() : '';
1305
- }
1306
- getParameters() {
1307
- if (!this.parameters) {
1308
- this.parameters = new Nodelist(this);
1309
- }
1310
- return this.parameters;
1311
- }
1312
- setGuard(node) {
1313
- if (node) {
1314
- node.attachTo(this);
1315
- this.guard = node;
1316
- }
1317
- return false;
1318
- }
1319
- }
1320
- exports.MixinDeclaration = MixinDeclaration;
1321
- class UnknownAtRule extends BodyDeclaration {
1322
- constructor(offset, length) {
1323
- super(offset, length);
1324
- }
1325
- get type() {
1326
- return NodeType.UnknownAtRule;
1327
- }
1328
- setAtRuleName(atRuleName) {
1329
- this.atRuleName = atRuleName;
1330
- }
1331
- getAtRuleName() {
1332
- return this.atRuleName;
1333
- }
1334
- }
1335
- exports.UnknownAtRule = UnknownAtRule;
1336
- class ListEntry extends Node {
1337
- get type() {
1338
- return NodeType.ListEntry;
1339
- }
1340
- setKey(node) {
1341
- return this.setNode('key', node, 0);
1342
- }
1343
- setValue(node) {
1344
- return this.setNode('value', node, 1);
1345
- }
1346
- }
1347
- exports.ListEntry = ListEntry;
1348
- class LessGuard extends Node {
1349
- getConditions() {
1350
- if (!this.conditions) {
1351
- this.conditions = new Nodelist(this);
1352
- }
1353
- return this.conditions;
1354
- }
1355
- }
1356
- exports.LessGuard = LessGuard;
1357
- class GuardCondition extends Node {
1358
- setVariable(node) {
1359
- return this.setNode('variable', node);
1360
- }
1361
- }
1362
- exports.GuardCondition = GuardCondition;
1363
- class Module extends Node {
1364
- get type() {
1365
- return NodeType.Module;
1366
- }
1367
- setIdentifier(node) {
1368
- return this.setNode('identifier', node, 0);
1369
- }
1370
- getIdentifier() {
1371
- return this.identifier;
1372
- }
1373
- }
1374
- exports.Module = Module;
1375
- var Level;
1376
- (function (Level) {
1377
- Level[Level["Ignore"] = 1] = "Ignore";
1378
- Level[Level["Warning"] = 2] = "Warning";
1379
- Level[Level["Error"] = 4] = "Error";
1380
- })(Level = exports.Level || (exports.Level = {}));
1381
- class Marker {
1382
- constructor(node, rule, level, message, offset = node.offset, length = node.length) {
1383
- this.node = node;
1384
- this.rule = rule;
1385
- this.level = level;
1386
- this.message = message || rule.message;
1387
- this.offset = offset;
1388
- this.length = length;
1389
- }
1390
- getRule() {
1391
- return this.rule;
1392
- }
1393
- getLevel() {
1394
- return this.level;
1395
- }
1396
- getOffset() {
1397
- return this.offset;
1398
- }
1399
- getLength() {
1400
- return this.length;
1401
- }
1402
- getNode() {
1403
- return this.node;
1404
- }
1405
- getMessage() {
1406
- return this.message;
1407
- }
1408
- }
1409
- exports.Marker = Marker;
1410
- /*
1411
- export class DefaultVisitor implements IVisitor {
1412
-
1413
- public visitNode(node:Node):boolean {
1414
- switch (node.type) {
1415
- case NodeType.Stylesheet:
1416
- return this.visitStylesheet(<Stylesheet> node);
1417
- case NodeType.FontFace:
1418
- return this.visitFontFace(<FontFace> node);
1419
- case NodeType.Ruleset:
1420
- return this.visitRuleSet(<RuleSet> node);
1421
- case NodeType.Selector:
1422
- return this.visitSelector(<Selector> node);
1423
- case NodeType.SimpleSelector:
1424
- return this.visitSimpleSelector(<SimpleSelector> node);
1425
- case NodeType.Declaration:
1426
- return this.visitDeclaration(<Declaration> node);
1427
- case NodeType.Function:
1428
- return this.visitFunction(<Function> node);
1429
- case NodeType.FunctionDeclaration:
1430
- return this.visitFunctionDeclaration(<FunctionDeclaration> node);
1431
- case NodeType.FunctionParameter:
1432
- return this.visitFunctionParameter(<FunctionParameter> node);
1433
- case NodeType.FunctionArgument:
1434
- return this.visitFunctionArgument(<FunctionArgument> node);
1435
- case NodeType.Term:
1436
- return this.visitTerm(<Term> node);
1437
- case NodeType.Declaration:
1438
- return this.visitExpression(<Expression> node);
1439
- case NodeType.NumericValue:
1440
- return this.visitNumericValue(<NumericValue> node);
1441
- case NodeType.Page:
1442
- return this.visitPage(<Page> node);
1443
- case NodeType.PageBoxMarginBox:
1444
- return this.visitPageBoxMarginBox(<PageBoxMarginBox> node);
1445
- case NodeType.Property:
1446
- return this.visitProperty(<Property> node);
1447
- case NodeType.NumericValue:
1448
- return this.visitNodelist(<Nodelist> node);
1449
- case NodeType.Import:
1450
- return this.visitImport(<Import> node);
1451
- case NodeType.Namespace:
1452
- return this.visitNamespace(<Namespace> node);
1453
- case NodeType.Keyframe:
1454
- return this.visitKeyframe(<Keyframe> node);
1455
- case NodeType.KeyframeSelector:
1456
- return this.visitKeyframeSelector(<KeyframeSelector> node);
1457
- case NodeType.MixinDeclaration:
1458
- return this.visitMixinDeclaration(<MixinDeclaration> node);
1459
- case NodeType.MixinReference:
1460
- return this.visitMixinReference(<MixinReference> node);
1461
- case NodeType.Variable:
1462
- return this.visitVariable(<Variable> node);
1463
- case NodeType.VariableDeclaration:
1464
- return this.visitVariableDeclaration(<VariableDeclaration> node);
1465
- }
1466
- return this.visitUnknownNode(node);
1467
- }
1468
-
1469
- public visitFontFace(node:FontFace):boolean {
1470
- return true;
1471
- }
1472
-
1473
- public visitKeyframe(node:Keyframe):boolean {
1474
- return true;
1475
- }
1476
-
1477
- public visitKeyframeSelector(node:KeyframeSelector):boolean {
1478
- return true;
1479
- }
1480
-
1481
- public visitStylesheet(node:Stylesheet):boolean {
1482
- return true;
1483
- }
1484
-
1485
- public visitProperty(Node:Property):boolean {
1486
- return true;
1487
- }
1488
-
1489
- public visitRuleSet(node:RuleSet):boolean {
1490
- return true;
1491
- }
1492
-
1493
- public visitSelector(node:Selector):boolean {
1494
- return true;
1495
- }
1496
-
1497
- public visitSimpleSelector(node:SimpleSelector):boolean {
1498
- return true;
1499
- }
1500
-
1501
- public visitDeclaration(node:Declaration):boolean {
1502
- return true;
1503
- }
1504
-
1505
- public visitFunction(node:Function):boolean {
1506
- return true;
1507
- }
1508
-
1509
- public visitFunctionDeclaration(node:FunctionDeclaration):boolean {
1510
- return true;
1511
- }
1512
-
1513
- public visitInvocation(node:Invocation):boolean {
1514
- return true;
1515
- }
1516
-
1517
- public visitTerm(node:Term):boolean {
1518
- return true;
1519
- }
1520
-
1521
- public visitImport(node:Import):boolean {
1522
- return true;
1523
- }
1524
-
1525
- public visitNamespace(node:Namespace):boolean {
1526
- return true;
1527
- }
1528
-
1529
- public visitExpression(node:Expression):boolean {
1530
- return true;
1531
- }
1532
-
1533
- public visitNumericValue(node:NumericValue):boolean {
1534
- return true;
1535
- }
1536
-
1537
- public visitPage(node:Page):boolean {
1538
- return true;
1539
- }
1540
-
1541
- public visitPageBoxMarginBox(node:PageBoxMarginBox):boolean {
1542
- return true;
1543
- }
1544
-
1545
- public visitNodelist(node:Nodelist):boolean {
1546
- return true;
1547
- }
1548
-
1549
- public visitVariableDeclaration(node:VariableDeclaration):boolean {
1550
- return true;
1551
- }
1552
-
1553
- public visitVariable(node:Variable):boolean {
1554
- return true;
1555
- }
1556
-
1557
- public visitMixinDeclaration(node:MixinDeclaration):boolean {
1558
- return true;
1559
- }
1560
-
1561
- public visitMixinReference(node:MixinReference):boolean {
1562
- return true;
1563
- }
1564
-
1565
- public visitUnknownNode(node:Node):boolean {
1566
- return true;
1567
- }
1568
- }
1569
- */
1570
- class ParseErrorCollector {
1571
- constructor() {
1572
- this.entries = [];
1573
- }
1574
- static entries(node) {
1575
- const visitor = new ParseErrorCollector();
1576
- node.acceptVisitor(visitor);
1577
- return visitor.entries;
1578
- }
1579
- visitNode(node) {
1580
- if (node.isErroneous()) {
1581
- node.collectIssues(this.entries);
1582
- }
1583
- return true;
1584
- }
1585
- }
1586
- exports.ParseErrorCollector = ParseErrorCollector;
1587
- });
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", "../utils/strings"], 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.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.Layer = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
17
+ const strings_1 = require("../utils/strings");
18
+ /// <summary>
19
+ /// Nodes for the css 2.1 specification. See for reference:
20
+ /// http://www.w3.org/TR/CSS21/grammar.html#grammar
21
+ /// </summary>
22
+ var NodeType;
23
+ (function (NodeType) {
24
+ NodeType[NodeType["Undefined"] = 0] = "Undefined";
25
+ NodeType[NodeType["Identifier"] = 1] = "Identifier";
26
+ NodeType[NodeType["Stylesheet"] = 2] = "Stylesheet";
27
+ NodeType[NodeType["Ruleset"] = 3] = "Ruleset";
28
+ NodeType[NodeType["Selector"] = 4] = "Selector";
29
+ NodeType[NodeType["SimpleSelector"] = 5] = "SimpleSelector";
30
+ NodeType[NodeType["SelectorInterpolation"] = 6] = "SelectorInterpolation";
31
+ NodeType[NodeType["SelectorCombinator"] = 7] = "SelectorCombinator";
32
+ NodeType[NodeType["SelectorCombinatorParent"] = 8] = "SelectorCombinatorParent";
33
+ NodeType[NodeType["SelectorCombinatorSibling"] = 9] = "SelectorCombinatorSibling";
34
+ NodeType[NodeType["SelectorCombinatorAllSiblings"] = 10] = "SelectorCombinatorAllSiblings";
35
+ NodeType[NodeType["SelectorCombinatorShadowPiercingDescendant"] = 11] = "SelectorCombinatorShadowPiercingDescendant";
36
+ NodeType[NodeType["Page"] = 12] = "Page";
37
+ NodeType[NodeType["PageBoxMarginBox"] = 13] = "PageBoxMarginBox";
38
+ NodeType[NodeType["ClassSelector"] = 14] = "ClassSelector";
39
+ NodeType[NodeType["IdentifierSelector"] = 15] = "IdentifierSelector";
40
+ NodeType[NodeType["ElementNameSelector"] = 16] = "ElementNameSelector";
41
+ NodeType[NodeType["PseudoSelector"] = 17] = "PseudoSelector";
42
+ NodeType[NodeType["AttributeSelector"] = 18] = "AttributeSelector";
43
+ NodeType[NodeType["Declaration"] = 19] = "Declaration";
44
+ NodeType[NodeType["Declarations"] = 20] = "Declarations";
45
+ NodeType[NodeType["Property"] = 21] = "Property";
46
+ NodeType[NodeType["Expression"] = 22] = "Expression";
47
+ NodeType[NodeType["BinaryExpression"] = 23] = "BinaryExpression";
48
+ NodeType[NodeType["Term"] = 24] = "Term";
49
+ NodeType[NodeType["Operator"] = 25] = "Operator";
50
+ NodeType[NodeType["Value"] = 26] = "Value";
51
+ NodeType[NodeType["StringLiteral"] = 27] = "StringLiteral";
52
+ NodeType[NodeType["URILiteral"] = 28] = "URILiteral";
53
+ NodeType[NodeType["EscapedValue"] = 29] = "EscapedValue";
54
+ NodeType[NodeType["Function"] = 30] = "Function";
55
+ NodeType[NodeType["NumericValue"] = 31] = "NumericValue";
56
+ NodeType[NodeType["HexColorValue"] = 32] = "HexColorValue";
57
+ NodeType[NodeType["RatioValue"] = 33] = "RatioValue";
58
+ NodeType[NodeType["MixinDeclaration"] = 34] = "MixinDeclaration";
59
+ NodeType[NodeType["MixinReference"] = 35] = "MixinReference";
60
+ NodeType[NodeType["VariableName"] = 36] = "VariableName";
61
+ NodeType[NodeType["VariableDeclaration"] = 37] = "VariableDeclaration";
62
+ NodeType[NodeType["Prio"] = 38] = "Prio";
63
+ NodeType[NodeType["Interpolation"] = 39] = "Interpolation";
64
+ NodeType[NodeType["NestedProperties"] = 40] = "NestedProperties";
65
+ NodeType[NodeType["ExtendsReference"] = 41] = "ExtendsReference";
66
+ NodeType[NodeType["SelectorPlaceholder"] = 42] = "SelectorPlaceholder";
67
+ NodeType[NodeType["Debug"] = 43] = "Debug";
68
+ NodeType[NodeType["If"] = 44] = "If";
69
+ NodeType[NodeType["Else"] = 45] = "Else";
70
+ NodeType[NodeType["For"] = 46] = "For";
71
+ NodeType[NodeType["Each"] = 47] = "Each";
72
+ NodeType[NodeType["While"] = 48] = "While";
73
+ NodeType[NodeType["MixinContentReference"] = 49] = "MixinContentReference";
74
+ NodeType[NodeType["MixinContentDeclaration"] = 50] = "MixinContentDeclaration";
75
+ NodeType[NodeType["Media"] = 51] = "Media";
76
+ NodeType[NodeType["Keyframe"] = 52] = "Keyframe";
77
+ NodeType[NodeType["FontFace"] = 53] = "FontFace";
78
+ NodeType[NodeType["Import"] = 54] = "Import";
79
+ NodeType[NodeType["Namespace"] = 55] = "Namespace";
80
+ NodeType[NodeType["Invocation"] = 56] = "Invocation";
81
+ NodeType[NodeType["FunctionDeclaration"] = 57] = "FunctionDeclaration";
82
+ NodeType[NodeType["ReturnStatement"] = 58] = "ReturnStatement";
83
+ NodeType[NodeType["MediaQuery"] = 59] = "MediaQuery";
84
+ NodeType[NodeType["MediaCondition"] = 60] = "MediaCondition";
85
+ NodeType[NodeType["MediaFeature"] = 61] = "MediaFeature";
86
+ NodeType[NodeType["FunctionParameter"] = 62] = "FunctionParameter";
87
+ NodeType[NodeType["FunctionArgument"] = 63] = "FunctionArgument";
88
+ NodeType[NodeType["KeyframeSelector"] = 64] = "KeyframeSelector";
89
+ NodeType[NodeType["ViewPort"] = 65] = "ViewPort";
90
+ NodeType[NodeType["Document"] = 66] = "Document";
91
+ NodeType[NodeType["AtApplyRule"] = 67] = "AtApplyRule";
92
+ NodeType[NodeType["CustomPropertyDeclaration"] = 68] = "CustomPropertyDeclaration";
93
+ NodeType[NodeType["CustomPropertySet"] = 69] = "CustomPropertySet";
94
+ NodeType[NodeType["ListEntry"] = 70] = "ListEntry";
95
+ NodeType[NodeType["Supports"] = 71] = "Supports";
96
+ NodeType[NodeType["SupportsCondition"] = 72] = "SupportsCondition";
97
+ NodeType[NodeType["NamespacePrefix"] = 73] = "NamespacePrefix";
98
+ NodeType[NodeType["GridLine"] = 74] = "GridLine";
99
+ NodeType[NodeType["Plugin"] = 75] = "Plugin";
100
+ NodeType[NodeType["UnknownAtRule"] = 76] = "UnknownAtRule";
101
+ NodeType[NodeType["Use"] = 77] = "Use";
102
+ NodeType[NodeType["ModuleConfiguration"] = 78] = "ModuleConfiguration";
103
+ NodeType[NodeType["Forward"] = 79] = "Forward";
104
+ NodeType[NodeType["ForwardVisibility"] = 80] = "ForwardVisibility";
105
+ NodeType[NodeType["Module"] = 81] = "Module";
106
+ NodeType[NodeType["UnicodeRange"] = 82] = "UnicodeRange";
107
+ NodeType[NodeType["Layer"] = 83] = "Layer";
108
+ NodeType[NodeType["LayerNameList"] = 84] = "LayerNameList";
109
+ NodeType[NodeType["LayerName"] = 85] = "LayerName";
110
+ })(NodeType = exports.NodeType || (exports.NodeType = {}));
111
+ var ReferenceType;
112
+ (function (ReferenceType) {
113
+ ReferenceType[ReferenceType["Mixin"] = 0] = "Mixin";
114
+ ReferenceType[ReferenceType["Rule"] = 1] = "Rule";
115
+ ReferenceType[ReferenceType["Variable"] = 2] = "Variable";
116
+ ReferenceType[ReferenceType["Function"] = 3] = "Function";
117
+ ReferenceType[ReferenceType["Keyframe"] = 4] = "Keyframe";
118
+ ReferenceType[ReferenceType["Unknown"] = 5] = "Unknown";
119
+ ReferenceType[ReferenceType["Module"] = 6] = "Module";
120
+ ReferenceType[ReferenceType["Forward"] = 7] = "Forward";
121
+ ReferenceType[ReferenceType["ForwardVisibility"] = 8] = "ForwardVisibility";
122
+ })(ReferenceType = exports.ReferenceType || (exports.ReferenceType = {}));
123
+ function getNodeAtOffset(node, offset) {
124
+ let candidate = null;
125
+ if (!node || offset < node.offset || offset > node.end) {
126
+ return null;
127
+ }
128
+ // Find the shortest node at the position
129
+ node.accept((node) => {
130
+ if (node.offset === -1 && node.length === -1) {
131
+ return true;
132
+ }
133
+ if (node.offset <= offset && node.end >= offset) {
134
+ if (!candidate) {
135
+ candidate = node;
136
+ }
137
+ else if (node.length <= candidate.length) {
138
+ candidate = node;
139
+ }
140
+ return true;
141
+ }
142
+ return false;
143
+ });
144
+ return candidate;
145
+ }
146
+ exports.getNodeAtOffset = getNodeAtOffset;
147
+ function getNodePath(node, offset) {
148
+ let candidate = getNodeAtOffset(node, offset);
149
+ const path = [];
150
+ while (candidate) {
151
+ path.unshift(candidate);
152
+ candidate = candidate.parent;
153
+ }
154
+ return path;
155
+ }
156
+ exports.getNodePath = getNodePath;
157
+ function getParentDeclaration(node) {
158
+ const decl = node.findParent(NodeType.Declaration);
159
+ const value = decl && decl.getValue();
160
+ if (value && value.encloses(node)) {
161
+ return decl;
162
+ }
163
+ return null;
164
+ }
165
+ exports.getParentDeclaration = getParentDeclaration;
166
+ class Node {
167
+ constructor(offset = -1, len = -1, nodeType) {
168
+ this.parent = null;
169
+ this.offset = offset;
170
+ this.length = len;
171
+ if (nodeType) {
172
+ this.nodeType = nodeType;
173
+ }
174
+ }
175
+ get end() { return this.offset + this.length; }
176
+ set type(type) {
177
+ this.nodeType = type;
178
+ }
179
+ get type() {
180
+ return this.nodeType || NodeType.Undefined;
181
+ }
182
+ getTextProvider() {
183
+ let node = this;
184
+ while (node && !node.textProvider) {
185
+ node = node.parent;
186
+ }
187
+ if (node) {
188
+ return node.textProvider;
189
+ }
190
+ return () => { return 'unknown'; };
191
+ }
192
+ getText() {
193
+ return this.getTextProvider()(this.offset, this.length);
194
+ }
195
+ matches(str) {
196
+ return this.length === str.length && this.getTextProvider()(this.offset, this.length) === str;
197
+ }
198
+ startsWith(str) {
199
+ return this.length >= str.length && this.getTextProvider()(this.offset, str.length) === str;
200
+ }
201
+ endsWith(str) {
202
+ return this.length >= str.length && this.getTextProvider()(this.end - str.length, str.length) === str;
203
+ }
204
+ accept(visitor) {
205
+ if (visitor(this) && this.children) {
206
+ for (const child of this.children) {
207
+ child.accept(visitor);
208
+ }
209
+ }
210
+ }
211
+ acceptVisitor(visitor) {
212
+ this.accept(visitor.visitNode.bind(visitor));
213
+ }
214
+ adoptChild(node, index = -1) {
215
+ if (node.parent && node.parent.children) {
216
+ const idx = node.parent.children.indexOf(node);
217
+ if (idx >= 0) {
218
+ node.parent.children.splice(idx, 1);
219
+ }
220
+ }
221
+ node.parent = this;
222
+ let children = this.children;
223
+ if (!children) {
224
+ children = this.children = [];
225
+ }
226
+ if (index !== -1) {
227
+ children.splice(index, 0, node);
228
+ }
229
+ else {
230
+ children.push(node);
231
+ }
232
+ return node;
233
+ }
234
+ attachTo(parent, index = -1) {
235
+ if (parent) {
236
+ parent.adoptChild(this, index);
237
+ }
238
+ return this;
239
+ }
240
+ collectIssues(results) {
241
+ if (this.issues) {
242
+ results.push.apply(results, this.issues);
243
+ }
244
+ }
245
+ addIssue(issue) {
246
+ if (!this.issues) {
247
+ this.issues = [];
248
+ }
249
+ this.issues.push(issue);
250
+ }
251
+ hasIssue(rule) {
252
+ return Array.isArray(this.issues) && this.issues.some(i => i.getRule() === rule);
253
+ }
254
+ isErroneous(recursive = false) {
255
+ if (this.issues && this.issues.length > 0) {
256
+ return true;
257
+ }
258
+ return recursive && Array.isArray(this.children) && this.children.some(c => c.isErroneous(true));
259
+ }
260
+ setNode(field, node, index = -1) {
261
+ if (node) {
262
+ node.attachTo(this, index);
263
+ this[field] = node;
264
+ return true;
265
+ }
266
+ return false;
267
+ }
268
+ addChild(node) {
269
+ if (node) {
270
+ if (!this.children) {
271
+ this.children = [];
272
+ }
273
+ node.attachTo(this);
274
+ this.updateOffsetAndLength(node);
275
+ return true;
276
+ }
277
+ return false;
278
+ }
279
+ updateOffsetAndLength(node) {
280
+ if (node.offset < this.offset || this.offset === -1) {
281
+ this.offset = node.offset;
282
+ }
283
+ const nodeEnd = node.end;
284
+ if ((nodeEnd > this.end) || this.length === -1) {
285
+ this.length = nodeEnd - this.offset;
286
+ }
287
+ }
288
+ hasChildren() {
289
+ return !!this.children && this.children.length > 0;
290
+ }
291
+ getChildren() {
292
+ return this.children ? this.children.slice(0) : [];
293
+ }
294
+ getChild(index) {
295
+ if (this.children && index < this.children.length) {
296
+ return this.children[index];
297
+ }
298
+ return null;
299
+ }
300
+ addChildren(nodes) {
301
+ for (const node of nodes) {
302
+ this.addChild(node);
303
+ }
304
+ }
305
+ findFirstChildBeforeOffset(offset) {
306
+ if (this.children) {
307
+ let current = null;
308
+ for (let i = this.children.length - 1; i >= 0; i--) {
309
+ // iterate until we find a child that has a start offset smaller than the input offset
310
+ current = this.children[i];
311
+ if (current.offset <= offset) {
312
+ return current;
313
+ }
314
+ }
315
+ }
316
+ return null;
317
+ }
318
+ findChildAtOffset(offset, goDeep) {
319
+ const current = this.findFirstChildBeforeOffset(offset);
320
+ if (current && current.end >= offset) {
321
+ if (goDeep) {
322
+ return current.findChildAtOffset(offset, true) || current;
323
+ }
324
+ return current;
325
+ }
326
+ return null;
327
+ }
328
+ encloses(candidate) {
329
+ return this.offset <= candidate.offset && this.offset + this.length >= candidate.offset + candidate.length;
330
+ }
331
+ getParent() {
332
+ let result = this.parent;
333
+ while (result instanceof Nodelist) {
334
+ result = result.parent;
335
+ }
336
+ return result;
337
+ }
338
+ findParent(type) {
339
+ let result = this;
340
+ while (result && result.type !== type) {
341
+ result = result.parent;
342
+ }
343
+ return result;
344
+ }
345
+ findAParent(...types) {
346
+ let result = this;
347
+ while (result && !types.some(t => result.type === t)) {
348
+ result = result.parent;
349
+ }
350
+ return result;
351
+ }
352
+ setData(key, value) {
353
+ if (!this.options) {
354
+ this.options = {};
355
+ }
356
+ this.options[key] = value;
357
+ }
358
+ getData(key) {
359
+ if (!this.options || !this.options.hasOwnProperty(key)) {
360
+ return null;
361
+ }
362
+ return this.options[key];
363
+ }
364
+ }
365
+ exports.Node = Node;
366
+ class Nodelist extends Node {
367
+ constructor(parent, index = -1) {
368
+ super(-1, -1);
369
+ this.attachTo(parent, index);
370
+ this.offset = -1;
371
+ this.length = -1;
372
+ }
373
+ }
374
+ exports.Nodelist = Nodelist;
375
+ class UnicodeRange extends Node {
376
+ constructor(offset, length) {
377
+ super(offset, length);
378
+ }
379
+ get type() {
380
+ return NodeType.UnicodeRange;
381
+ }
382
+ setRangeStart(rangeStart) {
383
+ return this.setNode('rangeStart', rangeStart);
384
+ }
385
+ getRangeStart() {
386
+ return this.rangeStart;
387
+ }
388
+ setRangeEnd(rangeEnd) {
389
+ return this.setNode('rangeEnd', rangeEnd);
390
+ }
391
+ getRangeEnd() {
392
+ return this.rangeEnd;
393
+ }
394
+ }
395
+ exports.UnicodeRange = UnicodeRange;
396
+ class Identifier extends Node {
397
+ constructor(offset, length) {
398
+ super(offset, length);
399
+ this.isCustomProperty = false;
400
+ }
401
+ get type() {
402
+ return NodeType.Identifier;
403
+ }
404
+ containsInterpolation() {
405
+ return this.hasChildren();
406
+ }
407
+ }
408
+ exports.Identifier = Identifier;
409
+ class Stylesheet extends Node {
410
+ constructor(offset, length) {
411
+ super(offset, length);
412
+ }
413
+ get type() {
414
+ return NodeType.Stylesheet;
415
+ }
416
+ }
417
+ exports.Stylesheet = Stylesheet;
418
+ class Declarations extends Node {
419
+ constructor(offset, length) {
420
+ super(offset, length);
421
+ }
422
+ get type() {
423
+ return NodeType.Declarations;
424
+ }
425
+ }
426
+ exports.Declarations = Declarations;
427
+ class BodyDeclaration extends Node {
428
+ constructor(offset, length) {
429
+ super(offset, length);
430
+ }
431
+ getDeclarations() {
432
+ return this.declarations;
433
+ }
434
+ setDeclarations(decls) {
435
+ return this.setNode('declarations', decls);
436
+ }
437
+ }
438
+ exports.BodyDeclaration = BodyDeclaration;
439
+ class RuleSet extends BodyDeclaration {
440
+ constructor(offset, length) {
441
+ super(offset, length);
442
+ }
443
+ get type() {
444
+ return NodeType.Ruleset;
445
+ }
446
+ getSelectors() {
447
+ if (!this.selectors) {
448
+ this.selectors = new Nodelist(this);
449
+ }
450
+ return this.selectors;
451
+ }
452
+ isNested() {
453
+ return !!this.parent && this.parent.findParent(NodeType.Declarations) !== null;
454
+ }
455
+ }
456
+ exports.RuleSet = RuleSet;
457
+ class Selector extends Node {
458
+ constructor(offset, length) {
459
+ super(offset, length);
460
+ }
461
+ get type() {
462
+ return NodeType.Selector;
463
+ }
464
+ }
465
+ exports.Selector = Selector;
466
+ class SimpleSelector extends Node {
467
+ constructor(offset, length) {
468
+ super(offset, length);
469
+ }
470
+ get type() {
471
+ return NodeType.SimpleSelector;
472
+ }
473
+ }
474
+ exports.SimpleSelector = SimpleSelector;
475
+ class AtApplyRule extends Node {
476
+ constructor(offset, length) {
477
+ super(offset, length);
478
+ }
479
+ get type() {
480
+ return NodeType.AtApplyRule;
481
+ }
482
+ setIdentifier(node) {
483
+ return this.setNode('identifier', node, 0);
484
+ }
485
+ getIdentifier() {
486
+ return this.identifier;
487
+ }
488
+ getName() {
489
+ return this.identifier ? this.identifier.getText() : '';
490
+ }
491
+ }
492
+ exports.AtApplyRule = AtApplyRule;
493
+ class AbstractDeclaration extends Node {
494
+ constructor(offset, length) {
495
+ super(offset, length);
496
+ }
497
+ }
498
+ exports.AbstractDeclaration = AbstractDeclaration;
499
+ class CustomPropertySet extends BodyDeclaration {
500
+ constructor(offset, length) {
501
+ super(offset, length);
502
+ }
503
+ get type() {
504
+ return NodeType.CustomPropertySet;
505
+ }
506
+ }
507
+ exports.CustomPropertySet = CustomPropertySet;
508
+ class Declaration extends AbstractDeclaration {
509
+ constructor(offset, length) {
510
+ super(offset, length);
511
+ this.property = null;
512
+ }
513
+ get type() {
514
+ return NodeType.Declaration;
515
+ }
516
+ setProperty(node) {
517
+ return this.setNode('property', node);
518
+ }
519
+ getProperty() {
520
+ return this.property;
521
+ }
522
+ getFullPropertyName() {
523
+ const propertyName = this.property ? this.property.getName() : 'unknown';
524
+ if (this.parent instanceof Declarations && this.parent.getParent() instanceof NestedProperties) {
525
+ const parentDecl = this.parent.getParent().getParent();
526
+ if (parentDecl instanceof Declaration) {
527
+ return parentDecl.getFullPropertyName() + propertyName;
528
+ }
529
+ }
530
+ return propertyName;
531
+ }
532
+ getNonPrefixedPropertyName() {
533
+ const propertyName = this.getFullPropertyName();
534
+ if (propertyName && propertyName.charAt(0) === '-') {
535
+ const vendorPrefixEnd = propertyName.indexOf('-', 1);
536
+ if (vendorPrefixEnd !== -1) {
537
+ return propertyName.substring(vendorPrefixEnd + 1);
538
+ }
539
+ }
540
+ return propertyName;
541
+ }
542
+ setValue(value) {
543
+ return this.setNode('value', value);
544
+ }
545
+ getValue() {
546
+ return this.value;
547
+ }
548
+ setNestedProperties(value) {
549
+ return this.setNode('nestedProperties', value);
550
+ }
551
+ getNestedProperties() {
552
+ return this.nestedProperties;
553
+ }
554
+ }
555
+ exports.Declaration = Declaration;
556
+ class CustomPropertyDeclaration extends Declaration {
557
+ constructor(offset, length) {
558
+ super(offset, length);
559
+ }
560
+ get type() {
561
+ return NodeType.CustomPropertyDeclaration;
562
+ }
563
+ setPropertySet(value) {
564
+ return this.setNode('propertySet', value);
565
+ }
566
+ getPropertySet() {
567
+ return this.propertySet;
568
+ }
569
+ }
570
+ exports.CustomPropertyDeclaration = CustomPropertyDeclaration;
571
+ class Property extends Node {
572
+ constructor(offset, length) {
573
+ super(offset, length);
574
+ }
575
+ get type() {
576
+ return NodeType.Property;
577
+ }
578
+ setIdentifier(value) {
579
+ return this.setNode('identifier', value);
580
+ }
581
+ getIdentifier() {
582
+ return this.identifier;
583
+ }
584
+ getName() {
585
+ return (0, strings_1.trim)(this.getText(), /[_\+]+$/); /* +_: less merge */
586
+ }
587
+ isCustomProperty() {
588
+ return !!this.identifier && this.identifier.isCustomProperty;
589
+ }
590
+ }
591
+ exports.Property = Property;
592
+ class Invocation extends Node {
593
+ constructor(offset, length) {
594
+ super(offset, length);
595
+ }
596
+ get type() {
597
+ return NodeType.Invocation;
598
+ }
599
+ getArguments() {
600
+ if (!this.arguments) {
601
+ this.arguments = new Nodelist(this);
602
+ }
603
+ return this.arguments;
604
+ }
605
+ }
606
+ exports.Invocation = Invocation;
607
+ class Function extends Invocation {
608
+ constructor(offset, length) {
609
+ super(offset, length);
610
+ }
611
+ get type() {
612
+ return NodeType.Function;
613
+ }
614
+ setIdentifier(node) {
615
+ return this.setNode('identifier', node, 0);
616
+ }
617
+ getIdentifier() {
618
+ return this.identifier;
619
+ }
620
+ getName() {
621
+ return this.identifier ? this.identifier.getText() : '';
622
+ }
623
+ }
624
+ exports.Function = Function;
625
+ class FunctionParameter extends Node {
626
+ constructor(offset, length) {
627
+ super(offset, length);
628
+ }
629
+ get type() {
630
+ return NodeType.FunctionParameter;
631
+ }
632
+ setIdentifier(node) {
633
+ return this.setNode('identifier', node, 0);
634
+ }
635
+ getIdentifier() {
636
+ return this.identifier;
637
+ }
638
+ getName() {
639
+ return this.identifier ? this.identifier.getText() : '';
640
+ }
641
+ setDefaultValue(node) {
642
+ return this.setNode('defaultValue', node, 0);
643
+ }
644
+ getDefaultValue() {
645
+ return this.defaultValue;
646
+ }
647
+ }
648
+ exports.FunctionParameter = FunctionParameter;
649
+ class FunctionArgument extends Node {
650
+ constructor(offset, length) {
651
+ super(offset, length);
652
+ }
653
+ get type() {
654
+ return NodeType.FunctionArgument;
655
+ }
656
+ setIdentifier(node) {
657
+ return this.setNode('identifier', node, 0);
658
+ }
659
+ getIdentifier() {
660
+ return this.identifier;
661
+ }
662
+ getName() {
663
+ return this.identifier ? this.identifier.getText() : '';
664
+ }
665
+ setValue(node) {
666
+ return this.setNode('value', node, 0);
667
+ }
668
+ getValue() {
669
+ return this.value;
670
+ }
671
+ }
672
+ exports.FunctionArgument = FunctionArgument;
673
+ class IfStatement extends BodyDeclaration {
674
+ constructor(offset, length) {
675
+ super(offset, length);
676
+ }
677
+ get type() {
678
+ return NodeType.If;
679
+ }
680
+ setExpression(node) {
681
+ return this.setNode('expression', node, 0);
682
+ }
683
+ setElseClause(elseClause) {
684
+ return this.setNode('elseClause', elseClause);
685
+ }
686
+ }
687
+ exports.IfStatement = IfStatement;
688
+ class ForStatement extends BodyDeclaration {
689
+ constructor(offset, length) {
690
+ super(offset, length);
691
+ }
692
+ get type() {
693
+ return NodeType.For;
694
+ }
695
+ setVariable(node) {
696
+ return this.setNode('variable', node, 0);
697
+ }
698
+ }
699
+ exports.ForStatement = ForStatement;
700
+ class EachStatement extends BodyDeclaration {
701
+ constructor(offset, length) {
702
+ super(offset, length);
703
+ }
704
+ get type() {
705
+ return NodeType.Each;
706
+ }
707
+ getVariables() {
708
+ if (!this.variables) {
709
+ this.variables = new Nodelist(this);
710
+ }
711
+ return this.variables;
712
+ }
713
+ }
714
+ exports.EachStatement = EachStatement;
715
+ class WhileStatement extends BodyDeclaration {
716
+ constructor(offset, length) {
717
+ super(offset, length);
718
+ }
719
+ get type() {
720
+ return NodeType.While;
721
+ }
722
+ }
723
+ exports.WhileStatement = WhileStatement;
724
+ class ElseStatement extends BodyDeclaration {
725
+ constructor(offset, length) {
726
+ super(offset, length);
727
+ }
728
+ get type() {
729
+ return NodeType.Else;
730
+ }
731
+ }
732
+ exports.ElseStatement = ElseStatement;
733
+ class FunctionDeclaration extends BodyDeclaration {
734
+ constructor(offset, length) {
735
+ super(offset, length);
736
+ }
737
+ get type() {
738
+ return NodeType.FunctionDeclaration;
739
+ }
740
+ setIdentifier(node) {
741
+ return this.setNode('identifier', node, 0);
742
+ }
743
+ getIdentifier() {
744
+ return this.identifier;
745
+ }
746
+ getName() {
747
+ return this.identifier ? this.identifier.getText() : '';
748
+ }
749
+ getParameters() {
750
+ if (!this.parameters) {
751
+ this.parameters = new Nodelist(this);
752
+ }
753
+ return this.parameters;
754
+ }
755
+ }
756
+ exports.FunctionDeclaration = FunctionDeclaration;
757
+ class ViewPort extends BodyDeclaration {
758
+ constructor(offset, length) {
759
+ super(offset, length);
760
+ }
761
+ get type() {
762
+ return NodeType.ViewPort;
763
+ }
764
+ }
765
+ exports.ViewPort = ViewPort;
766
+ class FontFace extends BodyDeclaration {
767
+ constructor(offset, length) {
768
+ super(offset, length);
769
+ }
770
+ get type() {
771
+ return NodeType.FontFace;
772
+ }
773
+ }
774
+ exports.FontFace = FontFace;
775
+ class NestedProperties extends BodyDeclaration {
776
+ constructor(offset, length) {
777
+ super(offset, length);
778
+ }
779
+ get type() {
780
+ return NodeType.NestedProperties;
781
+ }
782
+ }
783
+ exports.NestedProperties = NestedProperties;
784
+ class Keyframe extends BodyDeclaration {
785
+ constructor(offset, length) {
786
+ super(offset, length);
787
+ }
788
+ get type() {
789
+ return NodeType.Keyframe;
790
+ }
791
+ setKeyword(keyword) {
792
+ return this.setNode('keyword', keyword, 0);
793
+ }
794
+ getKeyword() {
795
+ return this.keyword;
796
+ }
797
+ setIdentifier(node) {
798
+ return this.setNode('identifier', node, 0);
799
+ }
800
+ getIdentifier() {
801
+ return this.identifier;
802
+ }
803
+ getName() {
804
+ return this.identifier ? this.identifier.getText() : '';
805
+ }
806
+ }
807
+ exports.Keyframe = Keyframe;
808
+ class KeyframeSelector extends BodyDeclaration {
809
+ constructor(offset, length) {
810
+ super(offset, length);
811
+ }
812
+ get type() {
813
+ return NodeType.KeyframeSelector;
814
+ }
815
+ }
816
+ exports.KeyframeSelector = KeyframeSelector;
817
+ class Import extends Node {
818
+ constructor(offset, length) {
819
+ super(offset, length);
820
+ }
821
+ get type() {
822
+ return NodeType.Import;
823
+ }
824
+ setMedialist(node) {
825
+ if (node) {
826
+ node.attachTo(this);
827
+ return true;
828
+ }
829
+ return false;
830
+ }
831
+ }
832
+ exports.Import = Import;
833
+ class Use extends Node {
834
+ get type() {
835
+ return NodeType.Use;
836
+ }
837
+ getParameters() {
838
+ if (!this.parameters) {
839
+ this.parameters = new Nodelist(this);
840
+ }
841
+ return this.parameters;
842
+ }
843
+ setIdentifier(node) {
844
+ return this.setNode('identifier', node, 0);
845
+ }
846
+ getIdentifier() {
847
+ return this.identifier;
848
+ }
849
+ }
850
+ exports.Use = Use;
851
+ class ModuleConfiguration extends Node {
852
+ get type() {
853
+ return NodeType.ModuleConfiguration;
854
+ }
855
+ setIdentifier(node) {
856
+ return this.setNode('identifier', node, 0);
857
+ }
858
+ getIdentifier() {
859
+ return this.identifier;
860
+ }
861
+ getName() {
862
+ return this.identifier ? this.identifier.getText() : '';
863
+ }
864
+ setValue(node) {
865
+ return this.setNode('value', node, 0);
866
+ }
867
+ getValue() {
868
+ return this.value;
869
+ }
870
+ }
871
+ exports.ModuleConfiguration = ModuleConfiguration;
872
+ class Forward extends Node {
873
+ get type() {
874
+ return NodeType.Forward;
875
+ }
876
+ setIdentifier(node) {
877
+ return this.setNode('identifier', node, 0);
878
+ }
879
+ getIdentifier() {
880
+ return this.identifier;
881
+ }
882
+ getMembers() {
883
+ if (!this.members) {
884
+ this.members = new Nodelist(this);
885
+ }
886
+ return this.members;
887
+ }
888
+ getParameters() {
889
+ if (!this.parameters) {
890
+ this.parameters = new Nodelist(this);
891
+ }
892
+ return this.parameters;
893
+ }
894
+ }
895
+ exports.Forward = Forward;
896
+ class ForwardVisibility extends Node {
897
+ get type() {
898
+ return NodeType.ForwardVisibility;
899
+ }
900
+ setIdentifier(node) {
901
+ return this.setNode('identifier', node, 0);
902
+ }
903
+ getIdentifier() {
904
+ return this.identifier;
905
+ }
906
+ }
907
+ exports.ForwardVisibility = ForwardVisibility;
908
+ class Namespace extends Node {
909
+ constructor(offset, length) {
910
+ super(offset, length);
911
+ }
912
+ get type() {
913
+ return NodeType.Namespace;
914
+ }
915
+ }
916
+ exports.Namespace = Namespace;
917
+ class Media extends BodyDeclaration {
918
+ constructor(offset, length) {
919
+ super(offset, length);
920
+ }
921
+ get type() {
922
+ return NodeType.Media;
923
+ }
924
+ }
925
+ exports.Media = Media;
926
+ class Supports extends BodyDeclaration {
927
+ constructor(offset, length) {
928
+ super(offset, length);
929
+ }
930
+ get type() {
931
+ return NodeType.Supports;
932
+ }
933
+ }
934
+ exports.Supports = Supports;
935
+ class Layer extends BodyDeclaration {
936
+ constructor(offset, length) {
937
+ super(offset, length);
938
+ }
939
+ get type() {
940
+ return NodeType.Layer;
941
+ }
942
+ setNames(names) {
943
+ return this.setNode('names', names);
944
+ }
945
+ getNames() {
946
+ return this.names;
947
+ }
948
+ }
949
+ exports.Layer = Layer;
950
+ class Document extends BodyDeclaration {
951
+ constructor(offset, length) {
952
+ super(offset, length);
953
+ }
954
+ get type() {
955
+ return NodeType.Document;
956
+ }
957
+ }
958
+ exports.Document = Document;
959
+ class Medialist extends Node {
960
+ constructor(offset, length) {
961
+ super(offset, length);
962
+ }
963
+ }
964
+ exports.Medialist = Medialist;
965
+ class MediaQuery extends Node {
966
+ constructor(offset, length) {
967
+ super(offset, length);
968
+ }
969
+ get type() {
970
+ return NodeType.MediaQuery;
971
+ }
972
+ }
973
+ exports.MediaQuery = MediaQuery;
974
+ class MediaCondition extends Node {
975
+ constructor(offset, length) {
976
+ super(offset, length);
977
+ }
978
+ get type() {
979
+ return NodeType.MediaCondition;
980
+ }
981
+ }
982
+ exports.MediaCondition = MediaCondition;
983
+ class MediaFeature extends Node {
984
+ constructor(offset, length) {
985
+ super(offset, length);
986
+ }
987
+ get type() {
988
+ return NodeType.MediaFeature;
989
+ }
990
+ }
991
+ exports.MediaFeature = MediaFeature;
992
+ class SupportsCondition extends Node {
993
+ constructor(offset, length) {
994
+ super(offset, length);
995
+ }
996
+ get type() {
997
+ return NodeType.SupportsCondition;
998
+ }
999
+ }
1000
+ exports.SupportsCondition = SupportsCondition;
1001
+ class Page extends BodyDeclaration {
1002
+ constructor(offset, length) {
1003
+ super(offset, length);
1004
+ }
1005
+ get type() {
1006
+ return NodeType.Page;
1007
+ }
1008
+ }
1009
+ exports.Page = Page;
1010
+ class PageBoxMarginBox extends BodyDeclaration {
1011
+ constructor(offset, length) {
1012
+ super(offset, length);
1013
+ }
1014
+ get type() {
1015
+ return NodeType.PageBoxMarginBox;
1016
+ }
1017
+ }
1018
+ exports.PageBoxMarginBox = PageBoxMarginBox;
1019
+ class Expression extends Node {
1020
+ constructor(offset, length) {
1021
+ super(offset, length);
1022
+ }
1023
+ get type() {
1024
+ return NodeType.Expression;
1025
+ }
1026
+ }
1027
+ exports.Expression = Expression;
1028
+ class BinaryExpression extends Node {
1029
+ constructor(offset, length) {
1030
+ super(offset, length);
1031
+ }
1032
+ get type() {
1033
+ return NodeType.BinaryExpression;
1034
+ }
1035
+ setLeft(left) {
1036
+ return this.setNode('left', left);
1037
+ }
1038
+ getLeft() {
1039
+ return this.left;
1040
+ }
1041
+ setRight(right) {
1042
+ return this.setNode('right', right);
1043
+ }
1044
+ getRight() {
1045
+ return this.right;
1046
+ }
1047
+ setOperator(value) {
1048
+ return this.setNode('operator', value);
1049
+ }
1050
+ getOperator() {
1051
+ return this.operator;
1052
+ }
1053
+ }
1054
+ exports.BinaryExpression = BinaryExpression;
1055
+ class Term extends Node {
1056
+ constructor(offset, length) {
1057
+ super(offset, length);
1058
+ }
1059
+ get type() {
1060
+ return NodeType.Term;
1061
+ }
1062
+ setOperator(value) {
1063
+ return this.setNode('operator', value);
1064
+ }
1065
+ getOperator() {
1066
+ return this.operator;
1067
+ }
1068
+ setExpression(value) {
1069
+ return this.setNode('expression', value);
1070
+ }
1071
+ getExpression() {
1072
+ return this.expression;
1073
+ }
1074
+ }
1075
+ exports.Term = Term;
1076
+ class AttributeSelector extends Node {
1077
+ constructor(offset, length) {
1078
+ super(offset, length);
1079
+ }
1080
+ get type() {
1081
+ return NodeType.AttributeSelector;
1082
+ }
1083
+ setNamespacePrefix(value) {
1084
+ return this.setNode('namespacePrefix', value);
1085
+ }
1086
+ getNamespacePrefix() {
1087
+ return this.namespacePrefix;
1088
+ }
1089
+ setIdentifier(value) {
1090
+ return this.setNode('identifier', value);
1091
+ }
1092
+ getIdentifier() {
1093
+ return this.identifier;
1094
+ }
1095
+ setOperator(operator) {
1096
+ return this.setNode('operator', operator);
1097
+ }
1098
+ getOperator() {
1099
+ return this.operator;
1100
+ }
1101
+ setValue(value) {
1102
+ return this.setNode('value', value);
1103
+ }
1104
+ getValue() {
1105
+ return this.value;
1106
+ }
1107
+ }
1108
+ exports.AttributeSelector = AttributeSelector;
1109
+ class Operator extends Node {
1110
+ constructor(offset, length) {
1111
+ super(offset, length);
1112
+ }
1113
+ get type() {
1114
+ return NodeType.Operator;
1115
+ }
1116
+ }
1117
+ exports.Operator = Operator;
1118
+ class HexColorValue extends Node {
1119
+ constructor(offset, length) {
1120
+ super(offset, length);
1121
+ }
1122
+ get type() {
1123
+ return NodeType.HexColorValue;
1124
+ }
1125
+ }
1126
+ exports.HexColorValue = HexColorValue;
1127
+ class RatioValue extends Node {
1128
+ constructor(offset, length) {
1129
+ super(offset, length);
1130
+ }
1131
+ get type() {
1132
+ return NodeType.RatioValue;
1133
+ }
1134
+ }
1135
+ exports.RatioValue = RatioValue;
1136
+ const _dot = '.'.charCodeAt(0), _0 = '0'.charCodeAt(0), _9 = '9'.charCodeAt(0);
1137
+ class NumericValue extends Node {
1138
+ constructor(offset, length) {
1139
+ super(offset, length);
1140
+ }
1141
+ get type() {
1142
+ return NodeType.NumericValue;
1143
+ }
1144
+ getValue() {
1145
+ const raw = this.getText();
1146
+ let unitIdx = 0;
1147
+ let code;
1148
+ for (let i = 0, len = raw.length; i < len; i++) {
1149
+ code = raw.charCodeAt(i);
1150
+ if (!(_0 <= code && code <= _9 || code === _dot)) {
1151
+ break;
1152
+ }
1153
+ unitIdx += 1;
1154
+ }
1155
+ return {
1156
+ value: raw.substring(0, unitIdx),
1157
+ unit: unitIdx < raw.length ? raw.substring(unitIdx) : undefined
1158
+ };
1159
+ }
1160
+ }
1161
+ exports.NumericValue = NumericValue;
1162
+ class VariableDeclaration extends AbstractDeclaration {
1163
+ constructor(offset, length) {
1164
+ super(offset, length);
1165
+ this.needsSemicolon = true;
1166
+ }
1167
+ get type() {
1168
+ return NodeType.VariableDeclaration;
1169
+ }
1170
+ setVariable(node) {
1171
+ if (node) {
1172
+ node.attachTo(this);
1173
+ this.variable = node;
1174
+ return true;
1175
+ }
1176
+ return false;
1177
+ }
1178
+ getVariable() {
1179
+ return this.variable;
1180
+ }
1181
+ getName() {
1182
+ return this.variable ? this.variable.getName() : '';
1183
+ }
1184
+ setValue(node) {
1185
+ if (node) {
1186
+ node.attachTo(this);
1187
+ this.value = node;
1188
+ return true;
1189
+ }
1190
+ return false;
1191
+ }
1192
+ getValue() {
1193
+ return this.value;
1194
+ }
1195
+ }
1196
+ exports.VariableDeclaration = VariableDeclaration;
1197
+ class Interpolation extends Node {
1198
+ // private _interpolations: void; // workaround for https://github.com/Microsoft/TypeScript/issues/18276
1199
+ constructor(offset, length) {
1200
+ super(offset, length);
1201
+ }
1202
+ get type() {
1203
+ return NodeType.Interpolation;
1204
+ }
1205
+ }
1206
+ exports.Interpolation = Interpolation;
1207
+ class Variable extends Node {
1208
+ constructor(offset, length) {
1209
+ super(offset, length);
1210
+ }
1211
+ get type() {
1212
+ return NodeType.VariableName;
1213
+ }
1214
+ getName() {
1215
+ return this.getText();
1216
+ }
1217
+ }
1218
+ exports.Variable = Variable;
1219
+ class ExtendsReference extends Node {
1220
+ constructor(offset, length) {
1221
+ super(offset, length);
1222
+ }
1223
+ get type() {
1224
+ return NodeType.ExtendsReference;
1225
+ }
1226
+ getSelectors() {
1227
+ if (!this.selectors) {
1228
+ this.selectors = new Nodelist(this);
1229
+ }
1230
+ return this.selectors;
1231
+ }
1232
+ }
1233
+ exports.ExtendsReference = ExtendsReference;
1234
+ class MixinContentReference extends Node {
1235
+ constructor(offset, length) {
1236
+ super(offset, length);
1237
+ }
1238
+ get type() {
1239
+ return NodeType.MixinContentReference;
1240
+ }
1241
+ getArguments() {
1242
+ if (!this.arguments) {
1243
+ this.arguments = new Nodelist(this);
1244
+ }
1245
+ return this.arguments;
1246
+ }
1247
+ }
1248
+ exports.MixinContentReference = MixinContentReference;
1249
+ class MixinContentDeclaration extends BodyDeclaration {
1250
+ constructor(offset, length) {
1251
+ super(offset, length);
1252
+ }
1253
+ get type() {
1254
+ return NodeType.MixinContentReference;
1255
+ }
1256
+ getParameters() {
1257
+ if (!this.parameters) {
1258
+ this.parameters = new Nodelist(this);
1259
+ }
1260
+ return this.parameters;
1261
+ }
1262
+ }
1263
+ exports.MixinContentDeclaration = MixinContentDeclaration;
1264
+ class MixinReference extends Node {
1265
+ constructor(offset, length) {
1266
+ super(offset, length);
1267
+ }
1268
+ get type() {
1269
+ return NodeType.MixinReference;
1270
+ }
1271
+ getNamespaces() {
1272
+ if (!this.namespaces) {
1273
+ this.namespaces = new Nodelist(this);
1274
+ }
1275
+ return this.namespaces;
1276
+ }
1277
+ setIdentifier(node) {
1278
+ return this.setNode('identifier', node, 0);
1279
+ }
1280
+ getIdentifier() {
1281
+ return this.identifier;
1282
+ }
1283
+ getName() {
1284
+ return this.identifier ? this.identifier.getText() : '';
1285
+ }
1286
+ getArguments() {
1287
+ if (!this.arguments) {
1288
+ this.arguments = new Nodelist(this);
1289
+ }
1290
+ return this.arguments;
1291
+ }
1292
+ setContent(node) {
1293
+ return this.setNode('content', node);
1294
+ }
1295
+ getContent() {
1296
+ return this.content;
1297
+ }
1298
+ }
1299
+ exports.MixinReference = MixinReference;
1300
+ class MixinDeclaration extends BodyDeclaration {
1301
+ constructor(offset, length) {
1302
+ super(offset, length);
1303
+ }
1304
+ get type() {
1305
+ return NodeType.MixinDeclaration;
1306
+ }
1307
+ setIdentifier(node) {
1308
+ return this.setNode('identifier', node, 0);
1309
+ }
1310
+ getIdentifier() {
1311
+ return this.identifier;
1312
+ }
1313
+ getName() {
1314
+ return this.identifier ? this.identifier.getText() : '';
1315
+ }
1316
+ getParameters() {
1317
+ if (!this.parameters) {
1318
+ this.parameters = new Nodelist(this);
1319
+ }
1320
+ return this.parameters;
1321
+ }
1322
+ setGuard(node) {
1323
+ if (node) {
1324
+ node.attachTo(this);
1325
+ this.guard = node;
1326
+ }
1327
+ return false;
1328
+ }
1329
+ }
1330
+ exports.MixinDeclaration = MixinDeclaration;
1331
+ class UnknownAtRule extends BodyDeclaration {
1332
+ constructor(offset, length) {
1333
+ super(offset, length);
1334
+ }
1335
+ get type() {
1336
+ return NodeType.UnknownAtRule;
1337
+ }
1338
+ setAtRuleName(atRuleName) {
1339
+ this.atRuleName = atRuleName;
1340
+ }
1341
+ getAtRuleName() {
1342
+ return this.atRuleName;
1343
+ }
1344
+ }
1345
+ exports.UnknownAtRule = UnknownAtRule;
1346
+ class ListEntry extends Node {
1347
+ get type() {
1348
+ return NodeType.ListEntry;
1349
+ }
1350
+ setKey(node) {
1351
+ return this.setNode('key', node, 0);
1352
+ }
1353
+ setValue(node) {
1354
+ return this.setNode('value', node, 1);
1355
+ }
1356
+ }
1357
+ exports.ListEntry = ListEntry;
1358
+ class LessGuard extends Node {
1359
+ getConditions() {
1360
+ if (!this.conditions) {
1361
+ this.conditions = new Nodelist(this);
1362
+ }
1363
+ return this.conditions;
1364
+ }
1365
+ }
1366
+ exports.LessGuard = LessGuard;
1367
+ class GuardCondition extends Node {
1368
+ setVariable(node) {
1369
+ return this.setNode('variable', node);
1370
+ }
1371
+ }
1372
+ exports.GuardCondition = GuardCondition;
1373
+ class Module extends Node {
1374
+ get type() {
1375
+ return NodeType.Module;
1376
+ }
1377
+ setIdentifier(node) {
1378
+ return this.setNode('identifier', node, 0);
1379
+ }
1380
+ getIdentifier() {
1381
+ return this.identifier;
1382
+ }
1383
+ }
1384
+ exports.Module = Module;
1385
+ var Level;
1386
+ (function (Level) {
1387
+ Level[Level["Ignore"] = 1] = "Ignore";
1388
+ Level[Level["Warning"] = 2] = "Warning";
1389
+ Level[Level["Error"] = 4] = "Error";
1390
+ })(Level = exports.Level || (exports.Level = {}));
1391
+ class Marker {
1392
+ constructor(node, rule, level, message, offset = node.offset, length = node.length) {
1393
+ this.node = node;
1394
+ this.rule = rule;
1395
+ this.level = level;
1396
+ this.message = message || rule.message;
1397
+ this.offset = offset;
1398
+ this.length = length;
1399
+ }
1400
+ getRule() {
1401
+ return this.rule;
1402
+ }
1403
+ getLevel() {
1404
+ return this.level;
1405
+ }
1406
+ getOffset() {
1407
+ return this.offset;
1408
+ }
1409
+ getLength() {
1410
+ return this.length;
1411
+ }
1412
+ getNode() {
1413
+ return this.node;
1414
+ }
1415
+ getMessage() {
1416
+ return this.message;
1417
+ }
1418
+ }
1419
+ exports.Marker = Marker;
1420
+ /*
1421
+ export class DefaultVisitor implements IVisitor {
1422
+
1423
+ public visitNode(node:Node):boolean {
1424
+ switch (node.type) {
1425
+ case NodeType.Stylesheet:
1426
+ return this.visitStylesheet(<Stylesheet> node);
1427
+ case NodeType.FontFace:
1428
+ return this.visitFontFace(<FontFace> node);
1429
+ case NodeType.Ruleset:
1430
+ return this.visitRuleSet(<RuleSet> node);
1431
+ case NodeType.Selector:
1432
+ return this.visitSelector(<Selector> node);
1433
+ case NodeType.SimpleSelector:
1434
+ return this.visitSimpleSelector(<SimpleSelector> node);
1435
+ case NodeType.Declaration:
1436
+ return this.visitDeclaration(<Declaration> node);
1437
+ case NodeType.Function:
1438
+ return this.visitFunction(<Function> node);
1439
+ case NodeType.FunctionDeclaration:
1440
+ return this.visitFunctionDeclaration(<FunctionDeclaration> node);
1441
+ case NodeType.FunctionParameter:
1442
+ return this.visitFunctionParameter(<FunctionParameter> node);
1443
+ case NodeType.FunctionArgument:
1444
+ return this.visitFunctionArgument(<FunctionArgument> node);
1445
+ case NodeType.Term:
1446
+ return this.visitTerm(<Term> node);
1447
+ case NodeType.Declaration:
1448
+ return this.visitExpression(<Expression> node);
1449
+ case NodeType.NumericValue:
1450
+ return this.visitNumericValue(<NumericValue> node);
1451
+ case NodeType.Page:
1452
+ return this.visitPage(<Page> node);
1453
+ case NodeType.PageBoxMarginBox:
1454
+ return this.visitPageBoxMarginBox(<PageBoxMarginBox> node);
1455
+ case NodeType.Property:
1456
+ return this.visitProperty(<Property> node);
1457
+ case NodeType.NumericValue:
1458
+ return this.visitNodelist(<Nodelist> node);
1459
+ case NodeType.Import:
1460
+ return this.visitImport(<Import> node);
1461
+ case NodeType.Namespace:
1462
+ return this.visitNamespace(<Namespace> node);
1463
+ case NodeType.Keyframe:
1464
+ return this.visitKeyframe(<Keyframe> node);
1465
+ case NodeType.KeyframeSelector:
1466
+ return this.visitKeyframeSelector(<KeyframeSelector> node);
1467
+ case NodeType.MixinDeclaration:
1468
+ return this.visitMixinDeclaration(<MixinDeclaration> node);
1469
+ case NodeType.MixinReference:
1470
+ return this.visitMixinReference(<MixinReference> node);
1471
+ case NodeType.Variable:
1472
+ return this.visitVariable(<Variable> node);
1473
+ case NodeType.VariableDeclaration:
1474
+ return this.visitVariableDeclaration(<VariableDeclaration> node);
1475
+ }
1476
+ return this.visitUnknownNode(node);
1477
+ }
1478
+
1479
+ public visitFontFace(node:FontFace):boolean {
1480
+ return true;
1481
+ }
1482
+
1483
+ public visitKeyframe(node:Keyframe):boolean {
1484
+ return true;
1485
+ }
1486
+
1487
+ public visitKeyframeSelector(node:KeyframeSelector):boolean {
1488
+ return true;
1489
+ }
1490
+
1491
+ public visitStylesheet(node:Stylesheet):boolean {
1492
+ return true;
1493
+ }
1494
+
1495
+ public visitProperty(Node:Property):boolean {
1496
+ return true;
1497
+ }
1498
+
1499
+ public visitRuleSet(node:RuleSet):boolean {
1500
+ return true;
1501
+ }
1502
+
1503
+ public visitSelector(node:Selector):boolean {
1504
+ return true;
1505
+ }
1506
+
1507
+ public visitSimpleSelector(node:SimpleSelector):boolean {
1508
+ return true;
1509
+ }
1510
+
1511
+ public visitDeclaration(node:Declaration):boolean {
1512
+ return true;
1513
+ }
1514
+
1515
+ public visitFunction(node:Function):boolean {
1516
+ return true;
1517
+ }
1518
+
1519
+ public visitFunctionDeclaration(node:FunctionDeclaration):boolean {
1520
+ return true;
1521
+ }
1522
+
1523
+ public visitInvocation(node:Invocation):boolean {
1524
+ return true;
1525
+ }
1526
+
1527
+ public visitTerm(node:Term):boolean {
1528
+ return true;
1529
+ }
1530
+
1531
+ public visitImport(node:Import):boolean {
1532
+ return true;
1533
+ }
1534
+
1535
+ public visitNamespace(node:Namespace):boolean {
1536
+ return true;
1537
+ }
1538
+
1539
+ public visitExpression(node:Expression):boolean {
1540
+ return true;
1541
+ }
1542
+
1543
+ public visitNumericValue(node:NumericValue):boolean {
1544
+ return true;
1545
+ }
1546
+
1547
+ public visitPage(node:Page):boolean {
1548
+ return true;
1549
+ }
1550
+
1551
+ public visitPageBoxMarginBox(node:PageBoxMarginBox):boolean {
1552
+ return true;
1553
+ }
1554
+
1555
+ public visitNodelist(node:Nodelist):boolean {
1556
+ return true;
1557
+ }
1558
+
1559
+ public visitVariableDeclaration(node:VariableDeclaration):boolean {
1560
+ return true;
1561
+ }
1562
+
1563
+ public visitVariable(node:Variable):boolean {
1564
+ return true;
1565
+ }
1566
+
1567
+ public visitMixinDeclaration(node:MixinDeclaration):boolean {
1568
+ return true;
1569
+ }
1570
+
1571
+ public visitMixinReference(node:MixinReference):boolean {
1572
+ return true;
1573
+ }
1574
+
1575
+ public visitUnknownNode(node:Node):boolean {
1576
+ return true;
1577
+ }
1578
+ }
1579
+ */
1580
+ class ParseErrorCollector {
1581
+ constructor() {
1582
+ this.entries = [];
1583
+ }
1584
+ static entries(node) {
1585
+ const visitor = new ParseErrorCollector();
1586
+ node.acceptVisitor(visitor);
1587
+ return visitor.entries;
1588
+ }
1589
+ visitNode(node) {
1590
+ if (node.isErroneous()) {
1591
+ node.collectIssues(this.entries);
1592
+ }
1593
+ return true;
1594
+ }
1595
+ }
1596
+ exports.ParseErrorCollector = ParseErrorCollector;
1597
+ });