vue-hook-optimizer 0.0.22 → 0.0.24

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
@@ -86271,30 +86271,45 @@ var NodeType = /* @__PURE__ */ ((NodeType3) => {
86271
86271
  return NodeType3;
86272
86272
  })(NodeType || {});
86273
86273
  var NodeCollection = class {
86274
+ lineOffset = 0;
86275
+ constructor(_lineOffset = 0) {
86276
+ this.lineOffset = _lineOffset;
86277
+ }
86274
86278
  nodes = /* @__PURE__ */ new Map();
86275
- addNode(label, node2, options = { isComputed: false }) {
86279
+ addNode(label, node2, options = { isComputed: false, isMethod: false }) {
86276
86280
  if (this.nodes.has(label)) {
86277
86281
  return;
86278
86282
  }
86279
86283
  if (!options.isComputed && (node2.type === "VariableDeclarator" && [
86280
86284
  "ArrowFunctionExpression",
86281
86285
  "FunctionDeclaration"
86282
- ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
86286
+ ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod") || options.isMethod) {
86283
86287
  this.nodes.set(label, {
86284
86288
  label,
86285
- type: "fun" /* fun */
86289
+ type: "fun" /* fun */,
86290
+ info: {
86291
+ line: (node2.loc?.start.line || 1) - 1 + this.lineOffset,
86292
+ column: node2.loc?.start.column || 0
86293
+ }
86286
86294
  });
86287
86295
  } else {
86288
86296
  this.nodes.set(label, {
86289
86297
  label,
86290
- type: "var" /* var */
86298
+ type: "var" /* var */,
86299
+ info: {
86300
+ line: (node2.loc?.start.line || 1) - 1 + this.lineOffset,
86301
+ column: node2.loc?.start.column || 0
86302
+ }
86291
86303
  });
86292
86304
  }
86293
86305
  }
86294
86306
  addTypedNode(label, node2) {
86295
86307
  this.nodes.set(label, {
86296
86308
  label,
86297
- type: node2.type
86309
+ type: node2.type,
86310
+ info: {
86311
+ ...node2.info || {}
86312
+ }
86298
86313
  });
86299
86314
  }
86300
86315
  map(graph) {
@@ -86318,9 +86333,9 @@ var traverse2 = (
86318
86333
  //@ts-ignore
86319
86334
  import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
86320
86335
  );
86321
- function processSetup(ast, parentScope, parentPath, _spread) {
86336
+ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
86322
86337
  const spread = _spread || [];
86323
- const nodeCollection = new NodeCollection();
86338
+ const nodeCollection = new NodeCollection(_lineOffset);
86324
86339
  const graph = {
86325
86340
  nodes: /* @__PURE__ */ new Set(),
86326
86341
  edges: /* @__PURE__ */ new Map(),
@@ -86336,7 +86351,18 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86336
86351
  const binding2 = path2.scope.getBinding(name);
86337
86352
  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))) {
86338
86353
  graph.nodes.add(name);
86339
- nodeCollection.addNode(name, declaration2);
86354
+ nodeCollection.addNode(name, element);
86355
+ if (!graph.edges.get(name)) {
86356
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86357
+ }
86358
+ }
86359
+ }
86360
+ if (element?.type === "RestElement" && element.argument.type === "Identifier") {
86361
+ const name = element.argument.name;
86362
+ const binding2 = path2.scope.getBinding(name);
86363
+ 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))) {
86364
+ graph.nodes.add(name);
86365
+ nodeCollection.addNode(name, element.argument);
86340
86366
  if (!graph.edges.get(name)) {
86341
86367
  graph.edges.set(name, /* @__PURE__ */ new Set());
86342
86368
  }
@@ -86351,7 +86377,18 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86351
86377
  const binding2 = path2.scope.getBinding(name);
86352
86378
  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))) {
86353
86379
  graph.nodes.add(name);
86354
- nodeCollection.addNode(name, declaration2);
86380
+ nodeCollection.addNode(name, property.value);
86381
+ if (!graph.edges.get(name)) {
86382
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86383
+ }
86384
+ }
86385
+ }
86386
+ if (property.type === "RestElement" && property.argument.type === "Identifier") {
86387
+ const name = property.argument.name;
86388
+ const binding2 = path2.scope.getBinding(name);
86389
+ 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))) {
86390
+ graph.nodes.add(name);
86391
+ nodeCollection.addNode(name, property.argument);
86355
86392
  if (!graph.edges.get(name)) {
86356
86393
  graph.edges.set(name, /* @__PURE__ */ new Set());
86357
86394
  }
@@ -86421,7 +86458,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86421
86458
  const binding2 = path2.scope.getBinding(name);
86422
86459
  if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
86423
86460
  graph.nodes.add(name);
86424
- nodeCollection.addNode(name, path2.node);
86461
+ nodeCollection.addNode(name, path2.node.id, { isMethod: true });
86425
86462
  if (!graph.edges.get(name)) {
86426
86463
  graph.edges.set(name, /* @__PURE__ */ new Set());
86427
86464
  }
@@ -86555,14 +86592,14 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86555
86592
  nodeCollection
86556
86593
  };
86557
86594
  }
86558
- function analyze2(content) {
86595
+ function analyze2(content, lineOffset = 0) {
86559
86596
  const ast = parse_1$1(content, {
86560
86597
  sourceType: "module",
86561
86598
  plugins: [
86562
86599
  "typescript"
86563
86600
  ]
86564
86601
  });
86565
- const { graph, nodeCollection } = processSetup(ast);
86602
+ const { graph, nodeCollection } = processSetup(ast, void 0, void 0, void 0, lineOffset);
86566
86603
  return nodeCollection.map(graph);
86567
86604
  }
86568
86605
 
@@ -86572,14 +86609,14 @@ var traverse3 = (
86572
86609
  //@ts-ignore
86573
86610
  import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
86574
86611
  );
86575
- function analyze3(content) {
86612
+ function analyze3(content, lineOffset = 0) {
86576
86613
  const ast = parse_1$1(content, {
86577
86614
  sourceType: "module",
86578
86615
  plugins: [
86579
86616
  "typescript"
86580
86617
  ]
86581
86618
  });
86582
- const nodeCollection = new NodeCollection();
86619
+ const nodeCollection = new NodeCollection(lineOffset);
86583
86620
  const graph = {
86584
86621
  nodes: /* @__PURE__ */ new Set(),
86585
86622
  edges: /* @__PURE__ */ new Map()
@@ -86588,6 +86625,29 @@ function analyze3(content) {
86588
86625
  traverse3(node2, {
86589
86626
  ObjectProperty(path1) {
86590
86627
  if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86628
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && path1.node.value.type === "ArrowFunctionExpression") {
86629
+ const dataNode = path1.node.value;
86630
+ traverse3(dataNode, {
86631
+ ReturnStatement(path22) {
86632
+ if (path22.parent == dataNode.body) {
86633
+ if (path22.node.argument?.type === "ObjectExpression") {
86634
+ path22.node.argument.properties.forEach((prop) => {
86635
+ if (prop.type === "ObjectProperty") {
86636
+ if (prop.key.type === "Identifier") {
86637
+ const name = prop.key.name;
86638
+ graph.nodes.add(name);
86639
+ nodeCollection.addNode(name, prop);
86640
+ if (!graph.edges.get(name)) {
86641
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86642
+ }
86643
+ }
86644
+ }
86645
+ });
86646
+ }
86647
+ }
86648
+ }
86649
+ }, path1.scope, path1);
86650
+ }
86591
86651
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
86592
86652
  const computedNode = path1.node;
86593
86653
  if (computedNode.value.type === "ObjectExpression") {
@@ -86611,11 +86671,11 @@ function analyze3(content) {
86611
86671
  const methodsNode = path1.node;
86612
86672
  if (methodsNode.value.type === "ObjectExpression") {
86613
86673
  methodsNode.value.properties.forEach((prop) => {
86614
- if (prop.type === "ObjectMethod") {
86674
+ if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
86615
86675
  if (prop.key.type === "Identifier") {
86616
86676
  const name = prop.key.name;
86617
86677
  graph.nodes.add(name);
86618
- nodeCollection.addNode(name, prop);
86678
+ nodeCollection.addNode(name, prop, { isMethod: true });
86619
86679
  if (!graph.edges.get(name)) {
86620
86680
  graph.edges.set(name, /* @__PURE__ */ new Set());
86621
86681
  }
@@ -86654,7 +86714,7 @@ function analyze3(content) {
86654
86714
  spread: tempSpread
86655
86715
  },
86656
86716
  nodeCollection: tempNodeCollection
86657
- } = processSetup(setupNode, path1.scope, setupNode, spread);
86717
+ } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
86658
86718
  traverse3(setupNode, {
86659
86719
  ReturnStatement(path22) {
86660
86720
  if (path22.node.argument?.type === "ObjectExpression") {
@@ -87054,7 +87114,8 @@ function getVisData(graph, usedNodes) {
87054
87114
  id: node2.label,
87055
87115
  label: node2.label,
87056
87116
  shape: node2.type === "var" ? "dot" : "diamond",
87057
- group: usedNodes.has(node2.label) ? "used" : "normal"
87117
+ group: usedNodes.has(node2.label) ? "used" : "normal",
87118
+ info: node2.info
87058
87119
  });
87059
87120
  });
87060
87121
  graph.edges.forEach((edge, key) => {