@pandacss/parser 0.7.0 → 0.8.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 +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +36 -17
- package/dist/index.mjs +36 -17
- package/package.json +11 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ts_morph from 'ts-morph';
|
|
2
2
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
3
|
-
import { ResultItem, RecipeConfig, PandaHookable } from '@pandacss/types';
|
|
3
|
+
import { ResultItem, RecipeConfig, ConfigTsOptions, Runtime, PandaHookable } from '@pandacss/types';
|
|
4
4
|
|
|
5
5
|
declare class ParserResult {
|
|
6
6
|
jsx: Set<ResultItem>;
|
|
@@ -48,21 +48,25 @@ type ParserRecipeNode = {
|
|
|
48
48
|
};
|
|
49
49
|
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
50
50
|
type ParserOptions = {
|
|
51
|
-
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
51
|
+
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string[]>;
|
|
52
52
|
jsx?: {
|
|
53
53
|
factory: string;
|
|
54
54
|
nodes: ParserNodeOptions[];
|
|
55
55
|
isStyleProp: (prop: string) => boolean;
|
|
56
56
|
};
|
|
57
57
|
getRecipesByJsxName: (jsxName: string) => RecipeConfig[];
|
|
58
|
+
tsOptions?: ConfigTsOptions;
|
|
59
|
+
join: Runtime['path']['join'];
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
|
61
|
-
readFile:
|
|
63
|
+
readFile: Runtime['fs']['readFileSync'];
|
|
62
64
|
getFiles: () => string[];
|
|
63
65
|
hooks: PandaHookable;
|
|
64
66
|
parserOptions: ParserOptions;
|
|
67
|
+
tsOptions?: ConfigTsOptions;
|
|
65
68
|
};
|
|
69
|
+
|
|
66
70
|
declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
|
|
67
71
|
getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
|
|
68
72
|
removeSourceFile: (filePath: string) => void;
|
|
@@ -74,4 +78,4 @@ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...pro
|
|
|
74
78
|
};
|
|
75
79
|
type Project = ReturnType<typeof createProject>;
|
|
76
80
|
|
|
77
|
-
export { ParserResult, Project,
|
|
81
|
+
export { ParserResult, Project, createParserResult, createProject };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ts_morph from 'ts-morph';
|
|
2
2
|
import { ProjectOptions as ProjectOptions$1 } from 'ts-morph';
|
|
3
|
-
import { ResultItem, RecipeConfig, PandaHookable } from '@pandacss/types';
|
|
3
|
+
import { ResultItem, RecipeConfig, ConfigTsOptions, Runtime, PandaHookable } from '@pandacss/types';
|
|
4
4
|
|
|
5
5
|
declare class ParserResult {
|
|
6
6
|
jsx: Set<ResultItem>;
|
|
@@ -48,21 +48,25 @@ type ParserRecipeNode = {
|
|
|
48
48
|
};
|
|
49
49
|
type ParserNodeOptions = ParserPatternNode | ParserRecipeNode;
|
|
50
50
|
type ParserOptions = {
|
|
51
|
-
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string>;
|
|
51
|
+
importMap: Record<'css' | 'recipe' | 'pattern' | 'jsx', string[]>;
|
|
52
52
|
jsx?: {
|
|
53
53
|
factory: string;
|
|
54
54
|
nodes: ParserNodeOptions[];
|
|
55
55
|
isStyleProp: (prop: string) => boolean;
|
|
56
56
|
};
|
|
57
57
|
getRecipesByJsxName: (jsxName: string) => RecipeConfig[];
|
|
58
|
+
tsOptions?: ConfigTsOptions;
|
|
59
|
+
join: Runtime['path']['join'];
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
|
61
|
-
readFile:
|
|
63
|
+
readFile: Runtime['fs']['readFileSync'];
|
|
62
64
|
getFiles: () => string[];
|
|
63
65
|
hooks: PandaHookable;
|
|
64
66
|
parserOptions: ParserOptions;
|
|
67
|
+
tsOptions?: ConfigTsOptions;
|
|
65
68
|
};
|
|
69
|
+
|
|
66
70
|
declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...projectOptions }: ProjectOptions) => {
|
|
67
71
|
getSourceFile: (filePath: string) => ts_morph.SourceFile | undefined;
|
|
68
72
|
removeSourceFile: (filePath: string) => void;
|
|
@@ -74,4 +78,4 @@ declare const createProject: ({ getFiles, readFile, parserOptions, hooks, ...pro
|
|
|
74
78
|
};
|
|
75
79
|
type Project = ReturnType<typeof createProject>;
|
|
76
80
|
|
|
77
|
-
export { ParserResult, Project,
|
|
81
|
+
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,6 +175,7 @@ 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";
|
|
178
180
|
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
179
181
|
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
@@ -197,7 +199,8 @@ var fallback = (box2) => ({
|
|
|
197
199
|
});
|
|
198
200
|
var defaultEnv = { preset: "NONE" };
|
|
199
201
|
function createParser(options) {
|
|
200
|
-
const { jsx,
|
|
202
|
+
const { jsx, getRecipesByJsxName, tsOptions, join } = options;
|
|
203
|
+
const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
|
|
201
204
|
const importRegex = [
|
|
202
205
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
203
206
|
createImportMatcher(importMap.recipe),
|
|
@@ -212,7 +215,23 @@ function createParser(options) {
|
|
|
212
215
|
const filePath = sourceFile.getFilePath();
|
|
213
216
|
const imports = getImportDeclarations(sourceFile, {
|
|
214
217
|
match(value) {
|
|
215
|
-
|
|
218
|
+
let found = false;
|
|
219
|
+
for (const { regex, mod } of importRegex) {
|
|
220
|
+
if (!regex.test(value.name))
|
|
221
|
+
continue;
|
|
222
|
+
if (value.mod.includes(mod)) {
|
|
223
|
+
found = true;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (tsOptions?.pathMappings) {
|
|
227
|
+
const filename = (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, value.mod);
|
|
228
|
+
if (filename?.includes(mod)) {
|
|
229
|
+
found = mod;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return found;
|
|
216
235
|
}
|
|
217
236
|
});
|
|
218
237
|
const collector = createParserResult();
|
|
@@ -226,6 +245,10 @@ function createParser(options) {
|
|
|
226
245
|
const isValidRecipe = imports.createMatch(importMap.recipe);
|
|
227
246
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
228
247
|
const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
|
|
248
|
+
const isRawFn = (fullName) => {
|
|
249
|
+
const name = fullName.split(".raw")[0] ?? "";
|
|
250
|
+
return name === "css" || isValidPattern(name) || isValidRecipe(name);
|
|
251
|
+
};
|
|
229
252
|
const jsxPatternNodes = new RegExp(
|
|
230
253
|
`^(${jsx?.nodes.filter((node) => node.type === "pattern").map((node) => node.name).join("|")})$`
|
|
231
254
|
);
|
|
@@ -289,7 +312,7 @@ function createParser(options) {
|
|
|
289
312
|
const matchFn = (0, import_shared2.memo)((fnName) => {
|
|
290
313
|
if (recipes.has(fnName) || patterns.has(fnName))
|
|
291
314
|
return true;
|
|
292
|
-
if (fnName === cvaAlias || fnName === cssAlias || isFactory(fnName))
|
|
315
|
+
if (fnName === cvaAlias || fnName === cssAlias || isRawFn(fnName) || isFactory(fnName))
|
|
293
316
|
return true;
|
|
294
317
|
return functions.has(fnName);
|
|
295
318
|
});
|
|
@@ -317,7 +340,9 @@ function createParser(options) {
|
|
|
317
340
|
});
|
|
318
341
|
measure();
|
|
319
342
|
extractResultByName.forEach((result, alias) => {
|
|
320
|
-
|
|
343
|
+
let name = imports.getName(alias);
|
|
344
|
+
if (isRawFn(name))
|
|
345
|
+
name = name.replace(".raw", "");
|
|
321
346
|
import_logger.logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
322
347
|
if (result.kind === "function") {
|
|
323
348
|
(0, import_ts_pattern.match)(name).when(css.match, (name2) => {
|
|
@@ -361,11 +386,8 @@ function createParser(options) {
|
|
|
361
386
|
result.queryList.forEach((query) => {
|
|
362
387
|
if (query.kind === "call-expression" && query.box.value[1]) {
|
|
363
388
|
const map = query.box.value[1];
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
box: map ?? fallback(query.box),
|
|
367
|
-
data: combineResult((0, import_extractor.unbox)(map))
|
|
368
|
-
};
|
|
389
|
+
const boxNode = import_extractor.box.isMap(map) ? map : fallback(query.box);
|
|
390
|
+
const result2 = { name, box: boxNode, data: combineResult((0, import_extractor.unbox)(boxNode)) };
|
|
369
391
|
if (import_extractor.box.isMap(map) && isCva(map.value)) {
|
|
370
392
|
collector.setCva(result2);
|
|
371
393
|
} else {
|
|
@@ -384,11 +406,8 @@ function createParser(options) {
|
|
|
384
406
|
result.queryList.forEach((query) => {
|
|
385
407
|
if (query.kind === "call-expression") {
|
|
386
408
|
const map = query.box.value[0];
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
box: map ?? fallback(query.box),
|
|
390
|
-
data: combineResult((0, import_extractor.unbox)(map))
|
|
391
|
-
};
|
|
409
|
+
const boxNode = import_extractor.box.isMap(map) ? map : fallback(query.box);
|
|
410
|
+
const result2 = { name: name2, box: boxNode, data: combineResult((0, import_extractor.unbox)(boxNode)) };
|
|
392
411
|
if (import_extractor.box.isMap(map) && isCva(map.value)) {
|
|
393
412
|
collector.setCva(result2);
|
|
394
413
|
} else {
|
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,6 +137,7 @@ 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";
|
|
140
142
|
var cvaProps = ["compoundVariants", "defaultVariants", "variants", "base"];
|
|
141
143
|
var isCva = (map) => cvaProps.some((prop) => map.has(prop));
|
|
@@ -159,7 +161,8 @@ var fallback = (box2) => ({
|
|
|
159
161
|
});
|
|
160
162
|
var defaultEnv = { preset: "NONE" };
|
|
161
163
|
function createParser(options) {
|
|
162
|
-
const { jsx,
|
|
164
|
+
const { jsx, getRecipesByJsxName, tsOptions, join } = options;
|
|
165
|
+
const importMap = Object.fromEntries(Object.entries(options.importMap).map(([key, value]) => [key, join(...value)]));
|
|
163
166
|
const importRegex = [
|
|
164
167
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
165
168
|
createImportMatcher(importMap.recipe),
|
|
@@ -174,7 +177,23 @@ function createParser(options) {
|
|
|
174
177
|
const filePath = sourceFile.getFilePath();
|
|
175
178
|
const imports = getImportDeclarations(sourceFile, {
|
|
176
179
|
match(value) {
|
|
177
|
-
|
|
180
|
+
let found = false;
|
|
181
|
+
for (const { regex, mod } of importRegex) {
|
|
182
|
+
if (!regex.test(value.name))
|
|
183
|
+
continue;
|
|
184
|
+
if (value.mod.includes(mod)) {
|
|
185
|
+
found = true;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (tsOptions?.pathMappings) {
|
|
189
|
+
const filename = resolveTsPathPattern(tsOptions.pathMappings, value.mod);
|
|
190
|
+
if (filename?.includes(mod)) {
|
|
191
|
+
found = mod;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return found;
|
|
178
197
|
}
|
|
179
198
|
});
|
|
180
199
|
const collector = createParserResult();
|
|
@@ -188,6 +207,10 @@ function createParser(options) {
|
|
|
188
207
|
const isValidRecipe = imports.createMatch(importMap.recipe);
|
|
189
208
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
190
209
|
const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
|
|
210
|
+
const isRawFn = (fullName) => {
|
|
211
|
+
const name = fullName.split(".raw")[0] ?? "";
|
|
212
|
+
return name === "css" || isValidPattern(name) || isValidRecipe(name);
|
|
213
|
+
};
|
|
191
214
|
const jsxPatternNodes = new RegExp(
|
|
192
215
|
`^(${jsx?.nodes.filter((node) => node.type === "pattern").map((node) => node.name).join("|")})$`
|
|
193
216
|
);
|
|
@@ -251,7 +274,7 @@ function createParser(options) {
|
|
|
251
274
|
const matchFn = memo2((fnName) => {
|
|
252
275
|
if (recipes.has(fnName) || patterns.has(fnName))
|
|
253
276
|
return true;
|
|
254
|
-
if (fnName === cvaAlias || fnName === cssAlias || isFactory(fnName))
|
|
277
|
+
if (fnName === cvaAlias || fnName === cssAlias || isRawFn(fnName) || isFactory(fnName))
|
|
255
278
|
return true;
|
|
256
279
|
return functions.has(fnName);
|
|
257
280
|
});
|
|
@@ -279,7 +302,9 @@ function createParser(options) {
|
|
|
279
302
|
});
|
|
280
303
|
measure();
|
|
281
304
|
extractResultByName.forEach((result, alias) => {
|
|
282
|
-
|
|
305
|
+
let name = imports.getName(alias);
|
|
306
|
+
if (isRawFn(name))
|
|
307
|
+
name = name.replace(".raw", "");
|
|
283
308
|
logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
284
309
|
if (result.kind === "function") {
|
|
285
310
|
match(name).when(css.match, (name2) => {
|
|
@@ -323,11 +348,8 @@ function createParser(options) {
|
|
|
323
348
|
result.queryList.forEach((query) => {
|
|
324
349
|
if (query.kind === "call-expression" && query.box.value[1]) {
|
|
325
350
|
const map = query.box.value[1];
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
box: map ?? fallback(query.box),
|
|
329
|
-
data: combineResult(unbox(map))
|
|
330
|
-
};
|
|
351
|
+
const boxNode = box.isMap(map) ? map : fallback(query.box);
|
|
352
|
+
const result2 = { name, box: boxNode, data: combineResult(unbox(boxNode)) };
|
|
331
353
|
if (box.isMap(map) && isCva(map.value)) {
|
|
332
354
|
collector.setCva(result2);
|
|
333
355
|
} else {
|
|
@@ -346,11 +368,8 @@ function createParser(options) {
|
|
|
346
368
|
result.queryList.forEach((query) => {
|
|
347
369
|
if (query.kind === "call-expression") {
|
|
348
370
|
const map = query.box.value[0];
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
box: map ?? fallback(query.box),
|
|
352
|
-
data: combineResult(unbox(map))
|
|
353
|
-
};
|
|
371
|
+
const boxNode = box.isMap(map) ? map : fallback(query.box);
|
|
372
|
+
const result2 = { name: name2, box: boxNode, data: combineResult(unbox(boxNode)) };
|
|
354
373
|
if (box.isMap(map) && isCva(map.value)) {
|
|
355
374
|
collector.setCva(result2);
|
|
356
375
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.8.0",
|
|
20
|
+
"@pandacss/extractor": "0.8.0",
|
|
21
|
+
"@pandacss/is-valid-prop": "0.8.0",
|
|
22
|
+
"@pandacss/logger": "0.8.0",
|
|
23
|
+
"@pandacss/shared": "0.8.0",
|
|
24
|
+
"@pandacss/types": "0.8.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"hookable": "5.5.3",
|
|
27
|
-
"@pandacss/fixture": "0.
|
|
28
|
-
"@pandacss/generator": "0.
|
|
28
|
+
"@pandacss/fixture": "0.8.0",
|
|
29
|
+
"@pandacss/generator": "0.8.0"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|