vue-hook-optimizer 0.0.57 → 0.0.59
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +70 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -2022,23 +2022,72 @@ function noIndegreeFilter(graph) {
|
|
2022
2022
|
function findLinearPaths(graph) {
|
2023
2023
|
const linearPaths = [];
|
2024
2024
|
const visitedNodes = /* @__PURE__ */ new Set();
|
2025
|
+
const nodeInDegrees = /* @__PURE__ */ new Map();
|
2025
2026
|
for (const [node, edges] of graph.entries()) {
|
2026
|
-
if (
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2027
|
+
if (!nodeInDegrees.has(node)) {
|
2028
|
+
nodeInDegrees.set(node, 0);
|
2029
|
+
}
|
2030
|
+
for (const edge of edges) {
|
2031
|
+
const inDegree = nodeInDegrees.get(edge) || 0;
|
2032
|
+
nodeInDegrees.set(edge, inDegree + 1);
|
2033
|
+
}
|
2034
|
+
}
|
2035
|
+
function dfs2(node, path) {
|
2036
|
+
if (visitedNodes.has(node)) {
|
2037
|
+
return;
|
2038
|
+
}
|
2039
|
+
path.push(node);
|
2040
|
+
visitedNodes.add(node);
|
2041
|
+
const edges = graph.get(node) || /* @__PURE__ */ new Set();
|
2042
|
+
if (edges.size === 0 || edges.size > 1) {
|
2043
|
+
if (path.length > 1) {
|
2044
|
+
addOrUpdatePath([...path]);
|
2045
|
+
}
|
2046
|
+
} else {
|
2047
|
+
const nextNode = Array.from(edges)[0];
|
2048
|
+
const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
|
2049
|
+
if (nextNodeInDegree === 1) {
|
2050
|
+
dfs2(nextNode, path);
|
2051
|
+
}
|
2052
|
+
}
|
2053
|
+
path.pop();
|
2054
|
+
visitedNodes.delete(node);
|
2055
|
+
}
|
2056
|
+
function addOrUpdatePath(newPath) {
|
2057
|
+
let shouldAddNewPath = true;
|
2058
|
+
for (let i = linearPaths.length - 1; i >= 0; i--) {
|
2059
|
+
const existingPath = linearPaths[i];
|
2060
|
+
if (isSubpath(existingPath, newPath)) {
|
2061
|
+
linearPaths.splice(i, 1);
|
2062
|
+
} else if (isSubpath(newPath, existingPath)) {
|
2063
|
+
shouldAddNewPath = false;
|
2064
|
+
break;
|
2065
|
+
}
|
2066
|
+
}
|
2067
|
+
if (shouldAddNewPath && newPath.length > 2) {
|
2068
|
+
linearPaths.push(newPath);
|
2069
|
+
}
|
2070
|
+
}
|
2071
|
+
function isSubpath(shortPath, longPath) {
|
2072
|
+
if (shortPath.length >= longPath.length) {
|
2073
|
+
return false;
|
2074
|
+
}
|
2075
|
+
for (let i = 0; i <= longPath.length - shortPath.length; i++) {
|
2076
|
+
let isSub = true;
|
2077
|
+
for (let j = 0; j < shortPath.length; j++) {
|
2078
|
+
if (shortPath[j] !== longPath[i + j]) {
|
2079
|
+
isSub = false;
|
2032
2080
|
break;
|
2033
2081
|
}
|
2034
|
-
path.push(nextNode);
|
2035
|
-
visitedNodes.add(nextNode);
|
2036
|
-
nextNode = Array.from(graph.get(nextNode))[0];
|
2037
2082
|
}
|
2038
|
-
if (
|
2039
|
-
|
2083
|
+
if (isSub) {
|
2084
|
+
return true;
|
2040
2085
|
}
|
2041
2086
|
}
|
2087
|
+
return false;
|
2088
|
+
}
|
2089
|
+
for (const node of graph.keys()) {
|
2090
|
+
dfs2(node, []);
|
2042
2091
|
}
|
2043
2092
|
return linearPaths;
|
2044
2093
|
}
|
@@ -2155,11 +2204,16 @@ function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new
|
|
2155
2204
|
}
|
2156
2205
|
const paths = findLinearPaths(g);
|
2157
2206
|
paths.forEach((path) => {
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2207
|
+
const firstUsedNodeIndex = path.findIndex((node) => usedNodes.has(node.label));
|
2208
|
+
const reverseLastNotUsedNodeIndex = path.slice().reverse().findIndex((node) => !usedNodes.has(node.label));
|
2209
|
+
const lastNotUsedNodeIndex = reverseLastNotUsedNodeIndex !== -1 ? path.length - 1 - reverseLastNotUsedNodeIndex : -1;
|
2210
|
+
if (firstUsedNodeIndex > -1 && firstUsedNodeIndex < lastNotUsedNodeIndex) {
|
2211
|
+
suggestions.push({
|
2212
|
+
type: "warning" /* warning */,
|
2213
|
+
message: `Nodes [${path.length > 10 ? `${path.slice(0, 10).map((node) => node.label).join(",")}...(${path.length})` : path.map((node) => node.label).join(",")}] are have function chain calls, perhaps you can refactor it.`,
|
2214
|
+
nodeInfo: path
|
2215
|
+
});
|
2216
|
+
}
|
2163
2217
|
});
|
2164
2218
|
if (g.size > 5) {
|
2165
2219
|
const ap = findArticulationPoints(g);
|