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.d.mts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
export { parse } from '@vue/compiler-sfc';
|
2
2
|
import * as vis_network from 'vis-network';
|
3
3
|
|
4
|
+
declare function analyze$2(content: string): Set<string>;
|
5
|
+
|
4
6
|
type TypedNode = {
|
5
7
|
label: string;
|
6
8
|
type: NodeType;
|
@@ -10,8 +12,6 @@ declare enum NodeType {
|
|
10
12
|
fun = "fun"
|
11
13
|
}
|
12
14
|
|
13
|
-
declare function analyze$2(content: string): Set<string>;
|
14
|
-
|
15
15
|
declare function analyze$1(content: string): {
|
16
16
|
nodes: Set<TypedNode>;
|
17
17
|
edges: Map<TypedNode, Set<TypedNode>>;
|
@@ -22,10 +22,19 @@ declare function analyze(content: string): {
|
|
22
22
|
edges: Map<TypedNode, Set<TypedNode>>;
|
23
23
|
};
|
24
24
|
|
25
|
+
declare enum SuggestionType {
|
26
|
+
'info' = "info",
|
27
|
+
'warning' = "warning",
|
28
|
+
'error' = "error"
|
29
|
+
}
|
30
|
+
type Suggestion = {
|
31
|
+
type: SuggestionType;
|
32
|
+
message: string;
|
33
|
+
};
|
25
34
|
declare function gen(graph: {
|
26
35
|
nodes: Set<TypedNode>;
|
27
36
|
edges: Map<TypedNode, Set<TypedNode>>;
|
28
|
-
}, usedNodes: Set<string>):
|
37
|
+
}, usedNodes: Set<string>): Suggestion[];
|
29
38
|
|
30
39
|
declare function getVisData(graph: {
|
31
40
|
nodes: Set<TypedNode>;
|
@@ -35,4 +44,4 @@ declare function getVisData(graph: {
|
|
35
44
|
edges: vis_network.Edge[];
|
36
45
|
};
|
37
46
|
|
38
|
-
export { NodeType, TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, gen, getVisData };
|
47
|
+
export { NodeType, Suggestion, SuggestionType, TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, gen, getVisData };
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
export { parse } from '@vue/compiler-sfc';
|
2
2
|
import * as vis_network from 'vis-network';
|
3
3
|
|
4
|
+
declare function analyze$2(content: string): Set<string>;
|
5
|
+
|
4
6
|
type TypedNode = {
|
5
7
|
label: string;
|
6
8
|
type: NodeType;
|
@@ -10,8 +12,6 @@ declare enum NodeType {
|
|
10
12
|
fun = "fun"
|
11
13
|
}
|
12
14
|
|
13
|
-
declare function analyze$2(content: string): Set<string>;
|
14
|
-
|
15
15
|
declare function analyze$1(content: string): {
|
16
16
|
nodes: Set<TypedNode>;
|
17
17
|
edges: Map<TypedNode, Set<TypedNode>>;
|
@@ -22,10 +22,19 @@ declare function analyze(content: string): {
|
|
22
22
|
edges: Map<TypedNode, Set<TypedNode>>;
|
23
23
|
};
|
24
24
|
|
25
|
+
declare enum SuggestionType {
|
26
|
+
'info' = "info",
|
27
|
+
'warning' = "warning",
|
28
|
+
'error' = "error"
|
29
|
+
}
|
30
|
+
type Suggestion = {
|
31
|
+
type: SuggestionType;
|
32
|
+
message: string;
|
33
|
+
};
|
25
34
|
declare function gen(graph: {
|
26
35
|
nodes: Set<TypedNode>;
|
27
36
|
edges: Map<TypedNode, Set<TypedNode>>;
|
28
|
-
}, usedNodes: Set<string>):
|
37
|
+
}, usedNodes: Set<string>): Suggestion[];
|
29
38
|
|
30
39
|
declare function getVisData(graph: {
|
31
40
|
nodes: Set<TypedNode>;
|
@@ -35,4 +44,4 @@ declare function getVisData(graph: {
|
|
35
44
|
edges: vis_network.Edge[];
|
36
45
|
};
|
37
46
|
|
38
|
-
export { NodeType, TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, gen, getVisData };
|
47
|
+
export { NodeType, Suggestion, SuggestionType, TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, gen, getVisData };
|
package/dist/index.js
CHANGED
@@ -46323,6 +46323,7 @@ var require_lib13 = __commonJS({
|
|
46323
46323
|
var src_exports = {};
|
46324
46324
|
__export(src_exports, {
|
46325
46325
|
NodeType: () => NodeType,
|
46326
|
+
SuggestionType: () => SuggestionType,
|
46326
46327
|
analyzeOptions: () => analyze3,
|
46327
46328
|
analyzeSetupScript: () => analyze2,
|
46328
46329
|
analyzeTemplate: () => analyze,
|
@@ -46332,55 +46333,6 @@ __export(src_exports, {
|
|
46332
46333
|
});
|
46333
46334
|
module.exports = __toCommonJS(src_exports);
|
46334
46335
|
|
46335
|
-
// src/analyze/utils.ts
|
46336
|
-
var NodeType = /* @__PURE__ */ ((NodeType3) => {
|
46337
|
-
NodeType3["var"] = "var";
|
46338
|
-
NodeType3["fun"] = "fun";
|
46339
|
-
return NodeType3;
|
46340
|
-
})(NodeType || {});
|
46341
|
-
var NodeCollection = class {
|
46342
|
-
nodes = /* @__PURE__ */ new Map();
|
46343
|
-
addNode(label, node2, options = { isComputed: false }) {
|
46344
|
-
if (this.nodes.has(label)) {
|
46345
|
-
return;
|
46346
|
-
}
|
46347
|
-
if (!options.isComputed && (node2.type === "VariableDeclarator" && [
|
46348
|
-
"ArrowFunctionExpression",
|
46349
|
-
"FunctionDeclaration"
|
46350
|
-
].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
|
46351
|
-
this.nodes.set(label, {
|
46352
|
-
label,
|
46353
|
-
type: "fun" /* fun */
|
46354
|
-
});
|
46355
|
-
} else {
|
46356
|
-
this.nodes.set(label, {
|
46357
|
-
label,
|
46358
|
-
type: "var" /* var */
|
46359
|
-
});
|
46360
|
-
}
|
46361
|
-
}
|
46362
|
-
addTypedNode(label, node2) {
|
46363
|
-
this.nodes.set(label, {
|
46364
|
-
label,
|
46365
|
-
type: node2.type
|
46366
|
-
});
|
46367
|
-
}
|
46368
|
-
map(graph) {
|
46369
|
-
const nodes = new Set(Array.from(graph.nodes).map((node2) => {
|
46370
|
-
return this.nodes.get(node2);
|
46371
|
-
}).filter((node2) => !!node2));
|
46372
|
-
const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
|
46373
|
-
return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
|
46374
|
-
return this.nodes.get(node2);
|
46375
|
-
}).filter((node2) => !!node2))];
|
46376
|
-
}));
|
46377
|
-
return {
|
46378
|
-
nodes,
|
46379
|
-
edges
|
46380
|
-
};
|
46381
|
-
}
|
46382
|
-
};
|
46383
|
-
|
46384
46336
|
// node_modules/.pnpm/@vue+compiler-sfc@3.3.4/node_modules/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js
|
46385
46337
|
function makeMap(str2, expectsLowerCase) {
|
46386
46338
|
const map2 = /* @__PURE__ */ Object.create(null);
|
@@ -86324,6 +86276,57 @@ function analyze(content) {
|
|
86324
86276
|
|
86325
86277
|
// src/analyze/setupScript.ts
|
86326
86278
|
var import_traverse2 = __toESM(require_lib13());
|
86279
|
+
|
86280
|
+
// src/analyze/utils.ts
|
86281
|
+
var NodeType = /* @__PURE__ */ ((NodeType3) => {
|
86282
|
+
NodeType3["var"] = "var";
|
86283
|
+
NodeType3["fun"] = "fun";
|
86284
|
+
return NodeType3;
|
86285
|
+
})(NodeType || {});
|
86286
|
+
var NodeCollection = class {
|
86287
|
+
nodes = /* @__PURE__ */ new Map();
|
86288
|
+
addNode(label, node2, options = { isComputed: false }) {
|
86289
|
+
if (this.nodes.has(label)) {
|
86290
|
+
return;
|
86291
|
+
}
|
86292
|
+
if (!options.isComputed && (node2.type === "VariableDeclarator" && [
|
86293
|
+
"ArrowFunctionExpression",
|
86294
|
+
"FunctionDeclaration"
|
86295
|
+
].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
|
86296
|
+
this.nodes.set(label, {
|
86297
|
+
label,
|
86298
|
+
type: "fun" /* fun */
|
86299
|
+
});
|
86300
|
+
} else {
|
86301
|
+
this.nodes.set(label, {
|
86302
|
+
label,
|
86303
|
+
type: "var" /* var */
|
86304
|
+
});
|
86305
|
+
}
|
86306
|
+
}
|
86307
|
+
addTypedNode(label, node2) {
|
86308
|
+
this.nodes.set(label, {
|
86309
|
+
label,
|
86310
|
+
type: node2.type
|
86311
|
+
});
|
86312
|
+
}
|
86313
|
+
map(graph) {
|
86314
|
+
const nodes = new Set(Array.from(graph.nodes).map((node2) => {
|
86315
|
+
return this.nodes.get(node2);
|
86316
|
+
}).filter((node2) => !!node2));
|
86317
|
+
const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
|
86318
|
+
return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
|
86319
|
+
return this.nodes.get(node2);
|
86320
|
+
}).filter((node2) => !!node2))];
|
86321
|
+
}));
|
86322
|
+
return {
|
86323
|
+
nodes,
|
86324
|
+
edges
|
86325
|
+
};
|
86326
|
+
}
|
86327
|
+
};
|
86328
|
+
|
86329
|
+
// src/analyze/setupScript.ts
|
86327
86330
|
var traverse2 = (
|
86328
86331
|
//@ts-ignore
|
86329
86332
|
import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
|
@@ -86883,8 +86886,63 @@ function noIndegreeFilter(graph) {
|
|
86883
86886
|
});
|
86884
86887
|
return nodes.filter((node2) => indegree.get(node2) === 0);
|
86885
86888
|
}
|
86889
|
+
function removeVariable(graph, targets) {
|
86890
|
+
const newTarget = /* @__PURE__ */ new Set();
|
86891
|
+
targets.forEach((target) => {
|
86892
|
+
if (target.type === "var" /* var */) {
|
86893
|
+
const nodes = graph.get(target);
|
86894
|
+
nodes?.forEach((node2) => {
|
86895
|
+
newTarget.add(node2);
|
86896
|
+
});
|
86897
|
+
}
|
86898
|
+
if (target.type === "fun" /* fun */) {
|
86899
|
+
newTarget.add(target);
|
86900
|
+
}
|
86901
|
+
});
|
86902
|
+
return newTarget;
|
86903
|
+
}
|
86904
|
+
function onlyFunctions(graph) {
|
86905
|
+
const result2 = /* @__PURE__ */ new Map();
|
86906
|
+
graph.forEach((targets, node2) => {
|
86907
|
+
if (node2.type === "fun" /* fun */) {
|
86908
|
+
const nodes = removeVariable(graph, targets);
|
86909
|
+
result2.set(node2, nodes);
|
86910
|
+
}
|
86911
|
+
});
|
86912
|
+
return result2;
|
86913
|
+
}
|
86914
|
+
|
86915
|
+
// src/suggest/utils.ts
|
86916
|
+
function hasCycle(graph) {
|
86917
|
+
const visited = /* @__PURE__ */ new Set();
|
86918
|
+
function dfs2(node2) {
|
86919
|
+
if (visited.has(node2)) {
|
86920
|
+
return true;
|
86921
|
+
}
|
86922
|
+
visited.add(node2);
|
86923
|
+
for (const neighbor of graph.get(node2) || /* @__PURE__ */ new Set()) {
|
86924
|
+
if (dfs2(neighbor)) {
|
86925
|
+
return true;
|
86926
|
+
}
|
86927
|
+
}
|
86928
|
+
visited.delete(node2);
|
86929
|
+
return false;
|
86930
|
+
}
|
86931
|
+
for (const [node2, targets] of graph) {
|
86932
|
+
if (dfs2(node2)) {
|
86933
|
+
return true;
|
86934
|
+
}
|
86935
|
+
}
|
86936
|
+
return false;
|
86937
|
+
}
|
86886
86938
|
|
86887
86939
|
// src/suggest/index.ts
|
86940
|
+
var SuggestionType = /* @__PURE__ */ ((SuggestionType2) => {
|
86941
|
+
SuggestionType2["info"] = "info";
|
86942
|
+
SuggestionType2["warning"] = "warning";
|
86943
|
+
SuggestionType2["error"] = "error";
|
86944
|
+
return SuggestionType2;
|
86945
|
+
})(SuggestionType || {});
|
86888
86946
|
function gen(graph, usedNodes) {
|
86889
86947
|
const suggestions = [];
|
86890
86948
|
const splitedGraph = splitGraph(graph.edges);
|
@@ -86892,17 +86950,32 @@ function gen(graph, usedNodes) {
|
|
86892
86950
|
const nodes = Array.from(g.keys());
|
86893
86951
|
if (splitedGraph.length > 1) {
|
86894
86952
|
if (nodes.length > 2 && nodes.some((node2) => !usedNodes.has(node2.label))) {
|
86895
|
-
suggestions.push(
|
86953
|
+
suggestions.push({
|
86954
|
+
type: "info" /* info */,
|
86955
|
+
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.`
|
86956
|
+
});
|
86896
86957
|
}
|
86897
86958
|
}
|
86898
|
-
if (nodes.every((node2) => !usedNodes.has(node2.label))) {
|
86899
|
-
suggestions.push(
|
86959
|
+
if (nodes.length > 1 && nodes.every((node2) => !usedNodes.has(node2.label))) {
|
86960
|
+
suggestions.push({
|
86961
|
+
type: "info" /* info */,
|
86962
|
+
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.`
|
86963
|
+
});
|
86964
|
+
}
|
86965
|
+
if (hasCycle(onlyFunctions(g))) {
|
86966
|
+
suggestions.push({
|
86967
|
+
type: "error" /* error */,
|
86968
|
+
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
|
+
});
|
86900
86970
|
}
|
86901
86971
|
});
|
86902
86972
|
const noIndegreeNodes = noIndegreeFilter(graph.edges);
|
86903
86973
|
noIndegreeNodes.forEach((node2) => {
|
86904
86974
|
if (!usedNodes.has(node2.label)) {
|
86905
|
-
suggestions.push(
|
86975
|
+
suggestions.push({
|
86976
|
+
type: "info" /* info */,
|
86977
|
+
message: `Node [${node2.label}] is not used, perhaps you can remove it.`
|
86978
|
+
});
|
86906
86979
|
}
|
86907
86980
|
});
|
86908
86981
|
return suggestions;
|
@@ -86944,6 +87017,7 @@ function getVisData(graph, usedNodes) {
|
|
86944
87017
|
// Annotate the CommonJS export names for ESM import in node:
|
86945
87018
|
0 && (module.exports = {
|
86946
87019
|
NodeType,
|
87020
|
+
SuggestionType,
|
86947
87021
|
analyzeOptions,
|
86948
87022
|
analyzeSetupScript,
|
86949
87023
|
analyzeTemplate,
|