@jesscss/less-parser 2.0.0-alpha.8 → 2.0.0-alpha.9

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 (58) hide show
  1. package/README.md +27 -10
  2. package/lib/ast/grammar.d.ts +2 -0
  3. package/lib/ast/grammar.d.ts.map +1 -0
  4. package/lib/grammar.cjs +39855 -31054
  5. package/lib/grammar.d.ts.map +1 -1
  6. package/lib/grammar.js +39855 -31054
  7. package/lib/index.cjs +49609 -15
  8. package/lib/index.d.ts +4 -9
  9. package/lib/index.d.ts.map +1 -1
  10. package/lib/index.js +49607 -5
  11. package/lib/parse-error.d.ts +15 -0
  12. package/lib/parse-error.d.ts.map +1 -0
  13. package/package.json +9 -24
  14. package/lib/builders.d.ts +0 -381
  15. package/lib/builders.d.ts.map +0 -1
  16. package/lib/functional-parser.cjs +0 -2654
  17. package/lib/functional-parser.d.ts +0 -18
  18. package/lib/functional-parser.d.ts.map +0 -1
  19. package/lib/functional-parser.js +0 -2589
  20. package/lib/jess.cjs +0 -3968
  21. package/lib/jess.d.ts +0 -7
  22. package/lib/jess.d.ts.map +0 -1
  23. package/lib/jess.js +0 -3962
  24. package/lib/lessParser.d.ts +0 -38
  25. package/lib/lessParser.d.ts.map +0 -1
  26. package/lib/lessRecursiveParser.d.ts +0 -99
  27. package/lib/lessRecursiveParser.d.ts.map +0 -1
  28. package/lib/lessTokens.d.ts +0 -23
  29. package/lib/lessTokens.d.ts.map +0 -1
  30. package/lib/productions/guards.d.ts +0 -113
  31. package/lib/productions/guards.d.ts.map +0 -1
  32. package/lib/productions/index.d.ts +0 -5
  33. package/lib/productions/index.d.ts.map +0 -1
  34. package/lib/productions/root.d.ts +0 -38
  35. package/lib/productions/root.d.ts.map +0 -1
  36. package/lib/productions/selectors.d.ts +0 -41
  37. package/lib/productions/selectors.d.ts.map +0 -1
  38. package/lib/productions/values.d.ts +0 -35
  39. package/lib/productions/values.d.ts.map +0 -1
  40. package/lib/utils.d.ts +0 -9
  41. package/lib/utils.d.ts.map +0 -1
  42. package/src/__tests__/debug-log.ts +0 -35
  43. package/src/__tests__/wall5-parse.test.ts +0 -67
  44. package/src/builders.ts +0 -3190
  45. package/src/cst.ts +0 -25
  46. package/src/functional-parser.ts +0 -162
  47. package/src/grammar.ts +0 -870
  48. package/src/index.ts +0 -19
  49. package/src/jess.ts +0 -6
  50. package/src/lessParser.ts +0 -120
  51. package/src/lessRecursiveParser.ts +0 -279
  52. package/src/lessTokens.ts +0 -350
  53. package/src/productions/guards.ts +0 -1066
  54. package/src/productions/index.ts +0 -29
  55. package/src/productions/root.ts +0 -1613
  56. package/src/productions/selectors.ts +0 -1309
  57. package/src/productions/values.ts +0 -1449
  58. package/src/utils.ts +0 -178
package/src/utils.ts DELETED
@@ -1,178 +0,0 @@
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
- };