@jesscss/less-parser 2.0.0-alpha.6 → 2.0.0-alpha.7

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