@pandacss/parser 0.5.1 → 0.7.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 +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +21 -13
- package/dist/index.mjs +21 -13
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -54,8 +54,7 @@ type ParserOptions = {
|
|
|
54
54
|
nodes: ParserNodeOptions[];
|
|
55
55
|
isStyleProp: (prop: string) => boolean;
|
|
56
56
|
};
|
|
57
|
-
|
|
58
|
-
getRecipeByName: (name: string) => RecipeConfig | undefined;
|
|
57
|
+
getRecipesByJsxName: (jsxName: string) => RecipeConfig[];
|
|
59
58
|
};
|
|
60
59
|
|
|
61
60
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -54,8 +54,7 @@ type ParserOptions = {
|
|
|
54
54
|
nodes: ParserNodeOptions[];
|
|
55
55
|
isStyleProp: (prop: string) => boolean;
|
|
56
56
|
};
|
|
57
|
-
|
|
58
|
-
getRecipeByName: (name: string) => RecipeConfig | undefined;
|
|
57
|
+
getRecipesByJsxName: (jsxName: string) => RecipeConfig[];
|
|
59
58
|
};
|
|
60
59
|
|
|
61
60
|
type ProjectOptions = Partial<ProjectOptions$1> & {
|
package/dist/index.js
CHANGED
|
@@ -197,7 +197,7 @@ var fallback = (box2) => ({
|
|
|
197
197
|
});
|
|
198
198
|
var defaultEnv = { preset: "NONE" };
|
|
199
199
|
function createParser(options) {
|
|
200
|
-
const { jsx, importMap,
|
|
200
|
+
const { jsx, importMap, getRecipesByJsxName } = options;
|
|
201
201
|
const importRegex = [
|
|
202
202
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
203
203
|
createImportMatcher(importMap.recipe),
|
|
@@ -227,7 +227,7 @@ function createParser(options) {
|
|
|
227
227
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
228
228
|
const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
|
|
229
229
|
const jsxPatternNodes = new RegExp(
|
|
230
|
-
`^(${jsx?.nodes.
|
|
230
|
+
`^(${jsx?.nodes.filter((node) => node.type === "pattern").map((node) => node.name).join("|")})$`
|
|
231
231
|
);
|
|
232
232
|
const recipes = /* @__PURE__ */ new Set();
|
|
233
233
|
const patterns = /* @__PURE__ */ new Set();
|
|
@@ -269,7 +269,6 @@ function createParser(options) {
|
|
|
269
269
|
components.set(alias, propertiesMap);
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
-
const getRecipeName = (0, import_shared2.memo)(options.getRecipeName);
|
|
273
272
|
const isJsxTagRecipe = (0, import_shared2.memo)(
|
|
274
273
|
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
275
274
|
);
|
|
@@ -282,8 +281,8 @@ function createParser(options) {
|
|
|
282
281
|
if (Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName))
|
|
283
282
|
return true;
|
|
284
283
|
if (isJsxTagRecipe(tagName)) {
|
|
285
|
-
const
|
|
286
|
-
return recipe
|
|
284
|
+
const recipeList = getRecipesByJsxName(tagName);
|
|
285
|
+
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.name)?.has(propName));
|
|
287
286
|
}
|
|
288
287
|
return false;
|
|
289
288
|
});
|
|
@@ -417,7 +416,10 @@ function createParser(options) {
|
|
|
417
416
|
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
418
417
|
}
|
|
419
418
|
).when(isJsxTagRecipe, (name2) => {
|
|
420
|
-
|
|
419
|
+
const recipeList = getRecipesByJsxName(name2);
|
|
420
|
+
recipeList.map((recipe) => {
|
|
421
|
+
collector.setRecipe(recipe.name, { type: "jsx-recipe", name: name2, box: query.box, data });
|
|
422
|
+
});
|
|
421
423
|
}).otherwise(() => {
|
|
422
424
|
collector.setJsx({ name, box: query.box, type: "jsx", data });
|
|
423
425
|
});
|
|
@@ -465,15 +467,21 @@ var vueToTsx = (code) => {
|
|
|
465
467
|
try {
|
|
466
468
|
const parsed = (0, import_compiler_sfc.parse)(code);
|
|
467
469
|
const fileStr = new import_magic_string.default(code);
|
|
468
|
-
|
|
470
|
+
const rewriteProp = (prop) => {
|
|
471
|
+
if (prop.type === NodeTypes.DIRECTIVE && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
472
|
+
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
const stack = [...parsed.descriptor.template.ast.children];
|
|
476
|
+
while (stack.length) {
|
|
477
|
+
const node = stack.pop();
|
|
478
|
+
if (!node)
|
|
479
|
+
continue;
|
|
469
480
|
if (node.type === NodeTypes.ELEMENT) {
|
|
470
|
-
node.props.forEach(
|
|
471
|
-
|
|
472
|
-
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
473
|
-
}
|
|
474
|
-
});
|
|
481
|
+
node.props.forEach(rewriteProp);
|
|
482
|
+
node.children.forEach((child) => stack.push(child));
|
|
475
483
|
}
|
|
476
|
-
}
|
|
484
|
+
}
|
|
477
485
|
const templateStart = code.indexOf("<template");
|
|
478
486
|
const templateEnd = code.indexOf("</template>") + "</template>".length;
|
|
479
487
|
const scriptContent = (parsed.descriptor.scriptSetup ?? parsed.descriptor.script)?.content + "\n";
|
package/dist/index.mjs
CHANGED
|
@@ -159,7 +159,7 @@ var fallback = (box2) => ({
|
|
|
159
159
|
});
|
|
160
160
|
var defaultEnv = { preset: "NONE" };
|
|
161
161
|
function createParser(options) {
|
|
162
|
-
const { jsx, importMap,
|
|
162
|
+
const { jsx, importMap, getRecipesByJsxName } = options;
|
|
163
163
|
const importRegex = [
|
|
164
164
|
createImportMatcher(importMap.css, ["css", "cva"]),
|
|
165
165
|
createImportMatcher(importMap.recipe),
|
|
@@ -189,7 +189,7 @@ function createParser(options) {
|
|
|
189
189
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
190
190
|
const isFactory = (name) => Boolean(jsx && name.startsWith(jsxFactoryAlias));
|
|
191
191
|
const jsxPatternNodes = new RegExp(
|
|
192
|
-
`^(${jsx?.nodes.
|
|
192
|
+
`^(${jsx?.nodes.filter((node) => node.type === "pattern").map((node) => node.name).join("|")})$`
|
|
193
193
|
);
|
|
194
194
|
const recipes = /* @__PURE__ */ new Set();
|
|
195
195
|
const patterns = /* @__PURE__ */ new Set();
|
|
@@ -231,7 +231,6 @@ function createParser(options) {
|
|
|
231
231
|
components.set(alias, propertiesMap);
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
|
-
const getRecipeName = memo2(options.getRecipeName);
|
|
235
234
|
const isJsxTagRecipe = memo2(
|
|
236
235
|
(tagName) => recipeJsxLists.string.has(tagName) || recipeJsxLists.regex.some((regex) => regex.test(tagName))
|
|
237
236
|
);
|
|
@@ -244,8 +243,8 @@ function createParser(options) {
|
|
|
244
243
|
if (Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName))
|
|
245
244
|
return true;
|
|
246
245
|
if (isJsxTagRecipe(tagName)) {
|
|
247
|
-
const
|
|
248
|
-
return recipe
|
|
246
|
+
const recipeList = getRecipesByJsxName(tagName);
|
|
247
|
+
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.name)?.has(propName));
|
|
249
248
|
}
|
|
250
249
|
return false;
|
|
251
250
|
});
|
|
@@ -379,7 +378,10 @@ function createParser(options) {
|
|
|
379
378
|
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
380
379
|
}
|
|
381
380
|
).when(isJsxTagRecipe, (name2) => {
|
|
382
|
-
|
|
381
|
+
const recipeList = getRecipesByJsxName(name2);
|
|
382
|
+
recipeList.map((recipe) => {
|
|
383
|
+
collector.setRecipe(recipe.name, { type: "jsx-recipe", name: name2, box: query.box, data });
|
|
384
|
+
});
|
|
383
385
|
}).otherwise(() => {
|
|
384
386
|
collector.setJsx({ name, box: query.box, type: "jsx", data });
|
|
385
387
|
});
|
|
@@ -427,15 +429,21 @@ var vueToTsx = (code) => {
|
|
|
427
429
|
try {
|
|
428
430
|
const parsed = parse(code);
|
|
429
431
|
const fileStr = new MagicString(code);
|
|
430
|
-
|
|
432
|
+
const rewriteProp = (prop) => {
|
|
433
|
+
if (prop.type === NodeTypes.DIRECTIVE && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
434
|
+
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
const stack = [...parsed.descriptor.template.ast.children];
|
|
438
|
+
while (stack.length) {
|
|
439
|
+
const node = stack.pop();
|
|
440
|
+
if (!node)
|
|
441
|
+
continue;
|
|
431
442
|
if (node.type === NodeTypes.ELEMENT) {
|
|
432
|
-
node.props.forEach(
|
|
433
|
-
|
|
434
|
-
fileStr.update(prop.loc.start.offset, prop.loc.end.offset, `${prop.arg.content}={${prop.exp.content}}`);
|
|
435
|
-
}
|
|
436
|
-
});
|
|
443
|
+
node.props.forEach(rewriteProp);
|
|
444
|
+
node.children.forEach((child) => stack.push(child));
|
|
437
445
|
}
|
|
438
|
-
}
|
|
446
|
+
}
|
|
439
447
|
const templateStart = code.indexOf("<template");
|
|
440
448
|
const templateEnd = code.indexOf("</template>") + "</template>".length;
|
|
441
449
|
const scriptContent = (parsed.descriptor.scriptSetup ?? parsed.descriptor.script)?.content + "\n";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@vue/compiler-sfc": "^3.3.4",
|
|
15
15
|
"lil-fp": "1.4.5",
|
|
16
|
-
"magic-string": "^0.30.
|
|
16
|
+
"magic-string": "^0.30.1",
|
|
17
17
|
"ts-morph": "18.0.0",
|
|
18
|
-
"ts-pattern": "
|
|
19
|
-
"@pandacss/extractor": "0.
|
|
20
|
-
"@pandacss/is-valid-prop": "0.
|
|
21
|
-
"@pandacss/logger": "0.
|
|
22
|
-
"@pandacss/shared": "0.
|
|
23
|
-
"@pandacss/types": "0.
|
|
18
|
+
"ts-pattern": "5.0.1",
|
|
19
|
+
"@pandacss/extractor": "0.7.0",
|
|
20
|
+
"@pandacss/is-valid-prop": "0.7.0",
|
|
21
|
+
"@pandacss/logger": "0.7.0",
|
|
22
|
+
"@pandacss/shared": "0.7.0",
|
|
23
|
+
"@pandacss/types": "0.7.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"hookable": "5.5.3",
|
|
27
|
-
"@pandacss/fixture": "0.
|
|
28
|
-
"@pandacss/generator": "0.
|
|
27
|
+
"@pandacss/fixture": "0.7.0",
|
|
28
|
+
"@pandacss/generator": "0.7.0"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist"
|