vue-hook-optimizer 0.0.10 → 0.0.11
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/README.md +3 -3
- package/dist/index.d.mts +38 -6
- package/dist/index.d.ts +38 -6
- package/dist/index.js +76 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -86263,11 +86263,58 @@ function analyze(content) {
|
|
86263
86263
|
|
86264
86264
|
// src/analyze/setupScript.ts
|
86265
86265
|
var import_traverse2 = __toESM(require_lib13());
|
86266
|
+
|
86267
|
+
// src/analyze/utils.ts
|
86268
|
+
var NodeCollection = class {
|
86269
|
+
nodes = /* @__PURE__ */ new Map();
|
86270
|
+
addNode(label, node2, isComputed = false) {
|
86271
|
+
if (this.nodes.has(label)) {
|
86272
|
+
return;
|
86273
|
+
}
|
86274
|
+
if (!isComputed && (node2.type === "VariableDeclarator" && [
|
86275
|
+
"ArrowFunctionExpression",
|
86276
|
+
"FunctionDeclaration"
|
86277
|
+
].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
|
86278
|
+
this.nodes.set(label, {
|
86279
|
+
label,
|
86280
|
+
type: "fun" /* fun */
|
86281
|
+
});
|
86282
|
+
} else {
|
86283
|
+
this.nodes.set(label, {
|
86284
|
+
label,
|
86285
|
+
type: "var" /* var */
|
86286
|
+
});
|
86287
|
+
}
|
86288
|
+
}
|
86289
|
+
addTypedNode(label, type) {
|
86290
|
+
this.nodes.set(label, {
|
86291
|
+
label,
|
86292
|
+
type
|
86293
|
+
});
|
86294
|
+
}
|
86295
|
+
map(graph) {
|
86296
|
+
const nodes = new Set(Array.from(graph.nodes).map((node2) => {
|
86297
|
+
return this.nodes.get(node2);
|
86298
|
+
}));
|
86299
|
+
const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
|
86300
|
+
return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
|
86301
|
+
return this.nodes.get(node2);
|
86302
|
+
}))];
|
86303
|
+
}));
|
86304
|
+
return {
|
86305
|
+
nodes,
|
86306
|
+
edges
|
86307
|
+
};
|
86308
|
+
}
|
86309
|
+
};
|
86310
|
+
|
86311
|
+
// src/analyze/setupScript.ts
|
86266
86312
|
var traverse2 = (
|
86267
86313
|
//@ts-ignore
|
86268
86314
|
import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
|
86269
86315
|
);
|
86270
86316
|
function processSetup(ast, parentScope, parentPath) {
|
86317
|
+
const nodeCollection = new NodeCollection();
|
86271
86318
|
const graph = {
|
86272
86319
|
nodes: /* @__PURE__ */ new Set(),
|
86273
86320
|
edges: /* @__PURE__ */ new Map()
|
@@ -86282,6 +86329,7 @@ function processSetup(ast, parentScope, parentPath) {
|
|
86282
86329
|
const binding2 = path2.scope.getBinding(name);
|
86283
86330
|
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))) {
|
86284
86331
|
graph.nodes.add(name);
|
86332
|
+
nodeCollection.addNode(name, declaration2);
|
86285
86333
|
if (!graph.edges.get(name)) {
|
86286
86334
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86287
86335
|
}
|
@@ -86296,6 +86344,7 @@ function processSetup(ast, parentScope, parentPath) {
|
|
86296
86344
|
const binding2 = path2.scope.getBinding(name);
|
86297
86345
|
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))) {
|
86298
86346
|
graph.nodes.add(name);
|
86347
|
+
nodeCollection.addNode(name, declaration2);
|
86299
86348
|
if (!graph.edges.get(name)) {
|
86300
86349
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86301
86350
|
}
|
@@ -86308,6 +86357,7 @@ function processSetup(ast, parentScope, parentPath) {
|
|
86308
86357
|
const binding2 = path2.scope.getBinding(name);
|
86309
86358
|
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))) {
|
86310
86359
|
graph.nodes.add(name);
|
86360
|
+
nodeCollection.addNode(name, declaration2);
|
86311
86361
|
if (!graph.edges.get(name)) {
|
86312
86362
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86313
86363
|
}
|
@@ -86321,6 +86371,7 @@ function processSetup(ast, parentScope, parentPath) {
|
|
86321
86371
|
const binding2 = path2.scope.getBinding(name);
|
86322
86372
|
if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
|
86323
86373
|
graph.nodes.add(name);
|
86374
|
+
nodeCollection.addNode(name, path2.node);
|
86324
86375
|
if (!graph.edges.get(name)) {
|
86325
86376
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86326
86377
|
}
|
@@ -86398,7 +86449,10 @@ function processSetup(ast, parentScope, parentPath) {
|
|
86398
86449
|
}
|
86399
86450
|
}
|
86400
86451
|
}, parentScope, parentPath);
|
86401
|
-
return
|
86452
|
+
return {
|
86453
|
+
graph,
|
86454
|
+
nodeCollection
|
86455
|
+
};
|
86402
86456
|
}
|
86403
86457
|
function analyze2(content) {
|
86404
86458
|
const ast = parse_1$1(content, {
|
@@ -86407,7 +86461,8 @@ function analyze2(content) {
|
|
86407
86461
|
"typescript"
|
86408
86462
|
]
|
86409
86463
|
});
|
86410
|
-
|
86464
|
+
const { graph, nodeCollection } = processSetup(ast);
|
86465
|
+
return nodeCollection.map(graph);
|
86411
86466
|
}
|
86412
86467
|
|
86413
86468
|
// src/analyze/options.ts
|
@@ -86423,6 +86478,7 @@ function analyze3(content) {
|
|
86423
86478
|
"typescript"
|
86424
86479
|
]
|
86425
86480
|
});
|
86481
|
+
const nodeCollection = new NodeCollection();
|
86426
86482
|
const graph = {
|
86427
86483
|
nodes: /* @__PURE__ */ new Set(),
|
86428
86484
|
edges: /* @__PURE__ */ new Map()
|
@@ -86439,6 +86495,7 @@ function analyze3(content) {
|
|
86439
86495
|
if (prop.key.type === "Identifier") {
|
86440
86496
|
const name = prop.key.name;
|
86441
86497
|
graph.nodes.add(name);
|
86498
|
+
nodeCollection.addNode(name, prop, true);
|
86442
86499
|
if (!graph.edges.get(name)) {
|
86443
86500
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86444
86501
|
}
|
@@ -86455,6 +86512,7 @@ function analyze3(content) {
|
|
86455
86512
|
if (prop.key.type === "Identifier") {
|
86456
86513
|
const name = prop.key.name;
|
86457
86514
|
graph.nodes.add(name);
|
86515
|
+
nodeCollection.addNode(name, prop);
|
86458
86516
|
if (!graph.edges.get(name)) {
|
86459
86517
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86460
86518
|
}
|
@@ -86470,8 +86528,11 @@ function analyze3(content) {
|
|
86470
86528
|
if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
|
86471
86529
|
const setupNode = path1.node;
|
86472
86530
|
const {
|
86473
|
-
|
86474
|
-
|
86531
|
+
graph: {
|
86532
|
+
nodes: tempNodes,
|
86533
|
+
edges: tempEdges
|
86534
|
+
},
|
86535
|
+
nodeCollection: tempNodeCollection
|
86475
86536
|
} = processSetup(setupNode, path1.scope, setupNode);
|
86476
86537
|
traverse3(setupNode, {
|
86477
86538
|
ReturnStatement(path22) {
|
@@ -86485,6 +86546,7 @@ function analyze3(content) {
|
|
86485
86546
|
const valName = path3.node.value.type === "Identifier" ? path3.node.value.name : "";
|
86486
86547
|
if (valName && tempNodes.has(valName)) {
|
86487
86548
|
graph.nodes.add(name);
|
86549
|
+
nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(valName).type);
|
86488
86550
|
if (!graph.edges.get(name)) {
|
86489
86551
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86490
86552
|
tempEdges.get(valName)?.forEach((edge) => {
|
@@ -86513,6 +86575,7 @@ function analyze3(content) {
|
|
86513
86575
|
if (prop.key.type === "Identifier") {
|
86514
86576
|
const name = prop.key.name;
|
86515
86577
|
graph.nodes.add(name);
|
86578
|
+
nodeCollection.addNode(name, prop);
|
86516
86579
|
if (!graph.edges.get(name)) {
|
86517
86580
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86518
86581
|
}
|
@@ -86591,7 +86654,7 @@ function analyze3(content) {
|
|
86591
86654
|
}
|
86592
86655
|
}
|
86593
86656
|
});
|
86594
|
-
return graph;
|
86657
|
+
return nodeCollection.map(graph);
|
86595
86658
|
}
|
86596
86659
|
|
86597
86660
|
// src/vis.ts
|
@@ -86600,16 +86663,19 @@ function getVisData(graph, usedNodes) {
|
|
86600
86663
|
const edges = [];
|
86601
86664
|
graph.nodes.forEach((node2) => {
|
86602
86665
|
nodes.push({
|
86603
|
-
id: node2,
|
86604
|
-
label: node2,
|
86605
|
-
|
86666
|
+
id: node2.label,
|
86667
|
+
label: node2.label,
|
86668
|
+
shape: node2.type === "var" ? "dot" : "diamond",
|
86669
|
+
group: usedNodes.has(node2.label) ? "used" : "normal"
|
86606
86670
|
});
|
86607
86671
|
});
|
86608
86672
|
graph.edges.forEach((edge, key) => {
|
86609
86673
|
edge.forEach((to) => {
|
86674
|
+
if (!to)
|
86675
|
+
return;
|
86610
86676
|
edges.push({
|
86611
|
-
from: key,
|
86612
|
-
to,
|
86677
|
+
from: key.label,
|
86678
|
+
to: to.label,
|
86613
86679
|
arrows: {
|
86614
86680
|
to: {
|
86615
86681
|
enabled: true,
|