vue-hook-optimizer 0.0.17 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
@@ -86873,6 +86873,15 @@ function noIndegreeFilter(graph) {
|
|
86873
86873
|
});
|
86874
86874
|
return nodes.filter((node2) => indegree.get(node2) === 0);
|
86875
86875
|
}
|
86876
|
+
function noOutdegreeFilter(graph) {
|
86877
|
+
const zeroOutdegreeNodes = [];
|
86878
|
+
for (let [node2, edges] of graph.entries()) {
|
86879
|
+
if (edges.size === 0) {
|
86880
|
+
zeroOutdegreeNodes.push(node2);
|
86881
|
+
}
|
86882
|
+
}
|
86883
|
+
return zeroOutdegreeNodes;
|
86884
|
+
}
|
86876
86885
|
function removeVariable(graph, targets) {
|
86877
86886
|
const newTarget = /* @__PURE__ */ new Set();
|
86878
86887
|
targets.forEach((target) => {
|
@@ -86898,6 +86907,64 @@ function onlyFunctions(graph) {
|
|
86898
86907
|
});
|
86899
86908
|
return result2;
|
86900
86909
|
}
|
86910
|
+
function findLinearPaths(graph) {
|
86911
|
+
let linearPaths = [];
|
86912
|
+
let visitedNodes = /* @__PURE__ */ new Set();
|
86913
|
+
for (let [node2, edges] of graph.entries()) {
|
86914
|
+
if (edges.size === 1 && !visitedNodes.has(node2)) {
|
86915
|
+
let path2 = [node2];
|
86916
|
+
let nextNode = Array.from(edges)[0];
|
86917
|
+
visitedNodes.add(node2);
|
86918
|
+
while (graph.get(nextNode)?.size === 1) {
|
86919
|
+
path2.push(nextNode);
|
86920
|
+
visitedNodes.add(nextNode);
|
86921
|
+
nextNode = Array.from(graph.get(nextNode))[0];
|
86922
|
+
}
|
86923
|
+
if (path2.length > 1) {
|
86924
|
+
linearPaths.push(path2);
|
86925
|
+
}
|
86926
|
+
}
|
86927
|
+
}
|
86928
|
+
return linearPaths;
|
86929
|
+
}
|
86930
|
+
function findArticulationPoints(graph) {
|
86931
|
+
const noIndegreeNodes = noIndegreeFilter(graph);
|
86932
|
+
let time = 0;
|
86933
|
+
const low = /* @__PURE__ */ new Map();
|
86934
|
+
const disc = /* @__PURE__ */ new Map();
|
86935
|
+
const parent = /* @__PURE__ */ new Map();
|
86936
|
+
const ap = /* @__PURE__ */ new Set();
|
86937
|
+
const visited = /* @__PURE__ */ new Set();
|
86938
|
+
function APUtil(graph2, node2) {
|
86939
|
+
let children = 0;
|
86940
|
+
disc.set(node2, time);
|
86941
|
+
low.set(node2, time);
|
86942
|
+
time++;
|
86943
|
+
visited.add(node2);
|
86944
|
+
for (let neighbor of graph2.get(node2) || []) {
|
86945
|
+
if (!visited.has(neighbor)) {
|
86946
|
+
children++;
|
86947
|
+
parent.set(neighbor, node2);
|
86948
|
+
APUtil(graph2, neighbor);
|
86949
|
+
low.set(node2, Math.min(low.get(node2), low.get(neighbor)));
|
86950
|
+
if (parent.get(node2) === null && children > 1) {
|
86951
|
+
ap.add(node2);
|
86952
|
+
}
|
86953
|
+
if (parent.get(node2) !== null && low.get(neighbor) >= disc.get(node2)) {
|
86954
|
+
ap.add(node2);
|
86955
|
+
}
|
86956
|
+
} else if (neighbor !== parent.get(node2)) {
|
86957
|
+
low.set(node2, Math.min(low.get(node2), disc.get(neighbor)));
|
86958
|
+
}
|
86959
|
+
}
|
86960
|
+
}
|
86961
|
+
for (let node2 of graph.keys()) {
|
86962
|
+
if (!visited.has(node2) && !noIndegreeNodes.includes(node2)) {
|
86963
|
+
APUtil(graph, node2);
|
86964
|
+
}
|
86965
|
+
}
|
86966
|
+
return ap;
|
86967
|
+
}
|
86901
86968
|
|
86902
86969
|
// src/suggest/utils.ts
|
86903
86970
|
function hasCycle(graph) {
|
@@ -86955,6 +87022,26 @@ function gen(graph, usedNodes) {
|
|
86955
87022
|
message: `There is a loop call in nodes [${nodes.length > 10 ? nodes.slice(0, 10).map((node2) => node2.label).join(",") + "...(" + nodes.length + ")" : nodes.map((node2) => node2.label).join(",")}], perhaps you can refactor it.`
|
86956
87023
|
});
|
86957
87024
|
}
|
87025
|
+
const paths = findLinearPaths(onlyFunctions(g));
|
87026
|
+
paths.forEach((path2) => {
|
87027
|
+
suggestions.push({
|
87028
|
+
type: "warning" /* warning */,
|
87029
|
+
message: `Nodes [${path2.length > 10 ? path2.slice(0, 10).map((node2) => node2.label).join(",") + "...(" + path2.length + ")" : path2.map((node2) => node2.label).join(",")}] are have function chain calls, perhaps you can refactor it.`
|
87030
|
+
});
|
87031
|
+
});
|
87032
|
+
if (g.size > 5) {
|
87033
|
+
const ap = findArticulationPoints(onlyFunctions(g));
|
87034
|
+
const noIndegreeNodes2 = noIndegreeFilter(g);
|
87035
|
+
ap.forEach((node2) => {
|
87036
|
+
if (!noIndegreeNodes2.includes(node2)) {
|
87037
|
+
suggestions.push({
|
87038
|
+
type: "info" /* info */,
|
87039
|
+
// eslint-disable-next-line max-len
|
87040
|
+
message: `Node [${node2.label}] is an articulation point, perhaps you need to pay special attention to this node.`
|
87041
|
+
});
|
87042
|
+
}
|
87043
|
+
});
|
87044
|
+
}
|
86958
87045
|
});
|
86959
87046
|
const noIndegreeNodes = noIndegreeFilter(graph.edges);
|
86960
87047
|
noIndegreeNodes.forEach((node2) => {
|
@@ -86965,6 +87052,15 @@ function gen(graph, usedNodes) {
|
|
86965
87052
|
});
|
86966
87053
|
}
|
86967
87054
|
});
|
87055
|
+
const noOutdegreeNodes = noOutdegreeFilter(graph.edges);
|
87056
|
+
noOutdegreeNodes.forEach((node2) => {
|
87057
|
+
if (!usedNodes.has(node2.label)) {
|
87058
|
+
suggestions.push({
|
87059
|
+
type: "info" /* info */,
|
87060
|
+
message: `Node [${node2.label}] is not used, perhaps you can remove it.`
|
87061
|
+
});
|
87062
|
+
}
|
87063
|
+
});
|
86968
87064
|
return suggestions;
|
86969
87065
|
}
|
86970
87066
|
|