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 CHANGED
@@ -73,7 +73,9 @@ function analyze(content) {
73
73
  if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
74
74
  if (path.node.value.type === "StringLiteral") {
75
75
  const name = path.node.value.value;
76
- name && nodes.add(name);
76
+ if (name) {
77
+ nodes.add(name);
78
+ }
77
79
  }
78
80
  }
79
81
  },
@@ -82,7 +84,9 @@ function analyze(content) {
82
84
  if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
83
85
  if (path.node.arguments[0].type === "StringLiteral") {
84
86
  const name = path.node.arguments[0].value;
85
- name && nodes.add(name);
87
+ if (name) {
88
+ nodes.add(name);
89
+ }
86
90
  }
87
91
  }
88
92
  }
@@ -182,7 +186,7 @@ function getComment(node) {
182
186
  return;
183
187
  }
184
188
  if (_comment.value.trim().startsWith("*")) {
185
- comment += `${_comment.value.trim().replace(/^[\s]*\*+[\s]*\**/gm, "").trim()}
189
+ comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
186
190
  `;
187
191
  }
188
192
  });
@@ -191,7 +195,7 @@ function getComment(node) {
191
195
  return;
192
196
  }
193
197
  if (_comment.value.trim().startsWith("*")) {
194
- comment += `${_comment.value.trim().replace(/^[\s]*\*+[\s]*\**/gm, "").trim()}
198
+ comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
195
199
  `;
196
200
  } else {
197
201
  comment += `${_comment.value.trim()}
@@ -2018,23 +2022,69 @@ function noIndegreeFilter(graph) {
2018
2022
  function findLinearPaths(graph) {
2019
2023
  const linearPaths = [];
2020
2024
  const visitedNodes = /* @__PURE__ */ new Set();
2025
+ const nodeInDegrees = /* @__PURE__ */ new Map();
2021
2026
  for (const [node, edges] of graph.entries()) {
2022
- if (edges.size === 1 && !visitedNodes.has(node) && node.type === "fun" /* fun */) {
2023
- const path = [node];
2024
- let nextNode = Array.from(edges)[0];
2025
- visitedNodes.add(node);
2026
- while (graph.get(nextNode)?.size === 1) {
2027
- if (visitedNodes.has(nextNode)) {
2027
+ for (const edge of edges) {
2028
+ const inDegree = nodeInDegrees.get(edge) || 0;
2029
+ nodeInDegrees.set(edge, inDegree + 1);
2030
+ }
2031
+ }
2032
+ function dfs2(node, path) {
2033
+ if (visitedNodes.has(node)) {
2034
+ return;
2035
+ }
2036
+ path.push(node);
2037
+ visitedNodes.add(node);
2038
+ const edges = graph.get(node) || /* @__PURE__ */ new Set();
2039
+ if (edges.size === 0 || edges.size > 1) {
2040
+ if (path.length > 1) {
2041
+ addOrUpdatePath([...path]);
2042
+ }
2043
+ } else {
2044
+ const nextNode = Array.from(edges)[0];
2045
+ const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
2046
+ if (nextNodeInDegree === 1) {
2047
+ dfs2(nextNode, path);
2048
+ }
2049
+ }
2050
+ path.pop();
2051
+ visitedNodes.delete(node);
2052
+ }
2053
+ function addOrUpdatePath(newPath) {
2054
+ let shouldAddNewPath = true;
2055
+ for (let i = linearPaths.length - 1; i >= 0; i--) {
2056
+ const existingPath = linearPaths[i];
2057
+ if (isSubpath(existingPath, newPath)) {
2058
+ linearPaths.splice(i, 1);
2059
+ } else if (isSubpath(newPath, existingPath)) {
2060
+ shouldAddNewPath = false;
2061
+ break;
2062
+ }
2063
+ }
2064
+ if (shouldAddNewPath && newPath.length > 2) {
2065
+ linearPaths.push(newPath);
2066
+ }
2067
+ }
2068
+ function isSubpath(shortPath, longPath) {
2069
+ if (shortPath.length >= longPath.length) {
2070
+ return false;
2071
+ }
2072
+ for (let i = 0; i <= longPath.length - shortPath.length; i++) {
2073
+ let isSub = true;
2074
+ for (let j = 0; j < shortPath.length; j++) {
2075
+ if (shortPath[j] !== longPath[i + j]) {
2076
+ isSub = false;
2028
2077
  break;
2029
2078
  }
2030
- path.push(nextNode);
2031
- visitedNodes.add(nextNode);
2032
- nextNode = Array.from(graph.get(nextNode))[0];
2033
2079
  }
2034
- if (path.length > 1) {
2035
- linearPaths.push(path);
2080
+ if (isSub) {
2081
+ return true;
2036
2082
  }
2037
2083
  }
2084
+ return false;
2085
+ }
2086
+ for (const node of graph.keys()) {
2087
+ dfs2(node, []);
2038
2088
  }
2039
2089
  return linearPaths;
2040
2090
  }