vue-hook-optimizer 0.0.45 → 0.0.47

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.mjs CHANGED
@@ -508,8 +508,11 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
508
508
  const binding = path1.scope.getBinding(path1.node.name);
509
509
  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)) {
510
510
  if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
511
+ const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
511
512
  watchArgs.forEach((watchArg) => {
512
- graph.edges.get(watchArg.name)?.add(path1.node.name);
513
+ if (!watchArgsNames.includes(path1.node.name)) {
514
+ graph.edges.get(watchArg.name)?.add(path1.node.name);
515
+ }
513
516
  });
514
517
  }
515
518
  const _node = nodeCollection.getNode(path1.node.name);
@@ -905,7 +908,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
905
908
  if (hookName === "watch" && path1.node.value.type === "ObjectExpression") {
906
909
  path1.node.value.properties.forEach((prop) => {
907
910
  if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && (prop.key.type === "Identifier" || prop.key.type === "StringLiteral")) {
908
- const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value : "";
911
+ const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value.split(".")[0] : "";
909
912
  const watchArg = tNodes.get(keyName);
910
913
  const _node = nodeCollection.getNode(keyName);
911
914
  if (_node?.info?.used) {
@@ -919,7 +922,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
919
922
  traverse3(path1.node.value, {
920
923
  MemberExpression(path2) {
921
924
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
922
- if (watchArg) {
925
+ if (watchArg && watchArg.name !== path2.node.property.name) {
923
926
  graph.edges.get(watchArg.name)?.add(path2.node.property.name);
924
927
  }
925
928
  }
@@ -2013,7 +2016,7 @@ function gen(graph, usedNodes) {
2013
2016
  suggestions.push({
2014
2017
  type: "error" /* error */,
2015
2018
  message: `There is a loop call in nodes [${hasCycleResult.cycleNodes.map((node) => node.label).join(",")}], perhaps you can refactor it.`,
2016
- nodeInfo: nodes
2019
+ nodeInfo: hasCycleResult.cycleNodes
2017
2020
  });
2018
2021
  }
2019
2022
  const paths = findLinearPaths(g);