vue-hook-optimizer 0.0.65 → 0.0.66

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.js CHANGED
@@ -28,75 +28,29 @@ 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
  NodeType: () => NodeType,
34
34
  SuggestionType: () => SuggestionType,
35
- analyzeOptions: () => analyze3,
36
- analyzeSetupScript: () => analyze2,
37
- analyzeStyle: () => analyze5,
38
- analyzeTemplate: () => analyze,
39
- analyzeTsx: () => analyze4,
35
+ analyzeOptions: () => analyze2,
36
+ analyzeSetupScript: () => analyze,
37
+ analyzeStyle: () => analyze3,
38
+ analyzeTemplate: () => analyze4,
39
+ analyzeTsx: () => analyze5,
40
40
  gen: () => gen,
41
+ getMermaidText: () => getMermaidText,
41
42
  getVisData: () => getVisData,
42
43
  parse: () => import_compiler_sfc5.parse
43
44
  });
44
- module.exports = __toCommonJS(src_exports);
45
- var import_compiler_sfc5 = require("@vue/compiler-sfc");
45
+ module.exports = __toCommonJS(index_exports);
46
46
 
47
- // src/analyze/template.ts
48
- var import_compiler_sfc = require("@vue/compiler-sfc");
49
- var import_traverse = __toESM(require("@babel/traverse"));
50
- var traverse = import_traverse.default.default?.default || import_traverse.default.default || import_traverse.default;
51
- function analyze(content) {
52
- const id = "template";
53
- const { code } = (0, import_compiler_sfc.compileTemplate)({
54
- id,
55
- source: content,
56
- filename: `${id}.js`
57
- });
58
- const ast = (0, import_compiler_sfc.babelParse)(code, { sourceType: "module", plugins: [
59
- "typescript"
60
- ] });
61
- const nodes = /* @__PURE__ */ new Set();
62
- traverse(ast, {
63
- MemberExpression(path) {
64
- if (path.type === "MemberExpression") {
65
- if (path.node.object && path.node.object.type === "Identifier" && path.node.object.name === "_ctx") {
66
- if (path.node.property && path.node.property.type === "Identifier") {
67
- nodes.add(path.node.property.name);
68
- }
69
- }
70
- }
71
- },
72
- ObjectProperty(path) {
73
- if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
74
- if (path.node.value.type === "StringLiteral") {
75
- const name = path.node.value.value;
76
- if (name) {
77
- nodes.add(name);
78
- }
79
- }
80
- }
81
- },
82
- // component
83
- CallExpression(path) {
84
- if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
85
- if (path.node.arguments[0].type === "StringLiteral") {
86
- const name = path.node.arguments[0].value;
87
- if (name) {
88
- nodes.add(name);
89
- }
90
- }
91
- }
92
- }
93
- });
94
- return nodes;
95
- }
47
+ // src/analyze/options.ts
48
+ var import_traverse2 = __toESM(require("@babel/traverse"));
49
+ var import_compiler_sfc2 = require("@vue/compiler-sfc");
96
50
 
97
51
  // src/analyze/setupScript.ts
98
- var import_compiler_sfc2 = require("@vue/compiler-sfc");
99
- var import_traverse2 = __toESM(require("@babel/traverse"));
52
+ var import_traverse = __toESM(require("@babel/traverse"));
53
+ var import_compiler_sfc = require("@vue/compiler-sfc");
100
54
 
101
55
  // src/analyze/utils.ts
102
56
  var NodeType = /* @__PURE__ */ ((NodeType3) => {
@@ -206,7 +160,7 @@ function getComment(node) {
206
160
  }
207
161
 
208
162
  // src/analyze/setupScript.ts
209
- var traverse2 = import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default;
163
+ var traverse = import_traverse.default.default?.default || import_traverse.default.default || import_traverse.default;
210
164
  var ignoreFunctionsName = ["defineProps", "defineEmits", "withDefaults"];
211
165
  function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
212
166
  const spread = _spread || [];
@@ -216,7 +170,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
216
170
  edges: /* @__PURE__ */ new Map(),
217
171
  spread: /* @__PURE__ */ new Map()
218
172
  };
219
- traverse2(ast, {
173
+ traverse(ast, {
220
174
  VariableDeclaration(path) {
221
175
  path.node.declarations.forEach((declaration) => {
222
176
  if (declaration.id.type === "ArrayPattern") {
@@ -378,7 +332,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
378
332
  const expression = node.type === "ExpressionStatement" ? node.expression : node;
379
333
  const watchArgs = /* @__PURE__ */ new Set();
380
334
  if (hookName === "provide") {
381
- traverse2(expression, {
335
+ traverse(expression, {
382
336
  Identifier(path1) {
383
337
  const binding = path1.scope.getBinding(path1.node.name);
384
338
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -401,7 +355,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
401
355
  watchArgs.add(expression.arguments[0]);
402
356
  }
403
357
  } else {
404
- traverse2(expression.arguments[0], {
358
+ traverse(expression.arguments[0], {
405
359
  Identifier(path1) {
406
360
  const binding = path1.scope.getBinding(path1.node.name);
407
361
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -411,7 +365,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
411
365
  }, patentScope, node);
412
366
  }
413
367
  } else if (hookName === "useEffect" && expression.arguments[1].type === "ArrayExpression") {
414
- traverse2(expression.arguments[1], {
368
+ traverse(expression.arguments[1], {
415
369
  Identifier(path1) {
416
370
  const binding = path1.scope.getBinding(path1.node.name);
417
371
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -447,7 +401,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
447
401
  }
448
402
  }
449
403
  } else {
450
- traverse2(argNode, {
404
+ traverse(argNode, {
451
405
  Identifier(path1) {
452
406
  const binding = path1.scope.getBinding(path1.node.name);
453
407
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -475,11 +429,11 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
475
429
  });
476
430
  }
477
431
  }
478
- traverse2(ast, {
432
+ traverse(ast, {
479
433
  FunctionDeclaration(path) {
480
434
  const name = path.node.id?.name;
481
435
  if (name && graph.nodes.has(name)) {
482
- traverse2(path.node.body, {
436
+ traverse(path.node.body, {
483
437
  Identifier(path1) {
484
438
  const binding = path1.scope.getBinding(path1.node.name);
485
439
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -504,7 +458,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
504
458
  if (element?.type === "Identifier") {
505
459
  const name = element.name;
506
460
  if (name && graph.nodes.has(name) && path.node.init?.type === "CallExpression") {
507
- traverse2(path.node.init, {
461
+ traverse(path.node.init, {
508
462
  Identifier(path1) {
509
463
  const binding = path1.scope.getBinding(path1.node.name);
510
464
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -528,7 +482,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
528
482
  if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
529
483
  const name = property.value.name;
530
484
  if (name && graph.nodes.has(name) && path.node.init) {
531
- traverse2(path.node.init, {
485
+ traverse(path.node.init, {
532
486
  Identifier(path1) {
533
487
  const binding = path1.scope.getBinding(path1.node.name);
534
488
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -557,7 +511,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
557
511
  }
558
512
  const name = path.node.id?.name;
559
513
  if (name && graph.nodes.has(name)) {
560
- traverse2(path.node.init, {
514
+ traverse(path.node.init, {
561
515
  Identifier(path1) {
562
516
  const binding = path1.scope.getBinding(path1.node.name);
563
517
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -582,7 +536,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
582
536
  graph.edges.get(name)?.add(path.node.init.name);
583
537
  }
584
538
  } else {
585
- traverse2(path.node.init, {
539
+ traverse(path.node.init, {
586
540
  Identifier(path1) {
587
541
  const binding = path1.scope.getBinding(path1.node.name);
588
542
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -597,7 +551,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
597
551
  ObjectMethod(path) {
598
552
  if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
599
553
  const name = path.node.key.name;
600
- traverse2(path.node.body, {
554
+ traverse(path.node.body, {
601
555
  Identifier(path1) {
602
556
  const binding = path1.scope.getBinding(path1.node.name);
603
557
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -618,7 +572,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
618
572
  ObjectProperty(path) {
619
573
  if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
620
574
  const name = path.node.key.name;
621
- traverse2(path.node.value, {
575
+ traverse(path.node.value, {
622
576
  MemberExpression(path1) {
623
577
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
624
578
  const binding = path1.scope.getBinding(path1.node.object.name);
@@ -657,8 +611,8 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
657
611
  nodeCollection
658
612
  };
659
613
  }
660
- function analyze2(content, lineOffset = 0, jsx = false) {
661
- const ast = (0, import_compiler_sfc2.babelParse)(content, { sourceType: "module", plugins: [
614
+ function analyze(content, lineOffset = 0, jsx = false) {
615
+ const ast = (0, import_compiler_sfc.babelParse)(content, { sourceType: "module", plugins: [
662
616
  "typescript",
663
617
  ...jsx ? ["jsx"] : []
664
618
  ] });
@@ -667,9 +621,7 @@ function analyze2(content, lineOffset = 0, jsx = false) {
667
621
  }
668
622
 
669
623
  // src/analyze/options.ts
670
- var import_compiler_sfc3 = require("@vue/compiler-sfc");
671
- var import_traverse3 = __toESM(require("@babel/traverse"));
672
- var traverse3 = import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default;
624
+ var traverse2 = import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default;
673
625
  var vueLifeCycleHooks = [
674
626
  "beforeCreate",
675
627
  "created",
@@ -686,8 +638,8 @@ var vueLifeCycleHooks = [
686
638
  "renderTriggered",
687
639
  "provide"
688
640
  ];
689
- function analyze3(content, lineOffset = 0, jsx = false) {
690
- const ast = (0, import_compiler_sfc3.babelParse)(content, { sourceType: "module", plugins: [
641
+ function analyze2(content, lineOffset = 0, jsx = false) {
642
+ const ast = (0, import_compiler_sfc2.babelParse)(content, { sourceType: "module", plugins: [
691
643
  "typescript",
692
644
  ...jsx ? ["jsx"] : []
693
645
  ] });
@@ -699,12 +651,12 @@ function analyze3(content, lineOffset = 0, jsx = false) {
699
651
  };
700
652
  const nodesUsedInTemplate = /* @__PURE__ */ new Set();
701
653
  function process(node, path) {
702
- traverse3(node, {
654
+ traverse2(node, {
703
655
  ObjectProperty(path1) {
704
656
  if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
705
657
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
706
658
  const dataNode = path1.node.value;
707
- traverse3(dataNode, {
659
+ traverse2(dataNode, {
708
660
  ReturnStatement(path2) {
709
661
  if (path2.parent === dataNode.body) {
710
662
  if (path2.node.argument?.type === "ObjectExpression") {
@@ -771,10 +723,10 @@ function analyze3(content, lineOffset = 0, jsx = false) {
771
723
  }
772
724
  }
773
725
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "render" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
774
- traverse3(path1.node.value, {
726
+ traverse2(path1.node.value, {
775
727
  ReturnStatement(path2) {
776
728
  const templateNode = path2.node;
777
- traverse3(templateNode, {
729
+ traverse2(templateNode, {
778
730
  MemberExpression(path3) {
779
731
  if (path3.node.object && path3.node.object.type === "ThisExpression") {
780
732
  if (path3.node.property && path3.node.property.type === "Identifier") {
@@ -793,11 +745,11 @@ function analyze3(content, lineOffset = 0, jsx = false) {
793
745
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
794
746
  const setupNode = path1.node;
795
747
  const spread = [];
796
- traverse3(setupNode, {
748
+ traverse2(setupNode, {
797
749
  ReturnStatement(path2) {
798
750
  if (path2.node.argument?.type === "ObjectExpression") {
799
751
  const returnNode = path2.node.argument;
800
- traverse3(returnNode, {
752
+ traverse2(returnNode, {
801
753
  SpreadElement(path3) {
802
754
  if (path3.node.argument.type === "CallExpression" && path3.node.argument.callee.type === "Identifier" && path3.node.argument.callee.name === "toRefs" && path3.node.argument.arguments[0].type === "Identifier") {
803
755
  spread.push(path3.node.argument.arguments[0].name);
@@ -809,7 +761,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
809
761
  }
810
762
  if (path2.node.argument?.type === "FunctionExpression" || path2.node.argument?.type === "ArrowFunctionExpression") {
811
763
  const templateNode = path2.node.argument.body;
812
- traverse3(templateNode, {
764
+ traverse2(templateNode, {
813
765
  Identifier(path3) {
814
766
  const binding = path3.scope.getBinding(path3.node.name);
815
767
  if (binding?.scope === path1.scope) {
@@ -834,14 +786,14 @@ function analyze3(content, lineOffset = 0, jsx = false) {
834
786
  },
835
787
  nodeCollection: tempNodeCollection
836
788
  } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
837
- traverse3(setupNode, {
789
+ traverse2(setupNode, {
838
790
  ReturnStatement(path2) {
839
791
  if (path2.scope !== path1.scope) {
840
792
  return;
841
793
  }
842
794
  if (path2.node.argument?.type === "ObjectExpression") {
843
795
  const returnNode = path2.node.argument;
844
- traverse3(returnNode, {
796
+ traverse2(returnNode, {
845
797
  ObjectProperty(path3) {
846
798
  if (path3.parent === returnNode) {
847
799
  if (path3.node.key.type === "Identifier" && path3.node.value.type === "Identifier" && tempNodes.has(path3.node.value.name)) {
@@ -909,7 +861,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
909
861
  }
910
862
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
911
863
  const dataNode = path1.node;
912
- traverse3(dataNode, {
864
+ traverse2(dataNode, {
913
865
  ReturnStatement(path2) {
914
866
  if (path2.parent === dataNode.body) {
915
867
  if (path2.node.argument?.type === "ObjectExpression") {
@@ -934,10 +886,10 @@ function analyze3(content, lineOffset = 0, jsx = false) {
934
886
  }, path1.scope, path1);
935
887
  }
936
888
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "render") {
937
- traverse3(path1.node, {
889
+ traverse2(path1.node, {
938
890
  ReturnStatement(path2) {
939
891
  const templateNode = path2.node;
940
- traverse3(templateNode, {
892
+ traverse2(templateNode, {
941
893
  MemberExpression(path3) {
942
894
  if (path3.node.object && path3.node.object.type === "ThisExpression") {
943
895
  if (path3.node.property && path3.node.property.type === "Identifier") {
@@ -952,12 +904,12 @@ function analyze3(content, lineOffset = 0, jsx = false) {
952
904
  }
953
905
  }
954
906
  }, path.scope, path);
955
- traverse3(node, {
907
+ traverse2(node, {
956
908
  ObjectMethod(path1) {
957
909
  if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
958
910
  if (path1.node.key.type === "Identifier" && vueLifeCycleHooks.includes(path1.node.key.name)) {
959
911
  const hookName = path1.node.key.name;
960
- traverse3(path1.node.body, {
912
+ traverse2(path1.node.body, {
961
913
  MemberExpression(path2) {
962
914
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
963
915
  const _node = nodeCollection.getNode(path2.node.property.name);
@@ -983,7 +935,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
983
935
  computedNode.value.properties.forEach((prop) => {
984
936
  if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
985
937
  const name = prop.key.name;
986
- traverse3(prop, {
938
+ traverse2(prop, {
987
939
  MemberExpression(path2) {
988
940
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
989
941
  graph.edges.get(name)?.add(path2.node.property.name);
@@ -995,7 +947,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
995
947
  const name = prop.key.name;
996
948
  prop.value.properties.forEach((prop1) => {
997
949
  if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") {
998
- traverse3(prop1, {
950
+ traverse2(prop1, {
999
951
  MemberExpression(path2) {
1000
952
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1001
953
  graph.edges.get(name)?.add(path2.node.property.name);
@@ -1014,7 +966,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1014
966
  methodsNode.value.properties.forEach((prop) => {
1015
967
  if ((prop.type === "ObjectMethod" || prop.type === "ObjectProperty") && prop.key.type === "Identifier") {
1016
968
  const name = prop.key.name;
1017
- traverse3(prop, {
969
+ traverse2(prop, {
1018
970
  MemberExpression(path2) {
1019
971
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1020
972
  graph.edges.get(name)?.add(path2.node.property.name);
@@ -1041,7 +993,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1041
993
  used: /* @__PURE__ */ new Set([hookName])
1042
994
  };
1043
995
  }
1044
- traverse3(path1.node.value, {
996
+ traverse2(path1.node.value, {
1045
997
  MemberExpression(path2) {
1046
998
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1047
999
  if (watchArg && watchArg.name !== path2.node.property.name) {
@@ -1053,7 +1005,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1053
1005
  }
1054
1006
  });
1055
1007
  } else {
1056
- traverse3(path1.node.value, {
1008
+ traverse2(path1.node.value, {
1057
1009
  MemberExpression(path2) {
1058
1010
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1059
1011
  const _node = nodeCollection.getNode(path2.node.property.name);
@@ -1074,7 +1026,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1074
1026
  }
1075
1027
  }, path.scope, path);
1076
1028
  }
1077
- traverse3(ast, {
1029
+ traverse2(ast, {
1078
1030
  ExportDefaultDeclaration(path) {
1079
1031
  if (path.node.declaration.type === "ObjectExpression") {
1080
1032
  process(path.node.declaration, path);
@@ -1089,6 +1041,117 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1089
1041
  };
1090
1042
  }
1091
1043
 
1044
+ // src/analyze/style.ts
1045
+ function lexBinding(content, start) {
1046
+ let state = 0 /* inParens */;
1047
+ let parenDepth = 0;
1048
+ for (let i = start; i < content.length; i++) {
1049
+ const char = content.charAt(i);
1050
+ switch (state) {
1051
+ case 0 /* inParens */:
1052
+ if (char === "'") {
1053
+ state = 1 /* inSingleQuoteString */;
1054
+ } else if (char === '"') {
1055
+ state = 2 /* inDoubleQuoteString */;
1056
+ } else if (char === "(") {
1057
+ parenDepth++;
1058
+ } else if (char === ")") {
1059
+ if (parenDepth > 0) {
1060
+ parenDepth--;
1061
+ } else {
1062
+ return i;
1063
+ }
1064
+ }
1065
+ break;
1066
+ case 1 /* inSingleQuoteString */:
1067
+ if (char === "'") {
1068
+ state = 0 /* inParens */;
1069
+ }
1070
+ break;
1071
+ case 2 /* inDoubleQuoteString */:
1072
+ if (char === '"') {
1073
+ state = 0 /* inParens */;
1074
+ }
1075
+ break;
1076
+ }
1077
+ }
1078
+ return null;
1079
+ }
1080
+ function normalizeExpression(exp) {
1081
+ exp = exp.trim();
1082
+ if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
1083
+ return exp.slice(1, -1);
1084
+ }
1085
+ return exp;
1086
+ }
1087
+ var vBindRE = /v-bind\s*\(/g;
1088
+ function analyze3(styles) {
1089
+ const nodes = /* @__PURE__ */ new Set();
1090
+ styles.forEach((style) => {
1091
+ let match;
1092
+ const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
1093
+ while (match = vBindRE.exec(content)) {
1094
+ const start = match.index + match[0].length;
1095
+ const end = lexBinding(content, start);
1096
+ if (end !== null) {
1097
+ const variable = normalizeExpression(content.slice(start, end));
1098
+ nodes.add(variable);
1099
+ }
1100
+ }
1101
+ });
1102
+ return nodes;
1103
+ }
1104
+
1105
+ // src/analyze/template.ts
1106
+ var import_traverse3 = __toESM(require("@babel/traverse"));
1107
+ var import_compiler_sfc3 = require("@vue/compiler-sfc");
1108
+ var traverse3 = import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default;
1109
+ function analyze4(content) {
1110
+ const id = "template";
1111
+ const { code } = (0, import_compiler_sfc3.compileTemplate)({
1112
+ id,
1113
+ source: content,
1114
+ filename: `${id}.js`
1115
+ });
1116
+ const ast = (0, import_compiler_sfc3.babelParse)(code, { sourceType: "module", plugins: [
1117
+ "typescript"
1118
+ ] });
1119
+ const nodes = /* @__PURE__ */ new Set();
1120
+ traverse3(ast, {
1121
+ MemberExpression(path) {
1122
+ if (path.type === "MemberExpression") {
1123
+ if (path.node.object && path.node.object.type === "Identifier" && path.node.object.name === "_ctx") {
1124
+ if (path.node.property && path.node.property.type === "Identifier") {
1125
+ nodes.add(path.node.property.name);
1126
+ }
1127
+ }
1128
+ }
1129
+ },
1130
+ ObjectProperty(path) {
1131
+ if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
1132
+ if (path.node.value.type === "StringLiteral") {
1133
+ const name = path.node.value.value;
1134
+ if (name) {
1135
+ nodes.add(name);
1136
+ }
1137
+ }
1138
+ }
1139
+ },
1140
+ // component
1141
+ CallExpression(path) {
1142
+ if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
1143
+ if (path.node.arguments[0].type === "StringLiteral") {
1144
+ const name = path.node.arguments[0].value;
1145
+ if (name) {
1146
+ nodes.add(name);
1147
+ }
1148
+ }
1149
+ }
1150
+ }
1151
+ });
1152
+ return nodes;
1153
+ }
1154
+
1092
1155
  // src/analyze/tsx.ts
1093
1156
  var import_compiler_sfc4 = require("@vue/compiler-sfc");
1094
1157
 
@@ -1921,7 +1984,7 @@ function processTsx(params) {
1921
1984
  });
1922
1985
  return result;
1923
1986
  }
1924
- function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
1987
+ function analyze5(content, type = "vue", lineOffset = 0, addInfo = true) {
1925
1988
  const ast = (0, import_compiler_sfc4.babelParse)(content, { sourceType: "module", plugins: [
1926
1989
  "typescript",
1927
1990
  "jsx"
@@ -1938,121 +2001,32 @@ function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
1938
2001
  };
1939
2002
  }
1940
2003
 
1941
- // src/analyze/style.ts
1942
- function lexBinding(content, start) {
1943
- let state = 0 /* inParens */;
1944
- let parenDepth = 0;
1945
- for (let i = start; i < content.length; i++) {
1946
- const char = content.charAt(i);
1947
- switch (state) {
1948
- case 0 /* inParens */:
1949
- if (char === "'") {
1950
- state = 1 /* inSingleQuoteString */;
1951
- } else if (char === '"') {
1952
- state = 2 /* inDoubleQuoteString */;
1953
- } else if (char === "(") {
1954
- parenDepth++;
1955
- } else if (char === ")") {
1956
- if (parenDepth > 0) {
1957
- parenDepth--;
1958
- } else {
1959
- return i;
1960
- }
1961
- }
1962
- break;
1963
- case 1 /* inSingleQuoteString */:
1964
- if (char === "'") {
1965
- state = 0 /* inParens */;
1966
- }
1967
- break;
1968
- case 2 /* inDoubleQuoteString */:
1969
- if (char === '"') {
1970
- state = 0 /* inParens */;
1971
- }
1972
- break;
1973
- }
1974
- }
1975
- return null;
1976
- }
1977
- function normalizeExpression(exp) {
1978
- exp = exp.trim();
1979
- if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
1980
- return exp.slice(1, -1);
1981
- }
1982
- return exp;
1983
- }
1984
- var vBindRE = /v-bind\s*\(/g;
1985
- function analyze5(styles) {
1986
- const nodes = /* @__PURE__ */ new Set();
1987
- styles.forEach((style) => {
1988
- let match;
1989
- const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
1990
- while (match = vBindRE.exec(content)) {
1991
- const start = match.index + match[0].length;
1992
- const end = lexBinding(content, start);
1993
- if (end !== null) {
1994
- const variable = normalizeExpression(content.slice(start, end));
1995
- nodes.add(variable);
1996
- }
1997
- }
1998
- });
1999
- return nodes;
2000
- }
2001
-
2002
- // src/suggest/split.ts
2003
- function dfs(graph, node, targets, visited, component) {
2004
- component.add(node);
2005
- visited.add(node);
2006
- targets.forEach((target) => {
2007
- if (!visited.has(target)) {
2008
- dfs(graph, target, graph.get(target) || /* @__PURE__ */ new Set(), visited, component);
2009
- }
2010
- });
2011
- }
2012
- function haveIntersection(setA, setB) {
2013
- for (const item of setA) {
2014
- if (setB.has(item)) {
2015
- return true;
2016
- }
2017
- }
2018
- return false;
2019
- }
2020
- function mergeSets(arr) {
2021
- let result = [...arr];
2022
- for (let i = 0; i < result.length; i++) {
2023
- for (let j = i + 1; j < result.length; j++) {
2024
- if (haveIntersection(result[i], result[j])) {
2025
- const newSet = /* @__PURE__ */ new Set([...result[i], ...result[j]]);
2026
- result.splice(j, 1);
2027
- result.splice(i, 1);
2028
- result = [...result, newSet];
2029
- return mergeSets(result);
2030
- }
2031
- }
2032
- }
2033
- return result;
2034
- }
2035
- function splitGraph(graph) {
2036
- const components = [];
2037
- const sorted = Array.from(graph).sort((a, b) => b[1].size - a[1].size);
2038
- new Map(sorted).forEach((targets, node) => {
2039
- const visited = /* @__PURE__ */ new Set();
2040
- if (!visited.has(node)) {
2041
- const component = /* @__PURE__ */ new Set();
2042
- dfs(graph, node, targets, visited, component);
2043
- components.push(component);
2004
+ // src/mermaid.ts
2005
+ function getMermaidText(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set(), options = {}) {
2006
+ const direction = options.direction || "TB";
2007
+ const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
2008
+ let mermaidText = `flowchart ${direction}
2009
+ `;
2010
+ graph.nodes.forEach((node) => {
2011
+ const shape = node.type === "var" ? `((${node.label}))` : `{${node.label}}`;
2012
+ const style = usedNodes.has(node.label) || node.info?.used?.size ? `style ${node.label} fill:#e1f5fe` : "";
2013
+ mermaidText += ` ${node.label}${shape}
2014
+ `;
2015
+ if (style) {
2016
+ mermaidText += ` ${style}
2017
+ `;
2044
2018
  }
2045
2019
  });
2046
- return mergeSets(components).map((component) => {
2047
- const subGraph = /* @__PURE__ */ new Map();
2048
- component.forEach((node) => {
2049
- const targets = graph.get(node);
2050
- if (targets) {
2051
- subGraph.set(node, targets);
2020
+ graph.edges.forEach((edge, key) => {
2021
+ edge.forEach((to) => {
2022
+ if (!to) {
2023
+ return;
2052
2024
  }
2025
+ mermaidText += ` ${key.label} --> ${to.label}
2026
+ `;
2053
2027
  });
2054
- return subGraph;
2055
2028
  });
2029
+ return mermaidText;
2056
2030
  }
2057
2031
 
2058
2032
  // src/suggest/filter.ts
@@ -2180,6 +2154,62 @@ function findArticulationPoints(graph) {
2180
2154
  return ap;
2181
2155
  }
2182
2156
 
2157
+ // src/suggest/split.ts
2158
+ function dfs(graph, node, targets, visited, component) {
2159
+ component.add(node);
2160
+ visited.add(node);
2161
+ targets.forEach((target) => {
2162
+ if (!visited.has(target)) {
2163
+ dfs(graph, target, graph.get(target) || /* @__PURE__ */ new Set(), visited, component);
2164
+ }
2165
+ });
2166
+ }
2167
+ function haveIntersection(setA, setB) {
2168
+ for (const item of setA) {
2169
+ if (setB.has(item)) {
2170
+ return true;
2171
+ }
2172
+ }
2173
+ return false;
2174
+ }
2175
+ function mergeSets(arr) {
2176
+ let result = [...arr];
2177
+ for (let i = 0; i < result.length; i++) {
2178
+ for (let j = i + 1; j < result.length; j++) {
2179
+ if (haveIntersection(result[i], result[j])) {
2180
+ const newSet = /* @__PURE__ */ new Set([...result[i], ...result[j]]);
2181
+ result.splice(j, 1);
2182
+ result.splice(i, 1);
2183
+ result = [...result, newSet];
2184
+ return mergeSets(result);
2185
+ }
2186
+ }
2187
+ }
2188
+ return result;
2189
+ }
2190
+ function splitGraph(graph) {
2191
+ const components = [];
2192
+ const sorted = Array.from(graph).sort((a, b) => b[1].size - a[1].size);
2193
+ new Map(sorted).forEach((targets, node) => {
2194
+ const visited = /* @__PURE__ */ new Set();
2195
+ if (!visited.has(node)) {
2196
+ const component = /* @__PURE__ */ new Set();
2197
+ dfs(graph, node, targets, visited, component);
2198
+ components.push(component);
2199
+ }
2200
+ });
2201
+ return mergeSets(components).map((component) => {
2202
+ const subGraph = /* @__PURE__ */ new Map();
2203
+ component.forEach((node) => {
2204
+ const targets = graph.get(node);
2205
+ if (targets) {
2206
+ subGraph.set(node, targets);
2207
+ }
2208
+ });
2209
+ return subGraph;
2210
+ });
2211
+ }
2212
+
2183
2213
  // src/suggest/utils.ts
2184
2214
  function hasCycle(graph) {
2185
2215
  const visited = /* @__PURE__ */ new Set();
@@ -2357,6 +2387,9 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
2357
2387
  edges
2358
2388
  };
2359
2389
  }
2390
+
2391
+ // src/index.ts
2392
+ var import_compiler_sfc5 = require("@vue/compiler-sfc");
2360
2393
  // Annotate the CommonJS export names for ESM import in node:
2361
2394
  0 && (module.exports = {
2362
2395
  NodeType,
@@ -2367,6 +2400,7 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
2367
2400
  analyzeTemplate,
2368
2401
  analyzeTsx,
2369
2402
  gen,
2403
+ getMermaidText,
2370
2404
  getVisData,
2371
2405
  parse
2372
2406
  });