vue-hook-optimizer 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -86271,6 +86271,10 @@ 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
86279
  addNode(label, node2, options = { isComputed: false, isMethod: false }) {
86276
86280
  if (this.nodes.has(label)) {
@@ -86282,19 +86286,30 @@ var NodeCollection = class {
86282
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,7 @@ 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);
86340
86355
  if (!graph.edges.get(name)) {
86341
86356
  graph.edges.set(name, /* @__PURE__ */ new Set());
86342
86357
  }
@@ -86347,7 +86362,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86347
86362
  const binding2 = path2.scope.getBinding(name);
86348
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))) {
86349
86364
  graph.nodes.add(name);
86350
- nodeCollection.addNode(name, declaration2);
86365
+ nodeCollection.addNode(name, element.argument);
86351
86366
  if (!graph.edges.get(name)) {
86352
86367
  graph.edges.set(name, /* @__PURE__ */ new Set());
86353
86368
  }
@@ -86362,7 +86377,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86362
86377
  const binding2 = path2.scope.getBinding(name);
86363
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))) {
86364
86379
  graph.nodes.add(name);
86365
- nodeCollection.addNode(name, declaration2);
86380
+ nodeCollection.addNode(name, property.value);
86366
86381
  if (!graph.edges.get(name)) {
86367
86382
  graph.edges.set(name, /* @__PURE__ */ new Set());
86368
86383
  }
@@ -86373,7 +86388,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86373
86388
  const binding2 = path2.scope.getBinding(name);
86374
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))) {
86375
86390
  graph.nodes.add(name);
86376
- nodeCollection.addNode(name, declaration2);
86391
+ nodeCollection.addNode(name, property.argument);
86377
86392
  if (!graph.edges.get(name)) {
86378
86393
  graph.edges.set(name, /* @__PURE__ */ new Set());
86379
86394
  }
@@ -86443,7 +86458,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86443
86458
  const binding2 = path2.scope.getBinding(name);
86444
86459
  if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
86445
86460
  graph.nodes.add(name);
86446
- nodeCollection.addNode(name, path2.node);
86461
+ nodeCollection.addNode(name, path2.node.id, { isMethod: true });
86447
86462
  if (!graph.edges.get(name)) {
86448
86463
  graph.edges.set(name, /* @__PURE__ */ new Set());
86449
86464
  }
@@ -86577,14 +86592,14 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86577
86592
  nodeCollection
86578
86593
  };
86579
86594
  }
86580
- function analyze2(content) {
86595
+ function analyze2(content, lineOffset = 0) {
86581
86596
  const ast = parse_1$1(content, {
86582
86597
  sourceType: "module",
86583
86598
  plugins: [
86584
86599
  "typescript"
86585
86600
  ]
86586
86601
  });
86587
- const { graph, nodeCollection } = processSetup(ast);
86602
+ const { graph, nodeCollection } = processSetup(ast, void 0, void 0, void 0, lineOffset);
86588
86603
  return nodeCollection.map(graph);
86589
86604
  }
86590
86605
 
@@ -86594,14 +86609,14 @@ var traverse3 = (
86594
86609
  //@ts-ignore
86595
86610
  import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
86596
86611
  );
86597
- function analyze3(content) {
86612
+ function analyze3(content, lineOffset = 0) {
86598
86613
  const ast = parse_1$1(content, {
86599
86614
  sourceType: "module",
86600
86615
  plugins: [
86601
86616
  "typescript"
86602
86617
  ]
86603
86618
  });
86604
- const nodeCollection = new NodeCollection();
86619
+ const nodeCollection = new NodeCollection(lineOffset);
86605
86620
  const graph = {
86606
86621
  nodes: /* @__PURE__ */ new Set(),
86607
86622
  edges: /* @__PURE__ */ new Map()
@@ -86699,7 +86714,7 @@ function analyze3(content) {
86699
86714
  spread: tempSpread
86700
86715
  },
86701
86716
  nodeCollection: tempNodeCollection
86702
- } = processSetup(setupNode, path1.scope, setupNode, spread);
86717
+ } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
86703
86718
  traverse3(setupNode, {
86704
86719
  ReturnStatement(path22) {
86705
86720
  if (path22.node.argument?.type === "ObjectExpression") {
@@ -87099,7 +87114,8 @@ function getVisData(graph, usedNodes) {
87099
87114
  id: node2.label,
87100
87115
  label: node2.label,
87101
87116
  shape: node2.type === "var" ? "dot" : "diamond",
87102
- group: usedNodes.has(node2.label) ? "used" : "normal"
87117
+ group: usedNodes.has(node2.label) ? "used" : "normal",
87118
+ info: node2.info
87103
87119
  });
87104
87120
  });
87105
87121
  graph.edges.forEach((edge, key) => {