vue-hook-optimizer 0.0.64 → 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)) {
@@ -433,38 +387,53 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
433
387
  }
434
388
  return;
435
389
  }
436
- traverse2(argNode, {
437
- Identifier(path1) {
438
- const binding = path1.scope.getBinding(path1.node.name);
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)) {
440
- if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
441
- const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
442
- watchArgs.forEach((watchArg) => {
443
- if (!watchArgsNames.includes(path1.node.name)) {
444
- graph.edges.get(watchArg.name)?.add(path1.node.name);
445
- }
446
- });
447
- }
448
- const _node = nodeCollection.getNode(path1.node.name);
449
- if (_node?.info?.used) {
450
- _node?.info?.used?.add(hookName);
451
- } else if (_node) {
452
- _node.info = {
453
- ..._node?.info,
454
- used: /* @__PURE__ */ new Set([hookName])
455
- };
456
- }
390
+ if (argNode.type === "Identifier") {
391
+ const binding = patentScope.getBinding(argNode.name);
392
+ if (graph.nodes.has(argNode.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
393
+ const _node = nodeCollection.getNode(argNode.name);
394
+ if (_node?.info?.used) {
395
+ _node?.info?.used?.add(hookName);
396
+ } else if (_node) {
397
+ _node.info = {
398
+ ..._node?.info,
399
+ used: /* @__PURE__ */ new Set([hookName])
400
+ };
457
401
  }
458
402
  }
459
- }, patentScope, node);
403
+ } else {
404
+ traverse(argNode, {
405
+ Identifier(path1) {
406
+ const binding = path1.scope.getBinding(path1.node.name);
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)) {
408
+ if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
409
+ const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
410
+ watchArgs.forEach((watchArg) => {
411
+ if (!watchArgsNames.includes(path1.node.name)) {
412
+ graph.edges.get(watchArg.name)?.add(path1.node.name);
413
+ }
414
+ });
415
+ }
416
+ const _node = nodeCollection.getNode(path1.node.name);
417
+ if (_node?.info?.used) {
418
+ _node?.info?.used?.add(hookName);
419
+ } else if (_node) {
420
+ _node.info = {
421
+ ..._node?.info,
422
+ used: /* @__PURE__ */ new Set([hookName])
423
+ };
424
+ }
425
+ }
426
+ }
427
+ }, patentScope, node);
428
+ }
460
429
  });
461
430
  }
462
431
  }
463
- traverse2(ast, {
432
+ traverse(ast, {
464
433
  FunctionDeclaration(path) {
465
434
  const name = path.node.id?.name;
466
435
  if (name && graph.nodes.has(name)) {
467
- traverse2(path.node.body, {
436
+ traverse(path.node.body, {
468
437
  Identifier(path1) {
469
438
  const binding = path1.scope.getBinding(path1.node.name);
470
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)) {
@@ -489,7 +458,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
489
458
  if (element?.type === "Identifier") {
490
459
  const name = element.name;
491
460
  if (name && graph.nodes.has(name) && path.node.init?.type === "CallExpression") {
492
- traverse2(path.node.init, {
461
+ traverse(path.node.init, {
493
462
  Identifier(path1) {
494
463
  const binding = path1.scope.getBinding(path1.node.name);
495
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)) {
@@ -513,7 +482,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
513
482
  if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
514
483
  const name = property.value.name;
515
484
  if (name && graph.nodes.has(name) && path.node.init) {
516
- traverse2(path.node.init, {
485
+ traverse(path.node.init, {
517
486
  Identifier(path1) {
518
487
  const binding = path1.scope.getBinding(path1.node.name);
519
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)) {
@@ -542,7 +511,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
542
511
  }
543
512
  const name = path.node.id?.name;
544
513
  if (name && graph.nodes.has(name)) {
545
- traverse2(path.node.init, {
514
+ traverse(path.node.init, {
546
515
  Identifier(path1) {
547
516
  const binding = path1.scope.getBinding(path1.node.name);
548
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)) {
@@ -567,7 +536,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
567
536
  graph.edges.get(name)?.add(path.node.init.name);
568
537
  }
569
538
  } else {
570
- traverse2(path.node.init, {
539
+ traverse(path.node.init, {
571
540
  Identifier(path1) {
572
541
  const binding = path1.scope.getBinding(path1.node.name);
573
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)) {
@@ -582,7 +551,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
582
551
  ObjectMethod(path) {
583
552
  if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
584
553
  const name = path.node.key.name;
585
- traverse2(path.node.body, {
554
+ traverse(path.node.body, {
586
555
  Identifier(path1) {
587
556
  const binding = path1.scope.getBinding(path1.node.name);
588
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)) {
@@ -603,7 +572,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
603
572
  ObjectProperty(path) {
604
573
  if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
605
574
  const name = path.node.key.name;
606
- traverse2(path.node.value, {
575
+ traverse(path.node.value, {
607
576
  MemberExpression(path1) {
608
577
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
609
578
  const binding = path1.scope.getBinding(path1.node.object.name);
@@ -642,8 +611,8 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
642
611
  nodeCollection
643
612
  };
644
613
  }
645
- function analyze2(content, lineOffset = 0, jsx = false) {
646
- 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: [
647
616
  "typescript",
648
617
  ...jsx ? ["jsx"] : []
649
618
  ] });
@@ -652,9 +621,7 @@ function analyze2(content, lineOffset = 0, jsx = false) {
652
621
  }
653
622
 
654
623
  // src/analyze/options.ts
655
- var import_compiler_sfc3 = require("@vue/compiler-sfc");
656
- var import_traverse3 = __toESM(require("@babel/traverse"));
657
- 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;
658
625
  var vueLifeCycleHooks = [
659
626
  "beforeCreate",
660
627
  "created",
@@ -671,8 +638,8 @@ var vueLifeCycleHooks = [
671
638
  "renderTriggered",
672
639
  "provide"
673
640
  ];
674
- function analyze3(content, lineOffset = 0, jsx = false) {
675
- 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: [
676
643
  "typescript",
677
644
  ...jsx ? ["jsx"] : []
678
645
  ] });
@@ -684,12 +651,12 @@ function analyze3(content, lineOffset = 0, jsx = false) {
684
651
  };
685
652
  const nodesUsedInTemplate = /* @__PURE__ */ new Set();
686
653
  function process(node, path) {
687
- traverse3(node, {
654
+ traverse2(node, {
688
655
  ObjectProperty(path1) {
689
656
  if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
690
657
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
691
658
  const dataNode = path1.node.value;
692
- traverse3(dataNode, {
659
+ traverse2(dataNode, {
693
660
  ReturnStatement(path2) {
694
661
  if (path2.parent === dataNode.body) {
695
662
  if (path2.node.argument?.type === "ObjectExpression") {
@@ -756,10 +723,10 @@ function analyze3(content, lineOffset = 0, jsx = false) {
756
723
  }
757
724
  }
758
725
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "render" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
759
- traverse3(path1.node.value, {
726
+ traverse2(path1.node.value, {
760
727
  ReturnStatement(path2) {
761
728
  const templateNode = path2.node;
762
- traverse3(templateNode, {
729
+ traverse2(templateNode, {
763
730
  MemberExpression(path3) {
764
731
  if (path3.node.object && path3.node.object.type === "ThisExpression") {
765
732
  if (path3.node.property && path3.node.property.type === "Identifier") {
@@ -778,11 +745,11 @@ function analyze3(content, lineOffset = 0, jsx = false) {
778
745
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
779
746
  const setupNode = path1.node;
780
747
  const spread = [];
781
- traverse3(setupNode, {
748
+ traverse2(setupNode, {
782
749
  ReturnStatement(path2) {
783
750
  if (path2.node.argument?.type === "ObjectExpression") {
784
751
  const returnNode = path2.node.argument;
785
- traverse3(returnNode, {
752
+ traverse2(returnNode, {
786
753
  SpreadElement(path3) {
787
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") {
788
755
  spread.push(path3.node.argument.arguments[0].name);
@@ -794,7 +761,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
794
761
  }
795
762
  if (path2.node.argument?.type === "FunctionExpression" || path2.node.argument?.type === "ArrowFunctionExpression") {
796
763
  const templateNode = path2.node.argument.body;
797
- traverse3(templateNode, {
764
+ traverse2(templateNode, {
798
765
  Identifier(path3) {
799
766
  const binding = path3.scope.getBinding(path3.node.name);
800
767
  if (binding?.scope === path1.scope) {
@@ -819,14 +786,14 @@ function analyze3(content, lineOffset = 0, jsx = false) {
819
786
  },
820
787
  nodeCollection: tempNodeCollection
821
788
  } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
822
- traverse3(setupNode, {
789
+ traverse2(setupNode, {
823
790
  ReturnStatement(path2) {
824
791
  if (path2.scope !== path1.scope) {
825
792
  return;
826
793
  }
827
794
  if (path2.node.argument?.type === "ObjectExpression") {
828
795
  const returnNode = path2.node.argument;
829
- traverse3(returnNode, {
796
+ traverse2(returnNode, {
830
797
  ObjectProperty(path3) {
831
798
  if (path3.parent === returnNode) {
832
799
  if (path3.node.key.type === "Identifier" && path3.node.value.type === "Identifier" && tempNodes.has(path3.node.value.name)) {
@@ -894,7 +861,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
894
861
  }
895
862
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
896
863
  const dataNode = path1.node;
897
- traverse3(dataNode, {
864
+ traverse2(dataNode, {
898
865
  ReturnStatement(path2) {
899
866
  if (path2.parent === dataNode.body) {
900
867
  if (path2.node.argument?.type === "ObjectExpression") {
@@ -919,10 +886,10 @@ function analyze3(content, lineOffset = 0, jsx = false) {
919
886
  }, path1.scope, path1);
920
887
  }
921
888
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "render") {
922
- traverse3(path1.node, {
889
+ traverse2(path1.node, {
923
890
  ReturnStatement(path2) {
924
891
  const templateNode = path2.node;
925
- traverse3(templateNode, {
892
+ traverse2(templateNode, {
926
893
  MemberExpression(path3) {
927
894
  if (path3.node.object && path3.node.object.type === "ThisExpression") {
928
895
  if (path3.node.property && path3.node.property.type === "Identifier") {
@@ -937,12 +904,12 @@ function analyze3(content, lineOffset = 0, jsx = false) {
937
904
  }
938
905
  }
939
906
  }, path.scope, path);
940
- traverse3(node, {
907
+ traverse2(node, {
941
908
  ObjectMethod(path1) {
942
909
  if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
943
910
  if (path1.node.key.type === "Identifier" && vueLifeCycleHooks.includes(path1.node.key.name)) {
944
911
  const hookName = path1.node.key.name;
945
- traverse3(path1.node.body, {
912
+ traverse2(path1.node.body, {
946
913
  MemberExpression(path2) {
947
914
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
948
915
  const _node = nodeCollection.getNode(path2.node.property.name);
@@ -968,7 +935,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
968
935
  computedNode.value.properties.forEach((prop) => {
969
936
  if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
970
937
  const name = prop.key.name;
971
- traverse3(prop, {
938
+ traverse2(prop, {
972
939
  MemberExpression(path2) {
973
940
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
974
941
  graph.edges.get(name)?.add(path2.node.property.name);
@@ -980,7 +947,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
980
947
  const name = prop.key.name;
981
948
  prop.value.properties.forEach((prop1) => {
982
949
  if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") {
983
- traverse3(prop1, {
950
+ traverse2(prop1, {
984
951
  MemberExpression(path2) {
985
952
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
986
953
  graph.edges.get(name)?.add(path2.node.property.name);
@@ -999,7 +966,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
999
966
  methodsNode.value.properties.forEach((prop) => {
1000
967
  if ((prop.type === "ObjectMethod" || prop.type === "ObjectProperty") && prop.key.type === "Identifier") {
1001
968
  const name = prop.key.name;
1002
- traverse3(prop, {
969
+ traverse2(prop, {
1003
970
  MemberExpression(path2) {
1004
971
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1005
972
  graph.edges.get(name)?.add(path2.node.property.name);
@@ -1026,7 +993,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1026
993
  used: /* @__PURE__ */ new Set([hookName])
1027
994
  };
1028
995
  }
1029
- traverse3(path1.node.value, {
996
+ traverse2(path1.node.value, {
1030
997
  MemberExpression(path2) {
1031
998
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1032
999
  if (watchArg && watchArg.name !== path2.node.property.name) {
@@ -1038,7 +1005,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1038
1005
  }
1039
1006
  });
1040
1007
  } else {
1041
- traverse3(path1.node.value, {
1008
+ traverse2(path1.node.value, {
1042
1009
  MemberExpression(path2) {
1043
1010
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1044
1011
  const _node = nodeCollection.getNode(path2.node.property.name);
@@ -1059,7 +1026,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1059
1026
  }
1060
1027
  }, path.scope, path);
1061
1028
  }
1062
- traverse3(ast, {
1029
+ traverse2(ast, {
1063
1030
  ExportDefaultDeclaration(path) {
1064
1031
  if (path.node.declaration.type === "ObjectExpression") {
1065
1032
  process(path.node.declaration, path);
@@ -1074,6 +1041,117 @@ function analyze3(content, lineOffset = 0, jsx = false) {
1074
1041
  };
1075
1042
  }
1076
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
+
1077
1155
  // src/analyze/tsx.ts
1078
1156
  var import_compiler_sfc4 = require("@vue/compiler-sfc");
1079
1157
 
@@ -1906,7 +1984,7 @@ function processTsx(params) {
1906
1984
  });
1907
1985
  return result;
1908
1986
  }
1909
- function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
1987
+ function analyze5(content, type = "vue", lineOffset = 0, addInfo = true) {
1910
1988
  const ast = (0, import_compiler_sfc4.babelParse)(content, { sourceType: "module", plugins: [
1911
1989
  "typescript",
1912
1990
  "jsx"
@@ -1923,121 +2001,32 @@ function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
1923
2001
  };
1924
2002
  }
1925
2003
 
1926
- // src/analyze/style.ts
1927
- function lexBinding(content, start) {
1928
- let state = 0 /* inParens */;
1929
- let parenDepth = 0;
1930
- for (let i = start; i < content.length; i++) {
1931
- const char = content.charAt(i);
1932
- switch (state) {
1933
- case 0 /* inParens */:
1934
- if (char === "'") {
1935
- state = 1 /* inSingleQuoteString */;
1936
- } else if (char === '"') {
1937
- state = 2 /* inDoubleQuoteString */;
1938
- } else if (char === "(") {
1939
- parenDepth++;
1940
- } else if (char === ")") {
1941
- if (parenDepth > 0) {
1942
- parenDepth--;
1943
- } else {
1944
- return i;
1945
- }
1946
- }
1947
- break;
1948
- case 1 /* inSingleQuoteString */:
1949
- if (char === "'") {
1950
- state = 0 /* inParens */;
1951
- }
1952
- break;
1953
- case 2 /* inDoubleQuoteString */:
1954
- if (char === '"') {
1955
- state = 0 /* inParens */;
1956
- }
1957
- break;
1958
- }
1959
- }
1960
- return null;
1961
- }
1962
- function normalizeExpression(exp) {
1963
- exp = exp.trim();
1964
- if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
1965
- return exp.slice(1, -1);
1966
- }
1967
- return exp;
1968
- }
1969
- var vBindRE = /v-bind\s*\(/g;
1970
- function analyze5(styles) {
1971
- const nodes = /* @__PURE__ */ new Set();
1972
- styles.forEach((style) => {
1973
- let match;
1974
- const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
1975
- while (match = vBindRE.exec(content)) {
1976
- const start = match.index + match[0].length;
1977
- const end = lexBinding(content, start);
1978
- if (end !== null) {
1979
- const variable = normalizeExpression(content.slice(start, end));
1980
- nodes.add(variable);
1981
- }
1982
- }
1983
- });
1984
- return nodes;
1985
- }
1986
-
1987
- // src/suggest/split.ts
1988
- function dfs(graph, node, targets, visited, component) {
1989
- component.add(node);
1990
- visited.add(node);
1991
- targets.forEach((target) => {
1992
- if (!visited.has(target)) {
1993
- dfs(graph, target, graph.get(target) || /* @__PURE__ */ new Set(), visited, component);
1994
- }
1995
- });
1996
- }
1997
- function haveIntersection(setA, setB) {
1998
- for (const item of setA) {
1999
- if (setB.has(item)) {
2000
- return true;
2001
- }
2002
- }
2003
- return false;
2004
- }
2005
- function mergeSets(arr) {
2006
- let result = [...arr];
2007
- for (let i = 0; i < result.length; i++) {
2008
- for (let j = i + 1; j < result.length; j++) {
2009
- if (haveIntersection(result[i], result[j])) {
2010
- const newSet = /* @__PURE__ */ new Set([...result[i], ...result[j]]);
2011
- result.splice(j, 1);
2012
- result.splice(i, 1);
2013
- result = [...result, newSet];
2014
- return mergeSets(result);
2015
- }
2016
- }
2017
- }
2018
- return result;
2019
- }
2020
- function splitGraph(graph) {
2021
- const components = [];
2022
- const sorted = Array.from(graph).sort((a, b) => b[1].size - a[1].size);
2023
- new Map(sorted).forEach((targets, node) => {
2024
- const visited = /* @__PURE__ */ new Set();
2025
- if (!visited.has(node)) {
2026
- const component = /* @__PURE__ */ new Set();
2027
- dfs(graph, node, targets, visited, component);
2028
- 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
+ `;
2029
2018
  }
2030
2019
  });
2031
- return mergeSets(components).map((component) => {
2032
- const subGraph = /* @__PURE__ */ new Map();
2033
- component.forEach((node) => {
2034
- const targets = graph.get(node);
2035
- if (targets) {
2036
- subGraph.set(node, targets);
2020
+ graph.edges.forEach((edge, key) => {
2021
+ edge.forEach((to) => {
2022
+ if (!to) {
2023
+ return;
2037
2024
  }
2025
+ mermaidText += ` ${key.label} --> ${to.label}
2026
+ `;
2038
2027
  });
2039
- return subGraph;
2040
2028
  });
2029
+ return mermaidText;
2041
2030
  }
2042
2031
 
2043
2032
  // src/suggest/filter.ts
@@ -2165,6 +2154,62 @@ function findArticulationPoints(graph) {
2165
2154
  return ap;
2166
2155
  }
2167
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
+
2168
2213
  // src/suggest/utils.ts
2169
2214
  function hasCycle(graph) {
2170
2215
  const visited = /* @__PURE__ */ new Set();
@@ -2342,6 +2387,9 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
2342
2387
  edges
2343
2388
  };
2344
2389
  }
2390
+
2391
+ // src/index.ts
2392
+ var import_compiler_sfc5 = require("@vue/compiler-sfc");
2345
2393
  // Annotate the CommonJS export names for ESM import in node:
2346
2394
  0 && (module.exports = {
2347
2395
  NodeType,
@@ -2352,6 +2400,7 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
2352
2400
  analyzeTemplate,
2353
2401
  analyzeTsx,
2354
2402
  gen,
2403
+ getMermaidText,
2355
2404
  getVisData,
2356
2405
  parse
2357
2406
  });