vue-hook-optimizer 0.0.56 → 0.0.58
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +65 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -7
package/dist/index.mjs
CHANGED
@@ -30,7 +30,9 @@ function analyze(content) {
|
|
30
30
|
if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
|
31
31
|
if (path.node.value.type === "StringLiteral") {
|
32
32
|
const name = path.node.value.value;
|
33
|
-
|
33
|
+
if (name) {
|
34
|
+
nodes.add(name);
|
35
|
+
}
|
34
36
|
}
|
35
37
|
}
|
36
38
|
},
|
@@ -39,7 +41,9 @@ function analyze(content) {
|
|
39
41
|
if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
|
40
42
|
if (path.node.arguments[0].type === "StringLiteral") {
|
41
43
|
const name = path.node.arguments[0].value;
|
42
|
-
|
44
|
+
if (name) {
|
45
|
+
nodes.add(name);
|
46
|
+
}
|
43
47
|
}
|
44
48
|
}
|
45
49
|
}
|
@@ -139,7 +143,7 @@ function getComment(node) {
|
|
139
143
|
return;
|
140
144
|
}
|
141
145
|
if (_comment.value.trim().startsWith("*")) {
|
142
|
-
comment += `${_comment.value.trim().replace(
|
146
|
+
comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
|
143
147
|
`;
|
144
148
|
}
|
145
149
|
});
|
@@ -148,7 +152,7 @@ function getComment(node) {
|
|
148
152
|
return;
|
149
153
|
}
|
150
154
|
if (_comment.value.trim().startsWith("*")) {
|
151
|
-
comment += `${_comment.value.trim().replace(
|
155
|
+
comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
|
152
156
|
`;
|
153
157
|
} else {
|
154
158
|
comment += `${_comment.value.trim()}
|
@@ -1975,23 +1979,69 @@ function noIndegreeFilter(graph) {
|
|
1975
1979
|
function findLinearPaths(graph) {
|
1976
1980
|
const linearPaths = [];
|
1977
1981
|
const visitedNodes = /* @__PURE__ */ new Set();
|
1982
|
+
const nodeInDegrees = /* @__PURE__ */ new Map();
|
1978
1983
|
for (const [node, edges] of graph.entries()) {
|
1979
|
-
|
1980
|
-
const
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
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;
|
1985
2034
|
break;
|
1986
2035
|
}
|
1987
|
-
path.push(nextNode);
|
1988
|
-
visitedNodes.add(nextNode);
|
1989
|
-
nextNode = Array.from(graph.get(nextNode))[0];
|
1990
2036
|
}
|
1991
|
-
if (
|
1992
|
-
|
2037
|
+
if (isSub) {
|
2038
|
+
return true;
|
1993
2039
|
}
|
1994
2040
|
}
|
2041
|
+
return false;
|
2042
|
+
}
|
2043
|
+
for (const node of graph.keys()) {
|
2044
|
+
dfs2(node, []);
|
1995
2045
|
}
|
1996
2046
|
return linearPaths;
|
1997
2047
|
}
|