@pandacss/parser 0.5.0 → 0.6.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 +33 -39
- package/dist/index.mjs +33 -39
- package/package.json +8 -9
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),
|
|
@@ -206,7 +206,7 @@ function createParser(options) {
|
|
|
206
206
|
if (jsx) {
|
|
207
207
|
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.name)]));
|
|
208
208
|
}
|
|
209
|
-
return function
|
|
209
|
+
return function parse2(sourceFile) {
|
|
210
210
|
if (!sourceFile)
|
|
211
211
|
return;
|
|
212
212
|
const filePath = sourceFile.getFilePath();
|
|
@@ -221,13 +221,13 @@ function createParser(options) {
|
|
|
221
221
|
imports.value.length ? `Found import { ${imports} } in ${filePath}` : `No import found in ${filePath}`
|
|
222
222
|
);
|
|
223
223
|
const [css] = importRegex;
|
|
224
|
+
const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "styled";
|
|
224
225
|
const isValidPattern = imports.createMatch(importMap.pattern);
|
|
225
226
|
const isValidRecipe = imports.createMatch(importMap.recipe);
|
|
226
227
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
227
|
-
const isFactory = (name) => jsx && name.startsWith(
|
|
228
|
-
const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "panda";
|
|
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,30 +269,27 @@ 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
|
);
|
|
276
275
|
const matchTag = (0, import_shared2.memo)((tagName) => {
|
|
277
276
|
if (!tagName)
|
|
278
277
|
return false;
|
|
279
|
-
return components.has(tagName) || isUpperCase(tagName) || tagName
|
|
278
|
+
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName);
|
|
280
279
|
});
|
|
281
280
|
const matchTagProp = (0, import_shared2.memo)((tagName, propName) => {
|
|
282
|
-
if (propertiesMap.size === 0)
|
|
283
|
-
return true;
|
|
284
281
|
if (Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName))
|
|
285
282
|
return true;
|
|
286
283
|
if (isJsxTagRecipe(tagName)) {
|
|
287
|
-
const
|
|
288
|
-
return recipe
|
|
284
|
+
const recipeList = getRecipesByJsxName(tagName);
|
|
285
|
+
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.name)?.has(propName));
|
|
289
286
|
}
|
|
290
287
|
return false;
|
|
291
288
|
});
|
|
292
289
|
const matchFn = (0, import_shared2.memo)((fnName) => {
|
|
293
290
|
if (recipes.has(fnName) || patterns.has(fnName))
|
|
294
291
|
return true;
|
|
295
|
-
if (fnName === cvaAlias || fnName === cssAlias || fnName
|
|
292
|
+
if (fnName === cvaAlias || fnName === cssAlias || isFactory(fnName))
|
|
296
293
|
return true;
|
|
297
294
|
return functions.has(fnName);
|
|
298
295
|
});
|
|
@@ -321,7 +318,7 @@ function createParser(options) {
|
|
|
321
318
|
measure();
|
|
322
319
|
extractResultByName.forEach((result, alias) => {
|
|
323
320
|
const name = imports.getName(alias);
|
|
324
|
-
import_logger.logger.debug(`ast:${name}`, {
|
|
321
|
+
import_logger.logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
325
322
|
if (result.kind === "function") {
|
|
326
323
|
(0, import_ts_pattern.match)(name).when(css.match, (name2) => {
|
|
327
324
|
result.queryList.forEach((query) => {
|
|
@@ -411,23 +408,19 @@ function createParser(options) {
|
|
|
411
408
|
} else if (result.kind === "component") {
|
|
412
409
|
result.queryList.forEach((query) => {
|
|
413
410
|
const data = combineResult((0, import_extractor.unbox)(query.box));
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
(name2) => {
|
|
418
|
-
collector.setJsx({ name: name2, box: query.box, type: "jsx-factory", data });
|
|
419
|
-
}
|
|
420
|
-
).when(
|
|
411
|
+
(0, import_ts_pattern.match)(name).when(isFactory, (name2) => {
|
|
412
|
+
collector.setJsx({ name: name2, box: query.box, type: "jsx-factory", data });
|
|
413
|
+
}).when(
|
|
421
414
|
(name2) => jsxPatternNodes.test(name2),
|
|
422
415
|
(name2) => {
|
|
423
416
|
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
424
417
|
}
|
|
425
|
-
).when(
|
|
426
|
-
|
|
427
|
-
(
|
|
428
|
-
collector.setRecipe(
|
|
429
|
-
}
|
|
430
|
-
).otherwise(() => {
|
|
418
|
+
).when(isJsxTagRecipe, (name2) => {
|
|
419
|
+
const recipeList = getRecipesByJsxName(name2);
|
|
420
|
+
recipeList.map((recipe) => {
|
|
421
|
+
collector.setRecipe(recipe.name, { type: "jsx-recipe", name: name2, box: query.box, data });
|
|
422
|
+
});
|
|
423
|
+
}).otherwise(() => {
|
|
431
424
|
collector.setJsx({ name, box: query.box, type: "jsx", data });
|
|
432
425
|
});
|
|
433
426
|
});
|
|
@@ -497,23 +490,24 @@ const render = ${fileStr.snip(templateStart, templateEnd).toString()}`
|
|
|
497
490
|
};
|
|
498
491
|
|
|
499
492
|
// src/svelte-to-tsx.ts
|
|
500
|
-
var svelte = __toESM(require("svelte/compiler"));
|
|
501
493
|
var import_magic_string2 = __toESM(require("magic-string"));
|
|
494
|
+
var regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi;
|
|
495
|
+
var regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi;
|
|
502
496
|
var svelteToTsx = (code) => {
|
|
503
497
|
try {
|
|
504
|
-
const
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
498
|
+
const scripts = [];
|
|
499
|
+
const original = new import_magic_string2.default(code);
|
|
500
|
+
let match2;
|
|
501
|
+
while ((match2 = regex_script_tags.exec(code)) != null) {
|
|
502
|
+
const [fullMatch, _attributesStr, scriptContent] = match2;
|
|
503
|
+
if (scriptContent) {
|
|
504
|
+
scripts.push(scriptContent);
|
|
505
|
+
original.remove(match2.index, match2.index + fullMatch.length);
|
|
506
|
+
}
|
|
509
507
|
}
|
|
510
|
-
const
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
const transformed = new import_magic_string2.default(
|
|
514
|
-
`${moduleContext + "\n"}${scriptContent + "\n"}
|
|
515
|
-
const render = <div>${templateContent}</div>`
|
|
516
|
-
);
|
|
508
|
+
const templateContent = original.toString().trimStart().replace(regex_style_tags, "").replace(regex_style_tags, "");
|
|
509
|
+
const transformed = `${scripts.join("")}
|
|
510
|
+
const render = <div>${templateContent}</div>`;
|
|
517
511
|
return transformed.toString().trim();
|
|
518
512
|
} catch (err) {
|
|
519
513
|
return "";
|
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),
|
|
@@ -168,7 +168,7 @@ function createParser(options) {
|
|
|
168
168
|
if (jsx) {
|
|
169
169
|
importRegex.push(createImportMatcher(importMap.jsx, [jsx.factory, ...jsx.nodes.map((node) => node.name)]));
|
|
170
170
|
}
|
|
171
|
-
return function
|
|
171
|
+
return function parse2(sourceFile) {
|
|
172
172
|
if (!sourceFile)
|
|
173
173
|
return;
|
|
174
174
|
const filePath = sourceFile.getFilePath();
|
|
@@ -183,13 +183,13 @@ function createParser(options) {
|
|
|
183
183
|
imports.value.length ? `Found import { ${imports} } in ${filePath}` : `No import found in ${filePath}`
|
|
184
184
|
);
|
|
185
185
|
const [css] = importRegex;
|
|
186
|
+
const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "styled";
|
|
186
187
|
const isValidPattern = imports.createMatch(importMap.pattern);
|
|
187
188
|
const isValidRecipe = imports.createMatch(importMap.recipe);
|
|
188
189
|
const isValidStyleFn = (name) => name === jsx?.factory;
|
|
189
|
-
const isFactory = (name) => jsx && name.startsWith(
|
|
190
|
-
const jsxFactoryAlias = jsx ? imports.getAlias(jsx.factory) : "panda";
|
|
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,30 +231,27 @@ 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
|
);
|
|
238
237
|
const matchTag = memo2((tagName) => {
|
|
239
238
|
if (!tagName)
|
|
240
239
|
return false;
|
|
241
|
-
return components.has(tagName) || isUpperCase(tagName) || tagName
|
|
240
|
+
return components.has(tagName) || isUpperCase(tagName) || isFactory(tagName) || isJsxTagRecipe(tagName);
|
|
242
241
|
});
|
|
243
242
|
const matchTagProp = memo2((tagName, propName) => {
|
|
244
|
-
if (propertiesMap.size === 0)
|
|
245
|
-
return true;
|
|
246
243
|
if (Boolean(components.get(tagName)?.has(propName)) || options.jsx?.isStyleProp(propName) || propertiesMap.has(propName))
|
|
247
244
|
return true;
|
|
248
245
|
if (isJsxTagRecipe(tagName)) {
|
|
249
|
-
const
|
|
250
|
-
return recipe
|
|
246
|
+
const recipeList = getRecipesByJsxName(tagName);
|
|
247
|
+
return recipeList.some((recipe) => recipePropertiesByName.get(recipe.name)?.has(propName));
|
|
251
248
|
}
|
|
252
249
|
return false;
|
|
253
250
|
});
|
|
254
251
|
const matchFn = memo2((fnName) => {
|
|
255
252
|
if (recipes.has(fnName) || patterns.has(fnName))
|
|
256
253
|
return true;
|
|
257
|
-
if (fnName === cvaAlias || fnName === cssAlias || fnName
|
|
254
|
+
if (fnName === cvaAlias || fnName === cssAlias || isFactory(fnName))
|
|
258
255
|
return true;
|
|
259
256
|
return functions.has(fnName);
|
|
260
257
|
});
|
|
@@ -283,7 +280,7 @@ function createParser(options) {
|
|
|
283
280
|
measure();
|
|
284
281
|
extractResultByName.forEach((result, alias) => {
|
|
285
282
|
const name = imports.getName(alias);
|
|
286
|
-
logger.debug(`ast:${name}`, {
|
|
283
|
+
logger.debug(`ast:${name}`, name !== alias ? { kind: result.kind, alias } : { kind: result.kind });
|
|
287
284
|
if (result.kind === "function") {
|
|
288
285
|
match(name).when(css.match, (name2) => {
|
|
289
286
|
result.queryList.forEach((query) => {
|
|
@@ -373,23 +370,19 @@ function createParser(options) {
|
|
|
373
370
|
} else if (result.kind === "component") {
|
|
374
371
|
result.queryList.forEach((query) => {
|
|
375
372
|
const data = combineResult(unbox(query.box));
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
(name2) => {
|
|
380
|
-
collector.setJsx({ name: name2, box: query.box, type: "jsx-factory", data });
|
|
381
|
-
}
|
|
382
|
-
).when(
|
|
373
|
+
match(name).when(isFactory, (name2) => {
|
|
374
|
+
collector.setJsx({ name: name2, box: query.box, type: "jsx-factory", data });
|
|
375
|
+
}).when(
|
|
383
376
|
(name2) => jsxPatternNodes.test(name2),
|
|
384
377
|
(name2) => {
|
|
385
378
|
collector.setPattern(name2, { type: "jsx-pattern", name: name2, box: query.box, data });
|
|
386
379
|
}
|
|
387
|
-
).when(
|
|
388
|
-
|
|
389
|
-
(
|
|
390
|
-
collector.setRecipe(
|
|
391
|
-
}
|
|
392
|
-
).otherwise(() => {
|
|
380
|
+
).when(isJsxTagRecipe, (name2) => {
|
|
381
|
+
const recipeList = getRecipesByJsxName(name2);
|
|
382
|
+
recipeList.map((recipe) => {
|
|
383
|
+
collector.setRecipe(recipe.name, { type: "jsx-recipe", name: name2, box: query.box, data });
|
|
384
|
+
});
|
|
385
|
+
}).otherwise(() => {
|
|
393
386
|
collector.setJsx({ name, box: query.box, type: "jsx", data });
|
|
394
387
|
});
|
|
395
388
|
});
|
|
@@ -459,23 +452,24 @@ const render = ${fileStr.snip(templateStart, templateEnd).toString()}`
|
|
|
459
452
|
};
|
|
460
453
|
|
|
461
454
|
// src/svelte-to-tsx.ts
|
|
462
|
-
import * as svelte from "svelte/compiler";
|
|
463
455
|
import MagicString2 from "magic-string";
|
|
456
|
+
var regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi;
|
|
457
|
+
var regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi;
|
|
464
458
|
var svelteToTsx = (code) => {
|
|
465
459
|
try {
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
460
|
+
const scripts = [];
|
|
461
|
+
const original = new MagicString2(code);
|
|
462
|
+
let match2;
|
|
463
|
+
while ((match2 = regex_script_tags.exec(code)) != null) {
|
|
464
|
+
const [fullMatch, _attributesStr, scriptContent] = match2;
|
|
465
|
+
if (scriptContent) {
|
|
466
|
+
scripts.push(scriptContent);
|
|
467
|
+
original.remove(match2.index, match2.index + fullMatch.length);
|
|
468
|
+
}
|
|
471
469
|
}
|
|
472
|
-
const
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
const transformed = new MagicString2(
|
|
476
|
-
`${moduleContext + "\n"}${scriptContent + "\n"}
|
|
477
|
-
const render = <div>${templateContent}</div>`
|
|
478
|
-
);
|
|
470
|
+
const templateContent = original.toString().trimStart().replace(regex_style_tags, "").replace(regex_style_tags, "");
|
|
471
|
+
const transformed = `${scripts.join("")}
|
|
472
|
+
const render = <div>${templateContent}</div>`;
|
|
479
473
|
return transformed.toString().trim();
|
|
480
474
|
} catch (err) {
|
|
481
475
|
return "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The static parser for panda css",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,19 +14,18 @@
|
|
|
14
14
|
"@vue/compiler-sfc": "^3.3.4",
|
|
15
15
|
"lil-fp": "1.4.5",
|
|
16
16
|
"magic-string": "^0.30.0",
|
|
17
|
-
"svelte": "^4.0.0",
|
|
18
17
|
"ts-morph": "18.0.0",
|
|
19
18
|
"ts-pattern": "4.3.0",
|
|
20
|
-
"@pandacss/extractor": "0.
|
|
21
|
-
"@pandacss/is-valid-prop": "0.
|
|
22
|
-
"@pandacss/logger": "0.
|
|
23
|
-
"@pandacss/shared": "0.
|
|
24
|
-
"@pandacss/types": "0.
|
|
19
|
+
"@pandacss/extractor": "0.6.0",
|
|
20
|
+
"@pandacss/is-valid-prop": "0.6.0",
|
|
21
|
+
"@pandacss/logger": "0.6.0",
|
|
22
|
+
"@pandacss/shared": "0.6.0",
|
|
23
|
+
"@pandacss/types": "0.6.0"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"hookable": "5.5.3",
|
|
28
|
-
"@pandacss/fixture": "0.
|
|
29
|
-
"@pandacss/generator": "0.
|
|
27
|
+
"@pandacss/fixture": "0.6.0",
|
|
28
|
+
"@pandacss/generator": "0.6.0"
|
|
30
29
|
},
|
|
31
30
|
"files": [
|
|
32
31
|
"dist"
|