vue-hook-optimizer 0.0.55 → 0.0.57
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +82 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
package/dist/index.d.mts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
import { SFCStyleBlock } from '@vue/compiler-sfc';
|
1
2
|
export { parse } from '@vue/compiler-sfc';
|
2
3
|
import { Edge, Node } from 'vis-network';
|
3
4
|
|
4
|
-
declare function analyze$
|
5
|
+
declare function analyze$4(content: string): Set<string>;
|
5
6
|
|
6
7
|
interface TypedNode {
|
7
8
|
label: string;
|
@@ -18,12 +19,12 @@ declare enum NodeType {
|
|
18
19
|
fun = "fun"
|
19
20
|
}
|
20
21
|
|
21
|
-
declare function analyze$
|
22
|
+
declare function analyze$3(content: string, lineOffset?: number, jsx?: boolean): {
|
22
23
|
nodes: Set<TypedNode>;
|
23
24
|
edges: Map<TypedNode, Set<TypedNode>>;
|
24
25
|
};
|
25
26
|
|
26
|
-
declare function analyze$
|
27
|
+
declare function analyze$2(content: string, lineOffset?: number, jsx?: boolean): {
|
27
28
|
graph: {
|
28
29
|
nodes: Set<TypedNode>;
|
29
30
|
edges: Map<TypedNode, Set<TypedNode>>;
|
@@ -31,7 +32,7 @@ declare function analyze$1(content: string, lineOffset?: number, jsx?: boolean):
|
|
31
32
|
nodesUsedInTemplate: Set<string>;
|
32
33
|
};
|
33
34
|
|
34
|
-
declare function analyze(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): {
|
35
|
+
declare function analyze$1(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): {
|
35
36
|
graph: {
|
36
37
|
nodes: Set<TypedNode>;
|
37
38
|
edges: Map<TypedNode, Set<TypedNode>>;
|
@@ -39,6 +40,8 @@ declare function analyze(content: string, type?: "vue" | "react", lineOffset?: n
|
|
39
40
|
nodesUsedInTemplate: Set<string>;
|
40
41
|
};
|
41
42
|
|
43
|
+
declare function analyze(styles: SFCStyleBlock[]): Set<string>;
|
44
|
+
|
42
45
|
declare enum SuggestionType {
|
43
46
|
info = "info",
|
44
47
|
warning = "warning",
|
@@ -52,7 +55,7 @@ interface Suggestion {
|
|
52
55
|
declare function gen(graph: {
|
53
56
|
nodes: Set<TypedNode>;
|
54
57
|
edges: Map<TypedNode, Set<TypedNode>>;
|
55
|
-
},
|
58
|
+
}, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): Suggestion[];
|
56
59
|
|
57
60
|
type CustomNode = Node & {
|
58
61
|
info: TypedNode['info'];
|
@@ -60,9 +63,9 @@ type CustomNode = Node & {
|
|
60
63
|
declare function getVisData(graph: {
|
61
64
|
nodes: Set<TypedNode>;
|
62
65
|
edges: Map<TypedNode, Set<TypedNode>>;
|
63
|
-
},
|
66
|
+
}, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): {
|
64
67
|
nodes: CustomNode[];
|
65
68
|
edges: Edge[];
|
66
69
|
};
|
67
70
|
|
68
|
-
export { NodeType, type Suggestion, SuggestionType, type TypedNode, analyze$
|
71
|
+
export { NodeType, type Suggestion, SuggestionType, type TypedNode, analyze$2 as analyzeOptions, analyze$3 as analyzeSetupScript, analyze as analyzeStyle, analyze$4 as analyzeTemplate, analyze$1 as analyzeTsx, gen, getVisData };
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
import { SFCStyleBlock } from '@vue/compiler-sfc';
|
1
2
|
export { parse } from '@vue/compiler-sfc';
|
2
3
|
import { Edge, Node } from 'vis-network';
|
3
4
|
|
4
|
-
declare function analyze$
|
5
|
+
declare function analyze$4(content: string): Set<string>;
|
5
6
|
|
6
7
|
interface TypedNode {
|
7
8
|
label: string;
|
@@ -18,12 +19,12 @@ declare enum NodeType {
|
|
18
19
|
fun = "fun"
|
19
20
|
}
|
20
21
|
|
21
|
-
declare function analyze$
|
22
|
+
declare function analyze$3(content: string, lineOffset?: number, jsx?: boolean): {
|
22
23
|
nodes: Set<TypedNode>;
|
23
24
|
edges: Map<TypedNode, Set<TypedNode>>;
|
24
25
|
};
|
25
26
|
|
26
|
-
declare function analyze$
|
27
|
+
declare function analyze$2(content: string, lineOffset?: number, jsx?: boolean): {
|
27
28
|
graph: {
|
28
29
|
nodes: Set<TypedNode>;
|
29
30
|
edges: Map<TypedNode, Set<TypedNode>>;
|
@@ -31,7 +32,7 @@ declare function analyze$1(content: string, lineOffset?: number, jsx?: boolean):
|
|
31
32
|
nodesUsedInTemplate: Set<string>;
|
32
33
|
};
|
33
34
|
|
34
|
-
declare function analyze(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): {
|
35
|
+
declare function analyze$1(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): {
|
35
36
|
graph: {
|
36
37
|
nodes: Set<TypedNode>;
|
37
38
|
edges: Map<TypedNode, Set<TypedNode>>;
|
@@ -39,6 +40,8 @@ declare function analyze(content: string, type?: "vue" | "react", lineOffset?: n
|
|
39
40
|
nodesUsedInTemplate: Set<string>;
|
40
41
|
};
|
41
42
|
|
43
|
+
declare function analyze(styles: SFCStyleBlock[]): Set<string>;
|
44
|
+
|
42
45
|
declare enum SuggestionType {
|
43
46
|
info = "info",
|
44
47
|
warning = "warning",
|
@@ -52,7 +55,7 @@ interface Suggestion {
|
|
52
55
|
declare function gen(graph: {
|
53
56
|
nodes: Set<TypedNode>;
|
54
57
|
edges: Map<TypedNode, Set<TypedNode>>;
|
55
|
-
},
|
58
|
+
}, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): Suggestion[];
|
56
59
|
|
57
60
|
type CustomNode = Node & {
|
58
61
|
info: TypedNode['info'];
|
@@ -60,9 +63,9 @@ type CustomNode = Node & {
|
|
60
63
|
declare function getVisData(graph: {
|
61
64
|
nodes: Set<TypedNode>;
|
62
65
|
edges: Map<TypedNode, Set<TypedNode>>;
|
63
|
-
},
|
66
|
+
}, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): {
|
64
67
|
nodes: CustomNode[];
|
65
68
|
edges: Edge[];
|
66
69
|
};
|
67
70
|
|
68
|
-
export { NodeType, type Suggestion, SuggestionType, type TypedNode, analyze$
|
71
|
+
export { NodeType, type Suggestion, SuggestionType, type TypedNode, analyze$2 as analyzeOptions, analyze$3 as analyzeSetupScript, analyze as analyzeStyle, analyze$4 as analyzeTemplate, analyze$1 as analyzeTsx, gen, getVisData };
|
package/dist/index.js
CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
34
34
|
SuggestionType: () => SuggestionType,
|
35
35
|
analyzeOptions: () => analyze3,
|
36
36
|
analyzeSetupScript: () => analyze2,
|
37
|
+
analyzeStyle: () => analyze5,
|
37
38
|
analyzeTemplate: () => analyze,
|
38
39
|
analyzeTsx: () => analyze4,
|
39
40
|
gen: () => gen,
|
@@ -72,7 +73,9 @@ function analyze(content) {
|
|
72
73
|
if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
|
73
74
|
if (path.node.value.type === "StringLiteral") {
|
74
75
|
const name = path.node.value.value;
|
75
|
-
|
76
|
+
if (name) {
|
77
|
+
nodes.add(name);
|
78
|
+
}
|
76
79
|
}
|
77
80
|
}
|
78
81
|
},
|
@@ -81,7 +84,9 @@ function analyze(content) {
|
|
81
84
|
if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
|
82
85
|
if (path.node.arguments[0].type === "StringLiteral") {
|
83
86
|
const name = path.node.arguments[0].value;
|
84
|
-
|
87
|
+
if (name) {
|
88
|
+
nodes.add(name);
|
89
|
+
}
|
85
90
|
}
|
86
91
|
}
|
87
92
|
}
|
@@ -181,7 +186,7 @@ function getComment(node) {
|
|
181
186
|
return;
|
182
187
|
}
|
183
188
|
if (_comment.value.trim().startsWith("*")) {
|
184
|
-
comment += `${_comment.value.trim().replace(
|
189
|
+
comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
|
185
190
|
`;
|
186
191
|
}
|
187
192
|
});
|
@@ -190,7 +195,7 @@ function getComment(node) {
|
|
190
195
|
return;
|
191
196
|
}
|
192
197
|
if (_comment.value.trim().startsWith("*")) {
|
193
|
-
comment += `${_comment.value.trim().replace(
|
198
|
+
comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
|
194
199
|
`;
|
195
200
|
} else {
|
196
201
|
comment += `${_comment.value.trim()}
|
@@ -1883,6 +1888,67 @@ function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
|
|
1883
1888
|
};
|
1884
1889
|
}
|
1885
1890
|
|
1891
|
+
// src/analyze/style.ts
|
1892
|
+
function lexBinding(content, start) {
|
1893
|
+
let state = 0 /* inParens */;
|
1894
|
+
let parenDepth = 0;
|
1895
|
+
for (let i = start; i < content.length; i++) {
|
1896
|
+
const char = content.charAt(i);
|
1897
|
+
switch (state) {
|
1898
|
+
case 0 /* inParens */:
|
1899
|
+
if (char === "'") {
|
1900
|
+
state = 1 /* inSingleQuoteString */;
|
1901
|
+
} else if (char === '"') {
|
1902
|
+
state = 2 /* inDoubleQuoteString */;
|
1903
|
+
} else if (char === "(") {
|
1904
|
+
parenDepth++;
|
1905
|
+
} else if (char === ")") {
|
1906
|
+
if (parenDepth > 0) {
|
1907
|
+
parenDepth--;
|
1908
|
+
} else {
|
1909
|
+
return i;
|
1910
|
+
}
|
1911
|
+
}
|
1912
|
+
break;
|
1913
|
+
case 1 /* inSingleQuoteString */:
|
1914
|
+
if (char === "'") {
|
1915
|
+
state = 0 /* inParens */;
|
1916
|
+
}
|
1917
|
+
break;
|
1918
|
+
case 2 /* inDoubleQuoteString */:
|
1919
|
+
if (char === '"') {
|
1920
|
+
state = 0 /* inParens */;
|
1921
|
+
}
|
1922
|
+
break;
|
1923
|
+
}
|
1924
|
+
}
|
1925
|
+
return null;
|
1926
|
+
}
|
1927
|
+
function normalizeExpression(exp) {
|
1928
|
+
exp = exp.trim();
|
1929
|
+
if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
|
1930
|
+
return exp.slice(1, -1);
|
1931
|
+
}
|
1932
|
+
return exp;
|
1933
|
+
}
|
1934
|
+
var vBindRE = /v-bind\s*\(/g;
|
1935
|
+
function analyze5(styles) {
|
1936
|
+
const nodes = /* @__PURE__ */ new Set();
|
1937
|
+
styles.forEach((style) => {
|
1938
|
+
let match;
|
1939
|
+
const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
|
1940
|
+
while (match = vBindRE.exec(content)) {
|
1941
|
+
const start = match.index + match[0].length;
|
1942
|
+
const end = lexBinding(content, start);
|
1943
|
+
if (end !== null) {
|
1944
|
+
const variable = normalizeExpression(content.slice(start, end));
|
1945
|
+
nodes.add(variable);
|
1946
|
+
}
|
1947
|
+
}
|
1948
|
+
});
|
1949
|
+
return nodes;
|
1950
|
+
}
|
1951
|
+
|
1886
1952
|
// src/suggest/split.ts
|
1887
1953
|
function dfs(graph, node, targets, visited, component) {
|
1888
1954
|
component.add(node);
|
@@ -1957,7 +2023,7 @@ function findLinearPaths(graph) {
|
|
1957
2023
|
const linearPaths = [];
|
1958
2024
|
const visitedNodes = /* @__PURE__ */ new Set();
|
1959
2025
|
for (const [node, edges] of graph.entries()) {
|
1960
|
-
if (edges.size === 1 && !visitedNodes.has(node)
|
2026
|
+
if (edges.size === 1 && !visitedNodes.has(node)) {
|
1961
2027
|
const path = [node];
|
1962
2028
|
let nextNode = Array.from(edges)[0];
|
1963
2029
|
visitedNodes.add(node);
|
@@ -2057,7 +2123,8 @@ var SuggestionType = /* @__PURE__ */ ((SuggestionType2) => {
|
|
2057
2123
|
SuggestionType2["error"] = "error";
|
2058
2124
|
return SuggestionType2;
|
2059
2125
|
})(SuggestionType || {});
|
2060
|
-
function gen(graph,
|
2126
|
+
function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2127
|
+
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2061
2128
|
const suggestions = [];
|
2062
2129
|
const splitedGraph = splitGraph(graph.edges);
|
2063
2130
|
splitedGraph.forEach((g) => {
|
@@ -2121,7 +2188,8 @@ function gen(graph, usedNodes) {
|
|
2121
2188
|
}
|
2122
2189
|
|
2123
2190
|
// src/vis.ts
|
2124
|
-
function getVisData(graph,
|
2191
|
+
function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2192
|
+
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2125
2193
|
const nodes = [];
|
2126
2194
|
const edges = [];
|
2127
2195
|
graph.nodes.forEach((node) => {
|
@@ -2132,7 +2200,12 @@ function getVisData(graph, usedNodes) {
|
|
2132
2200
|
group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
|
2133
2201
|
title: `${node.info?.used?.size ? `used by ${Array.from(node.info?.used || [])?.map((i) => `\`${i}\``).join(",")}
|
2134
2202
|
|
2135
|
-
` : ""}${usedNodes.has(node.label) ?
|
2203
|
+
` : ""}${usedNodes.has(node.label) ? `used in ${[
|
2204
|
+
nodesUsedInStyle.has(node.label) ? "style" : "",
|
2205
|
+
nodesUsedInTemplate.has(node.label) ? "template" : ""
|
2206
|
+
].filter(Boolean).join(" and ")}
|
2207
|
+
|
2208
|
+
` : ""}${node.info?.comment || ""}`.trim() || void 0,
|
2136
2209
|
info: node.info
|
2137
2210
|
});
|
2138
2211
|
});
|
@@ -2164,6 +2237,7 @@ function getVisData(graph, usedNodes) {
|
|
2164
2237
|
SuggestionType,
|
2165
2238
|
analyzeOptions,
|
2166
2239
|
analyzeSetupScript,
|
2240
|
+
analyzeStyle,
|
2167
2241
|
analyzeTemplate,
|
2168
2242
|
analyzeTsx,
|
2169
2243
|
gen,
|