vue-hook-optimizer 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +127 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -46320,55 +46320,6 @@ var require_lib13 = __commonJS({
|
|
46320
46320
|
}
|
46321
46321
|
});
|
46322
46322
|
|
46323
|
-
// src/analyze/utils.ts
|
46324
|
-
var NodeType = /* @__PURE__ */ ((NodeType3) => {
|
46325
|
-
NodeType3["var"] = "var";
|
46326
|
-
NodeType3["fun"] = "fun";
|
46327
|
-
return NodeType3;
|
46328
|
-
})(NodeType || {});
|
46329
|
-
var NodeCollection = class {
|
46330
|
-
nodes = /* @__PURE__ */ new Map();
|
46331
|
-
addNode(label, node2, options = { isComputed: false }) {
|
46332
|
-
if (this.nodes.has(label)) {
|
46333
|
-
return;
|
46334
|
-
}
|
46335
|
-
if (!options.isComputed && (node2.type === "VariableDeclarator" && [
|
46336
|
-
"ArrowFunctionExpression",
|
46337
|
-
"FunctionDeclaration"
|
46338
|
-
].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
|
46339
|
-
this.nodes.set(label, {
|
46340
|
-
label,
|
46341
|
-
type: "fun" /* fun */
|
46342
|
-
});
|
46343
|
-
} else {
|
46344
|
-
this.nodes.set(label, {
|
46345
|
-
label,
|
46346
|
-
type: "var" /* var */
|
46347
|
-
});
|
46348
|
-
}
|
46349
|
-
}
|
46350
|
-
addTypedNode(label, node2) {
|
46351
|
-
this.nodes.set(label, {
|
46352
|
-
label,
|
46353
|
-
type: node2.type
|
46354
|
-
});
|
46355
|
-
}
|
46356
|
-
map(graph) {
|
46357
|
-
const nodes = new Set(Array.from(graph.nodes).map((node2) => {
|
46358
|
-
return this.nodes.get(node2);
|
46359
|
-
}).filter((node2) => !!node2));
|
46360
|
-
const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
|
46361
|
-
return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
|
46362
|
-
return this.nodes.get(node2);
|
46363
|
-
}).filter((node2) => !!node2))];
|
46364
|
-
}));
|
46365
|
-
return {
|
46366
|
-
nodes,
|
46367
|
-
edges
|
46368
|
-
};
|
46369
|
-
}
|
46370
|
-
};
|
46371
|
-
|
46372
46323
|
// node_modules/.pnpm/@vue+compiler-sfc@3.3.4/node_modules/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js
|
46373
46324
|
function makeMap(str2, expectsLowerCase) {
|
46374
46325
|
const map2 = /* @__PURE__ */ Object.create(null);
|
@@ -86312,6 +86263,57 @@ function analyze(content) {
|
|
86312
86263
|
|
86313
86264
|
// src/analyze/setupScript.ts
|
86314
86265
|
var import_traverse2 = __toESM(require_lib13());
|
86266
|
+
|
86267
|
+
// src/analyze/utils.ts
|
86268
|
+
var NodeType = /* @__PURE__ */ ((NodeType3) => {
|
86269
|
+
NodeType3["var"] = "var";
|
86270
|
+
NodeType3["fun"] = "fun";
|
86271
|
+
return NodeType3;
|
86272
|
+
})(NodeType || {});
|
86273
|
+
var NodeCollection = class {
|
86274
|
+
nodes = /* @__PURE__ */ new Map();
|
86275
|
+
addNode(label, node2, options = { isComputed: false }) {
|
86276
|
+
if (this.nodes.has(label)) {
|
86277
|
+
return;
|
86278
|
+
}
|
86279
|
+
if (!options.isComputed && (node2.type === "VariableDeclarator" && [
|
86280
|
+
"ArrowFunctionExpression",
|
86281
|
+
"FunctionDeclaration"
|
86282
|
+
].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
|
86283
|
+
this.nodes.set(label, {
|
86284
|
+
label,
|
86285
|
+
type: "fun" /* fun */
|
86286
|
+
});
|
86287
|
+
} else {
|
86288
|
+
this.nodes.set(label, {
|
86289
|
+
label,
|
86290
|
+
type: "var" /* var */
|
86291
|
+
});
|
86292
|
+
}
|
86293
|
+
}
|
86294
|
+
addTypedNode(label, node2) {
|
86295
|
+
this.nodes.set(label, {
|
86296
|
+
label,
|
86297
|
+
type: node2.type
|
86298
|
+
});
|
86299
|
+
}
|
86300
|
+
map(graph) {
|
86301
|
+
const nodes = new Set(Array.from(graph.nodes).map((node2) => {
|
86302
|
+
return this.nodes.get(node2);
|
86303
|
+
}).filter((node2) => !!node2));
|
86304
|
+
const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
|
86305
|
+
return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
|
86306
|
+
return this.nodes.get(node2);
|
86307
|
+
}).filter((node2) => !!node2))];
|
86308
|
+
}));
|
86309
|
+
return {
|
86310
|
+
nodes,
|
86311
|
+
edges
|
86312
|
+
};
|
86313
|
+
}
|
86314
|
+
};
|
86315
|
+
|
86316
|
+
// src/analyze/setupScript.ts
|
86315
86317
|
var traverse2 = (
|
86316
86318
|
//@ts-ignore
|
86317
86319
|
import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
|
@@ -86871,8 +86873,63 @@ function noIndegreeFilter(graph) {
|
|
86871
86873
|
});
|
86872
86874
|
return nodes.filter((node2) => indegree.get(node2) === 0);
|
86873
86875
|
}
|
86876
|
+
function removeVariable(graph, targets) {
|
86877
|
+
const newTarget = /* @__PURE__ */ new Set();
|
86878
|
+
targets.forEach((target) => {
|
86879
|
+
if (target.type === "var" /* var */) {
|
86880
|
+
const nodes = graph.get(target);
|
86881
|
+
nodes?.forEach((node2) => {
|
86882
|
+
newTarget.add(node2);
|
86883
|
+
});
|
86884
|
+
}
|
86885
|
+
if (target.type === "fun" /* fun */) {
|
86886
|
+
newTarget.add(target);
|
86887
|
+
}
|
86888
|
+
});
|
86889
|
+
return newTarget;
|
86890
|
+
}
|
86891
|
+
function onlyFunctions(graph) {
|
86892
|
+
const result2 = /* @__PURE__ */ new Map();
|
86893
|
+
graph.forEach((targets, node2) => {
|
86894
|
+
if (node2.type === "fun" /* fun */) {
|
86895
|
+
const nodes = removeVariable(graph, targets);
|
86896
|
+
result2.set(node2, nodes);
|
86897
|
+
}
|
86898
|
+
});
|
86899
|
+
return result2;
|
86900
|
+
}
|
86901
|
+
|
86902
|
+
// src/suggest/utils.ts
|
86903
|
+
function hasCycle(graph) {
|
86904
|
+
const visited = /* @__PURE__ */ new Set();
|
86905
|
+
function dfs2(node2) {
|
86906
|
+
if (visited.has(node2)) {
|
86907
|
+
return true;
|
86908
|
+
}
|
86909
|
+
visited.add(node2);
|
86910
|
+
for (const neighbor of graph.get(node2) || /* @__PURE__ */ new Set()) {
|
86911
|
+
if (dfs2(neighbor)) {
|
86912
|
+
return true;
|
86913
|
+
}
|
86914
|
+
}
|
86915
|
+
visited.delete(node2);
|
86916
|
+
return false;
|
86917
|
+
}
|
86918
|
+
for (const [node2, targets] of graph) {
|
86919
|
+
if (dfs2(node2)) {
|
86920
|
+
return true;
|
86921
|
+
}
|
86922
|
+
}
|
86923
|
+
return false;
|
86924
|
+
}
|
86874
86925
|
|
86875
86926
|
// src/suggest/index.ts
|
86927
|
+
var SuggestionType = /* @__PURE__ */ ((SuggestionType2) => {
|
86928
|
+
SuggestionType2["info"] = "info";
|
86929
|
+
SuggestionType2["warning"] = "warning";
|
86930
|
+
SuggestionType2["error"] = "error";
|
86931
|
+
return SuggestionType2;
|
86932
|
+
})(SuggestionType || {});
|
86876
86933
|
function gen(graph, usedNodes) {
|
86877
86934
|
const suggestions = [];
|
86878
86935
|
const splitedGraph = splitGraph(graph.edges);
|
@@ -86880,17 +86937,32 @@ function gen(graph, usedNodes) {
|
|
86880
86937
|
const nodes = Array.from(g.keys());
|
86881
86938
|
if (splitedGraph.length > 1) {
|
86882
86939
|
if (nodes.length > 2 && nodes.some((node2) => !usedNodes.has(node2.label))) {
|
86883
|
-
suggestions.push(
|
86940
|
+
suggestions.push({
|
86941
|
+
type: "info" /* info */,
|
86942
|
+
message: `Nodes [${nodes.length > 10 ? nodes.slice(0, 10).map((node2) => node2.label).join(",") + "...(" + nodes.length + ")" : nodes.map((node2) => node2.label).join(",")}] are isolated, perhaps you can refactor them to an isolated file.`
|
86943
|
+
});
|
86884
86944
|
}
|
86885
86945
|
}
|
86886
|
-
if (nodes.every((node2) => !usedNodes.has(node2.label))) {
|
86887
|
-
suggestions.push(
|
86946
|
+
if (nodes.length > 1 && nodes.every((node2) => !usedNodes.has(node2.label))) {
|
86947
|
+
suggestions.push({
|
86948
|
+
type: "info" /* info */,
|
86949
|
+
message: `Nodes [${nodes.length > 10 ? nodes.slice(0, 10).map((node2) => node2.label).join(",") + "..." : nodes.map((node2) => node2.label).join(",")}] are not used, perhaps you can remove them.`
|
86950
|
+
});
|
86951
|
+
}
|
86952
|
+
if (hasCycle(onlyFunctions(g))) {
|
86953
|
+
suggestions.push({
|
86954
|
+
type: "error" /* error */,
|
86955
|
+
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.`
|
86956
|
+
});
|
86888
86957
|
}
|
86889
86958
|
});
|
86890
86959
|
const noIndegreeNodes = noIndegreeFilter(graph.edges);
|
86891
86960
|
noIndegreeNodes.forEach((node2) => {
|
86892
86961
|
if (!usedNodes.has(node2.label)) {
|
86893
|
-
suggestions.push(
|
86962
|
+
suggestions.push({
|
86963
|
+
type: "info" /* info */,
|
86964
|
+
message: `Node [${node2.label}] is not used, perhaps you can remove it.`
|
86965
|
+
});
|
86894
86966
|
}
|
86895
86967
|
});
|
86896
86968
|
return suggestions;
|
@@ -86931,6 +87003,7 @@ function getVisData(graph, usedNodes) {
|
|
86931
87003
|
}
|
86932
87004
|
export {
|
86933
87005
|
NodeType,
|
87006
|
+
SuggestionType,
|
86934
87007
|
analyze3 as analyzeOptions,
|
86935
87008
|
analyze2 as analyzeSetupScript,
|
86936
87009
|
analyze as analyzeTemplate,
|