vue-hook-optimizer 0.0.55 → 0.0.56
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.d.mts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +73 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
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,
|
@@ -1883,6 +1884,67 @@ function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
|
|
1883
1884
|
};
|
1884
1885
|
}
|
1885
1886
|
|
1887
|
+
// src/analyze/style.ts
|
1888
|
+
function lexBinding(content, start) {
|
1889
|
+
let state = 0 /* inParens */;
|
1890
|
+
let parenDepth = 0;
|
1891
|
+
for (let i = start; i < content.length; i++) {
|
1892
|
+
const char = content.charAt(i);
|
1893
|
+
switch (state) {
|
1894
|
+
case 0 /* inParens */:
|
1895
|
+
if (char === "'") {
|
1896
|
+
state = 1 /* inSingleQuoteString */;
|
1897
|
+
} else if (char === '"') {
|
1898
|
+
state = 2 /* inDoubleQuoteString */;
|
1899
|
+
} else if (char === "(") {
|
1900
|
+
parenDepth++;
|
1901
|
+
} else if (char === ")") {
|
1902
|
+
if (parenDepth > 0) {
|
1903
|
+
parenDepth--;
|
1904
|
+
} else {
|
1905
|
+
return i;
|
1906
|
+
}
|
1907
|
+
}
|
1908
|
+
break;
|
1909
|
+
case 1 /* inSingleQuoteString */:
|
1910
|
+
if (char === "'") {
|
1911
|
+
state = 0 /* inParens */;
|
1912
|
+
}
|
1913
|
+
break;
|
1914
|
+
case 2 /* inDoubleQuoteString */:
|
1915
|
+
if (char === '"') {
|
1916
|
+
state = 0 /* inParens */;
|
1917
|
+
}
|
1918
|
+
break;
|
1919
|
+
}
|
1920
|
+
}
|
1921
|
+
return null;
|
1922
|
+
}
|
1923
|
+
function normalizeExpression(exp) {
|
1924
|
+
exp = exp.trim();
|
1925
|
+
if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
|
1926
|
+
return exp.slice(1, -1);
|
1927
|
+
}
|
1928
|
+
return exp;
|
1929
|
+
}
|
1930
|
+
var vBindRE = /v-bind\s*\(/g;
|
1931
|
+
function analyze5(styles) {
|
1932
|
+
const nodes = /* @__PURE__ */ new Set();
|
1933
|
+
styles.forEach((style) => {
|
1934
|
+
let match;
|
1935
|
+
const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
|
1936
|
+
while (match = vBindRE.exec(content)) {
|
1937
|
+
const start = match.index + match[0].length;
|
1938
|
+
const end = lexBinding(content, start);
|
1939
|
+
if (end !== null) {
|
1940
|
+
const variable = normalizeExpression(content.slice(start, end));
|
1941
|
+
nodes.add(variable);
|
1942
|
+
}
|
1943
|
+
}
|
1944
|
+
});
|
1945
|
+
return nodes;
|
1946
|
+
}
|
1947
|
+
|
1886
1948
|
// src/suggest/split.ts
|
1887
1949
|
function dfs(graph, node, targets, visited, component) {
|
1888
1950
|
component.add(node);
|
@@ -2057,7 +2119,8 @@ var SuggestionType = /* @__PURE__ */ ((SuggestionType2) => {
|
|
2057
2119
|
SuggestionType2["error"] = "error";
|
2058
2120
|
return SuggestionType2;
|
2059
2121
|
})(SuggestionType || {});
|
2060
|
-
function gen(graph,
|
2122
|
+
function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2123
|
+
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2061
2124
|
const suggestions = [];
|
2062
2125
|
const splitedGraph = splitGraph(graph.edges);
|
2063
2126
|
splitedGraph.forEach((g) => {
|
@@ -2121,7 +2184,8 @@ function gen(graph, usedNodes) {
|
|
2121
2184
|
}
|
2122
2185
|
|
2123
2186
|
// src/vis.ts
|
2124
|
-
function getVisData(graph,
|
2187
|
+
function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2188
|
+
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2125
2189
|
const nodes = [];
|
2126
2190
|
const edges = [];
|
2127
2191
|
graph.nodes.forEach((node) => {
|
@@ -2132,7 +2196,12 @@ function getVisData(graph, usedNodes) {
|
|
2132
2196
|
group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
|
2133
2197
|
title: `${node.info?.used?.size ? `used by ${Array.from(node.info?.used || [])?.map((i) => `\`${i}\``).join(",")}
|
2134
2198
|
|
2135
|
-
` : ""}${usedNodes.has(node.label) ?
|
2199
|
+
` : ""}${usedNodes.has(node.label) ? `used in ${[
|
2200
|
+
nodesUsedInStyle.has(node.label) ? "style" : "",
|
2201
|
+
nodesUsedInTemplate.has(node.label) ? "template" : ""
|
2202
|
+
].filter(Boolean).join(" and ")}
|
2203
|
+
|
2204
|
+
` : ""}${node.info?.comment || ""}`.trim() || void 0,
|
2136
2205
|
info: node.info
|
2137
2206
|
});
|
2138
2207
|
});
|
@@ -2164,6 +2233,7 @@ function getVisData(graph, usedNodes) {
|
|
2164
2233
|
SuggestionType,
|
2165
2234
|
analyzeOptions,
|
2166
2235
|
analyzeSetupScript,
|
2236
|
+
analyzeStyle,
|
2167
2237
|
analyzeTemplate,
|
2168
2238
|
analyzeTsx,
|
2169
2239
|
gen,
|