vue-hook-optimizer 0.0.64 → 0.0.65

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -433,30 +433,45 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
433
433
  }
434
434
  return;
435
435
  }
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
- }
436
+ if (argNode.type === "Identifier") {
437
+ const binding = patentScope.getBinding(argNode.name);
438
+ if (graph.nodes.has(argNode.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
439
+ const _node = nodeCollection.getNode(argNode.name);
440
+ if (_node?.info?.used) {
441
+ _node?.info?.used?.add(hookName);
442
+ } else if (_node) {
443
+ _node.info = {
444
+ ..._node?.info,
445
+ used: /* @__PURE__ */ new Set([hookName])
446
+ };
457
447
  }
458
448
  }
459
- }, patentScope, node);
449
+ } else {
450
+ traverse2(argNode, {
451
+ Identifier(path1) {
452
+ const binding = path1.scope.getBinding(path1.node.name);
453
+ 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)) {
454
+ if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
455
+ const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
456
+ watchArgs.forEach((watchArg) => {
457
+ if (!watchArgsNames.includes(path1.node.name)) {
458
+ graph.edges.get(watchArg.name)?.add(path1.node.name);
459
+ }
460
+ });
461
+ }
462
+ const _node = nodeCollection.getNode(path1.node.name);
463
+ if (_node?.info?.used) {
464
+ _node?.info?.used?.add(hookName);
465
+ } else if (_node) {
466
+ _node.info = {
467
+ ..._node?.info,
468
+ used: /* @__PURE__ */ new Set([hookName])
469
+ };
470
+ }
471
+ }
472
+ }
473
+ }, patentScope, node);
474
+ }
460
475
  });
461
476
  }
462
477
  }