@jesscss/less-parser 1.0.8-alpha.6 → 2.0.0-alpha.2

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 (41) hide show
  1. package/README.md +34 -1
  2. package/lib/__tests__/debug-log.d.ts +1 -0
  3. package/lib/__tests__/debug-log.js +34 -0
  4. package/lib/__tests__/debug-log.js.map +1 -0
  5. package/lib/index.d.ts +30 -8
  6. package/lib/index.js +66 -29
  7. package/lib/index.js.map +1 -0
  8. package/lib/lessActionsParser.d.ts +156 -0
  9. package/lib/lessActionsParser.js +145 -0
  10. package/lib/lessActionsParser.js.map +1 -0
  11. package/lib/lessErrorMessageProvider.d.ts +3 -0
  12. package/lib/lessErrorMessageProvider.js +4 -0
  13. package/lib/lessErrorMessageProvider.js.map +1 -0
  14. package/lib/lessTokens.d.ts +22 -3
  15. package/lib/lessTokens.js +242 -148
  16. package/lib/lessTokens.js.map +1 -0
  17. package/lib/productions.d.ts +181 -0
  18. package/lib/productions.js +3521 -0
  19. package/lib/productions.js.map +1 -0
  20. package/lib/utils.d.ts +2 -0
  21. package/lib/utils.js +88 -0
  22. package/lib/utils.js.map +1 -0
  23. package/package.json +41 -19
  24. package/lib/lessParser.d.ts +0 -36
  25. package/lib/lessParser.js +0 -49
  26. package/lib/productions/atRules.d.ts +0 -2
  27. package/lib/productions/atRules.js +0 -160
  28. package/lib/productions/blocks.d.ts +0 -2
  29. package/lib/productions/blocks.js +0 -60
  30. package/lib/productions/declarations.d.ts +0 -2
  31. package/lib/productions/declarations.js +0 -36
  32. package/lib/productions/interpolation.d.ts +0 -2
  33. package/lib/productions/interpolation.js +0 -18
  34. package/lib/productions/mixin.d.ts +0 -2
  35. package/lib/productions/mixin.js +0 -373
  36. package/lib/productions/root.d.ts +0 -2
  37. package/lib/productions/root.js +0 -33
  38. package/lib/productions/selectors.d.ts +0 -2
  39. package/lib/productions/selectors.js +0 -91
  40. package/lib/productions/values.d.ts +0 -2
  41. package/lib/productions/values.js +0 -305
@@ -1,160 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- $.atImport = $.OVERRIDE_RULE('atImport', () => {
5
- const atRuleChildren = [
6
- $.CONSUME($.T.AtImport)
7
- ];
8
- const preludeChildren = [$._()];
9
- $.OPTION(() => {
10
- const L = $.CONSUME($.T.LParen);
11
- const listChildren = [{
12
- name: 'expression',
13
- children: [
14
- $._(1),
15
- $.CONSUME($.T.Ident),
16
- $._(2)
17
- ]
18
- }];
19
- $.MANY(() => {
20
- listChildren.push($.CONSUME($.T.Comma), {
21
- name: 'expression',
22
- children: [
23
- $._(3),
24
- $.CONSUME2($.T.Ident),
25
- $._(4)
26
- ]
27
- });
28
- }),
29
- preludeChildren.push({
30
- name: 'block',
31
- children: [
32
- L,
33
- {
34
- name: 'expressionList',
35
- children: listChildren
36
- },
37
- $.CONSUME($.T.RParen)
38
- ]
39
- }, $._(5));
40
- });
41
- preludeChildren.push($.OR([
42
- { ALT: () => $.CONSUME($.T.StringLiteral) },
43
- { ALT: () => $.CONSUME($.T.Uri) }
44
- ]), $._(6));
45
- preludeChildren.push($.OPTION2(() => $.SUBRULE($.mediaQueryList)));
46
- atRuleChildren.push({
47
- name: 'prelude',
48
- children: preludeChildren
49
- }, $.OPTION3(() => $.CONSUME($.T.SemiColon)));
50
- return {
51
- name: 'atRule',
52
- children: atRuleChildren
53
- };
54
- });
55
- $.mediaFeature = $.OVERRIDE_RULE('mediaFeature', (afterAnd) => ({
56
- name: 'mediaFeature',
57
- children: [
58
- $.OR([
59
- {
60
- GATE: () => !afterAnd,
61
- ALT: () => $.CONSUME($.T.PlainIdent)
62
- },
63
- { ALT: () => $.SUBRULE($.variable) },
64
- {
65
- ALT: () => ({
66
- name: 'block',
67
- children: [
68
- $.CONSUME($.T.LParen),
69
- $.SUBRULE($.expression),
70
- $.CONSUME($.T.RParen)
71
- ]
72
- })
73
- }
74
- ]),
75
- $._()
76
- ]
77
- }));
78
- $.unknownAtRule = $.OVERRIDE_RULE('unknownAtRule', () => {
79
- const name = $.CONSUME($.T.AtKeyword);
80
- const ws = $._(0);
81
- return $.OR({
82
- /**
83
- * A prelude could have a colon too, so the last two rules are
84
- * ambiguous, but any unknown at-rule in the form of `@rule:`
85
- * is assumed to be a variable assignment
86
- */
87
- IGNORE_AMBIGUITIES: true,
88
- DEF: [
89
- {
90
- GATE: () => !ws,
91
- /** Variable call */
92
- ALT: () => {
93
- return {
94
- name: 'variableCall',
95
- children: [
96
- name,
97
- $.CONSUME($.T.LParen),
98
- $.CONSUME($.T.RParen)
99
- ]
100
- };
101
- }
102
- },
103
- {
104
- /** Variable assignment */
105
- ALT: () => {
106
- const children = [
107
- name,
108
- ws,
109
- $.CONSUME($.T.Colon),
110
- $._(1)
111
- ];
112
- $.OR2([
113
- {
114
- ALT: () => {
115
- children.push($.SUBRULE($.curlyBlock), undefined);
116
- }
117
- },
118
- {
119
- ALT: () => {
120
- children.push($.SUBRULE($.expressionList), $.OPTION(() => ({
121
- name: 'important',
122
- children: [
123
- $.CONSUME($.T.Important),
124
- $._(2)
125
- ]
126
- })));
127
- }
128
- }
129
- ]);
130
- children.push($.OPTION2(() => $.CONSUME($.T.SemiColon)));
131
- return {
132
- name: 'declaration',
133
- children
134
- };
135
- }
136
- },
137
- {
138
- ALT: () => {
139
- var _a;
140
- const prelude = $.SUBRULE($.customPrelude);
141
- (_a = prelude.children) === null || _a === void 0 ? void 0 : _a.unshift(ws);
142
- return {
143
- name: 'atRule',
144
- children: [
145
- name,
146
- prelude,
147
- $.OR3([
148
- { ALT: () => $.SUBRULE2($.curlyBlock) },
149
- { ALT: () => $.OPTION3(() => $.CONSUME2($.T.SemiColon))
150
- }
151
- ])
152
- ]
153
- };
154
- }
155
- }
156
- ]
157
- });
158
- });
159
- }
160
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { LessParser } from '../lessParser';
2
- export default function (this: LessParser, $: LessParser): void;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- const resetState = () => {
5
- $.hasExtend = false;
6
- };
7
- $.qualifiedRule = $.OVERRIDE_RULE('qualifiedRule', () => {
8
- const sel = $.SUBRULE($.selectorList);
9
- const hasExtend = $.hasExtend;
10
- resetState();
11
- return {
12
- name: 'qualifiedRule',
13
- children: [
14
- sel,
15
- $.OR([
16
- {
17
- GATE: () => hasExtend,
18
- ALT: () => $.OR2([
19
- { ALT: () => $.SUBRULE($.curlyBlock) },
20
- { ALT: () => $.CONSUME($.T.SemiColon) }
21
- ])
22
- },
23
- {
24
- ALT: () => $.SUBRULE2($.curlyBlock)
25
- }
26
- ])
27
- ]
28
- };
29
- });
30
- $.testQualifiedRule = $.OVERRIDE_RULE('testQualifiedRule', () => {
31
- $.OR({
32
- IGNORE_AMBIGUITIES: true,
33
- DEF: [
34
- { ALT: () => $.CONSUME($.T.DotName) },
35
- { ALT: () => $.CONSUME($.T.HashName) },
36
- { ALT: () => $.CONSUME($.T.Colon) },
37
- { ALT: () => $.CONSUME($.T.Ampersand) },
38
- {
39
- ALT: () => {
40
- $.SUBRULE($.testQualifiedRuleExpression);
41
- $.OR2([
42
- { ALT: () => $.CONSUME($.T.LCurly) },
43
- { ALT: () => $.CONSUME($.T.Extend) },
44
- { ALT: () => {
45
- $.CONSUME($.T.When);
46
- $._();
47
- $.OPTION(() => {
48
- $.CONSUME($.T.Not);
49
- $._(1);
50
- });
51
- $.CONSUME($.T.LParen);
52
- } }
53
- ]);
54
- }
55
- }
56
- ]
57
- });
58
- });
59
- }
60
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { LessParser } from '../lessParser';
2
- export default function (this: LessParser, $: LessParser): void;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- /** "color" in "color: red" */
5
- $.property = $.OVERRIDE_RULE('property', () => {
6
- const children = [];
7
- /** Legacy - remove? */
8
- $.OPTION(() => children.push($.CONSUME($.T.Star)));
9
- $.AT_LEAST_ONE(() => children.push($.OR2([
10
- { ALT: () => $.CONSUME($.T.Ident) },
11
- { ALT: () => $.CONSUME($.T.InterpolatedIdent) },
12
- /** Isolated dashes */
13
- { ALT: () => $.CONSUME($.T.Minus) }
14
- ])));
15
- return {
16
- name: 'property',
17
- children
18
- };
19
- });
20
- $.customProperty = $.OVERRIDE_RULE('customProperty', () => {
21
- const children = [
22
- $.CONSUME($.T.CustomProperty)
23
- ];
24
- $.MANY(() => children.push($.OR([
25
- { ALT: () => $.CONSUME($.T.Ident) },
26
- { ALT: () => $.CONSUME($.T.InterpolatedIdent) },
27
- /** Isolated dashes */
28
- { ALT: () => $.CONSUME($.T.Minus) }
29
- ])));
30
- return {
31
- name: 'property',
32
- children
33
- };
34
- });
35
- }
36
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { LessParser } from '../lessParser';
2
- export default function (this: LessParser, $: LessParser): void;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- $.identOrInterpolated = $.RULE('identOrInterpolated', () => {
5
- const children = [];
6
- $.AT_LEAST_ONE(() => {
7
- children.push($.OR([
8
- { ALT: () => $.CONSUME($.T.Ident) },
9
- { ALT: () => $.CONSUME($.T.InterpolatedIdent) }
10
- ]));
11
- });
12
- return {
13
- name: 'identOrInterpolated',
14
- children
15
- };
16
- });
17
- }
18
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { LessParser } from '../lessParser';
2
- export default function (this: LessParser, $: LessParser): void;
@@ -1,373 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chevrotain_1 = require("chevrotain");
4
- function default_1($) {
5
- /**
6
- * .mixin .foo la (@foo: bar, blah, ...;)
7
- */
8
- /**
9
- * Test for mixin start
10
- */
11
- $.testMixin = $.RULE('testMixin', () => {
12
- $.SUBRULE($.mixinStart);
13
- $._();
14
- $.OR([
15
- { ALT: () => $.CONSUME($.T.SemiColon) },
16
- { ALT: () => $.CONSUME($.T.LParen) }
17
- ]);
18
- });
19
- /**
20
- * To avoid a lot of back-tracking, we parse the mixin start
21
- * and mixin arguments equally for mixin calls, as it's only
22
- * the final curlyBlock that determines if this is a definition
23
- * or a call.
24
- *
25
- * During CST-to-AST, we can throw an error if a mixin definition
26
- * doesn't have valid selectors or arguments, or if, say, a mixin
27
- * call has a guard and shouldn't.
28
- */
29
- $.mixin = $.RULE('mixin', () => {
30
- const children = [
31
- $.SUBRULE($.mixinStart)
32
- ];
33
- $.OR([
34
- { ALT: () => {
35
- children.push($.CONSUME($.T.LParen), $.SUBRULE($.mixinArgs), $.CONSUME($.T.RParen));
36
- } },
37
- { ALT: () => {
38
- children.push(undefined, undefined, undefined);
39
- return chevrotain_1.EMPTY_ALT;
40
- } }
41
- ]);
42
- children.push($._(1), $.OPTION(() => ({
43
- name: 'important',
44
- children: [
45
- $.CONSUME($.T.Important),
46
- $._(2)
47
- ]
48
- })), $.OPTION4(() => $.SUBRULE($.guard)));
49
- $.OR2([
50
- {
51
- ALT: () => {
52
- children.push($.CONSUME($.T.SemiColon));
53
- }
54
- },
55
- {
56
- ALT: () => {
57
- children.push($.SUBRULE($.curlyBlock));
58
- }
59
- },
60
- { ALT: () => chevrotain_1.EMPTY_ALT }
61
- ]);
62
- return {
63
- name: 'mixin',
64
- children
65
- };
66
- });
67
- $.mixinStart = $.RULE('mixinStart', () => {
68
- const children = [
69
- $.SUBRULE($.mixinName),
70
- $._()
71
- ];
72
- $.MANY(() => {
73
- children.push($.OPTION(() => ({
74
- name: 'combinator',
75
- children: [
76
- $.CONSUME($.T.Gt),
77
- $._(1)
78
- ]
79
- })), $.SUBRULE2($.mixinName), $._(2));
80
- });
81
- return {
82
- name: 'mixinStart',
83
- children
84
- };
85
- });
86
- $.mixinName = $.RULE('mixinName', () => $.OR([
87
- { ALT: () => $.CONSUME($.T.DotName) },
88
- { ALT: () => $.CONSUME($.T.HashName) },
89
- { ALT: () => $.CONSUME($.T.ColorIdentStart) },
90
- { ALT: () => $.CONSUME($.T.Interpolated) }
91
- ]));
92
- /**
93
- * This code gets a bit complicated. Less 2.x-4.x uses
94
- * lookaheads to find semi-colons, and if found, parses
95
- * arguments differently.
96
- *
97
- * Instead, here we just allow for semi-colon or comma
98
- * separators, and if BOTH, then we MERGE comma-separated
99
- * arguments into the initial expression as an expression
100
- * list.
101
- *
102
- * This allows us to have one parsing "pass" on arguments
103
- * without any back-tracking.
104
- *
105
- * Is this premature optimization? Possibly. It would depend
106
- * on the performance of backtracking and the potential
107
- * length of mixin args.
108
- */
109
- $.mixinArgs = $.RULE('mixinArgs', () => {
110
- let childrenGroups = [[
111
- $.SUBRULE($.mixinArg)
112
- ]];
113
- let children = childrenGroups[0];
114
- let groupIndex = 0;
115
- $.MANY(() => {
116
- $.OR([
117
- { ALT: () => {
118
- children.push($.CONSUME($.T.Comma), $.SUBRULE2($.mixinArg));
119
- } },
120
- { ALT: () => {
121
- children.push($.CONSUME($.T.SemiColon));
122
- childrenGroups.push([
123
- $.SUBRULE3($.mixinArg)
124
- ]);
125
- groupIndex++;
126
- children = childrenGroups[groupIndex];
127
- } }
128
- ]);
129
- });
130
- if (!this.RECORDING_PHASE && childrenGroups.length !== 1) {
131
- children = [];
132
- childrenGroups.forEach(group => {
133
- const length = group.length;
134
- const value = group[0].children[1];
135
- let expr;
136
- let exprList = [];
137
- if (value.name === 'declaration') {
138
- expr = value.children[4];
139
- }
140
- else {
141
- expr = value;
142
- }
143
- exprList.push(expr);
144
- for (let i = 1; i < length - 1; i += 2) {
145
- /** Comma separator */
146
- exprList.push(group[i]);
147
- expr = group[i + 1].children[1];
148
- exprList.push(expr);
149
- }
150
- const exprListNode = {
151
- name: 'expressionList',
152
- children: exprList
153
- };
154
- if (value.name === 'declaration') {
155
- value.children[4] = exprListNode;
156
- }
157
- else {
158
- group[0].children[1] = exprListNode;
159
- }
160
- children.push(group[0]);
161
- const semi = group[group.length - 1];
162
- if ((semi === null || semi === void 0 ? void 0 : semi.image) === ';') {
163
- children.push(semi);
164
- }
165
- });
166
- }
167
- return {
168
- name: 'mixinArgs',
169
- children
170
- };
171
- });
172
- /**
173
- * This will return a mixin arg containing
174
- * a declaration, an expression, or a rest
175
- * (e.g. `@var...`)
176
- */
177
- $.mixinArg = $.RULE('mixinArg', () => {
178
- let pre = $._(0);
179
- let varName;
180
- let ws;
181
- let assign;
182
- let postAssign;
183
- let isDeclaration = false;
184
- $.OPTION(() => {
185
- /**
186
- * In a mixin definition, this is the variable declaration.
187
- * In a mixin call, this is either assignment to a variable, OR
188
- * could be part of the expression value.
189
- */
190
- varName = $.CONSUME($.T.AtKeyword);
191
- ws = $._(1);
192
- $.OPTION2(() => {
193
- isDeclaration = true;
194
- assign = $.CONSUME($.T.Assign);
195
- postAssign = $._(2);
196
- });
197
- });
198
- let value = $.OR2([
199
- {
200
- GATE: () => !isDeclaration && !ws,
201
- ALT: () => ({
202
- name: 'rest',
203
- children: [
204
- varName,
205
- $.CONSUME2($.T.Ellipsis)
206
- ]
207
- })
208
- },
209
- {
210
- GATE: () => !varName || isDeclaration,
211
- ALT: () => ({
212
- name: 'expression',
213
- children: [$.SUBRULE($.curlyBlock)]
214
- })
215
- },
216
- {
217
- ALT: () => {
218
- const expr = $.SUBRULE($.expression);
219
- if (!isDeclaration) {
220
- if (varName) {
221
- if (ws) {
222
- expr.children.unshift(ws);
223
- }
224
- expr.children.unshift(varName);
225
- }
226
- if (pre) {
227
- expr.children.unshift(pre);
228
- pre = undefined;
229
- }
230
- }
231
- return expr;
232
- }
233
- }
234
- ]);
235
- const post = $._(3);
236
- let chunk = value;
237
- if (isDeclaration) {
238
- chunk = {
239
- name: 'declaration',
240
- children: [
241
- varName,
242
- ws,
243
- assign,
244
- postAssign,
245
- value,
246
- undefined,
247
- undefined
248
- ]
249
- };
250
- }
251
- else {
252
- chunk = value;
253
- }
254
- return {
255
- name: 'mixinArg',
256
- children: [
257
- pre,
258
- chunk,
259
- post
260
- ]
261
- };
262
- });
263
- $.anonMixin = $.RULE('anonMixin', () => ({
264
- name: 'anonMixin',
265
- children: [
266
- $.CONSUME($.T.AnonMixinStart),
267
- $.SUBRULE($.mixinArgs),
268
- $.CONSUME($.T.RParen),
269
- $._(),
270
- $.SUBRULE($.curlyBlock)
271
- ]
272
- }));
273
- /**
274
- * @note - Guards do not require parens during parsing,
275
- * in order to handle recursive nesting.
276
- * They should be evaluated during post-processing
277
- * (CST visitor?)
278
- */
279
- $.guard = $.RULE('guard', () => ({
280
- name: 'guard',
281
- children: [
282
- $.CONSUME($.T.When),
283
- $._(),
284
- $.SUBRULE($.guardOr)
285
- ]
286
- }));
287
- /** 'or' expression */
288
- $.guardOr = $.RULE('guardOr', (disallowComma) => {
289
- let expr = $.SUBRULE($.guardAnd);
290
- $.MANY({
291
- GATE: () => $.LA(1).tokenType !== $.T.Comma || !disallowComma,
292
- DEF: () => {
293
- /**
294
- * Nest expressions within expressions for correct
295
- * order of operations.
296
- */
297
- expr = {
298
- name: 'or',
299
- children: [
300
- expr,
301
- {
302
- name: 'combinator',
303
- children: [
304
- $.OR([
305
- { ALT: () => $.CONSUME($.T.Comma) },
306
- { ALT: () => $.CONSUME($.T.Or) }
307
- ]),
308
- $._()
309
- ]
310
- },
311
- $.SUBRULE2($.guardAnd)
312
- ]
313
- };
314
- }
315
- });
316
- return expr;
317
- });
318
- /**
319
- * 'and' and 'or' expressions
320
- *
321
- * In Media queries level 4, you cannot have
322
- * `([expr]) or ([expr]) and ([expr])` because
323
- * of evaluation order ambiguity.
324
- * However, Less allows it.
325
- */
326
- $.guardAnd = $.RULE('guardAnd', () => {
327
- let expr = $.SUBRULE($.guardExpression);
328
- $.MANY(() => {
329
- expr = {
330
- name: 'and',
331
- children: [
332
- expr,
333
- {
334
- name: 'combinator',
335
- children: [
336
- $.CONSUME($.T.And),
337
- $._(1)
338
- ]
339
- },
340
- $.SUBRULE2($.guardExpression)
341
- ]
342
- };
343
- });
344
- return expr;
345
- });
346
- $.guardExpression = $.RULE('guardExpression', () => {
347
- let expr = $.OPTION(() => [
348
- $.CONSUME($.T.Not),
349
- $._()
350
- ]);
351
- const guard = {
352
- name: 'guardExpression',
353
- children: [
354
- $.SUBRULE($.compare),
355
- $._(1)
356
- ]
357
- };
358
- if (expr) {
359
- return {
360
- name: 'not',
361
- children: [
362
- {
363
- name: 'combinator',
364
- children: expr
365
- },
366
- guard
367
- ]
368
- };
369
- }
370
- return guard;
371
- });
372
- }
373
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { LessParser } from '../lessParser';
2
- export default function (this: LessParser, $: LessParser): void;