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.mjs
CHANGED
@@ -390,30 +390,45 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
390
390
|
}
|
391
391
|
return;
|
392
392
|
}
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
}
|
405
|
-
const _node = nodeCollection.getNode(path1.node.name);
|
406
|
-
if (_node?.info?.used) {
|
407
|
-
_node?.info?.used?.add(hookName);
|
408
|
-
} else if (_node) {
|
409
|
-
_node.info = {
|
410
|
-
..._node?.info,
|
411
|
-
used: /* @__PURE__ */ new Set([hookName])
|
412
|
-
};
|
413
|
-
}
|
393
|
+
if (argNode.type === "Identifier") {
|
394
|
+
const binding = patentScope.getBinding(argNode.name);
|
395
|
+
if (graph.nodes.has(argNode.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
396
|
+
const _node = nodeCollection.getNode(argNode.name);
|
397
|
+
if (_node?.info?.used) {
|
398
|
+
_node?.info?.used?.add(hookName);
|
399
|
+
} else if (_node) {
|
400
|
+
_node.info = {
|
401
|
+
..._node?.info,
|
402
|
+
used: /* @__PURE__ */ new Set([hookName])
|
403
|
+
};
|
414
404
|
}
|
415
405
|
}
|
416
|
-
}
|
406
|
+
} else {
|
407
|
+
traverse2(argNode, {
|
408
|
+
Identifier(path1) {
|
409
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
410
|
+
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)) {
|
411
|
+
if (["watch", "useEffect"].includes(hookName) && watchArgs.size > 0) {
|
412
|
+
const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
|
413
|
+
watchArgs.forEach((watchArg) => {
|
414
|
+
if (!watchArgsNames.includes(path1.node.name)) {
|
415
|
+
graph.edges.get(watchArg.name)?.add(path1.node.name);
|
416
|
+
}
|
417
|
+
});
|
418
|
+
}
|
419
|
+
const _node = nodeCollection.getNode(path1.node.name);
|
420
|
+
if (_node?.info?.used) {
|
421
|
+
_node?.info?.used?.add(hookName);
|
422
|
+
} else if (_node) {
|
423
|
+
_node.info = {
|
424
|
+
..._node?.info,
|
425
|
+
used: /* @__PURE__ */ new Set([hookName])
|
426
|
+
};
|
427
|
+
}
|
428
|
+
}
|
429
|
+
}
|
430
|
+
}, patentScope, node);
|
431
|
+
}
|
417
432
|
});
|
418
433
|
}
|
419
434
|
}
|
@@ -2245,12 +2260,27 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
|
|
2245
2260
|
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2246
2261
|
const nodes = [];
|
2247
2262
|
const edges = [];
|
2263
|
+
const inDegreeMap = {};
|
2264
|
+
const outDegreeMap = {};
|
2265
|
+
graph.edges.forEach((edge) => {
|
2266
|
+
edge.forEach((to) => {
|
2267
|
+
if (to) {
|
2268
|
+
inDegreeMap[to.label] = (inDegreeMap[to.label] || 0) + 1;
|
2269
|
+
}
|
2270
|
+
});
|
2271
|
+
});
|
2272
|
+
graph.edges.forEach((edge, key) => {
|
2273
|
+
outDegreeMap[key.label] = edge.size;
|
2274
|
+
});
|
2248
2275
|
graph.nodes.forEach((node) => {
|
2276
|
+
const inDegree = inDegreeMap[node.label] || 0;
|
2277
|
+
const outDegree = outDegreeMap[node.label] || 0;
|
2249
2278
|
nodes.push({
|
2250
2279
|
id: node.label,
|
2251
2280
|
label: node.label,
|
2252
2281
|
shape: node.type === "var" ? "dot" : "diamond",
|
2253
2282
|
group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
|
2283
|
+
size: 20 + 1.6 ** (inDegree * 0.75 + outDegree * 0.25),
|
2254
2284
|
title: `${filterNodeUserd(node.info?.used).size ? `used by ${Array.from(filterNodeUserd(node.info?.used))?.map((i) => `\`${i}\``).join(",")}
|
2255
2285
|
|
2256
2286
|
` : ""}${usedNodes.has(node.label) ? `used in ${[
|