@jesscss/less-parser 2.0.0-alpha.5 → 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 (75) 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 +18 -0
  17. package/lib/index.d.ts +9 -32
  18. package/lib/index.d.ts.map +1 -0
  19. package/lib/index.js +7 -75
  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 +4 -3
  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 +8 -1
  41. package/lib/utils.d.ts.map +1 -0
  42. package/package.json +49 -16
  43. package/{lib/__tests__/debug-log.js → src/__tests__/debug-log.ts} +20 -19
  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/__tests__/debug-log.d.ts +0 -1
  61. package/lib/__tests__/debug-log.js.map +0 -1
  62. package/lib/index.js.map +0 -1
  63. package/lib/lessActionsParser.d.ts +0 -156
  64. package/lib/lessActionsParser.js +0 -145
  65. package/lib/lessActionsParser.js.map +0 -1
  66. package/lib/lessErrorMessageProvider.d.ts +0 -3
  67. package/lib/lessErrorMessageProvider.js +0 -4
  68. package/lib/lessErrorMessageProvider.js.map +0 -1
  69. package/lib/lessTokens.js +0 -249
  70. package/lib/lessTokens.js.map +0 -1
  71. package/lib/productions.d.ts +0 -181
  72. package/lib/productions.js +0 -3521
  73. package/lib/productions.js.map +0 -1
  74. package/lib/utils.js +0 -88
  75. package/lib/utils.js.map +0 -1
package/src/utils.ts ADDED
@@ -0,0 +1,178 @@
1
+ import {
2
+ InterpolatedSelector,
3
+ Interpolated,
4
+ Quoted,
5
+ Reference,
6
+ INTERPOLATION_PLACEHOLDER,
7
+ isNode,
8
+ N,
9
+ type Selector
10
+ } from '@jesscss/core';
11
+
12
+ // Pre-compiled regex for @{variable} interpolation - more efficient than creating new instances
13
+ const INTERPOLATION_REGEX = /([$@])\{([^}]+)\}/g;
14
+
15
+ export const createInterpolatedReference = (
16
+ prefix: string,
17
+ varName: string,
18
+ location?: any,
19
+ context?: any
20
+ ): Reference => {
21
+ const isProperty = prefix === '$';
22
+ const key = isProperty
23
+ ? new Quoted(varName, { quote: '\'' }, location)
24
+ : varName;
25
+ return new Reference(
26
+ { key },
27
+ { type: isProperty ? 'index' : 'variable', role: 'ident' },
28
+ location
29
+ );
30
+ };
31
+
32
+ export const getInterpolatedNode = (
33
+ name: string,
34
+ location?: any,
35
+ context?: any
36
+ ): Interpolated => {
37
+ const replacements: any[] = [];
38
+ let source = name;
39
+ let result;
40
+
41
+ INTERPOLATION_REGEX.lastIndex = 0;
42
+ while ((result = INTERPOLATION_REGEX.exec(name)) !== null) {
43
+ const [match, prefix, varName] = result;
44
+ source = source.replace(match, INTERPOLATION_PLACEHOLDER);
45
+ replacements.push(createInterpolatedReference(prefix ?? '', varName ?? '', location, context));
46
+ }
47
+
48
+ return new Interpolated({ source, replacements }, { role: 'ident' }, location);
49
+ };
50
+
51
+ export const normalizeMixinReferenceKey = (selector: Selector): { key: string | string[]; rawKey: Selector } => {
52
+ if (isNode(selector, N.BasicSelector) || selector instanceof InterpolatedSelector) {
53
+ return { key: selector.valueOf(), rawKey: selector };
54
+ }
55
+
56
+ if (isNode(selector, N.CompoundSelector)) {
57
+ return {
58
+ key: selector.value.map(node => node.valueOf()),
59
+ rawKey: selector
60
+ };
61
+ }
62
+
63
+ if (isNode(selector, N.ComplexSelector)) {
64
+ const path: string[] = [];
65
+ let canUsePath = true;
66
+
67
+ for (const node of selector.value) {
68
+ if (isNode(node, N.BasicSelector) || node instanceof InterpolatedSelector) {
69
+ path.push(node.valueOf());
70
+ continue;
71
+ }
72
+ if (isNode(node, N.CompoundSelector)) {
73
+ path.push(...node.value.map(child => child.valueOf()));
74
+ continue;
75
+ }
76
+ if (isNode(node, N.Combinator) && (node.value === '>' || node.value === ' ')) {
77
+ continue;
78
+ }
79
+ canUsePath = false;
80
+ break;
81
+ }
82
+
83
+ if (canUsePath && path.length > 0) {
84
+ return { key: path, rawKey: selector };
85
+ }
86
+ }
87
+
88
+ return { key: selector.valueOf(), rawKey: selector };
89
+ };
90
+
91
+ /* Handle both @{variable} interpolation and @id-@num variable variables */
92
+ export const getInterpolatedOrString = (name: string, location?: any, context?: any): Interpolated | string => {
93
+ // First check for @{variable} interpolation syntax
94
+ const matches: Array<{ fullMatch: string; prefix: string; varName: string; index: number }> = [];
95
+
96
+ // Reset regex state and collect all matches
97
+ INTERPOLATION_REGEX.lastIndex = 0;
98
+ let result;
99
+ while ((result = INTERPOLATION_REGEX.exec(name)) !== null) {
100
+ const [fullMatch, prefix, varName] = result;
101
+ if (varName && prefix) {
102
+ matches.push({
103
+ fullMatch,
104
+ prefix,
105
+ varName,
106
+ index: result.index
107
+ });
108
+ }
109
+ }
110
+
111
+ if (matches.length > 0) {
112
+ // Build source string and replacements
113
+ let source = name;
114
+ const replacements: any[] = [];
115
+ let offset = 0; // Track how much the string has been modified
116
+
117
+ // Process matches in forward order to maintain correct indices
118
+ for (let i = 0; i < matches.length; i++) {
119
+ const match = matches[i]!;
120
+ const adjustedIndex = match.index - offset;
121
+ const beforeMatch = source.substring(0, adjustedIndex);
122
+ const afterMatch = source.substring(adjustedIndex + match.fullMatch.length);
123
+
124
+ source = beforeMatch + INTERPOLATION_PLACEHOLDER + afterMatch;
125
+ offset += match.fullMatch.length - INTERPOLATION_PLACEHOLDER.length;
126
+
127
+ const ref = createInterpolatedReference(match.prefix, match.varName, location, context);
128
+ replacements.push(ref); // Add to end to maintain order
129
+ }
130
+
131
+ return new Interpolated({ source, replacements }, { role: 'ident' }, location);
132
+ }
133
+
134
+ // If no interpolation found, check for @id-@num variable variables
135
+ const atPos = name.indexOf('@', 1);
136
+ const dollarPos = name.indexOf('$', 1);
137
+
138
+ if (atPos === -1 && dollarPos === -1) {
139
+ if (name.startsWith('@') || name.startsWith('$')) {
140
+ return name.slice(1);
141
+ } else {
142
+ return name;
143
+ }
144
+ }
145
+
146
+ const nextPos = atPos !== -1 ? atPos : dollarPos;
147
+ const start = name.slice(1, nextPos);
148
+ const end = name.slice(nextPos);
149
+ const type: 'variable' | 'index' = end.startsWith('@') ? 'variable' : 'index';
150
+ // For @id-@num variable variables, we need to create an Interpolated node
151
+ const endResult = getInterpolatedOrString(end, location, context);
152
+ if (typeof endResult === 'string') {
153
+ const endKey = type === 'index'
154
+ ? new Quoted(endResult, { quote: '\'' }, location)
155
+ : endResult;
156
+ return new Interpolated({
157
+ source: start + INTERPOLATION_PLACEHOLDER,
158
+ replacements: [
159
+ new Reference(
160
+ { key: endKey },
161
+ { type, role: 'ident' },
162
+ location
163
+ )
164
+ ]
165
+ }, { role: 'ident' });
166
+ } else {
167
+ /**
168
+ * endResult is already an Interpolated node, so we need to handle this
169
+ * differently.
170
+ *
171
+ * @todo - test deep nesting
172
+ */
173
+ return new Interpolated({
174
+ source: start + INTERPOLATION_PLACEHOLDER,
175
+ replacements: [type === 'index' ? new Quoted(endResult, { quote: '\'' }, location) : endResult]
176
+ }, { role: 'ident' });
177
+ }
178
+ };
@@ -1 +0,0 @@
1
- export declare const syncLog: (data: object) => void;
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug-log.js","sourceRoot":"","sources":["../../src/__tests__/debug-log.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAErC,wDAAwD;AACxD,SAAS,gBAAgB,CAAC,KAAa;IACrC,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;QACnB,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC;YACjD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,CA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7B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAoC,CAAC;YACvE,MAAM,UAAU,GAAG,UAAU,EAAE,KAAwC,CAAC;QAC1E,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;IAChE,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,IAAY,EAAE,IAA0C;QAC9D,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,YAAY,EAAE,GAAG,IAAI,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAClD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,MAAM,GAAa,WAAW,CAAC,MAAM,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,KAAK,GAAI,IAAI,CAAC,MAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAkC,CAAC;YACvG,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACrB,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI;gBACnC,cAAc,EAAG,CAAC,CAAC,aAAqB,CAAC,KAAK;gBAC9C,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,eAAe,EAAE,CAAC,CAAC,eAAe;aACnC,CAAC,CAAC,CAAC;QACN,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
@@ -1,156 +0,0 @@
1
- import type { TokenVocabulary, TokenType, IToken } from 'chevrotain';
2
- import { type Rule, type RuleContext as CssRuleContext, type CssParserConfig, CssActionsParser, type CssTokenType, type TokenMap as CssTokenMap } from '@jesscss/css-parser';
3
- import { Reference, type MathMode, type Node, type Extend, type ComplexSelector, type Selector } from '@jesscss/core';
4
- import { type LessExtraTokenType } from './lessTokens.js';
5
- export type LessParserConfig = CssParserConfig & {
6
- /**
7
- * Is less strict with certain CSS rules and Less syntax
8
- * that the old Less parser allowed.
9
- *
10
- * @note This will also enable CSS legacyMode unless
11
- * legacyMode is explicitly false.
12
- */
13
- looseMode?: boolean;
14
- /**
15
- * Controls whether mixins and detached rulesets "leak" their inner rules.
16
- * When true (default):
17
- * - Mixins: Mixin and VarDeclaration nodes are 'public' and 'optional' respectively
18
- * - Detached rulesets: Mixin and VarDeclaration nodes are 'public' and 'private' respectively
19
- * When false:
20
- * - Both mixins and detached rulesets: Mixin and VarDeclaration nodes are 'private'
21
- */
22
- leakyRules?: boolean;
23
- /**
24
- * Less math evaluation mode. Used during parsing to decide whether a given
25
- * `Operation` should be represented as an `Expression` for Less→Jess conversion.
26
- *
27
- * Mirrors runtime behavior in `Context.shouldOperate()`.
28
- *
29
- * @default 'parens-division'
30
- */
31
- mathMode?: MathMode;
32
- /**
33
- * When enabled (default), the parser will wrap the *outermost* Less math/value
34
- * expressions (math operations, variable references, and chained mixin/variable
35
- * calls) in an `Expression({ parens: true })`.
36
- *
37
- * This is purely a parse-time AST shape choice to support Less→Jess conversion.
38
- *
39
- * @default true
40
- */
41
- wrapOuterExpressions?: boolean;
42
- };
43
- export type CombinedTokenMap = Record<CssTokenType, TokenType> & Record<LessExtraTokenType, TokenType>;
44
- export type TokenMap = CombinedTokenMap;
45
- export interface ExtendTarget {
46
- selector?: Selector;
47
- target: Selector;
48
- flag: IToken | undefined;
49
- }
50
- export type RuleContext = CssRuleContext & {
51
- selector?: Selector;
52
- hasDefault?: boolean;
53
- /** Selectors in a selector sequence are extended */
54
- allExtended?: boolean;
55
- /** Mixin definition */
56
- isDefinition?: boolean;
57
- allowAnonymousMixins?: boolean;
58
- requireAccessorsAfterMixinCall?: boolean;
59
- inValueList?: boolean;
60
- allowComma?: boolean;
61
- /** Allow passing in the currently constructed Node */
62
- node?: Node;
63
- ruleIsFinished?: boolean;
64
- sequences?: Array<ComplexSelector | Extend>;
65
- asReference?: boolean;
66
- /** For :extend(...) */
67
- extendTargets?: ExtendTarget[];
68
- extendNodes?: Extend[];
69
- /** Inside an extend production - prevents 'all' from being consumed as selector */
70
- inExtend?: boolean;
71
- /** Inside a custom property value - used for deprecation warnings */
72
- inCustomPropertyValue?: boolean;
73
- /**
74
- * When true, the current production should wrap the *outermost* parsed value
75
- * (if it is a Less expression) in `Expression({ parens: true })`.
76
- *
77
- * This flag should only be set by value-entry productions (e.g. `valueSequence`)
78
- * and must be cleared for nested parsing so Expressions never contain Expressions.
79
- */
80
- wrapInExpression?: boolean;
81
- /**
82
- * Parse-time equivalent of `Context.parenFrames`. This is a boolean stack
83
- * (not a depth counter) because some productions (notably `Call`) intentionally
84
- * push `false` to disable the ambient "in parens" math behavior.
85
- */
86
- parenFrames?: boolean[];
87
- /**
88
- * Parse-time equivalent of `Context.calcFrames`.
89
- */
90
- calcFrames?: number;
91
- /**
92
- * Tracks where a detached ruleset literal is parsed from so we can
93
- * disambiguate Collection vs anonymous mixin semantics.
94
- */
95
- detachedRulesetUsage?: 'function-arg' | 'mixin-arg' | 'default-param';
96
- };
97
- /**
98
- * Unlike the historical Less parser, this parser
99
- * avoids all backtracking
100
- */
101
- export declare class LessActionsParser extends CssActionsParser {
102
- T: CssTokenMap;
103
- looseMode: boolean;
104
- leakyRules: boolean;
105
- /** Warnings collected during parsing */
106
- warnings: Array<{
107
- message: string;
108
- token?: IToken;
109
- deprecation?: string;
110
- }>;
111
- expressionSum: Rule;
112
- expressionProduct: Rule;
113
- expressionValue: Rule;
114
- functionValueList: Rule;
115
- ifFunction: Rule;
116
- booleanFunction: Rule;
117
- wrappedDeclarationList: Rule;
118
- varDeclarationOrCall: Rule;
119
- varName: Rule;
120
- selectorCapture: Rule;
121
- valueReference: Rule;
122
- varReference: Rule;
123
- mixinReference: Rule;
124
- mixinName: Rule;
125
- mixinOrQualifiedRule: Rule;
126
- qualifiedRuleBody: Rule;
127
- mixinArgs: Rule;
128
- mixinArgList: Rule;
129
- mixinArg: Rule;
130
- anonymousMixinDefinition: Rule;
131
- callArgument: Rule;
132
- extend: Rule;
133
- ampersandExtend: Rule;
134
- lookupOrCall: Rule;
135
- comparison: Rule;
136
- guard: Rule;
137
- guardDefault: Rule;
138
- guardOr: Rule;
139
- guardAnd: Rule;
140
- guardInParens: Rule;
141
- guardInner: Rule;
142
- guardWithCondition: Rule;
143
- guardWithConditionValue: Rule;
144
- exportAtRule: Rule;
145
- /** See `LessParserConfig.mathMode` */
146
- mathMode: MathMode;
147
- /** See `LessParserConfig.wrapOuterExpressions` */
148
- wrapOuterExpressions: boolean;
149
- constructor(tokenVocabulary: TokenVocabulary, T: any, config?: LessParserConfig);
150
- protected processValueToken(token: IToken, ctx?: RuleContext): Reference | Node<unknown, import("core/lib/tree/node-base.js").NodeOptions>;
151
- /**
152
- * Emits a deprecation warning during parsing.
153
- * Only collects warnings during the non-recording phase.
154
- */
155
- protected warnDeprecation(message: string, token?: IToken, deprecationId?: string): void;
156
- }
@@ -1,145 +0,0 @@
1
- import { tokenMatcher } from 'chevrotain';
2
- // import { LLStarLookaheadStrategy } from 'chevrotain-allstar'
3
- import { CssActionsParser, productions as cssProductions } from '@jesscss/css-parser';
4
- import { Reference, DefaultGuard, Interpolated, Any, Bool } from '@jesscss/core';
5
- import { getInterpolatedOrString } from './utils.js';
6
- import * as productions from './productions.js';
7
- /**
8
- * Unlike the historical Less parser, this parser
9
- * avoids all backtracking
10
- */
11
- export class LessActionsParser extends CssActionsParser {
12
- looseMode;
13
- leakyRules;
14
- /** Warnings collected during parsing */
15
- warnings = [];
16
- expressionSum;
17
- expressionProduct;
18
- expressionValue;
19
- functionValueList;
20
- booleanFunction;
21
- wrappedDeclarationList;
22
- varDeclarationOrCall;
23
- varName;
24
- selectorCapture;
25
- valueReference;
26
- varReference;
27
- // mixins
28
- mixinReference;
29
- mixinName;
30
- mixinOrQualifiedRule;
31
- qualifiedRuleBody;
32
- // mixinDefinition!: Rule;
33
- // mixinCall!: Rule;
34
- // mixinCallStatement!: Rule;
35
- mixinArgs;
36
- mixinArgList;
37
- mixinArg;
38
- anonymousMixinDefinition;
39
- callArgument;
40
- extend;
41
- ampersandExtend;
42
- // namespaces
43
- // accessors!: Rule;
44
- lookupOrCall;
45
- comparison;
46
- guard;
47
- guardDefault;
48
- guardOr;
49
- guardAnd;
50
- guardInParens;
51
- guardInner;
52
- guardWithCondition;
53
- guardWithConditionValue;
54
- exportAtRule;
55
- /** See `LessParserConfig.mathMode` */
56
- mathMode;
57
- /** See `LessParserConfig.wrapOuterExpressions` */
58
- wrapOuterExpressions;
59
- constructor(tokenVocabulary, T, config = {}) {
60
- let { legacyMode, looseMode = true, leakyRules = true, mathMode = 'parens-division', wrapOuterExpressions = true, ...rest } = config;
61
- legacyMode = legacyMode ?? looseMode;
62
- super(tokenVocabulary, T, { legacyMode, ...rest });
63
- this.looseMode = looseMode;
64
- this.leakyRules = leakyRules;
65
- this.mathMode = mathMode;
66
- this.wrapOuterExpressions = wrapOuterExpressions;
67
- this.warnings = [];
68
- const $ = this;
69
- /** Less extensions */
70
- for (let [key, value] of Object.entries(productions)) {
71
- // @ts-expect-error - this is fine
72
- let rule = value.call(this, T);
73
- if (key in cssProductions) {
74
- this.OVERRIDE_RULE(key, rule);
75
- }
76
- else {
77
- this.RULE(key, rule);
78
- }
79
- }
80
- if ($.constructor === LessActionsParser) {
81
- $.performSelfAnalysis();
82
- }
83
- }
84
- processValueToken(token, ctx) {
85
- let tokenType = token.tokenType;
86
- const TT = this.T;
87
- const tokenName = tokenType.name;
88
- // Check if this is an AtKeyword token (can be consumed via T.AtName category or T.Value category)
89
- // Also check tokenMatcher in case the token type name check doesn't work
90
- if (tokenType.name === 'AtKeyword' || tokenMatcher(token, this.T.AtKeyword)) {
91
- if (!this.RECORDING_PHASE && ctx?.inCustomPropertyValue) {
92
- const atName = token.image;
93
- const ident = token.image.slice(1);
94
- 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');
95
- return new Any(token.image, { role: 'any' }, this.getLocationInfo(token), this.context);
96
- }
97
- return new Reference(token.image.slice(1), { type: 'variable' }, this.getLocationInfo(token), this.context);
98
- }
99
- else if (tokenType.name === 'PropertyReference') {
100
- if (!this.RECORDING_PHASE) {
101
- if (ctx?.inCustomPropertyValue) {
102
- const atName = token.image;
103
- const ident = token.image.slice(1);
104
- 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');
105
- return new Any(token.image, { role: 'any' }, this.getLocationInfo(token), this.context);
106
- }
107
- }
108
- return super.processValueToken(token, ctx);
109
- }
110
- else if (tokenType === TT['DefaultGuardFunc']) {
111
- return new DefaultGuard(token.image, undefined, this.getLocationInfo(token), this.context);
112
- }
113
- else if (tokenType.name === 'JavaScript'
114
- || (TT['JavaScript'] && tokenMatcher(token, TT['JavaScript']))) {
115
- throw new Error('Inline JavaScript using backticks is not supported. Use @use to import a JavaScript/TypeScript module instead. Script-module documentation is coming soon.');
116
- }
117
- else if (tokenType === TT['InterpolatedIdent']) {
118
- const result = getInterpolatedOrString(token.image, this.getLocationInfo(token), this.context);
119
- if (result instanceof Interpolated) {
120
- return result;
121
- }
122
- else {
123
- return new Any(result, { role: 'ident' }, this.getLocationInfo(token), this.context);
124
- }
125
- }
126
- else if (tokenType === TT['PlainIdent']) {
127
- // Parse true/false as Bool nodes in Less
128
- const image = token.image;
129
- if (image === 'true' || image === 'false') {
130
- return new Bool(image === 'true', undefined, this.getLocationInfo(token), this.context);
131
- }
132
- }
133
- return super.processValueToken(token, ctx);
134
- }
135
- /**
136
- * Emits a deprecation warning during parsing.
137
- * Only collects warnings during the non-recording phase.
138
- */
139
- warnDeprecation(message, token, deprecationId) {
140
- if (!this.RECORDING_PHASE) {
141
- this.warnings.push({ message, token, deprecation: deprecationId });
142
- }
143
- }
144
- }
145
- //# sourceMappingURL=lessActionsParser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lessActionsParser.js","sourceRoot":"","sources":["../src/lessActionsParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,+DAA+D;AAC/D,OAAO,EAIL,gBAAgB,EAChB,WAAW,IAAI,cAAc,EAG9B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,IAAI,EAML,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAsHhD;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,gBAAgB;IAErD,SAAS,CAAU;IACnB,UAAU,CAAU;IACpB,wCAAwC;IACxC,QAAQ,GAAqE,EAAE,CAAC;IAEhF,aAAa,CAAQ;IACrB,iBAAiB,CAAQ;IACzB,eAAe,CAAQ;IACvB,iBAAiB,CAAQ;IAEzB,eAAe,CAAQ;IAEvB,sBAAsB,CAAQ;IAE9B,oBAAoB,CAAQ;IAC5B,OAAO,CAAQ;IACf,eAAe,CAAQ;IACvB,cAAc,CAAQ;IACtB,YAAY,CAAQ;IAEpB,SAAS;IACT,cAAc,CAAQ;IACtB,SAAS,CAAQ;IACjB,oBAAoB,CAAQ;IAC5B,iBAAiB,CAAQ;IACzB,0BAA0B;IAC1B,oBAAoB;IACpB,6BAA6B;IAC7B,SAAS,CAAQ;IACjB,YAAY,CAAQ;IACpB,QAAQ,CAAQ;IAChB,wBAAwB,CAAQ;IAEhC,YAAY,CAAQ;IAEpB,MAAM,CAAQ;IACd,eAAe,CAAQ;IAEvB,aAAa;IACb,oBAAoB;IACpB,YAAY,CAAQ;IAEpB,UAAU,CAAQ;IAClB,KAA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AC,CAAC;YAC/F,IAAI,MAAM,YAAY,YAAY,EAAE,CAAC;gBACnC,OAAO,MAAM,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACvF,CAAC;QACH,CAAC;aAAM,IAAI,SAAS,KAAK,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;YAC1C,yCAAyC;YACzC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAC1B,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;gBAC1C,OAAO,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAC1F,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACO,eAAe,CAAC,OAAe,EAAE,KAAc,EAAE,aAAsB;QAC/E,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF"}
@@ -1,3 +0,0 @@
1
- import { CssErrorMessageProvider } from '@jesscss/css-parser';
2
- export declare class LessErrorMessageProvider extends CssErrorMessageProvider {
3
- }
@@ -1,4 +0,0 @@
1
- import { CssErrorMessageProvider } from '@jesscss/css-parser';
2
- export class LessErrorMessageProvider extends CssErrorMessageProvider {
3
- }
4
- //# sourceMappingURL=lessErrorMessageProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lessErrorMessageProvider.js","sourceRoot":"","sources":["../src/lessErrorMessageProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,OAAO,wBAAyB,SAAQ,uBAAuB;CAAG"}