vue-hook-optimizer 0.0.18 → 0.0.20

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 CHANGED
@@ -86886,6 +86886,15 @@ function noIndegreeFilter(graph) {
86886
86886
  });
86887
86887
  return nodes.filter((node2) => indegree.get(node2) === 0);
86888
86888
  }
86889
+ function noOutdegreeFilter(graph) {
86890
+ const zeroOutdegreeNodes = [];
86891
+ for (let [node2, edges] of graph.entries()) {
86892
+ if (edges.size === 0) {
86893
+ zeroOutdegreeNodes.push(node2);
86894
+ }
86895
+ }
86896
+ return zeroOutdegreeNodes;
86897
+ }
86889
86898
  function removeVariable(graph, targets) {
86890
86899
  const newTarget = /* @__PURE__ */ new Set();
86891
86900
  targets.forEach((target) => {
@@ -86911,6 +86920,64 @@ function onlyFunctions(graph) {
86911
86920
  });
86912
86921
  return result2;
86913
86922
  }
86923
+ function findLinearPaths(graph) {
86924
+ let linearPaths = [];
86925
+ let visitedNodes = /* @__PURE__ */ new Set();
86926
+ for (let [node2, edges] of graph.entries()) {
86927
+ if (edges.size === 1 && !visitedNodes.has(node2)) {
86928
+ let path2 = [node2];
86929
+ let nextNode = Array.from(edges)[0];
86930
+ visitedNodes.add(node2);
86931
+ while (graph.get(nextNode)?.size === 1) {
86932
+ path2.push(nextNode);
86933
+ visitedNodes.add(nextNode);
86934
+ nextNode = Array.from(graph.get(nextNode))[0];
86935
+ }
86936
+ if (path2.length > 1) {
86937
+ linearPaths.push(path2);
86938
+ }
86939
+ }
86940
+ }
86941
+ return linearPaths;
86942
+ }
86943
+ function findArticulationPoints(graph) {
86944
+ const noIndegreeNodes = noIndegreeFilter(graph);
86945
+ let time = 0;
86946
+ const low = /* @__PURE__ */ new Map();
86947
+ const disc = /* @__PURE__ */ new Map();
86948
+ const parent = /* @__PURE__ */ new Map();
86949
+ const ap = /* @__PURE__ */ new Set();
86950
+ const visited = /* @__PURE__ */ new Set();
86951
+ function APUtil(graph2, node2) {
86952
+ let children = 0;
86953
+ disc.set(node2, time);
86954
+ low.set(node2, time);
86955
+ time++;
86956
+ visited.add(node2);
86957
+ for (let neighbor of graph2.get(node2) || []) {
86958
+ if (!visited.has(neighbor)) {
86959
+ children++;
86960
+ parent.set(neighbor, node2);
86961
+ APUtil(graph2, neighbor);
86962
+ low.set(node2, Math.min(low.get(node2), low.get(neighbor)));
86963
+ if (parent.get(node2) === null && children > 1) {
86964
+ ap.add(node2);
86965
+ }
86966
+ if (parent.get(node2) !== null && low.get(neighbor) >= disc.get(node2)) {
86967
+ ap.add(node2);
86968
+ }
86969
+ } else if (neighbor !== parent.get(node2)) {
86970
+ low.set(node2, Math.min(low.get(node2), disc.get(neighbor)));
86971
+ }
86972
+ }
86973
+ }
86974
+ for (let node2 of graph.keys()) {
86975
+ if (!visited.has(node2) && !noIndegreeNodes.includes(node2)) {
86976
+ APUtil(graph, node2);
86977
+ }
86978
+ }
86979
+ return ap;
86980
+ }
86914
86981
 
86915
86982
  // src/suggest/utils.ts
86916
86983
  function hasCycle(graph) {
@@ -86968,6 +87035,23 @@ function gen(graph, usedNodes) {
86968
87035
  message: `There is a loop call in nodes [${nodes.length > 10 ? nodes.slice(0, 10).map((node2) => node2.label).join(",") + "...(" + nodes.length + ")" : nodes.map((node2) => node2.label).join(",")}], perhaps you can refactor it.`
86969
87036
  });
86970
87037
  }
87038
+ const paths = findLinearPaths(g);
87039
+ paths.forEach((path2) => {
87040
+ suggestions.push({
87041
+ type: "warning" /* warning */,
87042
+ message: `Nodes [${path2.length > 10 ? path2.slice(0, 10).map((node2) => node2.label).join(",") + "...(" + path2.length + ")" : path2.map((node2) => node2.label).join(",")}] are have function chain calls, perhaps you can refactor it.`
87043
+ });
87044
+ });
87045
+ if (g.size > 5) {
87046
+ const ap = findArticulationPoints(g);
87047
+ ap.forEach((node2) => {
87048
+ suggestions.push({
87049
+ type: "info" /* info */,
87050
+ // eslint-disable-next-line max-len
87051
+ message: `Node [${node2.label}] is an articulation point, perhaps you need to pay special attention to this node.`
87052
+ });
87053
+ });
87054
+ }
86971
87055
  });
86972
87056
  const noIndegreeNodes = noIndegreeFilter(graph.edges);
86973
87057
  noIndegreeNodes.forEach((node2) => {
@@ -86978,6 +87062,15 @@ function gen(graph, usedNodes) {
86978
87062
  });
86979
87063
  }
86980
87064
  });
87065
+ const noOutdegreeNodes = noOutdegreeFilter(graph.edges);
87066
+ noOutdegreeNodes.forEach((node2) => {
87067
+ if (!usedNodes.has(node2.label)) {
87068
+ suggestions.push({
87069
+ type: "info" /* info */,
87070
+ message: `Node [${node2.label}] is not used, perhaps you can remove it.`
87071
+ });
87072
+ }
87073
+ });
86981
87074
  return suggestions;
86982
87075
  }
86983
87076