vue-hook-optimizer 0.0.45 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
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
  }