@pandacss/parser 0.54.0 → 1.0.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.
Files changed (3) hide show
  1. package/dist/index.js +26 -45
  2. package/dist/index.mjs +23 -42
  3. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -28,12 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  ParserResult: () => ParserResult,
34
34
  Project: () => Project
35
35
  });
36
- module.exports = __toCommonJS(src_exports);
36
+ module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/project.ts
39
39
  var import_ts_morph2 = require("ts-morph");
@@ -61,19 +61,15 @@ function classifyProject(ctx, resultMap) {
61
61
  const { propName, value, tokenType } = reportItem;
62
62
  const utility = ctx.utility.config[propName];
63
63
  if (utility) {
64
- if (ctx.tokens.getByName(`${tokenType}.${value}`))
65
- return true;
66
- if (ctx.tokens.getReferences(String(value)).length > 0)
67
- return true;
68
- if (ctx.utility.resolveColorMix(String(value)).color)
69
- return true;
64
+ if (ctx.tokens.getByName(`${tokenType}.${value}`)) return true;
65
+ if (ctx.tokens.getReferences(String(value)).length > 0) return true;
66
+ if (ctx.utility.resolveColorMix(String(value)).color) return true;
70
67
  return false;
71
68
  }
72
69
  if (componentReportItem.reportItemType === "pattern") {
73
70
  const pattern = ctx.patterns.getConfig(componentReportItem.componentName.toLowerCase());
74
71
  const patternProp = pattern?.properties?.[propName];
75
- if (!patternProp)
76
- return false;
72
+ if (!patternProp) return false;
77
73
  if (patternProp.type === "boolean" || patternProp.type === "number") {
78
74
  return true;
79
75
  }
@@ -94,8 +90,7 @@ function classifyProject(ctx, resultMap) {
94
90
  const { boxNode, data, item, filepath, localMaps } = opts;
95
91
  const name = item.componentName;
96
92
  const pattern = ctx.patterns.details.find((p) => p.match.test(name) || p.baseName === name);
97
- if (!pattern)
98
- return;
93
+ if (!pattern) return;
99
94
  const cssObj = pattern.config.transform?.(data || {}, import_shared.patternFns) ?? {};
100
95
  const newItem = {
101
96
  name: "css",
@@ -145,8 +140,7 @@ function classifyProject(ctx, resultMap) {
145
140
  const processResultItemFn = (opts) => {
146
141
  const { item, filepath, localMaps, type } = opts;
147
142
  const componentReportItem = processResultItem({ item, kind: type, filepath, localMaps });
148
- if (!componentReportItem)
149
- return;
143
+ if (!componentReportItem) return;
150
144
  addTo(globalMaps.byComponentOfKind, type, componentReportItem.componentIndex);
151
145
  addTo(localMaps.byComponentOfKind, type, componentReportItem.componentIndex);
152
146
  byComponentIndex.set(componentReportItem.componentIndex, componentReportItem);
@@ -236,8 +230,7 @@ function classifyProject(ctx, resultMap) {
236
230
  });
237
231
  };
238
232
  resultMap.forEach((parserResult, filepath) => {
239
- if (parserResult.isEmpty())
240
- return;
233
+ if (parserResult.isEmpty()) return;
241
234
  const localMaps = createReportMaps();
242
235
  const componentFn = (item) => {
243
236
  processResultItemFn({ item, filepath, localMaps, type: "component" });
@@ -263,8 +256,7 @@ function classifyProject(ctx, resultMap) {
263
256
  Object.entries(ctx.recipes.config).forEach(([key, recipe]) => {
264
257
  const localMaps = createReportMaps();
265
258
  const functionFn = (styleObject) => {
266
- if (!styleObject)
267
- return;
259
+ if (!styleObject) return;
268
260
  const componentReportItem = {
269
261
  componentIndex: "0",
270
262
  componentName: `recipes.${key}.base`,
@@ -305,8 +297,7 @@ function classifyProject(ctx, resultMap) {
305
297
  }
306
298
  });
307
299
  Object.values(ctx.config.globalCss ?? {}).forEach((styleObject) => {
308
- if (!styleObject)
309
- return;
300
+ if (!styleObject) return;
310
301
  processMap({
311
302
  // @ts-expect-error
312
303
  map: import_extractor.box.objectToMap(styleObject, null, []),
@@ -475,19 +466,16 @@ function getImportDeclarations(context, sourceFile) {
475
466
  const importDeclarations = [];
476
467
  sourceFile.getImportDeclarations().forEach((node) => {
477
468
  const mod = getModuleSpecifierValue(node);
478
- if (!mod)
479
- return;
469
+ if (!mod) return;
480
470
  node.getNamedImports().forEach((specifier) => {
481
471
  const name = specifier.getNameNode().getText();
482
472
  const alias = specifier.getAliasNode()?.getText() || name;
483
473
  const result = { name, alias, mod, kind: "named" };
484
474
  const found = imports.match(result, (mod2) => {
485
- if (!tsOptions?.pathMappings)
486
- return;
475
+ if (!tsOptions?.pathMappings) return;
487
476
  return (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, mod2);
488
477
  });
489
- if (!found)
490
- return;
478
+ if (!found) return;
491
479
  importDeclarations.push(result);
492
480
  });
493
481
  const namespace = node.getNamespaceImport();
@@ -495,12 +483,10 @@ function getImportDeclarations(context, sourceFile) {
495
483
  const name = namespace.getText();
496
484
  const result = { name, alias: name, mod, kind: "namespace" };
497
485
  const found = imports.match(result, (mod2) => {
498
- if (!tsOptions?.pathMappings)
499
- return;
486
+ if (!tsOptions?.pathMappings) return;
500
487
  return (0, import_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, mod2);
501
488
  });
502
- if (!found)
503
- return;
489
+ if (!found) return;
504
490
  importDeclarations.push(result);
505
491
  }
506
492
  });
@@ -577,8 +563,7 @@ var ParserResult = class {
577
563
  const encoder = this.encoder;
578
564
  const recipes = this.context.recipes;
579
565
  const recipeConfig = recipes.getConfig(recipeName);
580
- if (!recipeConfig)
581
- return;
566
+ if (!recipeConfig) return;
582
567
  const recipe = result;
583
568
  if (result.type) {
584
569
  recipe.data.forEach((data) => {
@@ -643,8 +628,7 @@ function createParser(context) {
643
628
  const { jsx, imports, recipes, config } = context;
644
629
  const syntax = config.syntax;
645
630
  return function parse2(sourceFile, encoder, options) {
646
- if (!sourceFile)
647
- return;
631
+ if (!sourceFile) return;
648
632
  const importDeclarations = getImportDeclarations(context, sourceFile);
649
633
  const file = imports.file(importDeclarations);
650
634
  const filePath = sourceFile.getFilePath();
@@ -678,8 +662,7 @@ function createParser(context) {
678
662
  matchFn: (prop) => file.matchFn(prop.fnName),
679
663
  matchProp: () => true,
680
664
  matchArg: (prop) => {
681
- if (file.isJsxFactory(prop.fnName) && prop.index === 1 && import_ts_morph.Node.isIdentifier(prop.argNode))
682
- return false;
665
+ if (file.isJsxFactory(prop.fnName) && prop.index === 1 && import_ts_morph.Node.isIdentifier(prop.argNode)) return false;
683
666
  return true;
684
667
  }
685
668
  },
@@ -687,11 +670,9 @@ function createParser(context) {
687
670
  matchTaggedTemplate: (tag) => file.matchFn(tag.fnName)
688
671
  } : void 0,
689
672
  getEvaluateOptions: (node) => {
690
- if (!import_ts_morph.Node.isCallExpression(node))
691
- return evaluateOptions;
673
+ if (!import_ts_morph.Node.isCallExpression(node)) return evaluateOptions;
692
674
  const propAccessExpr = node.getExpression();
693
- if (!import_ts_morph.Node.isPropertyAccessExpression(propAccessExpr))
694
- return evaluateOptions;
675
+ if (!import_ts_morph.Node.isPropertyAccessExpression(propAccessExpr)) return evaluateOptions;
695
676
  let name = propAccessExpr.getText();
696
677
  if (!file.isRawFn(name)) {
697
678
  return evaluateOptions;
@@ -831,6 +812,7 @@ function createParser(context) {
831
812
  parserResult.setPattern(name, { type: "jsx-pattern", name, box: query.box, data });
832
813
  break;
833
814
  }
815
+ // name: Trigger
834
816
  case jsx.isJsxTagRecipe(name): {
835
817
  const matchingRecipes = recipes.filter(name);
836
818
  matchingRecipes.map((recipe) => {
@@ -838,6 +820,7 @@ function createParser(context) {
838
820
  });
839
821
  break;
840
822
  }
823
+ // alias: Tabs.Trigger
841
824
  case jsx.isJsxTagRecipe(alias): {
842
825
  const matchingRecipes = recipes.filter(alias);
843
826
  matchingRecipes.map((recipe) => {
@@ -925,8 +908,7 @@ var vueToTsx = (code) => {
925
908
  const stack = Array.from(parsed.descriptor.template?.ast?.children ?? []);
926
909
  while (stack.length) {
927
910
  const node = stack.pop();
928
- if (!node)
929
- continue;
911
+ if (!node) continue;
930
912
  if (node.type === NodeTypes.ELEMENT) {
931
913
  node.props.forEach(rewriteProp);
932
914
  node.children.forEach((child) => stack.push(child));
@@ -1028,8 +1010,7 @@ var Project = class {
1028
1010
  return this.parseJson(filePath);
1029
1011
  }
1030
1012
  const sourceFile = this.project.getSourceFile(filePath);
1031
- if (!sourceFile)
1032
- return;
1013
+ if (!sourceFile) return;
1033
1014
  const original = sourceFile.getText();
1034
1015
  const options = {};
1035
1016
  const custom = hooks["parser:before"]?.({
package/dist/index.mjs CHANGED
@@ -27,19 +27,15 @@ function classifyProject(ctx, resultMap) {
27
27
  const { propName, value, tokenType } = reportItem;
28
28
  const utility = ctx.utility.config[propName];
29
29
  if (utility) {
30
- if (ctx.tokens.getByName(`${tokenType}.${value}`))
31
- return true;
32
- if (ctx.tokens.getReferences(String(value)).length > 0)
33
- return true;
34
- if (ctx.utility.resolveColorMix(String(value)).color)
35
- return true;
30
+ if (ctx.tokens.getByName(`${tokenType}.${value}`)) return true;
31
+ if (ctx.tokens.getReferences(String(value)).length > 0) return true;
32
+ if (ctx.utility.resolveColorMix(String(value)).color) return true;
36
33
  return false;
37
34
  }
38
35
  if (componentReportItem.reportItemType === "pattern") {
39
36
  const pattern = ctx.patterns.getConfig(componentReportItem.componentName.toLowerCase());
40
37
  const patternProp = pattern?.properties?.[propName];
41
- if (!patternProp)
42
- return false;
38
+ if (!patternProp) return false;
43
39
  if (patternProp.type === "boolean" || patternProp.type === "number") {
44
40
  return true;
45
41
  }
@@ -60,8 +56,7 @@ function classifyProject(ctx, resultMap) {
60
56
  const { boxNode, data, item, filepath, localMaps } = opts;
61
57
  const name = item.componentName;
62
58
  const pattern = ctx.patterns.details.find((p) => p.match.test(name) || p.baseName === name);
63
- if (!pattern)
64
- return;
59
+ if (!pattern) return;
65
60
  const cssObj = pattern.config.transform?.(data || {}, patternFns) ?? {};
66
61
  const newItem = {
67
62
  name: "css",
@@ -111,8 +106,7 @@ function classifyProject(ctx, resultMap) {
111
106
  const processResultItemFn = (opts) => {
112
107
  const { item, filepath, localMaps, type } = opts;
113
108
  const componentReportItem = processResultItem({ item, kind: type, filepath, localMaps });
114
- if (!componentReportItem)
115
- return;
109
+ if (!componentReportItem) return;
116
110
  addTo(globalMaps.byComponentOfKind, type, componentReportItem.componentIndex);
117
111
  addTo(localMaps.byComponentOfKind, type, componentReportItem.componentIndex);
118
112
  byComponentIndex.set(componentReportItem.componentIndex, componentReportItem);
@@ -202,8 +196,7 @@ function classifyProject(ctx, resultMap) {
202
196
  });
203
197
  };
204
198
  resultMap.forEach((parserResult, filepath) => {
205
- if (parserResult.isEmpty())
206
- return;
199
+ if (parserResult.isEmpty()) return;
207
200
  const localMaps = createReportMaps();
208
201
  const componentFn = (item) => {
209
202
  processResultItemFn({ item, filepath, localMaps, type: "component" });
@@ -229,8 +222,7 @@ function classifyProject(ctx, resultMap) {
229
222
  Object.entries(ctx.recipes.config).forEach(([key, recipe]) => {
230
223
  const localMaps = createReportMaps();
231
224
  const functionFn = (styleObject) => {
232
- if (!styleObject)
233
- return;
225
+ if (!styleObject) return;
234
226
  const componentReportItem = {
235
227
  componentIndex: "0",
236
228
  componentName: `recipes.${key}.base`,
@@ -271,8 +263,7 @@ function classifyProject(ctx, resultMap) {
271
263
  }
272
264
  });
273
265
  Object.values(ctx.config.globalCss ?? {}).forEach((styleObject) => {
274
- if (!styleObject)
275
- return;
266
+ if (!styleObject) return;
276
267
  processMap({
277
268
  // @ts-expect-error
278
269
  map: box.objectToMap(styleObject, null, []),
@@ -441,19 +432,16 @@ function getImportDeclarations(context, sourceFile) {
441
432
  const importDeclarations = [];
442
433
  sourceFile.getImportDeclarations().forEach((node) => {
443
434
  const mod = getModuleSpecifierValue(node);
444
- if (!mod)
445
- return;
435
+ if (!mod) return;
446
436
  node.getNamedImports().forEach((specifier) => {
447
437
  const name = specifier.getNameNode().getText();
448
438
  const alias = specifier.getAliasNode()?.getText() || name;
449
439
  const result = { name, alias, mod, kind: "named" };
450
440
  const found = imports.match(result, (mod2) => {
451
- if (!tsOptions?.pathMappings)
452
- return;
441
+ if (!tsOptions?.pathMappings) return;
453
442
  return resolveTsPathPattern(tsOptions.pathMappings, mod2);
454
443
  });
455
- if (!found)
456
- return;
444
+ if (!found) return;
457
445
  importDeclarations.push(result);
458
446
  });
459
447
  const namespace = node.getNamespaceImport();
@@ -461,12 +449,10 @@ function getImportDeclarations(context, sourceFile) {
461
449
  const name = namespace.getText();
462
450
  const result = { name, alias: name, mod, kind: "namespace" };
463
451
  const found = imports.match(result, (mod2) => {
464
- if (!tsOptions?.pathMappings)
465
- return;
452
+ if (!tsOptions?.pathMappings) return;
466
453
  return resolveTsPathPattern(tsOptions.pathMappings, mod2);
467
454
  });
468
- if (!found)
469
- return;
455
+ if (!found) return;
470
456
  importDeclarations.push(result);
471
457
  }
472
458
  });
@@ -543,8 +529,7 @@ var ParserResult = class {
543
529
  const encoder = this.encoder;
544
530
  const recipes = this.context.recipes;
545
531
  const recipeConfig = recipes.getConfig(recipeName);
546
- if (!recipeConfig)
547
- return;
532
+ if (!recipeConfig) return;
548
533
  const recipe = result;
549
534
  if (result.type) {
550
535
  recipe.data.forEach((data) => {
@@ -609,8 +594,7 @@ function createParser(context) {
609
594
  const { jsx, imports, recipes, config } = context;
610
595
  const syntax = config.syntax;
611
596
  return function parse2(sourceFile, encoder, options) {
612
- if (!sourceFile)
613
- return;
597
+ if (!sourceFile) return;
614
598
  const importDeclarations = getImportDeclarations(context, sourceFile);
615
599
  const file = imports.file(importDeclarations);
616
600
  const filePath = sourceFile.getFilePath();
@@ -644,8 +628,7 @@ function createParser(context) {
644
628
  matchFn: (prop) => file.matchFn(prop.fnName),
645
629
  matchProp: () => true,
646
630
  matchArg: (prop) => {
647
- if (file.isJsxFactory(prop.fnName) && prop.index === 1 && Node.isIdentifier(prop.argNode))
648
- return false;
631
+ if (file.isJsxFactory(prop.fnName) && prop.index === 1 && Node.isIdentifier(prop.argNode)) return false;
649
632
  return true;
650
633
  }
651
634
  },
@@ -653,11 +636,9 @@ function createParser(context) {
653
636
  matchTaggedTemplate: (tag) => file.matchFn(tag.fnName)
654
637
  } : void 0,
655
638
  getEvaluateOptions: (node) => {
656
- if (!Node.isCallExpression(node))
657
- return evaluateOptions;
639
+ if (!Node.isCallExpression(node)) return evaluateOptions;
658
640
  const propAccessExpr = node.getExpression();
659
- if (!Node.isPropertyAccessExpression(propAccessExpr))
660
- return evaluateOptions;
641
+ if (!Node.isPropertyAccessExpression(propAccessExpr)) return evaluateOptions;
661
642
  let name = propAccessExpr.getText();
662
643
  if (!file.isRawFn(name)) {
663
644
  return evaluateOptions;
@@ -797,6 +778,7 @@ function createParser(context) {
797
778
  parserResult.setPattern(name, { type: "jsx-pattern", name, box: query.box, data });
798
779
  break;
799
780
  }
781
+ // name: Trigger
800
782
  case jsx.isJsxTagRecipe(name): {
801
783
  const matchingRecipes = recipes.filter(name);
802
784
  matchingRecipes.map((recipe) => {
@@ -804,6 +786,7 @@ function createParser(context) {
804
786
  });
805
787
  break;
806
788
  }
789
+ // alias: Tabs.Trigger
807
790
  case jsx.isJsxTagRecipe(alias): {
808
791
  const matchingRecipes = recipes.filter(alias);
809
792
  matchingRecipes.map((recipe) => {
@@ -891,8 +874,7 @@ var vueToTsx = (code) => {
891
874
  const stack = Array.from(parsed.descriptor.template?.ast?.children ?? []);
892
875
  while (stack.length) {
893
876
  const node = stack.pop();
894
- if (!node)
895
- continue;
877
+ if (!node) continue;
896
878
  if (node.type === NodeTypes.ELEMENT) {
897
879
  node.props.forEach(rewriteProp);
898
880
  node.children.forEach((child) => stack.push(child));
@@ -994,8 +976,7 @@ var Project = class {
994
976
  return this.parseJson(filePath);
995
977
  }
996
978
  const sourceFile = this.project.getSourceFile(filePath);
997
- if (!sourceFile)
998
- return;
979
+ if (!sourceFile) return;
999
980
  const original = sourceFile.getText();
1000
981
  const options = {};
1001
982
  const custom = hooks["parser:before"]?.({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/parser",
3
- "version": "0.54.0",
3
+ "version": "1.0.1",
4
4
  "description": "The static parser for panda css",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -30,18 +30,18 @@
30
30
  "dependencies": {
31
31
  "@vue/compiler-sfc": "3.4.19",
32
32
  "magic-string": "0.30.17",
33
- "ts-morph": "24.0.0",
34
- "ts-pattern": "5.0.8",
35
- "@pandacss/config": "^0.54.0",
36
- "@pandacss/core": "^0.54.0",
37
- "@pandacss/extractor": "0.54.0",
38
- "@pandacss/logger": "0.54.0",
39
- "@pandacss/shared": "0.54.0",
40
- "@pandacss/types": "0.54.0"
33
+ "ts-morph": "26.0.0",
34
+ "ts-pattern": "5.8.0",
35
+ "@pandacss/config": "^1.0.1",
36
+ "@pandacss/core": "^1.0.1",
37
+ "@pandacss/extractor": "1.0.1",
38
+ "@pandacss/logger": "1.0.1",
39
+ "@pandacss/shared": "1.0.1",
40
+ "@pandacss/types": "1.0.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@vue/compiler-core": "3.4.19",
44
- "@pandacss/generator": "0.54.0"
44
+ "@pandacss/generator": "1.0.1"
45
45
  },
46
46
  "files": [
47
47
  "dist"