vue-hook-optimizer 0.0.21 → 0.0.23

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
@@ -86285,14 +86285,14 @@ var NodeType = /* @__PURE__ */ ((NodeType3) => {
86285
86285
  })(NodeType || {});
86286
86286
  var NodeCollection = class {
86287
86287
  nodes = /* @__PURE__ */ new Map();
86288
- addNode(label, node2, options = { isComputed: false }) {
86288
+ addNode(label, node2, options = { isComputed: false, isMethod: false }) {
86289
86289
  if (this.nodes.has(label)) {
86290
86290
  return;
86291
86291
  }
86292
86292
  if (!options.isComputed && (node2.type === "VariableDeclarator" && [
86293
86293
  "ArrowFunctionExpression",
86294
86294
  "FunctionDeclaration"
86295
- ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
86295
+ ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod") || options.isMethod) {
86296
86296
  this.nodes.set(label, {
86297
86297
  label,
86298
86298
  type: "fun" /* fun */
@@ -86355,6 +86355,17 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86355
86355
  }
86356
86356
  }
86357
86357
  }
86358
+ if (element?.type === "RestElement" && element.argument.type === "Identifier") {
86359
+ const name = element.argument.name;
86360
+ const binding2 = path2.scope.getBinding(name);
86361
+ if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent) && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86362
+ graph.nodes.add(name);
86363
+ nodeCollection.addNode(name, declaration2);
86364
+ if (!graph.edges.get(name)) {
86365
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86366
+ }
86367
+ }
86368
+ }
86358
86369
  });
86359
86370
  }
86360
86371
  if (declaration2.id.type === "ObjectPattern") {
@@ -86370,6 +86381,17 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86370
86381
  }
86371
86382
  }
86372
86383
  }
86384
+ if (property.type === "RestElement" && property.argument.type === "Identifier") {
86385
+ const name = property.argument.name;
86386
+ const binding2 = path2.scope.getBinding(name);
86387
+ if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent) && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86388
+ graph.nodes.add(name);
86389
+ nodeCollection.addNode(name, declaration2);
86390
+ if (!graph.edges.get(name)) {
86391
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86392
+ }
86393
+ }
86394
+ }
86373
86395
  });
86374
86396
  }
86375
86397
  if (declaration2.id?.type === "Identifier") {
@@ -86601,6 +86623,29 @@ function analyze3(content) {
86601
86623
  traverse3(node2, {
86602
86624
  ObjectProperty(path1) {
86603
86625
  if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86626
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && path1.node.value.type === "ArrowFunctionExpression") {
86627
+ const dataNode = path1.node.value;
86628
+ traverse3(dataNode, {
86629
+ ReturnStatement(path22) {
86630
+ if (path22.parent == dataNode.body) {
86631
+ if (path22.node.argument?.type === "ObjectExpression") {
86632
+ path22.node.argument.properties.forEach((prop) => {
86633
+ if (prop.type === "ObjectProperty") {
86634
+ if (prop.key.type === "Identifier") {
86635
+ const name = prop.key.name;
86636
+ graph.nodes.add(name);
86637
+ nodeCollection.addNode(name, prop);
86638
+ if (!graph.edges.get(name)) {
86639
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86640
+ }
86641
+ }
86642
+ }
86643
+ });
86644
+ }
86645
+ }
86646
+ }
86647
+ }, path1.scope, path1);
86648
+ }
86604
86649
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
86605
86650
  const computedNode = path1.node;
86606
86651
  if (computedNode.value.type === "ObjectExpression") {
@@ -86624,11 +86669,11 @@ function analyze3(content) {
86624
86669
  const methodsNode = path1.node;
86625
86670
  if (methodsNode.value.type === "ObjectExpression") {
86626
86671
  methodsNode.value.properties.forEach((prop) => {
86627
- if (prop.type === "ObjectMethod") {
86672
+ if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
86628
86673
  if (prop.key.type === "Identifier") {
86629
86674
  const name = prop.key.name;
86630
86675
  graph.nodes.add(name);
86631
- nodeCollection.addNode(name, prop);
86676
+ nodeCollection.addNode(name, prop, { isMethod: true });
86632
86677
  if (!graph.edges.get(name)) {
86633
86678
  graph.edges.set(name, /* @__PURE__ */ new Set());
86634
86679
  }
@@ -86886,15 +86931,6 @@ function noIndegreeFilter(graph) {
86886
86931
  });
86887
86932
  return nodes.filter((node2) => indegree.get(node2) === 0);
86888
86933
  }
86889
- function noOutdegreeFilter(graph) {
86890
- const zeroOutdegreeNodes = [];
86891
- for (let [node2, edges] of graph.entries()) {
86892
- if (edges.size === 0) {
86893
- zeroOutdegreeNodes.push(node2);
86894
- }
86895
- }
86896
- return zeroOutdegreeNodes;
86897
- }
86898
86934
  function removeVariable(graph, targets) {
86899
86935
  const newTarget = /* @__PURE__ */ new Set();
86900
86936
  targets.forEach((target) => {
@@ -87064,15 +87100,6 @@ function gen(graph, usedNodes) {
87064
87100
  });
87065
87101
  }
87066
87102
  });
87067
- const noOutdegreeNodes = noOutdegreeFilter(graph.edges);
87068
- noOutdegreeNodes.forEach((node2) => {
87069
- if (!usedNodes.has(node2.label)) {
87070
- suggestions.push({
87071
- type: "info" /* info */,
87072
- message: `Node [${node2.label}] is not used, perhaps you can remove it.`
87073
- });
87074
- }
87075
- });
87076
87103
  return suggestions;
87077
87104
  }
87078
87105