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