vue-hook-optimizer 0.0.57 → 0.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +57 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -1979,23 +1979,69 @@ 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
|
-
|
1984
|
-
const
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1984
|
+
for (const edge of edges) {
|
1985
|
+
const inDegree = nodeInDegrees.get(edge) || 0;
|
1986
|
+
nodeInDegrees.set(edge, inDegree + 1);
|
1987
|
+
}
|
1988
|
+
}
|
1989
|
+
function dfs2(node, path) {
|
1990
|
+
if (visitedNodes.has(node)) {
|
1991
|
+
return;
|
1992
|
+
}
|
1993
|
+
path.push(node);
|
1994
|
+
visitedNodes.add(node);
|
1995
|
+
const edges = graph.get(node) || /* @__PURE__ */ new Set();
|
1996
|
+
if (edges.size === 0 || edges.size > 1) {
|
1997
|
+
if (path.length > 1) {
|
1998
|
+
addOrUpdatePath([...path]);
|
1999
|
+
}
|
2000
|
+
} else {
|
2001
|
+
const nextNode = Array.from(edges)[0];
|
2002
|
+
const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
|
2003
|
+
if (nextNodeInDegree === 1) {
|
2004
|
+
dfs2(nextNode, path);
|
2005
|
+
}
|
2006
|
+
}
|
2007
|
+
path.pop();
|
2008
|
+
visitedNodes.delete(node);
|
2009
|
+
}
|
2010
|
+
function addOrUpdatePath(newPath) {
|
2011
|
+
let shouldAddNewPath = true;
|
2012
|
+
for (let i = linearPaths.length - 1; i >= 0; i--) {
|
2013
|
+
const existingPath = linearPaths[i];
|
2014
|
+
if (isSubpath(existingPath, newPath)) {
|
2015
|
+
linearPaths.splice(i, 1);
|
2016
|
+
} else if (isSubpath(newPath, existingPath)) {
|
2017
|
+
shouldAddNewPath = false;
|
2018
|
+
break;
|
2019
|
+
}
|
2020
|
+
}
|
2021
|
+
if (shouldAddNewPath && newPath.length > 2) {
|
2022
|
+
linearPaths.push(newPath);
|
2023
|
+
}
|
2024
|
+
}
|
2025
|
+
function isSubpath(shortPath, longPath) {
|
2026
|
+
if (shortPath.length >= longPath.length) {
|
2027
|
+
return false;
|
2028
|
+
}
|
2029
|
+
for (let i = 0; i <= longPath.length - shortPath.length; i++) {
|
2030
|
+
let isSub = true;
|
2031
|
+
for (let j = 0; j < shortPath.length; j++) {
|
2032
|
+
if (shortPath[j] !== longPath[i + j]) {
|
2033
|
+
isSub = false;
|
1989
2034
|
break;
|
1990
2035
|
}
|
1991
|
-
path.push(nextNode);
|
1992
|
-
visitedNodes.add(nextNode);
|
1993
|
-
nextNode = Array.from(graph.get(nextNode))[0];
|
1994
2036
|
}
|
1995
|
-
if (
|
1996
|
-
|
2037
|
+
if (isSub) {
|
2038
|
+
return true;
|
1997
2039
|
}
|
1998
2040
|
}
|
2041
|
+
return false;
|
2042
|
+
}
|
2043
|
+
for (const node of graph.keys()) {
|
2044
|
+
dfs2(node, []);
|
1999
2045
|
}
|
2000
2046
|
return linearPaths;
|
2001
2047
|
}
|