@pandacss/parser 0.7.0 → 0.9.0
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 +13 -18
- package/dist/index.d.ts +13 -18
- package/dist/index.js +67 -31
- package/dist/index.mjs +67 -31
- package/package.json +11 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as ts_morph from 'ts-morph';
|
|
2
2
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
3
|
-
import { ResultItem,
|
|
3
|
+
import { ResultItem, ConfigTsOptions, Runtime, PandaHookable } from '@pandacss/types';
|
|
4
|
+
import { Generator } from '@pandacss/generator';
|
|
4
5
|
|
|
5
6
|
declare class ParserResult {
|
|
6
7
|
jsx: Set<ResultItem>;
|
|
@@ -33,36 +34,30 @@ declare class ParserResult {
|
|
|
33
34
|
}
|
|
34
35
|
declare const createParserResult: () => ParserResult;
|
|
35
36
|
|
|
36
|
-
type ParserPatternNode =
|
|
37
|
-
|
|
38
|
-
type: 'pattern';
|
|
39
|
-
props?: string[];
|
|
40
|
-
baseName: string;
|
|
41
|
-
};
|
|
42
|
-
type ParserRecipeNode = {
|
|
43
|
-
name: string;
|
|
44
|
-
type: 'recipe';
|
|
45
|
-
props: string[];
|
|
46
|
-
baseName: string;
|
|
47
|
-
jsx: RecipeConfig['jsx'];
|
|
48
|
-
};
|
|
37
|
+
type ParserPatternNode = Generator['patterns']['details'][number];
|
|
38
|
+
type ParserRecipeNode = Generator['recipes']['details'][number];
|
|
49
39
|
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
50
40
|
type ParserOptions = {
|
|
51
|
-
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
41
|
+
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string[]>;
|
|
52
42
|
jsx?: {
|
|
53
43
|
factory: string;
|
|
54
44
|
nodes: ParserNodeOptions[];
|
|
55
45
|
isStyleProp: (prop: string) => boolean;
|
|
56
46
|
};
|
|
57
|
-
getRecipesByJsxName: (jsxName: string) =>
|
|
47
|
+
getRecipesByJsxName: (jsxName: string) => ParserRecipeNode[];
|
|
48
|
+
getPatternsByJsxName: (jsxName: string) => ParserPatternNode[];
|
|
49
|
+
tsOptions?: ConfigTsOptions;
|
|
50
|
+
join: Runtime['path']['join'];
|
|
58
51
|
};
|
|
59
52
|
|
|
60
53
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
|
61
|
-
readFile:
|
|
54
|
+
readFile: Runtime['fs']['readFileSync'];
|
|
62
55
|
getFiles: () => string[];
|
|
63
56
|
hooks: PandaHookable;
|
|
64
57
|
parserOptions: ParserOptions;
|
|
58
|
+
tsOptions?: ConfigTsOptions;
|
|
65
59
|
};
|
|
60
|
+
|
|
66
61
|
declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
|
|
67
62
|
getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
|
|
68
63
|
removeSourceFile: (filePath: string) => void;
|
|
@@ -74,4 +69,4 @@ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...pro
|
|
|
74
69
|
};
|
|
75
70
|
type Project = ReturnType<typeof createProject>;
|
|
76
71
|
|
|
77
|
-
export { ParserResult, Project,
|
|
72
|
+
export { ParserResult, Project, createParserResult, createProject };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as ts_morph from 'ts-morph';
|
|
2
2
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
3
|
-
import { ResultItem,
|
|
3
|
+
import { ResultItem, ConfigTsOptions, Runtime, PandaHookable } from '@pandacss/types';
|
|
4
|
+
import { Generator } from '@pandacss/generator';
|
|
4
5
|
|
|
5
6
|
declare class ParserResult {
|
|
6
7
|
jsx: Set<ResultItem>;
|
|
@@ -33,36 +34,30 @@ declare class ParserResult {
|
|
|
33
34
|
}
|
|
34
35
|
declare const createParserResult: () => ParserResult;
|
|
35
36
|
|
|
36
|
-
type ParserPatternNode =
|
|
37
|
-
|
|
38
|
-
type: 'pattern';
|
|
39
|
-
props?: string[];
|
|
40
|
-
baseName: string;
|
|
41
|
-
};
|
|
42
|
-
type ParserRecipeNode = {
|
|
43
|
-
name: string;
|
|
44
|
-
type: 'recipe';
|
|
45
|
-
props: string[];
|
|
46
|
-
baseName: string;
|
|
47
|
-
jsx: RecipeConfig['jsx'];
|
|
48
|
-
};
|
|
37
|
+
type ParserPatternNode = Generator['patterns']['details'][number];
|
|
38
|
+
type ParserRecipeNode = Generator['recipes']['details'][number];
|
|
49
39
|
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
50
40
|
type ParserOptions = {
|
|
51
|
-
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
41
|
+
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string[]>;
|
|
52
42
|
jsx?: {
|
|
53
43
|
factory: string;
|
|
54
44
|
nodes: ParserNodeOptions[];
|
|
55
45
|
isStyleProp: (prop: string) => boolean;
|
|
56
46
|
};
|
|
57
|
-
getRecipesByJsxName: (jsxName: string) =>
|
|
47
|
+
getRecipesByJsxName: (jsxName: string) => ParserRecipeNode[];
|
|
48
|
+
getPatternsByJsxName: (jsxName: string) => ParserPatternNode[];
|
|
49
|
+
tsOptions?: ConfigTsOptions;
|
|
50
|
+
join: Runtime['path']['join'];
|
|
58
51
|
};
|
|
59
52
|
|
|
60
53
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
|
61
|
-
readFile:
|
|
54
|
+
readFile: Runtime['fs']['readFileSync'];
|
|
62
55
|
getFiles: () => string[];
|
|
63
56
|
hooks: PandaHookable;
|
|
64
57
|
parserOptions: ParserOptions;
|
|
58
|
+
tsOptions?: ConfigTsOptions;
|
|
65
59
|
};
|
|
60
|
+
|
|
66
61
|
declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
|
|
67
62
|
getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
|
|
68
63
|
removeSourceFile: (filePath: string) => void;
|
|
@@ -74,4 +69,4 @@ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...pro
|
|
|
74
69
|
};
|
|
75
70
|
type Project = ReturnType<typeof createProject>;
|
|
76
71
|
|
|
77
|
-
export { ParserResult, Project,
|
|
72
|
+
export { ParserResult, Project, createParserResult, createProject };
|
package/dist/index.js
CHANGED
|
@@ -67,9 +67,10 @@ function getImportDeclarations(file, options) {
|
|
|
67
67
|
specifiers.forEach((specifier) => {
|
|
68
68
|
const name = specifier.getNameNode().getText();
|
|
69
69
|
const alias = specifier.getAliasNode()?.getText() || name;
|
|
70
|
-
|
|
70
|
+
const importMapValue = match2({ name, alias, mod: source });
|
|
71
|
+
if (!importMapValue)
|
|
71
72
|
return;
|
|
72
|
-
result.push({ name, alias, mod: source });
|
|
73
|
+
result.push({ name, alias, mod: source, importMapValue });
|
|
73
74
|
});
|
|
74
75
|
});
|
|
75
76
|
return {
|
|
@@ -81,7 +82,7 @@ function getImportDeclarations(file, options) {
|
|
|
81
82
|
return result.find((o) => o.alias === id);
|
|
82
83
|
},
|
|
83
84
|
createMatch(mod) {
|
|
84
|
-
const mods = result.filter((o) => o.mod.includes(mod));
|
|
85
|
+
const mods = result.filter((o) => o.mod.includes(mod) || o.importMapValue === mod);
|
|
85
86
|
return (0, import_shared.memo)((id) => !!mods.find((mod2) => mod2.alias === id || mod2.name === id));
|
|
86
87
|
},
|
|
87
88
|
match(id) {
|
|
@@ -174,7 +175,9 @@ var ParserResult = class _ParserResult {
|
|
|
174
175
|
var createParserResult = () => new ParserResult();
|
|
175
176
|
|
|
176
177
|
// src/parser.ts
|
|
178
|
+
var import_ts_path = require("@pandacss/config/ts-path");
|
|
177
179
|
var isNodeRecipe = (node) => node.type === "recipe";
|
|
180
|
+
var isNodePattern = (node) => node.type === "pattern";
|
|
178
181
|
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
179
182
|
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
180
183
|
function createImportMatcher(mod, values) {
|
|
@@ -197,14 +200,15 @@ var fallback = (box2) => ({
|
|
|
197
200
|
});
|
|
198
201
|
var defaultEnv = { preset: "NONE" };
|
|
199
202
|
function createParser(options) {
|
|
200
|
-
const { jsx,
|
|
203
|
+
const { jsx, getRecipesByJsxName, getPatternsByJsxName, tsOptions, join } = options;
|
|
204
|
+
const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
|
|
201
205
|
const importRegex = [
|
|
202
206
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
203
207
|
createImportMatcher(importMap.recipe),
|
|
204
208
|
createImportMatcher(importMap.pattern)
|
|
205
209
|
];
|
|
206
210
|
if (jsx) {
|
|
207
|
-
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.
|
|
211
|
+
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.jsxName)]));
|
|
208
212
|
}
|
|
209
213
|
return function parse2(sourceFile) {
|
|
210
214
|
if (!sourceFile)
|
|
@@ -212,7 +216,23 @@ function createParser(options) {
|
|
|
212
216
|
const filePath = sourceFile.getFilePath();
|
|
213
217
|
const imports = getImportDeclarations(sourceFile, {
|
|
214
218
|
match(value) {
|
|
215
|
-
|
|
219
|
+
let found = false;
|
|
220
|
+
for (const { regex, mod } of importRegex) {
|
|
221
|
+
if (!regex.test(value.name))
|
|
222
|
+
continue;
|
|
223
|
+
if (value.mod.includes(mod)) {
|
|
224
|
+
found = true;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
if (tsOptions?.pathMappings) {
|
|
228
|
+
const filename = (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, value.mod);
|
|
229
|
+
if (filename?.includes(mod)) {
|
|
230
|
+
found = mod;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return found;
|
|
216
236
|
}
|
|
217
237
|
});
|
|
218
238
|
const collector = createParserResult();
|
|
@@ -226,8 +246,24 @@ function createParser(options) {
|
|
|
226
246
|
const isValidRecipe = imports.createMatch(importMap.recipe);
|
|
227
247
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
228
248
|
const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
|
|
229
|
-
const
|
|
230
|
-
|
|
249
|
+
const isRawFn = (fullName) => {
|
|
250
|
+
const name = fullName.split(".raw")[0] ?? "";
|
|
251
|
+
return name === "css" || isValidPattern(name) || isValidRecipe(name);
|
|
252
|
+
};
|
|
253
|
+
const patternPropertiesByName = /* @__PURE__ */ new Map();
|
|
254
|
+
const patternJsxLists = (jsx?.nodes ?? []).filter(isNodePattern).reduce(
|
|
255
|
+
(acc, pattern) => {
|
|
256
|
+
patternPropertiesByName.set(pattern.jsxName, new Set(pattern.props ?? []));
|
|
257
|
+
pattern.jsx?.forEach((jsx2) => {
|
|
258
|
+
if (typeof jsx2 === "string") {
|
|
259
|
+
acc.string.add(jsx2);
|
|
260
|
+
} else {
|
|
261
|
+
acc.regex.push(jsx2);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
return acc;
|
|
265
|
+
},
|
|
266
|
+
{ string: /* @__PURE__ */ new Set(), regex: [] }
|
|
231
267
|
);
|
|
232
268
|
const recipes = /* @__PURE__ */ new Set();
|
|
233
269
|
const patterns = /* @__PURE__ */ new Set();
|
|
@@ -246,7 +282,7 @@ function createParser(options) {
|
|
|
246
282
|
const recipePropertiesByName = /* @__PURE__ */ new Map();
|
|
247
283
|
const recipeJsxLists = (jsx?.nodes ?? []).filter(isNodeRecipe).reduce(
|
|
248
284
|
(acc, recipe) => {
|
|
249
|
-
recipePropertiesByName.set(recipe.
|
|
285
|
+
recipePropertiesByName.set(recipe.jsxName, new Set(recipe.props ?? []));
|
|
250
286
|
recipe.jsx?.forEach((jsx2) => {
|
|
251
287
|
if (typeof jsx2 === "string") {
|
|
252
288
|
acc.string.add(jsx2);
|
|
@@ -262,7 +298,7 @@ function createParser(options) {
|
|
|
262
298
|
const cssAlias = imports.getAlias("css");
|
|
263
299
|
if (options.jsx) {
|
|
264
300
|
options.jsx.nodes.forEach((node) => {
|
|
265
|
-
const alias = imports.getAlias(node.
|
|
301
|
+
const alias = imports.getAlias(node.jsxName);
|
|
266
302
|
node.props?.forEach((prop) => propertiesMap.set(prop, true));
|
|
267
303
|
functions.set(node.baseName, propertiesMap);
|
|
268
304
|
functions.set(alias, propertiesMap);
|
|
@@ -272,24 +308,31 @@ function createParser(options) {
|
|
|
272
308
|
const isJsxTagRecipe = (0, import_shared2.memo)(
|
|
273
309
|
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
274
310
|
);
|
|
311
|
+
const isJsxTagPattern = (0, import_shared2.memo)(
|
|
312
|
+
(tagName) => patternJsxLists.string.has(tagName) || patternJsxLists.regex.some((regex) => regex.test(tagName))
|
|
313
|
+
);
|
|
275
314
|
const matchTag = (0, import_shared2.memo)((tagName) => {
|
|
276
315
|
if (!tagName)
|
|
277
316
|
return false;
|
|
278
|
-
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName);
|
|
317
|
+
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName) || isJsxTagPattern(tagName);
|
|
279
318
|
});
|
|
280
319
|
const matchTagProp = (0, import_shared2.memo)((tagName, propName) => {
|
|
281
320
|
if (Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName))
|
|
282
321
|
return true;
|
|
283
322
|
if (isJsxTagRecipe(tagName)) {
|
|
284
323
|
const recipeList = getRecipesByJsxName(tagName);
|
|
285
|
-
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.
|
|
324
|
+
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.baseName)?.has(propName));
|
|
325
|
+
}
|
|
326
|
+
if (isJsxTagPattern(tagName)) {
|
|
327
|
+
const patternList = getPatternsByJsxName(tagName);
|
|
328
|
+
return patternList.some((pattern) => patternPropertiesByName.get(pattern.baseName)?.has(propName));
|
|
286
329
|
}
|
|
287
330
|
return false;
|
|
288
331
|
});
|
|
289
332
|
const matchFn = (0, import_shared2.memo)((fnName) => {
|
|
290
333
|
if (recipes.has(fnName) || patterns.has(fnName))
|
|
291
334
|
return true;
|
|
292
|
-
if (fnName === cvaAlias || fnName === cssAlias || isFactory(fnName))
|
|
335
|
+
if (fnName === cvaAlias || fnName === cssAlias || isRawFn(fnName) || isFactory(fnName))
|
|
293
336
|
return true;
|
|
294
337
|
return functions.has(fnName);
|
|
295
338
|
});
|
|
@@ -317,7 +360,9 @@ function createParser(options) {
|
|
|
317
360
|
});
|
|
318
361
|
measure();
|
|
319
362
|
extractResultByName.forEach((result, alias) => {
|
|
320
|
-
|
|
363
|
+
let name = imports.getName(alias);
|
|
364
|
+
if (isRawFn(name))
|
|
365
|
+
name = name.replace(".raw", "");
|
|
321
366
|
import_logger.logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
322
367
|
if (result.kind === "function") {
|
|
323
368
|
(0, import_ts_pattern.match)(name).when(css.match, (name2) => {
|
|
@@ -361,11 +406,8 @@ function createParser(options) {
|
|
|
361
406
|
result.queryList.forEach((query) => {
|
|
362
407
|
if (query.kind === "call-expression" && query.box.value[1]) {
|
|
363
408
|
const map = query.box.value[1];
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
box: map ?? fallback(query.box),
|
|
367
|
-
data: combineResult((0, import_extractor.unbox)(map))
|
|
368
|
-
};
|
|
409
|
+
const boxNode = import_extractor.box.isMap(map) ? map : fallback(query.box);
|
|
410
|
+
const result2 = { name, box: boxNode, data: combineResult((0, import_extractor.unbox)(boxNode)) };
|
|
369
411
|
if (import_extractor.box.isMap(map) && isCva(map.value)) {
|
|
370
412
|
collector.setCva(result2);
|
|
371
413
|
} else {
|
|
@@ -384,11 +426,8 @@ function createParser(options) {
|
|
|
384
426
|
result.queryList.forEach((query) => {
|
|
385
427
|
if (query.kind === "call-expression") {
|
|
386
428
|
const map = query.box.value[0];
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
box: map ?? fallback(query.box),
|
|
390
|
-
data: combineResult((0, import_extractor.unbox)(map))
|
|
391
|
-
};
|
|
429
|
+
const boxNode = import_extractor.box.isMap(map) ? map : fallback(query.box);
|
|
430
|
+
const result2 = { name: name2, box: boxNode, data: combineResult((0, import_extractor.unbox)(boxNode)) };
|
|
392
431
|
if (import_extractor.box.isMap(map) && isCva(map.value)) {
|
|
393
432
|
collector.setCva(result2);
|
|
394
433
|
} else {
|
|
@@ -410,15 +449,12 @@ function createParser(options) {
|
|
|
410
449
|
const data = combineResult((0, import_extractor.unbox)(query.box));
|
|
411
450
|
(0, import_ts_pattern.match)(name).when(isFactory, (name2) => {
|
|
412
451
|
collector.setJsx({ name: name2, box: query.box, type: "jsx-factory", data });
|
|
413
|
-
}).when(
|
|
414
|
-
(name2
|
|
415
|
-
|
|
416
|
-
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
417
|
-
}
|
|
418
|
-
).when(isJsxTagRecipe, (name2) => {
|
|
452
|
+
}).when(isJsxTagPattern, (name2) => {
|
|
453
|
+
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
454
|
+
}).when(isJsxTagRecipe, (name2) => {
|
|
419
455
|
const recipeList = getRecipesByJsxName(name2);
|
|
420
456
|
recipeList.map((recipe) => {
|
|
421
|
-
collector.setRecipe(recipe.
|
|
457
|
+
collector.setRecipe(recipe.baseName, { type: "jsx-recipe", name: name2, box: query.box, data });
|
|
422
458
|
});
|
|
423
459
|
}).otherwise(() => {
|
|
424
460
|
collector.setJsx({ name, box: query.box, type: "jsx", data });
|
package/dist/index.mjs
CHANGED
|
@@ -29,9 +29,10 @@ function getImportDeclarations(file, options) {
|
|
|
29
29
|
specifiers.forEach((specifier) => {
|
|
30
30
|
const name = specifier.getNameNode().getText();
|
|
31
31
|
const alias = specifier.getAliasNode()?.getText() || name;
|
|
32
|
-
|
|
32
|
+
const importMapValue = match2({ name, alias, mod: source });
|
|
33
|
+
if (!importMapValue)
|
|
33
34
|
return;
|
|
34
|
-
result.push({ name, alias, mod: source });
|
|
35
|
+
result.push({ name, alias, mod: source, importMapValue });
|
|
35
36
|
});
|
|
36
37
|
});
|
|
37
38
|
return {
|
|
@@ -43,7 +44,7 @@ function getImportDeclarations(file, options) {
|
|
|
43
44
|
return result.find((o) => o.alias === id);
|
|
44
45
|
},
|
|
45
46
|
createMatch(mod) {
|
|
46
|
-
const mods = result.filter((o) => o.mod.includes(mod));
|
|
47
|
+
const mods = result.filter((o) => o.mod.includes(mod) || o.importMapValue === mod);
|
|
47
48
|
return memo((id) => !!mods.find((mod2) => mod2.alias === id || mod2.name === id));
|
|
48
49
|
},
|
|
49
50
|
match(id) {
|
|
@@ -136,7 +137,9 @@ var ParserResult = class _ParserResult {
|
|
|
136
137
|
var createParserResult = () => new ParserResult();
|
|
137
138
|
|
|
138
139
|
// src/parser.ts
|
|
140
|
+
import { resolveTsPathPattern } from "@pandacss/config/ts-path";
|
|
139
141
|
var isNodeRecipe = (node) => node.type === "recipe";
|
|
142
|
+
var isNodePattern = (node) => node.type === "pattern";
|
|
140
143
|
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
141
144
|
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
142
145
|
function createImportMatcher(mod, values) {
|
|
@@ -159,14 +162,15 @@ var fallback = (box2) => ({
|
|
|
159
162
|
});
|
|
160
163
|
var defaultEnv = { preset: "NONE" };
|
|
161
164
|
function createParser(options) {
|
|
162
|
-
const { jsx,
|
|
165
|
+
const { jsx, getRecipesByJsxName, getPatternsByJsxName, tsOptions, join } = options;
|
|
166
|
+
const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
|
|
163
167
|
const importRegex = [
|
|
164
168
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
165
169
|
createImportMatcher(importMap.recipe),
|
|
166
170
|
createImportMatcher(importMap.pattern)
|
|
167
171
|
];
|
|
168
172
|
if (jsx) {
|
|
169
|
-
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.
|
|
173
|
+
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.jsxName)]));
|
|
170
174
|
}
|
|
171
175
|
return function parse2(sourceFile) {
|
|
172
176
|
if (!sourceFile)
|
|
@@ -174,7 +178,23 @@ function createParser(options) {
|
|
|
174
178
|
const filePath = sourceFile.getFilePath();
|
|
175
179
|
const imports = getImportDeclarations(sourceFile, {
|
|
176
180
|
match(value) {
|
|
177
|
-
|
|
181
|
+
let found = false;
|
|
182
|
+
for (const { regex, mod } of importRegex) {
|
|
183
|
+
if (!regex.test(value.name))
|
|
184
|
+
continue;
|
|
185
|
+
if (value.mod.includes(mod)) {
|
|
186
|
+
found = true;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
if (tsOptions?.pathMappings) {
|
|
190
|
+
const filename = resolveTsPathPattern(tsOptions.pathMappings, value.mod);
|
|
191
|
+
if (filename?.includes(mod)) {
|
|
192
|
+
found = mod;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return found;
|
|
178
198
|
}
|
|
179
199
|
});
|
|
180
200
|
const collector = createParserResult();
|
|
@@ -188,8 +208,24 @@ function createParser(options) {
|
|
|
188
208
|
const isValidRecipe = imports.createMatch(importMap.recipe);
|
|
189
209
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
190
210
|
const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
|
|
191
|
-
const
|
|
192
|
-
|
|
211
|
+
const isRawFn = (fullName) => {
|
|
212
|
+
const name = fullName.split(".raw")[0] ?? "";
|
|
213
|
+
return name === "css" || isValidPattern(name) || isValidRecipe(name);
|
|
214
|
+
};
|
|
215
|
+
const patternPropertiesByName = /* @__PURE__ */ new Map();
|
|
216
|
+
const patternJsxLists = (jsx?.nodes ?? []).filter(isNodePattern).reduce(
|
|
217
|
+
(acc, pattern) => {
|
|
218
|
+
patternPropertiesByName.set(pattern.jsxName, new Set(pattern.props ?? []));
|
|
219
|
+
pattern.jsx?.forEach((jsx2) => {
|
|
220
|
+
if (typeof jsx2 === "string") {
|
|
221
|
+
acc.string.add(jsx2);
|
|
222
|
+
} else {
|
|
223
|
+
acc.regex.push(jsx2);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return acc;
|
|
227
|
+
},
|
|
228
|
+
{ string: /* @__PURE__ */ new Set(), regex: [] }
|
|
193
229
|
);
|
|
194
230
|
const recipes = /* @__PURE__ */ new Set();
|
|
195
231
|
const patterns = /* @__PURE__ */ new Set();
|
|
@@ -208,7 +244,7 @@ function createParser(options) {
|
|
|
208
244
|
const recipePropertiesByName = /* @__PURE__ */ new Map();
|
|
209
245
|
const recipeJsxLists = (jsx?.nodes ?? []).filter(isNodeRecipe).reduce(
|
|
210
246
|
(acc, recipe) => {
|
|
211
|
-
recipePropertiesByName.set(recipe.
|
|
247
|
+
recipePropertiesByName.set(recipe.jsxName, new Set(recipe.props ?? []));
|
|
212
248
|
recipe.jsx?.forEach((jsx2) => {
|
|
213
249
|
if (typeof jsx2 === "string") {
|
|
214
250
|
acc.string.add(jsx2);
|
|
@@ -224,7 +260,7 @@ function createParser(options) {
|
|
|
224
260
|
const cssAlias = imports.getAlias("css");
|
|
225
261
|
if (options.jsx) {
|
|
226
262
|
options.jsx.nodes.forEach((node) => {
|
|
227
|
-
const alias = imports.getAlias(node.
|
|
263
|
+
const alias = imports.getAlias(node.jsxName);
|
|
228
264
|
node.props?.forEach((prop) => propertiesMap.set(prop, true));
|
|
229
265
|
functions.set(node.baseName, propertiesMap);
|
|
230
266
|
functions.set(alias, propertiesMap);
|
|
@@ -234,24 +270,31 @@ function createParser(options) {
|
|
|
234
270
|
const isJsxTagRecipe = memo2(
|
|
235
271
|
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
236
272
|
);
|
|
273
|
+
const isJsxTagPattern = memo2(
|
|
274
|
+
(tagName) => patternJsxLists.string.has(tagName) || patternJsxLists.regex.some((regex) => regex.test(tagName))
|
|
275
|
+
);
|
|
237
276
|
const matchTag = memo2((tagName) => {
|
|
238
277
|
if (!tagName)
|
|
239
278
|
return false;
|
|
240
|
-
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName);
|
|
279
|
+
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName) || isJsxTagPattern(tagName);
|
|
241
280
|
});
|
|
242
281
|
const matchTagProp = memo2((tagName, propName) => {
|
|
243
282
|
if (Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName))
|
|
244
283
|
return true;
|
|
245
284
|
if (isJsxTagRecipe(tagName)) {
|
|
246
285
|
const recipeList = getRecipesByJsxName(tagName);
|
|
247
|
-
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.
|
|
286
|
+
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.baseName)?.has(propName));
|
|
287
|
+
}
|
|
288
|
+
if (isJsxTagPattern(tagName)) {
|
|
289
|
+
const patternList = getPatternsByJsxName(tagName);
|
|
290
|
+
return patternList.some((pattern) => patternPropertiesByName.get(pattern.baseName)?.has(propName));
|
|
248
291
|
}
|
|
249
292
|
return false;
|
|
250
293
|
});
|
|
251
294
|
const matchFn = memo2((fnName) => {
|
|
252
295
|
if (recipes.has(fnName) || patterns.has(fnName))
|
|
253
296
|
return true;
|
|
254
|
-
if (fnName === cvaAlias || fnName === cssAlias || isFactory(fnName))
|
|
297
|
+
if (fnName === cvaAlias || fnName === cssAlias || isRawFn(fnName) || isFactory(fnName))
|
|
255
298
|
return true;
|
|
256
299
|
return functions.has(fnName);
|
|
257
300
|
});
|
|
@@ -279,7 +322,9 @@ function createParser(options) {
|
|
|
279
322
|
});
|
|
280
323
|
measure();
|
|
281
324
|
extractResultByName.forEach((result, alias) => {
|
|
282
|
-
|
|
325
|
+
let name = imports.getName(alias);
|
|
326
|
+
if (isRawFn(name))
|
|
327
|
+
name = name.replace(".raw", "");
|
|
283
328
|
logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
284
329
|
if (result.kind === "function") {
|
|
285
330
|
match(name).when(css.match, (name2) => {
|
|
@@ -323,11 +368,8 @@ function createParser(options) {
|
|
|
323
368
|
result.queryList.forEach((query) => {
|
|
324
369
|
if (query.kind === "call-expression" && query.box.value[1]) {
|
|
325
370
|
const map = query.box.value[1];
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
box: map ?? fallback(query.box),
|
|
329
|
-
data: combineResult(unbox(map))
|
|
330
|
-
};
|
|
371
|
+
const boxNode = box.isMap(map) ? map : fallback(query.box);
|
|
372
|
+
const result2 = { name, box: boxNode, data: combineResult(unbox(boxNode)) };
|
|
331
373
|
if (box.isMap(map) && isCva(map.value)) {
|
|
332
374
|
collector.setCva(result2);
|
|
333
375
|
} else {
|
|
@@ -346,11 +388,8 @@ function createParser(options) {
|
|
|
346
388
|
result.queryList.forEach((query) => {
|
|
347
389
|
if (query.kind === "call-expression") {
|
|
348
390
|
const map = query.box.value[0];
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
box: map ?? fallback(query.box),
|
|
352
|
-
data: combineResult(unbox(map))
|
|
353
|
-
};
|
|
391
|
+
const boxNode = box.isMap(map) ? map : fallback(query.box);
|
|
392
|
+
const result2 = { name: name2, box: boxNode, data: combineResult(unbox(boxNode)) };
|
|
354
393
|
if (box.isMap(map) && isCva(map.value)) {
|
|
355
394
|
collector.setCva(result2);
|
|
356
395
|
} else {
|
|
@@ -372,15 +411,12 @@ function createParser(options) {
|
|
|
372
411
|
const data = combineResult(unbox(query.box));
|
|
373
412
|
match(name).when(isFactory, (name2) => {
|
|
374
413
|
collector.setJsx({ name: name2, box: query.box, type: "jsx-factory", data });
|
|
375
|
-
}).when(
|
|
376
|
-
(name2
|
|
377
|
-
|
|
378
|
-
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
379
|
-
}
|
|
380
|
-
).when(isJsxTagRecipe, (name2) => {
|
|
414
|
+
}).when(isJsxTagPattern, (name2) => {
|
|
415
|
+
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
416
|
+
}).when(isJsxTagRecipe, (name2) => {
|
|
381
417
|
const recipeList = getRecipesByJsxName(name2);
|
|
382
418
|
recipeList.map((recipe) => {
|
|
383
|
-
collector.setRecipe(recipe.
|
|
419
|
+
collector.setRecipe(recipe.baseName, { type: "jsx-recipe", name: name2, box: query.box, data });
|
|
384
420
|
});
|
|
385
421
|
}).otherwise(() => {
|
|
386
422
|
collector.setJsx({ name, box: query.box, type: "jsx", data });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,18 +14,19 @@
|
|
|
14
14
|
"@vue/compiler-sfc": "^3.3.4",
|
|
15
15
|
"lil-fp": "1.4.5",
|
|
16
16
|
"magic-string": "^0.30.1",
|
|
17
|
-
"ts-morph": "
|
|
18
|
-
"ts-pattern": "5.0.
|
|
19
|
-
"@pandacss/
|
|
20
|
-
"@pandacss/
|
|
21
|
-
"@pandacss/
|
|
22
|
-
"@pandacss/
|
|
23
|
-
"@pandacss/
|
|
17
|
+
"ts-morph": "19.0.0",
|
|
18
|
+
"ts-pattern": "5.0.4",
|
|
19
|
+
"@pandacss/config": "^0.9.0",
|
|
20
|
+
"@pandacss/extractor": "0.9.0",
|
|
21
|
+
"@pandacss/is-valid-prop": "0.9.0",
|
|
22
|
+
"@pandacss/logger": "0.9.0",
|
|
23
|
+
"@pandacss/shared": "0.9.0",
|
|
24
|
+
"@pandacss/types": "0.9.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"hookable": "5.5.3",
|
|
27
|
-
"@pandacss/fixture": "0.
|
|
28
|
-
"@pandacss/generator": "0.
|
|
28
|
+
"@pandacss/fixture": "0.9.0",
|
|
29
|
+
"@pandacss/generator": "0.9.0"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|