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
|
@@ -3,21 +3,6 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
'use strict';
|
|
6
|
-
var __extends = (this && this.__extends) || (function () {
|
|
7
|
-
var extendStatics = function (d, b) {
|
|
8
|
-
extendStatics = Object.setPrototypeOf ||
|
|
9
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
11
|
-
return extendStatics(d, b);
|
|
12
|
-
};
|
|
13
|
-
return function (d, b) {
|
|
14
|
-
if (typeof b !== "function" && b !== null)
|
|
15
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
-
extendStatics(d, b);
|
|
17
|
-
function __() { this.constructor = d; }
|
|
18
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
19
|
-
};
|
|
20
|
-
})();
|
|
21
6
|
import * as scssScanner from './scssScanner';
|
|
22
7
|
import { TokenType } from './cssScanner';
|
|
23
8
|
import * as cssParser from './cssParser';
|
|
@@ -28,13 +13,11 @@ import { ParseError } from './cssErrors';
|
|
|
28
13
|
/// A parser for scss
|
|
29
14
|
/// http://sass-lang.com/documentation/file.SASS_REFERENCE.html
|
|
30
15
|
/// </summary>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return _super.call(this, new scssScanner.SCSSScanner()) || this;
|
|
16
|
+
export class SCSSParser extends cssParser.Parser {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(new scssScanner.SCSSScanner());
|
|
35
19
|
}
|
|
36
|
-
|
|
37
|
-
if (isNested === void 0) { isNested = false; }
|
|
20
|
+
_parseStylesheetStatement(isNested = false) {
|
|
38
21
|
if (this.peek(TokenType.AtKeyword)) {
|
|
39
22
|
return this._parseWarnAndDebug() // @warn, @debug and @error statements
|
|
40
23
|
|| this._parseControlStatement() // @if, @while, @for, @each
|
|
@@ -45,15 +28,15 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
45
28
|
|| this._parseForward() // @forward
|
|
46
29
|
|| this._parseUse() // @use
|
|
47
30
|
|| this._parseRuleset(isNested) // @at-rule
|
|
48
|
-
||
|
|
31
|
+
|| super._parseStylesheetAtStatement(isNested);
|
|
49
32
|
}
|
|
50
33
|
return this._parseRuleset(true) || this._parseVariableDeclaration();
|
|
51
|
-
}
|
|
52
|
-
|
|
34
|
+
}
|
|
35
|
+
_parseImport() {
|
|
53
36
|
if (!this.peekKeyword('@import')) {
|
|
54
37
|
return null;
|
|
55
38
|
}
|
|
56
|
-
|
|
39
|
+
const node = this.create(nodes.Import);
|
|
57
40
|
this.consumeToken();
|
|
58
41
|
if (!node.addChild(this._parseURILiteral()) && !node.addChild(this._parseStringLiteral())) {
|
|
59
42
|
return this.finish(node, ParseError.URIOrStringExpected);
|
|
@@ -67,14 +50,13 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
67
50
|
node.setMedialist(this._parseMediaQueryList());
|
|
68
51
|
}
|
|
69
52
|
return this.finish(node);
|
|
70
|
-
}
|
|
53
|
+
}
|
|
71
54
|
// scss variables: $font-size: 12px;
|
|
72
|
-
|
|
73
|
-
if (panic === void 0) { panic = []; }
|
|
55
|
+
_parseVariableDeclaration(panic = []) {
|
|
74
56
|
if (!this.peek(scssScanner.VariableName)) {
|
|
75
57
|
return null;
|
|
76
58
|
}
|
|
77
|
-
|
|
59
|
+
const node = this.create(nodes.VariableDeclaration);
|
|
78
60
|
if (!node.setVariable(this._parseVariable())) {
|
|
79
61
|
return null;
|
|
80
62
|
}
|
|
@@ -103,33 +85,33 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
103
85
|
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
104
86
|
}
|
|
105
87
|
return this.finish(node);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return this._parseInterpolation() ||
|
|
109
|
-
}
|
|
110
|
-
|
|
88
|
+
}
|
|
89
|
+
_parseMediaCondition() {
|
|
90
|
+
return this._parseInterpolation() || super._parseMediaCondition();
|
|
91
|
+
}
|
|
92
|
+
_parseMediaFeatureName() {
|
|
111
93
|
return this._parseModuleMember()
|
|
112
94
|
|| this._parseFunction() // function before ident
|
|
113
95
|
|| this._parseIdent()
|
|
114
96
|
|| this._parseVariable();
|
|
115
|
-
}
|
|
116
|
-
|
|
97
|
+
}
|
|
98
|
+
_parseKeyframeSelector() {
|
|
117
99
|
return this._tryParseKeyframeSelector()
|
|
118
100
|
|| this._parseControlStatement(this._parseKeyframeSelector.bind(this))
|
|
119
101
|
|| this._parseVariableDeclaration()
|
|
120
102
|
|| this._parseMixinContent();
|
|
121
|
-
}
|
|
122
|
-
|
|
103
|
+
}
|
|
104
|
+
_parseVariable() {
|
|
123
105
|
if (!this.peek(scssScanner.VariableName)) {
|
|
124
106
|
return null;
|
|
125
107
|
}
|
|
126
|
-
|
|
108
|
+
const node = this.create(nodes.Variable);
|
|
127
109
|
this.consumeToken();
|
|
128
110
|
return node;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
}
|
|
112
|
+
_parseModuleMember() {
|
|
113
|
+
const pos = this.mark();
|
|
114
|
+
const node = this.create(nodes.Module);
|
|
133
115
|
if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Module]))) {
|
|
134
116
|
return null;
|
|
135
117
|
}
|
|
@@ -143,28 +125,27 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
143
125
|
return this.finish(node, ParseError.IdentifierOrVariableExpected);
|
|
144
126
|
}
|
|
145
127
|
return node;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
var _this = this;
|
|
128
|
+
}
|
|
129
|
+
_parseIdent(referenceTypes) {
|
|
149
130
|
if (!this.peek(TokenType.Ident) && !this.peek(scssScanner.InterpolationFunction) && !this.peekDelim('-')) {
|
|
150
131
|
return null;
|
|
151
132
|
}
|
|
152
|
-
|
|
133
|
+
const node = this.create(nodes.Identifier);
|
|
153
134
|
node.referenceTypes = referenceTypes;
|
|
154
135
|
node.isCustomProperty = this.peekRegExp(TokenType.Ident, /^--/);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
if (!
|
|
160
|
-
|
|
136
|
+
let hasContent = false;
|
|
137
|
+
const indentInterpolation = () => {
|
|
138
|
+
const pos = this.mark();
|
|
139
|
+
if (this.acceptDelim('-')) {
|
|
140
|
+
if (!this.hasWhitespace()) {
|
|
141
|
+
this.acceptDelim('-');
|
|
161
142
|
}
|
|
162
|
-
if (
|
|
163
|
-
|
|
143
|
+
if (this.hasWhitespace()) {
|
|
144
|
+
this.restoreAtMark(pos);
|
|
164
145
|
return null;
|
|
165
146
|
}
|
|
166
147
|
}
|
|
167
|
-
return
|
|
148
|
+
return this._parseInterpolation();
|
|
168
149
|
};
|
|
169
150
|
while (this.accept(TokenType.Ident) || node.addChild(indentInterpolation()) || (hasContent && this.acceptRegexp(/^[\w-]/))) {
|
|
170
151
|
hasContent = true;
|
|
@@ -173,17 +154,17 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
173
154
|
}
|
|
174
155
|
}
|
|
175
156
|
return hasContent ? this.finish(node) : null;
|
|
176
|
-
}
|
|
177
|
-
|
|
157
|
+
}
|
|
158
|
+
_parseTermExpression() {
|
|
178
159
|
return this._parseModuleMember() ||
|
|
179
160
|
this._parseVariable() ||
|
|
180
161
|
this._parseSelectorCombinator() ||
|
|
181
162
|
//this._tryParsePrio() ||
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
163
|
+
super._parseTermExpression();
|
|
164
|
+
}
|
|
165
|
+
_parseInterpolation() {
|
|
185
166
|
if (this.peek(scssScanner.InterpolationFunction)) {
|
|
186
|
-
|
|
167
|
+
const node = this.create(nodes.Interpolation);
|
|
187
168
|
this.consumeToken();
|
|
188
169
|
if (!node.addChild(this._parseExpr()) && !this._parseSelectorCombinator()) {
|
|
189
170
|
if (this.accept(TokenType.CurlyR)) {
|
|
@@ -197,28 +178,28 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
197
178
|
return this.finish(node);
|
|
198
179
|
}
|
|
199
180
|
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
181
|
+
}
|
|
182
|
+
_parseOperator() {
|
|
202
183
|
if (this.peek(scssScanner.EqualsOperator) || this.peek(scssScanner.NotEqualsOperator)
|
|
203
184
|
|| this.peek(scssScanner.GreaterEqualsOperator) || this.peek(scssScanner.SmallerEqualsOperator)
|
|
204
185
|
|| this.peekDelim('>') || this.peekDelim('<')
|
|
205
186
|
|| this.peekIdent('and') || this.peekIdent('or')
|
|
206
187
|
|| this.peekDelim('%')) {
|
|
207
|
-
|
|
188
|
+
const node = this.createNode(nodes.NodeType.Operator);
|
|
208
189
|
this.consumeToken();
|
|
209
190
|
return this.finish(node);
|
|
210
191
|
}
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
|
|
192
|
+
return super._parseOperator();
|
|
193
|
+
}
|
|
194
|
+
_parseUnaryOperator() {
|
|
214
195
|
if (this.peekIdent('not')) {
|
|
215
|
-
|
|
196
|
+
const node = this.create(nodes.Node);
|
|
216
197
|
this.consumeToken();
|
|
217
198
|
return this.finish(node);
|
|
218
199
|
}
|
|
219
|
-
return
|
|
220
|
-
}
|
|
221
|
-
|
|
200
|
+
return super._parseUnaryOperator();
|
|
201
|
+
}
|
|
202
|
+
_parseRuleSetDeclaration() {
|
|
222
203
|
if (this.peek(TokenType.AtKeyword)) {
|
|
223
204
|
return this._parseKeyframe() // nested @keyframe
|
|
224
205
|
|| this._parseImport() // nested @import
|
|
@@ -233,18 +214,19 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
233
214
|
|| this._parseMixinDeclaration() // nested @mixin
|
|
234
215
|
|| this._parseRuleset(true) // @at-rule
|
|
235
216
|
|| this._parseSupports(true) // @supports
|
|
236
|
-
||
|
|
217
|
+
|| this._parseLayer() // @layer
|
|
218
|
+
|| super._parseRuleSetDeclarationAtStatement();
|
|
237
219
|
}
|
|
238
220
|
return this._parseVariableDeclaration() // variable declaration
|
|
239
221
|
|| this._tryParseRuleset(true) // nested ruleset
|
|
240
|
-
||
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
222
|
+
|| super._parseRuleSetDeclaration(); // try css ruleset declaration as last so in the error case, the ast will contain a declaration
|
|
223
|
+
}
|
|
224
|
+
_parseDeclaration(stopTokens) {
|
|
225
|
+
const custonProperty = this._tryParseCustomPropertyDeclaration(stopTokens);
|
|
244
226
|
if (custonProperty) {
|
|
245
227
|
return custonProperty;
|
|
246
228
|
}
|
|
247
|
-
|
|
229
|
+
const node = this.create(nodes.Declaration);
|
|
248
230
|
if (!node.setProperty(this._parseProperty())) {
|
|
249
231
|
return null;
|
|
250
232
|
}
|
|
@@ -254,7 +236,7 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
254
236
|
if (this.prevToken) {
|
|
255
237
|
node.colonPosition = this.prevToken.offset;
|
|
256
238
|
}
|
|
257
|
-
|
|
239
|
+
let hasContent = false;
|
|
258
240
|
if (node.setValue(this._parseExpr())) {
|
|
259
241
|
hasContent = true;
|
|
260
242
|
node.addChild(this._parsePrio());
|
|
@@ -271,14 +253,14 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
271
253
|
node.semicolonPosition = this.token.offset; // not part of the declaration, but useful information for code assist
|
|
272
254
|
}
|
|
273
255
|
return this.finish(node);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
256
|
+
}
|
|
257
|
+
_parseNestedProperties() {
|
|
258
|
+
const node = this.create(nodes.NestedProperties);
|
|
277
259
|
return this._parseBody(node, this._parseDeclaration.bind(this));
|
|
278
|
-
}
|
|
279
|
-
|
|
260
|
+
}
|
|
261
|
+
_parseExtends() {
|
|
280
262
|
if (this.peekKeyword('@extend')) {
|
|
281
|
-
|
|
263
|
+
const node = this.create(nodes.ExtendsReference);
|
|
282
264
|
this.consumeToken();
|
|
283
265
|
if (!node.getSelectors().addChild(this._parseSimpleSelector())) {
|
|
284
266
|
return this.finish(node, ParseError.SelectorExpected);
|
|
@@ -294,13 +276,13 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
294
276
|
return this.finish(node);
|
|
295
277
|
}
|
|
296
278
|
return null;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return this._parseSelectorCombinator() || this._parseSelectorPlaceholder() ||
|
|
300
|
-
}
|
|
301
|
-
|
|
279
|
+
}
|
|
280
|
+
_parseSimpleSelectorBody() {
|
|
281
|
+
return this._parseSelectorCombinator() || this._parseSelectorPlaceholder() || super._parseSimpleSelectorBody();
|
|
282
|
+
}
|
|
283
|
+
_parseSelectorCombinator() {
|
|
302
284
|
if (this.peekDelim('&')) {
|
|
303
|
-
|
|
285
|
+
const node = this.createNode(nodes.NodeType.SelectorCombinator);
|
|
304
286
|
this.consumeToken();
|
|
305
287
|
while (!this.hasWhitespace() && (this.acceptDelim('-') || this.accept(TokenType.Num) || this.accept(TokenType.Dimension) || node.addChild(this._parseIdent()) || this.acceptDelim('&'))) {
|
|
306
288
|
// support &-foo-1
|
|
@@ -308,60 +290,73 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
308
290
|
return this.finish(node);
|
|
309
291
|
}
|
|
310
292
|
return null;
|
|
311
|
-
}
|
|
312
|
-
|
|
293
|
+
}
|
|
294
|
+
_parseSelectorPlaceholder() {
|
|
313
295
|
if (this.peekDelim('%')) {
|
|
314
|
-
|
|
296
|
+
const node = this.createNode(nodes.NodeType.SelectorPlaceholder);
|
|
315
297
|
this.consumeToken();
|
|
316
298
|
this._parseIdent();
|
|
317
299
|
return this.finish(node);
|
|
318
300
|
}
|
|
319
301
|
else if (this.peekKeyword('@at-root')) {
|
|
320
|
-
|
|
302
|
+
const node = this.createNode(nodes.NodeType.SelectorPlaceholder);
|
|
321
303
|
this.consumeToken();
|
|
304
|
+
if (this.accept(TokenType.ParenthesisL)) {
|
|
305
|
+
if (!this.acceptIdent('with') && !this.acceptIdent('without')) {
|
|
306
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
307
|
+
}
|
|
308
|
+
if (!this.accept(TokenType.Colon)) {
|
|
309
|
+
return this.finish(node, ParseError.ColonExpected);
|
|
310
|
+
}
|
|
311
|
+
if (!node.addChild(this._parseIdent())) {
|
|
312
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
313
|
+
}
|
|
314
|
+
if (!this.accept(TokenType.ParenthesisR)) {
|
|
315
|
+
return this.finish(node, ParseError.RightParenthesisExpected, [TokenType.CurlyR]);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
322
318
|
return this.finish(node);
|
|
323
319
|
}
|
|
324
320
|
return null;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
321
|
+
}
|
|
322
|
+
_parseElementName() {
|
|
323
|
+
const pos = this.mark();
|
|
324
|
+
const node = super._parseElementName();
|
|
329
325
|
if (node && !this.hasWhitespace() && this.peek(TokenType.ParenthesisL)) { // for #49589
|
|
330
326
|
this.restoreAtMark(pos);
|
|
331
327
|
return null;
|
|
332
328
|
}
|
|
333
329
|
return node;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return this._parseInterpolation() ||
|
|
337
|
-
}
|
|
338
|
-
|
|
330
|
+
}
|
|
331
|
+
_tryParsePseudoIdentifier() {
|
|
332
|
+
return this._parseInterpolation() || super._tryParsePseudoIdentifier(); // for #49589
|
|
333
|
+
}
|
|
334
|
+
_parseWarnAndDebug() {
|
|
339
335
|
if (!this.peekKeyword('@debug')
|
|
340
336
|
&& !this.peekKeyword('@warn')
|
|
341
337
|
&& !this.peekKeyword('@error')) {
|
|
342
338
|
return null;
|
|
343
339
|
}
|
|
344
|
-
|
|
340
|
+
const node = this.createNode(nodes.NodeType.Debug);
|
|
345
341
|
this.consumeToken(); // @debug, @warn or @error
|
|
346
342
|
node.addChild(this._parseExpr()); // optional
|
|
347
343
|
return this.finish(node);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (parseStatement === void 0) { parseStatement = this._parseRuleSetDeclaration.bind(this); }
|
|
344
|
+
}
|
|
345
|
+
_parseControlStatement(parseStatement = this._parseRuleSetDeclaration.bind(this)) {
|
|
351
346
|
if (!this.peek(TokenType.AtKeyword)) {
|
|
352
347
|
return null;
|
|
353
348
|
}
|
|
354
349
|
return this._parseIfStatement(parseStatement) || this._parseForStatement(parseStatement)
|
|
355
350
|
|| this._parseEachStatement(parseStatement) || this._parseWhileStatement(parseStatement);
|
|
356
|
-
}
|
|
357
|
-
|
|
351
|
+
}
|
|
352
|
+
_parseIfStatement(parseStatement) {
|
|
358
353
|
if (!this.peekKeyword('@if')) {
|
|
359
354
|
return null;
|
|
360
355
|
}
|
|
361
356
|
return this._internalParseIfStatement(parseStatement);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
357
|
+
}
|
|
358
|
+
_internalParseIfStatement(parseStatement) {
|
|
359
|
+
const node = this.create(nodes.IfStatement);
|
|
365
360
|
this.consumeToken(); // @if or if
|
|
366
361
|
if (!node.setExpression(this._parseExpr(true))) {
|
|
367
362
|
return this.finish(node, ParseError.ExpressionExpected);
|
|
@@ -372,18 +367,18 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
372
367
|
node.setElseClause(this._internalParseIfStatement(parseStatement));
|
|
373
368
|
}
|
|
374
369
|
else if (this.peek(TokenType.CurlyL)) {
|
|
375
|
-
|
|
370
|
+
const elseNode = this.create(nodes.ElseStatement);
|
|
376
371
|
this._parseBody(elseNode, parseStatement);
|
|
377
372
|
node.setElseClause(elseNode);
|
|
378
373
|
}
|
|
379
374
|
}
|
|
380
375
|
return this.finish(node);
|
|
381
|
-
}
|
|
382
|
-
|
|
376
|
+
}
|
|
377
|
+
_parseForStatement(parseStatement) {
|
|
383
378
|
if (!this.peekKeyword('@for')) {
|
|
384
379
|
return null;
|
|
385
380
|
}
|
|
386
|
-
|
|
381
|
+
const node = this.create(nodes.ForStatement);
|
|
387
382
|
this.consumeToken(); // @for
|
|
388
383
|
if (!node.setVariable(this._parseVariable())) {
|
|
389
384
|
return this.finish(node, ParseError.VariableNameExpected, [TokenType.CurlyR]);
|
|
@@ -401,14 +396,14 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
401
396
|
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
402
397
|
}
|
|
403
398
|
return this._parseBody(node, parseStatement);
|
|
404
|
-
}
|
|
405
|
-
|
|
399
|
+
}
|
|
400
|
+
_parseEachStatement(parseStatement) {
|
|
406
401
|
if (!this.peekKeyword('@each')) {
|
|
407
402
|
return null;
|
|
408
403
|
}
|
|
409
|
-
|
|
404
|
+
const node = this.create(nodes.EachStatement);
|
|
410
405
|
this.consumeToken(); // @each
|
|
411
|
-
|
|
406
|
+
const variables = node.getVariables();
|
|
412
407
|
if (!variables.addChild(this._parseVariable())) {
|
|
413
408
|
return this.finish(node, ParseError.VariableNameExpected, [TokenType.CurlyR]);
|
|
414
409
|
}
|
|
@@ -425,27 +420,27 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
425
420
|
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
426
421
|
}
|
|
427
422
|
return this._parseBody(node, parseStatement);
|
|
428
|
-
}
|
|
429
|
-
|
|
423
|
+
}
|
|
424
|
+
_parseWhileStatement(parseStatement) {
|
|
430
425
|
if (!this.peekKeyword('@while')) {
|
|
431
426
|
return null;
|
|
432
427
|
}
|
|
433
|
-
|
|
428
|
+
const node = this.create(nodes.WhileStatement);
|
|
434
429
|
this.consumeToken(); // @while
|
|
435
430
|
if (!node.addChild(this._parseBinaryExpr())) {
|
|
436
431
|
return this.finish(node, ParseError.ExpressionExpected, [TokenType.CurlyR]);
|
|
437
432
|
}
|
|
438
433
|
return this._parseBody(node, parseStatement);
|
|
439
|
-
}
|
|
440
|
-
|
|
434
|
+
}
|
|
435
|
+
_parseFunctionBodyDeclaration() {
|
|
441
436
|
return this._parseVariableDeclaration() || this._parseReturnStatement() || this._parseWarnAndDebug()
|
|
442
437
|
|| this._parseControlStatement(this._parseFunctionBodyDeclaration.bind(this));
|
|
443
|
-
}
|
|
444
|
-
|
|
438
|
+
}
|
|
439
|
+
_parseFunctionDeclaration() {
|
|
445
440
|
if (!this.peekKeyword('@function')) {
|
|
446
441
|
return null;
|
|
447
442
|
}
|
|
448
|
-
|
|
443
|
+
const node = this.create(nodes.FunctionDeclaration);
|
|
449
444
|
this.consumeToken(); // @function
|
|
450
445
|
if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Function]))) {
|
|
451
446
|
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
@@ -467,23 +462,23 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
467
462
|
return this.finish(node, ParseError.RightParenthesisExpected, [TokenType.CurlyR]);
|
|
468
463
|
}
|
|
469
464
|
return this._parseBody(node, this._parseFunctionBodyDeclaration.bind(this));
|
|
470
|
-
}
|
|
471
|
-
|
|
465
|
+
}
|
|
466
|
+
_parseReturnStatement() {
|
|
472
467
|
if (!this.peekKeyword('@return')) {
|
|
473
468
|
return null;
|
|
474
469
|
}
|
|
475
|
-
|
|
470
|
+
const node = this.createNode(nodes.NodeType.ReturnStatement);
|
|
476
471
|
this.consumeToken(); // @function
|
|
477
472
|
if (!node.addChild(this._parseExpr())) {
|
|
478
473
|
return this.finish(node, ParseError.ExpressionExpected);
|
|
479
474
|
}
|
|
480
475
|
return this.finish(node);
|
|
481
|
-
}
|
|
482
|
-
|
|
476
|
+
}
|
|
477
|
+
_parseMixinDeclaration() {
|
|
483
478
|
if (!this.peekKeyword('@mixin')) {
|
|
484
479
|
return null;
|
|
485
480
|
}
|
|
486
|
-
|
|
481
|
+
const node = this.create(nodes.MixinDeclaration);
|
|
487
482
|
this.consumeToken();
|
|
488
483
|
if (!node.setIdentifier(this._parseIdent([nodes.ReferenceType.Mixin]))) {
|
|
489
484
|
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
@@ -504,9 +499,9 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
504
499
|
}
|
|
505
500
|
}
|
|
506
501
|
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
502
|
+
}
|
|
503
|
+
_parseParameterDeclaration() {
|
|
504
|
+
const node = this.create(nodes.FunctionParameter);
|
|
510
505
|
if (!node.setIdentifier(this._parseVariable())) {
|
|
511
506
|
return null;
|
|
512
507
|
}
|
|
@@ -519,12 +514,12 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
519
514
|
}
|
|
520
515
|
}
|
|
521
516
|
return this.finish(node);
|
|
522
|
-
}
|
|
523
|
-
|
|
517
|
+
}
|
|
518
|
+
_parseMixinContent() {
|
|
524
519
|
if (!this.peekKeyword('@content')) {
|
|
525
520
|
return null;
|
|
526
521
|
}
|
|
527
|
-
|
|
522
|
+
const node = this.create(nodes.MixinContentReference);
|
|
528
523
|
this.consumeToken();
|
|
529
524
|
if (this.accept(TokenType.ParenthesisL)) {
|
|
530
525
|
if (node.getArguments().addChild(this._parseFunctionArgument())) {
|
|
@@ -542,25 +537,25 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
542
537
|
}
|
|
543
538
|
}
|
|
544
539
|
return this.finish(node);
|
|
545
|
-
}
|
|
546
|
-
|
|
540
|
+
}
|
|
541
|
+
_parseMixinReference() {
|
|
547
542
|
if (!this.peekKeyword('@include')) {
|
|
548
543
|
return null;
|
|
549
544
|
}
|
|
550
|
-
|
|
545
|
+
const node = this.create(nodes.MixinReference);
|
|
551
546
|
this.consumeToken();
|
|
552
547
|
// Could be module or mixin identifier, set as mixin as default.
|
|
553
|
-
|
|
548
|
+
const firstIdent = this._parseIdent([nodes.ReferenceType.Mixin]);
|
|
554
549
|
if (!node.setIdentifier(firstIdent)) {
|
|
555
550
|
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
556
551
|
}
|
|
557
552
|
// Is a module accessor.
|
|
558
553
|
if (!this.hasWhitespace() && this.acceptDelim('.') && !this.hasWhitespace()) {
|
|
559
|
-
|
|
554
|
+
const secondIdent = this._parseIdent([nodes.ReferenceType.Mixin]);
|
|
560
555
|
if (!secondIdent) {
|
|
561
556
|
return this.finish(node, ParseError.IdentifierExpected, [TokenType.CurlyR]);
|
|
562
557
|
}
|
|
563
|
-
|
|
558
|
+
const moduleToken = this.create(nodes.Module);
|
|
564
559
|
// Re-purpose first matched ident as identifier for module token.
|
|
565
560
|
firstIdent.referenceTypes = [nodes.ReferenceType.Module];
|
|
566
561
|
moduleToken.setIdentifier(firstIdent);
|
|
@@ -587,9 +582,9 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
587
582
|
node.setContent(this._parseMixinContentDeclaration());
|
|
588
583
|
}
|
|
589
584
|
return this.finish(node);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
|
|
585
|
+
}
|
|
586
|
+
_parseMixinContentDeclaration() {
|
|
587
|
+
const node = this.create(nodes.MixinContentDeclaration);
|
|
593
588
|
if (this.acceptIdent('using')) {
|
|
594
589
|
if (!this.accept(TokenType.ParenthesisL)) {
|
|
595
590
|
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.CurlyL]);
|
|
@@ -612,15 +607,15 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
612
607
|
this._parseBody(node, this._parseMixinReferenceBodyStatement.bind(this));
|
|
613
608
|
}
|
|
614
609
|
return this.finish(node);
|
|
615
|
-
}
|
|
616
|
-
|
|
610
|
+
}
|
|
611
|
+
_parseMixinReferenceBodyStatement() {
|
|
617
612
|
return this._tryParseKeyframeSelector() || this._parseRuleSetDeclaration();
|
|
618
|
-
}
|
|
619
|
-
|
|
613
|
+
}
|
|
614
|
+
_parseFunctionArgument() {
|
|
620
615
|
// [variableName ':'] expression | variableName '...'
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
616
|
+
const node = this.create(nodes.FunctionArgument);
|
|
617
|
+
const pos = this.mark();
|
|
618
|
+
const argument = this._parseVariable();
|
|
624
619
|
if (argument) {
|
|
625
620
|
if (!this.accept(TokenType.Colon)) {
|
|
626
621
|
if (this.accept(scssScanner.Ellipsis)) { // optional
|
|
@@ -644,23 +639,23 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
644
639
|
return this.finish(node);
|
|
645
640
|
}
|
|
646
641
|
return null;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
642
|
+
}
|
|
643
|
+
_parseURLArgument() {
|
|
644
|
+
const pos = this.mark();
|
|
645
|
+
const node = super._parseURLArgument();
|
|
651
646
|
if (!node || !this.peek(TokenType.ParenthesisR)) {
|
|
652
647
|
this.restoreAtMark(pos);
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
return this.finish(
|
|
648
|
+
const node = this.create(nodes.Node);
|
|
649
|
+
node.addChild(this._parseBinaryExpr());
|
|
650
|
+
return this.finish(node);
|
|
656
651
|
}
|
|
657
652
|
return node;
|
|
658
|
-
}
|
|
659
|
-
|
|
653
|
+
}
|
|
654
|
+
_parseOperation() {
|
|
660
655
|
if (!this.peek(TokenType.ParenthesisL)) {
|
|
661
656
|
return null;
|
|
662
657
|
}
|
|
663
|
-
|
|
658
|
+
const node = this.create(nodes.Node);
|
|
664
659
|
this.consumeToken();
|
|
665
660
|
while (node.addChild(this._parseListElement())) {
|
|
666
661
|
this.accept(TokenType.Comma); // optional
|
|
@@ -669,10 +664,10 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
669
664
|
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
670
665
|
}
|
|
671
666
|
return this.finish(node);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
667
|
+
}
|
|
668
|
+
_parseListElement() {
|
|
669
|
+
const node = this.create(nodes.ListEntry);
|
|
670
|
+
const child = this._parseBinaryExpr();
|
|
676
671
|
if (!child) {
|
|
677
672
|
return null;
|
|
678
673
|
}
|
|
@@ -686,12 +681,12 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
686
681
|
node.setValue(child);
|
|
687
682
|
}
|
|
688
683
|
return this.finish(node);
|
|
689
|
-
}
|
|
690
|
-
|
|
684
|
+
}
|
|
685
|
+
_parseUse() {
|
|
691
686
|
if (!this.peekKeyword('@use')) {
|
|
692
687
|
return null;
|
|
693
688
|
}
|
|
694
|
-
|
|
689
|
+
const node = this.create(nodes.Use);
|
|
695
690
|
this.consumeToken(); // @use
|
|
696
691
|
if (!node.addChild(this._parseStringLiteral())) {
|
|
697
692
|
return this.finish(node, ParseError.StringLiteralExpected);
|
|
@@ -729,9 +724,9 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
729
724
|
return this.finish(node, ParseError.SemiColonExpected);
|
|
730
725
|
}
|
|
731
726
|
return this.finish(node);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
727
|
+
}
|
|
728
|
+
_parseModuleConfigDeclaration() {
|
|
729
|
+
const node = this.create(nodes.ModuleConfiguration);
|
|
735
730
|
if (!node.setIdentifier(this._parseVariable())) {
|
|
736
731
|
return null;
|
|
737
732
|
}
|
|
@@ -744,16 +739,26 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
744
739
|
}
|
|
745
740
|
}
|
|
746
741
|
return this.finish(node);
|
|
747
|
-
}
|
|
748
|
-
|
|
742
|
+
}
|
|
743
|
+
_parseForward() {
|
|
749
744
|
if (!this.peekKeyword('@forward')) {
|
|
750
745
|
return null;
|
|
751
746
|
}
|
|
752
|
-
|
|
747
|
+
const node = this.create(nodes.Forward);
|
|
753
748
|
this.consumeToken();
|
|
754
749
|
if (!node.addChild(this._parseStringLiteral())) {
|
|
755
750
|
return this.finish(node, ParseError.StringLiteralExpected);
|
|
756
751
|
}
|
|
752
|
+
if (this.acceptIdent('as')) {
|
|
753
|
+
const identifier = this._parseIdent([nodes.ReferenceType.Forward]);
|
|
754
|
+
if (!node.setIdentifier(identifier)) {
|
|
755
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
756
|
+
}
|
|
757
|
+
// Wildcard must be the next character after the identifier string.
|
|
758
|
+
if (this.hasWhitespace() || !this.acceptDelim('*')) {
|
|
759
|
+
return this.finish(node, ParseError.WildcardExpected);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
757
762
|
if (this.acceptIdent('with')) {
|
|
758
763
|
if (!this.accept(TokenType.ParenthesisL)) {
|
|
759
764
|
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.ParenthesisR]);
|
|
@@ -774,33 +779,18 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
774
779
|
return this.finish(node, ParseError.RightParenthesisExpected);
|
|
775
780
|
}
|
|
776
781
|
}
|
|
777
|
-
if (
|
|
778
|
-
if (!this.
|
|
779
|
-
return this.finish(node, ParseError.
|
|
780
|
-
}
|
|
781
|
-
if (this.acceptIdent('as')) {
|
|
782
|
-
var identifier = this._parseIdent([nodes.ReferenceType.Forward]);
|
|
783
|
-
if (!node.setIdentifier(identifier)) {
|
|
784
|
-
return this.finish(node, ParseError.IdentifierExpected);
|
|
785
|
-
}
|
|
786
|
-
// Wildcard must be the next character after the identifier string.
|
|
787
|
-
if (this.hasWhitespace() || !this.acceptDelim('*')) {
|
|
788
|
-
return this.finish(node, ParseError.WildcardExpected);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
if (this.peekIdent('hide') || this.peekIdent('show')) {
|
|
792
|
-
if (!node.addChild(this._parseForwardVisibility())) {
|
|
793
|
-
return this.finish(node, ParseError.IdentifierOrVariableExpected);
|
|
794
|
-
}
|
|
782
|
+
else if (this.peekIdent('hide') || this.peekIdent('show')) {
|
|
783
|
+
if (!node.addChild(this._parseForwardVisibility())) {
|
|
784
|
+
return this.finish(node, ParseError.IdentifierOrVariableExpected);
|
|
795
785
|
}
|
|
796
786
|
}
|
|
797
787
|
if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
|
|
798
788
|
return this.finish(node, ParseError.SemiColonExpected);
|
|
799
789
|
}
|
|
800
790
|
return this.finish(node);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
|
|
791
|
+
}
|
|
792
|
+
_parseForwardVisibility() {
|
|
793
|
+
const node = this.create(nodes.ForwardVisibility);
|
|
804
794
|
// Assume to be "hide" or "show".
|
|
805
795
|
node.setIdentifier(this._parseIdent());
|
|
806
796
|
while (node.addChild(this._parseVariable() || this._parseIdent())) {
|
|
@@ -809,10 +799,8 @@ var SCSSParser = /** @class */ (function (_super) {
|
|
|
809
799
|
}
|
|
810
800
|
// More than just identifier
|
|
811
801
|
return node.getChildren().length > 1 ? node : null;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
return this._parseInterpolation() ||
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
}(cssParser.Parser));
|
|
818
|
-
export { SCSSParser };
|
|
802
|
+
}
|
|
803
|
+
_parseSupportsCondition() {
|
|
804
|
+
return this._parseInterpolation() || super._parseSupportsCondition();
|
|
805
|
+
}
|
|
806
|
+
}
|