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.mjs
CHANGED
@@ -1979,23 +1979,72 @@ function noIndegreeFilter(graph) {
|
|
1979
1979
|
function findLinearPaths(graph) {
|
1980
1980
|
const linearPaths = [];
|
1981
1981
|
const visitedNodes = /* @__PURE__ */ new Set();
|
1982
|
+
const nodeInDegrees = /* @__PURE__ */ new Map();
|
1982
1983
|
for (const [node, edges] of graph.entries()) {
|
1983
|
-
if (
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1984
|
+
if (!nodeInDegrees.has(node)) {
|
1985
|
+
nodeInDegrees.set(node, 0);
|
1986
|
+
}
|
1987
|
+
for (const edge of edges) {
|
1988
|
+
const inDegree = nodeInDegrees.get(edge) || 0;
|
1989
|
+
nodeInDegrees.set(edge, inDegree + 1);
|
1990
|
+
}
|
1991
|
+
}
|
1992
|
+
function dfs2(node, path) {
|
1993
|
+
if (visitedNodes.has(node)) {
|
1994
|
+
return;
|
1995
|
+
}
|
1996
|
+
path.push(node);
|
1997
|
+
visitedNodes.add(node);
|
1998
|
+
const edges = graph.get(node) || /* @__PURE__ */ new Set();
|
1999
|
+
if (edges.size === 0 || edges.size > 1) {
|
2000
|
+
if (path.length > 1) {
|
2001
|
+
addOrUpdatePath([...path]);
|
2002
|
+
}
|
2003
|
+
} else {
|
2004
|
+
const nextNode = Array.from(edges)[0];
|
2005
|
+
const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
|
2006
|
+
if (nextNodeInDegree === 1) {
|
2007
|
+
dfs2(nextNode, path);
|
2008
|
+
}
|
2009
|
+
}
|
2010
|
+
path.pop();
|
2011
|
+
visitedNodes.delete(node);
|
2012
|
+
}
|
2013
|
+
function addOrUpdatePath(newPath) {
|
2014
|
+
let shouldAddNewPath = true;
|
2015
|
+
for (let i = linearPaths.length - 1; i >= 0; i--) {
|
2016
|
+
const existingPath = linearPaths[i];
|
2017
|
+
if (isSubpath(existingPath, newPath)) {
|
2018
|
+
linearPaths.splice(i, 1);
|
2019
|
+
} else if (isSubpath(newPath, existingPath)) {
|
2020
|
+
shouldAddNewPath = false;
|
2021
|
+
break;
|
2022
|
+
}
|
2023
|
+
}
|
2024
|
+
if (shouldAddNewPath && newPath.length > 2) {
|
2025
|
+
linearPaths.push(newPath);
|
2026
|
+
}
|
2027
|
+
}
|
2028
|
+
function isSubpath(shortPath, longPath) {
|
2029
|
+
if (shortPath.length >= longPath.length) {
|
2030
|
+
return false;
|
2031
|
+
}
|
2032
|
+
for (let i = 0; i <= longPath.length - shortPath.length; i++) {
|
2033
|
+
let isSub = true;
|
2034
|
+
for (let j = 0; j < shortPath.length; j++) {
|
2035
|
+
if (shortPath[j] !== longPath[i + j]) {
|
2036
|
+
isSub = false;
|
1989
2037
|
break;
|
1990
2038
|
}
|
1991
|
-
path.push(nextNode);
|
1992
|
-
visitedNodes.add(nextNode);
|
1993
|
-
nextNode = Array.from(graph.get(nextNode))[0];
|
1994
2039
|
}
|
1995
|
-
if (
|
1996
|
-
|
2040
|
+
if (isSub) {
|
2041
|
+
return true;
|
1997
2042
|
}
|
1998
2043
|
}
|
2044
|
+
return false;
|
2045
|
+
}
|
2046
|
+
for (const node of graph.keys()) {
|
2047
|
+
dfs2(node, []);
|
1999
2048
|
}
|
2000
2049
|
return linearPaths;
|
2001
2050
|
}
|
@@ -2112,11 +2161,16 @@ function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new
|
|
2112
2161
|
}
|
2113
2162
|
const paths = findLinearPaths(g);
|
2114
2163
|
paths.forEach((path) => {
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2164
|
+
const firstUsedNodeIndex = path.findIndex((node) => usedNodes.has(node.label));
|
2165
|
+
const reverseLastNotUsedNodeIndex = path.slice().reverse().findIndex((node) => !usedNodes.has(node.label));
|
2166
|
+
const lastNotUsedNodeIndex = reverseLastNotUsedNodeIndex !== -1 ? path.length - 1 - reverseLastNotUsedNodeIndex : -1;
|
2167
|
+
if (firstUsedNodeIndex > -1 && firstUsedNodeIndex < lastNotUsedNodeIndex) {
|
2168
|
+
suggestions.push({
|
2169
|
+
type: "warning" /* warning */,
|
2170
|
+
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.`,
|
2171
|
+
nodeInfo: path
|
2172
|
+
});
|
2173
|
+
}
|
2120
2174
|
});
|
2121
2175
|
if (g.size > 5) {
|
2122
2176
|
const ap = findArticulationPoints(g);
|