@jesscss/less-parser 2.0.0-alpha.6 → 2.0.0-alpha.8
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/README.md +149 -36
- package/lib/builders.d.ts +381 -0
- package/lib/builders.d.ts.map +1 -0
- package/lib/cst.cjs +14 -0
- package/lib/cst.d.ts +6 -0
- package/lib/cst.d.ts.map +1 -0
- package/lib/cst.js +12 -0
- package/lib/functional-parser.cjs +2654 -0
- package/lib/functional-parser.d.ts +18 -0
- package/lib/functional-parser.d.ts.map +1 -0
- package/lib/functional-parser.js +2589 -0
- package/lib/grammar.cjs +35057 -0
- package/lib/grammar.d.ts +2 -0
- package/lib/grammar.d.ts.map +1 -0
- package/lib/grammar.js +35056 -0
- package/lib/index.cjs +17 -4096
- package/lib/index.d.ts +9 -149
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -4091
- package/lib/jess.cjs +3968 -0
- package/lib/jess.d.ts +7 -0
- package/lib/jess.d.ts.map +1 -0
- package/lib/jess.js +3962 -0
- package/lib/lessParser.d.ts +38 -0
- package/lib/lessParser.d.ts.map +1 -0
- package/lib/lessRecursiveParser.d.ts +99 -0
- package/lib/lessRecursiveParser.d.ts.map +1 -0
- package/lib/lessTokens.d.ts +23 -0
- package/lib/lessTokens.d.ts.map +1 -0
- package/lib/productions/guards.d.ts +113 -0
- package/lib/productions/guards.d.ts.map +1 -0
- package/lib/productions/index.d.ts +5 -0
- package/lib/productions/index.d.ts.map +1 -0
- package/lib/productions/root.d.ts +38 -0
- package/lib/productions/root.d.ts.map +1 -0
- package/lib/productions/selectors.d.ts +41 -0
- package/lib/productions/selectors.d.ts.map +1 -0
- package/lib/productions/values.d.ts +35 -0
- package/lib/productions/values.d.ts.map +1 -0
- package/lib/utils.d.ts +9 -0
- package/lib/utils.d.ts.map +1 -0
- package/package.json +40 -9
- package/src/__tests__/debug-log.ts +35 -0
- package/src/__tests__/wall5-parse.test.ts +67 -0
- package/src/builders.ts +3190 -0
- package/src/cst.ts +25 -0
- package/src/functional-parser.ts +162 -0
- package/src/grammar.ts +870 -0
- package/src/index.ts +19 -0
- package/src/jess.ts +6 -0
- package/src/lessParser.ts +120 -0
- package/src/lessRecursiveParser.ts +279 -0
- package/src/lessTokens.ts +350 -0
- package/src/productions/guards.ts +1066 -0
- package/src/productions/index.ts +29 -0
- package/src/productions/root.ts +1613 -0
- package/src/productions/selectors.ts +1309 -0
- package/src/productions/values.ts +1449 -0
- package/src/utils.ts +178 -0
- package/lib/index.d.cts +0 -150
- package/lib/index.d.cts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/jess.js
ADDED
|
@@ -0,0 +1,3962 @@
|
|
|
1
|
+
import { a as getInterpolatedNode, d as lessTokens, i as createInterpolatedReference, n as parseLessFn, o as getInterpolatedOrString, r as LessGrammar, s as normalizeMixinReferenceKey, t as LessParser, u as lessFragments } from "./functional-parser.js";
|
|
2
|
+
import { createLexerDefinition } from "@jesscss/css-parser";
|
|
3
|
+
import { CssRecursiveParser, productions } from "@jesscss/css-parser/jess";
|
|
4
|
+
import { Ampersand, Any, AtRuleStatement, AttributeSelector, BasicSelector, Block, Bool, Call, Collection, Combinator, ComplexSelector, CompoundSelector, Condition, Declaration, DefaultGuard, Dimension, Expression, Extend, For, INTERPOLATION_PLACEHOLDER, Interpolated, InterpolatedSelector, JsImport, Keyword, List, Mixin, N, Negative, Nil, Node, Num, Operation, Paren, QueryCondition, Quoted, Reference, Rest, Rules, Ruleset, Selector, SelectorCapture, SelectorList, Sequence, StyleImport, Url, VarDeclaration, isNode, nil, shouldOperateWithMathFrames } from "@jesscss/core";
|
|
5
|
+
import { Lexer, NoViableAltException, tokenMatcher } from "chevrotain";
|
|
6
|
+
import { all } from "known-css-properties";
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/productions/root.ts
|
|
20
|
+
const cssMain = productions.main;
|
|
21
|
+
const cssDeclaration = productions.declaration;
|
|
22
|
+
productions.mediaTypeQuery;
|
|
23
|
+
function extendWithSelector$1(node, selector, context) {
|
|
24
|
+
return new Extend({
|
|
25
|
+
selector,
|
|
26
|
+
target: node.target,
|
|
27
|
+
namespace: node.namespace,
|
|
28
|
+
flag: node.flag
|
|
29
|
+
}, void 0, node.location, context);
|
|
30
|
+
}
|
|
31
|
+
function prependRules(rules, nodes, context) {
|
|
32
|
+
const out = new Rules([...nodes, ...rules.rules], rules.options, rules.location.length ? rules.location : void 0, context);
|
|
33
|
+
out._location = rules._location;
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function getParenFrames$2(ctx) {
|
|
37
|
+
return ctx?.parenFrames ?? [];
|
|
38
|
+
}
|
|
39
|
+
function getCalcFrames(ctx) {
|
|
40
|
+
return ctx?.calcFrames ?? 0;
|
|
41
|
+
}
|
|
42
|
+
function guardContainsDefaultCall(node) {
|
|
43
|
+
if (!node) return false;
|
|
44
|
+
const isNodeLike = (value) => {
|
|
45
|
+
return Boolean(value && typeof value === "object" && "type" in value && typeof value.type === "string" && "valueOf" in value && typeof value.valueOf === "function");
|
|
46
|
+
};
|
|
47
|
+
const queue = [node];
|
|
48
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49
|
+
while (queue.length > 0) {
|
|
50
|
+
const current = queue.shift();
|
|
51
|
+
if (!current || seen.has(current) || !isNodeLike(current)) continue;
|
|
52
|
+
seen.add(current);
|
|
53
|
+
if (current.type === "DefaultGuard") return true;
|
|
54
|
+
if (isNode(current, N.Call)) {
|
|
55
|
+
const callName = current.name;
|
|
56
|
+
const callNameStr = String(typeof callName === "object" && callName !== null && "valueOf" in callName ? callName.valueOf() : callName ?? "");
|
|
57
|
+
if (callNameStr === "default" || callNameStr === "??") return true;
|
|
58
|
+
if (callName instanceof Reference) {
|
|
59
|
+
const key = callName.key;
|
|
60
|
+
const keyStr = String(typeof key === "object" && key !== null && "valueOf" in key ? key.valueOf() : key ?? "");
|
|
61
|
+
if (keyStr === "default" || keyStr === "??") return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if ("data" in current) {
|
|
65
|
+
const value = current.data;
|
|
66
|
+
if (Array.isArray(value)) queue.push(...value);
|
|
67
|
+
else if (value && typeof value === "object") queue.push(...Object.values(value));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function loc(node) {
|
|
73
|
+
const location = node.location;
|
|
74
|
+
return location.length === 6 ? location : void 0;
|
|
75
|
+
}
|
|
76
|
+
function wrapAtRulePreludeExpression(node, ctx) {
|
|
77
|
+
if (!this.wrapOuterExpressions || ctx?.atRulePreludeBareVariableAs !== "index") return node;
|
|
78
|
+
if (node instanceof Expression) return node;
|
|
79
|
+
if (isNode(node, N.Reference) && !node.target && typeof node.key === "string") return node;
|
|
80
|
+
return new Expression(node, void 0, loc(node), this.context);
|
|
81
|
+
}
|
|
82
|
+
function wrapOuterExpressionIfNeeded(node, ctx) {
|
|
83
|
+
if (!this.wrapOuterExpressions) return node;
|
|
84
|
+
if (!ctx?.wrapInExpression) return node;
|
|
85
|
+
if (node instanceof Expression) return node;
|
|
86
|
+
if (isNode(node, N.Operation)) {
|
|
87
|
+
if (shouldOperateWithMathFrames({
|
|
88
|
+
mathMode: this.mathMode ?? "parens-division",
|
|
89
|
+
parenFrames: getParenFrames$2(ctx),
|
|
90
|
+
calcFrames: getCalcFrames(ctx)
|
|
91
|
+
}, node.operator, node.left, node.right)) return new Expression(node, { parens: true }, loc(node), this.context);
|
|
92
|
+
}
|
|
93
|
+
return node;
|
|
94
|
+
}
|
|
95
|
+
function isEscapedString($, T) {
|
|
96
|
+
const next = $.LA(1);
|
|
97
|
+
return next.image.startsWith("~") && ($.matchToken(next, T.QuoteStart) || $.matchToken(next, T.DoubleQuoteStart) || $.matchToken(next, T.SingleQuoteStart));
|
|
98
|
+
}
|
|
99
|
+
function startsLessMediaQueryReference($, T) {
|
|
100
|
+
if ($.isType(T.AtName) || $.isType(T.PropertyReference) || $.isType(T.NestedReference) || $.isType(T.DotName) || $.isType(T.HashName) || $.isType(T.InterpolatedIdent) || $.isType(T.InterpolatedSelector)) return true;
|
|
101
|
+
if (!$.isType(T.ColorIdentStart)) return false;
|
|
102
|
+
const tt2 = $.LA(2).tokenType;
|
|
103
|
+
return tt2 === T.Gt || tt2 === T.DotName || tt2 === T.HashName || tt2 === T.InterpolatedSelector || $.noSep(1) && (tt2 === T.LParen || tt2 === T.LSquare || tt2 === T.HashName || tt2 === T.DotName);
|
|
104
|
+
}
|
|
105
|
+
function startsCustomValue($, T) {
|
|
106
|
+
return $.isType(T.LParen) || $.isType(T.FunctionStart) || $.isType(T.FunctionalPseudoClass) || $.isType(T.LSquare) || $.isType(T.LCurly) || $.isType(T.SingleQuoteStart) || $.isType(T.DoubleQuoteStart) || $.isType(T.Value) || $.isType(T.PlainIdent) || $.isType(T.AtKeyword) || $.isType(T.PropertyReference) || $.isType(T.CustomProperty) || $.isType(T.Dimension) || $.isType(T.Number) || $.isType(T.Color) || $.isType(T.UnicodeRange) || $.isType(T.Colon) || $.isType(T.Comma) || $.isType(T.Important) || $.isType(T.Unknown);
|
|
107
|
+
}
|
|
108
|
+
function isVariableLike($, T) {
|
|
109
|
+
let token = $.LA(2);
|
|
110
|
+
let isColon = token.tokenType === T.Colon;
|
|
111
|
+
let isParen = token.tokenType === T.LParen;
|
|
112
|
+
let postToken = $.LA(3);
|
|
113
|
+
if (!$.trivia) return false;
|
|
114
|
+
if (!isColon && !isParen) return false;
|
|
115
|
+
if (isParen && $.matchToken($.LA(1), T.AtName) && $.LA(1).tokenType !== T.AtKeyword) {
|
|
116
|
+
if (postToken.tokenType === T.RParen) {
|
|
117
|
+
$.warnDeprecation("Using known at-rule names as variables is deprecated", $.LA(1), "at-rule-variable");
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return !$.trivia.has(token.startOffset, "before") || isColon && $.trivia.has(postToken.startOffset, "before");
|
|
123
|
+
}
|
|
124
|
+
const { isArray: isArray$1 } = Array;
|
|
125
|
+
/**
|
|
126
|
+
* Groups extends by target (using valueOf()) and flag.
|
|
127
|
+
* Returns an array of grouped Extend nodes where extends with the same target and flag
|
|
128
|
+
* are combined into a single Extend node with a SelectorList of all matching value.
|
|
129
|
+
*
|
|
130
|
+
* @todo Group complex value into selector lists
|
|
131
|
+
*/
|
|
132
|
+
function groupExtendsByTargetAndFlag(extendNodes) {
|
|
133
|
+
const groups = /* @__PURE__ */ new Map();
|
|
134
|
+
for (const ext of extendNodes) {
|
|
135
|
+
const { target, flag = 1 } = ext;
|
|
136
|
+
const key = `${target.valueOf()}|${flag}`;
|
|
137
|
+
let group = groups.get(key);
|
|
138
|
+
if (!group) groups.set(key, ext);
|
|
139
|
+
else if (isArray$1(group)) group.push(ext);
|
|
140
|
+
else groups.set(key, [group, ext]);
|
|
141
|
+
}
|
|
142
|
+
return Array.from(groups.values());
|
|
143
|
+
}
|
|
144
|
+
/** Charset moved within `main` (explained in that rule) */
|
|
145
|
+
function stylesheet(T) {
|
|
146
|
+
const $ = this;
|
|
147
|
+
return (options = {}) => {
|
|
148
|
+
let context;
|
|
149
|
+
if (options.context) context = $.context = options.context;
|
|
150
|
+
else context = $.context;
|
|
151
|
+
let charset;
|
|
152
|
+
if (!$.looseMode) $.OPTION(() => {
|
|
153
|
+
charset = $.CONSUME(T.Charset);
|
|
154
|
+
});
|
|
155
|
+
let root = $.SUBRULE($.main, { ARGS: [{ isRoot: true }] });
|
|
156
|
+
if (charset && isNode(root, N.Rules)) {
|
|
157
|
+
let charsetLoc = $.getLocationInfo(charset);
|
|
158
|
+
root = new Rules([new Any(charset.image, { role: "charset" }, charsetLoc, context), ...root.rules], root.options, root.location.length ? root.location : void 0, context);
|
|
159
|
+
let rootLoc = root.location;
|
|
160
|
+
rootLoc[0] = charsetLoc[0];
|
|
161
|
+
rootLoc[1] = charsetLoc[1];
|
|
162
|
+
rootLoc[2] = charsetLoc[2];
|
|
163
|
+
}
|
|
164
|
+
return root;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Starts with a colon, with these conditions
|
|
169
|
+
* 1. It is not preceded by a space or
|
|
170
|
+
* 2. If it is preceded by a space, then it is
|
|
171
|
+
* followed by a space.
|
|
172
|
+
*/
|
|
173
|
+
function main(T) {
|
|
174
|
+
const $ = this;
|
|
175
|
+
return (ctx = {}) => {
|
|
176
|
+
const isAmpersandExtendStart = () => $.LA(1).tokenType === T.Ampersand && $.LA(2).tokenType === T.Extend;
|
|
177
|
+
const isMixinOrQualifiedStart = () => {
|
|
178
|
+
const next = $.LA(1).tokenType;
|
|
179
|
+
return next === T.DotName || next === T.HashName || next === T.ColorIdentStart;
|
|
180
|
+
};
|
|
181
|
+
const isCustomPropertyStart = () => $.isType(T.InterpolatedCustomProperty) || $.isType(T.CustomProperty);
|
|
182
|
+
const isAtRuleStart = () => $.matchToken($.LA(1), T.AtName);
|
|
183
|
+
const shouldTryQualifiedRule = () => !isCustomPropertyStart() && !isMixinOrQualifiedStart() && !isAtRuleStart() && $.shouldTryQualifiedRuleInDeclarationList();
|
|
184
|
+
const ruleAlt = (ctx = {}) => {
|
|
185
|
+
let isVariable = isVariableLike($, T);
|
|
186
|
+
return [
|
|
187
|
+
{ ALT: () => $.SUBRULE($.functionCall, { ARGS: [ctx] }) },
|
|
188
|
+
{
|
|
189
|
+
GATE: isAmpersandExtendStart,
|
|
190
|
+
ALT: () => $.SUBRULE2($.ampersandExtend, { ARGS: [ctx] })
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
GATE: isMixinOrQualifiedStart,
|
|
194
|
+
ALT: () => $.SUBRULE3($.mixinOrQualifiedRule, { ARGS: [ctx] })
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
GATE: () => isVariable,
|
|
198
|
+
ALT: () => $.SUBRULE4($.varDeclarationOrCall, { ARGS: [ctx] })
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
GATE: () => !isVariable && isAtRuleStart(),
|
|
202
|
+
ALT: () => $.SUBRULE5($.atRule, { ARGS: [ctx] })
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
GATE: isCustomPropertyStart,
|
|
206
|
+
ALT: () => $.SUBRULE7($.declaration, { ARGS: [ctx] })
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
GATE: shouldTryQualifiedRule,
|
|
210
|
+
ALT: () => $.SUBRULE6($.qualifiedRule, { ARGS: [ctx] })
|
|
211
|
+
},
|
|
212
|
+
(
|
|
213
|
+
/**
|
|
214
|
+
* Historically, Less allows `@charset` anywhere,
|
|
215
|
+
* to avoid outputting it in the wrong place.
|
|
216
|
+
* Ideally, this would result in an error if, say,
|
|
217
|
+
* the `@charset` was defined at the bottom of the file,
|
|
218
|
+
* but that wasn't the solution made.
|
|
219
|
+
* @see https://github.com/less/less.js/issues/2126
|
|
220
|
+
*/
|
|
221
|
+
{
|
|
222
|
+
GATE: () => $.looseMode,
|
|
223
|
+
ALT: () => $.CONSUME(T.Charset)
|
|
224
|
+
}),
|
|
225
|
+
{ ALT: () => $.CONSUME(T.Semi) }
|
|
226
|
+
];
|
|
227
|
+
};
|
|
228
|
+
let RECORDING_PHASE = $.RECORDING_PHASE;
|
|
229
|
+
let context;
|
|
230
|
+
let rules;
|
|
231
|
+
if (!RECORDING_PHASE) {
|
|
232
|
+
context = $.context;
|
|
233
|
+
rules = [];
|
|
234
|
+
}
|
|
235
|
+
let requiredSemi = false;
|
|
236
|
+
let lastRule;
|
|
237
|
+
/**
|
|
238
|
+
* In this production rule, semi-colons are not required
|
|
239
|
+
* but this is repurposed by declarationList and by Less / Sass,
|
|
240
|
+
* so that's why this gate is here.
|
|
241
|
+
*/
|
|
242
|
+
$.MANY({
|
|
243
|
+
GATE: () => {
|
|
244
|
+
const next = $.LA(1);
|
|
245
|
+
if ($.isType(T.RCurly) || next.tokenType.name === "EOF") return false;
|
|
246
|
+
return !requiredSemi || requiredSemi && ($.isType(T.Semi) || $.isTypeAt(0, T.Semi));
|
|
247
|
+
},
|
|
248
|
+
DEF: () => {
|
|
249
|
+
const localAlt = ruleAlt(ctx);
|
|
250
|
+
let value = $.OR(localAlt);
|
|
251
|
+
if (!RECORDING_PHASE) {
|
|
252
|
+
/** @todo - When do we not have a value? */
|
|
253
|
+
if (value) if (!(value instanceof Node)) {
|
|
254
|
+
/** This is a semi-colon or charset token */
|
|
255
|
+
let tok = value;
|
|
256
|
+
if (tok.image.includes("@charset")) rules.push(new Any(tok.image, { role: "charset" }, $.getLocationInfo(tok), context));
|
|
257
|
+
else if (lastRule) lastRule.options.semi = true;
|
|
258
|
+
else rules.push(new Any(";", { role: "semi" }, $.getLocationInfo($.LA(1)), context));
|
|
259
|
+
} else {
|
|
260
|
+
requiredSemi = !!value.requiredSemi;
|
|
261
|
+
rules.push(value);
|
|
262
|
+
lastRule = value;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
if (RECORDING_PHASE) return;
|
|
268
|
+
if (ctx.extendNodes && ctx.extendNodes.length > 0) {
|
|
269
|
+
const filteredRules = rules.filter((r) => !(r instanceof Nil));
|
|
270
|
+
rules = [...ctx.extendNodes, ...filteredRules];
|
|
271
|
+
ctx.extendNodes = void 0;
|
|
272
|
+
}
|
|
273
|
+
return $.getRulesWithComments(rules, $.getLocationInfo($.LA(1)));
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function declarationList(T) {
|
|
277
|
+
const $ = this;
|
|
278
|
+
return (ctx = {}) => {
|
|
279
|
+
const isMixinOrQualifiedStart = () => {
|
|
280
|
+
const next = $.LA(1).tokenType;
|
|
281
|
+
return next === T.DotName || next === T.HashName || next === T.ColorIdentStart;
|
|
282
|
+
};
|
|
283
|
+
const isCustomPropertyStart = () => $.isType(T.InterpolatedCustomProperty) || $.isType(T.CustomProperty);
|
|
284
|
+
const isAtRuleStart = () => $.matchToken($.LA(1), T.AtName);
|
|
285
|
+
const isAmpersandExtendStart = () => $.LA(1).tokenType === T.Ampersand && $.LA(2).tokenType === T.Extend;
|
|
286
|
+
const shouldTryQualifiedRule = () => !isCustomPropertyStart() && !isMixinOrQualifiedStart() && !isAtRuleStart() && $.shouldTryQualifiedRuleInDeclarationList();
|
|
287
|
+
const ruleAlt = (ctx = {}) => {
|
|
288
|
+
const isVariable = isVariableLike($, T);
|
|
289
|
+
return [
|
|
290
|
+
{
|
|
291
|
+
GATE: isMixinOrQualifiedStart,
|
|
292
|
+
ALT: () => {
|
|
293
|
+
return $.SUBRULE($.mixinOrQualifiedRule, { ARGS: [{
|
|
294
|
+
...ctx,
|
|
295
|
+
inner: true
|
|
296
|
+
}] });
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
GATE: () => isVariable,
|
|
301
|
+
ALT: () => $.SUBRULE2($.varDeclarationOrCall, { ARGS: [ctx] })
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
GATE: () => !isVariable && isAtRuleStart(),
|
|
305
|
+
ALT: () => $.SUBRULE3($.innerAtRule, { ARGS: [ctx] })
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
GATE: isAmpersandExtendStart,
|
|
309
|
+
ALT: () => $.SUBRULE4($.ampersandExtend, { ARGS: [ctx] })
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
GATE: () => $.check(T.FunctionStart),
|
|
313
|
+
ALT: () => {
|
|
314
|
+
const fnCall = $.SUBRULE5($.functionCall, { ARGS: [ctx] });
|
|
315
|
+
if (fnCall instanceof Call) fnCall.requiredSemi = false;
|
|
316
|
+
return fnCall;
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
GATE: isCustomPropertyStart,
|
|
321
|
+
ALT: () => $.SUBRULE8($.declaration, { ARGS: [ctx] })
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
GATE: shouldTryQualifiedRule,
|
|
325
|
+
ALT: () => {
|
|
326
|
+
return $.SUBRULE6($.qualifiedRule, { ARGS: [{
|
|
327
|
+
...ctx,
|
|
328
|
+
inner: true
|
|
329
|
+
}] });
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
{ ALT: () => {
|
|
333
|
+
return $.SUBRULE7($.declaration, { ARGS: [ctx] });
|
|
334
|
+
} },
|
|
335
|
+
{ ALT: () => $.CONSUME(T.Semi) }
|
|
336
|
+
];
|
|
337
|
+
};
|
|
338
|
+
return cssMain.call($, T, ruleAlt)(ctx);
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function declaration(T) {
|
|
342
|
+
const $ = this;
|
|
343
|
+
return (ctx = {}) => {
|
|
344
|
+
const normalizeLessAssignToken = (assign) => {
|
|
345
|
+
if (assign.tokenType === T.PlusAssign) return {
|
|
346
|
+
...assign,
|
|
347
|
+
image: "+,:"
|
|
348
|
+
};
|
|
349
|
+
if (assign.tokenType === T.UnderscoreAssign) return {
|
|
350
|
+
...assign,
|
|
351
|
+
image: "+_:"
|
|
352
|
+
};
|
|
353
|
+
return assign;
|
|
354
|
+
};
|
|
355
|
+
const customPropertyAlt = (consumeName, occurrence) => ({ ALT: () => {
|
|
356
|
+
let nodes;
|
|
357
|
+
if (!$.RECORDING_PHASE) nodes = [];
|
|
358
|
+
const name = consumeName();
|
|
359
|
+
const assign = normalizeLessAssignToken(occurrence === 2 ? $.CONSUME2(T.Assign) : $.CONSUME3(T.Assign));
|
|
360
|
+
$.startRule();
|
|
361
|
+
while (startsCustomValue($, T)) {
|
|
362
|
+
const val = occurrence === 2 ? $.SUBRULE2($.customValue, { ARGS: [{
|
|
363
|
+
...ctx,
|
|
364
|
+
inCustomPropertyValue: true
|
|
365
|
+
}] }) : $.SUBRULE3($.customValue, { ARGS: [{
|
|
366
|
+
...ctx,
|
|
367
|
+
inCustomPropertyValue: true
|
|
368
|
+
}] });
|
|
369
|
+
if (!$.RECORDING_PHASE) nodes.push(val);
|
|
370
|
+
}
|
|
371
|
+
if (!$.RECORDING_PHASE) {
|
|
372
|
+
const location = $.endRule();
|
|
373
|
+
let nameNode;
|
|
374
|
+
const nameValue = name.image;
|
|
375
|
+
if (nameValue.includes("@") || nameValue.includes("$")) nameNode = getInterpolatedNode(nameValue, $.getLocationInfo(name), $.context);
|
|
376
|
+
else nameNode = new Any(name.image, { role: "property" }, $.getLocationInfo(name), $.context);
|
|
377
|
+
const value = new Sequence(nodes, void 0, location, $.context);
|
|
378
|
+
return [
|
|
379
|
+
nameNode,
|
|
380
|
+
assign,
|
|
381
|
+
value
|
|
382
|
+
];
|
|
383
|
+
}
|
|
384
|
+
} });
|
|
385
|
+
const ruleAlt = (ctx = {}) => [
|
|
386
|
+
{ ALT: () => {
|
|
387
|
+
let name;
|
|
388
|
+
$.OR2([{ ALT: () => {
|
|
389
|
+
name = $.CONSUME(T.Ident);
|
|
390
|
+
} }, {
|
|
391
|
+
GATE: () => $.legacyMode,
|
|
392
|
+
ALT: () => name = $.CONSUME(T.LegacyPropIdent)
|
|
393
|
+
}]);
|
|
394
|
+
const assign = normalizeLessAssignToken($.CONSUME(T.Assign));
|
|
395
|
+
let value;
|
|
396
|
+
if ($.looseMode) {
|
|
397
|
+
$.OPTION2({
|
|
398
|
+
GATE: () => !($.isType(T.Semi) || $.isType(T.RCurly)),
|
|
399
|
+
DEF: () => {
|
|
400
|
+
value = $.SUBRULE($.valueList, { ARGS: [ctx] });
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
if (!$.RECORDING_PHASE && !value) value = new Sequence([], void 0, void 0, $.context);
|
|
404
|
+
} else value = $.SUBRULE($.valueList, { ARGS: [ctx] });
|
|
405
|
+
let important;
|
|
406
|
+
$.OPTION(() => {
|
|
407
|
+
important = $.CONSUME(T.Important);
|
|
408
|
+
});
|
|
409
|
+
if (!$.RECORDING_PHASE) {
|
|
410
|
+
let nameNode;
|
|
411
|
+
const nameValue = name.image;
|
|
412
|
+
if (nameValue.includes("@") || nameValue.includes("$")) nameNode = getInterpolatedNode(nameValue, $.getLocationInfo(name), $.context);
|
|
413
|
+
else nameNode = new Any(name.image, { role: "property" }, $.getLocationInfo(name), $.context);
|
|
414
|
+
return [
|
|
415
|
+
nameNode,
|
|
416
|
+
assign,
|
|
417
|
+
value,
|
|
418
|
+
important
|
|
419
|
+
];
|
|
420
|
+
}
|
|
421
|
+
} },
|
|
422
|
+
customPropertyAlt(() => $.CONSUME(T.InterpolatedCustomProperty), 2),
|
|
423
|
+
customPropertyAlt(() => $.CONSUME(T.CustomProperty), 3)
|
|
424
|
+
];
|
|
425
|
+
return cssDeclaration.call($, T, ruleAlt)(ctx);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function mediaInParens(T) {
|
|
429
|
+
const $ = this;
|
|
430
|
+
return (ctx = {}) => {
|
|
431
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
432
|
+
$.startRule();
|
|
433
|
+
$.CONSUME(T.LParen);
|
|
434
|
+
const node = $.OR([
|
|
435
|
+
{
|
|
436
|
+
GATE: () => $.startsMediaCondition(T),
|
|
437
|
+
ALT: () => $.SUBRULE($.mediaCondition, { ARGS: [ctx] })
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
GATE: () => isEscapedString($, T),
|
|
441
|
+
ALT: () => $.SUBRULE($.string, { ARGS: [ctx] })
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
GATE: () => $.isType(T.PropertyReference) || $.isType(T.NestedReference) || $.isType(T.AtName) || $.isType(T.HashName) || $.isType(T.DotName) || $.isType(T.ColorIdentStart) || $.isType(T.InterpolatedSelector),
|
|
445
|
+
ALT: () => {
|
|
446
|
+
const node = $.SUBRULE2($.valueReference, { ARGS: [{
|
|
447
|
+
...ctx,
|
|
448
|
+
requireAccessorsAfterMixinCall: true
|
|
449
|
+
}] });
|
|
450
|
+
return wrapAtRulePreludeExpression.call($, node, ctx);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
{ ALT: () => $.SUBRULE($.mediaFeature, { ARGS: [ctx] }) }
|
|
454
|
+
]);
|
|
455
|
+
$.CONSUME(T.RParen);
|
|
456
|
+
if (RECORDING_PHASE) return;
|
|
457
|
+
return new Paren(node, void 0, $.endRule(), $.context);
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function mediaQuery(T) {
|
|
461
|
+
const $ = this;
|
|
462
|
+
return (ctx = {}) => {
|
|
463
|
+
const preludeCtx = {
|
|
464
|
+
...ctx,
|
|
465
|
+
atRulePreludeBareVariableAs: "index"
|
|
466
|
+
};
|
|
467
|
+
return $.OR2([
|
|
468
|
+
{
|
|
469
|
+
GATE: () => $.startsMediaCondition(T),
|
|
470
|
+
ALT: () => $.SUBRULE($.mediaConditionWithoutOr, { ARGS: [preludeCtx] })
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
GATE: () => isEscapedString($, T),
|
|
474
|
+
ALT: () => $.SUBRULE($.lessMediaQueryFromString, { ARGS: [preludeCtx] })
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
GATE: () => startsLessMediaQueryReference($, T),
|
|
478
|
+
ALT: () => $.SUBRULE2($.lessMediaQueryFromReference, { ARGS: [preludeCtx] })
|
|
479
|
+
},
|
|
480
|
+
{ ALT: () => $.SUBRULE7($.mediaTypeQuery, { ARGS: [preludeCtx] }) }
|
|
481
|
+
]);
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function mediaCondition(T) {
|
|
485
|
+
const $ = this;
|
|
486
|
+
return (ctx = {}) => $.SUBRULE($.mediaConditionWithoutOr, { ARGS: [ctx] });
|
|
487
|
+
}
|
|
488
|
+
function lessMediaQueryFromString(T) {
|
|
489
|
+
const $ = this;
|
|
490
|
+
return (ctx = {}) => {
|
|
491
|
+
const first = $.SUBRULE($.string, { ARGS: [ctx] });
|
|
492
|
+
return $.SUBRULE($.lessMediaQueryTail, { ARGS: [{
|
|
493
|
+
...ctx,
|
|
494
|
+
startValue: first
|
|
495
|
+
}] });
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function lessMediaQueryFromReference(T) {
|
|
499
|
+
const $ = this;
|
|
500
|
+
return (ctx = {}) => {
|
|
501
|
+
const first = $.SUBRULE($.valueReference, { ARGS: [{
|
|
502
|
+
...ctx,
|
|
503
|
+
requireAccessorsAfterMixinCall: true
|
|
504
|
+
}] });
|
|
505
|
+
return $.SUBRULE2($.lessMediaQueryTail, { ARGS: [{
|
|
506
|
+
...ctx,
|
|
507
|
+
startValue: wrapAtRulePreludeExpression.call($, first, ctx)
|
|
508
|
+
}] });
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function lessMediaQueryTail(T) {
|
|
512
|
+
const $ = this;
|
|
513
|
+
return (ctx = {}) => {
|
|
514
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
515
|
+
$.startRule();
|
|
516
|
+
let nodes;
|
|
517
|
+
if (!RECORDING_PHASE) nodes = [ctx.startValue];
|
|
518
|
+
$.MANY({
|
|
519
|
+
GATE: () => $.isType(T.And),
|
|
520
|
+
DEF: () => {
|
|
521
|
+
const andToken = $.CONSUME(T.And);
|
|
522
|
+
const next = $.OR([
|
|
523
|
+
{
|
|
524
|
+
GATE: () => isEscapedString($, T),
|
|
525
|
+
ALT: () => $.SUBRULE2($.string, { ARGS: [ctx] })
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
GATE: () => startsLessMediaQueryReference($, T),
|
|
529
|
+
ALT: () => {
|
|
530
|
+
const next = $.SUBRULE2($.valueReference, { ARGS: [{
|
|
531
|
+
...ctx,
|
|
532
|
+
requireAccessorsAfterMixinCall: true
|
|
533
|
+
}] });
|
|
534
|
+
return wrapAtRulePreludeExpression.call($, next, ctx);
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
GATE: () => $.startsMediaCondition(T),
|
|
539
|
+
ALT: () => $.SUBRULE2($.mediaConditionWithoutOr, { ARGS: [ctx] })
|
|
540
|
+
},
|
|
541
|
+
{ ALT: () => $.SUBRULE2($.mediaType, { ARGS: [ctx] }) }
|
|
542
|
+
]);
|
|
543
|
+
if (!RECORDING_PHASE) {
|
|
544
|
+
nodes.push(new Keyword(andToken.image, void 0, $.getLocationInfo(andToken), $.context));
|
|
545
|
+
nodes.push(next);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
if (RECORDING_PHASE) return;
|
|
550
|
+
const location = $.endRule();
|
|
551
|
+
if (nodes.length === 1) return nodes[0];
|
|
552
|
+
return new QueryCondition(nodes, void 0, location, $.context);
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function mediaConditionWithoutOr(T) {
|
|
556
|
+
const $ = this;
|
|
557
|
+
return (ctx = {}) => $.OR([{ ALT: () => $.SUBRULE($.mediaNot, { ARGS: [ctx] }) }, { ALT: () => {
|
|
558
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
559
|
+
$.startRule();
|
|
560
|
+
let nodes;
|
|
561
|
+
if (!RECORDING_PHASE) nodes = [];
|
|
562
|
+
const node = $.SUBRULE($.mediaInParens, { ARGS: [ctx] });
|
|
563
|
+
if (!RECORDING_PHASE) nodes.push(node);
|
|
564
|
+
$.MANY({
|
|
565
|
+
GATE: () => $.isType(T.And),
|
|
566
|
+
DEF: () => {
|
|
567
|
+
const rule = $.SUBRULE($.mediaAnd, { ARGS: [ctx] });
|
|
568
|
+
if (!RECORDING_PHASE) nodes.push(...rule);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
if (RECORDING_PHASE) return;
|
|
572
|
+
if (nodes.length === 1) {
|
|
573
|
+
$.endRule();
|
|
574
|
+
return nodes[0];
|
|
575
|
+
}
|
|
576
|
+
return new QueryCondition(nodes, void 0, $.endRule(), $.context);
|
|
577
|
+
} }]);
|
|
578
|
+
}
|
|
579
|
+
function mediaFeature(T) {
|
|
580
|
+
const $ = this;
|
|
581
|
+
function createFeatureIdentNode(token, role) {
|
|
582
|
+
const location = $.getLocationInfo(token);
|
|
583
|
+
const resolved = getInterpolatedOrString(token.image, location, $.context);
|
|
584
|
+
if (typeof resolved === "string") return new Any(resolved, { role }, location, $.context);
|
|
585
|
+
return resolved;
|
|
586
|
+
}
|
|
587
|
+
return (ctx = {}) => $.OR([{
|
|
588
|
+
GATE: () => {
|
|
589
|
+
return $.isType(T.InterpolatedIdent) || $.isType(T.Ident);
|
|
590
|
+
},
|
|
591
|
+
ALT: () => {
|
|
592
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
593
|
+
$.startRule();
|
|
594
|
+
let rule;
|
|
595
|
+
const ident = $.LA(1).tokenType === T.InterpolatedIdent ? $.CONSUME(T.InterpolatedIdent) : $.CONSUME(T.Ident);
|
|
596
|
+
$.OPTION(() => {
|
|
597
|
+
rule = $.OR2([
|
|
598
|
+
{ ALT: () => {
|
|
599
|
+
$.CONSUME(T.Colon);
|
|
600
|
+
const value = $.SUBRULE($.mfValue, { ARGS: [ctx] });
|
|
601
|
+
if (!RECORDING_PHASE) {
|
|
602
|
+
const location = $.endRule();
|
|
603
|
+
const featureName = createFeatureIdentNode(ident, "property");
|
|
604
|
+
return new Declaration({
|
|
605
|
+
name: featureName instanceof Any ? String(featureName.valueOf()) : featureName,
|
|
606
|
+
value
|
|
607
|
+
}, void 0, location, $.context);
|
|
608
|
+
}
|
|
609
|
+
} },
|
|
610
|
+
{
|
|
611
|
+
GATE: () => ($.isTypeAt(1, T.MfLt) || $.isTypeAt(1, T.MfGt)) && ($.isTypeAt(2, T.Ident) || $.isTypeAt(2, T.InterpolatedIdent)),
|
|
612
|
+
ALT: () => {
|
|
613
|
+
const seq = $.SUBRULE($.mediaRange, { ARGS: [ctx] });
|
|
614
|
+
if (!RECORDING_PHASE) {
|
|
615
|
+
const [startOffset, startLine, startColumn] = $.endRule();
|
|
616
|
+
seq.value.unshift(createFeatureIdentNode(ident, "ident"));
|
|
617
|
+
seq.location.start = startOffset;
|
|
618
|
+
seq.location[1] = startLine;
|
|
619
|
+
seq.location[2] = startColumn;
|
|
620
|
+
return new QueryCondition(seq.value, void 0, seq.location, $.context);
|
|
621
|
+
}
|
|
622
|
+
return seq;
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
GATE: () => $.isTypeAt(1, T.MfLt) || $.isTypeAt(1, T.MfGt) || $.LA(1).tokenType === T.Eq,
|
|
627
|
+
ALT: () => {
|
|
628
|
+
const op = $.SUBRULE($.mfComparison, { ARGS: [ctx] });
|
|
629
|
+
const value = $.SUBRULE($.mfNonIdentifierValue, { ARGS: [ctx] });
|
|
630
|
+
if (!RECORDING_PHASE) {
|
|
631
|
+
const location = $.endRule();
|
|
632
|
+
return new QueryCondition([
|
|
633
|
+
createFeatureIdentNode(ident, "ident"),
|
|
634
|
+
new Any(op.image, { role: "operator" }, $.getLocationInfo(op), $.context),
|
|
635
|
+
value
|
|
636
|
+
], void 0, location, $.context);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
]);
|
|
641
|
+
});
|
|
642
|
+
if (!RECORDING_PHASE && !rule) {
|
|
643
|
+
const location = $.endRule();
|
|
644
|
+
return new QueryCondition([createFeatureIdentNode(ident, "ident")], void 0, location, $.context);
|
|
645
|
+
}
|
|
646
|
+
return rule;
|
|
647
|
+
}
|
|
648
|
+
}, { ALT: () => {
|
|
649
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
650
|
+
$.startRule();
|
|
651
|
+
const left = $.SUBRULE2($.mfNonIdentifierValue, { ARGS: [{ ...ctx }] });
|
|
652
|
+
return $.OR3([{
|
|
653
|
+
GATE: () => {
|
|
654
|
+
const tt2 = $.LA(2).tokenType;
|
|
655
|
+
if (!(($.isTypeAt(1, T.MfLt) || $.isTypeAt(1, T.MfGt) || $.LA(1).tokenType === T.Eq) && (tt2 === T.Ident || tt2 === T.InterpolatedIdent))) return false;
|
|
656
|
+
if ($.isTypeAt(3, T.MfLt) || $.isTypeAt(3, T.MfGt)) return false;
|
|
657
|
+
return true;
|
|
658
|
+
},
|
|
659
|
+
ALT: () => {
|
|
660
|
+
const op = $.SUBRULE2($.mfComparison, { ARGS: [{ ...ctx }] });
|
|
661
|
+
const value = $.LA(1).tokenType === T.Ident ? $.CONSUME2(T.Ident) : $.CONSUME2(T.InterpolatedIdent);
|
|
662
|
+
if (!RECORDING_PHASE) {
|
|
663
|
+
const location = $.endRule();
|
|
664
|
+
return new QueryCondition([
|
|
665
|
+
left,
|
|
666
|
+
new Any(op.image, { role: "operator" }, $.getLocationInfo(op), $.context),
|
|
667
|
+
createFeatureIdentNode(value, "ident")
|
|
668
|
+
], void 0, location, $.context);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}, { ALT: () => {
|
|
672
|
+
const seq = $.SUBRULE2($.mediaRange, { ARGS: [{ ...ctx }] });
|
|
673
|
+
if (!RECORDING_PHASE) {
|
|
674
|
+
const [startOffset, startLine, startColumn] = $.endRule();
|
|
675
|
+
seq.value.unshift(left);
|
|
676
|
+
seq.location.start = startOffset;
|
|
677
|
+
seq.location[1] = startLine;
|
|
678
|
+
seq.location[2] = startColumn;
|
|
679
|
+
return new QueryCondition(seq.value, void 0, seq.location, $.context);
|
|
680
|
+
}
|
|
681
|
+
return seq;
|
|
682
|
+
} }]);
|
|
683
|
+
} }]);
|
|
684
|
+
}
|
|
685
|
+
function mfValue(T) {
|
|
686
|
+
const $ = this;
|
|
687
|
+
return (ctx = {}) => {
|
|
688
|
+
/**
|
|
689
|
+
* Like the original Less Parser, we're
|
|
690
|
+
* going to allow any value expression,
|
|
691
|
+
* and it's up to the Less author to know
|
|
692
|
+
* if it's valid.
|
|
693
|
+
*/
|
|
694
|
+
const exprCtx = {
|
|
695
|
+
...ctx,
|
|
696
|
+
wrapInExpression: true
|
|
697
|
+
};
|
|
698
|
+
const node = $.SUBRULE($.expressionSum, { ARGS: [exprCtx] });
|
|
699
|
+
return wrapOuterExpressionIfNeeded.call($, node, exprCtx);
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function mfNonIdentifierValue(T) {
|
|
703
|
+
const $ = this;
|
|
704
|
+
return (ctx = {}) => {
|
|
705
|
+
return $.OR2([
|
|
706
|
+
{
|
|
707
|
+
GATE: () => {
|
|
708
|
+
const next = $.LA(1);
|
|
709
|
+
return next.tokenType === T.AtKeyword || next.tokenType === T.PropertyReference || next.tokenType === T.NestedReference;
|
|
710
|
+
},
|
|
711
|
+
ALT: () => {
|
|
712
|
+
const node = $.SUBRULE($.valueReference, { ARGS: [{
|
|
713
|
+
...ctx,
|
|
714
|
+
requireAccessorsAfterMixinCall: true
|
|
715
|
+
}] });
|
|
716
|
+
return wrapAtRulePreludeExpression.call($, node, ctx);
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
{ ALT: () => {
|
|
720
|
+
$.startRule();
|
|
721
|
+
let num1 = $.CONSUME(T.Number);
|
|
722
|
+
let num2;
|
|
723
|
+
$.OPTION(() => {
|
|
724
|
+
$.CONSUME(T.Slash);
|
|
725
|
+
num2 = $.CONSUME2(T.Number);
|
|
726
|
+
});
|
|
727
|
+
let location = $.endRule();
|
|
728
|
+
let num1Node = $.processValueToken(num1);
|
|
729
|
+
if (!num2) return num1Node;
|
|
730
|
+
return new List([num1Node, $.processValueToken(num2)], { sep: "/" }, location, $.context);
|
|
731
|
+
} },
|
|
732
|
+
{ ALT: () => {
|
|
733
|
+
let dim = $.CONSUME(T.Dimension);
|
|
734
|
+
return $.processValueToken(dim);
|
|
735
|
+
} }
|
|
736
|
+
]);
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function wrappedDeclarationList(T) {
|
|
740
|
+
const $ = this;
|
|
741
|
+
return (ctx = {}) => {
|
|
742
|
+
$.CONSUME(T.LCurly);
|
|
743
|
+
let rules = $.SUBRULE($.declarationList, { ARGS: [ctx] });
|
|
744
|
+
$.CONSUME(T.RCurly);
|
|
745
|
+
return rules;
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function qualifiedRuleBody(T) {
|
|
749
|
+
const $ = this;
|
|
750
|
+
return (ctx = {}) => {
|
|
751
|
+
let selector;
|
|
752
|
+
let isSelectorList;
|
|
753
|
+
selector = ctx.selector;
|
|
754
|
+
isSelectorList = typeof ctx.isSelectorList === "boolean" ? ctx.isSelectorList : selector instanceof SelectorList;
|
|
755
|
+
let guard;
|
|
756
|
+
if (!isSelectorList) $.OPTION(() => {
|
|
757
|
+
guard = $.SUBRULE($.guard, { ARGS: [ctx] });
|
|
758
|
+
});
|
|
759
|
+
$.CONSUME(T.LCurly);
|
|
760
|
+
let savedExtendNodes;
|
|
761
|
+
if (!$.RECORDING_PHASE) {
|
|
762
|
+
savedExtendNodes = ctx.extendNodes ? [...ctx.extendNodes] : void 0;
|
|
763
|
+
ctx.extendNodes = void 0;
|
|
764
|
+
}
|
|
765
|
+
let rules = $.SUBRULE2($.declarationList, { ARGS: [ctx] });
|
|
766
|
+
let end = $.CONSUME(T.RCurly);
|
|
767
|
+
if (!$.RECORDING_PHASE) {
|
|
768
|
+
const newExtends = ctx.extendNodes;
|
|
769
|
+
if (newExtends && newExtends.length) if (savedExtendNodes && savedExtendNodes.length > 0) ctx.extendNodes = [...savedExtendNodes, ...newExtends];
|
|
770
|
+
else ctx.extendNodes = newExtends;
|
|
771
|
+
else ctx.extendNodes = savedExtendNodes;
|
|
772
|
+
let extend = ctx.extendNodes;
|
|
773
|
+
if (extend?.length)
|
|
774
|
+
/** If it's not a selector list, then our only extend does not need to be grouped */
|
|
775
|
+
if (!isSelectorList) {
|
|
776
|
+
/** For extends inside rulesets (not bubbled), selector should be undefined
|
|
777
|
+
* so it defaults to ampersand and resolves to the ruleset's selector */
|
|
778
|
+
extend = extend.map((e) => extendWithSelector$1(e, void 0, $.context));
|
|
779
|
+
rules = prependRules(rules, extend, $.context);
|
|
780
|
+
ctx.extendNodes = void 0;
|
|
781
|
+
} else {
|
|
782
|
+
const selectorList = selector instanceof SelectorList ? selector : void 0;
|
|
783
|
+
if (!selectorList) return;
|
|
784
|
+
const selectorCount = selectorList.value.length;
|
|
785
|
+
const extendCount = extend.length;
|
|
786
|
+
let shouldBubble = false;
|
|
787
|
+
if (extendCount < selectorCount) shouldBubble = true;
|
|
788
|
+
else if (extendCount === selectorCount) {
|
|
789
|
+
let finalExtends = groupExtendsByTargetAndFlag(extend);
|
|
790
|
+
if (finalExtends.length === 1) {
|
|
791
|
+
let extendNodes = finalExtends[0];
|
|
792
|
+
let finalExtend = isArray$1(extendNodes) ? extendNodes[0] : extendNodes;
|
|
793
|
+
finalExtend = extendWithSelector$1(finalExtend, void 0, $.context);
|
|
794
|
+
rules = prependRules(rules, [finalExtend], $.context);
|
|
795
|
+
ctx.extendNodes = void 0;
|
|
796
|
+
} else shouldBubble = true;
|
|
797
|
+
} else shouldBubble = true;
|
|
798
|
+
if (shouldBubble) {}
|
|
799
|
+
}
|
|
800
|
+
const hasDefault = Boolean(ctx.hasDefault);
|
|
801
|
+
let node = new Ruleset({
|
|
802
|
+
selector,
|
|
803
|
+
rules: rules.rules,
|
|
804
|
+
guard
|
|
805
|
+
}, guard && hasDefault ? { hasDefault } : void 0, void 0, $.context);
|
|
806
|
+
ctx.hasDefault = false;
|
|
807
|
+
let [startOffset, startLine, startColumn] = selector.location;
|
|
808
|
+
let { endOffset, endLine, endColumn } = end;
|
|
809
|
+
node._location = [
|
|
810
|
+
startOffset,
|
|
811
|
+
startLine,
|
|
812
|
+
startColumn,
|
|
813
|
+
endOffset,
|
|
814
|
+
endLine,
|
|
815
|
+
endColumn
|
|
816
|
+
];
|
|
817
|
+
return node;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
function qualifiedRule(T) {
|
|
822
|
+
const $ = this;
|
|
823
|
+
return (ctx = {}, altContext) => {
|
|
824
|
+
let selectorAlt = altContext ?? ((ctx) => [{
|
|
825
|
+
GATE: () => !ctx.inner,
|
|
826
|
+
ALT: () => {
|
|
827
|
+
let initialQualifiedRule = ctx.qualifiedRule;
|
|
828
|
+
ctx.qualifiedRule = true;
|
|
829
|
+
try {
|
|
830
|
+
return $.SUBRULE($.selectorList, { ARGS: [ctx] });
|
|
831
|
+
} finally {
|
|
832
|
+
ctx.qualifiedRule = initialQualifiedRule;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}, {
|
|
836
|
+
GATE: () => !!ctx.inner,
|
|
837
|
+
ALT: () => {
|
|
838
|
+
let initialQualifiedRule = ctx.qualifiedRule;
|
|
839
|
+
let initialFirstSelector = ctx.firstSelector;
|
|
840
|
+
ctx.firstSelector = true;
|
|
841
|
+
ctx.qualifiedRule = true;
|
|
842
|
+
try {
|
|
843
|
+
return $.SUBRULE2($.forgivingSelectorList, { ARGS: [ctx] });
|
|
844
|
+
} finally {
|
|
845
|
+
ctx.qualifiedRule = initialQualifiedRule;
|
|
846
|
+
ctx.firstSelector = initialFirstSelector;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}]);
|
|
850
|
+
let savedExtendNodes = ctx.extendNodes ? [...ctx.extendNodes] : void 0;
|
|
851
|
+
ctx.extendNodes = void 0;
|
|
852
|
+
let selector = $.OR(selectorAlt(ctx));
|
|
853
|
+
ctx.selector = selector;
|
|
854
|
+
let thisExtendNodes = ctx.extendNodes ? [...ctx.extendNodes] : void 0;
|
|
855
|
+
ctx.extendNodes = void 0;
|
|
856
|
+
let rule = $.SUBRULE3($.qualifiedRuleBody, { ARGS: [ctx] });
|
|
857
|
+
const bubblingExtends = ctx.extendNodes;
|
|
858
|
+
ctx.extendNodes = thisExtendNodes;
|
|
859
|
+
let parentExtendNodes = savedExtendNodes;
|
|
860
|
+
if (ctx.extendNodes) {
|
|
861
|
+
let qRuleset = rule;
|
|
862
|
+
for (const extendNode of ctx.extendNodes) {
|
|
863
|
+
const { selector: extendSelector } = extendNode;
|
|
864
|
+
if (extendSelector === void 0 || extendSelector instanceof Ampersand) {
|
|
865
|
+
const index = ctx.extendNodes.indexOf(extendNode);
|
|
866
|
+
ctx.extendNodes[index] = extendWithSelector$1(extendNode, selector, $.context);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
/** Prepend a rules block */
|
|
870
|
+
rule = new Rules([...ctx.extendNodes, qRuleset]);
|
|
871
|
+
if (qRuleset._location) rule._location = qRuleset._location;
|
|
872
|
+
ctx.extendNodes = void 0;
|
|
873
|
+
}
|
|
874
|
+
if (bubblingExtends && bubblingExtends.length > 0) if (parentExtendNodes && parentExtendNodes.length > 0) ctx.extendNodes = [...parentExtendNodes, ...bubblingExtends];
|
|
875
|
+
else ctx.extendNodes = bubblingExtends;
|
|
876
|
+
else ctx.extendNodes = parentExtendNodes;
|
|
877
|
+
return rule;
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* In order to not do any backtracking, anything with a class or id selector start
|
|
882
|
+
* will end up here, and everything else will be shunted to the qualified rule.
|
|
883
|
+
*/
|
|
884
|
+
function mixinOrQualifiedRule(T) {
|
|
885
|
+
const $ = this;
|
|
886
|
+
return (ctx = {}) => {
|
|
887
|
+
const convertArgsForDefinition = (args) => {
|
|
888
|
+
if (!args || !args.value.length) return;
|
|
889
|
+
for (let i = 0; i < args.value.length; i++) {
|
|
890
|
+
const node = args.value[i];
|
|
891
|
+
const location = node.location.length ? node.location : void 0;
|
|
892
|
+
if (isNode(node, N.Any) && node.role === "name") {
|
|
893
|
+
const replacement = new VarDeclaration({
|
|
894
|
+
name: String(node.valueOf()),
|
|
895
|
+
value: new Nil(void 0, void 0, location, $.context)
|
|
896
|
+
}, { paramVar: true }, location, $.context);
|
|
897
|
+
args.adopt(replacement);
|
|
898
|
+
args.value[i] = replacement;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
const convertArgsForCall = (args) => {
|
|
903
|
+
if (!args || !args.value.length) return;
|
|
904
|
+
for (let i = 0; i < args.value.length; i++) {
|
|
905
|
+
const node = args.value[i];
|
|
906
|
+
const location = node.location.length ? node.location : void 0;
|
|
907
|
+
let replacement;
|
|
908
|
+
if (isNode(node, N.Any) && node.role === "name") replacement = new Reference({ key: node.valueOf() }, { type: "variable" }, location, $.context);
|
|
909
|
+
else if (node instanceof Rest) {
|
|
910
|
+
const restValue = node.value;
|
|
911
|
+
if (typeof restValue === "string") replacement = new Rest(new Reference({ key: restValue }, { type: "variable" }, location, $.context), void 0, location, $.context);
|
|
912
|
+
}
|
|
913
|
+
if (replacement) {
|
|
914
|
+
args.adopt(replacement);
|
|
915
|
+
args.value[i] = replacement;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
$.startRule();
|
|
920
|
+
let selector = $.OR([{
|
|
921
|
+
GATE: () => !ctx.inner,
|
|
922
|
+
ALT: () => {
|
|
923
|
+
let initialQualifiedRule = ctx.qualifiedRule;
|
|
924
|
+
ctx.qualifiedRule = true;
|
|
925
|
+
try {
|
|
926
|
+
return $.SUBRULE($.selectorList, { ARGS: [ctx] });
|
|
927
|
+
} finally {
|
|
928
|
+
ctx.qualifiedRule = initialQualifiedRule;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}, {
|
|
932
|
+
GATE: () => !!ctx.inner,
|
|
933
|
+
ALT: () => {
|
|
934
|
+
let initialQualifiedRule = ctx.qualifiedRule;
|
|
935
|
+
let initialFirstSelector = ctx.firstSelector;
|
|
936
|
+
ctx.firstSelector = true;
|
|
937
|
+
ctx.qualifiedRule = true;
|
|
938
|
+
try {
|
|
939
|
+
return $.SUBRULE2($.forgivingSelectorList, { ARGS: [ctx] });
|
|
940
|
+
} finally {
|
|
941
|
+
ctx.qualifiedRule = initialQualifiedRule;
|
|
942
|
+
ctx.firstSelector = initialFirstSelector;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}]);
|
|
946
|
+
let isSelectorList = selector instanceof SelectorList;
|
|
947
|
+
let guard;
|
|
948
|
+
let args;
|
|
949
|
+
let important;
|
|
950
|
+
const createMixinCall = (location) => {
|
|
951
|
+
let leftNode;
|
|
952
|
+
if (!isSelectorList && (selector instanceof CompoundSelector || selector instanceof BasicSelector || selector instanceof InterpolatedSelector || selector instanceof ComplexSelector)) {
|
|
953
|
+
const { key, rawKey } = normalizeMixinReferenceKey(selector);
|
|
954
|
+
leftNode = new Reference({
|
|
955
|
+
key,
|
|
956
|
+
rawKey
|
|
957
|
+
}, {
|
|
958
|
+
type: "mixin-ruleset",
|
|
959
|
+
role: "name"
|
|
960
|
+
}, void 0, $.context);
|
|
961
|
+
} else for (let s of selector.nodes()) if (s instanceof BasicSelector) leftNode = new Reference({
|
|
962
|
+
target: leftNode instanceof Reference ? leftNode : leftNode instanceof Call ? leftNode : void 0,
|
|
963
|
+
key: s.valueOf()
|
|
964
|
+
}, {
|
|
965
|
+
type: "mixin-ruleset",
|
|
966
|
+
role: "name"
|
|
967
|
+
}, void 0, $.context);
|
|
968
|
+
/** Finally, pass this reference into a call */
|
|
969
|
+
leftNode = new Call({
|
|
970
|
+
name: leftNode,
|
|
971
|
+
args
|
|
972
|
+
}, { markImportant: !!important }, location, $.context);
|
|
973
|
+
return leftNode;
|
|
974
|
+
};
|
|
975
|
+
let isPossibleMixinDefinition = selector instanceof BasicSelector && (selector.isClass || selector.isId) || selector instanceof InterpolatedSelector && (selector.isClass || selector.isId);
|
|
976
|
+
let isPossibleMixinCall = true;
|
|
977
|
+
if (!$.RECORDING_PHASE && !isSelectorList && !isPossibleMixinDefinition) for (let s of selector.nodes()) {
|
|
978
|
+
/** Keep going until we get to basic value. */
|
|
979
|
+
if (s instanceof ComplexSelector || s instanceof CompoundSelector) continue;
|
|
980
|
+
if (s instanceof BasicSelector && (s.isClass || s.isId) || s instanceof InterpolatedSelector && (s.isClass || s.isId) || s instanceof Combinator && (s.value === ">" || s.value === " ")) continue;
|
|
981
|
+
isPossibleMixinCall = false;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
return $.OR2([
|
|
985
|
+
{
|
|
986
|
+
GATE: () => (isPossibleMixinDefinition || isPossibleMixinCall) && $.isType(T.LParen),
|
|
987
|
+
ALT: () => {
|
|
988
|
+
args = $.SUBRULE3($.mixinArgs, { ARGS: [ctx] });
|
|
989
|
+
let next = $.LA(1).tokenType;
|
|
990
|
+
if (next === T.LCurly || next === T.When) isPossibleMixinCall = false;
|
|
991
|
+
return $.OR3([{
|
|
992
|
+
GATE: () => isPossibleMixinDefinition,
|
|
993
|
+
ALT: () => {
|
|
994
|
+
$.OPTION(() => {
|
|
995
|
+
guard = $.SUBRULE4($.guard, { ARGS: [ctx] });
|
|
996
|
+
});
|
|
997
|
+
$.CONSUME(T.LCurly);
|
|
998
|
+
let rules = $.SUBRULE5($.declarationList, { ARGS: [ctx] });
|
|
999
|
+
$.CONSUME(T.RCurly);
|
|
1000
|
+
if (!$.RECORDING_PHASE) {
|
|
1001
|
+
convertArgsForDefinition(args);
|
|
1002
|
+
const guardText = String(guard?.toString?.() ?? "");
|
|
1003
|
+
const hasDefault = Boolean(ctx.hasDefault) || guardContainsDefaultCall(guard) || guardText.includes("??()");
|
|
1004
|
+
const node = new Mixin({
|
|
1005
|
+
name: selector.valueOf(),
|
|
1006
|
+
params: args,
|
|
1007
|
+
rules: rules.rules,
|
|
1008
|
+
guard
|
|
1009
|
+
}, guard && hasDefault ? { hasDefault } : void 0, $.endRule(), $.context);
|
|
1010
|
+
ctx.hasDefault = false;
|
|
1011
|
+
return node;
|
|
1012
|
+
}
|
|
1013
|
+
$.endRule();
|
|
1014
|
+
}
|
|
1015
|
+
}, {
|
|
1016
|
+
GATE: () => isPossibleMixinCall,
|
|
1017
|
+
ALT: () => {
|
|
1018
|
+
$.OPTION2(() => {
|
|
1019
|
+
important = $.CONSUME(T.Important);
|
|
1020
|
+
});
|
|
1021
|
+
let location = $.endRule();
|
|
1022
|
+
if (!$.RECORDING_PHASE) convertArgsForCall(args);
|
|
1023
|
+
let result;
|
|
1024
|
+
{
|
|
1025
|
+
/** in Less legacy mode, mixin calls can happen without a space. */
|
|
1026
|
+
let noSpace = $.noSep();
|
|
1027
|
+
let next = $.LA(1).tokenType;
|
|
1028
|
+
if (noSpace && next === T.LSquare || (noSpace || $.looseMode) && next === T.LParen) result = $.OPTION3(() => $.SUBRULE6($.lookupOrCall, { ARGS: [{
|
|
1029
|
+
...ctx,
|
|
1030
|
+
node: $.RECORDING_PHASE ? void 0 : createMixinCall(location)
|
|
1031
|
+
}] }));
|
|
1032
|
+
}
|
|
1033
|
+
return $.RECORDING_PHASE ? void 0 : result ?? createMixinCall(location);
|
|
1034
|
+
}
|
|
1035
|
+
}]);
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
GATE: () => isPossibleMixinCall && $.isType(T.Semi),
|
|
1040
|
+
ALT: () => {
|
|
1041
|
+
const semi = $.CONSUME(T.Semi);
|
|
1042
|
+
const location = $.endRule();
|
|
1043
|
+
if (!$.RECORDING_PHASE) {
|
|
1044
|
+
$.warnDeprecation("Calling a mixin without parentheses is deprecated", semi, "mixin-call-no-parens");
|
|
1045
|
+
return createMixinCall(location);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
},
|
|
1049
|
+
{ ALT: () => {
|
|
1050
|
+
$.endRule();
|
|
1051
|
+
let initialSelector = ctx.selector;
|
|
1052
|
+
let initialIsSelectorList = ctx.isSelectorList;
|
|
1053
|
+
ctx.selector = selector;
|
|
1054
|
+
ctx.isSelectorList = isSelectorList;
|
|
1055
|
+
let rule;
|
|
1056
|
+
try {
|
|
1057
|
+
rule = $.SUBRULE7($.qualifiedRuleBody, { ARGS: [ctx] });
|
|
1058
|
+
} finally {
|
|
1059
|
+
ctx.selector = initialSelector;
|
|
1060
|
+
ctx.isSelectorList = initialIsSelectorList;
|
|
1061
|
+
}
|
|
1062
|
+
if (ctx.extendNodes) {
|
|
1063
|
+
/** Prepend a rules block */
|
|
1064
|
+
let qRule = rule;
|
|
1065
|
+
for (const extendNode of ctx.extendNodes) {
|
|
1066
|
+
const { selector: extendSelector } = extendNode;
|
|
1067
|
+
if (extendSelector === void 0 || extendSelector instanceof Ampersand) {
|
|
1068
|
+
const index = ctx.extendNodes.indexOf(extendNode);
|
|
1069
|
+
ctx.extendNodes[index] = extendWithSelector$1(extendNode, selector, $.context);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
rule = new Rules([...ctx.extendNodes, qRule]);
|
|
1073
|
+
rule._location = qRule._location;
|
|
1074
|
+
ctx.extendNodes = void 0;
|
|
1075
|
+
}
|
|
1076
|
+
return rule;
|
|
1077
|
+
} }
|
|
1078
|
+
]);
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/productions/selectors.ts
|
|
1083
|
+
const COMBINATORS = new Set([
|
|
1084
|
+
" ",
|
|
1085
|
+
">",
|
|
1086
|
+
"+",
|
|
1087
|
+
"~",
|
|
1088
|
+
"|",
|
|
1089
|
+
"||"
|
|
1090
|
+
]);
|
|
1091
|
+
function toCombinator(image) {
|
|
1092
|
+
if (COMBINATORS.has(image)) return image;
|
|
1093
|
+
throw new Error(`Unexpected selector combinator "${image}".`);
|
|
1094
|
+
}
|
|
1095
|
+
function isComplexSelectorComponentNode(node) {
|
|
1096
|
+
return node instanceof Call || node instanceof Selector && !(node instanceof SelectorList) && !(node instanceof ComplexSelector);
|
|
1097
|
+
}
|
|
1098
|
+
function attributeSelector(T, valueAlt) {
|
|
1099
|
+
const $ = this;
|
|
1100
|
+
valueAlt ??= () => [
|
|
1101
|
+
{
|
|
1102
|
+
GATE: () => !$.isType(T.InterpolatedIdent),
|
|
1103
|
+
ALT: () => {
|
|
1104
|
+
const token = $.CONSUME5(T.Ident);
|
|
1105
|
+
if ($.RECORDING_PHASE) return;
|
|
1106
|
+
return new Any(token.image, { role: "ident" }, $.getLocationInfo(token), $.context);
|
|
1107
|
+
}
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
GATE: () => $.isType(T.InterpolatedIdent),
|
|
1111
|
+
ALT: () => {
|
|
1112
|
+
const token = $.CONSUME(T.InterpolatedIdent);
|
|
1113
|
+
if ($.RECORDING_PHASE) return;
|
|
1114
|
+
const match = /([$@])\{([^}]+)\}/.exec(token.image);
|
|
1115
|
+
if (match && match[0] === token.image) return createInterpolatedReference(match[1], match[2], $.getLocationInfo(token), $.context);
|
|
1116
|
+
const result = getInterpolatedOrString(token.image, $.getLocationInfo(token), $.context);
|
|
1117
|
+
return typeof result === "string" ? new Any(result, { role: "ident" }, $.getLocationInfo(token), $.context) : result;
|
|
1118
|
+
}
|
|
1119
|
+
},
|
|
1120
|
+
{ ALT: () => $.SUBRULE($.string) }
|
|
1121
|
+
];
|
|
1122
|
+
return (ctx = {}) => {
|
|
1123
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
1124
|
+
$.startRule();
|
|
1125
|
+
$.CONSUME2(T.LSquare);
|
|
1126
|
+
const key = $.SUBRULE2($.attributeName);
|
|
1127
|
+
let op;
|
|
1128
|
+
let value;
|
|
1129
|
+
let mod;
|
|
1130
|
+
$.OPTION(() => {
|
|
1131
|
+
op = $.OR([{ ALT: () => $.CONSUME4(T.Eq) }, { ALT: () => $.CONSUME6(T.AttrMatch) }]);
|
|
1132
|
+
value = $.OR2(valueAlt(ctx));
|
|
1133
|
+
});
|
|
1134
|
+
$.OPTION2(() => mod = $.CONSUME7(T.AttrFlag));
|
|
1135
|
+
$.CONSUME8(T.RSquare);
|
|
1136
|
+
if (!RECORDING_PHASE) {
|
|
1137
|
+
const location = $.endRule();
|
|
1138
|
+
return new AttributeSelector({
|
|
1139
|
+
name: key.valueOf(),
|
|
1140
|
+
op: op?.image,
|
|
1141
|
+
value,
|
|
1142
|
+
mod: mod?.image
|
|
1143
|
+
}, void 0, location, $.context);
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
function getAmpersandTemplateValue(image) {
|
|
1148
|
+
if (image === "&") return;
|
|
1149
|
+
if (image.startsWith("&")) return image.slice(1) || void 0;
|
|
1150
|
+
if (image.includes("&")) return image;
|
|
1151
|
+
}
|
|
1152
|
+
const { isArray } = Array;
|
|
1153
|
+
function getAllowedExtendSelectors(context) {
|
|
1154
|
+
return context.opts.allowExtendSelectors;
|
|
1155
|
+
}
|
|
1156
|
+
function findDisallowedExtendSelector(selector, allowed) {
|
|
1157
|
+
if (typeof selector === "string") return;
|
|
1158
|
+
if (!allowed) return;
|
|
1159
|
+
if (isNode(selector, N.SelectorList)) {
|
|
1160
|
+
for (const item of selector.value) {
|
|
1161
|
+
const disallowed = findDisallowedExtendSelector(item, allowed);
|
|
1162
|
+
if (disallowed) return disallowed;
|
|
1163
|
+
}
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
const kinds = isNode(selector, N.BasicSelector) ? ["simple", "basic"] : isNode(selector, N.PseudoSelector) ? ["simple", "pseudo"] : isNode(selector, N.CompoundSelector) ? ["compound"] : isNode(selector, N.ComplexSelector) ? ["complex"] : ["simple"];
|
|
1167
|
+
if (kinds.some((kind) => allowed.includes(kind))) return;
|
|
1168
|
+
return {
|
|
1169
|
+
kind: kinds[0],
|
|
1170
|
+
selector
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
function formatAllowedExtendSelectors(allowed) {
|
|
1174
|
+
if (allowed.length === 0) return "no selector kinds";
|
|
1175
|
+
if (allowed.length === 1) return `${allowed[0]} value`;
|
|
1176
|
+
return `${allowed.slice(0, -1).join(", ")}, or ${allowed[allowed.length - 1]} value`;
|
|
1177
|
+
}
|
|
1178
|
+
function validateExtendTarget($, selector, source) {
|
|
1179
|
+
const allowed = getAllowedExtendSelectors($.context);
|
|
1180
|
+
const disallowed = findDisallowedExtendSelector(selector, allowed);
|
|
1181
|
+
if (!disallowed || !allowed) return;
|
|
1182
|
+
throw new Error(`${source} only allows ${formatAllowedExtendSelectors(allowed)}, but found ${disallowed.kind} selector "${disallowed.selector.valueOf()}".`);
|
|
1183
|
+
}
|
|
1184
|
+
function mergeExtends(selector, extendTargets, location, context, flag) {
|
|
1185
|
+
let extendNodes;
|
|
1186
|
+
let currentTarget = extendTargets[0].target;
|
|
1187
|
+
let currentFlag = extendTargets[0].flag ?? flag ? 0 : 1;
|
|
1188
|
+
let currentNode = new Extend({
|
|
1189
|
+
selector,
|
|
1190
|
+
target: currentTarget,
|
|
1191
|
+
flag: currentFlag
|
|
1192
|
+
}, void 0, location, context);
|
|
1193
|
+
const flushCurrent = () => {
|
|
1194
|
+
(extendNodes ??= []).push(currentNode);
|
|
1195
|
+
};
|
|
1196
|
+
for (let i = 1; i < extendTargets.length; i++) {
|
|
1197
|
+
let ext = extendTargets[i];
|
|
1198
|
+
let thisFlag = ext.flag ?? flag ? 0 : 1;
|
|
1199
|
+
/**
|
|
1200
|
+
* Merge extends. We do this instead of merging earlier so that
|
|
1201
|
+
* selector lists with different flags are not merged.
|
|
1202
|
+
*/
|
|
1203
|
+
if (thisFlag === currentFlag) {
|
|
1204
|
+
const { target } = currentNode;
|
|
1205
|
+
let nextTarget;
|
|
1206
|
+
if (!(target instanceof SelectorList)) nextTarget = new SelectorList([target, ext.target], void 0, location, context);
|
|
1207
|
+
else nextTarget = new SelectorList([...target.value, ext.target], void 0, location, context);
|
|
1208
|
+
currentNode = new Extend({
|
|
1209
|
+
selector,
|
|
1210
|
+
target: nextTarget,
|
|
1211
|
+
flag: currentFlag
|
|
1212
|
+
}, void 0, location, context);
|
|
1213
|
+
} else {
|
|
1214
|
+
flushCurrent();
|
|
1215
|
+
currentFlag = thisFlag;
|
|
1216
|
+
currentTarget = ext.target;
|
|
1217
|
+
currentNode = new Extend({
|
|
1218
|
+
selector,
|
|
1219
|
+
target: currentTarget,
|
|
1220
|
+
flag: currentFlag
|
|
1221
|
+
}, void 0, location, context);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
if (!extendNodes) return currentNode;
|
|
1225
|
+
flushCurrent();
|
|
1226
|
+
if (extendNodes.length === 1) return extendNodes[0];
|
|
1227
|
+
return extendNodes;
|
|
1228
|
+
}
|
|
1229
|
+
function extendWithSelector(node, selector, location, context) {
|
|
1230
|
+
return new Extend({
|
|
1231
|
+
selector,
|
|
1232
|
+
target: node.target,
|
|
1233
|
+
namespace: node.namespace,
|
|
1234
|
+
flag: node.flag
|
|
1235
|
+
}, void 0, location, context);
|
|
1236
|
+
}
|
|
1237
|
+
/** True for a node that could be one item in the old unquoted selector list (e.g. .a or #id). */
|
|
1238
|
+
function isSelectorLikeListItem(node) {
|
|
1239
|
+
if (node.type === "SelectorCapture" || isNode(node, N.Call)) return false;
|
|
1240
|
+
if (isNode(node, N.Reference)) return node.options.type === "mixin-ruleset";
|
|
1241
|
+
if (node instanceof List) return node.value.length > 0 && node.value.every(isSelectorLikeListItem);
|
|
1242
|
+
if (node instanceof Sequence) return node.value.length > 0 && node.value.every(isSelectorLikeListItem);
|
|
1243
|
+
return false;
|
|
1244
|
+
}
|
|
1245
|
+
/** True only for the legacy unquoted selector-list form (e.g. @var: .a, .b, .c), not @var: .a; */
|
|
1246
|
+
function isLegacySelectorLikeValue(node) {
|
|
1247
|
+
if (node.type === "SelectorCapture" || isNode(node, N.Call)) return false;
|
|
1248
|
+
if (isNode(node, N.Reference)) return false;
|
|
1249
|
+
if (node instanceof List) return node.value.length > 1 && node.value.every(isSelectorLikeListItem);
|
|
1250
|
+
if (node instanceof Sequence) return node.value.length > 1 && node.value.every(isSelectorLikeListItem);
|
|
1251
|
+
return false;
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* We need to now handle a returned `Extend` node from the complexSelector rule
|
|
1255
|
+
*/
|
|
1256
|
+
function relativeSelector(T) {
|
|
1257
|
+
const $ = this;
|
|
1258
|
+
return (ctx = {}) => {
|
|
1259
|
+
return $.OR([{ ALT: () => {
|
|
1260
|
+
let co = $.CONSUME(T.Combinator);
|
|
1261
|
+
let node = $.SUBRULE2($.complexSelector, { ARGS: [ctx] });
|
|
1262
|
+
if ($.RECORDING_PHASE) return node;
|
|
1263
|
+
let combinator = new Combinator(toCombinator(co.image), void 0, $.getLocationInfo(co), $.context);
|
|
1264
|
+
let targetNode = node instanceof Extend ? node.selector : node;
|
|
1265
|
+
if (targetNode instanceof ComplexSelector) {
|
|
1266
|
+
const nodes = [combinator, ...targetNode.value];
|
|
1267
|
+
const complex = new ComplexSelector(nodes, void 0, $.getLocationFromNodes(nodes), $.context);
|
|
1268
|
+
if (node instanceof Extend) {
|
|
1269
|
+
const location = node.location.length === 6 ? [...node.location] : void 0;
|
|
1270
|
+
if (location) {
|
|
1271
|
+
location[0] = co.startOffset;
|
|
1272
|
+
location[1] = co.startLine;
|
|
1273
|
+
location[2] = co.startColumn;
|
|
1274
|
+
}
|
|
1275
|
+
node = extendWithSelector(node, complex, location, $.context);
|
|
1276
|
+
} else node = complex;
|
|
1277
|
+
} else {
|
|
1278
|
+
if (!isComplexSelectorComponentNode(targetNode)) {
|
|
1279
|
+
const targetType = typeof targetNode === "string" ? "string" : targetNode?.type ?? "none";
|
|
1280
|
+
throw new Error(`Expected selector component after relative combinator; got ${targetType}.`);
|
|
1281
|
+
}
|
|
1282
|
+
let nodes = [combinator, targetNode];
|
|
1283
|
+
let complex = new ComplexSelector(nodes, void 0, $.getLocationFromNodes(nodes), $.context);
|
|
1284
|
+
if (node instanceof Extend) {
|
|
1285
|
+
const location = node.location.length === 6 ? [...node.location] : void 0;
|
|
1286
|
+
if (location) {
|
|
1287
|
+
location[0] = co.startOffset;
|
|
1288
|
+
location[1] = co.startLine;
|
|
1289
|
+
location[2] = co.startColumn;
|
|
1290
|
+
}
|
|
1291
|
+
node = extendWithSelector(node, complex, location, $.context);
|
|
1292
|
+
} else node = complex;
|
|
1293
|
+
}
|
|
1294
|
+
return node;
|
|
1295
|
+
} }, { ALT: () => $.SUBRULE3($.complexSelector, { ARGS: [ctx] }) }]);
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
function forgivingSelectorList(T) {
|
|
1299
|
+
const $ = this;
|
|
1300
|
+
return (ctx = {}) => {
|
|
1301
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
1302
|
+
$.startRule();
|
|
1303
|
+
let sequences;
|
|
1304
|
+
let i = 0;
|
|
1305
|
+
if (!RECORDING_PHASE) sequences = [];
|
|
1306
|
+
$.AT_LEAST_ONE_SEP({
|
|
1307
|
+
SEP: T.Comma,
|
|
1308
|
+
DEF: () => {
|
|
1309
|
+
const selector = $.SUBRULE($.relativeSelector, { ARGS: [ctx] });
|
|
1310
|
+
if (!RECORDING_PHASE) {
|
|
1311
|
+
i++;
|
|
1312
|
+
if (i === 1 && ctx.qualifiedRule) sequences.push(selector);
|
|
1313
|
+
else sequences.push(selector);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
if (RECORDING_PHASE) return;
|
|
1318
|
+
const location = $.endRule();
|
|
1319
|
+
if (sequences.length === 1) return sequences[0];
|
|
1320
|
+
return new SelectorList(sequences, void 0, location, $.context);
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
function selectorList(T) {
|
|
1324
|
+
const $ = this;
|
|
1325
|
+
return (ctx = {}) => {
|
|
1326
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
1327
|
+
$.startRule();
|
|
1328
|
+
let sequences;
|
|
1329
|
+
let i = 0;
|
|
1330
|
+
if (!RECORDING_PHASE) sequences = [];
|
|
1331
|
+
$.AT_LEAST_ONE_SEP({
|
|
1332
|
+
SEP: T.Comma,
|
|
1333
|
+
DEF: () => {
|
|
1334
|
+
const selector = $.SUBRULE2($.complexSelector, { ARGS: [ctx] });
|
|
1335
|
+
if (!RECORDING_PHASE) {
|
|
1336
|
+
i++;
|
|
1337
|
+
if (i === 1 && ctx.qualifiedRule) sequences.push(selector);
|
|
1338
|
+
else sequences.push(selector);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
if (RECORDING_PHASE) return;
|
|
1343
|
+
const location = $.endRule();
|
|
1344
|
+
if (sequences.length === 1) return sequences[0];
|
|
1345
|
+
return new SelectorList(sequences, void 0, location, $.context);
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function compoundSelector(T) {
|
|
1349
|
+
const $ = this;
|
|
1350
|
+
return (ctx = {}) => {
|
|
1351
|
+
/**
|
|
1352
|
+
A sequence of simple value that are not separated by
|
|
1353
|
+
a combinator.
|
|
1354
|
+
.e.g. `a#selected`
|
|
1355
|
+
*/
|
|
1356
|
+
let RECORDING_PHASE = $.RECORDING_PHASE;
|
|
1357
|
+
let value;
|
|
1358
|
+
if (!RECORDING_PHASE) value = [];
|
|
1359
|
+
let sel = $.SUBRULE($.simpleSelector, { ARGS: [ctx] });
|
|
1360
|
+
if (!RECORDING_PHASE) value.push(sel);
|
|
1361
|
+
$.MANY({
|
|
1362
|
+
GATE: () => !$.hasWS() && !(ctx.inExtend && $.isType(T.All)),
|
|
1363
|
+
DEF: () => {
|
|
1364
|
+
let sel = $.SUBRULE2($.simpleSelector, { ARGS: [ctx] });
|
|
1365
|
+
if (!RECORDING_PHASE) value.push(sel);
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
if (RECORDING_PHASE) return;
|
|
1369
|
+
if (value.length === 1) return value[0];
|
|
1370
|
+
return new CompoundSelector(value, void 0, $.getLocationFromNodes(value), $.context);
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Extended with :extend
|
|
1375
|
+
*/
|
|
1376
|
+
function complexSelector(T) {
|
|
1377
|
+
const $ = this;
|
|
1378
|
+
return (ctx = {}) => {
|
|
1379
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
1380
|
+
$.startRule();
|
|
1381
|
+
let value;
|
|
1382
|
+
if (!RECORDING_PHASE) value = [$.SUBRULE($.compoundSelector, { ARGS: [ctx] })];
|
|
1383
|
+
else $.SUBRULE($.compoundSelector, { ARGS: [ctx] });
|
|
1384
|
+
$.MANY({
|
|
1385
|
+
GATE: () => {
|
|
1386
|
+
if (ctx.inExtend && $.isType(T.All)) return false;
|
|
1387
|
+
return $.hasWS() || $.isType(T.Combinator);
|
|
1388
|
+
},
|
|
1389
|
+
DEF: () => {
|
|
1390
|
+
let co;
|
|
1391
|
+
let combinator;
|
|
1392
|
+
$.OPTION(() => {
|
|
1393
|
+
co = $.CONSUME(T.Combinator);
|
|
1394
|
+
});
|
|
1395
|
+
if (!RECORDING_PHASE) if (co) combinator = new Combinator(toCombinator(co.image), void 0, $.getLocationInfo(co), $.context);
|
|
1396
|
+
else {
|
|
1397
|
+
const ws = $.claimSpaceCombinator($.LA(1).startOffset);
|
|
1398
|
+
combinator = new Combinator(" ", void 0, ws ? $.getLocationInfo(ws) : void 0, $.context);
|
|
1399
|
+
}
|
|
1400
|
+
const compound = $.SUBRULE2($.compoundSelector, { ARGS: [ctx] });
|
|
1401
|
+
if (!RECORDING_PHASE) value.push(combinator, compound);
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
let selector;
|
|
1405
|
+
if (!RECORDING_PHASE) {
|
|
1406
|
+
const location = $.endRule();
|
|
1407
|
+
selector = value.length === 1 ? value[0] : new ComplexSelector(value, void 0, location, $.context);
|
|
1408
|
+
}
|
|
1409
|
+
let flag;
|
|
1410
|
+
/** Inside :extend(...), only consume the optional trailing "all" keyword. */
|
|
1411
|
+
$.OPTION2({
|
|
1412
|
+
GATE: () => !!ctx.inExtend && $.isType(T.All),
|
|
1413
|
+
DEF: () => {
|
|
1414
|
+
flag = $.CONSUME(T.All);
|
|
1415
|
+
}
|
|
1416
|
+
});
|
|
1417
|
+
/**
|
|
1418
|
+
* Outside :extend(...), only enter the extend production when the next token
|
|
1419
|
+
* is actually :extend(. Do not commit based on context alone.
|
|
1420
|
+
*/
|
|
1421
|
+
$.OPTION3({
|
|
1422
|
+
GATE: () => !ctx.inExtend && !!ctx.qualifiedRule && $.isType(T.Extend),
|
|
1423
|
+
DEF: () => {
|
|
1424
|
+
const initialSelector = ctx.selector;
|
|
1425
|
+
if (!RECORDING_PHASE) ctx.selector = selector;
|
|
1426
|
+
try {
|
|
1427
|
+
$.SUBRULE($.extend, { ARGS: [ctx] });
|
|
1428
|
+
} finally {
|
|
1429
|
+
ctx.selector = initialSelector;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
if (ctx.inExtend) {
|
|
1434
|
+
validateExtendTarget($, selector, ":extend()");
|
|
1435
|
+
(ctx.extendTargets ??= []).push({
|
|
1436
|
+
selector: ctx.selector,
|
|
1437
|
+
target: selector,
|
|
1438
|
+
flag
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
return selector;
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* &:extend(...) statement ending with a semicolon.
|
|
1446
|
+
* This is the only valid standalone extend statement in Less.
|
|
1447
|
+
*/
|
|
1448
|
+
function ampersandExtend(T) {
|
|
1449
|
+
const $ = this;
|
|
1450
|
+
return (ctx = {}) => {
|
|
1451
|
+
$.startRule();
|
|
1452
|
+
$.CONSUME(T.Ampersand);
|
|
1453
|
+
$.CONSUME(T.Extend);
|
|
1454
|
+
ctx.inExtend = true;
|
|
1455
|
+
$.SUBRULE($.selectorList, { ARGS: [ctx] });
|
|
1456
|
+
ctx.inExtend = false;
|
|
1457
|
+
let extendTargets = ctx.extendTargets;
|
|
1458
|
+
let flag = $.OPTION(() => $.CONSUME(T.AllFlag));
|
|
1459
|
+
$.CONSUME(T.RParen);
|
|
1460
|
+
$.CONSUME(T.Semi);
|
|
1461
|
+
let location = $.endRule();
|
|
1462
|
+
if (!$.RECORDING_PHASE) {
|
|
1463
|
+
let result = mergeExtends(void 0, extendTargets, location, $.context, flag);
|
|
1464
|
+
/** We've converted these extend targets to nodes, so we can reset extend targets */
|
|
1465
|
+
ctx.extendTargets = void 0;
|
|
1466
|
+
if (ctx.extendNodes) if (isArray(result)) ctx.extendNodes = [...ctx.extendNodes, ...result];
|
|
1467
|
+
else ctx.extendNodes.push(result);
|
|
1468
|
+
else if (isArray(result)) ctx.extendNodes = result;
|
|
1469
|
+
else ctx.extendNodes = [result];
|
|
1470
|
+
return new Nil(void 0, void 0, location, $.context);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
function extend(T) {
|
|
1475
|
+
const $ = this;
|
|
1476
|
+
return (ctx = {}) => {
|
|
1477
|
+
$.startRule();
|
|
1478
|
+
$.CONSUME(T.Extend);
|
|
1479
|
+
ctx.inExtend = true;
|
|
1480
|
+
$.SUBRULE($.selectorList, { ARGS: [ctx] });
|
|
1481
|
+
let extendTargets = ctx.extendTargets;
|
|
1482
|
+
ctx.inExtend = false;
|
|
1483
|
+
let selector = ctx.selector;
|
|
1484
|
+
let flag = $.OPTION(() => $.CONSUME(T.AllFlag));
|
|
1485
|
+
$.CONSUME(T.RParen);
|
|
1486
|
+
let location = $.endRule();
|
|
1487
|
+
if (!$.RECORDING_PHASE) {
|
|
1488
|
+
let merged = mergeExtends(selector, extendTargets, location, $.context, flag);
|
|
1489
|
+
/**
|
|
1490
|
+
* If we don't have as many extends as we have value, we need a way to signal
|
|
1491
|
+
* that these should be bumped above the ruleset.
|
|
1492
|
+
*/
|
|
1493
|
+
/** We've converted these extend targets to nodes, so we can reset extend targets */
|
|
1494
|
+
ctx.extendTargets = void 0;
|
|
1495
|
+
if (ctx.extendNodes) if (isArray(merged)) ctx.extendNodes = [...ctx.extendNodes, ...merged];
|
|
1496
|
+
else ctx.extendNodes.push(merged);
|
|
1497
|
+
else if (isArray(merged)) ctx.extendNodes = merged;
|
|
1498
|
+
else ctx.extendNodes = [merged];
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
function simpleSelector(T) {
|
|
1503
|
+
const $ = this;
|
|
1504
|
+
return (ctx = {}) => {
|
|
1505
|
+
let selector = $.OR([
|
|
1506
|
+
{
|
|
1507
|
+
GATE: () => (!ctx.inExtend || $.LA(1).tokenType !== T.All) && $.LA(1).tokenType !== T.InterpolatedIdent,
|
|
1508
|
+
ALT: () => $.CONSUME(T.Ident)
|
|
1509
|
+
},
|
|
1510
|
+
{ ALT: () => {
|
|
1511
|
+
let amp = $.CONSUME(T.Ampersand);
|
|
1512
|
+
return new Ampersand({ appendValue: getAmpersandTemplateValue(amp.image) }, void 0, $.getLocationInfo(amp), $.context);
|
|
1513
|
+
} },
|
|
1514
|
+
{ ALT: () => {
|
|
1515
|
+
$.startRule();
|
|
1516
|
+
$.CONSUME(T.AmpersandLParen);
|
|
1517
|
+
const parts = [];
|
|
1518
|
+
let sawQuoted = false;
|
|
1519
|
+
$.MANY(() => {
|
|
1520
|
+
$.OR2([
|
|
1521
|
+
{
|
|
1522
|
+
GATE: () => $.isType(T.QuoteStart),
|
|
1523
|
+
ALT: () => {
|
|
1524
|
+
const quoted = $.SUBRULE($.string, { ARGS: [ctx] });
|
|
1525
|
+
parts.push(quoted.valueOf());
|
|
1526
|
+
sawQuoted = true;
|
|
1527
|
+
}
|
|
1528
|
+
},
|
|
1529
|
+
{
|
|
1530
|
+
GATE: () => $.isType(T.WS),
|
|
1531
|
+
ALT: () => {
|
|
1532
|
+
parts.push($.CONSUME(T.WS).image);
|
|
1533
|
+
}
|
|
1534
|
+
},
|
|
1535
|
+
{ ALT: () => {
|
|
1536
|
+
parts.push($.CONSUME(T.AmpersandTemplateContents).image);
|
|
1537
|
+
} }
|
|
1538
|
+
]);
|
|
1539
|
+
});
|
|
1540
|
+
$.CONSUME(T.AmpersandTemplateEnd);
|
|
1541
|
+
const location = $.endRule();
|
|
1542
|
+
const value = parts.join("");
|
|
1543
|
+
return new Ampersand({ appendValue: sawQuoted && value === "" ? "" : value === "nil" ? "" : value }, void 0, location, $.context);
|
|
1544
|
+
} },
|
|
1545
|
+
{ ALT: () => $.CONSUME(T.InterpolatedIdent) },
|
|
1546
|
+
{ ALT: () => $.CONSUME(T.InterpolatedSelector) },
|
|
1547
|
+
{ ALT: () => $.SUBRULE($.classSelector, { ARGS: [ctx] }) },
|
|
1548
|
+
{ ALT: () => $.SUBRULE($.idSelector, { ARGS: [ctx] }) },
|
|
1549
|
+
{ ALT: () => $.CONSUME(T.Star) },
|
|
1550
|
+
{ ALT: () => {
|
|
1551
|
+
let initialIsQualifiedRule = ctx.qualifiedRule;
|
|
1552
|
+
ctx.qualifiedRule = false;
|
|
1553
|
+
/** Make sure we prevent things like :extend() inside pseudo-value */
|
|
1554
|
+
try {
|
|
1555
|
+
return $.SUBRULE($.pseudoSelector, { ARGS: [ctx] });
|
|
1556
|
+
} finally {
|
|
1557
|
+
ctx.qualifiedRule = initialIsQualifiedRule;
|
|
1558
|
+
}
|
|
1559
|
+
} },
|
|
1560
|
+
(
|
|
1561
|
+
/** @todo - replicate this fix we made with the Jess parser
|
|
1562
|
+
*
|
|
1563
|
+
* { ALT: () => $.attributeSelector(ctx, () => [
|
|
1564
|
+
{
|
|
1565
|
+
ALT: () => {
|
|
1566
|
+
let token = $.CONSUME($.T.InterpolatedIdent);
|
|
1567
|
+
let location = $.getLocationInfo(token);
|
|
1568
|
+
let image = token.image;
|
|
1569
|
+
let match = interpolatedRegex.exec(image);
|
|
1570
|
+
interpolatedRegex.lastIndex = 0;
|
|
1571
|
+
if (match && match[0] === image) {
|
|
1572
|
+
return new Reference(
|
|
1573
|
+
{ key: new Keyword(match[2]!, undefined, location, $.context) },
|
|
1574
|
+
{ type: 'index' },
|
|
1575
|
+
location,
|
|
1576
|
+
$.context
|
|
1577
|
+
);
|
|
1578
|
+
}
|
|
1579
|
+
return getInterpolatedNode(image, location, $.context);
|
|
1580
|
+
}
|
|
1581
|
+
},
|
|
1582
|
+
*/
|
|
1583
|
+
{ ALT: () => $.SUBRULE($.attributeSelector, { ARGS: [ctx] }) }),
|
|
1584
|
+
(
|
|
1585
|
+
/** Supports keyframes value */
|
|
1586
|
+
{ ALT: () => $.CONSUME(T.DimensionInt) }),
|
|
1587
|
+
{ ALT: () => $.CONSUME(T.DimensionNum) }
|
|
1588
|
+
]);
|
|
1589
|
+
if ($.isToken(selector)) {
|
|
1590
|
+
if (selector.tokenType.name === "Ampersand") return new Ampersand({ appendValue: getAmpersandTemplateValue(selector.image) }, void 0, $.getLocationInfo(selector), $.context);
|
|
1591
|
+
if (selector.tokenType.name === "InterpolatedSelector" || selector.tokenType.name === "InterpolatedIdent") {
|
|
1592
|
+
let nameValue = selector.image;
|
|
1593
|
+
return new InterpolatedSelector(getInterpolatedNode(nameValue, $.getLocationInfo(selector), $.context), void 0, $.getLocationInfo(selector), $.context);
|
|
1594
|
+
}
|
|
1595
|
+
return new BasicSelector(selector.image, void 0, $.getLocationInfo(selector), $.context);
|
|
1596
|
+
}
|
|
1597
|
+
return selector;
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
function anonymousMixinDefinition(T) {
|
|
1601
|
+
const $ = this;
|
|
1602
|
+
return (ctx = {}) => {
|
|
1603
|
+
$.startRule();
|
|
1604
|
+
let params;
|
|
1605
|
+
let anonToken;
|
|
1606
|
+
$.OPTION(() => {
|
|
1607
|
+
anonToken = $.CONSUME(T.AnonMixinStart);
|
|
1608
|
+
$.OPTION2(() => {
|
|
1609
|
+
params = $.SUBRULE($.mixinArgList, { ARGS: [{
|
|
1610
|
+
...ctx,
|
|
1611
|
+
isDefinition: true
|
|
1612
|
+
}] });
|
|
1613
|
+
});
|
|
1614
|
+
$.CONSUME(T.RParen);
|
|
1615
|
+
});
|
|
1616
|
+
let rules = $.SUBRULE($.wrappedDeclarationList, { ARGS: [ctx] });
|
|
1617
|
+
if ($.RECORDING_PHASE) return;
|
|
1618
|
+
if (!rules.options.rulesVisibility) rules.options.rulesVisibility = {};
|
|
1619
|
+
if ($.leakyScope) {
|
|
1620
|
+
rules.options.rulesVisibility.Mixin = "public";
|
|
1621
|
+
rules.options.rulesVisibility.VarDeclaration = "private";
|
|
1622
|
+
} else {
|
|
1623
|
+
rules.options.rulesVisibility.Mixin = "private";
|
|
1624
|
+
rules.options.rulesVisibility.VarDeclaration = "private";
|
|
1625
|
+
}
|
|
1626
|
+
if (!anonToken) {
|
|
1627
|
+
/** To Less, this is a "detached ruleset" */
|
|
1628
|
+
const shouldBeCollection = (() => {
|
|
1629
|
+
let properties = [];
|
|
1630
|
+
for (const node of rules.rules) if (node.type === "Declaration") properties.push(node);
|
|
1631
|
+
else if (node.type === "Comment" || node.type === "VarDeclaration") continue;
|
|
1632
|
+
else
|
|
1633
|
+
/** Not a valid collection, parse as anonymous mixin */
|
|
1634
|
+
return false;
|
|
1635
|
+
if (properties.length === 0)
|
|
1636
|
+
/** If just var declarations and/or comments, parse as collection */
|
|
1637
|
+
return true;
|
|
1638
|
+
/** If this looks like mostly CSS properties, parse as mixin instead */
|
|
1639
|
+
return !(properties.filter((decl) => {
|
|
1640
|
+
const { name } = decl;
|
|
1641
|
+
const propName = typeof name === "string" ? name : name?.valueOf();
|
|
1642
|
+
if (!propName) return false;
|
|
1643
|
+
if (propName.startsWith("--")) return true;
|
|
1644
|
+
return all.includes(propName);
|
|
1645
|
+
}).length > properties.length / 2);
|
|
1646
|
+
})();
|
|
1647
|
+
const usage = ctx.detachedRulesetUsage ?? "none";
|
|
1648
|
+
if (shouldBeCollection && !(usage === "function-arg" || usage === "mixin-arg" || usage === "default-param")) return new Collection(rules.rules, rules.options, $.endRule(), $.context);
|
|
1649
|
+
}
|
|
1650
|
+
return new Mixin({
|
|
1651
|
+
params,
|
|
1652
|
+
rules: rules.rules
|
|
1653
|
+
}, void 0, $.endRule(), $.context);
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Mostly copied from css importAtRule, but it maps
|
|
1658
|
+
* differently to Jess nodes depending on if it's meant
|
|
1659
|
+
* to be a Jess-style import or just an at-rule
|
|
1660
|
+
*/
|
|
1661
|
+
function importAtRule(T) {
|
|
1662
|
+
const $ = this;
|
|
1663
|
+
return (ctx = {}) => {
|
|
1664
|
+
const isCssUrl = (url, options) => {
|
|
1665
|
+
if (options.includes("inline")) return false;
|
|
1666
|
+
const lower = url.toLowerCase();
|
|
1667
|
+
if (options.includes("less")) return false;
|
|
1668
|
+
if (options.includes("css")) return true;
|
|
1669
|
+
if (/\.css([?#].*)?$/.test(lower)) return true;
|
|
1670
|
+
if (/\.less([?#].*)?$/.test(lower)) return false;
|
|
1671
|
+
if (lower.startsWith("http://") || lower.startsWith("https://") || lower.startsWith("//")) return true;
|
|
1672
|
+
return false;
|
|
1673
|
+
};
|
|
1674
|
+
$.startRule();
|
|
1675
|
+
let name = $.CONSUME(T.AtImport);
|
|
1676
|
+
let options = [];
|
|
1677
|
+
$.OPTION(() => {
|
|
1678
|
+
$.CONSUME(T.LParen);
|
|
1679
|
+
$.AT_LEAST_ONE_SEP({
|
|
1680
|
+
SEP: T.Comma,
|
|
1681
|
+
DEF: () => {
|
|
1682
|
+
let opt = $.CONSUME(T.PlainIdent);
|
|
1683
|
+
options.push(opt.image);
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
$.CONSUME(T.RParen);
|
|
1687
|
+
});
|
|
1688
|
+
let urlNode = $.OR([{ ALT: () => $.SUBRULE($.urlFunction, { ARGS: [ctx] }) }, { ALT: () => $.SUBRULE($.string, { ARGS: [ctx] }) }]);
|
|
1689
|
+
let extraNodes;
|
|
1690
|
+
$.OPTION2(() => {
|
|
1691
|
+
extraNodes = $.SUBRULE($.importPostlude, { ARGS: [{}] });
|
|
1692
|
+
});
|
|
1693
|
+
$.CONSUME(T.Semi);
|
|
1694
|
+
if (!$.RECORDING_PHASE) {
|
|
1695
|
+
let isAtRule;
|
|
1696
|
+
let postludeNode;
|
|
1697
|
+
isAtRule = isCssUrl(urlNode.valueOf(), options);
|
|
1698
|
+
let preludeNodes = [urlNode];
|
|
1699
|
+
if (extraNodes && extraNodes.length) if (isAtRule) {
|
|
1700
|
+
isAtRule = true;
|
|
1701
|
+
for (const n of extraNodes) preludeNodes.push(n);
|
|
1702
|
+
} else {
|
|
1703
|
+
const postludeLoc = $.getLocationFromNodes(extraNodes);
|
|
1704
|
+
postludeNode = new Sequence(extraNodes, void 0, postludeLoc, $.context);
|
|
1705
|
+
}
|
|
1706
|
+
let location = $.endRule();
|
|
1707
|
+
if (isAtRule) {
|
|
1708
|
+
const prelude = new Sequence(preludeNodes, void 0, $.getLocationFromNodes(preludeNodes), $.context);
|
|
1709
|
+
return new AtRuleStatement({
|
|
1710
|
+
name: name.image,
|
|
1711
|
+
prelude
|
|
1712
|
+
}, void 0, location, $.context);
|
|
1713
|
+
}
|
|
1714
|
+
return new StyleImport({ path: urlNode }, {
|
|
1715
|
+
type: "import",
|
|
1716
|
+
importOptions: {
|
|
1717
|
+
type: options.includes("less") ? "less" : void 0,
|
|
1718
|
+
reference: options.includes("reference"),
|
|
1719
|
+
once: !options.includes("multiple"),
|
|
1720
|
+
multiple: options.includes("multiple"),
|
|
1721
|
+
optional: options.includes("optional"),
|
|
1722
|
+
inline: options.includes("inline"),
|
|
1723
|
+
postlude: postludeNode
|
|
1724
|
+
}
|
|
1725
|
+
}, location, $.context);
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
/** Less variables */
|
|
1730
|
+
function varDeclarationOrCall(T) {
|
|
1731
|
+
const $ = this;
|
|
1732
|
+
return (ctx = {}) => {
|
|
1733
|
+
$.startRule();
|
|
1734
|
+
let name = $.SUBRULE($.varName, { ARGS: [{}] });
|
|
1735
|
+
let value;
|
|
1736
|
+
let args;
|
|
1737
|
+
let important;
|
|
1738
|
+
$.OR([{ ALT: () => {
|
|
1739
|
+
$.CONSUME(T.Colon);
|
|
1740
|
+
return $.OR2([{
|
|
1741
|
+
GATE: () => {
|
|
1742
|
+
const type = $.LA(1).tokenType;
|
|
1743
|
+
return type === T.AnonMixinStart || type === T.LCurly;
|
|
1744
|
+
},
|
|
1745
|
+
ALT: () => {
|
|
1746
|
+
value = $.SUBRULE($.anonymousMixinDefinition, { ARGS: [ctx] });
|
|
1747
|
+
$.OPTION(() => $.CONSUME(T.Semi));
|
|
1748
|
+
return value;
|
|
1749
|
+
}
|
|
1750
|
+
}, {
|
|
1751
|
+
GATE: () => {
|
|
1752
|
+
const type = $.LA(1).tokenType;
|
|
1753
|
+
return type !== T.AnonMixinStart && type !== T.LCurly;
|
|
1754
|
+
},
|
|
1755
|
+
ALT: () => {
|
|
1756
|
+
value = $.SUBRULE($.valueList, { ARGS: [{
|
|
1757
|
+
...ctx,
|
|
1758
|
+
allowMixinCallWithoutAccessor: true
|
|
1759
|
+
}] });
|
|
1760
|
+
$.OPTION2(() => {
|
|
1761
|
+
important = $.CONSUME(T.Important);
|
|
1762
|
+
});
|
|
1763
|
+
return value;
|
|
1764
|
+
}
|
|
1765
|
+
}]);
|
|
1766
|
+
} }, (
|
|
1767
|
+
/** This is a variable call. Allow optional whitespace between name and (. */
|
|
1768
|
+
{
|
|
1769
|
+
GATE: () => $.isType(T.LParen),
|
|
1770
|
+
ALT: () => {
|
|
1771
|
+
args = $.SUBRULE($.mixinArgs, { ARGS: [ctx] });
|
|
1772
|
+
return args;
|
|
1773
|
+
}
|
|
1774
|
+
})]);
|
|
1775
|
+
let location = $.endRule();
|
|
1776
|
+
if ($.RECORDING_PHASE) return;
|
|
1777
|
+
let nameVal = getInterpolatedOrString(name.image);
|
|
1778
|
+
let nameNode;
|
|
1779
|
+
if (!(nameVal instanceof Interpolated)) nameNode = new Any(nameVal, { role: "ident" }, $.getLocationInfo(name), $.context);
|
|
1780
|
+
else nameNode = nameVal;
|
|
1781
|
+
/** An anonymous mixin call */
|
|
1782
|
+
if (!value) {
|
|
1783
|
+
const callNode = new Call({
|
|
1784
|
+
name: new Reference({ key: nameNode }, {
|
|
1785
|
+
type: "variable",
|
|
1786
|
+
role: "name"
|
|
1787
|
+
}),
|
|
1788
|
+
args
|
|
1789
|
+
}, important ? { markImportant: true } : void 0, location, $.context);
|
|
1790
|
+
if (important) important = void 0;
|
|
1791
|
+
return new Expression(callNode, void 0, location, $.context);
|
|
1792
|
+
}
|
|
1793
|
+
if (important && value instanceof Call) {
|
|
1794
|
+
value.options = value.options || {};
|
|
1795
|
+
value.options.markImportant = true;
|
|
1796
|
+
important = void 0;
|
|
1797
|
+
}
|
|
1798
|
+
if (value && isLegacySelectorLikeValue(value)) {
|
|
1799
|
+
const varName = String(nameNode.valueOf());
|
|
1800
|
+
$.warnDeprecation(`Unquoted selector capture in '${varName}' is no longer supported. Use '*[ ... ]' (e.g. ${varName}: *[.a, .b]).`, $.LA(1), "unquoted-selector-capture");
|
|
1801
|
+
}
|
|
1802
|
+
return new VarDeclaration({
|
|
1803
|
+
name: nameNode instanceof Any ? String(nameNode.valueOf()) : nameNode,
|
|
1804
|
+
value,
|
|
1805
|
+
important: important ? new Any(important.image, { role: "flag" }, $.getLocationInfo(important), $.context) : void 0
|
|
1806
|
+
}, void 0, location, $.context);
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
function selectorCapture(T) {
|
|
1810
|
+
const $ = this;
|
|
1811
|
+
return (ctx = {}) => {
|
|
1812
|
+
$.startRule();
|
|
1813
|
+
$.CONSUME(T.Star);
|
|
1814
|
+
const selector = $.OR([{
|
|
1815
|
+
GATE: $.noSep.bind($),
|
|
1816
|
+
ALT: () => {
|
|
1817
|
+
$.CONSUME(T.LSquare);
|
|
1818
|
+
const selector = $.SUBRULE($.forgivingSelectorList, { ARGS: [{
|
|
1819
|
+
...ctx,
|
|
1820
|
+
inner: true
|
|
1821
|
+
}] });
|
|
1822
|
+
$.CONSUME(T.RSquare);
|
|
1823
|
+
return selector;
|
|
1824
|
+
}
|
|
1825
|
+
}]);
|
|
1826
|
+
const location = $.endRule();
|
|
1827
|
+
if ($.RECORDING_PHASE) return;
|
|
1828
|
+
return new SelectorCapture(selector, void 0, location, $.context);
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
function valueSequence(_T) {
|
|
1832
|
+
const $ = this;
|
|
1833
|
+
return (ctx = {}) => {
|
|
1834
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
1835
|
+
$.startRule();
|
|
1836
|
+
let nodes;
|
|
1837
|
+
if (!RECORDING_PHASE) nodes = [];
|
|
1838
|
+
{
|
|
1839
|
+
const exprCtx = {
|
|
1840
|
+
...ctx,
|
|
1841
|
+
wrapInExpression: true
|
|
1842
|
+
};
|
|
1843
|
+
let value = $.SUBRULE2($.expressionSum, { ARGS: [exprCtx] });
|
|
1844
|
+
if (!RECORDING_PHASE) {
|
|
1845
|
+
value = wrapOuterExpressionIfNeeded.call($, value, exprCtx);
|
|
1846
|
+
nodes.push(value);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
$.MANY(() => {
|
|
1850
|
+
const exprCtx = {
|
|
1851
|
+
...ctx,
|
|
1852
|
+
wrapInExpression: true
|
|
1853
|
+
};
|
|
1854
|
+
let value = $.SUBRULE3($.expressionSum, { ARGS: [exprCtx] });
|
|
1855
|
+
if (!RECORDING_PHASE) {
|
|
1856
|
+
value = wrapOuterExpressionIfNeeded.call($, value, exprCtx);
|
|
1857
|
+
nodes.push(value);
|
|
1858
|
+
}
|
|
1859
|
+
});
|
|
1860
|
+
if (RECORDING_PHASE) return;
|
|
1861
|
+
let location = $.endRule();
|
|
1862
|
+
if (nodes.length === 1) return nodes[0];
|
|
1863
|
+
return new Sequence(nodes, void 0, location, $.context);
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
function squareValue(T) {
|
|
1867
|
+
const $ = this;
|
|
1868
|
+
return (ctx = {}) => {
|
|
1869
|
+
$.startRule();
|
|
1870
|
+
$.CONSUME(T.LSquare);
|
|
1871
|
+
let node = $.OR([{
|
|
1872
|
+
GATE: () => !$.looseMode,
|
|
1873
|
+
ALT: () => {
|
|
1874
|
+
let ident = $.CONSUME(T.Ident);
|
|
1875
|
+
return new Any(ident.image, { role: "ident" }, $.getLocationInfo(ident), $.context);
|
|
1876
|
+
}
|
|
1877
|
+
}, {
|
|
1878
|
+
GATE: () => !!$.looseMode,
|
|
1879
|
+
ALT: () => {
|
|
1880
|
+
let nodes = [];
|
|
1881
|
+
$.MANY(() => {
|
|
1882
|
+
const wrapped = $.SUBRULE($.anyInnerValue, { ARGS: [ctx] });
|
|
1883
|
+
nodes.push(wrapped);
|
|
1884
|
+
});
|
|
1885
|
+
return new Sequence(nodes, void 0, $.getLocationFromNodes(nodes), $.context);
|
|
1886
|
+
}
|
|
1887
|
+
}]);
|
|
1888
|
+
$.CONSUME(T.RSquare);
|
|
1889
|
+
return new Block(node, { type: "square" }, $.endRule(), $.context);
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1892
|
+
//#endregion
|
|
1893
|
+
//#region src/productions/values.ts
|
|
1894
|
+
const OPERATORS = new Set([
|
|
1895
|
+
"+",
|
|
1896
|
+
"-",
|
|
1897
|
+
"*",
|
|
1898
|
+
"/",
|
|
1899
|
+
"%"
|
|
1900
|
+
]);
|
|
1901
|
+
function toOperator(image) {
|
|
1902
|
+
if (image === "./") return "/";
|
|
1903
|
+
if (OPERATORS.has(image)) return image;
|
|
1904
|
+
throw new Error(`Unexpected operator "${image}".`);
|
|
1905
|
+
}
|
|
1906
|
+
function toQuote(image) {
|
|
1907
|
+
if (image === "\"" || image === "'") return image;
|
|
1908
|
+
throw new Error(`Unexpected quote "${image}".`);
|
|
1909
|
+
}
|
|
1910
|
+
function nonEmptyVarDeclarations(vars) {
|
|
1911
|
+
if (vars.length === 0) throw new Error("Expected at least one variable declaration.");
|
|
1912
|
+
return [vars[0], ...vars.slice(1)];
|
|
1913
|
+
}
|
|
1914
|
+
const cssNthValue = productions.nthValue;
|
|
1915
|
+
const cssKnownFunctions = productions.knownFunctions;
|
|
1916
|
+
const cssMathValue = productions.mathValue;
|
|
1917
|
+
function getParenFrames$1(ctx) {
|
|
1918
|
+
return ctx?.parenFrames ?? [];
|
|
1919
|
+
}
|
|
1920
|
+
function withCalcFrame(ctx, delta) {
|
|
1921
|
+
const calcFrames = (ctx?.calcFrames ?? 0) + delta;
|
|
1922
|
+
return {
|
|
1923
|
+
...ctx ?? {},
|
|
1924
|
+
calcFrames
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
function slashDivisionEnabled($, ctx) {
|
|
1928
|
+
const inParens = getParenFrames$1(ctx).at(-1) ?? false;
|
|
1929
|
+
return ($.mathMode ?? "parens-division") === "always" || inParens;
|
|
1930
|
+
}
|
|
1931
|
+
function isDivisionLikeNode(node) {
|
|
1932
|
+
if (!node) return false;
|
|
1933
|
+
if (isNode(node, N.Color) || isNode(node, N.Dimension) || node instanceof Num || isNode(node, N.Reference) || isNode(node, N.Call) || isNode(node, N.Operation) || node.type === "Negative" || isNode(node, N.Expression)) return true;
|
|
1934
|
+
if (isNode(node, N.Paren) || isNode(node, N.Expression)) return isDivisionLikeNode(node.value);
|
|
1935
|
+
return false;
|
|
1936
|
+
}
|
|
1937
|
+
function isSlashListContinuationToken($, T) {
|
|
1938
|
+
const next = $.LA(1);
|
|
1939
|
+
return !(next.tokenType?.name === "EOF" || $.matchToken(next, T.Comma) || $.matchToken(next, T.Semi) || $.matchToken(next, T.RCurly) || $.matchToken(next, T.RParen) || $.matchToken(next, T.RSquare) || $.matchToken(next, T.Important) || $.matchToken(next, T.Plus) || $.matchToken(next, T.Minus) || $.matchToken(next, T.Star) || $.matchToken(next, T.Slash) || $.matchToken(next, T.Percent));
|
|
1940
|
+
}
|
|
1941
|
+
function shouldParseSlashDivision($, T, ctx, left, right) {
|
|
1942
|
+
const enabled = slashDivisionEnabled($, ctx);
|
|
1943
|
+
const leftLike = isDivisionLikeNode(left);
|
|
1944
|
+
const rightLike = isDivisionLikeNode(right);
|
|
1945
|
+
const continuation = isSlashListContinuationToken($, T);
|
|
1946
|
+
if (!enabled) return false;
|
|
1947
|
+
if (!leftLike || !rightLike) return false;
|
|
1948
|
+
if (continuation) return false;
|
|
1949
|
+
return true;
|
|
1950
|
+
}
|
|
1951
|
+
function startsCustomValueToken($, T) {
|
|
1952
|
+
return $.isType(T.LParen) || $.isType(T.FunctionStart) || $.isType(T.FunctionalPseudoClass) || $.isType(T.LSquare) || $.isType(T.LCurly) || $.isType(T.SingleQuoteStart) || $.isType(T.DoubleQuoteStart) || $.isType(T.Value) || $.isType(T.PlainIdent) || $.isType(T.AtKeyword) || $.isType(T.PropertyReference) || $.isType(T.CustomProperty) || $.isType(T.Dimension) || $.isType(T.Number) || $.isType(T.Color) || $.isType(T.UnicodeRange) || $.isType(T.Colon) || $.isType(T.Comma) || $.isType(T.Important) || $.isType(T.Unknown);
|
|
1953
|
+
}
|
|
1954
|
+
function createEachPattern(mixin, location, context) {
|
|
1955
|
+
const defaultVars = [
|
|
1956
|
+
"value",
|
|
1957
|
+
"key",
|
|
1958
|
+
"index"
|
|
1959
|
+
].map((name) => {
|
|
1960
|
+
return new VarDeclaration({
|
|
1961
|
+
name,
|
|
1962
|
+
value: new Any("", { role: "any" })
|
|
1963
|
+
}, { paramVar: true }, location, context);
|
|
1964
|
+
});
|
|
1965
|
+
if (!isNode(mixin, N.Mixin) || !mixin.params) return {
|
|
1966
|
+
kind: "tuple",
|
|
1967
|
+
values: nonEmptyVarDeclarations(defaultVars)
|
|
1968
|
+
};
|
|
1969
|
+
const params = mixin.params.value.map((param) => {
|
|
1970
|
+
if (isNode(param, N.VarDeclaration)) return param;
|
|
1971
|
+
if (isNode(param, N.Any) && param.role === "property") return new VarDeclaration({
|
|
1972
|
+
name: String(param.value),
|
|
1973
|
+
value: new Any("", { role: "any" })
|
|
1974
|
+
}, { paramVar: true }, param.location, context);
|
|
1975
|
+
}).filter((param) => Boolean(param));
|
|
1976
|
+
if (params.length === 0) return {
|
|
1977
|
+
kind: "tuple",
|
|
1978
|
+
values: nonEmptyVarDeclarations(defaultVars)
|
|
1979
|
+
};
|
|
1980
|
+
if (params.length === 1) return {
|
|
1981
|
+
kind: "single",
|
|
1982
|
+
value: params[0]
|
|
1983
|
+
};
|
|
1984
|
+
return {
|
|
1985
|
+
kind: "tuple",
|
|
1986
|
+
values: nonEmptyVarDeclarations(params)
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
function expressionSum(T) {
|
|
1990
|
+
const $ = this;
|
|
1991
|
+
return (ctx = {}) => {
|
|
1992
|
+
$.startRule();
|
|
1993
|
+
let left = $.SUBRULE($.expressionProduct, { ARGS: [ctx] });
|
|
1994
|
+
while (true) {
|
|
1995
|
+
let op;
|
|
1996
|
+
let right;
|
|
1997
|
+
if ($.isType(T.Plus)) {
|
|
1998
|
+
op = $.CONSUME(T.Plus).image;
|
|
1999
|
+
right = $.SUBRULE2($.expressionProduct, { ARGS: [ctx] });
|
|
2000
|
+
} else if ($.isType(T.Minus)) {
|
|
2001
|
+
op = $.CONSUME(T.Minus).image;
|
|
2002
|
+
right = $.SUBRULE4($.expressionProduct, { ARGS: [ctx] });
|
|
2003
|
+
} else if ($.noSep() && $.matchToken($.LA(1), T.Signed)) {
|
|
2004
|
+
const tok = $.CONSUME(T.Signed);
|
|
2005
|
+
let startValue;
|
|
2006
|
+
const str = tok.image;
|
|
2007
|
+
op = str[0];
|
|
2008
|
+
if (tok.payload && tok.payload[1]) startValue = new Dimension({
|
|
2009
|
+
number: parseFloat(tok.payload[0]),
|
|
2010
|
+
unit: tok.payload[1]
|
|
2011
|
+
}, void 0, $.getLocationInfo(tok), $.context);
|
|
2012
|
+
else {
|
|
2013
|
+
const num = parseFloat(str);
|
|
2014
|
+
if (!Number.isNaN(num)) startValue = new Num(num, void 0, $.getLocationInfo(tok), $.context);
|
|
2015
|
+
else startValue = $.processValueToken(tok);
|
|
2016
|
+
}
|
|
2017
|
+
right = $.SUBRULE3($.expressionProduct, { ARGS: [{
|
|
2018
|
+
...ctx,
|
|
2019
|
+
startValue
|
|
2020
|
+
}] });
|
|
2021
|
+
} else break;
|
|
2022
|
+
left = new Operation([
|
|
2023
|
+
left,
|
|
2024
|
+
toOperator(op),
|
|
2025
|
+
right
|
|
2026
|
+
], void 0, $.getLocationFromNodes([left, right]), $.context);
|
|
2027
|
+
}
|
|
2028
|
+
$.endRule();
|
|
2029
|
+
return left;
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
function expressionProduct(T) {
|
|
2033
|
+
const $ = this;
|
|
2034
|
+
return (ctx = {}) => {
|
|
2035
|
+
$.startRule();
|
|
2036
|
+
let left = ctx.startValue ?? $.SUBRULE($.expressionValue, { ARGS: [ctx] });
|
|
2037
|
+
while (true) {
|
|
2038
|
+
let op;
|
|
2039
|
+
if ($.isType(T.Star)) op = $.CONSUME(T.Star);
|
|
2040
|
+
else if ($.isType(T.Slash)) op = $.CONSUME(T.Slash);
|
|
2041
|
+
else if ($.isType(T.Percent)) op = $.CONSUME(T.Percent);
|
|
2042
|
+
else break;
|
|
2043
|
+
if (op.image === "./") $.warnDeprecation("./ operator is deprecated", op, "dot-slash-operator");
|
|
2044
|
+
let right = $.SUBRULE2($.expressionValue, { ARGS: [ctx] });
|
|
2045
|
+
const location = $.getLocationFromNodes([left, right]);
|
|
2046
|
+
if (op.image === "/" && !shouldParseSlashDivision($, T, ctx, left, right)) {
|
|
2047
|
+
if (isNode(left, N.List) && left.options?.sep === "/") left = new List([...left.value, right], { sep: "/" }, location, $.context);
|
|
2048
|
+
else left = new List([left, right], { sep: "/" }, location, $.context);
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
left = new Operation([
|
|
2052
|
+
left,
|
|
2053
|
+
toOperator(op.image),
|
|
2054
|
+
right
|
|
2055
|
+
], void 0, location, $.context);
|
|
2056
|
+
}
|
|
2057
|
+
$.endRule();
|
|
2058
|
+
return left;
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
function customValue(T) {
|
|
2062
|
+
const $ = this;
|
|
2063
|
+
return (ctx = {}) => {
|
|
2064
|
+
if ($.isType(T.UrlStart) || $.isType(T.Var) || $.isType(T.Calc) || $.isType(T.IfFunction) || $.isType(T.BooleanFunction) || $.isType(T.FunctionStart)) return $.SUBRULE($.functionCall, { ARGS: [ctx] });
|
|
2065
|
+
if ($.isType(T.LParen) || $.isType(T.FunctionalPseudoClass) || $.isType(T.LSquare) || $.isType(T.LCurly)) return $.SUBRULE($.customBlock, { ARGS: [ctx] });
|
|
2066
|
+
if ($.isType(T.SingleQuoteStart) || $.isType(T.DoubleQuoteStart)) return $.SUBRULE($.string, { ARGS: [ctx] });
|
|
2067
|
+
let token;
|
|
2068
|
+
if ($.isType(T.Value)) token = $.CONSUME(T.Value);
|
|
2069
|
+
else if ($.isType(T.PlainIdent)) token = $.CONSUME(T.PlainIdent);
|
|
2070
|
+
else if ($.isType(T.AtKeyword)) token = $.CONSUME(T.AtKeyword);
|
|
2071
|
+
else if ($.isType(T.PropertyReference)) token = $.CONSUME(T.PropertyReference);
|
|
2072
|
+
else if ($.isType(T.CustomProperty)) token = $.CONSUME(T.CustomProperty);
|
|
2073
|
+
else if ($.isType(T.Dimension)) token = $.CONSUME(T.Dimension);
|
|
2074
|
+
else if ($.isType(T.Number)) token = $.CONSUME(T.Number);
|
|
2075
|
+
else if ($.isType(T.Color)) token = $.CONSUME(T.Color);
|
|
2076
|
+
else if ($.isType(T.UnicodeRange)) token = $.CONSUME(T.UnicodeRange);
|
|
2077
|
+
else if ($.isType(T.Colon)) token = $.CONSUME(T.Colon);
|
|
2078
|
+
else if ($.isType(T.Comma)) token = $.CONSUME(T.Comma);
|
|
2079
|
+
else if ($.isType(T.Important)) token = $.CONSUME(T.Important);
|
|
2080
|
+
else token = $.CONSUME(T.Unknown);
|
|
2081
|
+
if (!$.RECORDING_PHASE) return $.processValueToken(token, ctx);
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
2084
|
+
function innerCustomValue(T) {
|
|
2085
|
+
const $ = this;
|
|
2086
|
+
return (ctx = {}) => {
|
|
2087
|
+
if ($.isType(T.Semi)) {
|
|
2088
|
+
const semi = $.CONSUME(T.Semi);
|
|
2089
|
+
if ($.RECORDING_PHASE) return;
|
|
2090
|
+
return new Any(semi.image, { role: "semi" }, $.getLocationInfo(semi), $.context);
|
|
2091
|
+
}
|
|
2092
|
+
return $.SUBRULE($.customValue, { ARGS: [ctx] });
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
function customBlock(T) {
|
|
2096
|
+
const $ = this;
|
|
2097
|
+
return (ctx = {}) => {
|
|
2098
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
2099
|
+
$.startRule();
|
|
2100
|
+
let start;
|
|
2101
|
+
let end;
|
|
2102
|
+
let nodes;
|
|
2103
|
+
if (!RECORDING_PHASE) nodes = [];
|
|
2104
|
+
if ($.isType(T.LParen)) {
|
|
2105
|
+
start = $.CONSUME(T.LParen);
|
|
2106
|
+
while (!$.isType(T.RParen) && (startsCustomValueToken($, T) || $.isType(T.Semi))) {
|
|
2107
|
+
const val = $.SUBRULE($.innerCustomValue, { ARGS: [ctx] });
|
|
2108
|
+
if (!RECORDING_PHASE) nodes.push(val);
|
|
2109
|
+
}
|
|
2110
|
+
end = $.CONSUME(T.RParen);
|
|
2111
|
+
} else if ($.isType(T.FunctionStart) || $.isType(T.FunctionalPseudoClass)) {
|
|
2112
|
+
start = $.isType(T.FunctionStart) ? $.CONSUME(T.FunctionStart) : $.CONSUME(T.FunctionalPseudoClass);
|
|
2113
|
+
while (!$.isType(T.RParen) && (startsCustomValueToken($, T) || $.isType(T.Semi))) {
|
|
2114
|
+
const val = $.SUBRULE2($.innerCustomValue, { ARGS: [ctx] });
|
|
2115
|
+
if (!RECORDING_PHASE) nodes.push(val);
|
|
2116
|
+
}
|
|
2117
|
+
end = $.CONSUME2(T.RParen);
|
|
2118
|
+
} else if ($.isType(T.LSquare)) {
|
|
2119
|
+
start = $.CONSUME(T.LSquare);
|
|
2120
|
+
while (!$.isType(T.RSquare) && (startsCustomValueToken($, T) || $.isType(T.Semi))) {
|
|
2121
|
+
const val = $.SUBRULE3($.innerCustomValue, { ARGS: [ctx] });
|
|
2122
|
+
if (!RECORDING_PHASE) nodes.push(val);
|
|
2123
|
+
}
|
|
2124
|
+
end = $.CONSUME(T.RSquare);
|
|
2125
|
+
} else {
|
|
2126
|
+
start = $.CONSUME(T.LCurly);
|
|
2127
|
+
while (!$.isType(T.RCurly) && (startsCustomValueToken($, T) || $.isType(T.Semi))) {
|
|
2128
|
+
const val = $.SUBRULE4($.innerCustomValue, { ARGS: [ctx] });
|
|
2129
|
+
if (!RECORDING_PHASE) nodes.push(val);
|
|
2130
|
+
}
|
|
2131
|
+
end = $.CONSUME(T.RCurly);
|
|
2132
|
+
}
|
|
2133
|
+
if (RECORDING_PHASE) return;
|
|
2134
|
+
const location = $.endRule();
|
|
2135
|
+
let type;
|
|
2136
|
+
switch (start.image) {
|
|
2137
|
+
case "[":
|
|
2138
|
+
type = "square";
|
|
2139
|
+
break;
|
|
2140
|
+
case "{":
|
|
2141
|
+
type = "curly";
|
|
2142
|
+
break;
|
|
2143
|
+
}
|
|
2144
|
+
if (type) {
|
|
2145
|
+
const seqLoc = nodes.length ? $.getLocationFromNodes(nodes) : void 0;
|
|
2146
|
+
return new Block(new Sequence(nodes, void 0, seqLoc, $.context), { type }, location, $.context);
|
|
2147
|
+
}
|
|
2148
|
+
const startNode = new Any(start.image, { role: "any" }, $.getLocationInfo(start), $.context);
|
|
2149
|
+
const endNode = new Any(end.image, { role: "any" }, $.getLocationInfo(end), $.context);
|
|
2150
|
+
return new Sequence([
|
|
2151
|
+
startNode,
|
|
2152
|
+
...nodes,
|
|
2153
|
+
endNode
|
|
2154
|
+
], void 0, location, $.context);
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
function expressionValue(T) {
|
|
2158
|
+
const $ = this;
|
|
2159
|
+
return (ctx = {}) => {
|
|
2160
|
+
$.startRule();
|
|
2161
|
+
/** Can create a negative expression */
|
|
2162
|
+
let minus = $.OPTION(() => $.CONSUME(T.Minus));
|
|
2163
|
+
let node = $.OR([{ ALT: () => {
|
|
2164
|
+
$.startRule();
|
|
2165
|
+
let escape;
|
|
2166
|
+
$.OPTION2(() => {
|
|
2167
|
+
escape = $.CONSUME(T.Tilde);
|
|
2168
|
+
});
|
|
2169
|
+
$.CONSUME(T.LParen);
|
|
2170
|
+
const innerCtx = {
|
|
2171
|
+
...ctx,
|
|
2172
|
+
inner: true,
|
|
2173
|
+
allowComma: true,
|
|
2174
|
+
parenFrames: [...getParenFrames$1(ctx), true]
|
|
2175
|
+
};
|
|
2176
|
+
let node = $.SUBRULE($.valueList, { ARGS: [innerCtx] });
|
|
2177
|
+
let isSemiList = false;
|
|
2178
|
+
if (escape) {
|
|
2179
|
+
let semiNodes = [];
|
|
2180
|
+
$.OPTION3(() => {
|
|
2181
|
+
$.CONSUME(T.Semi);
|
|
2182
|
+
isSemiList = true;
|
|
2183
|
+
semiNodes.push(node);
|
|
2184
|
+
node = $.SUBRULE2($.valueList, { ARGS: [innerCtx] });
|
|
2185
|
+
semiNodes.push(node);
|
|
2186
|
+
$.MANY({
|
|
2187
|
+
GATE: () => $.isType(T.Semi),
|
|
2188
|
+
DEF: () => {
|
|
2189
|
+
$.CONSUME2(T.Semi);
|
|
2190
|
+
node = $.SUBRULE3($.valueList, { ARGS: [innerCtx] });
|
|
2191
|
+
semiNodes.push(node);
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2194
|
+
});
|
|
2195
|
+
if (isSemiList) node = new List(semiNodes, { sep: ";" });
|
|
2196
|
+
}
|
|
2197
|
+
$.CONSUME(T.RParen);
|
|
2198
|
+
let location = $.endRule();
|
|
2199
|
+
node = node;
|
|
2200
|
+
return new Paren(node, { escaped: !!escape }, location, $.context);
|
|
2201
|
+
} }, { ALT: () => $.SUBRULE($.value, { ARGS: [ctx] }) }]);
|
|
2202
|
+
let location = $.endRule();
|
|
2203
|
+
if (minus) return new Negative(node, void 0, location, $.context);
|
|
2204
|
+
return node;
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Add interpolation
|
|
2209
|
+
*/
|
|
2210
|
+
function nthValue(T) {
|
|
2211
|
+
const $ = this;
|
|
2212
|
+
return (ctx = {}) => {
|
|
2213
|
+
let nthValueAlt = (ctx = {}) => [
|
|
2214
|
+
{ ALT: () => $.CONSUME(T.InterpolatedIdent) },
|
|
2215
|
+
{ ALT: () => $.CONSUME(T.NthOdd) },
|
|
2216
|
+
{ ALT: () => $.CONSUME(T.NthEven) },
|
|
2217
|
+
{ ALT: () => $.CONSUME(T.Integer) },
|
|
2218
|
+
{ ALT: () => {
|
|
2219
|
+
$.OR2([
|
|
2220
|
+
{ ALT: () => $.CONSUME(T.NthSignedDimension) },
|
|
2221
|
+
{ ALT: () => $.CONSUME(T.NthUnsignedDimension) },
|
|
2222
|
+
{ ALT: () => $.CONSUME(T.NthSignedPlus) },
|
|
2223
|
+
{ ALT: () => $.CONSUME(T.NthIdent) }
|
|
2224
|
+
]);
|
|
2225
|
+
$.OPTION(() => {
|
|
2226
|
+
$.OR3([{ ALT: () => $.CONSUME(T.SignedInt) }, { ALT: () => {
|
|
2227
|
+
$.CONSUME(T.Minus);
|
|
2228
|
+
$.CONSUME(T.UnsignedInt);
|
|
2229
|
+
} }]);
|
|
2230
|
+
});
|
|
2231
|
+
$.OPTION2(() => {
|
|
2232
|
+
$.CONSUME(T.Of);
|
|
2233
|
+
$.SUBRULE($.complexSelector, { ARGS: [ctx] });
|
|
2234
|
+
});
|
|
2235
|
+
} }
|
|
2236
|
+
];
|
|
2237
|
+
return cssNthValue.call($, T, nthValueAlt)(ctx);
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
function knownFunctions(T) {
|
|
2241
|
+
const $ = this;
|
|
2242
|
+
return (ctx = {}) => {
|
|
2243
|
+
let functions = (ctx = {}) => [
|
|
2244
|
+
{ ALT: () => $.SUBRULE($.urlFunction, { ARGS: [ctx] }) },
|
|
2245
|
+
{ ALT: () => $.SUBRULE2($.varFunction, { ARGS: [ctx] }) },
|
|
2246
|
+
{ ALT: () => $.SUBRULE3($.calcFunction, { ARGS: [ctx] }) },
|
|
2247
|
+
{ ALT: () => $.SUBRULE4($.ifFunction, { ARGS: [ctx] }) },
|
|
2248
|
+
{ ALT: () => $.SUBRULE5($.booleanFunction, { ARGS: [ctx] }) }
|
|
2249
|
+
];
|
|
2250
|
+
return cssKnownFunctions.call($, T, functions)(ctx);
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
function urlFunction(T) {
|
|
2254
|
+
const $ = this;
|
|
2255
|
+
return (ctx = {}) => {
|
|
2256
|
+
$.startRule();
|
|
2257
|
+
$.CONSUME(T.UrlStart);
|
|
2258
|
+
let node = $.OR([
|
|
2259
|
+
{ ALT: () => $.SUBRULE($.string, { ARGS: [ctx] }) },
|
|
2260
|
+
{ ALT: () => $.SUBRULE($.varReference, { ARGS: [ctx] }) },
|
|
2261
|
+
{ ALT: () => $.CONSUME(T.NonQuotedUrl) }
|
|
2262
|
+
]);
|
|
2263
|
+
$.CONSUME(T.UrlEnd);
|
|
2264
|
+
if ($.RECORDING_PHASE) return;
|
|
2265
|
+
const location = $.endRule();
|
|
2266
|
+
if (!(node instanceof Node)) {
|
|
2267
|
+
const rawValue = node.image;
|
|
2268
|
+
const tokenLocation = $.getLocationInfo(node);
|
|
2269
|
+
if (rawValue.startsWith("@") || rawValue.startsWith("$")) {
|
|
2270
|
+
const resolved = getInterpolatedOrString(rawValue, tokenLocation, $.context);
|
|
2271
|
+
if (resolved instanceof Interpolated) node = resolved;
|
|
2272
|
+
else node = new Reference(resolved, { type: rawValue.startsWith("$") ? "property" : "variable" }, tokenLocation, $.context);
|
|
2273
|
+
} else node = new Any(rawValue, { role: "urlvalue" }, tokenLocation, $.context);
|
|
2274
|
+
}
|
|
2275
|
+
return new Url(node, void 0, location, $.context);
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Override CSS calc() parsing so we can maintain parse-time `calcFrames`.
|
|
2280
|
+
* This is the parse-time analogue of `Call.evalNode`'s calcFrames++/--.
|
|
2281
|
+
*/
|
|
2282
|
+
function calcFunction(T) {
|
|
2283
|
+
const $ = this;
|
|
2284
|
+
return (ctx = {}) => {
|
|
2285
|
+
$.startRule();
|
|
2286
|
+
$.CONSUME(T.Calc);
|
|
2287
|
+
const innerCtx = withCalcFrame(ctx, 1);
|
|
2288
|
+
const args = $.SUBRULE($.mathSum, { ARGS: [innerCtx] });
|
|
2289
|
+
$.CONSUME(T.RParen);
|
|
2290
|
+
const location = $.endRule();
|
|
2291
|
+
return new Call({
|
|
2292
|
+
name: "calc",
|
|
2293
|
+
args: new List([args])
|
|
2294
|
+
}, void 0, location, $.context);
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
function ifFunction(T) {
|
|
2298
|
+
const $ = this;
|
|
2299
|
+
return (ctx = {}) => {
|
|
2300
|
+
$.startRule();
|
|
2301
|
+
let name = $.CONSUME(T.IfFunction);
|
|
2302
|
+
let args = new List([]);
|
|
2303
|
+
let isCssBranch = false;
|
|
2304
|
+
const firstNode = $.SUBRULE($.guardInner, { ARGS: [{
|
|
2305
|
+
...ctx,
|
|
2306
|
+
inValueList: true
|
|
2307
|
+
}] });
|
|
2308
|
+
if ($.isType(T.Assign)) {
|
|
2309
|
+
isCssBranch = true;
|
|
2310
|
+
const branches = [];
|
|
2311
|
+
const pushBranch = (condition, value) => {
|
|
2312
|
+
const sep = new Any(":", { role: "operator" }, void 0, $.context);
|
|
2313
|
+
const loc = $.getLocationFromNodes([condition, value]);
|
|
2314
|
+
branches.push(new Sequence([
|
|
2315
|
+
condition,
|
|
2316
|
+
sep,
|
|
2317
|
+
value
|
|
2318
|
+
], void 0, loc, $.context));
|
|
2319
|
+
};
|
|
2320
|
+
$.CONSUME(T.Assign);
|
|
2321
|
+
pushBranch(firstNode, $.SUBRULE($.valueList, { ARGS: [{
|
|
2322
|
+
...ctx,
|
|
2323
|
+
inner: true
|
|
2324
|
+
}] }));
|
|
2325
|
+
$.MANY({
|
|
2326
|
+
GATE: () => $.isType(T.Semi) && !$.isTypeAt(2, T.RParen),
|
|
2327
|
+
DEF: () => {
|
|
2328
|
+
$.CONSUME2(T.Semi);
|
|
2329
|
+
const condition = $.SUBRULE2($.guardInner, { ARGS: [{
|
|
2330
|
+
...ctx,
|
|
2331
|
+
inValueList: true
|
|
2332
|
+
}] });
|
|
2333
|
+
$.CONSUME2(T.Assign);
|
|
2334
|
+
pushBranch(condition, $.SUBRULE2($.valueList, { ARGS: [{
|
|
2335
|
+
...ctx,
|
|
2336
|
+
inner: true
|
|
2337
|
+
}] }));
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
$.OPTION(() => $.CONSUME3(T.Semi));
|
|
2341
|
+
$.CONSUME2(T.RParen);
|
|
2342
|
+
args = new List([branches.length === 1 ? branches[0] : new List(branches, { sep: ";" }, $.getLocationFromNodes(branches), $.context)]);
|
|
2343
|
+
} else {
|
|
2344
|
+
isCssBranch = false;
|
|
2345
|
+
let node = firstNode;
|
|
2346
|
+
const parenValue = node instanceof Paren ? node.value : void 0;
|
|
2347
|
+
args = new List([parenValue instanceof Node ? parenValue : node]);
|
|
2348
|
+
$.OR([{ ALT: () => {
|
|
2349
|
+
$.CONSUME(T.Semi);
|
|
2350
|
+
node = $.SUBRULE2($.valueList, { ARGS: [{
|
|
2351
|
+
...ctx,
|
|
2352
|
+
allowAnonymousMixins: true
|
|
2353
|
+
}] });
|
|
2354
|
+
args = new List([...args.value, node], args.options, $.getLocationFromNodes([...args.value, node]), $.context);
|
|
2355
|
+
$.OPTION(() => {
|
|
2356
|
+
$.CONSUME4(T.Semi);
|
|
2357
|
+
node = $.SUBRULE3($.valueList, { ARGS: [{
|
|
2358
|
+
...ctx,
|
|
2359
|
+
allowAnonymousMixins: true
|
|
2360
|
+
}] });
|
|
2361
|
+
args = new List([...args.value, node], args.options, $.getLocationFromNodes([...args.value, node]), $.context);
|
|
2362
|
+
});
|
|
2363
|
+
} }, { ALT: () => {
|
|
2364
|
+
$.CONSUME(T.Comma);
|
|
2365
|
+
node = $.SUBRULE($.callArgument, { ARGS: [{
|
|
2366
|
+
...ctx,
|
|
2367
|
+
allowAnonymousMixins: true
|
|
2368
|
+
}] });
|
|
2369
|
+
args = new List([...args.value, node], args.options, $.getLocationFromNodes([...args.value, node]), $.context);
|
|
2370
|
+
$.OPTION2(() => {
|
|
2371
|
+
$.CONSUME2(T.Comma);
|
|
2372
|
+
node = $.SUBRULE2($.callArgument, { ARGS: [{
|
|
2373
|
+
...ctx,
|
|
2374
|
+
allowAnonymousMixins: true
|
|
2375
|
+
}] });
|
|
2376
|
+
args = new List([...args.value, node], args.options, $.getLocationFromNodes([...args.value, node]), $.context);
|
|
2377
|
+
});
|
|
2378
|
+
} }]);
|
|
2379
|
+
$.CONSUME3(T.RParen);
|
|
2380
|
+
}
|
|
2381
|
+
let location = $.endRule();
|
|
2382
|
+
return new Call({
|
|
2383
|
+
name: new Reference("if", {
|
|
2384
|
+
type: "function",
|
|
2385
|
+
fallbackValue: isCssBranch ? true : void 0
|
|
2386
|
+
}, $.getLocationInfo(name), $.context),
|
|
2387
|
+
args
|
|
2388
|
+
}, void 0, location, $.context);
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
function booleanFunction(T) {
|
|
2392
|
+
const $ = this;
|
|
2393
|
+
return (ctx = {}) => {
|
|
2394
|
+
$.startRule();
|
|
2395
|
+
$.CONSUME(T.BooleanFunction);
|
|
2396
|
+
let arg = $.SUBRULE($.guardInner, { ARGS: [{
|
|
2397
|
+
...ctx,
|
|
2398
|
+
inValueList: true
|
|
2399
|
+
}] });
|
|
2400
|
+
$.CONSUME(T.RParen);
|
|
2401
|
+
let location = $.endRule();
|
|
2402
|
+
const argValue = arg instanceof Paren ? arg.value : void 0;
|
|
2403
|
+
return new Expression(argValue instanceof Node ? argValue : arg, { parens: true }, location, $.context);
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
function varReference(T) {
|
|
2407
|
+
const $ = this;
|
|
2408
|
+
return (ctx = {}) => {
|
|
2409
|
+
let node = $.OR([
|
|
2410
|
+
{ ALT: () => {
|
|
2411
|
+
let token = $.CONSUME(T.PropertyReference);
|
|
2412
|
+
if ($.RECORDING_PHASE) return;
|
|
2413
|
+
if (ctx.inCustomPropertyValue) {
|
|
2414
|
+
const atName = token.image;
|
|
2415
|
+
const ident = token.image.slice(1);
|
|
2416
|
+
$.warnDeprecation(`${atName} in custom property values is treated as literal text, not a property reference. Use \${${ident}} if you want it to be evaluated.`, token, "property-in-unknown-value");
|
|
2417
|
+
return new Reference({ key: new Quoted(token.image.slice(1), { quote: "'" }, $.getLocationInfo(token), $.context) }, {
|
|
2418
|
+
type: "index",
|
|
2419
|
+
role: "ident"
|
|
2420
|
+
}, $.getLocationInfo(token), $.context);
|
|
2421
|
+
}
|
|
2422
|
+
return new Reference({ key: new Quoted(token.image.slice(1), { quote: "'" }, $.getLocationInfo(token), $.context) }, { type: "index" }, $.getLocationInfo(token), $.context);
|
|
2423
|
+
} },
|
|
2424
|
+
{ ALT: () => {
|
|
2425
|
+
let token = $.CONSUME(T.NestedReference);
|
|
2426
|
+
if ($.RECORDING_PHASE) return;
|
|
2427
|
+
const raw = token.image;
|
|
2428
|
+
const isPropertyLookup = raw.startsWith("$");
|
|
2429
|
+
const type = raw.startsWith("@") ? "variable" : "index";
|
|
2430
|
+
const rawKey = getInterpolatedOrString(raw);
|
|
2431
|
+
const key = isPropertyLookup ? typeof rawKey === "string" ? new Quoted(rawKey, { quote: "'" }, $.getLocationInfo(token), $.context) : new Quoted(rawKey, { quote: "'" }, $.getLocationInfo(token), $.context) : rawKey;
|
|
2432
|
+
if (ctx.inCustomPropertyValue && typeof key === "string") return new Reference({ key }, {
|
|
2433
|
+
type: "variable",
|
|
2434
|
+
role: "ident"
|
|
2435
|
+
}, $.getLocationInfo(token), $.context);
|
|
2436
|
+
if (typeof key === "string") return new Reference(key, { type }, $.getLocationInfo(token), $.context);
|
|
2437
|
+
return new Reference({ key }, { type }, $.getLocationInfo(token), $.context);
|
|
2438
|
+
} },
|
|
2439
|
+
{ ALT: () => {
|
|
2440
|
+
let token = $.SUBRULE($.varName, { ARGS: [ctx] });
|
|
2441
|
+
if ($.RECORDING_PHASE) return;
|
|
2442
|
+
if (ctx.inCustomPropertyValue) {
|
|
2443
|
+
const atName = token.image;
|
|
2444
|
+
const ident = token.image.slice(1);
|
|
2445
|
+
$.warnDeprecation(`${atName} in custom property values is treated as literal text, not a variable reference. Use @{${ident}} if you want it to be evaluated.`, token, "variable-in-unknown-value");
|
|
2446
|
+
return new Reference({ key: token.image.slice(1) }, {
|
|
2447
|
+
type: "variable",
|
|
2448
|
+
role: "ident"
|
|
2449
|
+
}, $.getLocationInfo(token), $.context);
|
|
2450
|
+
}
|
|
2451
|
+
if (ctx.atRulePreludeBareVariableAs === "index") {
|
|
2452
|
+
const nextToken = $.LA(1).tokenType;
|
|
2453
|
+
if ($.noSep() && (nextToken === T.LSquare || nextToken === T.LParen)) return new Reference(token.image.slice(1), { type: "variable" }, $.getLocationInfo(token), $.context);
|
|
2454
|
+
const atName = token.image;
|
|
2455
|
+
const ident = token.image.slice(1);
|
|
2456
|
+
$.warnDeprecation(`"${atName}" in at-rule preludes is deprecated. Use "@{${ident}}" in Less; outside declaration values this is normalized to indexed lookup syntax.`, token, "at-rule-prelude-variable");
|
|
2457
|
+
return new Reference({ key: ident }, {
|
|
2458
|
+
type: "index",
|
|
2459
|
+
role: "ident"
|
|
2460
|
+
}, $.getLocationInfo(token), $.context);
|
|
2461
|
+
}
|
|
2462
|
+
return new Reference(token.image.slice(1), { type: "variable" }, $.getLocationInfo(token), $.context);
|
|
2463
|
+
} }
|
|
2464
|
+
]);
|
|
2465
|
+
$.OR2([
|
|
2466
|
+
{ ALT: () => {
|
|
2467
|
+
/** This spreads a (list) value within a containing list when evaluated */
|
|
2468
|
+
let token = $.CONSUME(T.Ellipsis);
|
|
2469
|
+
if (!$.RECORDING_PHASE) node = new Rest(node, void 0, $.getLocationFromNodes([node, token]), $.context);
|
|
2470
|
+
} },
|
|
2471
|
+
{
|
|
2472
|
+
GATE: () => {
|
|
2473
|
+
if (node?.options?.type !== "variable") return false;
|
|
2474
|
+
let next = $.LA(1).tokenType;
|
|
2475
|
+
if (next !== T.LSquare && next !== T.LParen) return false;
|
|
2476
|
+
if (!$.noSep()) return false;
|
|
2477
|
+
return true;
|
|
2478
|
+
},
|
|
2479
|
+
ALT: () => {
|
|
2480
|
+
$.AT_LEAST_ONE({
|
|
2481
|
+
GATE: () => {
|
|
2482
|
+
let next = $.LA(1).tokenType;
|
|
2483
|
+
if (next !== T.LSquare && next !== T.LParen) return false;
|
|
2484
|
+
if (!$.noSep()) return false;
|
|
2485
|
+
return true;
|
|
2486
|
+
},
|
|
2487
|
+
DEF: () => {
|
|
2488
|
+
node = $.SUBRULE($.lookupOrCall, { ARGS: [{
|
|
2489
|
+
...ctx,
|
|
2490
|
+
node
|
|
2491
|
+
}] });
|
|
2492
|
+
}
|
|
2493
|
+
});
|
|
2494
|
+
$.OPTION(() => {
|
|
2495
|
+
$.OPTION2(() => $.CONSUME(T.Gt));
|
|
2496
|
+
node = $.SUBRULE($.mixinReference, { ARGS: [{
|
|
2497
|
+
...ctx,
|
|
2498
|
+
node
|
|
2499
|
+
}] });
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
},
|
|
2503
|
+
{ ALT: () => void 0 }
|
|
2504
|
+
]);
|
|
2505
|
+
return node;
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2508
|
+
function valueReference(T) {
|
|
2509
|
+
const $ = this;
|
|
2510
|
+
return (ctx = {}) => {
|
|
2511
|
+
return $.OR([{ ALT: () => $.SUBRULE($.varReference, { ARGS: [ctx] }) }, { ALT: () => $.SUBRULE2($.mixinReference, { ARGS: [ctx] }) }]);
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2514
|
+
function functionCall(T) {
|
|
2515
|
+
const $ = this;
|
|
2516
|
+
return (ctx = {}) => {
|
|
2517
|
+
const modernColorFunctions = new Set([
|
|
2518
|
+
"rgb",
|
|
2519
|
+
"rgba",
|
|
2520
|
+
"hsl",
|
|
2521
|
+
"hsla"
|
|
2522
|
+
]);
|
|
2523
|
+
const isModernColorCall = (name, args) => {
|
|
2524
|
+
if (!modernColorFunctions.has(name.toLowerCase())) return false;
|
|
2525
|
+
if (!args || args.value.length !== 1) return false;
|
|
2526
|
+
const firstArg = args.value[0];
|
|
2527
|
+
return Boolean(isNode(firstArg, N.Sequence) && firstArg.value.length >= 2);
|
|
2528
|
+
};
|
|
2529
|
+
let funcAlt = (ctx = {}) => [{
|
|
2530
|
+
GATE: () => {
|
|
2531
|
+
let tokenType = $.LA(1).tokenType;
|
|
2532
|
+
return tokenType === T.UrlStart || tokenType === T.Var || tokenType === T.Calc || tokenType === T.IfFunction || tokenType === T.BooleanFunction;
|
|
2533
|
+
},
|
|
2534
|
+
ALT: () => $.SUBRULE($.knownFunctions, { ARGS: [ctx] })
|
|
2535
|
+
}, {
|
|
2536
|
+
GATE: () => {
|
|
2537
|
+
let tokenType = $.LA(1).tokenType;
|
|
2538
|
+
return tokenType !== T.UrlStart && tokenType !== T.Var && tokenType !== T.Calc && tokenType !== T.IfFunction && tokenType !== T.BooleanFunction;
|
|
2539
|
+
},
|
|
2540
|
+
ALT: () => {
|
|
2541
|
+
$.startRule();
|
|
2542
|
+
const fnStart = $.CONSUME(T.FunctionStart);
|
|
2543
|
+
const fnNameForCtx = fnStart.image.slice(0, -1);
|
|
2544
|
+
let args;
|
|
2545
|
+
$.OPTION(() => args = $.SUBRULE2($.functionCallArgs, { ARGS: [{
|
|
2546
|
+
...ctx,
|
|
2547
|
+
currentFunctionName: fnNameForCtx
|
|
2548
|
+
}] }));
|
|
2549
|
+
$.CONSUME(T.RParen);
|
|
2550
|
+
const location = $.endRule();
|
|
2551
|
+
const nameValue = fnNameForCtx;
|
|
2552
|
+
if (nameValue === "unit" && args?.value[1] instanceof Any) {
|
|
2553
|
+
const unitArg = args.value[1];
|
|
2554
|
+
const quotedUnit = new Quoted(unitArg.valueOf(), { quote: "\"" }, void 0, $.context);
|
|
2555
|
+
const newArgsData = [...args.value];
|
|
2556
|
+
newArgsData[1] = quotedUnit;
|
|
2557
|
+
args = new List(newArgsData, args.options, $.getLocationFromNodes(newArgsData), $.context);
|
|
2558
|
+
}
|
|
2559
|
+
if (ctx.detachedRulesetUsage === "default-param" && nameValue === "default") return new Call({
|
|
2560
|
+
name: "default",
|
|
2561
|
+
args
|
|
2562
|
+
}, void 0, location, $.context);
|
|
2563
|
+
if (nameValue === "each" && args?.value.length === 2 && isNode(args.value[1], N.Mixin)) {
|
|
2564
|
+
const iterable = args.value[0];
|
|
2565
|
+
const callback = args.value[1];
|
|
2566
|
+
return new For({
|
|
2567
|
+
pattern: createEachPattern(callback, location, $.context),
|
|
2568
|
+
iterable: {
|
|
2569
|
+
kind: "node",
|
|
2570
|
+
value: iterable
|
|
2571
|
+
},
|
|
2572
|
+
rules: callback.rules
|
|
2573
|
+
}, void 0, location, $.context);
|
|
2574
|
+
}
|
|
2575
|
+
const nameNode = new Reference(nameValue, {
|
|
2576
|
+
type: "function",
|
|
2577
|
+
fallbackValue: true
|
|
2578
|
+
}, $.getLocationInfo(fnStart), $.context);
|
|
2579
|
+
/** Less / Sass functions we try to call that throw just get turned into calls. */
|
|
2580
|
+
const modernSyntax = isModernColorCall(nameValue, args);
|
|
2581
|
+
return new Call({
|
|
2582
|
+
name: nameNode,
|
|
2583
|
+
args
|
|
2584
|
+
}, {
|
|
2585
|
+
silentFail: true,
|
|
2586
|
+
...modernSyntax ? { modernSyntax: true } : {}
|
|
2587
|
+
}, location, $.context);
|
|
2588
|
+
}
|
|
2589
|
+
}];
|
|
2590
|
+
return $.OR(funcAlt(ctx));
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2593
|
+
function functionCallArgs(T) {
|
|
2594
|
+
const $ = this;
|
|
2595
|
+
return (ctx = {}) => {
|
|
2596
|
+
$.startRule();
|
|
2597
|
+
const prevInner = ctx.inner;
|
|
2598
|
+
ctx.inner = true;
|
|
2599
|
+
const argCtx = {
|
|
2600
|
+
...ctx,
|
|
2601
|
+
allowComma: false,
|
|
2602
|
+
parenFrames: [...getParenFrames$1(ctx), false],
|
|
2603
|
+
detachedRulesetUsage: "function-arg",
|
|
2604
|
+
inFunctionArgs: true
|
|
2605
|
+
};
|
|
2606
|
+
let commaNodes;
|
|
2607
|
+
let semiNodes = [];
|
|
2608
|
+
let isSemiList = false;
|
|
2609
|
+
try {
|
|
2610
|
+
let node = $.SUBRULE($.callArgument, { ARGS: [argCtx] });
|
|
2611
|
+
commaNodes = [node];
|
|
2612
|
+
$.MANY({
|
|
2613
|
+
GATE: () => $.isType(T.Comma),
|
|
2614
|
+
DEF: () => {
|
|
2615
|
+
$.CONSUME(T.Comma);
|
|
2616
|
+
node = $.SUBRULE2($.callArgument, { ARGS: [argCtx] });
|
|
2617
|
+
commaNodes.push(node);
|
|
2618
|
+
}
|
|
2619
|
+
});
|
|
2620
|
+
$.OPTION(() => {
|
|
2621
|
+
$.CONSUME(T.Semi);
|
|
2622
|
+
isSemiList = true;
|
|
2623
|
+
if (commaNodes.length > 1) semiNodes.push(new List(commaNodes, void 0, $.getLocationFromNodes(commaNodes), $.context));
|
|
2624
|
+
else semiNodes.push(commaNodes[0]);
|
|
2625
|
+
node = $.SUBRULE3($.callArgument, { ARGS: [{
|
|
2626
|
+
...argCtx,
|
|
2627
|
+
allowComma: true
|
|
2628
|
+
}] });
|
|
2629
|
+
semiNodes.push(node);
|
|
2630
|
+
$.MANY2({
|
|
2631
|
+
GATE: () => $.isType(T.Semi),
|
|
2632
|
+
DEF: () => {
|
|
2633
|
+
$.CONSUME2(T.Semi);
|
|
2634
|
+
node = $.SUBRULE4($.callArgument, { ARGS: [{
|
|
2635
|
+
...argCtx,
|
|
2636
|
+
allowComma: true
|
|
2637
|
+
}] });
|
|
2638
|
+
semiNodes.push(node);
|
|
2639
|
+
}
|
|
2640
|
+
});
|
|
2641
|
+
});
|
|
2642
|
+
} finally {
|
|
2643
|
+
ctx.inner = prevInner;
|
|
2644
|
+
}
|
|
2645
|
+
$.endRule();
|
|
2646
|
+
return new List(isSemiList ? semiNodes : commaNodes, isSemiList ? { sep: ";" } : void 0);
|
|
2647
|
+
};
|
|
2648
|
+
}
|
|
2649
|
+
function value(T) {
|
|
2650
|
+
const $ = this;
|
|
2651
|
+
return (ctx = {}) => {
|
|
2652
|
+
if ($.isType(T.Percent)) {}
|
|
2653
|
+
let _isMixinReference = void 0;
|
|
2654
|
+
const isMixinReference = () => {
|
|
2655
|
+
if (_isMixinReference === void 0) {
|
|
2656
|
+
let tt1 = $.LA(1).tokenType;
|
|
2657
|
+
let tt2 = $.LA(2).tokenType;
|
|
2658
|
+
/**
|
|
2659
|
+
* We'll allow a few "bare" mixin references without parens
|
|
2660
|
+
* or square brackets, but not if they'll conflict with
|
|
2661
|
+
* other syntax.
|
|
2662
|
+
*/
|
|
2663
|
+
_isMixinReference = tt1 === T.DotName || tt1 === T.HashName || tt1 === T.InterpolatedSelector || (tt1 === T.ColorIdentStart || tt1 === T.InterpolatedSelector) && (tt2 === T.Gt || tt2 === T.DotName || tt2 === T.HashName || tt2 === T.InterpolatedSelector || $.noSep(1) && (tt2 === T.LParen || tt2 === T.LSquare || tt2 === T.HashName || tt2 === T.DotName));
|
|
2664
|
+
}
|
|
2665
|
+
return _isMixinReference;
|
|
2666
|
+
};
|
|
2667
|
+
let node = $.OR([
|
|
2668
|
+
{
|
|
2669
|
+
GATE: () => $.check(T.FunctionStart),
|
|
2670
|
+
ALT: () => $.SUBRULE($.functionCall, { ARGS: [ctx] })
|
|
2671
|
+
},
|
|
2672
|
+
{
|
|
2673
|
+
GATE: () => $.isType(T.Star) && $.isTypeAt(2, T.LSquare),
|
|
2674
|
+
ALT: () => $.SUBRULE($.selectorCapture, { ARGS: [ctx] })
|
|
2675
|
+
},
|
|
2676
|
+
{
|
|
2677
|
+
GATE: isMixinReference,
|
|
2678
|
+
ALT: () => $.SUBRULE($.mixinReference, { ARGS: [ctx] })
|
|
2679
|
+
},
|
|
2680
|
+
{
|
|
2681
|
+
GATE: () => !isMixinReference(),
|
|
2682
|
+
ALT: () => $.CONSUME(T.Color)
|
|
2683
|
+
},
|
|
2684
|
+
{
|
|
2685
|
+
GATE: () => !isMixinReference(),
|
|
2686
|
+
ALT: () => $.CONSUME2(T.Ident)
|
|
2687
|
+
},
|
|
2688
|
+
{ ALT: () => $.SUBRULE($.varReference, { ARGS: [ctx] }) },
|
|
2689
|
+
{ ALT: () => $.CONSUME(T.DefaultGuardFunc) },
|
|
2690
|
+
{ ALT: () => $.CONSUME(T.Dimension) },
|
|
2691
|
+
{ ALT: () => $.CONSUME(T.Number) },
|
|
2692
|
+
{
|
|
2693
|
+
GATE: () => ctx.currentFunctionName === "unit",
|
|
2694
|
+
ALT: () => $.CONSUME(T.Percent)
|
|
2695
|
+
},
|
|
2696
|
+
{ ALT: () => $.CONSUME(T.UnicodeRange) },
|
|
2697
|
+
{ ALT: () => $.SUBRULE($.string, { ARGS: [ctx] }) },
|
|
2698
|
+
{ ALT: () => $.CONSUME(T.JavaScript) },
|
|
2699
|
+
(
|
|
2700
|
+
/** Explicitly not marked as an ident */
|
|
2701
|
+
{ ALT: () => $.CONSUME(T.When) }),
|
|
2702
|
+
{ ALT: () => $.SUBRULE($.squareValue, { ARGS: [ctx] }) },
|
|
2703
|
+
{
|
|
2704
|
+
GATE: () => $.looseMode && !!ctx.inner,
|
|
2705
|
+
ALT: () => $.CONSUME(T.Colon)
|
|
2706
|
+
},
|
|
2707
|
+
{
|
|
2708
|
+
GATE: () => $.looseMode && !!ctx.inFunctionArgs,
|
|
2709
|
+
ALT: () => $.CONSUME(T.Eq)
|
|
2710
|
+
},
|
|
2711
|
+
{
|
|
2712
|
+
GATE: () => $.looseMode,
|
|
2713
|
+
ALT: () => $.CONSUME(T.Unknown)
|
|
2714
|
+
},
|
|
2715
|
+
{
|
|
2716
|
+
GATE: () => $.legacyMode,
|
|
2717
|
+
ALT: () => $.CONSUME(T.LegacyMSFilter)
|
|
2718
|
+
}
|
|
2719
|
+
]);
|
|
2720
|
+
if (!$.RECORDING_PHASE) {
|
|
2721
|
+
if (!(node instanceof Node)) node = $.processValueToken(node);
|
|
2722
|
+
return node;
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
function string(T) {
|
|
2727
|
+
const $ = this;
|
|
2728
|
+
return (ctx = {}) => {
|
|
2729
|
+
return $.OR([{
|
|
2730
|
+
GATE: () => $.isType(T.SingleQuoteStart),
|
|
2731
|
+
ALT: () => {
|
|
2732
|
+
$.startRule();
|
|
2733
|
+
let quote = $.CONSUME(T.SingleQuoteStart);
|
|
2734
|
+
let contents;
|
|
2735
|
+
$.OPTION2(() => contents = $.CONSUME(T.SingleQuoteStringContents));
|
|
2736
|
+
$.CONSUME(T.SingleQuoteEnd);
|
|
2737
|
+
let quoteImg = quote.image;
|
|
2738
|
+
let escaped = false;
|
|
2739
|
+
if (quoteImg.startsWith("~")) {
|
|
2740
|
+
escaped = true;
|
|
2741
|
+
quoteImg = quoteImg.slice(1);
|
|
2742
|
+
}
|
|
2743
|
+
let location = $.endRule();
|
|
2744
|
+
let value = contents?.image;
|
|
2745
|
+
if (escaped && value) value = value.replace(/\\(?:\r\n?|\n|\f)/g, "\n");
|
|
2746
|
+
if ($.RECORDING_PHASE) return;
|
|
2747
|
+
const quoteChar = toQuote(quoteImg);
|
|
2748
|
+
if (value && (value.includes("@{") || value.includes("${"))) return new Quoted(processStringInterpolation(value, location, $.context), {
|
|
2749
|
+
quote: quoteChar,
|
|
2750
|
+
escaped
|
|
2751
|
+
}, location, $.context);
|
|
2752
|
+
return new Quoted(new Any(value ?? "", { role: "any" }), {
|
|
2753
|
+
quote: quoteChar,
|
|
2754
|
+
escaped
|
|
2755
|
+
}, location, $.context);
|
|
2756
|
+
}
|
|
2757
|
+
}, {
|
|
2758
|
+
GATE: () => $.isType(T.DoubleQuoteStart),
|
|
2759
|
+
ALT: () => {
|
|
2760
|
+
$.startRule();
|
|
2761
|
+
let quote = $.CONSUME(T.DoubleQuoteStart);
|
|
2762
|
+
let contents;
|
|
2763
|
+
$.OPTION3(() => contents = $.CONSUME(T.DoubleQuoteStringContents));
|
|
2764
|
+
$.CONSUME(T.DoubleQuoteEnd);
|
|
2765
|
+
let quoteImg = quote.image;
|
|
2766
|
+
let escaped = false;
|
|
2767
|
+
if (quoteImg.startsWith("~")) {
|
|
2768
|
+
escaped = true;
|
|
2769
|
+
quoteImg = quoteImg.slice(1);
|
|
2770
|
+
}
|
|
2771
|
+
let location = $.endRule();
|
|
2772
|
+
let value = contents?.image;
|
|
2773
|
+
if (escaped && value) value = value.replace(/\\(?:\r\n?|\n|\f)/g, "\n");
|
|
2774
|
+
if ($.RECORDING_PHASE) return;
|
|
2775
|
+
const quoteChar = toQuote(quoteImg);
|
|
2776
|
+
if (value && (value.includes("@{") || value.includes("${"))) return new Quoted(processStringInterpolation(value, location, $.context), {
|
|
2777
|
+
quote: quoteChar,
|
|
2778
|
+
escaped
|
|
2779
|
+
}, location, $.context);
|
|
2780
|
+
return new Quoted(new Any(value ?? "", { role: "any" }), {
|
|
2781
|
+
quote: quoteChar,
|
|
2782
|
+
escaped
|
|
2783
|
+
}, location, $.context);
|
|
2784
|
+
}
|
|
2785
|
+
}]);
|
|
2786
|
+
};
|
|
2787
|
+
}
|
|
2788
|
+
/**
|
|
2789
|
+
* Find interpolation patterns like @{...} or ${...}, handling nested braces.
|
|
2790
|
+
* Returns an array of { start, end, prefix, content } for each match.
|
|
2791
|
+
*/
|
|
2792
|
+
function findInterpolations(value) {
|
|
2793
|
+
const matches = [];
|
|
2794
|
+
let i = 0;
|
|
2795
|
+
while (i < value.length) if ((value[i] === "@" || value[i] === "$") && value[i + 1] === "{") {
|
|
2796
|
+
const prefix = value[i];
|
|
2797
|
+
const start = i;
|
|
2798
|
+
i += 2;
|
|
2799
|
+
let braceCount = 1;
|
|
2800
|
+
const contentStart = i;
|
|
2801
|
+
while (i < value.length && braceCount > 0) {
|
|
2802
|
+
if (value[i] === "{") braceCount++;
|
|
2803
|
+
else if (value[i] === "}") braceCount--;
|
|
2804
|
+
i++;
|
|
2805
|
+
}
|
|
2806
|
+
if (braceCount === 0) {
|
|
2807
|
+
const content = value.slice(contentStart, i - 1);
|
|
2808
|
+
matches.push({
|
|
2809
|
+
start,
|
|
2810
|
+
end: i,
|
|
2811
|
+
prefix,
|
|
2812
|
+
content
|
|
2813
|
+
});
|
|
2814
|
+
}
|
|
2815
|
+
} else i++;
|
|
2816
|
+
return matches;
|
|
2817
|
+
}
|
|
2818
|
+
function processStringInterpolation(value, location, context) {
|
|
2819
|
+
const matches = findInterpolations(value);
|
|
2820
|
+
if (matches.length === 0) return new Any(value, { role: "any" }, location, context);
|
|
2821
|
+
const replacements = [];
|
|
2822
|
+
let source = value;
|
|
2823
|
+
let offset = 0;
|
|
2824
|
+
for (const match of matches) {
|
|
2825
|
+
const adjustedStart = match.start - offset;
|
|
2826
|
+
const adjustedEnd = match.end - offset;
|
|
2827
|
+
const before = source.slice(0, adjustedStart);
|
|
2828
|
+
const after = source.slice(adjustedEnd);
|
|
2829
|
+
source = before + INTERPOLATION_PLACEHOLDER + after;
|
|
2830
|
+
offset += match.end - match.start - INTERPOLATION_PLACEHOLDER.length;
|
|
2831
|
+
const innerResult = processStringInterpolation(match.content, location, context);
|
|
2832
|
+
if (innerResult instanceof Interpolated) {
|
|
2833
|
+
const nestedRef = new Reference({ key: innerResult }, {
|
|
2834
|
+
type: "variable",
|
|
2835
|
+
role: "ident"
|
|
2836
|
+
}, location, context);
|
|
2837
|
+
replacements.push(new Expression(nestedRef, void 0, location, context));
|
|
2838
|
+
} else replacements.push(createInterpolatedReference(match.prefix, match.content, location, context));
|
|
2839
|
+
}
|
|
2840
|
+
return new Interpolated({
|
|
2841
|
+
source,
|
|
2842
|
+
replacements
|
|
2843
|
+
}, { role: "ident" }, location, context);
|
|
2844
|
+
}
|
|
2845
|
+
function mathValue(T) {
|
|
2846
|
+
const $ = this;
|
|
2847
|
+
return (ctx = {}) => {
|
|
2848
|
+
let valueAlt = (ctx = {}) => [
|
|
2849
|
+
{ ALT: () => $.CONSUME(T.AtKeyword) },
|
|
2850
|
+
{ ALT: () => $.CONSUME(T.Number) },
|
|
2851
|
+
{ ALT: () => $.CONSUME(T.Dimension) },
|
|
2852
|
+
{ ALT: () => $.CONSUME(T.Ident) },
|
|
2853
|
+
{ ALT: () => $.SUBRULE($.functionCall, { ARGS: [ctx] }) },
|
|
2854
|
+
{
|
|
2855
|
+
GATE: () => $.LA(1).image.startsWith("~"),
|
|
2856
|
+
ALT: () => $.SUBRULE2($.string, { ARGS: [ctx] })
|
|
2857
|
+
},
|
|
2858
|
+
{
|
|
2859
|
+
GATE: () => !$.isTypeAt(2, T.LParen),
|
|
2860
|
+
ALT: () => $.CONSUME(T.MathConstant)
|
|
2861
|
+
},
|
|
2862
|
+
{ ALT: () => $.SUBRULE($.mathParen, { ARGS: [ctx] }) }
|
|
2863
|
+
];
|
|
2864
|
+
return cssMathValue.call($, T, valueAlt)(ctx);
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
function mathProduct(T) {
|
|
2868
|
+
const $ = this;
|
|
2869
|
+
return (ctx = {}) => {
|
|
2870
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
2871
|
+
$.startRule();
|
|
2872
|
+
let left = $.SUBRULE($.mathValue, { ARGS: [ctx] });
|
|
2873
|
+
while ($.isType(T.Star) || $.isType(T.Divide)) {
|
|
2874
|
+
const op = $.isType(T.Star) ? $.CONSUME(T.Star) : $.CONSUME(T.Divide);
|
|
2875
|
+
const right = $.SUBRULE2($.mathValue, { ARGS: [ctx] });
|
|
2876
|
+
if (!RECORDING_PHASE) {
|
|
2877
|
+
const opStr = toOperator(op.image);
|
|
2878
|
+
left = new Operation([
|
|
2879
|
+
left,
|
|
2880
|
+
opStr,
|
|
2881
|
+
right
|
|
2882
|
+
], { inCalc: true }, void 0, $.context);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
if (RECORDING_PHASE) return;
|
|
2886
|
+
left._location = $.endRule();
|
|
2887
|
+
return left;
|
|
2888
|
+
};
|
|
2889
|
+
}
|
|
2890
|
+
function mathSum(T) {
|
|
2891
|
+
const $ = this;
|
|
2892
|
+
return (ctx = {}) => {
|
|
2893
|
+
const RECORDING_PHASE = $.RECORDING_PHASE;
|
|
2894
|
+
$.startRule();
|
|
2895
|
+
let left = $.SUBRULE($.mathProduct, { ARGS: [ctx] });
|
|
2896
|
+
$.MANY(() => {
|
|
2897
|
+
const op = $.CONSUME(T.AdditionOperator);
|
|
2898
|
+
const right = $.SUBRULE2($.mathProduct, { ARGS: [ctx] });
|
|
2899
|
+
if (!RECORDING_PHASE) {
|
|
2900
|
+
const opStr = toOperator(op.image);
|
|
2901
|
+
left = new Operation([
|
|
2902
|
+
left,
|
|
2903
|
+
opStr,
|
|
2904
|
+
right
|
|
2905
|
+
], { inCalc: true }, void 0, $.context);
|
|
2906
|
+
}
|
|
2907
|
+
});
|
|
2908
|
+
if (RECORDING_PHASE) return;
|
|
2909
|
+
left._location = $.endRule();
|
|
2910
|
+
return left;
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
//#endregion
|
|
2914
|
+
//#region src/productions/guards.ts
|
|
2915
|
+
function isScriptUsePath(path) {
|
|
2916
|
+
const filePart = path.replace(/[?#].*$/u, "");
|
|
2917
|
+
return path === "#less" || path.startsWith("#less/") || /\.(?:js|mjs|cjs|ts|mts|cts|json)$/i.test(filePart);
|
|
2918
|
+
}
|
|
2919
|
+
function defaultNamespaceFromPath(path) {
|
|
2920
|
+
if (path === "#less") return "less";
|
|
2921
|
+
if (path.startsWith("#less/")) return path.split("/").filter(Boolean).pop();
|
|
2922
|
+
const base = path.split("/").filter(Boolean).pop();
|
|
2923
|
+
if (!base) return;
|
|
2924
|
+
return base.replace(/\.(less|css|jess|js|mjs|cjs|ts|mts|cts|json)$/i, "") || void 0;
|
|
2925
|
+
}
|
|
2926
|
+
function getParenFrames(ctx) {
|
|
2927
|
+
return ctx?.parenFrames ?? [];
|
|
2928
|
+
}
|
|
2929
|
+
function isDefaultGuardCall(node) {
|
|
2930
|
+
if (!node || !isNode(node, N.Call)) return false;
|
|
2931
|
+
const callName = node.name;
|
|
2932
|
+
const callNameStr = String(typeof callName === "object" && callName !== null && "valueOf" in callName ? callName.valueOf() : callName ?? "");
|
|
2933
|
+
if (callNameStr === "default" || callNameStr === "??") return true;
|
|
2934
|
+
if (callName instanceof Reference) {
|
|
2935
|
+
const key = callName.key;
|
|
2936
|
+
const keyStr = String(typeof key === "object" && key !== null && "valueOf" in key ? key.valueOf() : key ?? "");
|
|
2937
|
+
return keyStr === "default" || keyStr === "??";
|
|
2938
|
+
}
|
|
2939
|
+
return false;
|
|
2940
|
+
}
|
|
2941
|
+
const cssUnknownAtRule = productions.unknownAtRule;
|
|
2942
|
+
function isGuardComparisonToken(tt, T) {
|
|
2943
|
+
return tt === T.CompareOperator || tt === T.Eq || tt === T.Gt || tt === T.GtEq || tt === T.GtEqAlias || tt === T.Lt || tt === T.LtEq || tt === T.LtEqAlias;
|
|
2944
|
+
}
|
|
2945
|
+
function normalizeComparisonOperator(op) {
|
|
2946
|
+
switch (op) {
|
|
2947
|
+
case "=>":
|
|
2948
|
+
case ">=": return ">=";
|
|
2949
|
+
case "=<":
|
|
2950
|
+
case "<=": return "<=";
|
|
2951
|
+
case "=": return "=";
|
|
2952
|
+
case ">": return ">";
|
|
2953
|
+
case "<": return "<";
|
|
2954
|
+
default: return "=";
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
function guard(T) {
|
|
2958
|
+
const $ = this;
|
|
2959
|
+
return (ctx = {}) => {
|
|
2960
|
+
$.CONSUME(T.When);
|
|
2961
|
+
return $.OR([{
|
|
2962
|
+
GATE: () => !!ctx.inValueList,
|
|
2963
|
+
ALT: () => $.SUBRULE($.comparison, { ARGS: [ctx] })
|
|
2964
|
+
}, { ALT: () => {
|
|
2965
|
+
return $.SUBRULE($.guardOr, { ARGS: [{
|
|
2966
|
+
...ctx,
|
|
2967
|
+
allowComma: true
|
|
2968
|
+
}] });
|
|
2969
|
+
} }]);
|
|
2970
|
+
};
|
|
2971
|
+
}
|
|
2972
|
+
/**
|
|
2973
|
+
* 'or' expression
|
|
2974
|
+
* Allows an (outer) comma like historical media queries
|
|
2975
|
+
*/
|
|
2976
|
+
function guardOr(T) {
|
|
2977
|
+
const $ = this;
|
|
2978
|
+
return (ctx = {}) => {
|
|
2979
|
+
$.startRule();
|
|
2980
|
+
let left = $.SUBRULE($.guardAnd, { ARGS: [ctx] });
|
|
2981
|
+
let right;
|
|
2982
|
+
$.MANY({
|
|
2983
|
+
GATE: () => ctx.allowComma && $.isType(T.Comma) || $.isType(T.Or),
|
|
2984
|
+
DEF: () => {
|
|
2985
|
+
/**
|
|
2986
|
+
* Nest expressions within expressions for correct
|
|
2987
|
+
* order of operations.
|
|
2988
|
+
*/
|
|
2989
|
+
$.OR([{ ALT: () => $.CONSUME(T.Comma) }, { ALT: () => $.CONSUME(T.Or) }]);
|
|
2990
|
+
right = $.SUBRULE2($.guardAnd, { ARGS: [ctx] });
|
|
2991
|
+
let location = $.endRule();
|
|
2992
|
+
$.startRule();
|
|
2993
|
+
left = new Condition([
|
|
2994
|
+
left,
|
|
2995
|
+
"or",
|
|
2996
|
+
right
|
|
2997
|
+
], void 0, location, $.context);
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
$.endRule();
|
|
3001
|
+
return left;
|
|
3002
|
+
};
|
|
3003
|
+
}
|
|
3004
|
+
function guardDefault(T) {
|
|
3005
|
+
const $ = this;
|
|
3006
|
+
return (ctx = {}) => {
|
|
3007
|
+
let guard = $.OR([{ ALT: () => $.CONSUME(T.DefaultGuardIdent) }, { ALT: () => $.CONSUME(T.DefaultGuardFunc) }]);
|
|
3008
|
+
if ($.RECORDING_PHASE) return;
|
|
3009
|
+
ctx.hasDefault = true;
|
|
3010
|
+
return new DefaultGuard(guard.image, void 0, $.getLocationInfo(guard));
|
|
3011
|
+
};
|
|
3012
|
+
}
|
|
3013
|
+
/**
|
|
3014
|
+
* 'and' and 'or' expressions
|
|
3015
|
+
*
|
|
3016
|
+
* In Media queries level 4, you cannot have
|
|
3017
|
+
* `([expr]) or ([expr]) and ([expr])` because
|
|
3018
|
+
* of evaluation order ambiguity.
|
|
3019
|
+
* However, Less allows it.
|
|
3020
|
+
*/
|
|
3021
|
+
function guardAnd(T) {
|
|
3022
|
+
const $ = this;
|
|
3023
|
+
return (ctx = {}) => {
|
|
3024
|
+
let left;
|
|
3025
|
+
$.MANY_SEP({
|
|
3026
|
+
SEP: T.And,
|
|
3027
|
+
DEF: () => {
|
|
3028
|
+
let not;
|
|
3029
|
+
$.OPTION(() => not = $.CONSUME(T.Not));
|
|
3030
|
+
let allowComma = ctx.allowComma;
|
|
3031
|
+
ctx.allowComma = false;
|
|
3032
|
+
let right;
|
|
3033
|
+
try {
|
|
3034
|
+
right = $.OR([{ ALT: () => $.SUBRULE($.guardInParens, { ARGS: [ctx] }) }, {
|
|
3035
|
+
GATE: () => {
|
|
3036
|
+
const tokenType = $.LA(1).tokenType;
|
|
3037
|
+
return tokenType !== T.Not && tokenType !== T.DefaultGuardFunc && tokenType !== T.DefaultGuardIdent;
|
|
3038
|
+
},
|
|
3039
|
+
ALT: () => $.SUBRULE($.expressionSum, { ARGS: [ctx] })
|
|
3040
|
+
}]);
|
|
3041
|
+
$.OPTION2({
|
|
3042
|
+
GATE: () => isGuardComparisonToken($.LA(1).tokenType, T),
|
|
3043
|
+
DEF: () => {
|
|
3044
|
+
const op = $.CONSUME(T.CompareOperator);
|
|
3045
|
+
const compareRight = $.SUBRULE2($.expressionSum, { ARGS: [ctx] });
|
|
3046
|
+
if (!$.RECORDING_PHASE) right = new Condition([
|
|
3047
|
+
right,
|
|
3048
|
+
normalizeComparisonOperator(op.image),
|
|
3049
|
+
compareRight
|
|
3050
|
+
], void 0, $.getLocationFromNodes([right, compareRight]), $.context);
|
|
3051
|
+
}
|
|
3052
|
+
});
|
|
3053
|
+
} finally {
|
|
3054
|
+
ctx.allowComma = allowComma;
|
|
3055
|
+
}
|
|
3056
|
+
if (!$.RECORDING_PHASE) {
|
|
3057
|
+
if (isDefaultGuardCall(right)) {
|
|
3058
|
+
ctx.hasDefault = true;
|
|
3059
|
+
right = new DefaultGuard("default()", void 0, Array.isArray(right.location) && right.location.length === 6 ? right.location : void 0);
|
|
3060
|
+
}
|
|
3061
|
+
if (not) {
|
|
3062
|
+
let [, , , endOffset, endLine, endColumn] = right.location;
|
|
3063
|
+
let [startOffset, startLine, startColumn] = $.getLocationInfo(not);
|
|
3064
|
+
right = new Condition([right], { negate: true }, [
|
|
3065
|
+
startOffset,
|
|
3066
|
+
startLine,
|
|
3067
|
+
startColumn,
|
|
3068
|
+
endOffset,
|
|
3069
|
+
endLine,
|
|
3070
|
+
endColumn
|
|
3071
|
+
], $.context);
|
|
3072
|
+
}
|
|
3073
|
+
if (!left) {
|
|
3074
|
+
left = right;
|
|
3075
|
+
return;
|
|
3076
|
+
}
|
|
3077
|
+
left = new Condition([
|
|
3078
|
+
left,
|
|
3079
|
+
"and",
|
|
3080
|
+
right
|
|
3081
|
+
], void 0, $.getLocationFromNodes([left, right]), $.context);
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
});
|
|
3085
|
+
return left;
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
function guardInParens(T) {
|
|
3089
|
+
const $ = this;
|
|
3090
|
+
return (ctx) => {
|
|
3091
|
+
$.startRule();
|
|
3092
|
+
let node = $.OR([{ ALT: () => $.SUBRULE($.guardDefault, { ARGS: [ctx] }) }, { ALT: () => {
|
|
3093
|
+
$.CONSUME(T.LParen);
|
|
3094
|
+
let node = $.SUBRULE($.guardInner, { ARGS: [ctx] });
|
|
3095
|
+
$.CONSUME(T.RParen);
|
|
3096
|
+
return node;
|
|
3097
|
+
} }]);
|
|
3098
|
+
if (isDefaultGuardCall(node)) {
|
|
3099
|
+
ctx.hasDefault = true;
|
|
3100
|
+
node = new DefaultGuard("default()", void 0, Array.isArray(node.location) && node.location.length === 6 ? node.location : void 0);
|
|
3101
|
+
}
|
|
3102
|
+
node = node;
|
|
3103
|
+
return new Paren(node, void 0, $.endRule(), $.context);
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
function guardInner(_T) {
|
|
3107
|
+
const $ = this;
|
|
3108
|
+
return (ctx = {}) => {
|
|
3109
|
+
return $.SUBRULE($.guardOr, { ARGS: [ctx] });
|
|
3110
|
+
};
|
|
3111
|
+
}
|
|
3112
|
+
function guardWithConditionValue(T) {
|
|
3113
|
+
const $ = this;
|
|
3114
|
+
return (ctx = {}) => {
|
|
3115
|
+
if ($.isType(T.DefaultGuardIdent) || $.isType(T.DefaultGuardFunc)) {
|
|
3116
|
+
$.OR([{ ALT: () => $.CONSUME(T.DefaultGuardIdent) }, { ALT: () => $.CONSUME(T.DefaultGuardFunc) }]);
|
|
3117
|
+
return;
|
|
3118
|
+
}
|
|
3119
|
+
return $.SUBRULE($.guardInParens, { ARGS: [ctx] });
|
|
3120
|
+
};
|
|
3121
|
+
}
|
|
3122
|
+
function guardWithCondition(T) {
|
|
3123
|
+
const $ = this;
|
|
3124
|
+
return (ctx = {}) => {
|
|
3125
|
+
$.SUBRULE($.guardWithConditionValue, { ARGS: [ctx] });
|
|
3126
|
+
$.AT_LEAST_ONE(() => {
|
|
3127
|
+
$.OR([
|
|
3128
|
+
{ ALT: () => $.CONSUME(T.Or) },
|
|
3129
|
+
{ ALT: () => $.CONSUME(T.And) },
|
|
3130
|
+
{ ALT: () => $.CONSUME(T.Comma) }
|
|
3131
|
+
]);
|
|
3132
|
+
$.SUBRULE2($.guardWithConditionValue, { ARGS: [ctx] });
|
|
3133
|
+
});
|
|
3134
|
+
};
|
|
3135
|
+
}
|
|
3136
|
+
/**
|
|
3137
|
+
* Currently, Less only allows a single comparison expression,
|
|
3138
|
+
* unlike Media Queries Level 4, which allows a left and right
|
|
3139
|
+
* comparison.
|
|
3140
|
+
*/
|
|
3141
|
+
function comparison(T) {
|
|
3142
|
+
const $ = this;
|
|
3143
|
+
return (ctx = {}) => {
|
|
3144
|
+
let left = $.SUBRULE($.expressionSum, { ARGS: [ctx] });
|
|
3145
|
+
const op = $.CONSUME(T.CompareOperator);
|
|
3146
|
+
let right = $.SUBRULE2($.expressionSum, { ARGS: [ctx] });
|
|
3147
|
+
if (isDefaultGuardCall(right)) {
|
|
3148
|
+
ctx.hasDefault = true;
|
|
3149
|
+
right = new DefaultGuard("default()", void 0, Array.isArray(right.location) && right.location.length === 6 ? right.location : void 0);
|
|
3150
|
+
}
|
|
3151
|
+
left = new Condition([
|
|
3152
|
+
left,
|
|
3153
|
+
normalizeComparisonOperator(op.image),
|
|
3154
|
+
right
|
|
3155
|
+
], void 0, $.getLocationFromNodes([left, right]), $.context);
|
|
3156
|
+
return left;
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
/**
|
|
3160
|
+
* Less (perhaps unwisely) allows bubbling of normally document-root
|
|
3161
|
+
* at-rules, so we need to override CSS here.
|
|
3162
|
+
*/
|
|
3163
|
+
function innerAtRule(_T) {
|
|
3164
|
+
const $ = this;
|
|
3165
|
+
return (ctx = {}) => {
|
|
3166
|
+
return $.OR([
|
|
3167
|
+
{ ALT: () => $.SUBRULE($.mediaAtRule, { ARGS: [{
|
|
3168
|
+
...ctx,
|
|
3169
|
+
inner: true
|
|
3170
|
+
}] }) },
|
|
3171
|
+
{ ALT: () => $.SUBRULE($.supportsAtRule, { ARGS: [{
|
|
3172
|
+
...ctx,
|
|
3173
|
+
inner: true
|
|
3174
|
+
}] }) },
|
|
3175
|
+
{ ALT: () => $.SUBRULE($.layerAtRule, { ARGS: [{
|
|
3176
|
+
...ctx,
|
|
3177
|
+
inner: true
|
|
3178
|
+
}] }) },
|
|
3179
|
+
{ ALT: () => $.SUBRULE($.containerAtRule, { ARGS: [{
|
|
3180
|
+
...ctx,
|
|
3181
|
+
inner: true
|
|
3182
|
+
}] }) },
|
|
3183
|
+
{ ALT: () => $.SUBRULE($.keyframesAtRule, { ARGS: [{
|
|
3184
|
+
...ctx,
|
|
3185
|
+
inner: true
|
|
3186
|
+
}] }) },
|
|
3187
|
+
{ ALT: () => $.SUBRULE($.documentAtRule, { ARGS: [{
|
|
3188
|
+
...ctx,
|
|
3189
|
+
inner: true
|
|
3190
|
+
}] }) },
|
|
3191
|
+
{ ALT: () => $.SUBRULE($.importAtRule, { ARGS: [ctx] }) },
|
|
3192
|
+
{ ALT: () => $.SUBRULE($.pageAtRule, { ARGS: [ctx] }) },
|
|
3193
|
+
{ ALT: () => $.SUBRULE($.fontFaceAtRule, { ARGS: [ctx] }) },
|
|
3194
|
+
{ ALT: () => $.SUBRULE($.nestedAtRule, { ARGS: [ctx] }) },
|
|
3195
|
+
{ ALT: () => $.SUBRULE($.nonNestedAtRule, { ARGS: [ctx] }) },
|
|
3196
|
+
{ ALT: () => $.SUBRULE($.unknownAtRule, { ARGS: [{
|
|
3197
|
+
...ctx,
|
|
3198
|
+
inner: true
|
|
3199
|
+
}] }) }
|
|
3200
|
+
]);
|
|
3201
|
+
};
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Less override: allow variable reference as the first segment of a layer-name
|
|
3205
|
+
* CSS: <ident> ('.' <ident>)*
|
|
3206
|
+
* Less: (<var-ref> | <ident>) ('.' <ident>)*
|
|
3207
|
+
*/
|
|
3208
|
+
function layerName(T) {
|
|
3209
|
+
const $ = this;
|
|
3210
|
+
return (ctx = {}) => {
|
|
3211
|
+
const preludeCtx = {
|
|
3212
|
+
...ctx,
|
|
3213
|
+
atRulePreludeBareVariableAs: "index"
|
|
3214
|
+
};
|
|
3215
|
+
$.startRule();
|
|
3216
|
+
let RECORDING_PHASE = $.RECORDING_PHASE;
|
|
3217
|
+
let nodes;
|
|
3218
|
+
if (!RECORDING_PHASE) nodes = [];
|
|
3219
|
+
const first = $.OR([{ ALT: () => $.SUBRULE($.valueReference, { ARGS: [preludeCtx] }) }, {
|
|
3220
|
+
GATE: () => $.isType(T.Ident),
|
|
3221
|
+
ALT: () => $.CONSUME(T.Ident)
|
|
3222
|
+
}]);
|
|
3223
|
+
if (!RECORDING_PHASE) if (first instanceof Node) nodes.push(first);
|
|
3224
|
+
else nodes.push($.processValueToken(first));
|
|
3225
|
+
$.MANY({
|
|
3226
|
+
GATE: $.noSep.bind($),
|
|
3227
|
+
DEF: () => {
|
|
3228
|
+
const seg = $.CONSUME(T.DotName);
|
|
3229
|
+
if (!RECORDING_PHASE) nodes.push($.processValueToken(seg));
|
|
3230
|
+
}
|
|
3231
|
+
});
|
|
3232
|
+
if (RECORDING_PHASE) return;
|
|
3233
|
+
const loc = $.endRule();
|
|
3234
|
+
return new Sequence(nodes, void 0, loc, $.context);
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
/**
|
|
3238
|
+
* Less override: allow variable reference for @keyframes name
|
|
3239
|
+
* CSS: Ident | String
|
|
3240
|
+
* Less: valueReference | Ident | String
|
|
3241
|
+
*/
|
|
3242
|
+
function keyframesName(T) {
|
|
3243
|
+
const $ = this;
|
|
3244
|
+
return (ctx = {}) => {
|
|
3245
|
+
const preludeCtx = {
|
|
3246
|
+
...ctx,
|
|
3247
|
+
atRulePreludeBareVariableAs: "index"
|
|
3248
|
+
};
|
|
3249
|
+
let node;
|
|
3250
|
+
$.OR([
|
|
3251
|
+
{ ALT: () => node = $.SUBRULE($.valueReference, { ARGS: [preludeCtx] }) },
|
|
3252
|
+
{
|
|
3253
|
+
GATE: () => $.isType(T.Ident) && !$.isType(T.InterpolatedIdent),
|
|
3254
|
+
ALT: () => {
|
|
3255
|
+
const tok = $.CONSUME(T.Ident);
|
|
3256
|
+
node = $.processValueToken(tok);
|
|
3257
|
+
}
|
|
3258
|
+
},
|
|
3259
|
+
{ ALT: () => node = $.SUBRULE($.string, { ARGS: [] }) }
|
|
3260
|
+
]);
|
|
3261
|
+
return node;
|
|
3262
|
+
};
|
|
3263
|
+
}
|
|
3264
|
+
/**
|
|
3265
|
+
* One of the rare rules that returns a token, because
|
|
3266
|
+
* other rules will transform it differently.
|
|
3267
|
+
*/
|
|
3268
|
+
function mixinName(T) {
|
|
3269
|
+
const $ = this;
|
|
3270
|
+
return (ctx = {}) => {
|
|
3271
|
+
/** e.g. .mixin, #mixin */
|
|
3272
|
+
let name = $.OR([
|
|
3273
|
+
{ ALT: () => $.CONSUME(T.HashName) },
|
|
3274
|
+
{ ALT: () => $.CONSUME(T.ColorIdentStart) },
|
|
3275
|
+
{ ALT: () => $.CONSUME(T.DotName) },
|
|
3276
|
+
{ ALT: () => $.CONSUME(T.InterpolatedIdent) },
|
|
3277
|
+
{ ALT: () => $.CONSUME(T.InterpolatedSelector) }
|
|
3278
|
+
]);
|
|
3279
|
+
if ($.RECORDING_PHASE) return;
|
|
3280
|
+
const asReference = ctx.asReference;
|
|
3281
|
+
let nameNode;
|
|
3282
|
+
let nameValue = name.image;
|
|
3283
|
+
let location = $.getLocationInfo(name);
|
|
3284
|
+
if (nameValue.includes("@") || nameValue.includes("$")) {
|
|
3285
|
+
const interpolated = getInterpolatedNode(nameValue, location, $.context);
|
|
3286
|
+
nameNode = interpolated;
|
|
3287
|
+
if (asReference) if (isNode(ctx.node, N.Reference) && ctx.node.options.type === "mixin-ruleset") nameNode = new Reference({
|
|
3288
|
+
target: ctx.node,
|
|
3289
|
+
key: interpolated
|
|
3290
|
+
}, {
|
|
3291
|
+
type: "mixin-ruleset",
|
|
3292
|
+
role: "name"
|
|
3293
|
+
}, location, $.context);
|
|
3294
|
+
else {
|
|
3295
|
+
const target = ctx.node;
|
|
3296
|
+
nameNode = new Reference({
|
|
3297
|
+
target: target instanceof Call ? target : target instanceof Reference ? target : void 0,
|
|
3298
|
+
key: interpolated
|
|
3299
|
+
}, {
|
|
3300
|
+
type: "mixin-ruleset",
|
|
3301
|
+
role: "name"
|
|
3302
|
+
}, location, $.context);
|
|
3303
|
+
}
|
|
3304
|
+
} else if (asReference) if (isNode(ctx.node, N.Reference) && ctx.node.options.type === "mixin-ruleset") {
|
|
3305
|
+
const existingKey = ctx.node.key;
|
|
3306
|
+
const existingRawKey = ctx.node.rawKey;
|
|
3307
|
+
let mergedKeys;
|
|
3308
|
+
if (Array.isArray(existingKey)) mergedKeys = [...existingKey];
|
|
3309
|
+
else mergedKeys = [String(existingKey)];
|
|
3310
|
+
mergedKeys.push(nameValue);
|
|
3311
|
+
const rawPrefix = Array.isArray(existingRawKey) ? existingRawKey.join(" > ") : typeof existingRawKey === "string" ? existingRawKey : Array.isArray(existingKey) ? existingKey.join(" > ") : String(existingKey);
|
|
3312
|
+
nameNode = new Reference({
|
|
3313
|
+
key: mergedKeys.length === 1 ? mergedKeys[0] : mergedKeys,
|
|
3314
|
+
rawKey: `${rawPrefix} > ${nameValue}`
|
|
3315
|
+
}, {
|
|
3316
|
+
type: "mixin-ruleset",
|
|
3317
|
+
role: "name"
|
|
3318
|
+
}, location, $.context);
|
|
3319
|
+
} else {
|
|
3320
|
+
const target = ctx.node;
|
|
3321
|
+
nameNode = new Reference({
|
|
3322
|
+
target: target instanceof Call ? target : target instanceof Reference ? target : void 0,
|
|
3323
|
+
key: nameValue
|
|
3324
|
+
}, {
|
|
3325
|
+
type: "mixin-ruleset",
|
|
3326
|
+
role: "name"
|
|
3327
|
+
}, location, $.context);
|
|
3328
|
+
}
|
|
3329
|
+
else nameNode = new Any(nameValue, { role: "name" }, $.getLocationInfo(name), $.context);
|
|
3330
|
+
return nameNode;
|
|
3331
|
+
};
|
|
3332
|
+
}
|
|
3333
|
+
/**
|
|
3334
|
+
* Used within a value. These can be
|
|
3335
|
+
* chained more recursively, unlike
|
|
3336
|
+
* Less 1.x-4.x
|
|
3337
|
+
* e.g. .mixin1() > .mixin2[@val1].ns() > .sub-mixin[@val2]
|
|
3338
|
+
*
|
|
3339
|
+
* This production intelligently decides whether to produce a Call or Reference
|
|
3340
|
+
* based on whether there are parentheses at the end:
|
|
3341
|
+
* - foo: #id; // Reference
|
|
3342
|
+
* - foo: .class; // Reference
|
|
3343
|
+
* - foo: #id > .scoped; // Reference
|
|
3344
|
+
* - foo: #id > .scoped(); // Call
|
|
3345
|
+
* - foo: #id[]; // Reference with accessor
|
|
3346
|
+
* - foo: #id > .scoped[foo]; // Reference with accessor
|
|
3347
|
+
* - foo: #id > .scoped[@ref](); // Call with accessor
|
|
3348
|
+
*/
|
|
3349
|
+
function mixinReference(T) {
|
|
3350
|
+
const $ = this;
|
|
3351
|
+
return (ctx = {}) => {
|
|
3352
|
+
let leftNode = $.SUBRULE($.mixinName, { ARGS: [{
|
|
3353
|
+
...ctx,
|
|
3354
|
+
asReference: true
|
|
3355
|
+
}] });
|
|
3356
|
+
$.MANY({
|
|
3357
|
+
GATE: () => {
|
|
3358
|
+
let next = $.LA(1).tokenType;
|
|
3359
|
+
return $.noSep() && (next === T.LParen || next === T.LSquare);
|
|
3360
|
+
},
|
|
3361
|
+
DEF: () => {
|
|
3362
|
+
leftNode = $.SUBRULE($.lookupOrCall, { ARGS: [{
|
|
3363
|
+
...ctx,
|
|
3364
|
+
node: leftNode
|
|
3365
|
+
}] });
|
|
3366
|
+
}
|
|
3367
|
+
});
|
|
3368
|
+
$.OPTION(() => {
|
|
3369
|
+
$.OPTION2(() => $.CONSUME(T.Gt));
|
|
3370
|
+
leftNode = $.SUBRULE($.mixinReference, { ARGS: [{
|
|
3371
|
+
...ctx,
|
|
3372
|
+
node: leftNode
|
|
3373
|
+
}] });
|
|
3374
|
+
});
|
|
3375
|
+
return leftNode;
|
|
3376
|
+
};
|
|
3377
|
+
}
|
|
3378
|
+
function mixinArgs(T) {
|
|
3379
|
+
const $ = this;
|
|
3380
|
+
return (ctx = {}) => {
|
|
3381
|
+
let args;
|
|
3382
|
+
const hasWhitespace = !$.noSep();
|
|
3383
|
+
const openingParenToken = hasWhitespace ? $.LA(1) : void 0;
|
|
3384
|
+
$.CONSUME(T.LParen);
|
|
3385
|
+
const argCtx = {
|
|
3386
|
+
...ctx,
|
|
3387
|
+
node: void 0,
|
|
3388
|
+
allowComma: false,
|
|
3389
|
+
parenFrames: [...getParenFrames(ctx), false],
|
|
3390
|
+
detachedRulesetUsage: ctx.isDefinition ? "default-param" : "mixin-arg"
|
|
3391
|
+
};
|
|
3392
|
+
if (!$.isType(T.RParen)) args = $.SUBRULE($.mixinArgList, { ARGS: [argCtx] });
|
|
3393
|
+
$.CONSUME(T.RParen);
|
|
3394
|
+
if (hasWhitespace && openingParenToken) {
|
|
3395
|
+
const nextAfterParens = $.LA(1).tokenType;
|
|
3396
|
+
if (!(nextAfterParens === T.LCurly || nextAfterParens === T.When)) $.warnDeprecation("Whitespace between a mixin name and parentheses for a mixin call is deprecated", openingParenToken, "mixin-call-whitespace");
|
|
3397
|
+
}
|
|
3398
|
+
return args;
|
|
3399
|
+
};
|
|
3400
|
+
}
|
|
3401
|
+
function lookupOrCall(T) {
|
|
3402
|
+
const $ = this;
|
|
3403
|
+
return (ctx = {}) => {
|
|
3404
|
+
$.startRule();
|
|
3405
|
+
return $.OR([{ ALT: () => {
|
|
3406
|
+
let keyToken;
|
|
3407
|
+
$.CONSUME(T.LSquare);
|
|
3408
|
+
$.OPTION(() => keyToken = $.OR2([
|
|
3409
|
+
{ ALT: () => $.CONSUME(T.NestedReference) },
|
|
3410
|
+
{ ALT: () => $.CONSUME(T.AtKeyword) },
|
|
3411
|
+
{ ALT: () => $.CONSUME(T.PropertyReference) },
|
|
3412
|
+
{ ALT: () => $.CONSUME(T.InterpolatedIdent) },
|
|
3413
|
+
{
|
|
3414
|
+
GATE: () => !$.isType(T.NestedReference) && !$.isType(T.AtKeyword) && !$.isType(T.PropertyReference) && !$.isType(T.InterpolatedIdent) && $.isType(T.Ident),
|
|
3415
|
+
ALT: () => $.CONSUME(T.Ident)
|
|
3416
|
+
}
|
|
3417
|
+
]));
|
|
3418
|
+
$.CONSUME(T.RSquare);
|
|
3419
|
+
if ($.RECORDING_PHASE) return;
|
|
3420
|
+
let ref;
|
|
3421
|
+
const targetNode = ctx.node;
|
|
3422
|
+
const target = targetNode instanceof Call ? targetNode : targetNode instanceof Reference ? targetNode : void 0;
|
|
3423
|
+
if (keyToken) {
|
|
3424
|
+
let tokenStr = keyToken.image;
|
|
3425
|
+
let type = tokenStr.startsWith("@") ? "variable" : "index";
|
|
3426
|
+
if (keyToken.tokenType === T.NestedReference) {
|
|
3427
|
+
tokenStr = keyToken.image;
|
|
3428
|
+
if (!tokenStr.startsWith("$") && !tokenStr.startsWith("@")) tokenStr = "$" + tokenStr;
|
|
3429
|
+
}
|
|
3430
|
+
let rawResult = getInterpolatedOrString(tokenStr, $.getLocationInfo(keyToken), $.context);
|
|
3431
|
+
let result = rawResult;
|
|
3432
|
+
if (type === "index") result = new Quoted(rawResult, { quote: "'" }, $.getLocationInfo(keyToken), $.context);
|
|
3433
|
+
const targetType = isNode(target, N.Reference) ? target.options.type : void 0;
|
|
3434
|
+
const shouldMergeKeys = targetType === "mixin" || targetType === "mixin-ruleset";
|
|
3435
|
+
if (isNode(target, N.Reference) && target.options.type === type && typeof result === "string" && shouldMergeKeys) {
|
|
3436
|
+
const existingKey = target.key;
|
|
3437
|
+
let mergedKeys;
|
|
3438
|
+
if (Array.isArray(existingKey)) mergedKeys = [...existingKey];
|
|
3439
|
+
else mergedKeys = [String(existingKey)];
|
|
3440
|
+
mergedKeys.push(result);
|
|
3441
|
+
ref = new Reference({ key: mergedKeys.length === 1 ? mergedKeys[0] : mergedKeys }, { type }, $.endRule(), $.context);
|
|
3442
|
+
} else ref = new Reference({
|
|
3443
|
+
target,
|
|
3444
|
+
key: result
|
|
3445
|
+
}, { type }, $.endRule(), $.context);
|
|
3446
|
+
} else ref = new Reference({
|
|
3447
|
+
target,
|
|
3448
|
+
key: -1
|
|
3449
|
+
}, { type: "index" }, $.endRule(), $.context);
|
|
3450
|
+
/** Reference targets will technically precede the reference, so we need to update the location to the target start location */
|
|
3451
|
+
if (target) {
|
|
3452
|
+
let [targetStartOffset, targetStartLine, targetStartColumn] = target.location;
|
|
3453
|
+
ref.location.start = targetStartOffset;
|
|
3454
|
+
ref.location[1] = targetStartLine;
|
|
3455
|
+
ref.location[2] = targetStartColumn;
|
|
3456
|
+
}
|
|
3457
|
+
return ref;
|
|
3458
|
+
} }, { ALT: () => {
|
|
3459
|
+
let args = $.SUBRULE($.mixinArgs, { ARGS: [ctx] });
|
|
3460
|
+
if ($.RECORDING_PHASE) return;
|
|
3461
|
+
return new Call({
|
|
3462
|
+
name: ctx.node,
|
|
3463
|
+
args
|
|
3464
|
+
}, void 0, $.endRule(), $.context);
|
|
3465
|
+
} }]);
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
/**
|
|
3469
|
+
* @see https://lesscss.org/features/#mixins-feature-mixins-parametric-feature
|
|
3470
|
+
*
|
|
3471
|
+
* This rule is recursive to allow chevrotain-allstar (hopefully) to lookahead
|
|
3472
|
+
* and find semi-colon separators vs. commas.
|
|
3473
|
+
*/
|
|
3474
|
+
function mixinArgList(T) {
|
|
3475
|
+
const $ = this;
|
|
3476
|
+
return (ctx = {}) => {
|
|
3477
|
+
$.startRule();
|
|
3478
|
+
let commaNodes = [$.SUBRULE($.mixinArg, { ARGS: [ctx] })];
|
|
3479
|
+
const semiNodes = [];
|
|
3480
|
+
let isSemiList = false;
|
|
3481
|
+
const collapseCommaNodesIntoSemiNodes = (semi) => {
|
|
3482
|
+
if (!commaNodes) return;
|
|
3483
|
+
if (commaNodes.length > 1) {
|
|
3484
|
+
const [head, ...rest] = commaNodes;
|
|
3485
|
+
let hasDeclarations = false;
|
|
3486
|
+
if (head instanceof VarDeclaration) {
|
|
3487
|
+
const headValue = head.value instanceof Node ? head.value : void 0;
|
|
3488
|
+
const nodes = headValue ? [headValue, ...rest] : [...rest];
|
|
3489
|
+
hasDeclarations = rest.some((n) => n instanceof VarDeclaration);
|
|
3490
|
+
const value = new List(nodes, void 0, $.getLocationFromNodes(nodes), $.context);
|
|
3491
|
+
semiNodes.push(new VarDeclaration({
|
|
3492
|
+
name: head.name,
|
|
3493
|
+
value,
|
|
3494
|
+
important: head.important
|
|
3495
|
+
}, head.options, head.location, $.context));
|
|
3496
|
+
} else {
|
|
3497
|
+
hasDeclarations = commaNodes.some((n) => n instanceof VarDeclaration);
|
|
3498
|
+
semiNodes.push(new List(commaNodes, void 0, $.getLocationFromNodes(commaNodes), $.context));
|
|
3499
|
+
}
|
|
3500
|
+
if (hasDeclarations) {
|
|
3501
|
+
const indexOfSemi = $.input.indexOf(semi);
|
|
3502
|
+
const previousToken = $.input[indexOfSemi - 1];
|
|
3503
|
+
$.SAVE_ERROR(new NoViableAltException("Cannot mix ; and , as delimiter types", semi, previousToken));
|
|
3504
|
+
}
|
|
3505
|
+
} else semiNodes.push(commaNodes[0]);
|
|
3506
|
+
commaNodes = void 0;
|
|
3507
|
+
};
|
|
3508
|
+
while ($.isType(T.Comma) || $.isType(T.Semi)) {
|
|
3509
|
+
if ($.isType(T.Comma)) {
|
|
3510
|
+
const comma = $.CONSUME(T.Comma);
|
|
3511
|
+
const node = $.SUBRULE2($.mixinArg, { ARGS: [ctx] });
|
|
3512
|
+
if (commaNodes) commaNodes.push(node);
|
|
3513
|
+
else {
|
|
3514
|
+
$.SAVE_ERROR(new NoViableAltException("Cannot mix ; and , as delimiter types", comma, $.LA(0)));
|
|
3515
|
+
semiNodes.push(node);
|
|
3516
|
+
}
|
|
3517
|
+
continue;
|
|
3518
|
+
}
|
|
3519
|
+
const semi = $.CONSUME(T.Semi);
|
|
3520
|
+
isSemiList = true;
|
|
3521
|
+
collapseCommaNodesIntoSemiNodes(semi);
|
|
3522
|
+
if ($.isType(T.RParen)) break;
|
|
3523
|
+
const prevAllow = ctx.allowComma;
|
|
3524
|
+
ctx.allowComma = true;
|
|
3525
|
+
const node = $.SUBRULE3($.mixinArg, { ARGS: [ctx] });
|
|
3526
|
+
ctx.allowComma = prevAllow;
|
|
3527
|
+
semiNodes.push(node);
|
|
3528
|
+
}
|
|
3529
|
+
let location = $.endRule();
|
|
3530
|
+
return new List(isSemiList ? semiNodes : commaNodes, { sep: isSemiList ? ";" : "," }, location, $.context);
|
|
3531
|
+
};
|
|
3532
|
+
}
|
|
3533
|
+
/**
|
|
3534
|
+
* Less is more lenient about at-keywords. See lessTokens.ts for more details.
|
|
3535
|
+
*/
|
|
3536
|
+
function varName(T) {
|
|
3537
|
+
const $ = this;
|
|
3538
|
+
return () => {
|
|
3539
|
+
return $.CONSUME(T.AtName);
|
|
3540
|
+
};
|
|
3541
|
+
}
|
|
3542
|
+
/**
|
|
3543
|
+
* Originally, we were creating alternatives for mixin calls and mixin definitions
|
|
3544
|
+
* that could mostly overlap, which led to longer parsing. Instead, we parse
|
|
3545
|
+
* as if it could be either, and then we disambiguate at the end.
|
|
3546
|
+
*/
|
|
3547
|
+
function mixinArg(T) {
|
|
3548
|
+
const $ = this;
|
|
3549
|
+
return (ctx = {}) => {
|
|
3550
|
+
const firstToken = $.LA(1);
|
|
3551
|
+
const atStart = $.matchToken(firstToken, T.AtName);
|
|
3552
|
+
const tt2 = $.LA(2).tokenType;
|
|
3553
|
+
const tt3 = $.LA(3).tokenType;
|
|
3554
|
+
const hasWsAfterName = tt2 === T.WS;
|
|
3555
|
+
const nextTokenType = hasWsAfterName ? tt3 : tt2;
|
|
3556
|
+
if (atStart && nextTokenType === T.Ellipsis) {
|
|
3557
|
+
$.startRule();
|
|
3558
|
+
const name = $.CONSUME(T.AtName);
|
|
3559
|
+
if (hasWsAfterName) $.CONSUME(T.WS);
|
|
3560
|
+
$.CONSUME(T.Ellipsis);
|
|
3561
|
+
if ($.RECORDING_PHASE) return;
|
|
3562
|
+
return new Rest(name.image.slice(1), void 0, $.endRule(), $.context);
|
|
3563
|
+
}
|
|
3564
|
+
if (atStart && nextTokenType === T.Colon) {
|
|
3565
|
+
$.startRule();
|
|
3566
|
+
const name = $.CONSUME2(T.AtName);
|
|
3567
|
+
if (hasWsAfterName) $.CONSUME2(T.WS);
|
|
3568
|
+
$.CONSUME(T.Colon);
|
|
3569
|
+
const value = $.SUBRULE3($.callArgument, { ARGS: [{
|
|
3570
|
+
...ctx,
|
|
3571
|
+
allowComma: !!ctx.allowComma,
|
|
3572
|
+
detachedRulesetUsage: "default-param"
|
|
3573
|
+
}] });
|
|
3574
|
+
const location = $.endRule();
|
|
3575
|
+
if ($.RECORDING_PHASE) return;
|
|
3576
|
+
return new VarDeclaration({
|
|
3577
|
+
name: name.image.slice(1),
|
|
3578
|
+
value
|
|
3579
|
+
}, { paramVar: true }, location, $.context);
|
|
3580
|
+
}
|
|
3581
|
+
if (atStart && (nextTokenType === T.RParen || nextTokenType === T.Comma || nextTokenType === T.Semi)) {
|
|
3582
|
+
$.startRule();
|
|
3583
|
+
const name = $.CONSUME3(T.AtName);
|
|
3584
|
+
if ($.RECORDING_PHASE) return;
|
|
3585
|
+
const location = $.endRule();
|
|
3586
|
+
if (ctx.isDefinition) return new VarDeclaration({
|
|
3587
|
+
name: name.image.slice(1),
|
|
3588
|
+
value: new Nil(void 0, void 0, location, $.context)
|
|
3589
|
+
}, { paramVar: true }, location, $.context);
|
|
3590
|
+
return new Any(name.image.slice(1), { role: "name" }, location, $.context);
|
|
3591
|
+
}
|
|
3592
|
+
if ($.isType(T.Ellipsis)) {
|
|
3593
|
+
const ellipsis = $.CONSUME2(T.Ellipsis);
|
|
3594
|
+
return new Rest(void 0, void 0, $.getLocationInfo(ellipsis), $.context);
|
|
3595
|
+
}
|
|
3596
|
+
return $.SUBRULE($.callArgument, { ARGS: [ctx] });
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3599
|
+
function callArgument(T) {
|
|
3600
|
+
const $ = this;
|
|
3601
|
+
return (ctx = {}) => {
|
|
3602
|
+
return $.OR([
|
|
3603
|
+
{
|
|
3604
|
+
GATE: () => $.isType(T.AnonMixinStart) || $.isType(T.LCurly),
|
|
3605
|
+
ALT: () => $.SUBRULE($.anonymousMixinDefinition, { ARGS: [ctx] })
|
|
3606
|
+
},
|
|
3607
|
+
{
|
|
3608
|
+
GATE: () => !ctx.allowComma,
|
|
3609
|
+
ALT: () => $.SUBRULE($.valueSequence, { ARGS: [ctx] })
|
|
3610
|
+
},
|
|
3611
|
+
{
|
|
3612
|
+
GATE: () => !!ctx.allowComma,
|
|
3613
|
+
ALT: () => $.SUBRULE($.valueList, { ARGS: [ctx] })
|
|
3614
|
+
}
|
|
3615
|
+
]);
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
/**
|
|
3619
|
+
* Override unknownAtRule to handle @-export for stylesheet forwarding.
|
|
3620
|
+
* @-export is like @-compose but with forward semantics and no `with` support.
|
|
3621
|
+
*/
|
|
3622
|
+
function unknownAtRule(T) {
|
|
3623
|
+
const $ = this;
|
|
3624
|
+
return (ctx = {}) => {
|
|
3625
|
+
const img = $.LA(1).image;
|
|
3626
|
+
if (img === "@use" || img === "@-use") return $.SUBRULE($.useAtRule, { ARGS: [ctx] });
|
|
3627
|
+
if (img === "@-export") return $.SUBRULE($.exportAtRule, { ARGS: [ctx] });
|
|
3628
|
+
return cssUnknownAtRule.call($, T)(ctx);
|
|
3629
|
+
};
|
|
3630
|
+
}
|
|
3631
|
+
/**
|
|
3632
|
+
* Parse Less v5 script-module imports.
|
|
3633
|
+
*
|
|
3634
|
+
* Stylesheet composition uses `@compose`; `@use` / `@-use` only become
|
|
3635
|
+
* JsImport nodes for script-style paths and aliases like `#less/math`.
|
|
3636
|
+
*/
|
|
3637
|
+
function useAtRule(T) {
|
|
3638
|
+
const $ = this;
|
|
3639
|
+
return (ctx = {}) => {
|
|
3640
|
+
$.startRule();
|
|
3641
|
+
const name = $.CONSUME(T.AtName);
|
|
3642
|
+
const pathNode = $.SUBRULE($.string, { ARGS: [ctx] });
|
|
3643
|
+
let namespace;
|
|
3644
|
+
$.OPTION({
|
|
3645
|
+
GATE: () => $.LA(1).tokenType === T.PlainIdent && $.LA(1).image === "as",
|
|
3646
|
+
DEF: () => {
|
|
3647
|
+
$.CONSUME(T.PlainIdent);
|
|
3648
|
+
$.OR2([{ ALT: () => {
|
|
3649
|
+
namespace = $.CONSUME2(T.PlainIdent).image;
|
|
3650
|
+
} }, { ALT: () => {
|
|
3651
|
+
namespace = $.CONSUME(T.Star).image;
|
|
3652
|
+
} }]);
|
|
3653
|
+
}
|
|
3654
|
+
});
|
|
3655
|
+
$.CONSUME(T.Semi);
|
|
3656
|
+
const location = $.endRule();
|
|
3657
|
+
if ($.RECORDING_PHASE) return;
|
|
3658
|
+
const rawPath = pathNode.valueOf();
|
|
3659
|
+
if (isScriptUsePath(rawPath)) return new JsImport({ path: pathNode }, { namespace: namespace ?? defaultNamespaceFromPath(rawPath) }, location, $.context);
|
|
3660
|
+
const preludeNodes = [pathNode];
|
|
3661
|
+
if (namespace) preludeNodes.push(new Any("as", { role: "ident" }, void 0, $.context), new Any(namespace, { role: namespace === "*" ? "operator" : "ident" }, void 0, $.context));
|
|
3662
|
+
return new AtRuleStatement({
|
|
3663
|
+
name: name.image,
|
|
3664
|
+
prelude: new Sequence(preludeNodes, void 0, $.getLocationFromNodes(preludeNodes), $.context)
|
|
3665
|
+
}, void 0, location, $.context);
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3668
|
+
/**
|
|
3669
|
+
* Parse @-export './foo.jess' [as <namespace>]
|
|
3670
|
+
*
|
|
3671
|
+
* Creates a StyleImport with forward semantics (members not visible locally but transitive).
|
|
3672
|
+
* Does NOT support `with` (unlike @-compose).
|
|
3673
|
+
* Participates in evaldTrees caching like @-compose.
|
|
3674
|
+
*/
|
|
3675
|
+
function exportAtRule(T) {
|
|
3676
|
+
const $ = this;
|
|
3677
|
+
return (ctx = {}) => {
|
|
3678
|
+
$.startRule();
|
|
3679
|
+
$.CONSUME(T.AtKeyword);
|
|
3680
|
+
const pathNode = $.OR([{ ALT: () => $.SUBRULE($.urlFunction, { ARGS: [ctx] }) }, { ALT: () => $.SUBRULE($.string, { ARGS: [ctx] }) }]);
|
|
3681
|
+
let namespace;
|
|
3682
|
+
$.OPTION(() => {
|
|
3683
|
+
const la = $.LA(1);
|
|
3684
|
+
if (!((la.tokenType === T.PlainIdent || la.tokenType === T.Ident) && la.image === "as")) return;
|
|
3685
|
+
if ($.isType(T.Ident)) $.CONSUME(T.Ident);
|
|
3686
|
+
else $.CONSUME(T.PlainIdent);
|
|
3687
|
+
namespace = ($.isType(T.Ident) ? $.CONSUME(T.Ident) : $.CONSUME(T.PlainIdent)).image;
|
|
3688
|
+
});
|
|
3689
|
+
$.CONSUME(T.Semi);
|
|
3690
|
+
const loc = $.endRule();
|
|
3691
|
+
return new StyleImport({ path: pathNode }, {
|
|
3692
|
+
type: "compose",
|
|
3693
|
+
namespace,
|
|
3694
|
+
importOptions: { forward: true }
|
|
3695
|
+
}, loc, $.context);
|
|
3696
|
+
};
|
|
3697
|
+
}
|
|
3698
|
+
//#endregion
|
|
3699
|
+
//#region src/productions/index.ts
|
|
3700
|
+
var productions_exports = /* @__PURE__ */ __exportAll({
|
|
3701
|
+
ampersandExtend: () => ampersandExtend,
|
|
3702
|
+
anonymousMixinDefinition: () => anonymousMixinDefinition,
|
|
3703
|
+
attributeSelector: () => attributeSelector,
|
|
3704
|
+
booleanFunction: () => booleanFunction,
|
|
3705
|
+
calcFunction: () => calcFunction,
|
|
3706
|
+
callArgument: () => callArgument,
|
|
3707
|
+
comparison: () => comparison,
|
|
3708
|
+
complexSelector: () => complexSelector,
|
|
3709
|
+
compoundSelector: () => compoundSelector,
|
|
3710
|
+
customBlock: () => customBlock,
|
|
3711
|
+
customValue: () => customValue,
|
|
3712
|
+
declaration: () => declaration,
|
|
3713
|
+
declarationList: () => declarationList,
|
|
3714
|
+
exportAtRule: () => exportAtRule,
|
|
3715
|
+
expressionProduct: () => expressionProduct,
|
|
3716
|
+
expressionSum: () => expressionSum,
|
|
3717
|
+
expressionValue: () => expressionValue,
|
|
3718
|
+
extend: () => extend,
|
|
3719
|
+
forgivingSelectorList: () => forgivingSelectorList,
|
|
3720
|
+
functionCall: () => functionCall,
|
|
3721
|
+
functionCallArgs: () => functionCallArgs,
|
|
3722
|
+
guard: () => guard,
|
|
3723
|
+
guardAnd: () => guardAnd,
|
|
3724
|
+
guardDefault: () => guardDefault,
|
|
3725
|
+
guardInParens: () => guardInParens,
|
|
3726
|
+
guardInner: () => guardInner,
|
|
3727
|
+
guardOr: () => guardOr,
|
|
3728
|
+
guardWithCondition: () => guardWithCondition,
|
|
3729
|
+
guardWithConditionValue: () => guardWithConditionValue,
|
|
3730
|
+
ifFunction: () => ifFunction,
|
|
3731
|
+
importAtRule: () => importAtRule,
|
|
3732
|
+
innerAtRule: () => innerAtRule,
|
|
3733
|
+
innerCustomValue: () => innerCustomValue,
|
|
3734
|
+
keyframesName: () => keyframesName,
|
|
3735
|
+
knownFunctions: () => knownFunctions,
|
|
3736
|
+
layerName: () => layerName,
|
|
3737
|
+
lessMediaQueryFromReference: () => lessMediaQueryFromReference,
|
|
3738
|
+
lessMediaQueryFromString: () => lessMediaQueryFromString,
|
|
3739
|
+
lessMediaQueryTail: () => lessMediaQueryTail,
|
|
3740
|
+
lookupOrCall: () => lookupOrCall,
|
|
3741
|
+
main: () => main,
|
|
3742
|
+
mathProduct: () => mathProduct,
|
|
3743
|
+
mathSum: () => mathSum,
|
|
3744
|
+
mathValue: () => mathValue,
|
|
3745
|
+
mediaCondition: () => mediaCondition,
|
|
3746
|
+
mediaConditionWithoutOr: () => mediaConditionWithoutOr,
|
|
3747
|
+
mediaFeature: () => mediaFeature,
|
|
3748
|
+
mediaInParens: () => mediaInParens,
|
|
3749
|
+
mediaQuery: () => mediaQuery,
|
|
3750
|
+
mfNonIdentifierValue: () => mfNonIdentifierValue,
|
|
3751
|
+
mfValue: () => mfValue,
|
|
3752
|
+
mixinArg: () => mixinArg,
|
|
3753
|
+
mixinArgList: () => mixinArgList,
|
|
3754
|
+
mixinArgs: () => mixinArgs,
|
|
3755
|
+
mixinName: () => mixinName,
|
|
3756
|
+
mixinOrQualifiedRule: () => mixinOrQualifiedRule,
|
|
3757
|
+
mixinReference: () => mixinReference,
|
|
3758
|
+
nthValue: () => nthValue,
|
|
3759
|
+
qualifiedRule: () => qualifiedRule,
|
|
3760
|
+
qualifiedRuleBody: () => qualifiedRuleBody,
|
|
3761
|
+
relativeSelector: () => relativeSelector,
|
|
3762
|
+
selectorCapture: () => selectorCapture,
|
|
3763
|
+
selectorList: () => selectorList,
|
|
3764
|
+
simpleSelector: () => simpleSelector,
|
|
3765
|
+
squareValue: () => squareValue,
|
|
3766
|
+
string: () => string,
|
|
3767
|
+
stylesheet: () => stylesheet,
|
|
3768
|
+
unknownAtRule: () => unknownAtRule,
|
|
3769
|
+
urlFunction: () => urlFunction,
|
|
3770
|
+
useAtRule: () => useAtRule,
|
|
3771
|
+
value: () => value,
|
|
3772
|
+
valueReference: () => valueReference,
|
|
3773
|
+
valueSequence: () => valueSequence,
|
|
3774
|
+
varDeclarationOrCall: () => varDeclarationOrCall,
|
|
3775
|
+
varName: () => varName,
|
|
3776
|
+
varReference: () => varReference,
|
|
3777
|
+
wrappedDeclarationList: () => wrappedDeclarationList
|
|
3778
|
+
});
|
|
3779
|
+
//#endregion
|
|
3780
|
+
//#region src/lessRecursiveParser.ts
|
|
3781
|
+
/**
|
|
3782
|
+
* @deprecated LEGACY — Chevrotain-based Less parser engine (extends the deprecated
|
|
3783
|
+
* CssRecursiveParser). Superseded by the functional macro grammar in ./grammar.ts.
|
|
3784
|
+
* Kept only for benchmarking; TO BE DELETED once the functional parser fully lands.
|
|
3785
|
+
*/
|
|
3786
|
+
var LessRecursiveParser = class LessRecursiveParser extends CssRecursiveParser {
|
|
3787
|
+
looseMode;
|
|
3788
|
+
leakyScope;
|
|
3789
|
+
/** Warnings collected during parsing */
|
|
3790
|
+
warnings = [];
|
|
3791
|
+
/** See `LessParserConfig.mathMode` */
|
|
3792
|
+
mathMode;
|
|
3793
|
+
/** See `LessParserConfig.wrapOuterExpressions` */
|
|
3794
|
+
wrapOuterExpressions;
|
|
3795
|
+
processLegacyMSFilterToken(token) {
|
|
3796
|
+
const location = this.getLocationInfo(token);
|
|
3797
|
+
const source = token.image.replace(/\s*=\s*/g, "=");
|
|
3798
|
+
const matches = [...source.matchAll(/@([_a-zA-Z\xA0-\uFFFF][-_a-zA-Z0-9\xA0-\uFFFF]*)/g)];
|
|
3799
|
+
if (matches.length === 0) return new Any(source, { type: token.tokenType?.name }, location);
|
|
3800
|
+
return new Interpolated({
|
|
3801
|
+
source: source.replace(/@([_a-zA-Z\xA0-\uFFFF][-_a-zA-Z0-9\xA0-\uFFFF]*)/g, (_full, _name, offset, fullSource) => {
|
|
3802
|
+
const key = fullSource.slice(0, offset).match(/([A-Za-z]+)=$/)?.[1];
|
|
3803
|
+
if (key && /colorstr$/i.test(key)) return `"${INTERPOLATION_PLACEHOLDER}"`;
|
|
3804
|
+
return INTERPOLATION_PLACEHOLDER;
|
|
3805
|
+
}),
|
|
3806
|
+
replacements: matches.map((match) => createInterpolatedReference("@", match[1], location, this.context))
|
|
3807
|
+
}, { role: "any" }, location);
|
|
3808
|
+
}
|
|
3809
|
+
constructor(T, config = {}) {
|
|
3810
|
+
let { legacyMode, looseMode = true, leakyScope = true, mathMode = "parens-division", wrapOuterExpressions = true, ...rest } = config;
|
|
3811
|
+
legacyMode = legacyMode ?? looseMode;
|
|
3812
|
+
super(T, {
|
|
3813
|
+
legacyMode,
|
|
3814
|
+
...rest
|
|
3815
|
+
});
|
|
3816
|
+
this.T = T;
|
|
3817
|
+
this.looseMode = looseMode;
|
|
3818
|
+
this.leakyScope = leakyScope;
|
|
3819
|
+
this.mathMode = mathMode;
|
|
3820
|
+
this.wrapOuterExpressions = wrapOuterExpressions;
|
|
3821
|
+
this.warnings = [];
|
|
3822
|
+
for (const [key, factory] of Object.entries(productions_exports)) {
|
|
3823
|
+
if (typeof factory !== "function") continue;
|
|
3824
|
+
const rule = factory.call(this, this.T);
|
|
3825
|
+
if (key in productions) this.OVERRIDE_RULE(key, rule);
|
|
3826
|
+
else this.RULE(key, rule);
|
|
3827
|
+
}
|
|
3828
|
+
if (this.constructor === LessRecursiveParser) this.performSelfAnalysis();
|
|
3829
|
+
}
|
|
3830
|
+
processValueToken(token, ctx) {
|
|
3831
|
+
let tokenType = token.tokenType;
|
|
3832
|
+
const T = this.T;
|
|
3833
|
+
if (tokenType.name === "AtKeyword" || tokenMatcher(token, T.AtKeyword)) {
|
|
3834
|
+
if (ctx?.inCustomPropertyValue) {
|
|
3835
|
+
const atName = token.image;
|
|
3836
|
+
const ident = token.image.slice(1);
|
|
3837
|
+
this.warnDeprecation(`"${atName}" in custom property values is treated as literal text, not a variable reference. Use "\@{${ident}}" if you want it to be evaluated.`, token, "variable-in-unknown-value");
|
|
3838
|
+
return new Any(token.image, { role: "any" }, this.getLocationInfo(token));
|
|
3839
|
+
}
|
|
3840
|
+
if (ctx?.atRulePreludeBareVariableAs === "index") {
|
|
3841
|
+
const nextToken = this.LA(1).tokenType;
|
|
3842
|
+
if (this.noSep() && (nextToken === T.LSquare || nextToken === T.LParen)) return new Reference(token.image.slice(1), { type: "variable" }, this.getLocationInfo(token));
|
|
3843
|
+
const atName = token.image;
|
|
3844
|
+
const ident = token.image.slice(1);
|
|
3845
|
+
this.warnDeprecation(`"${atName}" in at-rule preludes is deprecated. Use "@{${ident}}" in Less; outside declaration values this is normalized to indexed lookup syntax.`, token, "at-rule-prelude-variable");
|
|
3846
|
+
return new Reference({ key: ident }, {
|
|
3847
|
+
type: "index",
|
|
3848
|
+
role: "ident"
|
|
3849
|
+
}, this.getLocationInfo(token));
|
|
3850
|
+
}
|
|
3851
|
+
return new Reference(token.image.slice(1), { type: "variable" }, this.getLocationInfo(token));
|
|
3852
|
+
} else if (tokenType.name === "PropertyReference") {
|
|
3853
|
+
if (ctx?.inCustomPropertyValue) {
|
|
3854
|
+
const atName = token.image;
|
|
3855
|
+
const ident = token.image.slice(1);
|
|
3856
|
+
this.warnDeprecation(`"${atName}" in custom property values is treated as literal text, not a property reference. Use "\${${ident}}" if you want it to be evaluated.`, token, "property-in-unknown-value");
|
|
3857
|
+
return new Any(token.image, { role: "any" }, this.getLocationInfo(token));
|
|
3858
|
+
}
|
|
3859
|
+
return super.processValueToken(token, ctx);
|
|
3860
|
+
} else if (tokenType === T["DefaultGuardFunc"]) return new DefaultGuard(token.image, void 0, this.getLocationInfo(token));
|
|
3861
|
+
else if (tokenType.name === "JavaScript" || T["JavaScript"] && tokenMatcher(token, T["JavaScript"])) throw new Error("Inline JavaScript using backticks is not supported. Use @use / @-use to import a script module instead. Script-module documentation is coming soon.");
|
|
3862
|
+
else if (tokenType === T["InterpolatedIdent"]) {
|
|
3863
|
+
const result = getInterpolatedOrString(token.image, this.getLocationInfo(token), this.context);
|
|
3864
|
+
if (result instanceof Interpolated) return result;
|
|
3865
|
+
else return new Any(result, { role: "ident" }, this.getLocationInfo(token));
|
|
3866
|
+
} else if (tokenType === T["LegacyMSFilter"]) return this.processLegacyMSFilterToken(token);
|
|
3867
|
+
else if (tokenType === T["PlainIdent"]) {
|
|
3868
|
+
const image = token.image;
|
|
3869
|
+
if (image === "true" || image === "false") return new Bool(image === "true", void 0, this.getLocationInfo(token));
|
|
3870
|
+
}
|
|
3871
|
+
return super.processValueToken(token, ctx);
|
|
3872
|
+
}
|
|
3873
|
+
warnDeprecation(message, token, deprecationId) {
|
|
3874
|
+
this.warnings.push({
|
|
3875
|
+
message,
|
|
3876
|
+
token,
|
|
3877
|
+
deprecation: deprecationId
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
};
|
|
3881
|
+
//#endregion
|
|
3882
|
+
//#region src/lessParser.ts
|
|
3883
|
+
/**
|
|
3884
|
+
* Cached lexer + parser singletons. Chevrotain initialization (~500ms)
|
|
3885
|
+
* only happens once — config changes are applied via instance properties
|
|
3886
|
+
* before each parse.
|
|
3887
|
+
*/
|
|
3888
|
+
let cachedLexer;
|
|
3889
|
+
let cachedParser;
|
|
3890
|
+
let cachedTokenMap;
|
|
3891
|
+
function getSharedLexerAndParser(config) {
|
|
3892
|
+
if (!cachedLexer || !cachedParser) {
|
|
3893
|
+
const { lexer, T } = createLexerDefinition(lessFragments(), lessTokens());
|
|
3894
|
+
cachedTokenMap = T;
|
|
3895
|
+
cachedLexer = new Lexer(lexer, {
|
|
3896
|
+
ensureOptimizations: true,
|
|
3897
|
+
skipValidations: process.env.TEST !== "true"
|
|
3898
|
+
});
|
|
3899
|
+
cachedParser = new LessRecursiveParser(cachedTokenMap, config);
|
|
3900
|
+
}
|
|
3901
|
+
const { looseMode = true, leakyScope = true, mathMode = "parens-division", wrapOuterExpressions = true, legacyMode = looseMode } = config;
|
|
3902
|
+
cachedParser.looseMode = looseMode;
|
|
3903
|
+
cachedParser.leakyScope = leakyScope;
|
|
3904
|
+
cachedParser.mathMode = mathMode;
|
|
3905
|
+
cachedParser.wrapOuterExpressions = wrapOuterExpressions;
|
|
3906
|
+
cachedParser.legacyMode = legacyMode;
|
|
3907
|
+
return {
|
|
3908
|
+
lexer: cachedLexer,
|
|
3909
|
+
parser: cachedParser
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
/**
|
|
3913
|
+
* @deprecated LEGACY — Chevrotain-lexer + recursive-descent Less parser. Superseded
|
|
3914
|
+
* by the functional macro grammar (`LessParser` in ./grammar.ts). Kept only for
|
|
3915
|
+
* benchmarking / migration reference; TO BE DELETED once the functional parser
|
|
3916
|
+
* fully lands.
|
|
3917
|
+
*/
|
|
3918
|
+
var LessParser$1 = class {
|
|
3919
|
+
lexer;
|
|
3920
|
+
parser;
|
|
3921
|
+
constructor(config = {}) {
|
|
3922
|
+
config = {
|
|
3923
|
+
looseMode: true,
|
|
3924
|
+
...config
|
|
3925
|
+
};
|
|
3926
|
+
const shared = getSharedLexerAndParser(config);
|
|
3927
|
+
this.lexer = shared.lexer;
|
|
3928
|
+
this.parser = shared.parser;
|
|
3929
|
+
this.parse = this.parse.bind(this);
|
|
3930
|
+
}
|
|
3931
|
+
parse(text, rule = "stylesheet", options) {
|
|
3932
|
+
const parser = this.parser;
|
|
3933
|
+
const lexerResult = this.lexer.tokenize(text);
|
|
3934
|
+
parser.warnings = [];
|
|
3935
|
+
if (options?.context) parser.context = options.context;
|
|
3936
|
+
parser.context.opts.trivia = void 0;
|
|
3937
|
+
parser.input = lexerResult.tokens;
|
|
3938
|
+
const ruleMethod = parser[rule];
|
|
3939
|
+
if (typeof ruleMethod !== "function") throw new Error(`Unknown parser rule: ${rule}`);
|
|
3940
|
+
const tree = ruleMethod.call(parser);
|
|
3941
|
+
const trivia = parser.trivia;
|
|
3942
|
+
parser.context.opts.trivia = trivia;
|
|
3943
|
+
const resultTree = tree ?? nil();
|
|
3944
|
+
(resultTree.sourceRoot?._treeContext ?? parser.context).opts.trivia = trivia;
|
|
3945
|
+
const warnings = [...parser.warnings];
|
|
3946
|
+
return {
|
|
3947
|
+
tree: resultTree,
|
|
3948
|
+
lexerResult,
|
|
3949
|
+
errors: parser.errors,
|
|
3950
|
+
trivia,
|
|
3951
|
+
warnings
|
|
3952
|
+
};
|
|
3953
|
+
}
|
|
3954
|
+
/**
|
|
3955
|
+
* @todo Implement content assist for the new parser
|
|
3956
|
+
*/
|
|
3957
|
+
suggest(text, init) {
|
|
3958
|
+
return [];
|
|
3959
|
+
}
|
|
3960
|
+
};
|
|
3961
|
+
//#endregion
|
|
3962
|
+
export { LessGrammar, LessParser, LessParser as Parser, LessParser$1 as LessParserChevrotain, LessRecursiveParser, parseLessFn };
|