vue-hook-optimizer 0.0.22 → 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 +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +79 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
export { parse } from '@vue/compiler-sfc';
|
2
|
-
import
|
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:
|
44
|
-
edges:
|
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
|
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:
|
44
|
-
edges:
|
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,30 +86284,45 @@ 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
|
-
addNode(label, node2, options = { isComputed: false }) {
|
86292
|
+
addNode(label, node2, options = { isComputed: false, isMethod: false }) {
|
86289
86293
|
if (this.nodes.has(label)) {
|
86290
86294
|
return;
|
86291
86295
|
}
|
86292
86296
|
if (!options.isComputed && (node2.type === "VariableDeclarator" && [
|
86293
86297
|
"ArrowFunctionExpression",
|
86294
86298
|
"FunctionDeclaration"
|
86295
|
-
].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
|
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,18 @@ 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,
|
86367
|
+
nodeCollection.addNode(name, element);
|
86368
|
+
if (!graph.edges.get(name)) {
|
86369
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86370
|
+
}
|
86371
|
+
}
|
86372
|
+
}
|
86373
|
+
if (element?.type === "RestElement" && element.argument.type === "Identifier") {
|
86374
|
+
const name = element.argument.name;
|
86375
|
+
const binding2 = path2.scope.getBinding(name);
|
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))) {
|
86377
|
+
graph.nodes.add(name);
|
86378
|
+
nodeCollection.addNode(name, element.argument);
|
86353
86379
|
if (!graph.edges.get(name)) {
|
86354
86380
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86355
86381
|
}
|
@@ -86364,7 +86390,18 @@ function processSetup(ast, parentScope, parentPath, _spread) {
|
|
86364
86390
|
const binding2 = path2.scope.getBinding(name);
|
86365
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))) {
|
86366
86392
|
graph.nodes.add(name);
|
86367
|
-
nodeCollection.addNode(name,
|
86393
|
+
nodeCollection.addNode(name, property.value);
|
86394
|
+
if (!graph.edges.get(name)) {
|
86395
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86396
|
+
}
|
86397
|
+
}
|
86398
|
+
}
|
86399
|
+
if (property.type === "RestElement" && property.argument.type === "Identifier") {
|
86400
|
+
const name = property.argument.name;
|
86401
|
+
const binding2 = path2.scope.getBinding(name);
|
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))) {
|
86403
|
+
graph.nodes.add(name);
|
86404
|
+
nodeCollection.addNode(name, property.argument);
|
86368
86405
|
if (!graph.edges.get(name)) {
|
86369
86406
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86370
86407
|
}
|
@@ -86434,7 +86471,7 @@ function processSetup(ast, parentScope, parentPath, _spread) {
|
|
86434
86471
|
const binding2 = path2.scope.getBinding(name);
|
86435
86472
|
if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
|
86436
86473
|
graph.nodes.add(name);
|
86437
|
-
nodeCollection.addNode(name, path2.node);
|
86474
|
+
nodeCollection.addNode(name, path2.node.id, { isMethod: true });
|
86438
86475
|
if (!graph.edges.get(name)) {
|
86439
86476
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86440
86477
|
}
|
@@ -86568,14 +86605,14 @@ function processSetup(ast, parentScope, parentPath, _spread) {
|
|
86568
86605
|
nodeCollection
|
86569
86606
|
};
|
86570
86607
|
}
|
86571
|
-
function analyze2(content) {
|
86608
|
+
function analyze2(content, lineOffset = 0) {
|
86572
86609
|
const ast = parse_1$1(content, {
|
86573
86610
|
sourceType: "module",
|
86574
86611
|
plugins: [
|
86575
86612
|
"typescript"
|
86576
86613
|
]
|
86577
86614
|
});
|
86578
|
-
const { graph, nodeCollection } = processSetup(ast);
|
86615
|
+
const { graph, nodeCollection } = processSetup(ast, void 0, void 0, void 0, lineOffset);
|
86579
86616
|
return nodeCollection.map(graph);
|
86580
86617
|
}
|
86581
86618
|
|
@@ -86585,14 +86622,14 @@ var traverse3 = (
|
|
86585
86622
|
//@ts-ignore
|
86586
86623
|
import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
|
86587
86624
|
);
|
86588
|
-
function analyze3(content) {
|
86625
|
+
function analyze3(content, lineOffset = 0) {
|
86589
86626
|
const ast = parse_1$1(content, {
|
86590
86627
|
sourceType: "module",
|
86591
86628
|
plugins: [
|
86592
86629
|
"typescript"
|
86593
86630
|
]
|
86594
86631
|
});
|
86595
|
-
const nodeCollection = new NodeCollection();
|
86632
|
+
const nodeCollection = new NodeCollection(lineOffset);
|
86596
86633
|
const graph = {
|
86597
86634
|
nodes: /* @__PURE__ */ new Set(),
|
86598
86635
|
edges: /* @__PURE__ */ new Map()
|
@@ -86601,6 +86638,29 @@ function analyze3(content) {
|
|
86601
86638
|
traverse3(node2, {
|
86602
86639
|
ObjectProperty(path1) {
|
86603
86640
|
if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
|
86641
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && path1.node.value.type === "ArrowFunctionExpression") {
|
86642
|
+
const dataNode = path1.node.value;
|
86643
|
+
traverse3(dataNode, {
|
86644
|
+
ReturnStatement(path22) {
|
86645
|
+
if (path22.parent == dataNode.body) {
|
86646
|
+
if (path22.node.argument?.type === "ObjectExpression") {
|
86647
|
+
path22.node.argument.properties.forEach((prop) => {
|
86648
|
+
if (prop.type === "ObjectProperty") {
|
86649
|
+
if (prop.key.type === "Identifier") {
|
86650
|
+
const name = prop.key.name;
|
86651
|
+
graph.nodes.add(name);
|
86652
|
+
nodeCollection.addNode(name, prop);
|
86653
|
+
if (!graph.edges.get(name)) {
|
86654
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86655
|
+
}
|
86656
|
+
}
|
86657
|
+
}
|
86658
|
+
});
|
86659
|
+
}
|
86660
|
+
}
|
86661
|
+
}
|
86662
|
+
}, path1.scope, path1);
|
86663
|
+
}
|
86604
86664
|
if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
|
86605
86665
|
const computedNode = path1.node;
|
86606
86666
|
if (computedNode.value.type === "ObjectExpression") {
|
@@ -86624,11 +86684,11 @@ function analyze3(content) {
|
|
86624
86684
|
const methodsNode = path1.node;
|
86625
86685
|
if (methodsNode.value.type === "ObjectExpression") {
|
86626
86686
|
methodsNode.value.properties.forEach((prop) => {
|
86627
|
-
if (prop.type === "ObjectMethod") {
|
86687
|
+
if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
|
86628
86688
|
if (prop.key.type === "Identifier") {
|
86629
86689
|
const name = prop.key.name;
|
86630
86690
|
graph.nodes.add(name);
|
86631
|
-
nodeCollection.addNode(name, prop);
|
86691
|
+
nodeCollection.addNode(name, prop, { isMethod: true });
|
86632
86692
|
if (!graph.edges.get(name)) {
|
86633
86693
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86634
86694
|
}
|
@@ -86667,7 +86727,7 @@ function analyze3(content) {
|
|
86667
86727
|
spread: tempSpread
|
86668
86728
|
},
|
86669
86729
|
nodeCollection: tempNodeCollection
|
86670
|
-
} = processSetup(setupNode, path1.scope, setupNode, spread);
|
86730
|
+
} = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
|
86671
86731
|
traverse3(setupNode, {
|
86672
86732
|
ReturnStatement(path22) {
|
86673
86733
|
if (path22.node.argument?.type === "ObjectExpression") {
|
@@ -87067,7 +87127,8 @@ function getVisData(graph, usedNodes) {
|
|
87067
87127
|
id: node2.label,
|
87068
87128
|
label: node2.label,
|
87069
87129
|
shape: node2.type === "var" ? "dot" : "diamond",
|
87070
|
-
group: usedNodes.has(node2.label) ? "used" : "normal"
|
87130
|
+
group: usedNodes.has(node2.label) ? "used" : "normal",
|
87131
|
+
info: node2.info
|
87071
87132
|
});
|
87072
87133
|
});
|
87073
87134
|
graph.edges.forEach((edge, key) => {
|