vue-hook-optimizer 0.0.63 → 0.0.65
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +52 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -433,30 +433,45 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
433
433
|
}
|
434
434
|
return;
|
435
435
|
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
}
|
448
|
-
const _node = nodeCollection.getNode(path1.node.name);
|
449
|
-
if (_node?.info?.used) {
|
450
|
-
_node?.info?.used?.add(hookName);
|
451
|
-
} else if (_node) {
|
452
|
-
_node.info = {
|
453
|
-
..._node?.info,
|
454
|
-
used: /* @__PURE__ */ new Set([hookName])
|
455
|
-
};
|
456
|
-
}
|
436
|
+
if (argNode.type === "Identifier") {
|
437
|
+
const binding = patentScope.getBinding(argNode.name);
|
438
|
+
if (graph.nodes.has(argNode.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
439
|
+
const _node = nodeCollection.getNode(argNode.name);
|
440
|
+
if (_node?.info?.used) {
|
441
|
+
_node?.info?.used?.add(hookName);
|
442
|
+
} else if (_node) {
|
443
|
+
_node.info = {
|
444
|
+
..._node?.info,
|
445
|
+
used: /* @__PURE__ */ new Set([hookName])
|
446
|
+
};
|
457
447
|
}
|
458
448
|
}
|
459
|
-
}
|
449
|
+
} else {
|
450
|
+
traverse2(argNode, {
|
451
|
+
Identifier(path1) {
|
452
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
453
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
454
|
+
if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
|
455
|
+
const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
|
456
|
+
watchArgs.forEach((watchArg) => {
|
457
|
+
if (!watchArgsNames.includes(path1.node.name)) {
|
458
|
+
graph.edges.get(watchArg.name)?.add(path1.node.name);
|
459
|
+
}
|
460
|
+
});
|
461
|
+
}
|
462
|
+
const _node = nodeCollection.getNode(path1.node.name);
|
463
|
+
if (_node?.info?.used) {
|
464
|
+
_node?.info?.used?.add(hookName);
|
465
|
+
} else if (_node) {
|
466
|
+
_node.info = {
|
467
|
+
..._node?.info,
|
468
|
+
used: /* @__PURE__ */ new Set([hookName])
|
469
|
+
};
|
470
|
+
}
|
471
|
+
}
|
472
|
+
}
|
473
|
+
}, patentScope, node);
|
474
|
+
}
|
460
475
|
});
|
461
476
|
}
|
462
477
|
}
|
@@ -2288,12 +2303,27 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
|
|
2288
2303
|
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2289
2304
|
const nodes = [];
|
2290
2305
|
const edges = [];
|
2306
|
+
const inDegreeMap = {};
|
2307
|
+
const outDegreeMap = {};
|
2308
|
+
graph.edges.forEach((edge) => {
|
2309
|
+
edge.forEach((to) => {
|
2310
|
+
if (to) {
|
2311
|
+
inDegreeMap[to.label] = (inDegreeMap[to.label] || 0) + 1;
|
2312
|
+
}
|
2313
|
+
});
|
2314
|
+
});
|
2315
|
+
graph.edges.forEach((edge, key) => {
|
2316
|
+
outDegreeMap[key.label] = edge.size;
|
2317
|
+
});
|
2291
2318
|
graph.nodes.forEach((node) => {
|
2319
|
+
const inDegree = inDegreeMap[node.label] || 0;
|
2320
|
+
const outDegree = outDegreeMap[node.label] || 0;
|
2292
2321
|
nodes.push({
|
2293
2322
|
id: node.label,
|
2294
2323
|
label: node.label,
|
2295
2324
|
shape: node.type === "var" ? "dot" : "diamond",
|
2296
2325
|
group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
|
2326
|
+
size: 20 + 1.6 ** (inDegree * 0.75 + outDegree * 0.25),
|
2297
2327
|
title: `${filterNodeUserd(node.info?.used).size ? `used by ${Array.from(filterNodeUserd(node.info?.used))?.map((i) => `\`${i}\``).join(",")}
|
2298
2328
|
|
2299
2329
|
` : ""}${usedNodes.has(node.label) ? `used in ${[
|