vscode-css-languageservice 5.4.2 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/SECURITY.md +41 -0
- package/lib/esm/beautify/beautify-css.js +11 -4
- package/lib/esm/cssLanguageService.d.ts +2 -1
- package/lib/esm/cssLanguageService.js +15 -17
- package/lib/esm/cssLanguageTypes.js +2 -2
- package/lib/esm/data/webCustomData.js +356 -232
- package/lib/esm/languageFacts/builtinData.js +15 -15
- package/lib/esm/languageFacts/colors.js +66 -69
- package/lib/esm/languageFacts/dataManager.js +38 -42
- package/lib/esm/languageFacts/dataProvider.js +17 -23
- package/lib/esm/languageFacts/entry.js +22 -23
- package/lib/esm/parser/cssErrors.js +5 -7
- package/lib/esm/parser/cssNodes.js +869 -1377
- package/lib/esm/parser/cssParser.js +419 -376
- package/lib/esm/parser/cssScanner.js +168 -175
- package/lib/esm/parser/cssSymbolScope.js +107 -137
- package/lib/esm/parser/lessParser.js +177 -202
- package/lib/esm/parser/lessScanner.js +22 -43
- package/lib/esm/parser/scssErrors.js +5 -7
- package/lib/esm/parser/scssParser.js +196 -208
- package/lib/esm/parser/scssScanner.js +33 -54
- package/lib/esm/services/cssCodeActions.js +36 -40
- package/lib/esm/services/cssCompletion.js +300 -395
- package/lib/esm/services/cssFolding.js +32 -35
- package/lib/esm/services/cssFormatter.js +22 -22
- package/lib/esm/services/cssHover.js +30 -33
- package/lib/esm/services/cssNavigation.js +260 -289
- package/lib/esm/services/cssSelectionRange.js +6 -6
- package/lib/esm/services/cssValidation.js +13 -16
- package/lib/esm/services/lessCompletion.js +351 -370
- package/lib/esm/services/lint.js +161 -175
- package/lib/esm/services/lintRules.js +20 -27
- package/lib/esm/services/lintUtil.js +19 -28
- package/lib/esm/services/pathCompletion.js +84 -158
- package/lib/esm/services/scssCompletion.js +283 -307
- package/lib/esm/services/scssNavigation.js +65 -137
- package/lib/esm/services/selectorPrinting.js +131 -175
- package/lib/esm/utils/arrays.js +6 -12
- package/lib/esm/utils/objects.js +1 -1
- package/lib/esm/utils/resources.js +3 -16
- package/lib/esm/utils/strings.js +10 -12
- package/lib/umd/beautify/beautify-css.js +11 -4
- package/lib/umd/cssLanguageService.d.ts +2 -1
- package/lib/umd/cssLanguageService.js +34 -32
- package/lib/umd/cssLanguageTypes.js +4 -3
- package/lib/umd/data/webCustomData.js +355 -231
- package/lib/umd/languageFacts/colors.js +65 -68
- package/lib/umd/languageFacts/dataManager.js +41 -44
- package/lib/umd/languageFacts/dataProvider.js +17 -22
- package/lib/umd/languageFacts/entry.js +22 -23
- package/lib/umd/languageFacts/facts.js +5 -1
- package/lib/umd/parser/cssErrors.js +5 -6
- package/lib/umd/parser/cssNodes.js +870 -1307
- package/lib/umd/parser/cssParser.js +424 -380
- package/lib/umd/parser/cssScanner.js +168 -173
- package/lib/umd/parser/cssSymbolScope.js +109 -134
- package/lib/umd/parser/lessParser.js +182 -206
- package/lib/umd/parser/lessScanner.js +22 -42
- package/lib/umd/parser/scssErrors.js +5 -6
- package/lib/umd/parser/scssParser.js +202 -213
- package/lib/umd/parser/scssScanner.js +25 -45
- package/lib/umd/services/cssCodeActions.js +41 -44
- package/lib/umd/services/cssCompletion.js +308 -402
- package/lib/umd/services/cssFolding.js +35 -38
- package/lib/umd/services/cssFormatter.js +25 -25
- package/lib/umd/services/cssHover.js +36 -38
- package/lib/umd/services/cssNavigation.js +267 -295
- package/lib/umd/services/cssSelectionRange.js +8 -8
- package/lib/umd/services/cssValidation.js +17 -19
- package/lib/umd/services/lessCompletion.js +354 -372
- package/lib/umd/services/lint.js +167 -180
- package/lib/umd/services/lintRules.js +20 -24
- package/lib/umd/services/lintUtil.js +20 -28
- package/lib/umd/services/pathCompletion.js +87 -160
- package/lib/umd/services/scssCompletion.js +287 -310
- package/lib/umd/services/scssNavigation.js +69 -140
- package/lib/umd/services/selectorPrinting.js +134 -174
- package/lib/umd/utils/arrays.js +6 -12
- package/lib/umd/utils/objects.js +1 -1
- package/lib/umd/utils/resources.js +4 -17
- package/lib/umd/utils/strings.js +10 -12
- package/package.json +16 -15
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
(function (factory) {
|
|
17
2
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
18
3
|
var v = factory(require, exports);
|
|
@@ -29,28 +14,27 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
29
14
|
'use strict';
|
|
30
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
16
|
exports.selectorToElement = exports.SelectorPrinting = exports.toElement = exports.LabelElement = exports.RootElement = exports.Element = void 0;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
const nodes = require("../parser/cssNodes");
|
|
18
|
+
const cssScanner_1 = require("../parser/cssScanner");
|
|
19
|
+
const nls = require("vscode-nls");
|
|
20
|
+
const localize = nls.loadMessageBundle();
|
|
21
|
+
class Element {
|
|
22
|
+
constructor() {
|
|
38
23
|
this.parent = null;
|
|
39
24
|
this.children = null;
|
|
40
25
|
this.attributes = null;
|
|
41
26
|
}
|
|
42
|
-
|
|
27
|
+
findAttribute(name) {
|
|
43
28
|
if (this.attributes) {
|
|
44
|
-
for (
|
|
45
|
-
var attribute = _a[_i];
|
|
29
|
+
for (const attribute of this.attributes) {
|
|
46
30
|
if (attribute.name === name) {
|
|
47
31
|
return attribute.value;
|
|
48
32
|
}
|
|
49
33
|
}
|
|
50
34
|
}
|
|
51
35
|
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
36
|
+
}
|
|
37
|
+
addChild(child) {
|
|
54
38
|
if (child instanceof Element) {
|
|
55
39
|
child.parent = this;
|
|
56
40
|
}
|
|
@@ -58,103 +42,91 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
58
42
|
this.children = [];
|
|
59
43
|
}
|
|
60
44
|
this.children.push(child);
|
|
61
|
-
}
|
|
62
|
-
|
|
45
|
+
}
|
|
46
|
+
append(text) {
|
|
63
47
|
if (this.attributes) {
|
|
64
|
-
|
|
48
|
+
const last = this.attributes[this.attributes.length - 1];
|
|
65
49
|
last.value = last.value + text;
|
|
66
50
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
51
|
+
}
|
|
52
|
+
prepend(text) {
|
|
69
53
|
if (this.attributes) {
|
|
70
|
-
|
|
54
|
+
const first = this.attributes[0];
|
|
71
55
|
first.value = text + first.value;
|
|
72
56
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
}
|
|
58
|
+
findRoot() {
|
|
59
|
+
let curr = this;
|
|
76
60
|
while (curr.parent && !(curr.parent instanceof RootElement)) {
|
|
77
61
|
curr = curr.parent;
|
|
78
62
|
}
|
|
79
63
|
return curr;
|
|
80
|
-
}
|
|
81
|
-
|
|
64
|
+
}
|
|
65
|
+
removeChild(child) {
|
|
82
66
|
if (this.children) {
|
|
83
|
-
|
|
67
|
+
const index = this.children.indexOf(child);
|
|
84
68
|
if (index !== -1) {
|
|
85
69
|
this.children.splice(index, 1);
|
|
86
70
|
return true;
|
|
87
71
|
}
|
|
88
72
|
}
|
|
89
73
|
return false;
|
|
90
|
-
}
|
|
91
|
-
|
|
74
|
+
}
|
|
75
|
+
addAttr(name, value) {
|
|
92
76
|
if (!this.attributes) {
|
|
93
77
|
this.attributes = [];
|
|
94
78
|
}
|
|
95
|
-
for (
|
|
96
|
-
var attribute = _a[_i];
|
|
79
|
+
for (const attribute of this.attributes) {
|
|
97
80
|
if (attribute.name === name) {
|
|
98
81
|
attribute.value += ' ' + value;
|
|
99
82
|
return;
|
|
100
83
|
}
|
|
101
84
|
}
|
|
102
|
-
this.attributes.push({ name
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var elem = new Element();
|
|
85
|
+
this.attributes.push({ name, value });
|
|
86
|
+
}
|
|
87
|
+
clone(cloneChildren = true) {
|
|
88
|
+
const elem = new Element();
|
|
107
89
|
if (this.attributes) {
|
|
108
90
|
elem.attributes = [];
|
|
109
|
-
for (
|
|
110
|
-
var attribute = _a[_i];
|
|
91
|
+
for (const attribute of this.attributes) {
|
|
111
92
|
elem.addAttr(attribute.name, attribute.value);
|
|
112
93
|
}
|
|
113
94
|
}
|
|
114
95
|
if (cloneChildren && this.children) {
|
|
115
96
|
elem.children = [];
|
|
116
|
-
for (
|
|
97
|
+
for (let index = 0; index < this.children.length; index++) {
|
|
117
98
|
elem.addChild(this.children[index].clone());
|
|
118
99
|
}
|
|
119
100
|
}
|
|
120
101
|
return elem;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
102
|
+
}
|
|
103
|
+
cloneWithParent() {
|
|
104
|
+
const clone = this.clone(false);
|
|
124
105
|
if (this.parent && !(this.parent instanceof RootElement)) {
|
|
125
|
-
|
|
106
|
+
const parentClone = this.parent.cloneWithParent();
|
|
126
107
|
parentClone.addChild(clone);
|
|
127
108
|
}
|
|
128
109
|
return clone;
|
|
129
|
-
};
|
|
130
|
-
return Element;
|
|
131
|
-
}());
|
|
132
|
-
exports.Element = Element;
|
|
133
|
-
var RootElement = /** @class */ (function (_super) {
|
|
134
|
-
__extends(RootElement, _super);
|
|
135
|
-
function RootElement() {
|
|
136
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
137
110
|
}
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
}
|
|
112
|
+
exports.Element = Element;
|
|
113
|
+
class RootElement extends Element {
|
|
114
|
+
}
|
|
140
115
|
exports.RootElement = RootElement;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return LabelElement;
|
|
149
|
-
}(Element));
|
|
116
|
+
class LabelElement extends Element {
|
|
117
|
+
constructor(label) {
|
|
118
|
+
super();
|
|
119
|
+
this.addAttr('name', label);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
150
122
|
exports.LabelElement = LabelElement;
|
|
151
|
-
|
|
152
|
-
|
|
123
|
+
class MarkedStringPrinter {
|
|
124
|
+
constructor(quote) {
|
|
153
125
|
this.quote = quote;
|
|
154
126
|
this.result = [];
|
|
155
127
|
// empty
|
|
156
128
|
}
|
|
157
|
-
|
|
129
|
+
print(element) {
|
|
158
130
|
this.result = [];
|
|
159
131
|
if (element instanceof RootElement) {
|
|
160
132
|
if (element.children) {
|
|
@@ -164,31 +136,30 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
164
136
|
else {
|
|
165
137
|
this.doPrint([element], 0);
|
|
166
138
|
}
|
|
167
|
-
|
|
168
|
-
return [{ language: 'html', value
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
for (
|
|
172
|
-
var element = elements_1[_i];
|
|
139
|
+
const value = this.result.join('\n');
|
|
140
|
+
return [{ language: 'html', value }];
|
|
141
|
+
}
|
|
142
|
+
doPrint(elements, indent) {
|
|
143
|
+
for (const element of elements) {
|
|
173
144
|
this.doPrintElement(element, indent);
|
|
174
145
|
if (element.children) {
|
|
175
146
|
this.doPrint(element.children, indent + 1);
|
|
176
147
|
}
|
|
177
148
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
149
|
+
}
|
|
150
|
+
writeLine(level, content) {
|
|
151
|
+
const indent = new Array(level + 1).join(' ');
|
|
181
152
|
this.result.push(indent + content);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
153
|
+
}
|
|
154
|
+
doPrintElement(element, indent) {
|
|
155
|
+
const name = element.findAttribute('name');
|
|
185
156
|
// special case: a simple label
|
|
186
157
|
if (element instanceof LabelElement || name === '\u2026') {
|
|
187
158
|
this.writeLine(indent, name);
|
|
188
159
|
return;
|
|
189
160
|
}
|
|
190
161
|
// the real deal
|
|
191
|
-
|
|
162
|
+
const content = ['<'];
|
|
192
163
|
// element name
|
|
193
164
|
if (name) {
|
|
194
165
|
content.push(name);
|
|
@@ -198,12 +169,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
198
169
|
}
|
|
199
170
|
// attributes
|
|
200
171
|
if (element.attributes) {
|
|
201
|
-
for (
|
|
202
|
-
var attr = _a[_i];
|
|
172
|
+
for (const attr of element.attributes) {
|
|
203
173
|
if (attr.name !== 'name') {
|
|
204
174
|
content.push(' ');
|
|
205
175
|
content.push(attr.name);
|
|
206
|
-
|
|
176
|
+
const value = attr.value;
|
|
207
177
|
if (value) {
|
|
208
178
|
content.push('=');
|
|
209
179
|
content.push(quotes.ensure(value, this.quote));
|
|
@@ -213,9 +183,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
213
183
|
}
|
|
214
184
|
content.push('>');
|
|
215
185
|
this.writeLine(indent, content.join(''));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
}());
|
|
186
|
+
}
|
|
187
|
+
}
|
|
219
188
|
var quotes;
|
|
220
189
|
(function (quotes) {
|
|
221
190
|
function ensure(value, which) {
|
|
@@ -223,7 +192,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
223
192
|
}
|
|
224
193
|
quotes.ensure = ensure;
|
|
225
194
|
function remove(value) {
|
|
226
|
-
|
|
195
|
+
const match = value.match(/^['"](.*)["']$/);
|
|
227
196
|
if (match) {
|
|
228
197
|
return match[1];
|
|
229
198
|
}
|
|
@@ -231,8 +200,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
231
200
|
}
|
|
232
201
|
quotes.remove = remove;
|
|
233
202
|
})(quotes || (quotes = {}));
|
|
234
|
-
|
|
235
|
-
|
|
203
|
+
class Specificity {
|
|
204
|
+
constructor() {
|
|
236
205
|
/** Count of identifiers (e.g., `#app`) */
|
|
237
206
|
this.id = 0;
|
|
238
207
|
/** Count of attributes (`[type="number"]`), classes (`.container-fluid`), and pseudo-classes (`:hover`) */
|
|
@@ -240,16 +209,14 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
240
209
|
/** Count of tag names (`div`), and pseudo-elements (`::before`) */
|
|
241
210
|
this.tag = 0;
|
|
242
211
|
}
|
|
243
|
-
|
|
244
|
-
}());
|
|
212
|
+
}
|
|
245
213
|
function toElement(node, parentElement) {
|
|
246
|
-
|
|
247
|
-
for (
|
|
248
|
-
var child = _a[_i];
|
|
214
|
+
let result = new Element();
|
|
215
|
+
for (const child of node.getChildren()) {
|
|
249
216
|
switch (child.type) {
|
|
250
217
|
case nodes.NodeType.SelectorCombinator:
|
|
251
218
|
if (parentElement) {
|
|
252
|
-
|
|
219
|
+
const segments = child.getText().split('&');
|
|
253
220
|
if (segments.length === 1) {
|
|
254
221
|
// should not happen
|
|
255
222
|
result.addAttr('name', segments[0]);
|
|
@@ -257,12 +224,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
257
224
|
}
|
|
258
225
|
result = parentElement.cloneWithParent();
|
|
259
226
|
if (segments[0]) {
|
|
260
|
-
|
|
227
|
+
const root = result.findRoot();
|
|
261
228
|
root.prepend(segments[0]);
|
|
262
229
|
}
|
|
263
|
-
for (
|
|
230
|
+
for (let i = 1; i < segments.length; i++) {
|
|
264
231
|
if (i > 1) {
|
|
265
|
-
|
|
232
|
+
const clone = parentElement.cloneWithParent();
|
|
266
233
|
result.addChild(clone.findRoot());
|
|
267
234
|
result = clone;
|
|
268
235
|
}
|
|
@@ -276,7 +243,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
276
243
|
}
|
|
277
244
|
// fall through
|
|
278
245
|
case nodes.NodeType.ElementNameSelector:
|
|
279
|
-
|
|
246
|
+
const text = child.getText();
|
|
280
247
|
result.addAttr('name', text === '*' ? 'element' : unescape(text));
|
|
281
248
|
break;
|
|
282
249
|
case nodes.NodeType.ClassSelector:
|
|
@@ -292,33 +259,33 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
292
259
|
result.addAttr(unescape(child.getText()), '');
|
|
293
260
|
break;
|
|
294
261
|
case nodes.NodeType.AttributeSelector:
|
|
295
|
-
|
|
296
|
-
|
|
262
|
+
const selector = child;
|
|
263
|
+
const identifier = selector.getIdentifier();
|
|
297
264
|
if (identifier) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
265
|
+
const expression = selector.getValue();
|
|
266
|
+
const operator = selector.getOperator();
|
|
267
|
+
let value;
|
|
301
268
|
if (expression && operator) {
|
|
302
269
|
switch (unescape(operator.getText())) {
|
|
303
270
|
case '|=':
|
|
304
271
|
// excatly or followed by -words
|
|
305
|
-
value =
|
|
272
|
+
value = `${quotes.remove(unescape(expression.getText()))}-\u2026`;
|
|
306
273
|
break;
|
|
307
274
|
case '^=':
|
|
308
275
|
// prefix
|
|
309
|
-
value =
|
|
276
|
+
value = `${quotes.remove(unescape(expression.getText()))}\u2026`;
|
|
310
277
|
break;
|
|
311
278
|
case '$=':
|
|
312
279
|
// suffix
|
|
313
|
-
value =
|
|
280
|
+
value = `\u2026${quotes.remove(unescape(expression.getText()))}`;
|
|
314
281
|
break;
|
|
315
282
|
case '~=':
|
|
316
283
|
// one of a list of words
|
|
317
|
-
value =
|
|
284
|
+
value = ` \u2026 ${quotes.remove(unescape(expression.getText()))} \u2026 `;
|
|
318
285
|
break;
|
|
319
286
|
case '*=':
|
|
320
287
|
// substring
|
|
321
|
-
value =
|
|
288
|
+
value = `\u2026${quotes.remove(unescape(expression.getText()))}\u2026`;
|
|
322
289
|
break;
|
|
323
290
|
default:
|
|
324
291
|
value = quotes.remove(unescape(expression.getText()));
|
|
@@ -334,49 +301,47 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
334
301
|
}
|
|
335
302
|
exports.toElement = toElement;
|
|
336
303
|
function unescape(content) {
|
|
337
|
-
|
|
304
|
+
const scanner = new cssScanner_1.Scanner();
|
|
338
305
|
scanner.setSource(content);
|
|
339
|
-
|
|
306
|
+
const token = scanner.scanUnquotedString();
|
|
340
307
|
if (token) {
|
|
341
308
|
return token.text;
|
|
342
309
|
}
|
|
343
310
|
return content;
|
|
344
311
|
}
|
|
345
|
-
|
|
346
|
-
|
|
312
|
+
class SelectorPrinting {
|
|
313
|
+
constructor(cssDataManager) {
|
|
347
314
|
this.cssDataManager = cssDataManager;
|
|
348
315
|
}
|
|
349
|
-
|
|
350
|
-
|
|
316
|
+
selectorToMarkedString(node) {
|
|
317
|
+
const root = selectorToElement(node);
|
|
351
318
|
if (root) {
|
|
352
|
-
|
|
319
|
+
const markedStrings = new MarkedStringPrinter('"').print(root);
|
|
353
320
|
markedStrings.push(this.selectorToSpecificityMarkedString(node));
|
|
354
321
|
return markedStrings;
|
|
355
322
|
}
|
|
356
323
|
else {
|
|
357
324
|
return [];
|
|
358
325
|
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
326
|
+
}
|
|
327
|
+
simpleSelectorToMarkedString(node) {
|
|
328
|
+
const element = toElement(node);
|
|
329
|
+
const markedStrings = new MarkedStringPrinter('"').print(element);
|
|
363
330
|
markedStrings.push(this.selectorToSpecificityMarkedString(node));
|
|
364
331
|
return markedStrings;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
332
|
+
}
|
|
333
|
+
isPseudoElementIdentifier(text) {
|
|
334
|
+
const match = text.match(/^::?([\w-]+)/);
|
|
368
335
|
if (!match) {
|
|
369
336
|
return false;
|
|
370
337
|
}
|
|
371
338
|
return !!this.cssDataManager.getPseudoElement("::" + match[1]);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
var _this = this;
|
|
339
|
+
}
|
|
340
|
+
selectorToSpecificityMarkedString(node) {
|
|
375
341
|
//https://www.w3.org/TR/selectors-3/#specificity
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
elementLoop: for (
|
|
379
|
-
var element = _a[_i];
|
|
342
|
+
const calculateScore = (node) => {
|
|
343
|
+
const specificity = new Specificity();
|
|
344
|
+
elementLoop: for (const element of node.getChildren()) {
|
|
380
345
|
switch (element.type) {
|
|
381
346
|
case nodes.NodeType.IdentifierSelector:
|
|
382
347
|
specificity.id++;
|
|
@@ -393,8 +358,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
393
358
|
specificity.tag++;
|
|
394
359
|
break;
|
|
395
360
|
case nodes.NodeType.PseudoSelector:
|
|
396
|
-
|
|
397
|
-
if (
|
|
361
|
+
const text = element.getText();
|
|
362
|
+
if (this.isPseudoElementIdentifier(text)) {
|
|
398
363
|
specificity.tag++; // pseudo element
|
|
399
364
|
continue elementLoop;
|
|
400
365
|
}
|
|
@@ -404,19 +369,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
404
369
|
}
|
|
405
370
|
// the most specific child selector
|
|
406
371
|
if (text.match(/^:(not|has|is)/i) && element.getChildren().length > 0) {
|
|
407
|
-
|
|
408
|
-
for (
|
|
409
|
-
|
|
410
|
-
var list = void 0;
|
|
372
|
+
let mostSpecificListItem = new Specificity();
|
|
373
|
+
for (const containerElement of element.getChildren()) {
|
|
374
|
+
let list;
|
|
411
375
|
if (containerElement.type === nodes.NodeType.Undefined) { // containerElement is a list of selectors
|
|
412
376
|
list = containerElement.getChildren();
|
|
413
377
|
}
|
|
414
378
|
else { // containerElement is a selector
|
|
415
379
|
list = [containerElement];
|
|
416
380
|
}
|
|
417
|
-
for (
|
|
418
|
-
|
|
419
|
-
var itemSpecificity = calculateScore(childElement);
|
|
381
|
+
for (const childElement of containerElement.getChildren()) {
|
|
382
|
+
const itemSpecificity = calculateScore(childElement);
|
|
420
383
|
if (itemSpecificity.id > mostSpecificListItem.id) {
|
|
421
384
|
mostSpecificListItem = itemSpecificity;
|
|
422
385
|
continue;
|
|
@@ -446,7 +409,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
446
409
|
continue elementLoop;
|
|
447
410
|
}
|
|
448
411
|
if (element.getChildren().length > 0) {
|
|
449
|
-
|
|
412
|
+
const itemSpecificity = calculateScore(element);
|
|
450
413
|
specificity.id += itemSpecificity.id;
|
|
451
414
|
specificity.attr += itemSpecificity.attr;
|
|
452
415
|
specificity.tag += itemSpecificity.tag;
|
|
@@ -454,23 +417,22 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
454
417
|
}
|
|
455
418
|
return specificity;
|
|
456
419
|
};
|
|
457
|
-
|
|
420
|
+
const specificity = calculateScore(node);
|
|
458
421
|
;
|
|
459
422
|
return localize('specificity', "[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): ({0}, {1}, {2})", specificity.id, specificity.attr, specificity.tag);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
}());
|
|
423
|
+
}
|
|
424
|
+
}
|
|
463
425
|
exports.SelectorPrinting = SelectorPrinting;
|
|
464
|
-
|
|
465
|
-
|
|
426
|
+
class SelectorElementBuilder {
|
|
427
|
+
constructor(element) {
|
|
466
428
|
this.prev = null;
|
|
467
429
|
this.element = element;
|
|
468
430
|
}
|
|
469
|
-
|
|
470
|
-
|
|
431
|
+
processSelector(selector) {
|
|
432
|
+
let parentElement = null;
|
|
471
433
|
if (!(this.element instanceof RootElement)) {
|
|
472
|
-
if (selector.getChildren().some(
|
|
473
|
-
|
|
434
|
+
if (selector.getChildren().some((c) => c.hasChildren() && c.getChild(0).type === nodes.NodeType.SelectorCombinator)) {
|
|
435
|
+
const curr = this.element.findRoot();
|
|
474
436
|
if (curr.parent instanceof RootElement) {
|
|
475
437
|
parentElement = this.element;
|
|
476
438
|
this.element = curr.parent;
|
|
@@ -479,11 +441,10 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
479
441
|
}
|
|
480
442
|
}
|
|
481
443
|
}
|
|
482
|
-
for (
|
|
483
|
-
var selectorChild = _a[_i];
|
|
444
|
+
for (const selectorChild of selector.getChildren()) {
|
|
484
445
|
if (selectorChild instanceof nodes.SimpleSelector) {
|
|
485
446
|
if (this.prev instanceof nodes.SimpleSelector) {
|
|
486
|
-
|
|
447
|
+
const labelElement = new LabelElement('\u2026');
|
|
487
448
|
this.element.addChild(labelElement);
|
|
488
449
|
this.element = labelElement;
|
|
489
450
|
}
|
|
@@ -493,8 +454,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
493
454
|
if (this.prev && this.prev.matches('~')) {
|
|
494
455
|
this.element.addChild(new LabelElement('\u22EE'));
|
|
495
456
|
}
|
|
496
|
-
|
|
497
|
-
|
|
457
|
+
const thisElement = toElement(selectorChild, parentElement);
|
|
458
|
+
const root = thisElement.findRoot();
|
|
498
459
|
this.element.addChild(root);
|
|
499
460
|
this.element = thisElement;
|
|
500
461
|
}
|
|
@@ -506,9 +467,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
506
467
|
this.prev = selectorChild;
|
|
507
468
|
}
|
|
508
469
|
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
}());
|
|
470
|
+
}
|
|
471
|
+
}
|
|
512
472
|
function isNewSelectorContext(node) {
|
|
513
473
|
switch (node.type) {
|
|
514
474
|
case nodes.NodeType.MixinDeclaration:
|
|
@@ -521,11 +481,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
521
481
|
if (node.matches('@at-root')) {
|
|
522
482
|
return null;
|
|
523
483
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
484
|
+
const root = new RootElement();
|
|
485
|
+
const parentRuleSets = [];
|
|
486
|
+
const ruleSet = node.getParent();
|
|
527
487
|
if (ruleSet instanceof nodes.RuleSet) {
|
|
528
|
-
|
|
488
|
+
let parent = ruleSet.getParent(); // parent of the selector's ruleset
|
|
529
489
|
while (parent && !isNewSelectorContext(parent)) {
|
|
530
490
|
if (parent instanceof nodes.RuleSet) {
|
|
531
491
|
if (parent.getSelectors().matches('@at-root')) {
|
|
@@ -536,9 +496,9 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
536
496
|
parent = parent.getParent();
|
|
537
497
|
}
|
|
538
498
|
}
|
|
539
|
-
|
|
540
|
-
for (
|
|
541
|
-
|
|
499
|
+
const builder = new SelectorElementBuilder(root);
|
|
500
|
+
for (let i = parentRuleSets.length - 1; i >= 0; i--) {
|
|
501
|
+
const selector = parentRuleSets[i].getSelectors().getChild(0);
|
|
542
502
|
if (selector) {
|
|
543
503
|
builder.processSelector(selector);
|
|
544
504
|
}
|
package/lib/umd/utils/arrays.js
CHANGED
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
* @returns the least x for which p(x) is true or array.length if no element fullfills the given function.
|
|
21
21
|
*/
|
|
22
22
|
function findFirst(array, p) {
|
|
23
|
-
|
|
23
|
+
let low = 0, high = array.length;
|
|
24
24
|
if (high === 0) {
|
|
25
25
|
return 0; // no children
|
|
26
26
|
}
|
|
27
27
|
while (low < high) {
|
|
28
|
-
|
|
28
|
+
let mid = Math.floor((low + high) / 2);
|
|
29
29
|
if (p(array[mid])) {
|
|
30
30
|
high = mid;
|
|
31
31
|
}
|
|
@@ -40,16 +40,10 @@
|
|
|
40
40
|
return array.indexOf(item) !== -1;
|
|
41
41
|
}
|
|
42
42
|
exports.includes = includes;
|
|
43
|
-
function union() {
|
|
44
|
-
|
|
45
|
-
for (
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
var result = [];
|
|
49
|
-
for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
|
|
50
|
-
var array = arrays_1[_a];
|
|
51
|
-
for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
|
|
52
|
-
var item = array_1[_b];
|
|
43
|
+
function union(...arrays) {
|
|
44
|
+
const result = [];
|
|
45
|
+
for (const array of arrays) {
|
|
46
|
+
for (const item of array) {
|
|
53
47
|
if (!includes(result, item)) {
|
|
54
48
|
result.push(item);
|
|
55
49
|
}
|
package/lib/umd/utils/objects.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.isDefined = exports.values = void 0;
|
|
17
17
|
function values(obj) {
|
|
18
|
-
return Object.keys(obj).map(
|
|
18
|
+
return Object.keys(obj).map(key => obj[key]);
|
|
19
19
|
}
|
|
20
20
|
exports.values = values;
|
|
21
21
|
function isDefined(obj) {
|