vue-hook-optimizer 0.0.75 → 0.0.77

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
@@ -159,6 +159,21 @@ function getRelationType(path) {
159
159
  // src/analyze/setupScript.ts
160
160
  var traverse = _traverse.default?.default || _traverse.default || _traverse;
161
161
  var ignoreFunctionsName = ["defineProps", "defineEmits", "withDefaults"];
162
+ var watchHooks = [
163
+ "watch",
164
+ // from `@vueuse/core`
165
+ "watchArray",
166
+ "watchAtMost",
167
+ "watchDebounced",
168
+ "watchDeep",
169
+ "watchIgnorable",
170
+ "watchImmediate",
171
+ "watchOnce",
172
+ "watchPausable",
173
+ "watchThrottled",
174
+ "watchTriggerable",
175
+ "watchWithFilter"
176
+ ];
162
177
  function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
163
178
  const spread = _spread || [];
164
179
  const nodeCollection = new NodeCollection(_lineOffset);
@@ -345,7 +360,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
345
360
  }
346
361
  }
347
362
  }, patentScope, node);
348
- } else if (hookName === "watch") {
363
+ } else if (watchHooks.includes(hookName)) {
349
364
  if (expression.arguments[0].type === "Identifier") {
350
365
  const binding = patentScope.getBinding(expression.arguments[0].name);
351
366
  if (graph.nodes.has(expression.arguments[0].name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -372,7 +387,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
372
387
  }, patentScope, node);
373
388
  }
374
389
  expression.arguments.forEach((argNode, index) => {
375
- if (hookName === "watch" && index === 0 && argNode.type === "Identifier") {
390
+ if (watchHooks.includes(hookName) && index === 0 && argNode.type === "Identifier") {
376
391
  const _node = nodeCollection.getNode(argNode.name);
377
392
  if (_node?.info?.used) {
378
393
  _node?.info?.used?.add(hookName);
@@ -402,7 +417,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
402
417
  Identifier(path1) {
403
418
  const binding = path1.scope.getBinding(path1.node.name);
404
419
  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)) {
405
- if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
420
+ if ([...watchHooks, "useEffect"].includes(hookName) && watchArgs.size > 0) {
406
421
  const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
407
422
  watchArgs.forEach((watchArg) => {
408
423
  if (!watchArgsNames.includes(path1.node.name)) {
@@ -524,7 +539,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
524
539
  "ArrowFunctionExpression",
525
540
  "FunctionDeclaration"
526
541
  ].includes(path.node.init.type) && path.node.id.type === "Identifier") {
527
- if (path.node.init.type === "CallExpression" && path.node.init.callee.type === "Identifier" && ["watch", "watchEffect"].includes(path.node.init.callee.name)) {
542
+ if (path.node.init.type === "CallExpression" && path.node.init.callee.type === "Identifier" && [...watchHooks, "watchEffect"].includes(path.node.init.callee.name)) {
528
543
  traverseHooks(path.node.init, path.scope);
529
544
  }
530
545
  const name = path.node.id?.name;
@@ -1028,9 +1043,9 @@ function analyze2(content, lineOffset = 0, jsx = false) {
1028
1043
  });
1029
1044
  }
1030
1045
  }
1031
- if (path1.node.key.type === "Identifier" && ["watch", ...vueLifeCycleHooks].includes(path1.node.key.name)) {
1046
+ if (path1.node.key.type === "Identifier" && [...watchHooks, ...vueLifeCycleHooks].includes(path1.node.key.name)) {
1032
1047
  const hookName = path1.node.key.name;
1033
- if (hookName === "watch" && path1.node.value.type === "ObjectExpression") {
1048
+ if (watchHooks.includes(hookName) && path1.node.value.type === "ObjectExpression") {
1034
1049
  path1.node.value.properties.forEach((prop) => {
1035
1050
  if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && (prop.key.type === "Identifier" || prop.key.type === "StringLiteral")) {
1036
1051
  const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value.split(".")[0] : "";
@@ -2084,10 +2099,10 @@ function getMermaidText(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PUR
2084
2099
  });
2085
2100
  graph.edges.forEach((edge, key) => {
2086
2101
  edge.forEach((to) => {
2087
- if (!to) {
2102
+ if (!to || !to.node.label) {
2088
2103
  return;
2089
2104
  }
2090
- mermaidText += ` ${key.label} --> ${to.label}
2105
+ mermaidText += ` ${key.label} --> ${to.node.label}
2091
2106
  `;
2092
2107
  });
2093
2108
  });