vue-hook-optimizer 0.0.45 → 0.0.47

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -550,8 +550,11 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
550
550
  const binding = path1.scope.getBinding(path1.node.name);
551
551
  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)) {
552
552
  if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
553
+ const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
553
554
  watchArgs.forEach((watchArg) => {
554
- graph.edges.get(watchArg.name)?.add(path1.node.name);
555
+ if (!watchArgsNames.includes(path1.node.name)) {
556
+ graph.edges.get(watchArg.name)?.add(path1.node.name);
557
+ }
555
558
  });
556
559
  }
557
560
  const _node = nodeCollection.getNode(path1.node.name);
@@ -947,7 +950,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
947
950
  if (hookName === "watch" && path1.node.value.type === "ObjectExpression") {
948
951
  path1.node.value.properties.forEach((prop) => {
949
952
  if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && (prop.key.type === "Identifier" || prop.key.type === "StringLiteral")) {
950
- const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value : "";
953
+ const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value.split(".")[0] : "";
951
954
  const watchArg = tNodes.get(keyName);
952
955
  const _node = nodeCollection.getNode(keyName);
953
956
  if (_node?.info?.used) {
@@ -961,7 +964,7 @@ function analyze3(content, lineOffset = 0, jsx = false) {
961
964
  traverse3(path1.node.value, {
962
965
  MemberExpression(path2) {
963
966
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
964
- if (watchArg) {
967
+ if (watchArg && watchArg.name !== path2.node.property.name) {
965
968
  graph.edges.get(watchArg.name)?.add(path2.node.property.name);
966
969
  }
967
970
  }
@@ -2055,7 +2058,7 @@ function gen(graph, usedNodes) {
2055
2058
  suggestions.push({
2056
2059
  type: "error" /* error */,
2057
2060
  message: `There is a loop call in nodes [${hasCycleResult.cycleNodes.map((node) => node.label).join(",")}], perhaps you can refactor it.`,
2058
- nodeInfo: nodes
2061
+ nodeInfo: hasCycleResult.cycleNodes
2059
2062
  });
2060
2063
  }
2061
2064
  const paths = findLinearPaths(g);