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.d.mts CHANGED
@@ -1,23 +1,27 @@
1
1
  export { parse } from '@vue/compiler-sfc';
2
- import * as vis_network from 'vis-network';
2
+ import { Edge, Node } from 'vis-network';
3
3
 
4
4
  declare function analyze$2(content: string): Set<string>;
5
5
 
6
6
  type TypedNode = {
7
7
  label: string;
8
8
  type: NodeType;
9
+ info?: Partial<{
10
+ line: number;
11
+ column: number;
12
+ }>;
9
13
  };
10
14
  declare enum NodeType {
11
15
  var = "var",
12
16
  fun = "fun"
13
17
  }
14
18
 
15
- declare function analyze$1(content: string): {
19
+ declare function analyze$1(content: string, lineOffset?: number): {
16
20
  nodes: Set<TypedNode>;
17
21
  edges: Map<TypedNode, Set<TypedNode>>;
18
22
  };
19
23
 
20
- declare function analyze(content: string): {
24
+ declare function analyze(content: string, lineOffset?: number): {
21
25
  nodes: Set<TypedNode>;
22
26
  edges: Map<TypedNode, Set<TypedNode>>;
23
27
  };
@@ -36,12 +40,15 @@ declare function gen(graph: {
36
40
  edges: Map<TypedNode, Set<TypedNode>>;
37
41
  }, usedNodes: Set<string>): Suggestion[];
38
42
 
43
+ type CustomNode = Node & {
44
+ info: TypedNode['info'];
45
+ };
39
46
  declare function getVisData(graph: {
40
47
  nodes: Set<TypedNode>;
41
48
  edges: Map<TypedNode, Set<TypedNode>>;
42
49
  }, usedNodes: Set<string>): {
43
- nodes: vis_network.Node[];
44
- edges: vis_network.Edge[];
50
+ nodes: CustomNode[];
51
+ edges: Edge[];
45
52
  };
46
53
 
47
54
  export { NodeType, Suggestion, SuggestionType, TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, gen, getVisData };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,27 @@
1
1
  export { parse } from '@vue/compiler-sfc';
2
- import * as vis_network from 'vis-network';
2
+ import { Edge, Node } from 'vis-network';
3
3
 
4
4
  declare function analyze$2(content: string): Set<string>;
5
5
 
6
6
  type TypedNode = {
7
7
  label: string;
8
8
  type: NodeType;
9
+ info?: Partial<{
10
+ line: number;
11
+ column: number;
12
+ }>;
9
13
  };
10
14
  declare enum NodeType {
11
15
  var = "var",
12
16
  fun = "fun"
13
17
  }
14
18
 
15
- declare function analyze$1(content: string): {
19
+ declare function analyze$1(content: string, lineOffset?: number): {
16
20
  nodes: Set<TypedNode>;
17
21
  edges: Map<TypedNode, Set<TypedNode>>;
18
22
  };
19
23
 
20
- declare function analyze(content: string): {
24
+ declare function analyze(content: string, lineOffset?: number): {
21
25
  nodes: Set<TypedNode>;
22
26
  edges: Map<TypedNode, Set<TypedNode>>;
23
27
  };
@@ -36,12 +40,15 @@ declare function gen(graph: {
36
40
  edges: Map<TypedNode, Set<TypedNode>>;
37
41
  }, usedNodes: Set<string>): Suggestion[];
38
42
 
43
+ type CustomNode = Node & {
44
+ info: TypedNode['info'];
45
+ };
39
46
  declare function getVisData(graph: {
40
47
  nodes: Set<TypedNode>;
41
48
  edges: Map<TypedNode, Set<TypedNode>>;
42
49
  }, usedNodes: Set<string>): {
43
- nodes: vis_network.Node[];
44
- edges: vis_network.Edge[];
50
+ nodes: CustomNode[];
51
+ edges: Edge[];
45
52
  };
46
53
 
47
54
  export { NodeType, Suggestion, SuggestionType, TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, gen, getVisData };
package/dist/index.js CHANGED
@@ -86284,6 +86284,10 @@ var NodeType = /* @__PURE__ */ ((NodeType3) => {
86284
86284
  return NodeType3;
86285
86285
  })(NodeType || {});
86286
86286
  var NodeCollection = class {
86287
+ lineOffset = 0;
86288
+ constructor(_lineOffset = 0) {
86289
+ this.lineOffset = _lineOffset;
86290
+ }
86287
86291
  nodes = /* @__PURE__ */ new Map();
86288
86292
  addNode(label, node2, options = { isComputed: false, isMethod: false }) {
86289
86293
  if (this.nodes.has(label)) {
@@ -86295,19 +86299,30 @@ var NodeCollection = class {
86295
86299
  ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod") || options.isMethod) {
86296
86300
  this.nodes.set(label, {
86297
86301
  label,
86298
- type: "fun" /* fun */
86302
+ type: "fun" /* fun */,
86303
+ info: {
86304
+ line: (node2.loc?.start.line || 1) - 1 + this.lineOffset,
86305
+ column: node2.loc?.start.column || 0
86306
+ }
86299
86307
  });
86300
86308
  } else {
86301
86309
  this.nodes.set(label, {
86302
86310
  label,
86303
- type: "var" /* var */
86311
+ type: "var" /* var */,
86312
+ info: {
86313
+ line: (node2.loc?.start.line || 1) - 1 + this.lineOffset,
86314
+ column: node2.loc?.start.column || 0
86315
+ }
86304
86316
  });
86305
86317
  }
86306
86318
  }
86307
86319
  addTypedNode(label, node2) {
86308
86320
  this.nodes.set(label, {
86309
86321
  label,
86310
- type: node2.type
86322
+ type: node2.type,
86323
+ info: {
86324
+ ...node2.info || {}
86325
+ }
86311
86326
  });
86312
86327
  }
86313
86328
  map(graph) {
@@ -86331,9 +86346,9 @@ var traverse2 = (
86331
86346
  //@ts-ignore
86332
86347
  import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
86333
86348
  );
86334
- function processSetup(ast, parentScope, parentPath, _spread) {
86349
+ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
86335
86350
  const spread = _spread || [];
86336
- const nodeCollection = new NodeCollection();
86351
+ const nodeCollection = new NodeCollection(_lineOffset);
86337
86352
  const graph = {
86338
86353
  nodes: /* @__PURE__ */ new Set(),
86339
86354
  edges: /* @__PURE__ */ new Map(),
@@ -86349,7 +86364,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86349
86364
  const binding2 = path2.scope.getBinding(name);
86350
86365
  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))) {
86351
86366
  graph.nodes.add(name);
86352
- nodeCollection.addNode(name, declaration2);
86367
+ nodeCollection.addNode(name, element);
86353
86368
  if (!graph.edges.get(name)) {
86354
86369
  graph.edges.set(name, /* @__PURE__ */ new Set());
86355
86370
  }
@@ -86360,7 +86375,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86360
86375
  const binding2 = path2.scope.getBinding(name);
86361
86376
  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
86377
  graph.nodes.add(name);
86363
- nodeCollection.addNode(name, declaration2);
86378
+ nodeCollection.addNode(name, element.argument);
86364
86379
  if (!graph.edges.get(name)) {
86365
86380
  graph.edges.set(name, /* @__PURE__ */ new Set());
86366
86381
  }
@@ -86375,7 +86390,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86375
86390
  const binding2 = path2.scope.getBinding(name);
86376
86391
  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))) {
86377
86392
  graph.nodes.add(name);
86378
- nodeCollection.addNode(name, declaration2);
86393
+ nodeCollection.addNode(name, property.value);
86379
86394
  if (!graph.edges.get(name)) {
86380
86395
  graph.edges.set(name, /* @__PURE__ */ new Set());
86381
86396
  }
@@ -86386,7 +86401,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86386
86401
  const binding2 = path2.scope.getBinding(name);
86387
86402
  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
86403
  graph.nodes.add(name);
86389
- nodeCollection.addNode(name, declaration2);
86404
+ nodeCollection.addNode(name, property.argument);
86390
86405
  if (!graph.edges.get(name)) {
86391
86406
  graph.edges.set(name, /* @__PURE__ */ new Set());
86392
86407
  }
@@ -86456,7 +86471,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86456
86471
  const binding2 = path2.scope.getBinding(name);
86457
86472
  if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
86458
86473
  graph.nodes.add(name);
86459
- nodeCollection.addNode(name, path2.node);
86474
+ nodeCollection.addNode(name, path2.node.id, { isMethod: true });
86460
86475
  if (!graph.edges.get(name)) {
86461
86476
  graph.edges.set(name, /* @__PURE__ */ new Set());
86462
86477
  }
@@ -86590,14 +86605,14 @@ function processSetup(ast, parentScope, parentPath, _spread) {
86590
86605
  nodeCollection
86591
86606
  };
86592
86607
  }
86593
- function analyze2(content) {
86608
+ function analyze2(content, lineOffset = 0) {
86594
86609
  const ast = parse_1$1(content, {
86595
86610
  sourceType: "module",
86596
86611
  plugins: [
86597
86612
  "typescript"
86598
86613
  ]
86599
86614
  });
86600
- const { graph, nodeCollection } = processSetup(ast);
86615
+ const { graph, nodeCollection } = processSetup(ast, void 0, void 0, void 0, lineOffset);
86601
86616
  return nodeCollection.map(graph);
86602
86617
  }
86603
86618
 
@@ -86607,14 +86622,14 @@ var traverse3 = (
86607
86622
  //@ts-ignore
86608
86623
  import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
86609
86624
  );
86610
- function analyze3(content) {
86625
+ function analyze3(content, lineOffset = 0) {
86611
86626
  const ast = parse_1$1(content, {
86612
86627
  sourceType: "module",
86613
86628
  plugins: [
86614
86629
  "typescript"
86615
86630
  ]
86616
86631
  });
86617
- const nodeCollection = new NodeCollection();
86632
+ const nodeCollection = new NodeCollection(lineOffset);
86618
86633
  const graph = {
86619
86634
  nodes: /* @__PURE__ */ new Set(),
86620
86635
  edges: /* @__PURE__ */ new Map()
@@ -86712,7 +86727,7 @@ function analyze3(content) {
86712
86727
  spread: tempSpread
86713
86728
  },
86714
86729
  nodeCollection: tempNodeCollection
86715
- } = processSetup(setupNode, path1.scope, setupNode, spread);
86730
+ } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
86716
86731
  traverse3(setupNode, {
86717
86732
  ReturnStatement(path22) {
86718
86733
  if (path22.node.argument?.type === "ObjectExpression") {
@@ -87112,7 +87127,8 @@ function getVisData(graph, usedNodes) {
87112
87127
  id: node2.label,
87113
87128
  label: node2.label,
87114
87129
  shape: node2.type === "var" ? "dot" : "diamond",
87115
- group: usedNodes.has(node2.label) ? "used" : "normal"
87130
+ group: usedNodes.has(node2.label) ? "used" : "normal",
87131
+ info: node2.info
87116
87132
  });
87117
87133
  });
87118
87134
  graph.edges.forEach((edge, key) => {