vue-hook-optimizer 0.0.74 → 0.0.76

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
@@ -205,6 +205,21 @@ function getRelationType(path) {
205
205
  // src/analyze/setupScript.ts
206
206
  var traverse = import_traverse.default.default?.default || import_traverse.default.default || import_traverse.default;
207
207
  var ignoreFunctionsName = ["defineProps", "defineEmits", "withDefaults"];
208
+ var watchHooks = [
209
+ "watch",
210
+ // from `@vueuse/core`
211
+ "watchArray",
212
+ "watchAtMost",
213
+ "watchDebounced",
214
+ "watchDeep",
215
+ "watchIgnorable",
216
+ "watchImmediate",
217
+ "watchOnce",
218
+ "watchPausable",
219
+ "watchThrottled",
220
+ "watchTriggerable",
221
+ "watchWithFilter"
222
+ ];
208
223
  function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
209
224
  const spread = _spread || [];
210
225
  const nodeCollection = new NodeCollection(_lineOffset);
@@ -391,7 +406,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
391
406
  }
392
407
  }
393
408
  }, patentScope, node);
394
- } else if (hookName === "watch") {
409
+ } else if (watchHooks.includes(hookName)) {
395
410
  if (expression.arguments[0].type === "Identifier") {
396
411
  const binding = patentScope.getBinding(expression.arguments[0].name);
397
412
  if (graph.nodes.has(expression.arguments[0].name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -418,7 +433,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
418
433
  }, patentScope, node);
419
434
  }
420
435
  expression.arguments.forEach((argNode, index) => {
421
- if (hookName === "watch" && index === 0 && argNode.type === "Identifier") {
436
+ if (watchHooks.includes(hookName) && index === 0 && argNode.type === "Identifier") {
422
437
  const _node = nodeCollection.getNode(argNode.name);
423
438
  if (_node?.info?.used) {
424
439
  _node?.info?.used?.add(hookName);
@@ -448,7 +463,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
448
463
  Identifier(path1) {
449
464
  const binding = path1.scope.getBinding(path1.node.name);
450
465
  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)) {
451
- if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
466
+ if ([...watchHooks, "useEffect"].includes(hookName) && watchArgs.size > 0) {
452
467
  const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
453
468
  watchArgs.forEach((watchArg) => {
454
469
  if (!watchArgsNames.includes(path1.node.name)) {
@@ -570,7 +585,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
570
585
  "ArrowFunctionExpression",
571
586
  "FunctionDeclaration"
572
587
  ].includes(path.node.init.type) && path.node.id.type === "Identifier") {
573
- if (path.node.init.type === "CallExpression" && path.node.init.callee.type === "Identifier" && ["watch", "watchEffect"].includes(path.node.init.callee.name)) {
588
+ if (path.node.init.type === "CallExpression" && path.node.init.callee.type === "Identifier" && [...watchHooks, "watchEffect"].includes(path.node.init.callee.name)) {
574
589
  traverseHooks(path.node.init, path.scope);
575
590
  }
576
591
  const name = path.node.id?.name;
@@ -1074,9 +1089,9 @@ function analyze2(content, lineOffset = 0, jsx = false) {
1074
1089
  });
1075
1090
  }
1076
1091
  }
1077
- if (path1.node.key.type === "Identifier" && ["watch", ...vueLifeCycleHooks].includes(path1.node.key.name)) {
1092
+ if (path1.node.key.type === "Identifier" && [...watchHooks, ...vueLifeCycleHooks].includes(path1.node.key.name)) {
1078
1093
  const hookName = path1.node.key.name;
1079
- if (hookName === "watch" && path1.node.value.type === "ObjectExpression") {
1094
+ if (watchHooks.includes(hookName) && path1.node.value.type === "ObjectExpression") {
1080
1095
  path1.node.value.properties.forEach((prop) => {
1081
1096
  if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && (prop.key.type === "Identifier" || prop.key.type === "StringLiteral")) {
1082
1097
  const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value.split(".")[0] : "";