@pandacss/parser 0.25.0 → 0.26.1
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/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +113 -268
- package/dist/index.mjs +105 -260
- package/package.json +9 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ParserOptions
|
|
1
|
+
import { ParserOptions } from '@pandacss/core';
|
|
2
2
|
import { ParserResultInterface, ResultItem, Runtime, PandaHookable, ConfigTsOptions } from '@pandacss/types';
|
|
3
3
|
import { SourceFile, ProjectOptions as ProjectOptions$1, Project as Project$1, FileSystemRefreshResult } from 'ts-morph';
|
|
4
|
+
import { Generator } from '@pandacss/generator';
|
|
4
5
|
|
|
5
6
|
declare class ParserResult implements ParserResultInterface {
|
|
6
7
|
private context;
|
|
@@ -17,6 +18,7 @@ declare class ParserResult implements ParserResultInterface {
|
|
|
17
18
|
constructor(context: ParserOptions, encoder?: ParserOptions['encoder']);
|
|
18
19
|
append(result: ResultItem): ResultItem;
|
|
19
20
|
set(name: 'cva' | 'css' | 'sva', result: ResultItem): void;
|
|
21
|
+
setCss(result: ResultItem): void;
|
|
20
22
|
setCva(result: ResultItem): void;
|
|
21
23
|
setSva(result: ResultItem): void;
|
|
22
24
|
setJsx(result: ResultItem): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ParserOptions
|
|
1
|
+
import { ParserOptions } from '@pandacss/core';
|
|
2
2
|
import { ParserResultInterface, ResultItem, Runtime, PandaHookable, ConfigTsOptions } from '@pandacss/types';
|
|
3
3
|
import { SourceFile, ProjectOptions as ProjectOptions$1, Project as Project$1, FileSystemRefreshResult } from 'ts-morph';
|
|
4
|
+
import { Generator } from '@pandacss/generator';
|
|
4
5
|
|
|
5
6
|
declare class ParserResult implements ParserResultInterface {
|
|
6
7
|
private context;
|
|
@@ -17,6 +18,7 @@ declare class ParserResult implements ParserResultInterface {
|
|
|
17
18
|
constructor(context: ParserOptions, encoder?: ParserOptions['encoder']);
|
|
18
19
|
append(result: ResultItem): ResultItem;
|
|
19
20
|
set(name: 'cva' | 'css' | 'sva', result: ResultItem): void;
|
|
21
|
+
setCss(result: ResultItem): void;
|
|
20
22
|
setCva(result: ResultItem): void;
|
|
21
23
|
setSva(result: ResultItem): void;
|
|
22
24
|
setJsx(result: ResultItem): void;
|
package/dist/index.js
CHANGED
|
@@ -39,15 +39,16 @@ module.exports = __toCommonJS(src_exports);
|
|
|
39
39
|
var import_ts_morph2 = require("ts-morph");
|
|
40
40
|
|
|
41
41
|
// src/parser.ts
|
|
42
|
-
var import_ts_path = require("@pandacss/config/ts-path");
|
|
43
42
|
var import_extractor = require("@pandacss/extractor");
|
|
44
43
|
var import_logger = require("@pandacss/logger");
|
|
45
|
-
var
|
|
44
|
+
var import_shared2 = require("@pandacss/shared");
|
|
46
45
|
var import_ts_morph = require("ts-morph");
|
|
47
46
|
var import_ts_pattern = require("ts-pattern");
|
|
48
47
|
|
|
49
|
-
// src/import.ts
|
|
50
|
-
var
|
|
48
|
+
// src/get-import-declarations.ts
|
|
49
|
+
var import_ts_path = require("@pandacss/config/ts-path");
|
|
50
|
+
|
|
51
|
+
// src/get-module-specifier-value.ts
|
|
51
52
|
var getModuleSpecifierValue = (node) => {
|
|
52
53
|
try {
|
|
53
54
|
return node.getModuleSpecifierValue();
|
|
@@ -55,53 +56,34 @@ var getModuleSpecifierValue = (node) => {
|
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
|
|
60
|
+
// src/get-import-declarations.ts
|
|
61
|
+
function getImportDeclarations(context, sourceFile) {
|
|
62
|
+
const { imports, tsOptions } = context;
|
|
63
|
+
const importDeclarations = [];
|
|
64
|
+
sourceFile.getImportDeclarations().forEach((node) => {
|
|
65
|
+
const mod = getModuleSpecifierValue(node);
|
|
66
|
+
if (!mod)
|
|
64
67
|
return;
|
|
65
|
-
|
|
66
|
-
specifiers.forEach((specifier) => {
|
|
68
|
+
node.getNamedImports().forEach((specifier) => {
|
|
67
69
|
const name = specifier.getNameNode().getText();
|
|
68
70
|
const alias = specifier.getAliasNode()?.getText() || name;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
+
const result = { name, alias, mod };
|
|
72
|
+
const found = imports.match(result, (mod2) => {
|
|
73
|
+
if (!tsOptions?.pathMappings)
|
|
74
|
+
return;
|
|
75
|
+
return (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, mod2);
|
|
76
|
+
});
|
|
77
|
+
if (!found)
|
|
71
78
|
return;
|
|
72
|
-
|
|
79
|
+
importDeclarations.push(result);
|
|
73
80
|
});
|
|
74
81
|
});
|
|
75
|
-
return
|
|
76
|
-
value: result,
|
|
77
|
-
toString() {
|
|
78
|
-
return result.map((item) => item.alias).join(", ");
|
|
79
|
-
},
|
|
80
|
-
find(id) {
|
|
81
|
-
return result.find((o) => o.alias === id);
|
|
82
|
-
},
|
|
83
|
-
createMatch(mod, keys) {
|
|
84
|
-
const mods = result.filter((o) => {
|
|
85
|
-
const isFromMod = o.mod.includes(mod) || o.importMapValue === mod;
|
|
86
|
-
const isOneOfKeys = keys.includes(o.name);
|
|
87
|
-
return isFromMod && isOneOfKeys;
|
|
88
|
-
});
|
|
89
|
-
return (0, import_shared.memo)((id) => !!mods.find((mod2) => mod2.alias === id || mod2.name === id));
|
|
90
|
-
},
|
|
91
|
-
match(id) {
|
|
92
|
-
return !!this.find(id);
|
|
93
|
-
},
|
|
94
|
-
getName(id) {
|
|
95
|
-
return this.find(id)?.name || id;
|
|
96
|
-
},
|
|
97
|
-
getAlias(id) {
|
|
98
|
-
return result.find((o) => o.name === id)?.alias || id;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
82
|
+
return importDeclarations;
|
|
101
83
|
}
|
|
102
84
|
|
|
103
85
|
// src/parser-result.ts
|
|
104
|
-
var
|
|
86
|
+
var import_shared = require("@pandacss/shared");
|
|
105
87
|
var ParserResult = class {
|
|
106
88
|
constructor(context, encoder) {
|
|
107
89
|
this.context = context;
|
|
@@ -122,21 +104,25 @@ var ParserResult = class {
|
|
|
122
104
|
return result;
|
|
123
105
|
}
|
|
124
106
|
set(name, result) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return;
|
|
107
|
+
switch (name) {
|
|
108
|
+
case "css":
|
|
109
|
+
this.setCss(result);
|
|
110
|
+
break;
|
|
111
|
+
case "cva":
|
|
112
|
+
this.setCva(result);
|
|
113
|
+
break;
|
|
114
|
+
case "sva":
|
|
115
|
+
this.setSva(result);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
throw new Error(`Unknown result type ${name}`);
|
|
138
119
|
}
|
|
139
120
|
}
|
|
121
|
+
setCss(result) {
|
|
122
|
+
this.css.add(this.append(Object.assign({ type: "css" }, result)));
|
|
123
|
+
const encoder = this.encoder;
|
|
124
|
+
result.data.forEach((obj) => encoder.processAtomic(obj));
|
|
125
|
+
}
|
|
140
126
|
setCva(result) {
|
|
141
127
|
this.cva.add(this.append(Object.assign({ type: "cva" }, result)));
|
|
142
128
|
const encoder = this.encoder;
|
|
@@ -153,7 +139,7 @@ var ParserResult = class {
|
|
|
153
139
|
result.data.forEach((obj) => encoder.processStyleProps(obj));
|
|
154
140
|
}
|
|
155
141
|
setPattern(name, result) {
|
|
156
|
-
const set = (0,
|
|
142
|
+
const set = (0, import_shared.getOrCreateSet)(this.pattern, name);
|
|
157
143
|
set.add(this.append(Object.assign({ type: "pattern", name }, result)));
|
|
158
144
|
const encoder = this.encoder;
|
|
159
145
|
result.data.forEach(
|
|
@@ -161,7 +147,7 @@ var ParserResult = class {
|
|
|
161
147
|
);
|
|
162
148
|
}
|
|
163
149
|
setRecipe(recipeName, result) {
|
|
164
|
-
const set = (0,
|
|
150
|
+
const set = (0, import_shared.getOrCreateSet)(this.recipe, recipeName);
|
|
165
151
|
set.add(this.append(Object.assign({ type: "recipe" }, result)));
|
|
166
152
|
const encoder = this.encoder;
|
|
167
153
|
const recipes = this.context.recipes;
|
|
@@ -194,11 +180,11 @@ var ParserResult = class {
|
|
|
194
180
|
result.sva.forEach((item) => this.sva.add(this.append(item)));
|
|
195
181
|
result.jsx.forEach((item) => this.jsx.add(this.append(item)));
|
|
196
182
|
result.recipe.forEach((items, name) => {
|
|
197
|
-
const set = (0,
|
|
183
|
+
const set = (0, import_shared.getOrCreateSet)(this.recipe, name);
|
|
198
184
|
items.forEach((item) => set.add(this.append(item)));
|
|
199
185
|
});
|
|
200
186
|
result.pattern.forEach((items, name) => {
|
|
201
|
-
const set = (0,
|
|
187
|
+
const set = (0, import_shared.getOrCreateSet)(this.pattern, name);
|
|
202
188
|
items.forEach((item) => set.add(this.append(item)));
|
|
203
189
|
});
|
|
204
190
|
return this;
|
|
@@ -219,199 +205,50 @@ var ParserResult = class {
|
|
|
219
205
|
};
|
|
220
206
|
|
|
221
207
|
// src/parser.ts
|
|
222
|
-
var isNodeRecipe = (node) => node.type === "recipe";
|
|
223
|
-
var isNodePattern = (node) => node.type === "pattern";
|
|
224
|
-
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
225
|
-
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
226
|
-
var noop = (..._args) => void 0;
|
|
227
|
-
function createImportMatcher(mod, values) {
|
|
228
|
-
const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
|
|
229
|
-
return {
|
|
230
|
-
mod,
|
|
231
|
-
regex,
|
|
232
|
-
match(value) {
|
|
233
|
-
return regex.test(value);
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
208
|
var combineResult = (unboxed) => {
|
|
238
209
|
return [...unboxed.conditions, unboxed.raw, ...unboxed.spreadConditions];
|
|
239
210
|
};
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
var identityFn = (styles) => styles;
|
|
247
|
-
var evaluateOptions = { environment: defaultEnv };
|
|
211
|
+
var defaultEnv = {
|
|
212
|
+
preset: "ECMA"
|
|
213
|
+
};
|
|
214
|
+
var evaluateOptions = {
|
|
215
|
+
environment: defaultEnv
|
|
216
|
+
};
|
|
248
217
|
function createParser(context) {
|
|
249
|
-
const { jsx,
|
|
250
|
-
const getRecipesByJsxName = context.recipes.filter;
|
|
251
|
-
const getPatternsByJsxName = context.patterns.filter;
|
|
252
|
-
const [recipeKeys, patternKeys] = [context.recipes.keys, context.patterns.keys];
|
|
253
|
-
const importMap = Object.fromEntries(Object.entries(context.importMap).map(([key, value]) => [key, join(...value)]));
|
|
254
|
-
const isJsxEnabled = jsx.framework;
|
|
255
|
-
const importRegex = [
|
|
256
|
-
createImportMatcher(importMap.css, ["css", "cva", "sva"]),
|
|
257
|
-
createImportMatcher(importMap.recipe),
|
|
258
|
-
createImportMatcher(importMap.pattern)
|
|
259
|
-
];
|
|
260
|
-
if (isJsxEnabled) {
|
|
261
|
-
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.jsxName)]));
|
|
262
|
-
}
|
|
218
|
+
const { jsx, imports, recipes, syntax } = context;
|
|
263
219
|
return function parse2(sourceFile, encoder) {
|
|
264
220
|
if (!sourceFile)
|
|
265
221
|
return;
|
|
222
|
+
const importDeclarations = getImportDeclarations(context, sourceFile);
|
|
223
|
+
const file = imports.file(importDeclarations);
|
|
266
224
|
const filePath = sourceFile.getFilePath();
|
|
267
|
-
const imports = getImportDeclarations(sourceFile, {
|
|
268
|
-
match(value) {
|
|
269
|
-
let found = false;
|
|
270
|
-
for (const { regex, mod } of importRegex) {
|
|
271
|
-
if (!regex.test(value.name))
|
|
272
|
-
continue;
|
|
273
|
-
if (value.mod.includes(mod)) {
|
|
274
|
-
found = true;
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
if (tsOptions?.pathMappings) {
|
|
278
|
-
const filename = (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, value.mod);
|
|
279
|
-
if (filename?.includes(mod)) {
|
|
280
|
-
found = mod;
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return found;
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
const parserResult = new ParserResult(context, encoder);
|
|
289
225
|
import_logger.logger.debug(
|
|
290
226
|
"ast:import",
|
|
291
|
-
|
|
227
|
+
!file.isEmpty() ? `Found import { ${file.toString()} } in ${filePath}` : `No import found in ${filePath}`
|
|
292
228
|
);
|
|
293
|
-
|
|
229
|
+
const parserResult = new ParserResult(context, encoder);
|
|
230
|
+
if (file.isEmpty() && !jsx.isEnabled) {
|
|
294
231
|
return parserResult;
|
|
295
232
|
}
|
|
296
|
-
const
|
|
297
|
-
const jsxFactoryAlias = isJsxEnabled ? imports.getAlias(jsx.factory) : "styled";
|
|
298
|
-
const isValidPattern = imports.createMatch(importMap.pattern, patternKeys);
|
|
299
|
-
const isValidRecipe = imports.createMatch(importMap.recipe, recipeKeys);
|
|
300
|
-
const isValidStyleFn = (name) => name === jsx.factory;
|
|
301
|
-
const isFactory = (name) => Boolean(isJsxEnabled && name.startsWith(jsxFactoryAlias));
|
|
302
|
-
const isRawFn = (fullName) => {
|
|
303
|
-
const name = fullName.split(".raw")[0] ?? "";
|
|
304
|
-
return name === "css" || isValidPattern(name) || isValidRecipe(name);
|
|
305
|
-
};
|
|
306
|
-
const patternPropertiesByJsxName = /* @__PURE__ */ new Map();
|
|
307
|
-
const initialPatterns = { string: /* @__PURE__ */ new Set(), regex: [] };
|
|
308
|
-
const patternJsxLists = isJsxEnabled ? (jsx.nodes ?? []).filter(isNodePattern).reduce((acc, pattern) => {
|
|
309
|
-
patternPropertiesByJsxName.set(pattern.jsxName, new Set(pattern.props ?? []));
|
|
310
|
-
pattern.jsx.forEach((jsx2) => {
|
|
311
|
-
if (typeof jsx2 === "string") {
|
|
312
|
-
acc.string.add(jsx2);
|
|
313
|
-
} else if (jsx2) {
|
|
314
|
-
acc.regex.push(jsx2);
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
return acc;
|
|
318
|
-
}, initialPatterns) : initialPatterns;
|
|
319
|
-
const recipes = /* @__PURE__ */ new Set();
|
|
320
|
-
const patterns = /* @__PURE__ */ new Set();
|
|
321
|
-
imports.value.forEach((importDeclaration) => {
|
|
322
|
-
const { alias } = importDeclaration;
|
|
323
|
-
if (isValidRecipe(alias)) {
|
|
324
|
-
recipes.add(alias);
|
|
325
|
-
}
|
|
326
|
-
if (isValidPattern(alias)) {
|
|
327
|
-
patterns.add(alias);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
const functions = /* @__PURE__ */ new Map();
|
|
331
|
-
const components = /* @__PURE__ */ new Map();
|
|
332
|
-
const propertiesMap = /* @__PURE__ */ new Map();
|
|
333
|
-
const recipePropertiesByJsxName = /* @__PURE__ */ new Map();
|
|
334
|
-
const initialRecipes = { string: /* @__PURE__ */ new Set(), regex: [] };
|
|
335
|
-
const recipeJsxLists = isJsxEnabled ? (jsx.nodes ?? []).filter(isNodeRecipe).reduce((acc, recipe) => {
|
|
336
|
-
recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
|
|
337
|
-
recipe.jsx.forEach((jsx2) => {
|
|
338
|
-
if (typeof jsx2 === "string") {
|
|
339
|
-
acc.string.add(jsx2);
|
|
340
|
-
} else {
|
|
341
|
-
acc.regex.push(jsx2);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
return acc;
|
|
345
|
-
}, initialRecipes) : initialRecipes;
|
|
346
|
-
const cvaAlias = imports.getAlias("cva");
|
|
347
|
-
const cssAlias = imports.getAlias("css");
|
|
348
|
-
const svaAlias = imports.getAlias("sva");
|
|
349
|
-
if (context.jsx) {
|
|
350
|
-
context.jsx.nodes.forEach((node) => {
|
|
351
|
-
const alias = imports.getAlias(node.jsxName);
|
|
352
|
-
node.props?.forEach((prop) => propertiesMap.set(prop, true));
|
|
353
|
-
functions.set(node.baseName, propertiesMap);
|
|
354
|
-
functions.set(alias, propertiesMap);
|
|
355
|
-
components.set(alias, propertiesMap);
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
const isJsxTagRecipe = isJsxEnabled ? (0, import_shared3.memo)(
|
|
359
|
-
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
360
|
-
) : noop;
|
|
361
|
-
const isJsxTagPattern = isJsxEnabled ? (0, import_shared3.memo)(
|
|
362
|
-
(tagName) => patternJsxLists.string.has(tagName) || patternJsxLists.regex.some((regex) => regex.test(tagName))
|
|
363
|
-
) : noop;
|
|
364
|
-
const matchTag = isJsxEnabled ? (0, import_shared3.memo)((tagName) => {
|
|
365
|
-
if (!tagName)
|
|
366
|
-
return false;
|
|
367
|
-
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName) || isJsxTagPattern(tagName);
|
|
368
|
-
}) : noop;
|
|
369
|
-
const isRecipeOrPatternProp = (0, import_shared3.memo)((tagName, propName) => {
|
|
370
|
-
if (isJsxEnabled && isJsxTagRecipe(tagName)) {
|
|
371
|
-
const recipeList = getRecipesByJsxName(tagName);
|
|
372
|
-
return recipeList.some((recipe) => recipePropertiesByJsxName.get(recipe.jsxName)?.has(propName));
|
|
373
|
-
}
|
|
374
|
-
if (isJsxEnabled && isJsxTagPattern(tagName)) {
|
|
375
|
-
const patternList = getPatternsByJsxName(tagName);
|
|
376
|
-
return patternList.some((pattern) => patternPropertiesByJsxName.get(pattern.jsxName)?.has(propName));
|
|
377
|
-
}
|
|
378
|
-
return false;
|
|
379
|
-
});
|
|
380
|
-
const matchTagProp = isJsxEnabled ? (0, import_ts_pattern.match)(jsx.styleProps).with(
|
|
381
|
-
"all",
|
|
382
|
-
() => (0, import_shared3.memo)((tagName, propName) => {
|
|
383
|
-
return Boolean(components.get(tagName)?.has(propName)) || isValidProperty(propName) || propertiesMap.has(propName) || isRecipeOrPatternProp(tagName, propName);
|
|
384
|
-
})
|
|
385
|
-
).with(
|
|
386
|
-
"minimal",
|
|
387
|
-
() => (0, import_shared3.memo)((tagName, propName) => {
|
|
388
|
-
return propName === "css" || isRecipeOrPatternProp(tagName, propName);
|
|
389
|
-
})
|
|
390
|
-
).with("none", () => (0, import_shared3.memo)((tagName, propName) => isRecipeOrPatternProp(tagName, propName))).exhaustive() : noop;
|
|
391
|
-
const matchFn = (0, import_shared3.memo)((fnName) => {
|
|
392
|
-
if (recipes.has(fnName) || patterns.has(fnName))
|
|
393
|
-
return true;
|
|
394
|
-
if (fnName === cvaAlias || fnName === cssAlias || fnName === svaAlias || isRawFn(fnName) || isFactory(fnName))
|
|
395
|
-
return true;
|
|
396
|
-
return functions.has(fnName);
|
|
397
|
-
});
|
|
398
|
-
const measure = import_logger.logger.time.debug(`Tokens extracted from ${filePath}`);
|
|
233
|
+
const measure = import_logger.logger.time.debug(`Extract AST from ${filePath}`);
|
|
399
234
|
const extractResultByName = (0, import_extractor.extract)({
|
|
400
235
|
ast: sourceFile,
|
|
401
|
-
components:
|
|
402
|
-
matchTag: (prop) => !!matchTag(prop.tagName),
|
|
403
|
-
matchProp: (prop) => !!matchTagProp(prop.tagName, prop.propName)
|
|
236
|
+
components: jsx.isEnabled ? {
|
|
237
|
+
matchTag: (prop) => !!file.matchTag(prop.tagName),
|
|
238
|
+
matchProp: (prop) => !!file.matchTagProp(prop.tagName, prop.propName)
|
|
404
239
|
} : void 0,
|
|
405
240
|
functions: {
|
|
406
|
-
matchFn: (prop) => matchFn(prop.fnName),
|
|
241
|
+
matchFn: (prop) => file.matchFn(prop.fnName),
|
|
407
242
|
matchProp: () => true,
|
|
408
243
|
matchArg: (prop) => {
|
|
409
|
-
if (prop.fnName === jsxFactoryAlias && prop.index === 1 && import_ts_morph.Node.isIdentifier(prop.argNode))
|
|
244
|
+
if (prop.fnName === file.jsxFactoryAlias && prop.index === 1 && import_ts_morph.Node.isIdentifier(prop.argNode))
|
|
410
245
|
return false;
|
|
411
246
|
return true;
|
|
412
247
|
}
|
|
413
248
|
},
|
|
414
|
-
taggedTemplates: syntax === "template-literal" ? {
|
|
249
|
+
taggedTemplates: syntax === "template-literal" ? {
|
|
250
|
+
matchTaggedTemplate: (tag) => file.matchFn(tag.fnName)
|
|
251
|
+
} : void 0,
|
|
415
252
|
getEvaluateOptions: (node) => {
|
|
416
253
|
if (!import_ts_morph.Node.isCallExpression(node))
|
|
417
254
|
return evaluateOptions;
|
|
@@ -419,25 +256,26 @@ function createParser(context) {
|
|
|
419
256
|
if (!import_ts_morph.Node.isPropertyAccessExpression(propAccessExpr))
|
|
420
257
|
return evaluateOptions;
|
|
421
258
|
let name = propAccessExpr.getText();
|
|
422
|
-
if (!isRawFn(name)) {
|
|
259
|
+
if (!file.isRawFn(name)) {
|
|
423
260
|
return evaluateOptions;
|
|
424
261
|
}
|
|
425
262
|
name = name.replace(".raw", "");
|
|
426
263
|
return {
|
|
427
|
-
environment: Object.assign({}, defaultEnv, {
|
|
264
|
+
environment: Object.assign({}, defaultEnv, {
|
|
265
|
+
extra: {
|
|
266
|
+
[name]: { raw: (v) => v }
|
|
267
|
+
}
|
|
268
|
+
})
|
|
428
269
|
};
|
|
429
270
|
},
|
|
430
271
|
flags: { skipTraverseFiles: true }
|
|
431
272
|
});
|
|
432
273
|
measure();
|
|
433
274
|
extractResultByName.forEach((result, alias) => {
|
|
434
|
-
|
|
435
|
-
if (isRawFn(name))
|
|
436
|
-
name = name.replace(".raw", "");
|
|
437
|
-
name = imports.getName(name);
|
|
275
|
+
const name = file.getName(file.normalizeFnName(alias));
|
|
438
276
|
import_logger.logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
439
277
|
if (result.kind === "function") {
|
|
440
|
-
(0, import_ts_pattern.match)(name).when(css.match, (name2) => {
|
|
278
|
+
(0, import_ts_pattern.match)(name).when(imports.matchers.css.match, (name2) => {
|
|
441
279
|
result.queryList.forEach((query) => {
|
|
442
280
|
if (query.kind === "call-expression") {
|
|
443
281
|
if (query.box.value.length > 1) {
|
|
@@ -452,46 +290,46 @@ function createParser(context) {
|
|
|
452
290
|
} else {
|
|
453
291
|
parserResult.set(name2, {
|
|
454
292
|
name: name2,
|
|
455
|
-
box: query.box.value[0] ?? fallback(query.box),
|
|
293
|
+
box: query.box.value[0] ?? import_extractor.box.fallback(query.box),
|
|
456
294
|
data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
|
|
457
295
|
});
|
|
458
296
|
}
|
|
459
297
|
} else if (query.kind === "tagged-template") {
|
|
460
|
-
const obj = (0,
|
|
298
|
+
const obj = (0, import_shared2.astish)(query.box.value);
|
|
461
299
|
parserResult.set(name2, {
|
|
462
300
|
name: name2,
|
|
463
|
-
box: query.box ?? fallback(query.box),
|
|
301
|
+
box: query.box ?? import_extractor.box.fallback(query.box),
|
|
464
302
|
data: [obj]
|
|
465
303
|
});
|
|
466
304
|
}
|
|
467
305
|
});
|
|
468
|
-
}).when(isValidPattern, (name2) => {
|
|
306
|
+
}).when(file.isValidPattern, (name2) => {
|
|
469
307
|
result.queryList.forEach((query) => {
|
|
470
308
|
if (query.kind === "call-expression") {
|
|
471
309
|
parserResult.setPattern(name2, {
|
|
472
310
|
name: name2,
|
|
473
|
-
box: query.box.value[0] ?? fallback(query.box),
|
|
311
|
+
box: query.box.value[0] ?? import_extractor.box.fallback(query.box),
|
|
474
312
|
data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
|
|
475
313
|
});
|
|
476
314
|
}
|
|
477
315
|
});
|
|
478
|
-
}).when(isValidRecipe, (name2) => {
|
|
316
|
+
}).when(file.isValidRecipe, (name2) => {
|
|
479
317
|
result.queryList.forEach((query) => {
|
|
480
318
|
if (query.kind === "call-expression") {
|
|
481
319
|
parserResult.setRecipe(name2, {
|
|
482
320
|
name: name2,
|
|
483
|
-
box: query.box.value[0] ?? fallback(query.box),
|
|
321
|
+
box: query.box.value[0] ?? import_extractor.box.fallback(query.box),
|
|
484
322
|
data: combineResult((0, import_extractor.unbox)(query.box.value[0]))
|
|
485
323
|
});
|
|
486
324
|
}
|
|
487
325
|
});
|
|
488
|
-
}).when(
|
|
326
|
+
}).when(jsx.isJsxFactory, () => {
|
|
489
327
|
result.queryList.forEach((query) => {
|
|
490
328
|
if (query.kind === "call-expression" && query.box.value[1]) {
|
|
491
329
|
const map = query.box.value[1];
|
|
492
|
-
const boxNode = import_extractor.box.isMap(map) ? map : fallback(query.box);
|
|
330
|
+
const boxNode = import_extractor.box.isMap(map) ? map : import_extractor.box.fallback(query.box);
|
|
493
331
|
const result2 = { name, box: boxNode, data: combineResult((0, import_extractor.unbox)(boxNode)) };
|
|
494
|
-
if (import_extractor.box.
|
|
332
|
+
if (import_extractor.box.isRecipe(map)) {
|
|
495
333
|
parserResult.setCva(result2);
|
|
496
334
|
} else {
|
|
497
335
|
parserResult.set("css", result2);
|
|
@@ -501,7 +339,7 @@ function createParser(context) {
|
|
|
501
339
|
const maybeIdentifier = map.getNode();
|
|
502
340
|
if (import_ts_morph.Node.isIdentifier(maybeIdentifier)) {
|
|
503
341
|
const name2 = maybeIdentifier.getText();
|
|
504
|
-
const recipeName =
|
|
342
|
+
const recipeName = file.getName(name2);
|
|
505
343
|
parserResult.setRecipe(recipeName, {
|
|
506
344
|
type: "jsx-recipe",
|
|
507
345
|
name: recipeName,
|
|
@@ -511,58 +349,65 @@ function createParser(context) {
|
|
|
511
349
|
}
|
|
512
350
|
}
|
|
513
351
|
} else if (query.kind === "tagged-template") {
|
|
514
|
-
const obj = (0,
|
|
352
|
+
const obj = (0, import_shared2.astish)(query.box.value);
|
|
515
353
|
parserResult.set("css", {
|
|
516
354
|
name,
|
|
517
|
-
box: query.box ?? fallback(query.box),
|
|
355
|
+
box: query.box ?? import_extractor.box.fallback(query.box),
|
|
518
356
|
data: [obj]
|
|
519
357
|
});
|
|
520
358
|
}
|
|
521
359
|
});
|
|
522
|
-
}).when(
|
|
360
|
+
}).when(file.isJsxFactory, (name2) => {
|
|
523
361
|
result.queryList.forEach((query) => {
|
|
524
362
|
if (query.kind === "call-expression") {
|
|
525
363
|
const map = query.box.value[0];
|
|
526
|
-
const boxNode = import_extractor.box.isMap(map) ? map : fallback(query.box);
|
|
364
|
+
const boxNode = import_extractor.box.isMap(map) ? map : import_extractor.box.fallback(query.box);
|
|
527
365
|
const result2 = { name: name2, box: boxNode, data: combineResult((0, import_extractor.unbox)(boxNode)) };
|
|
528
|
-
if (import_extractor.box.
|
|
366
|
+
if (import_extractor.box.isRecipe(map)) {
|
|
529
367
|
parserResult.setCva(result2);
|
|
530
368
|
} else {
|
|
531
369
|
parserResult.set("css", result2);
|
|
532
370
|
}
|
|
533
371
|
} else if (query.kind === "tagged-template") {
|
|
534
|
-
const obj = (0,
|
|
372
|
+
const obj = (0, import_shared2.astish)(query.box.value);
|
|
535
373
|
parserResult.set("css", {
|
|
536
374
|
name: name2,
|
|
537
|
-
box: query.box ?? fallback(query.box),
|
|
375
|
+
box: query.box ?? import_extractor.box.fallback(query.box),
|
|
538
376
|
data: [obj]
|
|
539
377
|
});
|
|
540
378
|
}
|
|
541
379
|
});
|
|
542
380
|
}).otherwise(() => {
|
|
543
381
|
});
|
|
544
|
-
} else if (
|
|
382
|
+
} else if (jsx.isEnabled && result.kind === "component") {
|
|
545
383
|
result.queryList.forEach((query) => {
|
|
546
384
|
const data = combineResult((0, import_extractor.unbox)(query.box));
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
385
|
+
switch (true) {
|
|
386
|
+
case file.isJsxFactory(name): {
|
|
387
|
+
parserResult.setJsx({ type: "jsx-factory", name, box: query.box, data });
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
case jsx.isJsxTagPattern(name): {
|
|
391
|
+
parserResult.setPattern(name, { type: "jsx-pattern", name, box: query.box, data });
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
case jsx.isJsxTagRecipe(name): {
|
|
395
|
+
const matchingRecipes = recipes.filter(name);
|
|
396
|
+
matchingRecipes.map((recipe) => {
|
|
397
|
+
parserResult.setRecipe(recipe.baseName, { type: "jsx-recipe", name, box: query.box, data });
|
|
398
|
+
});
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
default: {
|
|
402
|
+
parserResult.setJsx({ type: "jsx", name, box: query.box, data });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
559
405
|
});
|
|
560
406
|
}
|
|
561
407
|
});
|
|
562
408
|
return parserResult;
|
|
563
409
|
};
|
|
564
410
|
}
|
|
565
|
-
var isUpperCase = (value) => value[0] === value[0]?.toUpperCase();
|
|
566
411
|
|
|
567
412
|
// src/svelte-to-tsx.ts
|
|
568
413
|
var import_magic_string = __toESM(require("magic-string"));
|
package/dist/index.mjs
CHANGED
|
@@ -5,15 +5,16 @@ import {
|
|
|
5
5
|
} from "ts-morph";
|
|
6
6
|
|
|
7
7
|
// src/parser.ts
|
|
8
|
-
import { resolveTsPathPattern } from "@pandacss/config/ts-path";
|
|
9
8
|
import { box, extract, unbox } from "@pandacss/extractor";
|
|
10
9
|
import { logger } from "@pandacss/logger";
|
|
11
|
-
import { astish
|
|
10
|
+
import { astish } from "@pandacss/shared";
|
|
12
11
|
import { Node } from "ts-morph";
|
|
13
12
|
import { match } from "ts-pattern";
|
|
14
13
|
|
|
15
|
-
// src/import.ts
|
|
16
|
-
import {
|
|
14
|
+
// src/get-import-declarations.ts
|
|
15
|
+
import { resolveTsPathPattern } from "@pandacss/config/ts-path";
|
|
16
|
+
|
|
17
|
+
// src/get-module-specifier-value.ts
|
|
17
18
|
var getModuleSpecifierValue = (node) => {
|
|
18
19
|
try {
|
|
19
20
|
return node.getModuleSpecifierValue();
|
|
@@ -21,49 +22,30 @@ var getModuleSpecifierValue = (node) => {
|
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
|
|
26
|
+
// src/get-import-declarations.ts
|
|
27
|
+
function getImportDeclarations(context, sourceFile) {
|
|
28
|
+
const { imports, tsOptions } = context;
|
|
29
|
+
const importDeclarations = [];
|
|
30
|
+
sourceFile.getImportDeclarations().forEach((node) => {
|
|
31
|
+
const mod = getModuleSpecifierValue(node);
|
|
32
|
+
if (!mod)
|
|
30
33
|
return;
|
|
31
|
-
|
|
32
|
-
specifiers.forEach((specifier) => {
|
|
34
|
+
node.getNamedImports().forEach((specifier) => {
|
|
33
35
|
const name = specifier.getNameNode().getText();
|
|
34
36
|
const alias = specifier.getAliasNode()?.getText() || name;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
+
const result = { name, alias, mod };
|
|
38
|
+
const found = imports.match(result, (mod2) => {
|
|
39
|
+
if (!tsOptions?.pathMappings)
|
|
40
|
+
return;
|
|
41
|
+
return resolveTsPathPattern(tsOptions.pathMappings, mod2);
|
|
42
|
+
});
|
|
43
|
+
if (!found)
|
|
37
44
|
return;
|
|
38
|
-
|
|
45
|
+
importDeclarations.push(result);
|
|
39
46
|
});
|
|
40
47
|
});
|
|
41
|
-
return
|
|
42
|
-
value: result,
|
|
43
|
-
toString() {
|
|
44
|
-
return result.map((item) => item.alias).join(", ");
|
|
45
|
-
},
|
|
46
|
-
find(id) {
|
|
47
|
-
return result.find((o) => o.alias === id);
|
|
48
|
-
},
|
|
49
|
-
createMatch(mod, keys) {
|
|
50
|
-
const mods = result.filter((o) => {
|
|
51
|
-
const isFromMod = o.mod.includes(mod) || o.importMapValue === mod;
|
|
52
|
-
const isOneOfKeys = keys.includes(o.name);
|
|
53
|
-
return isFromMod && isOneOfKeys;
|
|
54
|
-
});
|
|
55
|
-
return memo((id) => !!mods.find((mod2) => mod2.alias === id || mod2.name === id));
|
|
56
|
-
},
|
|
57
|
-
match(id) {
|
|
58
|
-
return !!this.find(id);
|
|
59
|
-
},
|
|
60
|
-
getName(id) {
|
|
61
|
-
return this.find(id)?.name || id;
|
|
62
|
-
},
|
|
63
|
-
getAlias(id) {
|
|
64
|
-
return result.find((o) => o.name === id)?.alias || id;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
48
|
+
return importDeclarations;
|
|
67
49
|
}
|
|
68
50
|
|
|
69
51
|
// src/parser-result.ts
|
|
@@ -88,21 +70,25 @@ var ParserResult = class {
|
|
|
88
70
|
return result;
|
|
89
71
|
}
|
|
90
72
|
set(name, result) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return;
|
|
73
|
+
switch (name) {
|
|
74
|
+
case "css":
|
|
75
|
+
this.setCss(result);
|
|
76
|
+
break;
|
|
77
|
+
case "cva":
|
|
78
|
+
this.setCva(result);
|
|
79
|
+
break;
|
|
80
|
+
case "sva":
|
|
81
|
+
this.setSva(result);
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(`Unknown result type ${name}`);
|
|
104
85
|
}
|
|
105
86
|
}
|
|
87
|
+
setCss(result) {
|
|
88
|
+
this.css.add(this.append(Object.assign({ type: "css" }, result)));
|
|
89
|
+
const encoder = this.encoder;
|
|
90
|
+
result.data.forEach((obj) => encoder.processAtomic(obj));
|
|
91
|
+
}
|
|
106
92
|
setCva(result) {
|
|
107
93
|
this.cva.add(this.append(Object.assign({ type: "cva" }, result)));
|
|
108
94
|
const encoder = this.encoder;
|
|
@@ -185,199 +171,50 @@ var ParserResult = class {
|
|
|
185
171
|
};
|
|
186
172
|
|
|
187
173
|
// src/parser.ts
|
|
188
|
-
var isNodeRecipe = (node) => node.type === "recipe";
|
|
189
|
-
var isNodePattern = (node) => node.type === "pattern";
|
|
190
|
-
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
191
|
-
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
192
|
-
var noop = (..._args) => void 0;
|
|
193
|
-
function createImportMatcher(mod, values) {
|
|
194
|
-
const regex = values ? new RegExp(`^(${values.join("|")})$`) : /.*/;
|
|
195
|
-
return {
|
|
196
|
-
mod,
|
|
197
|
-
regex,
|
|
198
|
-
match(value) {
|
|
199
|
-
return regex.test(value);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
174
|
var combineResult = (unboxed) => {
|
|
204
175
|
return [...unboxed.conditions, unboxed.raw, ...unboxed.spreadConditions];
|
|
205
176
|
};
|
|
206
|
-
var
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
var identityFn = (styles) => styles;
|
|
213
|
-
var evaluateOptions = { environment: defaultEnv };
|
|
177
|
+
var defaultEnv = {
|
|
178
|
+
preset: "ECMA"
|
|
179
|
+
};
|
|
180
|
+
var evaluateOptions = {
|
|
181
|
+
environment: defaultEnv
|
|
182
|
+
};
|
|
214
183
|
function createParser(context) {
|
|
215
|
-
const { jsx,
|
|
216
|
-
const getRecipesByJsxName = context.recipes.filter;
|
|
217
|
-
const getPatternsByJsxName = context.patterns.filter;
|
|
218
|
-
const [recipeKeys, patternKeys] = [context.recipes.keys, context.patterns.keys];
|
|
219
|
-
const importMap = Object.fromEntries(Object.entries(context.importMap).map(([key, value]) => [key, join(...value)]));
|
|
220
|
-
const isJsxEnabled = jsx.framework;
|
|
221
|
-
const importRegex = [
|
|
222
|
-
createImportMatcher(importMap.css, ["css", "cva", "sva"]),
|
|
223
|
-
createImportMatcher(importMap.recipe),
|
|
224
|
-
createImportMatcher(importMap.pattern)
|
|
225
|
-
];
|
|
226
|
-
if (isJsxEnabled) {
|
|
227
|
-
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.jsxName)]));
|
|
228
|
-
}
|
|
184
|
+
const { jsx, imports, recipes, syntax } = context;
|
|
229
185
|
return function parse2(sourceFile, encoder) {
|
|
230
186
|
if (!sourceFile)
|
|
231
187
|
return;
|
|
188
|
+
const importDeclarations = getImportDeclarations(context, sourceFile);
|
|
189
|
+
const file = imports.file(importDeclarations);
|
|
232
190
|
const filePath = sourceFile.getFilePath();
|
|
233
|
-
const imports = getImportDeclarations(sourceFile, {
|
|
234
|
-
match(value) {
|
|
235
|
-
let found = false;
|
|
236
|
-
for (const { regex, mod } of importRegex) {
|
|
237
|
-
if (!regex.test(value.name))
|
|
238
|
-
continue;
|
|
239
|
-
if (value.mod.includes(mod)) {
|
|
240
|
-
found = true;
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
if (tsOptions?.pathMappings) {
|
|
244
|
-
const filename = resolveTsPathPattern(tsOptions.pathMappings, value.mod);
|
|
245
|
-
if (filename?.includes(mod)) {
|
|
246
|
-
found = mod;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return found;
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
const parserResult = new ParserResult(context, encoder);
|
|
255
191
|
logger.debug(
|
|
256
192
|
"ast:import",
|
|
257
|
-
|
|
193
|
+
!file.isEmpty() ? `Found import { ${file.toString()} } in ${filePath}` : `No import found in ${filePath}`
|
|
258
194
|
);
|
|
259
|
-
|
|
195
|
+
const parserResult = new ParserResult(context, encoder);
|
|
196
|
+
if (file.isEmpty() && !jsx.isEnabled) {
|
|
260
197
|
return parserResult;
|
|
261
198
|
}
|
|
262
|
-
const
|
|
263
|
-
const jsxFactoryAlias = isJsxEnabled ? imports.getAlias(jsx.factory) : "styled";
|
|
264
|
-
const isValidPattern = imports.createMatch(importMap.pattern, patternKeys);
|
|
265
|
-
const isValidRecipe = imports.createMatch(importMap.recipe, recipeKeys);
|
|
266
|
-
const isValidStyleFn = (name) => name === jsx.factory;
|
|
267
|
-
const isFactory = (name) => Boolean(isJsxEnabled && name.startsWith(jsxFactoryAlias));
|
|
268
|
-
const isRawFn = (fullName) => {
|
|
269
|
-
const name = fullName.split(".raw")[0] ?? "";
|
|
270
|
-
return name === "css" || isValidPattern(name) || isValidRecipe(name);
|
|
271
|
-
};
|
|
272
|
-
const patternPropertiesByJsxName = /* @__PURE__ */ new Map();
|
|
273
|
-
const initialPatterns = { string: /* @__PURE__ */ new Set(), regex: [] };
|
|
274
|
-
const patternJsxLists = isJsxEnabled ? (jsx.nodes ?? []).filter(isNodePattern).reduce((acc, pattern) => {
|
|
275
|
-
patternPropertiesByJsxName.set(pattern.jsxName, new Set(pattern.props ?? []));
|
|
276
|
-
pattern.jsx.forEach((jsx2) => {
|
|
277
|
-
if (typeof jsx2 === "string") {
|
|
278
|
-
acc.string.add(jsx2);
|
|
279
|
-
} else if (jsx2) {
|
|
280
|
-
acc.regex.push(jsx2);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
return acc;
|
|
284
|
-
}, initialPatterns) : initialPatterns;
|
|
285
|
-
const recipes = /* @__PURE__ */ new Set();
|
|
286
|
-
const patterns = /* @__PURE__ */ new Set();
|
|
287
|
-
imports.value.forEach((importDeclaration) => {
|
|
288
|
-
const { alias } = importDeclaration;
|
|
289
|
-
if (isValidRecipe(alias)) {
|
|
290
|
-
recipes.add(alias);
|
|
291
|
-
}
|
|
292
|
-
if (isValidPattern(alias)) {
|
|
293
|
-
patterns.add(alias);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
const functions = /* @__PURE__ */ new Map();
|
|
297
|
-
const components = /* @__PURE__ */ new Map();
|
|
298
|
-
const propertiesMap = /* @__PURE__ */ new Map();
|
|
299
|
-
const recipePropertiesByJsxName = /* @__PURE__ */ new Map();
|
|
300
|
-
const initialRecipes = { string: /* @__PURE__ */ new Set(), regex: [] };
|
|
301
|
-
const recipeJsxLists = isJsxEnabled ? (jsx.nodes ?? []).filter(isNodeRecipe).reduce((acc, recipe) => {
|
|
302
|
-
recipePropertiesByJsxName.set(recipe.jsxName, new Set(recipe.props ?? []));
|
|
303
|
-
recipe.jsx.forEach((jsx2) => {
|
|
304
|
-
if (typeof jsx2 === "string") {
|
|
305
|
-
acc.string.add(jsx2);
|
|
306
|
-
} else {
|
|
307
|
-
acc.regex.push(jsx2);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
return acc;
|
|
311
|
-
}, initialRecipes) : initialRecipes;
|
|
312
|
-
const cvaAlias = imports.getAlias("cva");
|
|
313
|
-
const cssAlias = imports.getAlias("css");
|
|
314
|
-
const svaAlias = imports.getAlias("sva");
|
|
315
|
-
if (context.jsx) {
|
|
316
|
-
context.jsx.nodes.forEach((node) => {
|
|
317
|
-
const alias = imports.getAlias(node.jsxName);
|
|
318
|
-
node.props?.forEach((prop) => propertiesMap.set(prop, true));
|
|
319
|
-
functions.set(node.baseName, propertiesMap);
|
|
320
|
-
functions.set(alias, propertiesMap);
|
|
321
|
-
components.set(alias, propertiesMap);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
const isJsxTagRecipe = isJsxEnabled ? memo2(
|
|
325
|
-
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
326
|
-
) : noop;
|
|
327
|
-
const isJsxTagPattern = isJsxEnabled ? memo2(
|
|
328
|
-
(tagName) => patternJsxLists.string.has(tagName) || patternJsxLists.regex.some((regex) => regex.test(tagName))
|
|
329
|
-
) : noop;
|
|
330
|
-
const matchTag = isJsxEnabled ? memo2((tagName) => {
|
|
331
|
-
if (!tagName)
|
|
332
|
-
return false;
|
|
333
|
-
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName) || isJsxTagPattern(tagName);
|
|
334
|
-
}) : noop;
|
|
335
|
-
const isRecipeOrPatternProp = memo2((tagName, propName) => {
|
|
336
|
-
if (isJsxEnabled && isJsxTagRecipe(tagName)) {
|
|
337
|
-
const recipeList = getRecipesByJsxName(tagName);
|
|
338
|
-
return recipeList.some((recipe) => recipePropertiesByJsxName.get(recipe.jsxName)?.has(propName));
|
|
339
|
-
}
|
|
340
|
-
if (isJsxEnabled && isJsxTagPattern(tagName)) {
|
|
341
|
-
const patternList = getPatternsByJsxName(tagName);
|
|
342
|
-
return patternList.some((pattern) => patternPropertiesByJsxName.get(pattern.jsxName)?.has(propName));
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
|
-
});
|
|
346
|
-
const matchTagProp = isJsxEnabled ? match(jsx.styleProps).with(
|
|
347
|
-
"all",
|
|
348
|
-
() => memo2((tagName, propName) => {
|
|
349
|
-
return Boolean(components.get(tagName)?.has(propName)) || isValidProperty(propName) || propertiesMap.has(propName) || isRecipeOrPatternProp(tagName, propName);
|
|
350
|
-
})
|
|
351
|
-
).with(
|
|
352
|
-
"minimal",
|
|
353
|
-
() => memo2((tagName, propName) => {
|
|
354
|
-
return propName === "css" || isRecipeOrPatternProp(tagName, propName);
|
|
355
|
-
})
|
|
356
|
-
).with("none", () => memo2((tagName, propName) => isRecipeOrPatternProp(tagName, propName))).exhaustive() : noop;
|
|
357
|
-
const matchFn = memo2((fnName) => {
|
|
358
|
-
if (recipes.has(fnName) || patterns.has(fnName))
|
|
359
|
-
return true;
|
|
360
|
-
if (fnName === cvaAlias || fnName === cssAlias || fnName === svaAlias || isRawFn(fnName) || isFactory(fnName))
|
|
361
|
-
return true;
|
|
362
|
-
return functions.has(fnName);
|
|
363
|
-
});
|
|
364
|
-
const measure = logger.time.debug(`Tokens extracted from ${filePath}`);
|
|
199
|
+
const measure = logger.time.debug(`Extract AST from ${filePath}`);
|
|
365
200
|
const extractResultByName = extract({
|
|
366
201
|
ast: sourceFile,
|
|
367
|
-
components:
|
|
368
|
-
matchTag: (prop) => !!matchTag(prop.tagName),
|
|
369
|
-
matchProp: (prop) => !!matchTagProp(prop.tagName, prop.propName)
|
|
202
|
+
components: jsx.isEnabled ? {
|
|
203
|
+
matchTag: (prop) => !!file.matchTag(prop.tagName),
|
|
204
|
+
matchProp: (prop) => !!file.matchTagProp(prop.tagName, prop.propName)
|
|
370
205
|
} : void 0,
|
|
371
206
|
functions: {
|
|
372
|
-
matchFn: (prop) => matchFn(prop.fnName),
|
|
207
|
+
matchFn: (prop) => file.matchFn(prop.fnName),
|
|
373
208
|
matchProp: () => true,
|
|
374
209
|
matchArg: (prop) => {
|
|
375
|
-
if (prop.fnName === jsxFactoryAlias && prop.index === 1 && Node.isIdentifier(prop.argNode))
|
|
210
|
+
if (prop.fnName === file.jsxFactoryAlias && prop.index === 1 && Node.isIdentifier(prop.argNode))
|
|
376
211
|
return false;
|
|
377
212
|
return true;
|
|
378
213
|
}
|
|
379
214
|
},
|
|
380
|
-
taggedTemplates: syntax === "template-literal" ? {
|
|
215
|
+
taggedTemplates: syntax === "template-literal" ? {
|
|
216
|
+
matchTaggedTemplate: (tag) => file.matchFn(tag.fnName)
|
|
217
|
+
} : void 0,
|
|
381
218
|
getEvaluateOptions: (node) => {
|
|
382
219
|
if (!Node.isCallExpression(node))
|
|
383
220
|
return evaluateOptions;
|
|
@@ -385,25 +222,26 @@ function createParser(context) {
|
|
|
385
222
|
if (!Node.isPropertyAccessExpression(propAccessExpr))
|
|
386
223
|
return evaluateOptions;
|
|
387
224
|
let name = propAccessExpr.getText();
|
|
388
|
-
if (!isRawFn(name)) {
|
|
225
|
+
if (!file.isRawFn(name)) {
|
|
389
226
|
return evaluateOptions;
|
|
390
227
|
}
|
|
391
228
|
name = name.replace(".raw", "");
|
|
392
229
|
return {
|
|
393
|
-
environment: Object.assign({}, defaultEnv, {
|
|
230
|
+
environment: Object.assign({}, defaultEnv, {
|
|
231
|
+
extra: {
|
|
232
|
+
[name]: { raw: (v) => v }
|
|
233
|
+
}
|
|
234
|
+
})
|
|
394
235
|
};
|
|
395
236
|
},
|
|
396
237
|
flags: { skipTraverseFiles: true }
|
|
397
238
|
});
|
|
398
239
|
measure();
|
|
399
240
|
extractResultByName.forEach((result, alias) => {
|
|
400
|
-
|
|
401
|
-
if (isRawFn(name))
|
|
402
|
-
name = name.replace(".raw", "");
|
|
403
|
-
name = imports.getName(name);
|
|
241
|
+
const name = file.getName(file.normalizeFnName(alias));
|
|
404
242
|
logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
405
243
|
if (result.kind === "function") {
|
|
406
|
-
match(name).when(css.match, (name2) => {
|
|
244
|
+
match(name).when(imports.matchers.css.match, (name2) => {
|
|
407
245
|
result.queryList.forEach((query) => {
|
|
408
246
|
if (query.kind === "call-expression") {
|
|
409
247
|
if (query.box.value.length > 1) {
|
|
@@ -418,7 +256,7 @@ function createParser(context) {
|
|
|
418
256
|
} else {
|
|
419
257
|
parserResult.set(name2, {
|
|
420
258
|
name: name2,
|
|
421
|
-
box: query.box.value[0] ?? fallback(query.box),
|
|
259
|
+
box: query.box.value[0] ?? box.fallback(query.box),
|
|
422
260
|
data: combineResult(unbox(query.box.value[0]))
|
|
423
261
|
});
|
|
424
262
|
}
|
|
@@ -426,38 +264,38 @@ function createParser(context) {
|
|
|
426
264
|
const obj = astish(query.box.value);
|
|
427
265
|
parserResult.set(name2, {
|
|
428
266
|
name: name2,
|
|
429
|
-
box: query.box ?? fallback(query.box),
|
|
267
|
+
box: query.box ?? box.fallback(query.box),
|
|
430
268
|
data: [obj]
|
|
431
269
|
});
|
|
432
270
|
}
|
|
433
271
|
});
|
|
434
|
-
}).when(isValidPattern, (name2) => {
|
|
272
|
+
}).when(file.isValidPattern, (name2) => {
|
|
435
273
|
result.queryList.forEach((query) => {
|
|
436
274
|
if (query.kind === "call-expression") {
|
|
437
275
|
parserResult.setPattern(name2, {
|
|
438
276
|
name: name2,
|
|
439
|
-
box: query.box.value[0] ?? fallback(query.box),
|
|
277
|
+
box: query.box.value[0] ?? box.fallback(query.box),
|
|
440
278
|
data: combineResult(unbox(query.box.value[0]))
|
|
441
279
|
});
|
|
442
280
|
}
|
|
443
281
|
});
|
|
444
|
-
}).when(isValidRecipe, (name2) => {
|
|
282
|
+
}).when(file.isValidRecipe, (name2) => {
|
|
445
283
|
result.queryList.forEach((query) => {
|
|
446
284
|
if (query.kind === "call-expression") {
|
|
447
285
|
parserResult.setRecipe(name2, {
|
|
448
286
|
name: name2,
|
|
449
|
-
box: query.box.value[0] ?? fallback(query.box),
|
|
287
|
+
box: query.box.value[0] ?? box.fallback(query.box),
|
|
450
288
|
data: combineResult(unbox(query.box.value[0]))
|
|
451
289
|
});
|
|
452
290
|
}
|
|
453
291
|
});
|
|
454
|
-
}).when(
|
|
292
|
+
}).when(jsx.isJsxFactory, () => {
|
|
455
293
|
result.queryList.forEach((query) => {
|
|
456
294
|
if (query.kind === "call-expression" && query.box.value[1]) {
|
|
457
295
|
const map = query.box.value[1];
|
|
458
|
-
const boxNode = box.isMap(map) ? map : fallback(query.box);
|
|
296
|
+
const boxNode = box.isMap(map) ? map : box.fallback(query.box);
|
|
459
297
|
const result2 = { name, box: boxNode, data: combineResult(unbox(boxNode)) };
|
|
460
|
-
if (box.
|
|
298
|
+
if (box.isRecipe(map)) {
|
|
461
299
|
parserResult.setCva(result2);
|
|
462
300
|
} else {
|
|
463
301
|
parserResult.set("css", result2);
|
|
@@ -467,7 +305,7 @@ function createParser(context) {
|
|
|
467
305
|
const maybeIdentifier = map.getNode();
|
|
468
306
|
if (Node.isIdentifier(maybeIdentifier)) {
|
|
469
307
|
const name2 = maybeIdentifier.getText();
|
|
470
|
-
const recipeName =
|
|
308
|
+
const recipeName = file.getName(name2);
|
|
471
309
|
parserResult.setRecipe(recipeName, {
|
|
472
310
|
type: "jsx-recipe",
|
|
473
311
|
name: recipeName,
|
|
@@ -480,18 +318,18 @@ function createParser(context) {
|
|
|
480
318
|
const obj = astish(query.box.value);
|
|
481
319
|
parserResult.set("css", {
|
|
482
320
|
name,
|
|
483
|
-
box: query.box ?? fallback(query.box),
|
|
321
|
+
box: query.box ?? box.fallback(query.box),
|
|
484
322
|
data: [obj]
|
|
485
323
|
});
|
|
486
324
|
}
|
|
487
325
|
});
|
|
488
|
-
}).when(
|
|
326
|
+
}).when(file.isJsxFactory, (name2) => {
|
|
489
327
|
result.queryList.forEach((query) => {
|
|
490
328
|
if (query.kind === "call-expression") {
|
|
491
329
|
const map = query.box.value[0];
|
|
492
|
-
const boxNode = box.isMap(map) ? map : fallback(query.box);
|
|
330
|
+
const boxNode = box.isMap(map) ? map : box.fallback(query.box);
|
|
493
331
|
const result2 = { name: name2, box: boxNode, data: combineResult(unbox(boxNode)) };
|
|
494
|
-
if (box.
|
|
332
|
+
if (box.isRecipe(map)) {
|
|
495
333
|
parserResult.setCva(result2);
|
|
496
334
|
} else {
|
|
497
335
|
parserResult.set("css", result2);
|
|
@@ -500,35 +338,42 @@ function createParser(context) {
|
|
|
500
338
|
const obj = astish(query.box.value);
|
|
501
339
|
parserResult.set("css", {
|
|
502
340
|
name: name2,
|
|
503
|
-
box: query.box ?? fallback(query.box),
|
|
341
|
+
box: query.box ?? box.fallback(query.box),
|
|
504
342
|
data: [obj]
|
|
505
343
|
});
|
|
506
344
|
}
|
|
507
345
|
});
|
|
508
346
|
}).otherwise(() => {
|
|
509
347
|
});
|
|
510
|
-
} else if (
|
|
348
|
+
} else if (jsx.isEnabled && result.kind === "component") {
|
|
511
349
|
result.queryList.forEach((query) => {
|
|
512
350
|
const data = combineResult(unbox(query.box));
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
351
|
+
switch (true) {
|
|
352
|
+
case file.isJsxFactory(name): {
|
|
353
|
+
parserResult.setJsx({ type: "jsx-factory", name, box: query.box, data });
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case jsx.isJsxTagPattern(name): {
|
|
357
|
+
parserResult.setPattern(name, { type: "jsx-pattern", name, box: query.box, data });
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case jsx.isJsxTagRecipe(name): {
|
|
361
|
+
const matchingRecipes = recipes.filter(name);
|
|
362
|
+
matchingRecipes.map((recipe) => {
|
|
363
|
+
parserResult.setRecipe(recipe.baseName, { type: "jsx-recipe", name, box: query.box, data });
|
|
364
|
+
});
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
default: {
|
|
368
|
+
parserResult.setJsx({ type: "jsx", name, box: query.box, data });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
525
371
|
});
|
|
526
372
|
}
|
|
527
373
|
});
|
|
528
374
|
return parserResult;
|
|
529
375
|
};
|
|
530
376
|
}
|
|
531
|
-
var isUpperCase = (value) => value[0] === value[0]?.toUpperCase();
|
|
532
377
|
|
|
533
378
|
// src/svelte-to-tsx.ts
|
|
534
379
|
import MagicString from "magic-string";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,19 +29,20 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@vue/compiler-sfc": "3.3.4",
|
|
32
|
-
"magic-string": "0.30.
|
|
32
|
+
"magic-string": "0.30.5",
|
|
33
33
|
"ts-morph": "19.0.0",
|
|
34
34
|
"ts-pattern": "5.0.5",
|
|
35
|
-
"@pandacss/config": "^0.
|
|
36
|
-
"@pandacss/
|
|
37
|
-
"@pandacss/
|
|
38
|
-
"@pandacss/
|
|
39
|
-
"@pandacss/
|
|
35
|
+
"@pandacss/config": "^0.26.1",
|
|
36
|
+
"@pandacss/core": "^0.26.1",
|
|
37
|
+
"@pandacss/extractor": "0.26.1",
|
|
38
|
+
"@pandacss/logger": "0.26.1",
|
|
39
|
+
"@pandacss/shared": "0.26.1",
|
|
40
|
+
"@pandacss/types": "0.26.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@vue/compiler-core": "3.3.4",
|
|
43
44
|
"hookable": "5.5.3",
|
|
44
|
-
"@pandacss/generator": "0.
|
|
45
|
+
"@pandacss/generator": "0.26.1"
|
|
45
46
|
},
|
|
46
47
|
"files": [
|
|
47
48
|
"dist"
|