vue-hook-optimizer 0.0.55 → 0.0.56
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 +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.mjs
CHANGED
@@ -1841,6 +1841,67 @@ function analyze4(content, type = "vue", lineOffset = 0, addInfo = true) {
|
|
1841
1841
|
};
|
1842
1842
|
}
|
1843
1843
|
|
1844
|
+
// src/analyze/style.ts
|
1845
|
+
function lexBinding(content, start) {
|
1846
|
+
let state = 0 /* inParens */;
|
1847
|
+
let parenDepth = 0;
|
1848
|
+
for (let i = start; i < content.length; i++) {
|
1849
|
+
const char = content.charAt(i);
|
1850
|
+
switch (state) {
|
1851
|
+
case 0 /* inParens */:
|
1852
|
+
if (char === "'") {
|
1853
|
+
state = 1 /* inSingleQuoteString */;
|
1854
|
+
} else if (char === '"') {
|
1855
|
+
state = 2 /* inDoubleQuoteString */;
|
1856
|
+
} else if (char === "(") {
|
1857
|
+
parenDepth++;
|
1858
|
+
} else if (char === ")") {
|
1859
|
+
if (parenDepth > 0) {
|
1860
|
+
parenDepth--;
|
1861
|
+
} else {
|
1862
|
+
return i;
|
1863
|
+
}
|
1864
|
+
}
|
1865
|
+
break;
|
1866
|
+
case 1 /* inSingleQuoteString */:
|
1867
|
+
if (char === "'") {
|
1868
|
+
state = 0 /* inParens */;
|
1869
|
+
}
|
1870
|
+
break;
|
1871
|
+
case 2 /* inDoubleQuoteString */:
|
1872
|
+
if (char === '"') {
|
1873
|
+
state = 0 /* inParens */;
|
1874
|
+
}
|
1875
|
+
break;
|
1876
|
+
}
|
1877
|
+
}
|
1878
|
+
return null;
|
1879
|
+
}
|
1880
|
+
function normalizeExpression(exp) {
|
1881
|
+
exp = exp.trim();
|
1882
|
+
if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
|
1883
|
+
return exp.slice(1, -1);
|
1884
|
+
}
|
1885
|
+
return exp;
|
1886
|
+
}
|
1887
|
+
var vBindRE = /v-bind\s*\(/g;
|
1888
|
+
function analyze5(styles) {
|
1889
|
+
const nodes = /* @__PURE__ */ new Set();
|
1890
|
+
styles.forEach((style) => {
|
1891
|
+
let match;
|
1892
|
+
const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
|
1893
|
+
while (match = vBindRE.exec(content)) {
|
1894
|
+
const start = match.index + match[0].length;
|
1895
|
+
const end = lexBinding(content, start);
|
1896
|
+
if (end !== null) {
|
1897
|
+
const variable = normalizeExpression(content.slice(start, end));
|
1898
|
+
nodes.add(variable);
|
1899
|
+
}
|
1900
|
+
}
|
1901
|
+
});
|
1902
|
+
return nodes;
|
1903
|
+
}
|
1904
|
+
|
1844
1905
|
// src/suggest/split.ts
|
1845
1906
|
function dfs(graph, node, targets, visited, component) {
|
1846
1907
|
component.add(node);
|
@@ -2015,7 +2076,8 @@ var SuggestionType = /* @__PURE__ */ ((SuggestionType2) => {
|
|
2015
2076
|
SuggestionType2["error"] = "error";
|
2016
2077
|
return SuggestionType2;
|
2017
2078
|
})(SuggestionType || {});
|
2018
|
-
function gen(graph,
|
2079
|
+
function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2080
|
+
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2019
2081
|
const suggestions = [];
|
2020
2082
|
const splitedGraph = splitGraph(graph.edges);
|
2021
2083
|
splitedGraph.forEach((g) => {
|
@@ -2079,7 +2141,8 @@ function gen(graph, usedNodes) {
|
|
2079
2141
|
}
|
2080
2142
|
|
2081
2143
|
// src/vis.ts
|
2082
|
-
function getVisData(graph,
|
2144
|
+
function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2145
|
+
const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
2083
2146
|
const nodes = [];
|
2084
2147
|
const edges = [];
|
2085
2148
|
graph.nodes.forEach((node) => {
|
@@ -2090,7 +2153,12 @@ function getVisData(graph, usedNodes) {
|
|
2090
2153
|
group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
|
2091
2154
|
title: `${node.info?.used?.size ? `used by ${Array.from(node.info?.used || [])?.map((i) => `\`${i}\``).join(",")}
|
2092
2155
|
|
2093
|
-
` : ""}${usedNodes.has(node.label) ?
|
2156
|
+
` : ""}${usedNodes.has(node.label) ? `used in ${[
|
2157
|
+
nodesUsedInStyle.has(node.label) ? "style" : "",
|
2158
|
+
nodesUsedInTemplate.has(node.label) ? "template" : ""
|
2159
|
+
].filter(Boolean).join(" and ")}
|
2160
|
+
|
2161
|
+
` : ""}${node.info?.comment || ""}`.trim() || void 0,
|
2094
2162
|
info: node.info
|
2095
2163
|
});
|
2096
2164
|
});
|
@@ -2121,6 +2189,7 @@ export {
|
|
2121
2189
|
SuggestionType,
|
2122
2190
|
analyze3 as analyzeOptions,
|
2123
2191
|
analyze2 as analyzeSetupScript,
|
2192
|
+
analyze5 as analyzeStyle,
|
2124
2193
|
analyze as analyzeTemplate,
|
2125
2194
|
analyze4 as analyzeTsx,
|
2126
2195
|
gen,
|