@geajs/vite-plugin 1.0.19 → 1.0.21
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.js +1013 -736
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1827,7 +1827,7 @@ function generate(node) {
|
|
|
1827
1827
|
import * as t22 from "@babel/types";
|
|
1828
1828
|
|
|
1829
1829
|
// src/analyze.ts
|
|
1830
|
-
import * as
|
|
1830
|
+
import * as t9 from "@babel/types";
|
|
1831
1831
|
|
|
1832
1832
|
// src/template-param-utils.ts
|
|
1833
1833
|
import * as t4 from "@babel/types";
|
|
@@ -1840,43 +1840,285 @@ function getTemplateParamBinding(param) {
|
|
|
1840
1840
|
return void 0;
|
|
1841
1841
|
}
|
|
1842
1842
|
|
|
1843
|
+
// src/component-event-helpers.ts
|
|
1844
|
+
import * as t5 from "@babel/types";
|
|
1845
|
+
import { existsSync, readFileSync } from "fs";
|
|
1846
|
+
import { dirname, resolve } from "path";
|
|
1847
|
+
var EVENT_NAMES = /* @__PURE__ */ new Set([
|
|
1848
|
+
"click",
|
|
1849
|
+
"dblclick",
|
|
1850
|
+
"mousedown",
|
|
1851
|
+
"mouseup",
|
|
1852
|
+
"mouseover",
|
|
1853
|
+
"mouseout",
|
|
1854
|
+
"mousemove",
|
|
1855
|
+
"keydown",
|
|
1856
|
+
"keyup",
|
|
1857
|
+
"keypress",
|
|
1858
|
+
"focus",
|
|
1859
|
+
"blur",
|
|
1860
|
+
"input",
|
|
1861
|
+
"change",
|
|
1862
|
+
"submit",
|
|
1863
|
+
"scroll",
|
|
1864
|
+
"touchstart",
|
|
1865
|
+
"touchmove",
|
|
1866
|
+
"touchend",
|
|
1867
|
+
"tap",
|
|
1868
|
+
"longTap",
|
|
1869
|
+
"swipeRight",
|
|
1870
|
+
"swipeUp",
|
|
1871
|
+
"swipeLeft",
|
|
1872
|
+
"swipeDown",
|
|
1873
|
+
"dragstart",
|
|
1874
|
+
"dragend",
|
|
1875
|
+
"dragover",
|
|
1876
|
+
"dragleave",
|
|
1877
|
+
"drop"
|
|
1878
|
+
]);
|
|
1879
|
+
function toGeaEventType(attrName) {
|
|
1880
|
+
if (attrName.startsWith("on") && attrName.length > 2) {
|
|
1881
|
+
const rest = attrName.slice(2);
|
|
1882
|
+
return rest.charAt(0).toLowerCase() + rest.slice(1);
|
|
1883
|
+
}
|
|
1884
|
+
return attrName;
|
|
1885
|
+
}
|
|
1886
|
+
function getPropContext(params) {
|
|
1887
|
+
const context = {
|
|
1888
|
+
destructuredPropNames: /* @__PURE__ */ new Set()
|
|
1889
|
+
};
|
|
1890
|
+
const firstParam = params?.[0];
|
|
1891
|
+
if (!firstParam || t5.isRestElement(firstParam)) return context;
|
|
1892
|
+
const binding = getTemplateParamBinding(firstParam);
|
|
1893
|
+
if (!binding) return context;
|
|
1894
|
+
if (t5.isIdentifier(binding)) {
|
|
1895
|
+
context.propsParamName = binding.name;
|
|
1896
|
+
return context;
|
|
1897
|
+
}
|
|
1898
|
+
context.propsParamName = "props";
|
|
1899
|
+
binding.properties.forEach((prop) => {
|
|
1900
|
+
if (t5.isObjectProperty(prop) && t5.isIdentifier(prop.key)) {
|
|
1901
|
+
context.destructuredPropNames.add(prop.key.name);
|
|
1902
|
+
}
|
|
1903
|
+
});
|
|
1904
|
+
return context;
|
|
1905
|
+
}
|
|
1906
|
+
function getRootClassSelector(node) {
|
|
1907
|
+
for (const attr of node.openingElement.attributes) {
|
|
1908
|
+
if (!t5.isJSXAttribute(attr) || !t5.isJSXIdentifier(attr.name)) continue;
|
|
1909
|
+
if (attr.name.name !== "class" && attr.name.name !== "className") continue;
|
|
1910
|
+
let firstClass = "";
|
|
1911
|
+
if (t5.isStringLiteral(attr.value)) {
|
|
1912
|
+
firstClass = attr.value.value.trim().split(/\s+/)[0] || "";
|
|
1913
|
+
} else if (t5.isJSXExpressionContainer(attr.value) && !t5.isJSXEmptyExpression(attr.value.expression)) {
|
|
1914
|
+
const expr = attr.value.expression;
|
|
1915
|
+
if (t5.isStringLiteral(expr)) {
|
|
1916
|
+
firstClass = expr.value.trim().split(/\s+/)[0] || "";
|
|
1917
|
+
} else if (t5.isTemplateLiteral(expr)) {
|
|
1918
|
+
firstClass = expr.quasis[0]?.value.raw.trim().split(/\s+/)[0] || "";
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
if (firstClass) return `.${firstClass}`;
|
|
1922
|
+
}
|
|
1923
|
+
return null;
|
|
1924
|
+
}
|
|
1925
|
+
function resolvePropCallbackName(expr, context) {
|
|
1926
|
+
if (t5.isIdentifier(expr) && context.destructuredPropNames.has(expr.name)) {
|
|
1927
|
+
return expr.name;
|
|
1928
|
+
}
|
|
1929
|
+
if (t5.isMemberExpression(expr) && t5.isIdentifier(expr.property) && t5.isIdentifier(expr.object) && expr.object.name === (context.propsParamName || "props")) {
|
|
1930
|
+
return expr.property.name;
|
|
1931
|
+
}
|
|
1932
|
+
if (t5.isMemberExpression(expr) && t5.isIdentifier(expr.property) && t5.isMemberExpression(expr.object) && t5.isIdentifier(expr.object.property) && expr.object.property.name === "props" && (t5.isThisExpression(expr.object.object) || t5.isIdentifier(expr.object.object) && expr.object.object.name === (context.propsParamName || "props"))) {
|
|
1933
|
+
return expr.property.name;
|
|
1934
|
+
}
|
|
1935
|
+
return null;
|
|
1936
|
+
}
|
|
1937
|
+
function extractSingleCallExpression(expr) {
|
|
1938
|
+
if (t5.isCallExpression(expr)) return expr;
|
|
1939
|
+
if (t5.isArrowFunctionExpression(expr) || t5.isFunctionExpression(expr)) {
|
|
1940
|
+
if (t5.isCallExpression(expr.body)) return expr.body;
|
|
1941
|
+
if (!t5.isBlockStatement(expr.body) || expr.body.body.length !== 1) return null;
|
|
1942
|
+
const stmt = expr.body.body[0];
|
|
1943
|
+
if (t5.isExpressionStatement(stmt) && t5.isCallExpression(stmt.expression)) return stmt.expression;
|
|
1944
|
+
if (t5.isReturnStatement(stmt) && stmt.argument && t5.isCallExpression(stmt.argument)) return stmt.argument;
|
|
1945
|
+
}
|
|
1946
|
+
return null;
|
|
1947
|
+
}
|
|
1948
|
+
function getHoistableRootEvent(attrName, expr, elementPath, context, selector) {
|
|
1949
|
+
if (elementPath.length !== 0 || !selector) return null;
|
|
1950
|
+
if (attrName.startsWith("data-") || attrName === "class" || attrName === "className" || attrName === "style" || attrName === "id")
|
|
1951
|
+
return null;
|
|
1952
|
+
const eventType = toGeaEventType(attrName);
|
|
1953
|
+
const directProp = resolvePropCallbackName(expr, context);
|
|
1954
|
+
if (directProp) return { eventType, propName: directProp, selector };
|
|
1955
|
+
const callExpr = extractSingleCallExpression(expr);
|
|
1956
|
+
if (!callExpr) return null;
|
|
1957
|
+
const propName = resolvePropCallbackName(callExpr.callee, context);
|
|
1958
|
+
if (!propName) return null;
|
|
1959
|
+
return { eventType, propName, selector };
|
|
1960
|
+
}
|
|
1961
|
+
function resolveImportPath(importer, source) {
|
|
1962
|
+
const base = resolve(dirname(importer), source);
|
|
1963
|
+
const candidates = [
|
|
1964
|
+
base,
|
|
1965
|
+
`${base}.js`,
|
|
1966
|
+
`${base}.jsx`,
|
|
1967
|
+
`${base}.ts`,
|
|
1968
|
+
`${base}.tsx`,
|
|
1969
|
+
resolve(base, "index.js"),
|
|
1970
|
+
resolve(base, "index.jsx"),
|
|
1971
|
+
resolve(base, "index.ts"),
|
|
1972
|
+
resolve(base, "index.tsx")
|
|
1973
|
+
];
|
|
1974
|
+
for (const candidate of candidates) {
|
|
1975
|
+
if (existsSync(candidate)) return candidate;
|
|
1976
|
+
}
|
|
1977
|
+
return null;
|
|
1978
|
+
}
|
|
1979
|
+
function getReturnedRootJSX(ast, componentClassName) {
|
|
1980
|
+
let found = null;
|
|
1981
|
+
for (const stmt of ast.program.body) {
|
|
1982
|
+
if (t5.isExportDefaultDeclaration(stmt)) {
|
|
1983
|
+
const decl = stmt.declaration;
|
|
1984
|
+
if (t5.isFunctionDeclaration(decl) && decl.body) {
|
|
1985
|
+
const ret = decl.body.body.find(
|
|
1986
|
+
(node) => t5.isReturnStatement(node) && node.argument && t5.isJSXElement(node.argument)
|
|
1987
|
+
);
|
|
1988
|
+
if (ret && t5.isReturnStatement(ret) && ret.argument && t5.isJSXElement(ret.argument)) {
|
|
1989
|
+
return { jsx: ret.argument, context: getPropContext(decl.params) };
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
if (t5.isIdentifier(decl)) {
|
|
1993
|
+
for (const bodyStmt of ast.program.body) {
|
|
1994
|
+
if (!t5.isVariableDeclaration(bodyStmt)) continue;
|
|
1995
|
+
for (const dec of bodyStmt.declarations) {
|
|
1996
|
+
if (!t5.isIdentifier(dec.id, { name: decl.name })) continue;
|
|
1997
|
+
if (!dec.init || !t5.isArrowFunctionExpression(dec.init) && !t5.isFunctionExpression(dec.init)) continue;
|
|
1998
|
+
const fn = dec.init;
|
|
1999
|
+
if (t5.isJSXElement(fn.body)) return { jsx: fn.body, context: getPropContext(fn.params) };
|
|
2000
|
+
if (t5.isBlockStatement(fn.body)) {
|
|
2001
|
+
const ret = fn.body.body.find(
|
|
2002
|
+
(node) => t5.isReturnStatement(node) && node.argument && t5.isJSXElement(node.argument)
|
|
2003
|
+
);
|
|
2004
|
+
if (ret && t5.isReturnStatement(ret) && ret.argument && t5.isJSXElement(ret.argument)) {
|
|
2005
|
+
return { jsx: ret.argument, context: getPropContext(fn.params) };
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
if (componentClassName && t5.isExportDefaultDeclaration(stmt) && t5.isClassDeclaration(stmt.declaration) && t5.isIdentifier(stmt.declaration.id, { name: componentClassName })) {
|
|
2013
|
+
const templateMethod = stmt.declaration.body.body.find(
|
|
2014
|
+
(member) => t5.isClassMethod(member) && t5.isIdentifier(member.key) && member.key.name === "template"
|
|
2015
|
+
);
|
|
2016
|
+
if (!templateMethod || !t5.isBlockStatement(templateMethod.body)) return null;
|
|
2017
|
+
const ret = templateMethod.body.body.find(
|
|
2018
|
+
(node) => t5.isReturnStatement(node) && node.argument && t5.isJSXElement(node.argument)
|
|
2019
|
+
);
|
|
2020
|
+
if (ret && t5.isReturnStatement(ret) && ret.argument && t5.isJSXElement(ret.argument)) {
|
|
2021
|
+
return {
|
|
2022
|
+
jsx: ret.argument,
|
|
2023
|
+
context: getPropContext(templateMethod.params)
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
for (const stmt of ast.program.body) {
|
|
2029
|
+
if (!componentClassName || !t5.isClassDeclaration(stmt) || !t5.isIdentifier(stmt.id, { name: componentClassName }))
|
|
2030
|
+
continue;
|
|
2031
|
+
const templateMethod = stmt.body.body.find(
|
|
2032
|
+
(member) => t5.isClassMethod(member) && t5.isIdentifier(member.key) && member.key.name === "template"
|
|
2033
|
+
);
|
|
2034
|
+
if (!templateMethod || !t5.isBlockStatement(templateMethod.body)) continue;
|
|
2035
|
+
const ret = templateMethod.body.body.find(
|
|
2036
|
+
(node) => t5.isReturnStatement(node) && node.argument && t5.isJSXElement(node.argument)
|
|
2037
|
+
);
|
|
2038
|
+
if (ret && t5.isReturnStatement(ret) && ret.argument && t5.isJSXElement(ret.argument)) {
|
|
2039
|
+
found = {
|
|
2040
|
+
jsx: ret.argument,
|
|
2041
|
+
context: getPropContext(templateMethod.params)
|
|
2042
|
+
};
|
|
2043
|
+
break;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
return found;
|
|
2047
|
+
}
|
|
2048
|
+
var hoistableRootEventCache = /* @__PURE__ */ new Map();
|
|
2049
|
+
function getHoistableRootEventsForImport(importer, source) {
|
|
2050
|
+
const resolved = resolveImportPath(importer, source);
|
|
2051
|
+
if (!resolved) return [];
|
|
2052
|
+
const cached = hoistableRootEventCache.get(resolved);
|
|
2053
|
+
if (cached) return cached;
|
|
2054
|
+
let result;
|
|
2055
|
+
try {
|
|
2056
|
+
const code = readFileSync(resolved, "utf8");
|
|
2057
|
+
const parsed = parseSource(code);
|
|
2058
|
+
if (!parsed) return [];
|
|
2059
|
+
const root = getReturnedRootJSX(parsed.ast, parsed.componentClassName);
|
|
2060
|
+
if (!root) return [];
|
|
2061
|
+
const selector = getRootClassSelector(root.jsx);
|
|
2062
|
+
if (!selector) return [];
|
|
2063
|
+
result = root.jsx.openingElement.attributes.flatMap((attr) => {
|
|
2064
|
+
if (!t5.isJSXAttribute(attr) || !t5.isJSXIdentifier(attr.name)) return [];
|
|
2065
|
+
if (!attr.value || !t5.isJSXExpressionContainer(attr.value) || t5.isJSXEmptyExpression(attr.value.expression)) {
|
|
2066
|
+
return [];
|
|
2067
|
+
}
|
|
2068
|
+
const meta = getHoistableRootEvent(
|
|
2069
|
+
attr.name.name,
|
|
2070
|
+
attr.value.expression,
|
|
2071
|
+
[],
|
|
2072
|
+
root.context,
|
|
2073
|
+
selector
|
|
2074
|
+
);
|
|
2075
|
+
return meta ? [meta] : [];
|
|
2076
|
+
});
|
|
2077
|
+
} catch (err) {
|
|
2078
|
+
console.warn(`[gea] Failed to analyze root events for ${resolved}:`, err instanceof Error ? err.message : err);
|
|
2079
|
+
result = [];
|
|
2080
|
+
}
|
|
2081
|
+
hoistableRootEventCache.set(resolved, result);
|
|
2082
|
+
return result;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
1843
2085
|
// src/analyze-map.ts
|
|
1844
|
-
import * as
|
|
2086
|
+
import * as t7 from "@babel/types";
|
|
1845
2087
|
|
|
1846
2088
|
// src/analyze-helpers.ts
|
|
1847
|
-
import * as
|
|
2089
|
+
import * as t6 from "@babel/types";
|
|
1848
2090
|
function resolvePropRef(expr, propsParamName, destructuredPropNames) {
|
|
1849
|
-
if (
|
|
1850
|
-
if (!
|
|
2091
|
+
if (t6.isIdentifier(expr) && destructuredPropNames?.has(expr.name)) return expr.name;
|
|
2092
|
+
if (!t6.isMemberExpression(expr) || !t6.isIdentifier(expr.property)) return null;
|
|
1851
2093
|
const propName = expr.property.name;
|
|
1852
|
-
if (
|
|
2094
|
+
if (t6.isMemberExpression(expr.object) && t6.isIdentifier(expr.object.property) && expr.object.property.name === "props") {
|
|
1853
2095
|
const obj = expr.object.object;
|
|
1854
|
-
if (
|
|
1855
|
-
if (
|
|
2096
|
+
if (t6.isThisExpression(obj)) return propName;
|
|
2097
|
+
if (t6.isIdentifier(obj) && obj.name === propsParamName) return propName;
|
|
1856
2098
|
}
|
|
1857
|
-
if (
|
|
2099
|
+
if (t6.isIdentifier(expr.object) && expr.object.name === (propsParamName || "props")) return propName;
|
|
1858
2100
|
return null;
|
|
1859
2101
|
}
|
|
1860
2102
|
function resolveExpr(expr, stateRefs) {
|
|
1861
|
-
if (
|
|
2103
|
+
if (t6.isMemberExpression(expr) && t6.isCallExpression(expr.object) && t6.isMemberExpression(expr.object.callee)) {
|
|
1862
2104
|
return resolvePath(expr.object.callee.object, stateRefs);
|
|
1863
2105
|
}
|
|
1864
|
-
if (
|
|
1865
|
-
if (
|
|
1866
|
-
if (
|
|
2106
|
+
if (t6.isMemberExpression(expr) || t6.isIdentifier(expr)) return resolvePath(expr, stateRefs);
|
|
2107
|
+
if (t6.isCallExpression(expr)) {
|
|
2108
|
+
if (t6.isMemberExpression(expr.callee)) {
|
|
1867
2109
|
const result = resolvePath(expr.callee.object, stateRefs);
|
|
1868
2110
|
if (result?.parts?.length) return result;
|
|
1869
2111
|
}
|
|
1870
2112
|
for (const arg of expr.arguments) {
|
|
1871
|
-
if (
|
|
2113
|
+
if (t6.isExpression(arg) && (t6.isMemberExpression(arg) || t6.isIdentifier(arg))) {
|
|
1872
2114
|
const result = resolvePath(arg, stateRefs);
|
|
1873
2115
|
if (result?.parts?.length) return result;
|
|
1874
2116
|
}
|
|
1875
2117
|
}
|
|
1876
2118
|
}
|
|
1877
|
-
if (
|
|
2119
|
+
if (t6.isTemplateLiteral(expr)) {
|
|
1878
2120
|
for (const inner of expr.expressions) {
|
|
1879
|
-
if (
|
|
2121
|
+
if (t6.isExpression(inner)) {
|
|
1880
2122
|
const result = resolveExpr(inner, stateRefs);
|
|
1881
2123
|
if (result?.parts?.length) return result;
|
|
1882
2124
|
}
|
|
@@ -1894,7 +2136,7 @@ function applyImportedState(binding, result, stateProps) {
|
|
|
1894
2136
|
function isComputedArrayProp(pathParts, textExpressions, stateRefs) {
|
|
1895
2137
|
const deps = /* @__PURE__ */ new Set();
|
|
1896
2138
|
textExpressions.forEach((te) => {
|
|
1897
|
-
if (te.expression &&
|
|
2139
|
+
if (te.expression && t6.isCallExpression(te.expression) && t6.isMemberExpression(te.expression.callee)) {
|
|
1898
2140
|
const r = resolvePath(te.expression.callee.object, stateRefs);
|
|
1899
2141
|
if (r?.parts?.length) deps.add(r.parts[0]);
|
|
1900
2142
|
}
|
|
@@ -1905,7 +2147,7 @@ function addArrayTextBindings(selector, tagName, elementPath, bindings, statePro
|
|
|
1905
2147
|
const deps = /* @__PURE__ */ new Set();
|
|
1906
2148
|
textExpressions.forEach((te) => {
|
|
1907
2149
|
if (te.pathParts.length > 0) deps.add(te.pathParts[0]);
|
|
1908
|
-
if (te.expression &&
|
|
2150
|
+
if (te.expression && t6.isCallExpression(te.expression) && t6.isMemberExpression(te.expression.callee)) {
|
|
1909
2151
|
const r = resolvePath(te.expression.callee.object, stateRefs);
|
|
1910
2152
|
if (r?.parts?.length) deps.add(r.parts[0]);
|
|
1911
2153
|
}
|
|
@@ -1931,10 +2173,10 @@ function addArrayTextBindings(selector, tagName, elementPath, bindings, statePro
|
|
|
1931
2173
|
});
|
|
1932
2174
|
}
|
|
1933
2175
|
function unwrapJSX(expr) {
|
|
1934
|
-
if (
|
|
1935
|
-
if (
|
|
1936
|
-
if (
|
|
1937
|
-
if (
|
|
2176
|
+
if (t6.isJSXElement(expr)) return expr;
|
|
2177
|
+
if (t6.isJSXFragment(expr)) return expr;
|
|
2178
|
+
if (t6.isParenthesizedExpression(expr) && t6.isJSXElement(expr.expression)) return expr.expression;
|
|
2179
|
+
if (t6.isConditionalExpression(expr)) {
|
|
1938
2180
|
const fromCons = unwrapJSX(expr.consequent);
|
|
1939
2181
|
if (fromCons) return fromCons;
|
|
1940
2182
|
return unwrapJSX(expr.alternate);
|
|
@@ -1943,14 +2185,14 @@ function unwrapJSX(expr) {
|
|
|
1943
2185
|
}
|
|
1944
2186
|
function normalizeDestructuredMapCallback(arrowFn) {
|
|
1945
2187
|
const param = arrowFn.params[0];
|
|
1946
|
-
if (!param ||
|
|
1947
|
-
if (!
|
|
2188
|
+
if (!param || t6.isIdentifier(param) || t6.isRestElement(param)) return;
|
|
2189
|
+
if (!t6.isObjectPattern(param) && !t6.isArrayPattern(param)) return;
|
|
1948
2190
|
const itemName = "__item";
|
|
1949
|
-
if (
|
|
2191
|
+
if (t6.isArrayPattern(param)) {
|
|
1950
2192
|
const indexMap = /* @__PURE__ */ new Map();
|
|
1951
2193
|
for (let i = 0; i < param.elements.length; i++) {
|
|
1952
2194
|
const el = param.elements[i];
|
|
1953
|
-
if (
|
|
2195
|
+
if (t6.isIdentifier(el)) indexMap.set(el.name, i);
|
|
1954
2196
|
}
|
|
1955
2197
|
if (indexMap.size === 0) return;
|
|
1956
2198
|
const rewriteNode2 = (node) => {
|
|
@@ -1962,12 +2204,12 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
1962
2204
|
if (Array.isArray(child)) {
|
|
1963
2205
|
for (let i = 0; i < child.length; i++) {
|
|
1964
2206
|
if (child[i] && typeof child[i] === "object" && child[i].type) {
|
|
1965
|
-
if (
|
|
1966
|
-
if (
|
|
1967
|
-
if (
|
|
1968
|
-
child[i] =
|
|
1969
|
-
|
|
1970
|
-
|
|
2207
|
+
if (t6.isIdentifier(child[i]) && indexMap.has(child[i].name)) {
|
|
2208
|
+
if (t6.isMemberExpression(node) && key === "property" && !node.computed) continue;
|
|
2209
|
+
if (t6.isObjectProperty(node) && key === "key") continue;
|
|
2210
|
+
child[i] = t6.memberExpression(
|
|
2211
|
+
t6.identifier(itemName),
|
|
2212
|
+
t6.numericLiteral(indexMap.get(child[i].name)),
|
|
1971
2213
|
true
|
|
1972
2214
|
);
|
|
1973
2215
|
} else {
|
|
@@ -1976,12 +2218,12 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
1976
2218
|
}
|
|
1977
2219
|
}
|
|
1978
2220
|
} else if (child && typeof child === "object" && child.type) {
|
|
1979
|
-
if (
|
|
1980
|
-
if (
|
|
1981
|
-
if (
|
|
1982
|
-
node[key] =
|
|
1983
|
-
|
|
1984
|
-
|
|
2221
|
+
if (t6.isIdentifier(child) && indexMap.has(child.name)) {
|
|
2222
|
+
if (t6.isMemberExpression(node) && key === "property" && !node.computed) continue;
|
|
2223
|
+
if (t6.isObjectProperty(node) && key === "key") continue;
|
|
2224
|
+
node[key] = t6.memberExpression(
|
|
2225
|
+
t6.identifier(itemName),
|
|
2226
|
+
t6.numericLiteral(indexMap.get(child.name)),
|
|
1985
2227
|
true
|
|
1986
2228
|
);
|
|
1987
2229
|
} else {
|
|
@@ -1991,14 +2233,14 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
1991
2233
|
}
|
|
1992
2234
|
};
|
|
1993
2235
|
rewriteNode2(arrowFn.body);
|
|
1994
|
-
arrowFn.params[0] =
|
|
2236
|
+
arrowFn.params[0] = t6.identifier(itemName);
|
|
1995
2237
|
return;
|
|
1996
2238
|
}
|
|
1997
2239
|
const nameMap = /* @__PURE__ */ new Map();
|
|
1998
2240
|
for (const prop of param.properties) {
|
|
1999
|
-
if (
|
|
2000
|
-
const keyName =
|
|
2001
|
-
const valueName =
|
|
2241
|
+
if (t6.isObjectProperty(prop)) {
|
|
2242
|
+
const keyName = t6.isIdentifier(prop.key) ? prop.key.name : t6.isStringLiteral(prop.key) ? prop.key.value : null;
|
|
2243
|
+
const valueName = t6.isIdentifier(prop.value) ? prop.value.name : null;
|
|
2002
2244
|
if (keyName && valueName) nameMap.set(valueName, keyName);
|
|
2003
2245
|
}
|
|
2004
2246
|
}
|
|
@@ -2012,20 +2254,20 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
2012
2254
|
if (Array.isArray(child)) {
|
|
2013
2255
|
for (let i = 0; i < child.length; i++) {
|
|
2014
2256
|
if (child[i] && typeof child[i] === "object" && child[i].type) {
|
|
2015
|
-
if (
|
|
2016
|
-
if (
|
|
2017
|
-
if (
|
|
2018
|
-
child[i] =
|
|
2257
|
+
if (t6.isIdentifier(child[i]) && nameMap.has(child[i].name)) {
|
|
2258
|
+
if (t6.isMemberExpression(node) && key === "property" && !node.computed) continue;
|
|
2259
|
+
if (t6.isObjectProperty(node) && key === "key") continue;
|
|
2260
|
+
child[i] = t6.memberExpression(t6.identifier(itemName), t6.identifier(nameMap.get(child[i].name)));
|
|
2019
2261
|
} else {
|
|
2020
2262
|
rewriteNode(child[i]);
|
|
2021
2263
|
}
|
|
2022
2264
|
}
|
|
2023
2265
|
}
|
|
2024
2266
|
} else if (child && typeof child === "object" && child.type) {
|
|
2025
|
-
if (
|
|
2026
|
-
if (
|
|
2027
|
-
if (
|
|
2028
|
-
node[key] =
|
|
2267
|
+
if (t6.isIdentifier(child) && nameMap.has(child.name)) {
|
|
2268
|
+
if (t6.isMemberExpression(node) && key === "property" && !node.computed) continue;
|
|
2269
|
+
if (t6.isObjectProperty(node) && key === "key") continue;
|
|
2270
|
+
node[key] = t6.memberExpression(t6.identifier(itemName), t6.identifier(nameMap.get(child.name)));
|
|
2029
2271
|
} else {
|
|
2030
2272
|
rewriteNode(child);
|
|
2031
2273
|
}
|
|
@@ -2033,29 +2275,29 @@ function normalizeDestructuredMapCallback(arrowFn) {
|
|
|
2033
2275
|
}
|
|
2034
2276
|
};
|
|
2035
2277
|
rewriteNode(arrowFn.body);
|
|
2036
|
-
arrowFn.params[0] =
|
|
2278
|
+
arrowFn.params[0] = t6.identifier(itemName);
|
|
2037
2279
|
}
|
|
2038
2280
|
function extractItemTemplate(arrowFn) {
|
|
2039
2281
|
let body;
|
|
2040
|
-
if (
|
|
2041
|
-
else if (
|
|
2042
|
-
else if (
|
|
2043
|
-
const returnStmt = arrowFn.body.body.find((s) =>
|
|
2282
|
+
if (t6.isJSXElement(arrowFn.body) || t6.isJSXFragment(arrowFn.body)) body = arrowFn.body;
|
|
2283
|
+
else if (t6.isParenthesizedExpression(arrowFn.body)) body = arrowFn.body.expression;
|
|
2284
|
+
else if (t6.isBlockStatement(arrowFn.body)) {
|
|
2285
|
+
const returnStmt = arrowFn.body.body.find((s) => t6.isReturnStatement(s));
|
|
2044
2286
|
body = returnStmt?.argument;
|
|
2045
|
-
} else if (
|
|
2287
|
+
} else if (t6.isConditionalExpression(arrowFn.body)) body = arrowFn.body;
|
|
2046
2288
|
return body ? unwrapJSX(body) : void 0;
|
|
2047
2289
|
}
|
|
2048
2290
|
function extractCallbackBodyStatements(arrowFn) {
|
|
2049
|
-
if (!
|
|
2291
|
+
if (!t6.isBlockStatement(arrowFn.body)) return [];
|
|
2050
2292
|
const stmts = [];
|
|
2051
2293
|
for (const s of arrowFn.body.body) {
|
|
2052
|
-
if (
|
|
2053
|
-
if (
|
|
2294
|
+
if (t6.isReturnStatement(s) && s.argument) {
|
|
2295
|
+
if (t6.isJSXElement(s.argument) || t6.isJSXFragment(s.argument) || t6.isParenthesizedExpression(s.argument)) {
|
|
2054
2296
|
break;
|
|
2055
2297
|
}
|
|
2056
|
-
stmts.push(
|
|
2298
|
+
stmts.push(t6.returnStatement(t6.stringLiteral("")));
|
|
2057
2299
|
} else {
|
|
2058
|
-
const cloned =
|
|
2300
|
+
const cloned = t6.cloneNode(s, true);
|
|
2059
2301
|
rewriteEarlyReturns(cloned);
|
|
2060
2302
|
stmts.push(cloned);
|
|
2061
2303
|
}
|
|
@@ -2063,18 +2305,18 @@ function extractCallbackBodyStatements(arrowFn) {
|
|
|
2063
2305
|
return stmts;
|
|
2064
2306
|
}
|
|
2065
2307
|
function rewriteEarlyReturns(node) {
|
|
2066
|
-
if (
|
|
2067
|
-
if (
|
|
2068
|
-
if (!node.consequent.argument ||
|
|
2069
|
-
node.consequent =
|
|
2308
|
+
if (t6.isIfStatement(node)) {
|
|
2309
|
+
if (t6.isReturnStatement(node.consequent)) {
|
|
2310
|
+
if (!node.consequent.argument || t6.isNullLiteral(node.consequent.argument) || t6.isIdentifier(node.consequent.argument) && node.consequent.argument.name === "undefined") {
|
|
2311
|
+
node.consequent = t6.returnStatement(t6.stringLiteral(""));
|
|
2070
2312
|
}
|
|
2071
|
-
} else if (
|
|
2313
|
+
} else if (t6.isBlockStatement(node.consequent)) {
|
|
2072
2314
|
node.consequent.body.forEach(rewriteEarlyReturns);
|
|
2073
2315
|
}
|
|
2074
2316
|
if (node.alternate) {
|
|
2075
|
-
if (
|
|
2076
|
-
if (!node.alternate.argument ||
|
|
2077
|
-
node.alternate =
|
|
2317
|
+
if (t6.isReturnStatement(node.alternate)) {
|
|
2318
|
+
if (!node.alternate.argument || t6.isNullLiteral(node.alternate.argument) || t6.isIdentifier(node.alternate.argument) && node.alternate.argument.name === "undefined") {
|
|
2319
|
+
node.alternate = t6.returnStatement(t6.stringLiteral(""));
|
|
2078
2320
|
}
|
|
2079
2321
|
} else {
|
|
2080
2322
|
rewriteEarlyReturns(node.alternate);
|
|
@@ -2086,42 +2328,42 @@ var ITEM_IS_KEY = "__self__";
|
|
|
2086
2328
|
function getItemMemberPath(expr, itemVar) {
|
|
2087
2329
|
const parts = [];
|
|
2088
2330
|
let current = expr;
|
|
2089
|
-
while (
|
|
2331
|
+
while (t6.isMemberExpression(current) && !current.computed && t6.isIdentifier(current.property)) {
|
|
2090
2332
|
parts.unshift(current.property.name);
|
|
2091
2333
|
current = current.object;
|
|
2092
2334
|
}
|
|
2093
|
-
if (!
|
|
2335
|
+
if (!t6.isIdentifier(current) || current.name !== itemVar || parts.length === 0) return void 0;
|
|
2094
2336
|
return parts.join(".");
|
|
2095
2337
|
}
|
|
2096
2338
|
function detectItemIdProperty(template, itemVar) {
|
|
2097
|
-
if (!template || !
|
|
2339
|
+
if (!template || !t6.isJSXElement(template)) return void 0;
|
|
2098
2340
|
for (const attr of template.openingElement.attributes) {
|
|
2099
|
-
if (!
|
|
2100
|
-
if (!
|
|
2341
|
+
if (!t6.isJSXAttribute(attr) || !t6.isJSXIdentifier(attr.name) || attr.name.name !== "key") continue;
|
|
2342
|
+
if (!t6.isJSXExpressionContainer(attr.value)) continue;
|
|
2101
2343
|
const keyExpr = attr.value.expression;
|
|
2102
2344
|
const memberPath = getItemMemberPath(keyExpr, itemVar);
|
|
2103
2345
|
if (memberPath) return memberPath;
|
|
2104
|
-
if (
|
|
2346
|
+
if (t6.isIdentifier(keyExpr) && keyExpr.name === itemVar) return ITEM_IS_KEY;
|
|
2105
2347
|
}
|
|
2106
2348
|
return void 0;
|
|
2107
2349
|
}
|
|
2108
2350
|
function hasExplicitItemKey(template) {
|
|
2109
|
-
if (!template || !
|
|
2351
|
+
if (!template || !t6.isJSXElement(template)) return false;
|
|
2110
2352
|
return template.openingElement.attributes.some(
|
|
2111
|
-
(attr) =>
|
|
2353
|
+
(attr) => t6.isJSXAttribute(attr) && t6.isJSXIdentifier(attr.name) && attr.name.name === "key"
|
|
2112
2354
|
);
|
|
2113
2355
|
}
|
|
2114
2356
|
function hasRootUserIdAttribute(template) {
|
|
2115
|
-
if (!template || !
|
|
2357
|
+
if (!template || !t6.isJSXElement(template)) return false;
|
|
2116
2358
|
return template.openingElement.attributes.some(
|
|
2117
|
-
(attr) =>
|
|
2359
|
+
(attr) => t6.isJSXAttribute(attr) && t6.isJSXIdentifier(attr.name) && attr.name.name === "id"
|
|
2118
2360
|
);
|
|
2119
2361
|
}
|
|
2120
2362
|
function detectContainerSelector(node, tagName) {
|
|
2121
2363
|
for (const attr of node.openingElement.attributes) {
|
|
2122
|
-
if (!
|
|
2123
|
-
if (attr.name.name === "class" &&
|
|
2124
|
-
if (attr.name.name === "id" &&
|
|
2364
|
+
if (!t6.isJSXAttribute(attr) || !t6.isJSXIdentifier(attr.name)) continue;
|
|
2365
|
+
if (attr.name.name === "class" && t6.isStringLiteral(attr.value)) return `.${attr.value.value.split(" ")[0]}`;
|
|
2366
|
+
if (attr.name.name === "id" && t6.isStringLiteral(attr.value)) return `#${attr.value.value}`;
|
|
2125
2367
|
}
|
|
2126
2368
|
return tagName;
|
|
2127
2369
|
}
|
|
@@ -2133,21 +2375,21 @@ var traverse3 = require4("@babel/traverse").default;
|
|
|
2133
2375
|
function getItemMemberPath2(expr, itemVar) {
|
|
2134
2376
|
const parts = [];
|
|
2135
2377
|
let current = expr;
|
|
2136
|
-
while (
|
|
2378
|
+
while (t7.isMemberExpression(current) && !current.computed && t7.isIdentifier(current.property)) {
|
|
2137
2379
|
parts.unshift(current.property.name);
|
|
2138
2380
|
current = current.object;
|
|
2139
2381
|
}
|
|
2140
|
-
if (!
|
|
2382
|
+
if (!t7.isIdentifier(current) || current.name !== itemVar || parts.length === 0) return null;
|
|
2141
2383
|
return parts.join(".");
|
|
2142
2384
|
}
|
|
2143
2385
|
function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindings, conditionalBindings, elementPath, isImportedState, itemIdProperty, stateRefs, childIndices = [], storeVar) {
|
|
2144
2386
|
const context = { inMap: true, mapItemVar: itemVar };
|
|
2145
2387
|
node.openingElement.attributes.forEach((attr) => {
|
|
2146
|
-
if (!
|
|
2388
|
+
if (!t7.isJSXAttribute(attr) || !t7.isJSXIdentifier(attr.name)) return;
|
|
2147
2389
|
const attrName = attr.name.name;
|
|
2148
|
-
if (!attr.value || !
|
|
2390
|
+
if (!attr.value || !t7.isJSXExpressionContainer(attr.value)) return;
|
|
2149
2391
|
const expr = attr.value.expression;
|
|
2150
|
-
if (
|
|
2392
|
+
if (t7.isMemberExpression(expr)) {
|
|
2151
2393
|
analyzeItemMemberExpr(
|
|
2152
2394
|
expr,
|
|
2153
2395
|
attrName,
|
|
@@ -2162,7 +2404,7 @@ function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindi
|
|
|
2162
2404
|
context,
|
|
2163
2405
|
childIndices
|
|
2164
2406
|
);
|
|
2165
|
-
} else if (
|
|
2407
|
+
} else if (t7.isConditionalExpression(expr)) {
|
|
2166
2408
|
const isClassAttr = attrName === "class" || attrName === "className";
|
|
2167
2409
|
analyzeItemConditional(
|
|
2168
2410
|
expr,
|
|
@@ -2181,7 +2423,7 @@ function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindi
|
|
|
2181
2423
|
storeVar,
|
|
2182
2424
|
isClassAttr
|
|
2183
2425
|
);
|
|
2184
|
-
} else if (
|
|
2426
|
+
} else if (t7.isTemplateLiteral(expr)) {
|
|
2185
2427
|
analyzeItemTemplateLiteral(
|
|
2186
2428
|
expr,
|
|
2187
2429
|
arrayPath,
|
|
@@ -2200,8 +2442,8 @@ function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindi
|
|
|
2200
2442
|
}
|
|
2201
2443
|
});
|
|
2202
2444
|
node.children.forEach((child) => {
|
|
2203
|
-
if (
|
|
2204
|
-
if (
|
|
2445
|
+
if (t7.isJSXExpressionContainer(child) && !t7.isJSXEmptyExpression(child.expression)) {
|
|
2446
|
+
if (t7.isMemberExpression(child.expression)) {
|
|
2205
2447
|
const propPathResult = resolvePath(child.expression, stateRefs, context);
|
|
2206
2448
|
if (propPathResult?.parts?.length === 1 && propPathResult.parts[0] !== "id") {
|
|
2207
2449
|
const wildcardPath = [...arrayPath, "*", propPathResult.parts[0]];
|
|
@@ -2215,7 +2457,7 @@ function analyzeJSXInMap(node, arrayPath, itemVar, itemBindings, relationalBindi
|
|
|
2215
2457
|
};
|
|
2216
2458
|
itemBindings.push(binding);
|
|
2217
2459
|
}
|
|
2218
|
-
} else if (
|
|
2460
|
+
} else if (t7.isConditionalExpression(child.expression)) {
|
|
2219
2461
|
collectConditionalBindings(
|
|
2220
2462
|
child.expression,
|
|
2221
2463
|
"text",
|
|
@@ -2272,8 +2514,8 @@ function analyzeItemConditional(expr, attrName, arrayPath, itemVar, itemBindings
|
|
|
2272
2514
|
return;
|
|
2273
2515
|
}
|
|
2274
2516
|
const isClassAttribute = attrName === "class" || attrName === "className";
|
|
2275
|
-
if (isClassAttribute &&
|
|
2276
|
-
const propName =
|
|
2517
|
+
if (isClassAttribute && t7.isMemberExpression(expr.test) && t7.isIdentifier(expr.test.object) && expr.test.object.name === itemVar) {
|
|
2518
|
+
const propName = t7.isIdentifier(expr.test.property) ? expr.test.property.name : null;
|
|
2277
2519
|
if (!propName) return;
|
|
2278
2520
|
const detectedClassName = extractClassName(expr.consequent) || extractClassName(expr.alternate);
|
|
2279
2521
|
const wildcardPath = [...arrayPath, "*", propName];
|
|
@@ -2291,7 +2533,7 @@ function analyzeItemConditional(expr, attrName, arrayPath, itemVar, itemBindings
|
|
|
2291
2533
|
itemBindings.push(binding);
|
|
2292
2534
|
return;
|
|
2293
2535
|
}
|
|
2294
|
-
if (isClassAttribute &&
|
|
2536
|
+
if (isClassAttribute && t7.isBinaryExpression(expr.test) && (expr.test.operator === "===" || expr.test.operator === "==")) {
|
|
2295
2537
|
const detectedClassName = extractClassName(expr.consequent) || extractClassName(expr.alternate);
|
|
2296
2538
|
if (!detectedClassName) return;
|
|
2297
2539
|
const binding = {
|
|
@@ -2323,7 +2565,7 @@ function analyzeItemConditional(expr, attrName, arrayPath, itemVar, itemBindings
|
|
|
2323
2565
|
}
|
|
2324
2566
|
function analyzeItemTemplateLiteral(expr, arrayPath, itemVar, itemBindings, relationalBindings, conditionalBindings, elementPath, isImportedState, itemIdProperty, node, stateRefs, childIndices = [], storeVar) {
|
|
2325
2567
|
expr.expressions.forEach((innerExpr) => {
|
|
2326
|
-
if (!
|
|
2568
|
+
if (!t7.isConditionalExpression(innerExpr)) return;
|
|
2327
2569
|
analyzeItemConditional(
|
|
2328
2570
|
innerExpr,
|
|
2329
2571
|
"class",
|
|
@@ -2345,13 +2587,13 @@ function analyzeItemTemplateLiteral(expr, arrayPath, itemVar, itemBindings, rela
|
|
|
2345
2587
|
function collectConditionalBindings(expr, type, attributeName, conditionalBindings, arrayPath, itemVar, elementPath, childPath, stateRefs, storeVar) {
|
|
2346
2588
|
const dependencies = /* @__PURE__ */ new Map();
|
|
2347
2589
|
const requiresRerender = conditionalExpressionRequiresRerender(expr);
|
|
2348
|
-
const program12 =
|
|
2590
|
+
const program12 = t7.program([t7.expressionStatement(t7.cloneNode(expr, true))]);
|
|
2349
2591
|
traverse3(program12, {
|
|
2350
2592
|
noScope: true,
|
|
2351
2593
|
MemberExpression(path) {
|
|
2352
2594
|
const parent = path.parentPath;
|
|
2353
|
-
if (parent &&
|
|
2354
|
-
if (
|
|
2595
|
+
if (parent && t7.isMemberExpression(parent.node) && parent.node.object === path.node) return;
|
|
2596
|
+
if (t7.isIdentifier(path.node.object) && path.node.object.name === itemVar && t7.isIdentifier(path.node.property)) {
|
|
2355
2597
|
const pathParts = [...arrayPath];
|
|
2356
2598
|
const observeKey2 = buildObserveKey(pathParts, storeVar);
|
|
2357
2599
|
if (!dependencies.has(observeKey2)) {
|
|
@@ -2382,14 +2624,14 @@ function collectConditionalBindings(expr, type, attributeName, conditionalBindin
|
|
|
2382
2624
|
childPath: [...childPath],
|
|
2383
2625
|
selector: generateSelector(elementPath),
|
|
2384
2626
|
attributeName,
|
|
2385
|
-
expression:
|
|
2627
|
+
expression: t7.cloneNode(expr, true),
|
|
2386
2628
|
requiresRerender
|
|
2387
2629
|
});
|
|
2388
2630
|
});
|
|
2389
2631
|
}
|
|
2390
2632
|
function conditionalExpressionRequiresRerender(expr) {
|
|
2391
2633
|
let needsRerender = false;
|
|
2392
|
-
const program12 =
|
|
2634
|
+
const program12 = t7.program([t7.expressionStatement(t7.cloneNode(expr, true))]);
|
|
2393
2635
|
traverse3(program12, {
|
|
2394
2636
|
noScope: true,
|
|
2395
2637
|
JSXElement(path) {
|
|
@@ -2435,7 +2677,7 @@ function buildRelationalClassBinding(expr, elementPath, itemVar, itemIdProperty,
|
|
|
2435
2677
|
return null;
|
|
2436
2678
|
}
|
|
2437
2679
|
function resolveExternalIdentityPredicate(test, itemVar, itemIdProperty, stateRefs) {
|
|
2438
|
-
if (!
|
|
2680
|
+
if (!t7.isBinaryExpression(test)) return null;
|
|
2439
2681
|
if (!["===", "==", "!==", "!="].includes(test.operator)) return null;
|
|
2440
2682
|
const left = resolveSide(test.left, itemVar, itemIdProperty, stateRefs);
|
|
2441
2683
|
const right = resolveSide(test.right, itemVar, itemIdProperty, stateRefs);
|
|
@@ -2450,13 +2692,13 @@ function resolveExternalIdentityPredicate(test, itemVar, itemIdProperty, stateRe
|
|
|
2450
2692
|
};
|
|
2451
2693
|
}
|
|
2452
2694
|
function resolveSide(expr, itemVar, itemIdProperty, stateRefs) {
|
|
2453
|
-
if (itemIdProperty === ITEM_IS_KEY &&
|
|
2695
|
+
if (itemIdProperty === ITEM_IS_KEY && t7.isIdentifier(expr) && expr.name === itemVar) {
|
|
2454
2696
|
return { kind: "item-id" };
|
|
2455
2697
|
}
|
|
2456
2698
|
if (getItemMemberPath2(expr, itemVar) === itemIdProperty) {
|
|
2457
2699
|
return { kind: "item-id" };
|
|
2458
2700
|
}
|
|
2459
|
-
if (!
|
|
2701
|
+
if (!t7.isMemberExpression(expr) && !t7.isIdentifier(expr)) return null;
|
|
2460
2702
|
const resolved = resolvePath(expr, stateRefs);
|
|
2461
2703
|
if (!resolved?.parts) return null;
|
|
2462
2704
|
if (resolved.parts[0] === itemVar) return null;
|
|
@@ -2467,14 +2709,14 @@ function resolveSide(expr, itemVar, itemIdProperty, stateRefs) {
|
|
|
2467
2709
|
};
|
|
2468
2710
|
}
|
|
2469
2711
|
function isEmptyBranch(node) {
|
|
2470
|
-
return
|
|
2712
|
+
return t7.isStringLiteral(node) && node.value.trim() === "" || t7.isTemplateLiteral(node) && node.expressions.length === 0 && node.quasis.every((q) => q.value.raw.trim() === "");
|
|
2471
2713
|
}
|
|
2472
2714
|
function extractClassName(node) {
|
|
2473
|
-
if (
|
|
2715
|
+
if (t7.isStringLiteral(node)) {
|
|
2474
2716
|
const cls = node.value.trim();
|
|
2475
2717
|
return cls ? cls.split(" ")[0] : void 0;
|
|
2476
2718
|
}
|
|
2477
|
-
if (
|
|
2719
|
+
if (t7.isTemplateLiteral(node)) {
|
|
2478
2720
|
const raw = node.quasis[0]?.value.raw.trim();
|
|
2479
2721
|
return raw ? raw.split(" ")[0] : void 0;
|
|
2480
2722
|
}
|
|
@@ -2482,7 +2724,7 @@ function extractClassName(node) {
|
|
|
2482
2724
|
}
|
|
2483
2725
|
|
|
2484
2726
|
// src/transform-attributes.ts
|
|
2485
|
-
import * as
|
|
2727
|
+
import * as t8 from "@babel/types";
|
|
2486
2728
|
import { createRequire as createRequire4 } from "module";
|
|
2487
2729
|
var require5 = createRequire4(import.meta.url);
|
|
2488
2730
|
var traverse4 = require5("@babel/traverse").default;
|
|
@@ -2490,35 +2732,35 @@ function buildComponentPropsExpression(jsxElement, imports, componentInstances,
|
|
|
2490
2732
|
const props = [];
|
|
2491
2733
|
const dependencies = /* @__PURE__ */ new Map();
|
|
2492
2734
|
jsxElement.openingElement.attributes.forEach((attr) => {
|
|
2493
|
-
if (!
|
|
2735
|
+
if (!t8.isJSXAttribute(attr) || !t8.isJSXIdentifier(attr.name) || attr.name.name === "key") return;
|
|
2494
2736
|
const propName = attr.name.name;
|
|
2495
2737
|
let propValue = null;
|
|
2496
|
-
if (attr.value === null) propValue =
|
|
2497
|
-
else if (
|
|
2498
|
-
else if (
|
|
2738
|
+
if (attr.value === null) propValue = t8.booleanLiteral(true);
|
|
2739
|
+
else if (t8.isStringLiteral(attr.value)) propValue = t8.stringLiteral(attr.value.value);
|
|
2740
|
+
else if (t8.isJSXExpressionContainer(attr.value) && !t8.isJSXEmptyExpression(attr.value.expression)) {
|
|
2499
2741
|
const expr = attr.value.expression;
|
|
2500
2742
|
propValue = transformExpression(expr);
|
|
2501
2743
|
if (propValue && (/^on[A-Z]/.test(propName) || /^(click|input|change|submit|focus|blur|keydown|keyup|keypress|mousedown|mouseup|mouseover|mouseout|mouseenter|mouseleave|touchstart|touchend|touchmove|pointerdown|pointerup|pointermove|scroll|resize|drag|dragstart|dragend|dragover|drop|reset)$/.test(
|
|
2502
2744
|
propName
|
|
2503
|
-
)) &&
|
|
2504
|
-
const argsId =
|
|
2505
|
-
propValue =
|
|
2506
|
-
[
|
|
2507
|
-
|
|
2745
|
+
)) && t8.isMemberExpression(propValue)) {
|
|
2746
|
+
const argsId = t8.identifier("args");
|
|
2747
|
+
propValue = t8.arrowFunctionExpression(
|
|
2748
|
+
[t8.restElement(argsId)],
|
|
2749
|
+
t8.callExpression(t8.cloneNode(propValue, true), [t8.spreadElement(argsId)])
|
|
2508
2750
|
);
|
|
2509
2751
|
}
|
|
2510
2752
|
}
|
|
2511
2753
|
if (propValue) {
|
|
2512
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propName) ?
|
|
2513
|
-
props.push(
|
|
2754
|
+
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propName) ? t8.identifier(propName) : t8.stringLiteral(propName);
|
|
2755
|
+
props.push(t8.objectProperty(key, propValue));
|
|
2514
2756
|
}
|
|
2515
2757
|
});
|
|
2516
|
-
const meaningfulChildren = jsxElement.children.filter((c) => !(
|
|
2758
|
+
const meaningfulChildren = jsxElement.children.filter((c) => !(t8.isJSXText(c) && c.value.trim() === ""));
|
|
2517
2759
|
if (meaningfulChildren.length > 0) {
|
|
2518
|
-
const frag =
|
|
2519
|
-
props.push(
|
|
2760
|
+
const frag = t8.jsxFragment(t8.jsxOpeningFragment(), t8.jsxClosingFragment(), meaningfulChildren);
|
|
2761
|
+
props.push(t8.objectProperty(t8.identifier("children"), transformFragment(frag)));
|
|
2520
2762
|
}
|
|
2521
|
-
const expression =
|
|
2763
|
+
const expression = t8.objectExpression(props);
|
|
2522
2764
|
const setupStatements = collectTemplateSetupStatements(expression, templateSetupContext);
|
|
2523
2765
|
collectExpressionDependenciesInto(expression, stateRefs, dependencies, setupStatements);
|
|
2524
2766
|
return { expression, dependencies: Array.from(dependencies.values()), setupStatements };
|
|
@@ -2542,18 +2784,18 @@ function collectExpressionDependenciesInto(expr, stateRefs, dependencies, setupS
|
|
|
2542
2784
|
};
|
|
2543
2785
|
const referencedNames = collectReferencedIdentifiers(expr);
|
|
2544
2786
|
setupStatements.forEach((statement) => {
|
|
2545
|
-
if (!
|
|
2787
|
+
if (!t8.isVariableDeclaration(statement)) return;
|
|
2546
2788
|
statement.declarations.forEach((declaration) => {
|
|
2547
|
-
if (!
|
|
2789
|
+
if (!t8.isObjectPattern(declaration.id) || !declaration.init) return;
|
|
2548
2790
|
const resolved = resolvePath(declaration.init, stateRefs);
|
|
2549
2791
|
if (!resolved?.parts) return;
|
|
2550
2792
|
declaration.id.properties.forEach((property) => {
|
|
2551
|
-
if (!
|
|
2552
|
-
const keyName =
|
|
2793
|
+
if (!t8.isObjectProperty(property)) return;
|
|
2794
|
+
const keyName = t8.isIdentifier(property.key) ? property.key.name : t8.isStringLiteral(property.key) ? property.key.value : null;
|
|
2553
2795
|
if (!keyName) return;
|
|
2554
2796
|
const valueNames = collectPatternIdentifiers(property.value);
|
|
2555
2797
|
if (!valueNames.some((name) => referencedNames.has(name))) return;
|
|
2556
|
-
const isStoreInstanceDestructure = resolved.isImportedState && resolved.parts.length === 0 &&
|
|
2798
|
+
const isStoreInstanceDestructure = resolved.isImportedState && resolved.parts.length === 0 && t8.isIdentifier(declaration.init);
|
|
2557
2799
|
if (isStoreInstanceDestructure) {
|
|
2558
2800
|
const storeRef = stateRefs.get(declaration.init.name);
|
|
2559
2801
|
const getterStatePaths = storeRef?.getterDeps?.get(keyName);
|
|
@@ -2572,18 +2814,18 @@ function collectExpressionDependenciesInto(expr, stateRefs, dependencies, setupS
|
|
|
2572
2814
|
});
|
|
2573
2815
|
});
|
|
2574
2816
|
});
|
|
2575
|
-
const program12 =
|
|
2576
|
-
...setupStatements.map((statement) =>
|
|
2577
|
-
|
|
2817
|
+
const program12 = t8.program([
|
|
2818
|
+
...setupStatements.map((statement) => t8.cloneNode(statement, true)),
|
|
2819
|
+
t8.expressionStatement(t8.cloneNode(expr, true))
|
|
2578
2820
|
]);
|
|
2579
2821
|
traverse4(program12, {
|
|
2580
2822
|
noScope: true,
|
|
2581
2823
|
MemberExpression(path) {
|
|
2582
2824
|
const parent = path.parentPath;
|
|
2583
|
-
if (parent &&
|
|
2825
|
+
if (parent && t8.isMemberExpression(parent.node) && parent.node.object === path.node) return;
|
|
2584
2826
|
const resolved = resolvePath(path.node, stateRefs);
|
|
2585
2827
|
if (!resolved?.parts?.length) return;
|
|
2586
|
-
const isMethodCall = parent &&
|
|
2828
|
+
const isMethodCall = parent && t8.isCallExpression(parent.node) && parent.node.callee === path.node;
|
|
2587
2829
|
if (isMethodCall && resolved.isImportedState && resolved.storeVar) {
|
|
2588
2830
|
const ref = stateRefs?.get(resolved.storeVar);
|
|
2589
2831
|
if (ref && !ref.reactiveFields) {
|
|
@@ -2622,12 +2864,12 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
|
|
|
2622
2864
|
if (!templateSetupContext) return [];
|
|
2623
2865
|
const bindingMap = /* @__PURE__ */ new Map();
|
|
2624
2866
|
const firstParam = templateSetupContext.params[0];
|
|
2625
|
-
const paramBinding = firstParam && !
|
|
2867
|
+
const paramBinding = firstParam && !t8.isRestElement(firstParam) ? getTemplateParamBinding(firstParam) : void 0;
|
|
2626
2868
|
if (paramBinding) {
|
|
2627
|
-
const paramStatement =
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2869
|
+
const paramStatement = t8.variableDeclaration("const", [
|
|
2870
|
+
t8.variableDeclarator(
|
|
2871
|
+
t8.cloneNode(paramBinding, true),
|
|
2872
|
+
t8.memberExpression(t8.thisExpression(), t8.identifier("props"))
|
|
2631
2873
|
)
|
|
2632
2874
|
]);
|
|
2633
2875
|
collectPatternIdentifiers(paramBinding).forEach((name) => {
|
|
@@ -2652,7 +2894,7 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
|
|
|
2652
2894
|
if (binding.index === -1) includedParamNames.add(name);
|
|
2653
2895
|
if (!included.has(binding.index)) {
|
|
2654
2896
|
included.add(binding.index);
|
|
2655
|
-
ordered.push({ index: binding.index, statement:
|
|
2897
|
+
ordered.push({ index: binding.index, statement: t8.cloneNode(binding.statement, true) });
|
|
2656
2898
|
}
|
|
2657
2899
|
};
|
|
2658
2900
|
collectReferencedIdentifiers(expr).forEach(includeName);
|
|
@@ -2670,7 +2912,7 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
|
|
|
2670
2912
|
if (!have.has(bi)) {
|
|
2671
2913
|
extra.push({
|
|
2672
2914
|
index: bi,
|
|
2673
|
-
statement:
|
|
2915
|
+
statement: t8.cloneNode(templateSetupContext.statements[bi], true)
|
|
2674
2916
|
});
|
|
2675
2917
|
}
|
|
2676
2918
|
}
|
|
@@ -2681,13 +2923,13 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
|
|
|
2681
2923
|
}
|
|
2682
2924
|
for (const entry of ordered) {
|
|
2683
2925
|
if (entry.index !== -1) continue;
|
|
2684
|
-
if (!
|
|
2926
|
+
if (!t8.isVariableDeclaration(entry.statement)) continue;
|
|
2685
2927
|
const decl = entry.statement.declarations[0];
|
|
2686
|
-
if (!
|
|
2928
|
+
if (!t8.isObjectPattern(decl.id)) continue;
|
|
2687
2929
|
decl.id.properties = decl.id.properties.filter((prop) => {
|
|
2688
|
-
if (
|
|
2689
|
-
if (
|
|
2690
|
-
const keyName =
|
|
2930
|
+
if (t8.isRestElement(prop)) return true;
|
|
2931
|
+
if (t8.isObjectProperty(prop)) {
|
|
2932
|
+
const keyName = t8.isIdentifier(prop.key) ? prop.key.name : t8.isStringLiteral(prop.key) ? prop.key.value : null;
|
|
2691
2933
|
return keyName ? includedParamNames.has(keyName) : true;
|
|
2692
2934
|
}
|
|
2693
2935
|
return true;
|
|
@@ -2696,36 +2938,36 @@ function collectTemplateSetupStatements(expr, templateSetupContext) {
|
|
|
2696
2938
|
return ordered.map((entry) => entry.statement);
|
|
2697
2939
|
}
|
|
2698
2940
|
function collectStatementBindingNames(statement) {
|
|
2699
|
-
if (
|
|
2941
|
+
if (t8.isVariableDeclaration(statement)) {
|
|
2700
2942
|
return statement.declarations.flatMap((declaration) => collectPatternIdentifiers(declaration.id));
|
|
2701
2943
|
}
|
|
2702
|
-
if (
|
|
2944
|
+
if (t8.isFunctionDeclaration(statement) && statement.id) {
|
|
2703
2945
|
return [statement.id.name];
|
|
2704
2946
|
}
|
|
2705
|
-
if (
|
|
2947
|
+
if (t8.isClassDeclaration(statement) && statement.id) {
|
|
2706
2948
|
return [statement.id.name];
|
|
2707
2949
|
}
|
|
2708
2950
|
return [];
|
|
2709
2951
|
}
|
|
2710
2952
|
function collectPatternIdentifiers(pattern) {
|
|
2711
|
-
if (
|
|
2712
|
-
if (
|
|
2713
|
-
if (
|
|
2714
|
-
if (
|
|
2953
|
+
if (t8.isIdentifier(pattern)) return [pattern.name];
|
|
2954
|
+
if (t8.isRestElement(pattern)) return collectPatternIdentifiers(pattern.argument);
|
|
2955
|
+
if (t8.isAssignmentPattern(pattern)) return collectPatternIdentifiers(pattern.left);
|
|
2956
|
+
if (t8.isObjectPattern(pattern)) {
|
|
2715
2957
|
return pattern.properties.flatMap((property) => {
|
|
2716
|
-
if (
|
|
2958
|
+
if (t8.isRestElement(property)) return collectPatternIdentifiers(property.argument);
|
|
2717
2959
|
return collectPatternIdentifiers(property.value);
|
|
2718
2960
|
});
|
|
2719
2961
|
}
|
|
2720
|
-
if (
|
|
2962
|
+
if (t8.isArrayPattern(pattern)) {
|
|
2721
2963
|
return pattern.elements.flatMap((element) => element ? collectPatternIdentifiers(element) : []);
|
|
2722
2964
|
}
|
|
2723
2965
|
return [];
|
|
2724
2966
|
}
|
|
2725
2967
|
function collectReferencedIdentifiers(node) {
|
|
2726
2968
|
const names = /* @__PURE__ */ new Set();
|
|
2727
|
-
const program12 =
|
|
2728
|
-
|
|
2969
|
+
const program12 = t8.program([
|
|
2970
|
+
t8.isStatement(node) ? t8.cloneNode(node, true) : t8.expressionStatement(t8.cloneNode(node, true))
|
|
2729
2971
|
]);
|
|
2730
2972
|
traverse4(program12, {
|
|
2731
2973
|
noScope: true,
|
|
@@ -2748,18 +2990,18 @@ function buildTextTemplateExpressionFromParts(textTemplate, textExpressions) {
|
|
|
2748
2990
|
for (let i = 0; i < templateParts.length; i++) {
|
|
2749
2991
|
if (i % 2 === 0) {
|
|
2750
2992
|
const raw = templateParts[i] || "";
|
|
2751
|
-
quasis.push(
|
|
2993
|
+
quasis.push(t9.templateElement({ raw, cooked: raw }, i === templateParts.length - 1));
|
|
2752
2994
|
continue;
|
|
2753
2995
|
}
|
|
2754
2996
|
const idx = Number.parseInt(templateParts[i] || "-1", 10);
|
|
2755
2997
|
const textExpr = textExpressions[idx];
|
|
2756
2998
|
if (textExpr?.expression) {
|
|
2757
|
-
expressions.push(
|
|
2999
|
+
expressions.push(t9.cloneNode(textExpr.expression, true));
|
|
2758
3000
|
} else {
|
|
2759
|
-
expressions.push(
|
|
3001
|
+
expressions.push(t9.identifier("undefined"));
|
|
2760
3002
|
}
|
|
2761
3003
|
}
|
|
2762
|
-
return
|
|
3004
|
+
return t9.templateLiteral(quasis, expressions);
|
|
2763
3005
|
}
|
|
2764
3006
|
function assignBindingIds(bindings, propBindings, unresolvedMaps, arrayMaps) {
|
|
2765
3007
|
const pathToId = /* @__PURE__ */ new Map();
|
|
@@ -2809,16 +3051,16 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
2809
3051
|
const destructuredPropNames = /* @__PURE__ */ new Set();
|
|
2810
3052
|
const binding = getTemplateParamBinding(templateMethod.params[0]);
|
|
2811
3053
|
if (binding) {
|
|
2812
|
-
if (
|
|
3054
|
+
if (t9.isIdentifier(binding)) propsParamName = binding.name;
|
|
2813
3055
|
else {
|
|
2814
3056
|
propsParamName = "props";
|
|
2815
3057
|
for (const prop of binding.properties) {
|
|
2816
|
-
if (
|
|
3058
|
+
if (t9.isObjectProperty(prop) && t9.isIdentifier(prop.key) && !prop.computed)
|
|
2817
3059
|
destructuredPropNames.add(prop.key.name);
|
|
2818
3060
|
}
|
|
2819
3061
|
}
|
|
2820
3062
|
}
|
|
2821
|
-
if (!templateMethod.body || !
|
|
3063
|
+
if (!templateMethod.body || !t9.isBlockStatement(templateMethod.body))
|
|
2822
3064
|
return {
|
|
2823
3065
|
bindings,
|
|
2824
3066
|
propBindings,
|
|
@@ -2835,7 +3077,7 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
2835
3077
|
conditionalSlotNodeMap: /* @__PURE__ */ new Map()
|
|
2836
3078
|
};
|
|
2837
3079
|
const bodyStmts = templateMethod.body.body;
|
|
2838
|
-
const returnStmt = bodyStmts.find((s) =>
|
|
3080
|
+
const returnStmt = bodyStmts.find((s) => t9.isReturnStatement(s) && s.argument !== null);
|
|
2839
3081
|
if (!returnStmt?.argument)
|
|
2840
3082
|
return {
|
|
2841
3083
|
bindings,
|
|
@@ -2856,49 +3098,49 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
2856
3098
|
let earlyReturnGuard;
|
|
2857
3099
|
let earlyReturnBarrierIndex;
|
|
2858
3100
|
const earlyReturnFromIf = (s) => {
|
|
2859
|
-
if (
|
|
2860
|
-
if (
|
|
3101
|
+
if (t9.isReturnStatement(s.consequent) && s.consequent.argument) return s.consequent;
|
|
3102
|
+
if (t9.isBlockStatement(s.consequent) && s.consequent.body.length === 1 && t9.isReturnStatement(s.consequent.body[0]) && s.consequent.body[0].argument) {
|
|
2861
3103
|
return s.consequent.body[0];
|
|
2862
3104
|
}
|
|
2863
3105
|
return null;
|
|
2864
3106
|
};
|
|
2865
3107
|
for (let i = 0; i < returnIndex; i++) {
|
|
2866
3108
|
const s = bodyStmts[i];
|
|
2867
|
-
if (!
|
|
3109
|
+
if (!t9.isIfStatement(s) || s.alternate) continue;
|
|
2868
3110
|
const earlyRet = earlyReturnFromIf(s);
|
|
2869
3111
|
if (!earlyRet?.argument) continue;
|
|
2870
|
-
earlyReturnGuard =
|
|
3112
|
+
earlyReturnGuard = t9.cloneNode(s.test, true);
|
|
2871
3113
|
earlyReturnBarrierIndex = i;
|
|
2872
3114
|
break;
|
|
2873
3115
|
}
|
|
2874
3116
|
const templateSetupContext = {
|
|
2875
3117
|
params: templateMethod.params.filter(
|
|
2876
|
-
(param) => !
|
|
3118
|
+
(param) => !t9.isTSParameterProperty(param)
|
|
2877
3119
|
),
|
|
2878
3120
|
statements: returnIndex >= 0 ? templateMethod.body.body.slice(0, returnIndex) : []
|
|
2879
3121
|
};
|
|
2880
|
-
const templateRoot =
|
|
3122
|
+
const templateRoot = t9.isJSXElement(returnStmt.argument) ? returnStmt.argument : null;
|
|
2881
3123
|
const conditionalSlotNodeMap = /* @__PURE__ */ new Map();
|
|
2882
3124
|
const elementPathToUserIdExpr = /* @__PURE__ */ new Map();
|
|
2883
3125
|
const walk = (node, elementPath = []) => {
|
|
2884
|
-
if (
|
|
3126
|
+
if (t9.isJSXFragment(node)) {
|
|
2885
3127
|
getDirectChildElements(node.children).forEach((child) => {
|
|
2886
3128
|
walk(child.node, [...elementPath, child.selectorSegment]);
|
|
2887
3129
|
});
|
|
2888
3130
|
return;
|
|
2889
3131
|
}
|
|
2890
|
-
const tagName =
|
|
3132
|
+
const tagName = t9.isJSXIdentifier(node.openingElement.name) ? node.openingElement.name.name : "div";
|
|
2891
3133
|
const isComponentTag2 = /^[A-Z]/.test(tagName);
|
|
2892
3134
|
if (!isComponentTag2) {
|
|
2893
3135
|
const idAttr = node.openingElement.attributes.find(
|
|
2894
|
-
(a) =>
|
|
3136
|
+
(a) => t9.isJSXAttribute(a) && t9.isJSXIdentifier(a.name) && a.name.name === "id"
|
|
2895
3137
|
);
|
|
2896
3138
|
if (idAttr) {
|
|
2897
3139
|
const pathKey = elementPath.join(" > ");
|
|
2898
|
-
if (
|
|
2899
|
-
elementPathToUserIdExpr.set(pathKey,
|
|
2900
|
-
} else if (
|
|
2901
|
-
elementPathToUserIdExpr.set(pathKey,
|
|
3140
|
+
if (t9.isStringLiteral(idAttr.value)) {
|
|
3141
|
+
elementPathToUserIdExpr.set(pathKey, t9.stringLiteral(idAttr.value.value));
|
|
3142
|
+
} else if (t9.isJSXExpressionContainer(idAttr.value) && idAttr.value.expression && !t9.isJSXEmptyExpression(idAttr.value.expression)) {
|
|
3143
|
+
elementPathToUserIdExpr.set(pathKey, t9.cloneNode(idAttr.value.expression, true));
|
|
2902
3144
|
}
|
|
2903
3145
|
}
|
|
2904
3146
|
analyzeAttributes(
|
|
@@ -2941,8 +3183,8 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
2941
3183
|
conditionalSlotNodeMap
|
|
2942
3184
|
);
|
|
2943
3185
|
};
|
|
2944
|
-
if (
|
|
2945
|
-
else if (
|
|
3186
|
+
if (t9.isJSXElement(returnStmt.argument)) walk(returnStmt.argument);
|
|
3187
|
+
else if (t9.isJSXFragment(returnStmt.argument)) walk(returnStmt.argument);
|
|
2946
3188
|
collectAllStateAccesses(templateMethod, stateRefs, stateProps, templateSetupContext, returnStmt.argument);
|
|
2947
3189
|
assignBindingIds(bindings, propBindings, unresolvedMaps, arrayMaps);
|
|
2948
3190
|
const elementPathToBindingId = /* @__PURE__ */ new Map();
|
|
@@ -2973,44 +3215,44 @@ function analyzeTemplate(templateMethod, stateRefs, classBody2) {
|
|
|
2973
3215
|
for (const b of bindings) {
|
|
2974
3216
|
const pathKey = b.elementPath.join(" > ");
|
|
2975
3217
|
const userExpr = elementPathToUserIdExpr.get(pathKey);
|
|
2976
|
-
if (userExpr) b.userIdExpr =
|
|
3218
|
+
if (userExpr) b.userIdExpr = t9.cloneNode(userExpr, true);
|
|
2977
3219
|
}
|
|
2978
3220
|
for (const pb of propBindings) {
|
|
2979
3221
|
if (!pb.elementPath?.length) continue;
|
|
2980
3222
|
const pathKey = pb.elementPath.join(" > ");
|
|
2981
3223
|
const userExpr = elementPathToUserIdExpr.get(pathKey);
|
|
2982
|
-
if (userExpr) pb.userIdExpr =
|
|
3224
|
+
if (userExpr) pb.userIdExpr = t9.cloneNode(userExpr, true);
|
|
2983
3225
|
}
|
|
2984
3226
|
for (const um of unresolvedMaps) {
|
|
2985
3227
|
if (um.containerElementPath?.length) {
|
|
2986
3228
|
const pathKey = um.containerElementPath.join(" > ");
|
|
2987
3229
|
const userExpr = elementPathToUserIdExpr.get(pathKey);
|
|
2988
|
-
if (userExpr) um.containerUserIdExpr =
|
|
3230
|
+
if (userExpr) um.containerUserIdExpr = t9.cloneNode(userExpr, true);
|
|
2989
3231
|
}
|
|
2990
3232
|
}
|
|
2991
3233
|
for (const am of arrayMaps) {
|
|
2992
3234
|
if (am.containerElementPath?.length) {
|
|
2993
3235
|
const pathKey = am.containerElementPath.join(" > ");
|
|
2994
3236
|
const userExpr = elementPathToUserIdExpr.get(pathKey);
|
|
2995
|
-
if (userExpr) am.containerUserIdExpr =
|
|
3237
|
+
if (userExpr) am.containerUserIdExpr = t9.cloneNode(userExpr, true);
|
|
2996
3238
|
}
|
|
2997
3239
|
}
|
|
2998
3240
|
for (const um of unresolvedMaps) {
|
|
2999
3241
|
if (!um.computationExpr) continue;
|
|
3000
|
-
if (
|
|
3242
|
+
if (t9.isIdentifier(um.computationExpr)) {
|
|
3001
3243
|
const varName = um.computationExpr.name;
|
|
3002
|
-
um.mapObjectExpr =
|
|
3244
|
+
um.mapObjectExpr = t9.identifier(varName);
|
|
3003
3245
|
for (const stmt of templateMethod.body.body) {
|
|
3004
|
-
if (!
|
|
3246
|
+
if (!t9.isVariableDeclaration(stmt)) continue;
|
|
3005
3247
|
for (const decl of stmt.declarations) {
|
|
3006
|
-
if (
|
|
3007
|
-
um.computationExpr =
|
|
3248
|
+
if (t9.isIdentifier(decl.id) && decl.id.name === varName && decl.init) {
|
|
3249
|
+
um.computationExpr = t9.cloneNode(decl.init, true);
|
|
3008
3250
|
break;
|
|
3009
3251
|
}
|
|
3010
3252
|
}
|
|
3011
3253
|
}
|
|
3012
3254
|
} else {
|
|
3013
|
-
um.mapObjectExpr =
|
|
3255
|
+
um.mapObjectExpr = t9.cloneNode(um.computationExpr, true);
|
|
3014
3256
|
}
|
|
3015
3257
|
const derived = buildDerivedUnresolvedMapDescriptor(um.computationExpr, stateRefs, classBody2);
|
|
3016
3258
|
if (derived) {
|
|
@@ -3077,9 +3319,9 @@ function computeConditionalSlotScopedStoreKeys(conditionalSlots, stateProps, sta
|
|
|
3077
3319
|
for (const dep of condDeps) conditionKeys.add(dep.observeKey);
|
|
3078
3320
|
if (!slot.originalExpr) continue;
|
|
3079
3321
|
const branches = [];
|
|
3080
|
-
if (
|
|
3322
|
+
if (t9.isConditionalExpression(slot.originalExpr)) {
|
|
3081
3323
|
branches.push(slot.originalExpr.consequent, slot.originalExpr.alternate);
|
|
3082
|
-
} else if (
|
|
3324
|
+
} else if (t9.isLogicalExpression(slot.originalExpr)) {
|
|
3083
3325
|
branches.push(slot.originalExpr.right);
|
|
3084
3326
|
}
|
|
3085
3327
|
for (const branch of branches) {
|
|
@@ -3097,29 +3339,29 @@ function computeConditionalSlotScopedStoreKeys(conditionalSlots, stateProps, sta
|
|
|
3097
3339
|
return result;
|
|
3098
3340
|
}
|
|
3099
3341
|
function resolveHelperCallExpression(expr, classBody2) {
|
|
3100
|
-
if (!expr || !
|
|
3342
|
+
if (!expr || !t9.isCallExpression(expr) || !t9.isMemberExpression(expr.callee) || !t9.isThisExpression(expr.callee.object) || !t9.isIdentifier(expr.callee.property)) {
|
|
3101
3343
|
return expr;
|
|
3102
3344
|
}
|
|
3103
3345
|
const helperName = expr.callee.property.name;
|
|
3104
3346
|
if (!classBody2) return expr;
|
|
3105
3347
|
const helperMethod = classBody2.body.find(
|
|
3106
|
-
(node) =>
|
|
3348
|
+
(node) => t9.isClassMethod(node) && t9.isIdentifier(node.key) && node.key.name === helperName
|
|
3107
3349
|
);
|
|
3108
|
-
if (!helperMethod || !
|
|
3109
|
-
const returnStmt = helperMethod.body.body.find((stmt) =>
|
|
3110
|
-
return returnStmt?.argument ?
|
|
3350
|
+
if (!helperMethod || !t9.isBlockStatement(helperMethod.body)) return expr;
|
|
3351
|
+
const returnStmt = helperMethod.body.body.find((stmt) => t9.isReturnStatement(stmt) && !!stmt.argument);
|
|
3352
|
+
return returnStmt?.argument ? t9.cloneNode(returnStmt.argument, true) : expr;
|
|
3111
3353
|
}
|
|
3112
3354
|
function collectHelperMethodDependencies(expr, classBody2, stateRefs) {
|
|
3113
|
-
if (!expr || !
|
|
3355
|
+
if (!expr || !t9.isCallExpression(expr) || !t9.isMemberExpression(expr.callee) || !t9.isThisExpression(expr.callee.object) || !t9.isIdentifier(expr.callee.property) || !classBody2) {
|
|
3114
3356
|
return [];
|
|
3115
3357
|
}
|
|
3116
3358
|
const helperMethodName = expr.callee.property.name;
|
|
3117
3359
|
const helperMethod = classBody2.body.find(
|
|
3118
|
-
(node) =>
|
|
3360
|
+
(node) => t9.isClassMethod(node) && t9.isIdentifier(node.key) && node.key.name === helperMethodName
|
|
3119
3361
|
);
|
|
3120
|
-
if (!helperMethod || !
|
|
3362
|
+
if (!helperMethod || !t9.isBlockStatement(helperMethod.body)) return [];
|
|
3121
3363
|
const deps = /* @__PURE__ */ new Map();
|
|
3122
|
-
const program12 =
|
|
3364
|
+
const program12 = t9.program(helperMethod.body.body.map((stmt) => t9.cloneNode(stmt, true)));
|
|
3123
3365
|
traverse5(program12, {
|
|
3124
3366
|
noScope: true,
|
|
3125
3367
|
MemberExpression(path) {
|
|
@@ -3150,26 +3392,26 @@ function buildDerivedUnresolvedMapDescriptor(expr, stateRefs, classBody2) {
|
|
|
3150
3392
|
const normalized = resolveHelperCallExpression(expr, classBody2);
|
|
3151
3393
|
const stages = [];
|
|
3152
3394
|
const walk = (node) => {
|
|
3153
|
-
if (
|
|
3395
|
+
if (t9.isCallExpression(node) && t9.isMemberExpression(node.callee) && t9.isIdentifier(node.callee.property) && !node.callee.computed) {
|
|
3154
3396
|
const method = node.callee.property.name;
|
|
3155
3397
|
if (method === "filter" || method === "slice" || method === "sort" || method === "reverse") {
|
|
3156
3398
|
const source2 = walk(node.callee.object);
|
|
3157
3399
|
if (!source2) return null;
|
|
3158
3400
|
const stage = { method };
|
|
3159
|
-
if (method === "filter" &&
|
|
3401
|
+
if (method === "filter" && t9.isArrowFunctionExpression(node.arguments[0])) {
|
|
3160
3402
|
const filterFn = node.arguments[0];
|
|
3161
|
-
stage.itemVariable =
|
|
3162
|
-
stage.indexVariable =
|
|
3403
|
+
stage.itemVariable = t9.isIdentifier(filterFn.params[0]) ? filterFn.params[0].name : "item";
|
|
3404
|
+
stage.indexVariable = t9.isIdentifier(filterFn.params[1]) ? filterFn.params[1].name : void 0;
|
|
3163
3405
|
const callbackBodyStatements = extractCallbackBodyStatements(filterFn);
|
|
3164
3406
|
if (callbackBodyStatements.length > 0) stage.callbackBodyStatements = callbackBodyStatements;
|
|
3165
|
-
if (
|
|
3166
|
-
stage.predicateExpr =
|
|
3167
|
-
} else if (
|
|
3407
|
+
if (t9.isExpression(filterFn.body)) {
|
|
3408
|
+
stage.predicateExpr = t9.cloneNode(filterFn.body, true);
|
|
3409
|
+
} else if (t9.isBlockStatement(filterFn.body)) {
|
|
3168
3410
|
const returnStmt = filterFn.body.body.find(
|
|
3169
|
-
(stmt) =>
|
|
3411
|
+
(stmt) => t9.isReturnStatement(stmt) && !!stmt.argument
|
|
3170
3412
|
);
|
|
3171
3413
|
if (returnStmt?.argument) {
|
|
3172
|
-
stage.predicateExpr =
|
|
3414
|
+
stage.predicateExpr = t9.cloneNode(returnStmt.argument, true);
|
|
3173
3415
|
}
|
|
3174
3416
|
}
|
|
3175
3417
|
}
|
|
@@ -3177,8 +3419,8 @@ function buildDerivedUnresolvedMapDescriptor(expr, stateRefs, classBody2) {
|
|
|
3177
3419
|
return source2;
|
|
3178
3420
|
}
|
|
3179
3421
|
}
|
|
3180
|
-
if (!
|
|
3181
|
-
if (!
|
|
3422
|
+
if (!t9.isExpression(node)) return null;
|
|
3423
|
+
if (!t9.isMemberExpression(node) && !t9.isIdentifier(node) && !t9.isThisExpression(node) && !t9.isCallExpression(node)) {
|
|
3182
3424
|
return null;
|
|
3183
3425
|
}
|
|
3184
3426
|
const resolved = resolvePath(node, stateRefs);
|
|
@@ -3197,41 +3439,41 @@ function buildDerivedUnresolvedMapDescriptor(expr, stateRefs, classBody2) {
|
|
|
3197
3439
|
};
|
|
3198
3440
|
}
|
|
3199
3441
|
function getHelperMethodObserveKey(expr) {
|
|
3200
|
-
if (!expr || !
|
|
3442
|
+
if (!expr || !t9.isCallExpression(expr) || !t9.isMemberExpression(expr.callee) || !t9.isThisExpression(expr.callee.object) || !t9.isIdentifier(expr.callee.property)) {
|
|
3201
3443
|
return void 0;
|
|
3202
3444
|
}
|
|
3203
3445
|
return buildObserveKey([expr.callee.property.name]);
|
|
3204
3446
|
}
|
|
3205
3447
|
function analyzeAttributes(node, tagName, elementPath, bindings, propBindings, stateProps, stateRefs, propsParamName, destructuredPropNames, templateSetupContext, classBody2) {
|
|
3206
3448
|
node.openingElement.attributes.forEach((attr) => {
|
|
3207
|
-
if (!
|
|
3208
|
-
if (!attr.value || !
|
|
3449
|
+
if (!t9.isJSXAttribute(attr) || !t9.isJSXIdentifier(attr.name)) return;
|
|
3450
|
+
if (!attr.value || !t9.isJSXExpressionContainer(attr.value)) return;
|
|
3209
3451
|
const name = attr.name.name;
|
|
3210
|
-
if (
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
].includes(name))
|
|
3452
|
+
if (name === "ref") return;
|
|
3453
|
+
if (EVENT_NAMES.has(name) || EVENT_NAMES.has(toGeaEventType(name))) return;
|
|
3454
|
+
if (name === "dangerouslySetInnerHTML") {
|
|
3455
|
+
const expr2 = attr.value.expression;
|
|
3456
|
+
if (templateSetupContext && !t9.isJSXEmptyExpression(expr2)) {
|
|
3457
|
+
const setupStatements = collectTemplateSetupStatements(expr2, templateSetupContext);
|
|
3458
|
+
const dependencies = collectExpressionDependencies(expr2, stateRefs, setupStatements);
|
|
3459
|
+
const stateDeps = dependencies.filter(
|
|
3460
|
+
(d) => d.storeVar || d.pathParts.length > 0 && d.pathParts[0] !== "props"
|
|
3461
|
+
);
|
|
3462
|
+
if (stateDeps.length > 0) {
|
|
3463
|
+
const selector = generateSelector(elementPath);
|
|
3464
|
+
propBindings.push({
|
|
3465
|
+
propName: "__state__",
|
|
3466
|
+
selector,
|
|
3467
|
+
type: "attribute",
|
|
3468
|
+
attributeName: "dangerouslySetInnerHTML",
|
|
3469
|
+
elementPath: [...elementPath],
|
|
3470
|
+
expression: t9.cloneNode(expr2, true),
|
|
3471
|
+
setupStatements: setupStatements.length > 0 ? setupStatements : void 0
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3234
3475
|
return;
|
|
3476
|
+
}
|
|
3235
3477
|
const expr = attr.value.expression;
|
|
3236
3478
|
const propName = resolvePropRef(expr, propsParamName, destructuredPropNames);
|
|
3237
3479
|
if (propName) {
|
|
@@ -3266,8 +3508,8 @@ function analyzeAttributes(node, tagName, elementPath, bindings, propBindings, s
|
|
|
3266
3508
|
propBindings.push(...derived);
|
|
3267
3509
|
}
|
|
3268
3510
|
const tagNameNode = node.openingElement.name;
|
|
3269
|
-
const isNativeElement =
|
|
3270
|
-
if (isNativeElement && templateSetupContext && !
|
|
3511
|
+
const isNativeElement = t9.isJSXIdentifier(tagNameNode) && /^[a-z]/.test(tagNameNode.name);
|
|
3512
|
+
if (isNativeElement && templateSetupContext && !t9.isJSXEmptyExpression(expr)) {
|
|
3271
3513
|
const setupStatements = collectTemplateSetupStatements(expr, templateSetupContext);
|
|
3272
3514
|
const dependencies = collectExpressionDependencies(expr, stateRefs, setupStatements);
|
|
3273
3515
|
const stateDeps = dependencies.filter((d) => d.storeVar || d.pathParts.length > 0 && d.pathParts[0] !== "props");
|
|
@@ -3279,8 +3521,8 @@ function analyzeAttributes(node, tagName, elementPath, bindings, propBindings, s
|
|
|
3279
3521
|
type: attrType,
|
|
3280
3522
|
attributeName: attrType === "class" ? void 0 : name,
|
|
3281
3523
|
elementPath: [...elementPath],
|
|
3282
|
-
expression:
|
|
3283
|
-
setupStatements: setupStatements.map((s) =>
|
|
3524
|
+
expression: t9.cloneNode(expr, true),
|
|
3525
|
+
setupStatements: setupStatements.map((s) => t9.cloneNode(s, true)),
|
|
3284
3526
|
stateOnly: true
|
|
3285
3527
|
});
|
|
3286
3528
|
return;
|
|
@@ -3306,13 +3548,13 @@ function collectTextChildren(node, stateRefs, stateProps) {
|
|
|
3306
3548
|
const textChildren = [];
|
|
3307
3549
|
let hasExpr = false;
|
|
3308
3550
|
node.children.forEach((child) => {
|
|
3309
|
-
if (
|
|
3551
|
+
if (t9.isJSXText(child)) {
|
|
3310
3552
|
textChildren.push({ type: "text", value: child.value });
|
|
3311
|
-
} else if (
|
|
3553
|
+
} else if (t9.isJSXExpressionContainer(child) && !t9.isJSXEmptyExpression(child.expression)) {
|
|
3312
3554
|
const expr = child.expression;
|
|
3313
|
-
const isMap =
|
|
3555
|
+
const isMap = t9.isCallExpression(expr) && t9.isMemberExpression(expr.callee) && t9.isIdentifier(expr.callee.property) && expr.callee.property.name === "map";
|
|
3314
3556
|
if (!isMap) {
|
|
3315
|
-
if (
|
|
3557
|
+
if (t9.isTemplateLiteral(expr)) {
|
|
3316
3558
|
for (let i = 0; i < expr.quasis.length; i++) {
|
|
3317
3559
|
const quasi = expr.quasis[i];
|
|
3318
3560
|
if (quasi.value.raw) {
|
|
@@ -3320,7 +3562,7 @@ function collectTextChildren(node, stateRefs, stateProps) {
|
|
|
3320
3562
|
}
|
|
3321
3563
|
if (i < expr.expressions.length) {
|
|
3322
3564
|
const innerExpr = expr.expressions[i];
|
|
3323
|
-
if (
|
|
3565
|
+
if (t9.isExpression(innerExpr)) {
|
|
3324
3566
|
textChildren.push({ type: "expression", expression: innerExpr });
|
|
3325
3567
|
hasExpr = true;
|
|
3326
3568
|
}
|
|
@@ -3365,26 +3607,26 @@ function collectTextChildren(node, stateRefs, stateProps) {
|
|
|
3365
3607
|
return { textTemplate, textExpressions, shouldBuildTextTemplate };
|
|
3366
3608
|
}
|
|
3367
3609
|
function parentHasElementChildren(node) {
|
|
3368
|
-
return node.children.some((c) =>
|
|
3610
|
+
return node.children.some((c) => t9.isJSXElement(c));
|
|
3369
3611
|
}
|
|
3370
3612
|
function getDOMTextNodeIndex(children, childIndex) {
|
|
3371
3613
|
let domIndex = 0;
|
|
3372
3614
|
let inTextRun = false;
|
|
3373
3615
|
for (let i = 0; i < children.length; i++) {
|
|
3374
3616
|
const child = children[i];
|
|
3375
|
-
if (
|
|
3617
|
+
if (t9.isJSXText(child)) {
|
|
3376
3618
|
if (child.value.trim() === "") continue;
|
|
3377
3619
|
if (!inTextRun) {
|
|
3378
3620
|
inTextRun = true;
|
|
3379
3621
|
domIndex++;
|
|
3380
3622
|
}
|
|
3381
|
-
} else if (
|
|
3623
|
+
} else if (t9.isJSXExpressionContainer(child)) {
|
|
3382
3624
|
if (!inTextRun) {
|
|
3383
3625
|
inTextRun = true;
|
|
3384
3626
|
domIndex++;
|
|
3385
3627
|
}
|
|
3386
3628
|
if (i === childIndex) return domIndex - 1;
|
|
3387
|
-
} else if (
|
|
3629
|
+
} else if (t9.isJSXElement(child) || t9.isJSXFragment(child)) {
|
|
3388
3630
|
inTextRun = false;
|
|
3389
3631
|
domIndex++;
|
|
3390
3632
|
}
|
|
@@ -3396,7 +3638,7 @@ function analyzeChildren(node, tagName, elementPath, bindings, propBindings, arr
|
|
|
3396
3638
|
walk(child.node, [...elementPath, child.selectorSegment]);
|
|
3397
3639
|
});
|
|
3398
3640
|
node.children.forEach((child, index) => {
|
|
3399
|
-
if (
|
|
3641
|
+
if (t9.isJSXExpressionContainer(child) && !t9.isJSXEmptyExpression(child.expression)) {
|
|
3400
3642
|
const expr = child.expression;
|
|
3401
3643
|
if (isMapCall(expr)) {
|
|
3402
3644
|
handleArrayMap(
|
|
@@ -3475,12 +3717,12 @@ function analyzeChildren(node, tagName, elementPath, bindings, propBindings, arr
|
|
|
3475
3717
|
});
|
|
3476
3718
|
}
|
|
3477
3719
|
function isMapCall(expr) {
|
|
3478
|
-
return
|
|
3720
|
+
return t9.isCallExpression(expr) && t9.isMemberExpression(expr.callee) && t9.isIdentifier(expr.callee.property) && expr.callee.property.name === "map";
|
|
3479
3721
|
}
|
|
3480
3722
|
function collectNestedMapCalls(expr) {
|
|
3481
|
-
if (
|
|
3723
|
+
if (t9.isJSXEmptyExpression(expr)) return [];
|
|
3482
3724
|
const maps = [];
|
|
3483
|
-
const program12 =
|
|
3725
|
+
const program12 = t9.program([t9.expressionStatement(t9.cloneNode(expr, true))]);
|
|
3484
3726
|
traverse5(program12, {
|
|
3485
3727
|
noScope: true,
|
|
3486
3728
|
CallExpression(path) {
|
|
@@ -3522,19 +3764,19 @@ function collectNestedMapCalls(expr) {
|
|
|
3522
3764
|
return maps;
|
|
3523
3765
|
}
|
|
3524
3766
|
function collectImportedStoreGetterDependencies(expr, setupStatements, stateRefs) {
|
|
3525
|
-
if (!
|
|
3767
|
+
if (!t9.isIdentifier(expr)) return [];
|
|
3526
3768
|
const deps = /* @__PURE__ */ new Map();
|
|
3527
3769
|
for (const stmt of setupStatements) {
|
|
3528
|
-
if (!
|
|
3770
|
+
if (!t9.isVariableDeclaration(stmt)) continue;
|
|
3529
3771
|
for (const decl of stmt.declarations) {
|
|
3530
|
-
if (!
|
|
3772
|
+
if (!t9.isObjectPattern(decl.id) || !t9.isIdentifier(decl.init)) continue;
|
|
3531
3773
|
const storeRef = stateRefs.get(decl.init.name);
|
|
3532
3774
|
if (!storeRef || storeRef.kind !== "imported") continue;
|
|
3533
3775
|
for (const prop of decl.id.properties) {
|
|
3534
|
-
if (!
|
|
3535
|
-
const localName =
|
|
3776
|
+
if (!t9.isObjectProperty(prop)) continue;
|
|
3777
|
+
const localName = t9.isIdentifier(prop.value) ? prop.value.name : t9.isIdentifier(prop.key) ? prop.key.name : null;
|
|
3536
3778
|
if (localName !== expr.name) continue;
|
|
3537
|
-
const getterName =
|
|
3779
|
+
const getterName = t9.isIdentifier(prop.key) ? prop.key.name : null;
|
|
3538
3780
|
const getterStatePaths = getterName ? storeRef.getterDeps?.get(getterName) : void 0;
|
|
3539
3781
|
if (getterStatePaths && getterStatePaths.length > 0) {
|
|
3540
3782
|
for (const pathParts of getterStatePaths) {
|
|
@@ -3553,7 +3795,7 @@ function collectImportedStoreGetterDependencies(expr, setupStatements, stateRefs
|
|
|
3553
3795
|
function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stateProps, stateRefs, onUnresolvedMap, classBody2, templateSetupContext) {
|
|
3554
3796
|
const arrayExpr = expr.callee.object;
|
|
3555
3797
|
const normalizedArrayExpr = resolveHelperCallExpression(arrayExpr, classBody2) || arrayExpr;
|
|
3556
|
-
if (
|
|
3798
|
+
if (t9.isArrowFunctionExpression(expr.arguments?.[0])) {
|
|
3557
3799
|
const tpl = extractItemTemplate(expr.arguments[0]);
|
|
3558
3800
|
if (tpl && !hasExplicitItemKey(tpl)) {
|
|
3559
3801
|
const loc = tpl.loc?.start;
|
|
@@ -3566,18 +3808,18 @@ function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stat
|
|
|
3566
3808
|
}
|
|
3567
3809
|
}
|
|
3568
3810
|
const result = resolvePath(normalizedArrayExpr, stateRefs);
|
|
3569
|
-
const isDestructuredNonReactive = result?.parts?.length === 1 && result.isImportedState &&
|
|
3811
|
+
const isDestructuredNonReactive = result?.parts?.length === 1 && result.isImportedState && t9.isIdentifier(normalizedArrayExpr) && (() => {
|
|
3570
3812
|
const ref = stateRefs.get(normalizedArrayExpr.name);
|
|
3571
3813
|
if (!ref || ref.kind !== "imported-destructured" || !ref.storeVar || !ref.propName) return false;
|
|
3572
3814
|
const storeRef = stateRefs.get(ref.storeVar);
|
|
3573
3815
|
return !storeRef?.reactiveFields?.has(ref.propName);
|
|
3574
3816
|
})();
|
|
3575
|
-
if (!result?.parts?.length || isDestructuredNonReactive || !
|
|
3576
|
-
if (
|
|
3817
|
+
if (!result?.parts?.length || isDestructuredNonReactive || !t9.isArrowFunctionExpression(expr.arguments[0])) {
|
|
3818
|
+
if (t9.isArrowFunctionExpression(expr.arguments?.[0])) {
|
|
3577
3819
|
const arrowFn2 = expr.arguments[0];
|
|
3578
3820
|
normalizeDestructuredMapCallback(arrowFn2);
|
|
3579
|
-
const itemVar2 =
|
|
3580
|
-
const indexVar2 =
|
|
3821
|
+
const itemVar2 = t9.isIdentifier(arrowFn2.params[0]) ? arrowFn2.params[0].name : "item";
|
|
3822
|
+
const indexVar2 = t9.isIdentifier(arrowFn2.params[1]) ? arrowFn2.params[1].name : void 0;
|
|
3581
3823
|
const itemTemplate2 = extractItemTemplate(arrowFn2);
|
|
3582
3824
|
const itemIdProp = detectItemIdProperty(itemTemplate2, itemVar2);
|
|
3583
3825
|
const computationSetupStatements = templateSetupContext ? collectTemplateSetupStatements(normalizedArrayExpr, templateSetupContext) : [];
|
|
@@ -3602,8 +3844,8 @@ function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stat
|
|
|
3602
3844
|
...indexVar2 ? { indexVariable: indexVar2 } : {},
|
|
3603
3845
|
itemIdProperty: itemIdProp,
|
|
3604
3846
|
rootHasUserId: hasRootUserIdAttribute(itemTemplate2),
|
|
3605
|
-
computationExpr:
|
|
3606
|
-
computationSetupStatements: computationSetupStatements.map((stmt) =>
|
|
3847
|
+
computationExpr: t9.cloneNode(normalizedArrayExpr, true),
|
|
3848
|
+
computationSetupStatements: computationSetupStatements.map((stmt) => t9.cloneNode(stmt, true)),
|
|
3607
3849
|
dependencies,
|
|
3608
3850
|
containerElementPath: [...elementPath],
|
|
3609
3851
|
...cbBodyStmts2.length > 0 ? { callbackBodyStatements: cbBodyStmts2 } : {},
|
|
@@ -3618,8 +3860,8 @@ function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stat
|
|
|
3618
3860
|
const finalPath = result.parts;
|
|
3619
3861
|
const arrowFn = expr.arguments[0];
|
|
3620
3862
|
normalizeDestructuredMapCallback(arrowFn);
|
|
3621
|
-
const itemVar =
|
|
3622
|
-
const indexVar =
|
|
3863
|
+
const itemVar = t9.isIdentifier(arrowFn.params[0]) ? arrowFn.params[0].name : "item";
|
|
3864
|
+
const indexVar = t9.isIdentifier(arrowFn.params[1]) ? arrowFn.params[1].name : void 0;
|
|
3623
3865
|
const itemTemplate = extractItemTemplate(arrowFn);
|
|
3624
3866
|
const cbBodyStmts = extractCallbackBodyStatements(arrowFn);
|
|
3625
3867
|
const itemIdProperty = detectItemIdProperty(itemTemplate, itemVar);
|
|
@@ -3632,15 +3874,15 @@ function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stat
|
|
|
3632
3874
|
const storeVar = result.isImportedState ? result.storeVar : void 0;
|
|
3633
3875
|
const walkBody = (body) => {
|
|
3634
3876
|
let target = body;
|
|
3635
|
-
if (
|
|
3636
|
-
const returnStmt = body.body.find((s) =>
|
|
3877
|
+
if (t9.isBlockStatement(body)) {
|
|
3878
|
+
const returnStmt = body.body.find((s) => t9.isReturnStatement(s));
|
|
3637
3879
|
target = returnStmt?.argument;
|
|
3638
3880
|
}
|
|
3639
3881
|
if (!target) return;
|
|
3640
|
-
if (
|
|
3641
|
-
target =
|
|
3642
|
-
if (
|
|
3643
|
-
if (
|
|
3882
|
+
if (t9.isConditionalExpression(target))
|
|
3883
|
+
target = t9.isJSXElement(target.consequent) ? target.consequent : target.alternate;
|
|
3884
|
+
if (t9.isParenthesizedExpression(target)) target = target.expression;
|
|
3885
|
+
if (t9.isJSXElement(target))
|
|
3644
3886
|
analyzeJSXInMap(
|
|
3645
3887
|
target,
|
|
3646
3888
|
finalPath,
|
|
@@ -3655,9 +3897,9 @@ function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stat
|
|
|
3655
3897
|
[],
|
|
3656
3898
|
storeVar
|
|
3657
3899
|
);
|
|
3658
|
-
else if (
|
|
3900
|
+
else if (t9.isJSXFragment(target))
|
|
3659
3901
|
target.children.forEach((fc) => {
|
|
3660
|
-
if (
|
|
3902
|
+
if (t9.isJSXElement(fc))
|
|
3661
3903
|
analyzeJSXInMap(
|
|
3662
3904
|
fc,
|
|
3663
3905
|
finalPath,
|
|
@@ -3673,7 +3915,7 @@ function handleArrayMap(expr, tagName, node, elementPath, index, arrayMaps, stat
|
|
|
3673
3915
|
storeVar
|
|
3674
3916
|
);
|
|
3675
3917
|
});
|
|
3676
|
-
else if (
|
|
3918
|
+
else if (t9.isParenthesizedExpression(target) && t9.isJSXElement(target.expression))
|
|
3677
3919
|
analyzeJSXInMap(
|
|
3678
3920
|
target.expression,
|
|
3679
3921
|
finalPath,
|
|
@@ -3740,8 +3982,8 @@ function handleTextBinding(expr, node, tagName, elementPath, bindings, propBindi
|
|
|
3740
3982
|
selector: selector3,
|
|
3741
3983
|
type: "text",
|
|
3742
3984
|
elementPath: [...elementPath],
|
|
3743
|
-
expression:
|
|
3744
|
-
setupStatements: setupStatements.map((statement) =>
|
|
3985
|
+
expression: t9.cloneNode(derivedTemplateExpr, true),
|
|
3986
|
+
setupStatements: setupStatements.map((statement) => t9.cloneNode(statement, true)),
|
|
3745
3987
|
...textNodeIndex !== void 0 ? { textNodeIndex } : {}
|
|
3746
3988
|
}))
|
|
3747
3989
|
);
|
|
@@ -3777,8 +4019,8 @@ function handleTextBinding(expr, node, tagName, elementPath, bindings, propBindi
|
|
|
3777
4019
|
selector: selector2,
|
|
3778
4020
|
type: "text",
|
|
3779
4021
|
elementPath: [...elementPath],
|
|
3780
|
-
expression:
|
|
3781
|
-
setupStatements: setupStatements.map((statement) =>
|
|
4022
|
+
expression: t9.cloneNode(derivedTemplateExpr, true),
|
|
4023
|
+
setupStatements: setupStatements.map((statement) => t9.cloneNode(statement, true)),
|
|
3782
4024
|
...textNodeIndex !== void 0 ? { textNodeIndex } : {}
|
|
3783
4025
|
}))
|
|
3784
4026
|
);
|
|
@@ -3804,7 +4046,7 @@ function handleTextBinding(expr, node, tagName, elementPath, bindings, propBindi
|
|
|
3804
4046
|
}
|
|
3805
4047
|
}
|
|
3806
4048
|
if (templateSetupContext && expressionMayProduceJSX(expr) && rerenderPropNames) {
|
|
3807
|
-
if (
|
|
4049
|
+
if (t9.isJSXEmptyExpression(expr)) return;
|
|
3808
4050
|
const conditionExpr = extractConditionalControlExpression(expr);
|
|
3809
4051
|
if (conditionExpr) {
|
|
3810
4052
|
const condSetupStatements = collectTemplateSetupStatements(conditionExpr, templateSetupContext);
|
|
@@ -3829,23 +4071,23 @@ function handleTextBinding(expr, node, tagName, elementPath, bindings, propBindi
|
|
|
3829
4071
|
dependentProps.forEach((propName2) => rerenderPropNames.add(propName2));
|
|
3830
4072
|
if (dependentProps.length > 0 || dependencies.length > 0) {
|
|
3831
4073
|
rerenderConditions?.push({
|
|
3832
|
-
expression:
|
|
3833
|
-
setupStatements: condSetupStatements.map((s) =>
|
|
4074
|
+
expression: t9.cloneNode(conditionExpr, true),
|
|
4075
|
+
setupStatements: condSetupStatements.map((s) => t9.cloneNode(s, true))
|
|
3834
4076
|
});
|
|
3835
4077
|
if (conditionalSlots) {
|
|
3836
4078
|
const slotId = `c${conditionalSlots.length}`;
|
|
3837
4079
|
conditionalSlots.push({
|
|
3838
4080
|
slotId,
|
|
3839
|
-
conditionExpr:
|
|
3840
|
-
setupStatements: condSetupStatements.map((s) =>
|
|
3841
|
-
htmlSetupStatements: fullSetupStatements.map((s) =>
|
|
4081
|
+
conditionExpr: t9.cloneNode(conditionExpr, true),
|
|
4082
|
+
setupStatements: condSetupStatements.map((s) => t9.cloneNode(s, true)),
|
|
4083
|
+
htmlSetupStatements: fullSetupStatements.map((s) => t9.cloneNode(s, true)),
|
|
3842
4084
|
dependentPropNames: [...dependentProps],
|
|
3843
4085
|
dependencies: dependencies.map((dep) => ({
|
|
3844
4086
|
observeKey: dep.observeKey,
|
|
3845
4087
|
pathParts: [...dep.pathParts],
|
|
3846
4088
|
...dep.storeVar ? { storeVar: dep.storeVar } : {}
|
|
3847
4089
|
})),
|
|
3848
|
-
originalExpr:
|
|
4090
|
+
originalExpr: t9.cloneNode(expr, true)
|
|
3849
4091
|
});
|
|
3850
4092
|
conditionalSlotNodeMap?.set(expr, slotId);
|
|
3851
4093
|
}
|
|
@@ -3854,7 +4096,7 @@ function handleTextBinding(expr, node, tagName, elementPath, bindings, propBindi
|
|
|
3854
4096
|
}
|
|
3855
4097
|
const result = resolveExpr(expr, stateRefs);
|
|
3856
4098
|
if (!result?.parts?.length) {
|
|
3857
|
-
if (templateSetupContext && !
|
|
4099
|
+
if (templateSetupContext && !t9.isJSXEmptyExpression(expr) && !expressionMayProduceJSX(expr)) {
|
|
3858
4100
|
const exprToUse = shouldBuildTextTemplate && textTemplate && !jsxInTextSiblingGroup ? buildTextTemplateExpressionFromParts(textTemplate, textExpressions) : expr;
|
|
3859
4101
|
const setupStatements = collectTemplateSetupStatements(exprToUse, templateSetupContext);
|
|
3860
4102
|
const dependencies = collectExpressionDependencies(exprToUse, stateRefs, setupStatements);
|
|
@@ -3866,8 +4108,8 @@ function handleTextBinding(expr, node, tagName, elementPath, bindings, propBindi
|
|
|
3866
4108
|
selector: selector2,
|
|
3867
4109
|
type: "text",
|
|
3868
4110
|
elementPath: [...elementPath],
|
|
3869
|
-
expression:
|
|
3870
|
-
setupStatements: setupStatements.map((s) =>
|
|
4111
|
+
expression: t9.cloneNode(exprToUse, true),
|
|
4112
|
+
setupStatements: setupStatements.map((s) => t9.cloneNode(s, true)),
|
|
3871
4113
|
stateOnly: true,
|
|
3872
4114
|
...textNodeIndex !== void 0 ? { textNodeIndex } : {}
|
|
3873
4115
|
});
|
|
@@ -3913,23 +4155,23 @@ function textSiblingGroupContainsJSX(textExpressions) {
|
|
|
3913
4155
|
return textExpressions.some((te) => te.expression && expressionMayProduceJSX(te.expression));
|
|
3914
4156
|
}
|
|
3915
4157
|
function expressionMayProduceJSX(expr) {
|
|
3916
|
-
if (
|
|
3917
|
-
if (
|
|
3918
|
-
if (
|
|
4158
|
+
if (t9.isJSXEmptyExpression(expr)) return false;
|
|
4159
|
+
if (t9.isJSXElement(expr) || t9.isJSXFragment(expr)) return true;
|
|
4160
|
+
if (t9.isLogicalExpression(expr)) {
|
|
3919
4161
|
return expressionMayProduceJSX(expr.left) || expressionMayProduceJSX(expr.right);
|
|
3920
4162
|
}
|
|
3921
|
-
if (
|
|
4163
|
+
if (t9.isConditionalExpression(expr)) {
|
|
3922
4164
|
return expressionMayProduceJSX(expr.consequent) || expressionMayProduceJSX(expr.alternate);
|
|
3923
4165
|
}
|
|
3924
|
-
if (
|
|
4166
|
+
if (t9.isParenthesizedExpression(expr)) {
|
|
3925
4167
|
return expressionMayProduceJSX(expr.expression);
|
|
3926
4168
|
}
|
|
3927
|
-
if (
|
|
4169
|
+
if (t9.isCallExpression(expr)) {
|
|
3928
4170
|
const callee = expr.callee;
|
|
3929
|
-
if (
|
|
3930
|
-
if (
|
|
4171
|
+
if (t9.isArrowFunctionExpression(callee) || t9.isFunctionExpression(callee)) {
|
|
4172
|
+
if (t9.isBlockStatement(callee.body)) {
|
|
3931
4173
|
return callee.body.body.some(
|
|
3932
|
-
(s) =>
|
|
4174
|
+
(s) => t9.isReturnStatement(s) && !!s.argument && expressionMayProduceJSX(s.argument)
|
|
3933
4175
|
);
|
|
3934
4176
|
}
|
|
3935
4177
|
return expressionMayProduceJSX(callee.body);
|
|
@@ -3938,24 +4180,24 @@ function expressionMayProduceJSX(expr) {
|
|
|
3938
4180
|
return false;
|
|
3939
4181
|
}
|
|
3940
4182
|
function extractConditionalControlExpression(expr) {
|
|
3941
|
-
if (
|
|
4183
|
+
if (t9.isParenthesizedExpression(expr)) {
|
|
3942
4184
|
return extractConditionalControlExpression(expr.expression);
|
|
3943
4185
|
}
|
|
3944
|
-
if (
|
|
4186
|
+
if (t9.isLogicalExpression(expr) && expr.operator === "&&") {
|
|
3945
4187
|
if (expressionMayProduceJSX(expr.right)) return expr.left;
|
|
3946
4188
|
if (expressionMayProduceJSX(expr.left)) return expr.right;
|
|
3947
4189
|
return null;
|
|
3948
4190
|
}
|
|
3949
|
-
if (
|
|
4191
|
+
if (t9.isLogicalExpression(expr) && expr.operator === "||") {
|
|
3950
4192
|
return expr.left;
|
|
3951
4193
|
}
|
|
3952
|
-
if (
|
|
4194
|
+
if (t9.isConditionalExpression(expr)) {
|
|
3953
4195
|
return expr.test;
|
|
3954
4196
|
}
|
|
3955
4197
|
return null;
|
|
3956
4198
|
}
|
|
3957
4199
|
function buildDerivedPropBindings(expr, type, attributeName, elementPath, propsParamName, destructuredPropNames, templateSetupContext, classBody2) {
|
|
3958
|
-
if (
|
|
4200
|
+
if (t9.isJSXEmptyExpression(expr) || !templateSetupContext) return [];
|
|
3959
4201
|
const setupStatements = collectTemplateSetupStatements(expr, templateSetupContext);
|
|
3960
4202
|
const dependentProps = collectDependentPropNames(
|
|
3961
4203
|
expr,
|
|
@@ -3972,15 +4214,15 @@ function buildDerivedPropBindings(expr, type, attributeName, elementPath, propsP
|
|
|
3972
4214
|
type,
|
|
3973
4215
|
attributeName,
|
|
3974
4216
|
elementPath: [...elementPath],
|
|
3975
|
-
expression:
|
|
3976
|
-
setupStatements: setupStatements.map((statement) =>
|
|
4217
|
+
expression: t9.cloneNode(expr, true),
|
|
4218
|
+
setupStatements: setupStatements.map((statement) => t9.cloneNode(statement, true))
|
|
3977
4219
|
}));
|
|
3978
4220
|
}
|
|
3979
4221
|
function collectDependentPropNames(expr, setupStatements, propsParamName, destructuredPropNames, classBody2) {
|
|
3980
4222
|
const names = /* @__PURE__ */ new Set();
|
|
3981
|
-
const program12 =
|
|
3982
|
-
...setupStatements.map((statement) =>
|
|
3983
|
-
|
|
4223
|
+
const program12 = t9.program([
|
|
4224
|
+
...setupStatements.map((statement) => t9.cloneNode(statement, true)),
|
|
4225
|
+
t9.expressionStatement(t9.cloneNode(expr, true))
|
|
3984
4226
|
]);
|
|
3985
4227
|
const getterNamesToExpand = /* @__PURE__ */ new Set();
|
|
3986
4228
|
traverse5(program12, {
|
|
@@ -3992,16 +4234,16 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
|
|
|
3992
4234
|
MemberExpression(path) {
|
|
3993
4235
|
const propName = resolvePropRef(path.node, propsParamName, destructuredPropNames);
|
|
3994
4236
|
if (propName) names.add(propName);
|
|
3995
|
-
if (classBody2 &&
|
|
4237
|
+
if (classBody2 && t9.isThisExpression(path.node.object) && t9.isIdentifier(path.node.property)) {
|
|
3996
4238
|
getterNamesToExpand.add(path.node.property.name);
|
|
3997
4239
|
}
|
|
3998
4240
|
}
|
|
3999
4241
|
});
|
|
4000
4242
|
if (classBody2 && getterNamesToExpand.size > 0) {
|
|
4001
4243
|
for (const member of classBody2.body) {
|
|
4002
|
-
if (!
|
|
4244
|
+
if (!t9.isClassMethod(member) || member.kind !== "get" || !t9.isIdentifier(member.key) || !getterNamesToExpand.has(member.key.name))
|
|
4003
4245
|
continue;
|
|
4004
|
-
const getterProgram =
|
|
4246
|
+
const getterProgram = t9.program(member.body.body.map((s) => t9.cloneNode(s, true)));
|
|
4005
4247
|
traverse5(getterProgram, {
|
|
4006
4248
|
noScope: true,
|
|
4007
4249
|
Identifier(path) {
|
|
@@ -4009,10 +4251,10 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
|
|
|
4009
4251
|
if (destructuredPropNames?.has(path.node.name)) names.add(path.node.name);
|
|
4010
4252
|
},
|
|
4011
4253
|
MemberExpression(path) {
|
|
4012
|
-
if (
|
|
4013
|
-
if (path.node.property.name === "props" &&
|
|
4254
|
+
if (t9.isThisExpression(path.node.object) && t9.isIdentifier(path.node.property)) {
|
|
4255
|
+
if (path.node.property.name === "props" && t9.isMemberExpression(path.parentPath?.node)) {
|
|
4014
4256
|
const parent = path.parentPath.node;
|
|
4015
|
-
if (
|
|
4257
|
+
if (t9.isIdentifier(parent.property)) names.add(parent.property.name);
|
|
4016
4258
|
}
|
|
4017
4259
|
}
|
|
4018
4260
|
const propName = resolvePropRef(path.node, propsParamName, destructuredPropNames);
|
|
@@ -4023,24 +4265,34 @@ function collectDependentPropNames(expr, setupStatements, propsParamName, destru
|
|
|
4023
4265
|
}
|
|
4024
4266
|
return Array.from(names);
|
|
4025
4267
|
}
|
|
4268
|
+
function isInsideRefAttribute(path) {
|
|
4269
|
+
let current = path;
|
|
4270
|
+
while (current) {
|
|
4271
|
+
if (t9.isJSXAttribute(current.node) && t9.isJSXIdentifier(current.node.name) && current.node.name.name === "ref")
|
|
4272
|
+
return true;
|
|
4273
|
+
current = current.parentPath;
|
|
4274
|
+
}
|
|
4275
|
+
return false;
|
|
4276
|
+
}
|
|
4026
4277
|
function collectAllStateAccesses(templateMethod, stateRefs, stateProps, templateSetupContext, rootExpr) {
|
|
4027
|
-
const params = templateMethod.params.filter((param) => !
|
|
4028
|
-
const expr = rootExpr && !
|
|
4278
|
+
const params = templateMethod.params.filter((param) => !t9.isTSParameterProperty(param));
|
|
4279
|
+
const expr = rootExpr && !t9.isJSXEmptyExpression(rootExpr) ? t9.cloneNode(rootExpr, true) : t9.arrowFunctionExpression(params, templateMethod.body);
|
|
4029
4280
|
const setupStatements = rootExpr && templateSetupContext ? (() => {
|
|
4030
4281
|
const collected = collectTemplateSetupStatements(rootExpr, templateSetupContext);
|
|
4031
|
-
if (collected.length > 0) return collected.map((s) =>
|
|
4282
|
+
if (collected.length > 0) return collected.map((s) => t9.cloneNode(s, true));
|
|
4032
4283
|
if (templateSetupContext.earlyReturnBarrierIndex === void 0) return [];
|
|
4033
|
-
return templateSetupContext.statements.slice(0, templateSetupContext.earlyReturnBarrierIndex + 1).map((s) =>
|
|
4284
|
+
return templateSetupContext.statements.slice(0, templateSetupContext.earlyReturnBarrierIndex + 1).map((s) => t9.cloneNode(s, true));
|
|
4034
4285
|
})() : [];
|
|
4035
|
-
const prog =
|
|
4286
|
+
const prog = t9.program([...setupStatements, t9.expressionStatement(expr)]);
|
|
4036
4287
|
traverse5(prog, {
|
|
4037
4288
|
noScope: true,
|
|
4038
4289
|
Identifier(path) {
|
|
4039
4290
|
if (!stateRefs.has(path.node.name)) return;
|
|
4291
|
+
if (isInsideRefAttribute(path)) return;
|
|
4040
4292
|
const ref = stateRefs.get(path.node.name);
|
|
4041
|
-
if (path.parentPath &&
|
|
4293
|
+
if (path.parentPath && t9.isMemberExpression(path.parentPath.node) && path.parentPath.node.object === path.node && t9.isIdentifier(path.parentPath.node.property) && !path.parentPath.node.computed) {
|
|
4042
4294
|
const grandParent = path.parentPath.parentPath;
|
|
4043
|
-
if (!(grandParent &&
|
|
4295
|
+
if (!(grandParent && t9.isCallExpression(grandParent.node) && grandParent.node.callee === path.parentPath.node)) {
|
|
4044
4296
|
return;
|
|
4045
4297
|
}
|
|
4046
4298
|
}
|
|
@@ -4064,17 +4316,18 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps, template
|
|
|
4064
4316
|
}
|
|
4065
4317
|
},
|
|
4066
4318
|
MemberExpression(path) {
|
|
4067
|
-
if (!
|
|
4319
|
+
if (!t9.isIdentifier(path.node.property)) return;
|
|
4320
|
+
if (isInsideRefAttribute(path)) return;
|
|
4068
4321
|
const parent = path.parentPath;
|
|
4069
|
-
if (parent &&
|
|
4322
|
+
if (parent && t9.isCallExpression(parent.node) && parent.node.callee === path.node) return;
|
|
4070
4323
|
const resolved = resolvePath(path.node, stateRefs);
|
|
4071
4324
|
if (!resolved || resolved.parts === null) return;
|
|
4072
4325
|
if (resolved.parts.length === 0 && resolved.storeVar) {
|
|
4073
4326
|
const decl = parent?.node;
|
|
4074
|
-
if (
|
|
4327
|
+
if (t9.isVariableDeclarator(decl) && t9.isObjectPattern(decl.id)) {
|
|
4075
4328
|
for (const prop of decl.id.properties) {
|
|
4076
|
-
if (!
|
|
4077
|
-
const key =
|
|
4329
|
+
if (!t9.isObjectProperty(prop)) continue;
|
|
4330
|
+
const key = t9.isIdentifier(prop.key) ? prop.key.name : t9.isStringLiteral(prop.key) ? prop.key.value : null;
|
|
4078
4331
|
if (!key) continue;
|
|
4079
4332
|
const observeKey2 = buildObserveKey([key], resolved.storeVar);
|
|
4080
4333
|
if (!stateProps.has(observeKey2)) stateProps.set(observeKey2, [key]);
|
|
@@ -4092,15 +4345,15 @@ function collectAllStateAccesses(templateMethod, stateRefs, stateProps, template
|
|
|
4092
4345
|
}
|
|
4093
4346
|
function collectItemTemplateStoreDependencies(itemTemplate, itemVar, stateRefs, dependencies) {
|
|
4094
4347
|
if (!itemTemplate) return;
|
|
4095
|
-
const prog =
|
|
4348
|
+
const prog = t9.program([t9.expressionStatement(t9.cloneNode(itemTemplate, true))]);
|
|
4096
4349
|
traverse5(prog, {
|
|
4097
4350
|
noScope: true,
|
|
4098
4351
|
MemberExpression(path) {
|
|
4099
4352
|
let root = path.node;
|
|
4100
|
-
while (
|
|
4101
|
-
if (
|
|
4353
|
+
while (t9.isMemberExpression(root)) root = root.object;
|
|
4354
|
+
if (t9.isIdentifier(root) && root.name === itemVar) return;
|
|
4102
4355
|
const parent = path.parentPath;
|
|
4103
|
-
if (parent &&
|
|
4356
|
+
if (parent && t9.isCallExpression(parent.node) && parent.node.callee === path.node) return;
|
|
4104
4357
|
const resolved = resolvePath(path.node, stateRefs);
|
|
4105
4358
|
if (!resolved?.parts?.length) return;
|
|
4106
4359
|
const parts = [...resolved.parts];
|
|
@@ -4117,39 +4370,39 @@ function collectItemTemplateStoreDependencies(itemTemplate, itemVar, stateRefs,
|
|
|
4117
4370
|
});
|
|
4118
4371
|
}
|
|
4119
4372
|
function detectUnresolvedRelationalClassBindings(itemTemplate, itemVar, stateRefs, dependencies) {
|
|
4120
|
-
if (!itemTemplate || !
|
|
4373
|
+
if (!itemTemplate || !t9.isJSXElement(itemTemplate)) return [];
|
|
4121
4374
|
const classAttr = itemTemplate.openingElement.attributes.find(
|
|
4122
|
-
(attr) =>
|
|
4375
|
+
(attr) => t9.isJSXAttribute(attr) && t9.isJSXIdentifier(attr.name) && (attr.name.name === "class" || attr.name.name === "className")
|
|
4123
4376
|
);
|
|
4124
|
-
if (!classAttr?.value || !
|
|
4377
|
+
if (!classAttr?.value || !t9.isJSXExpressionContainer(classAttr.value)) return [];
|
|
4125
4378
|
const expr = classAttr.value.expression;
|
|
4126
4379
|
const conditionals = [];
|
|
4127
|
-
if (
|
|
4380
|
+
if (t9.isTemplateLiteral(expr)) {
|
|
4128
4381
|
for (const inner of expr.expressions) {
|
|
4129
|
-
if (
|
|
4382
|
+
if (t9.isConditionalExpression(inner)) conditionals.push(inner);
|
|
4130
4383
|
}
|
|
4131
|
-
} else if (
|
|
4384
|
+
} else if (t9.isConditionalExpression(expr)) {
|
|
4132
4385
|
conditionals.push(expr);
|
|
4133
4386
|
}
|
|
4134
4387
|
const results = [];
|
|
4135
4388
|
for (const cond of conditionals) {
|
|
4136
|
-
if (!
|
|
4389
|
+
if (!t9.isBinaryExpression(cond.test)) continue;
|
|
4137
4390
|
if (!["===", "==", "!==", "!="].includes(cond.test.operator)) continue;
|
|
4138
4391
|
const matchWhenEqual = cond.test.operator === "===" || cond.test.operator === "==";
|
|
4139
4392
|
let storeObserveKey;
|
|
4140
4393
|
let itemSideFound = false;
|
|
4141
4394
|
let itemProperty;
|
|
4142
4395
|
for (const side of [cond.test.left, cond.test.right]) {
|
|
4143
|
-
if (
|
|
4396
|
+
if (t9.isIdentifier(side) && side.name === itemVar) {
|
|
4144
4397
|
itemSideFound = true;
|
|
4145
4398
|
continue;
|
|
4146
4399
|
}
|
|
4147
|
-
if (
|
|
4400
|
+
if (t9.isMemberExpression(side) && t9.isIdentifier(side.object) && side.object.name === itemVar && t9.isIdentifier(side.property)) {
|
|
4148
4401
|
itemSideFound = true;
|
|
4149
4402
|
itemProperty = side.property.name;
|
|
4150
4403
|
continue;
|
|
4151
4404
|
}
|
|
4152
|
-
if (
|
|
4405
|
+
if (t9.isMemberExpression(side) || t9.isIdentifier(side)) {
|
|
4153
4406
|
const resolved = resolvePath(side, stateRefs);
|
|
4154
4407
|
if (resolved?.parts?.length && resolved.isImportedState) {
|
|
4155
4408
|
storeObserveKey = buildObserveKey(resolved.parts, resolved.storeVar);
|
|
@@ -4159,7 +4412,7 @@ function detectUnresolvedRelationalClassBindings(itemTemplate, itemVar, stateRef
|
|
|
4159
4412
|
if (!storeObserveKey || !itemSideFound) continue;
|
|
4160
4413
|
if (!dependencies.some((d) => d.observeKey === storeObserveKey)) continue;
|
|
4161
4414
|
const extractName = (node) => {
|
|
4162
|
-
if (
|
|
4415
|
+
if (t9.isStringLiteral(node)) return node.value.trim() || null;
|
|
4163
4416
|
return null;
|
|
4164
4417
|
};
|
|
4165
4418
|
const className = extractName(cond.consequent) || extractName(cond.alternate);
|
|
@@ -4177,218 +4430,6 @@ function detectUnresolvedRelationalClassBindings(itemTemplate, itemVar, stateRef
|
|
|
4177
4430
|
|
|
4178
4431
|
// src/transform-jsx.ts
|
|
4179
4432
|
import * as t10 from "@babel/types";
|
|
4180
|
-
|
|
4181
|
-
// src/component-event-helpers.ts
|
|
4182
|
-
import * as t9 from "@babel/types";
|
|
4183
|
-
import { existsSync, readFileSync } from "fs";
|
|
4184
|
-
import { dirname, resolve } from "path";
|
|
4185
|
-
function toGeaEventType(attrName) {
|
|
4186
|
-
if (attrName.startsWith("on") && attrName.length > 2) {
|
|
4187
|
-
const rest = attrName.slice(2);
|
|
4188
|
-
return rest.charAt(0).toLowerCase() + rest.slice(1);
|
|
4189
|
-
}
|
|
4190
|
-
return attrName;
|
|
4191
|
-
}
|
|
4192
|
-
function getPropContext(params) {
|
|
4193
|
-
const context = {
|
|
4194
|
-
destructuredPropNames: /* @__PURE__ */ new Set()
|
|
4195
|
-
};
|
|
4196
|
-
const firstParam = params?.[0];
|
|
4197
|
-
if (!firstParam || t9.isRestElement(firstParam)) return context;
|
|
4198
|
-
const binding = getTemplateParamBinding(firstParam);
|
|
4199
|
-
if (!binding) return context;
|
|
4200
|
-
if (t9.isIdentifier(binding)) {
|
|
4201
|
-
context.propsParamName = binding.name;
|
|
4202
|
-
return context;
|
|
4203
|
-
}
|
|
4204
|
-
context.propsParamName = "props";
|
|
4205
|
-
binding.properties.forEach((prop) => {
|
|
4206
|
-
if (t9.isObjectProperty(prop) && t9.isIdentifier(prop.key)) {
|
|
4207
|
-
context.destructuredPropNames.add(prop.key.name);
|
|
4208
|
-
}
|
|
4209
|
-
});
|
|
4210
|
-
return context;
|
|
4211
|
-
}
|
|
4212
|
-
function getRootClassSelector(node) {
|
|
4213
|
-
for (const attr of node.openingElement.attributes) {
|
|
4214
|
-
if (!t9.isJSXAttribute(attr) || !t9.isJSXIdentifier(attr.name)) continue;
|
|
4215
|
-
if (attr.name.name !== "class" && attr.name.name !== "className") continue;
|
|
4216
|
-
let firstClass = "";
|
|
4217
|
-
if (t9.isStringLiteral(attr.value)) {
|
|
4218
|
-
firstClass = attr.value.value.trim().split(/\s+/)[0] || "";
|
|
4219
|
-
} else if (t9.isJSXExpressionContainer(attr.value) && !t9.isJSXEmptyExpression(attr.value.expression)) {
|
|
4220
|
-
const expr = attr.value.expression;
|
|
4221
|
-
if (t9.isStringLiteral(expr)) {
|
|
4222
|
-
firstClass = expr.value.trim().split(/\s+/)[0] || "";
|
|
4223
|
-
} else if (t9.isTemplateLiteral(expr)) {
|
|
4224
|
-
firstClass = expr.quasis[0]?.value.raw.trim().split(/\s+/)[0] || "";
|
|
4225
|
-
}
|
|
4226
|
-
}
|
|
4227
|
-
if (firstClass) return `.${firstClass}`;
|
|
4228
|
-
}
|
|
4229
|
-
return null;
|
|
4230
|
-
}
|
|
4231
|
-
function resolvePropCallbackName(expr, context) {
|
|
4232
|
-
if (t9.isIdentifier(expr) && context.destructuredPropNames.has(expr.name)) {
|
|
4233
|
-
return expr.name;
|
|
4234
|
-
}
|
|
4235
|
-
if (t9.isMemberExpression(expr) && t9.isIdentifier(expr.property) && t9.isIdentifier(expr.object) && expr.object.name === (context.propsParamName || "props")) {
|
|
4236
|
-
return expr.property.name;
|
|
4237
|
-
}
|
|
4238
|
-
if (t9.isMemberExpression(expr) && t9.isIdentifier(expr.property) && t9.isMemberExpression(expr.object) && t9.isIdentifier(expr.object.property) && expr.object.property.name === "props" && (t9.isThisExpression(expr.object.object) || t9.isIdentifier(expr.object.object) && expr.object.object.name === (context.propsParamName || "props"))) {
|
|
4239
|
-
return expr.property.name;
|
|
4240
|
-
}
|
|
4241
|
-
return null;
|
|
4242
|
-
}
|
|
4243
|
-
function extractSingleCallExpression(expr) {
|
|
4244
|
-
if (t9.isCallExpression(expr)) return expr;
|
|
4245
|
-
if (t9.isArrowFunctionExpression(expr) || t9.isFunctionExpression(expr)) {
|
|
4246
|
-
if (t9.isCallExpression(expr.body)) return expr.body;
|
|
4247
|
-
if (!t9.isBlockStatement(expr.body) || expr.body.body.length !== 1) return null;
|
|
4248
|
-
const stmt = expr.body.body[0];
|
|
4249
|
-
if (t9.isExpressionStatement(stmt) && t9.isCallExpression(stmt.expression)) return stmt.expression;
|
|
4250
|
-
if (t9.isReturnStatement(stmt) && stmt.argument && t9.isCallExpression(stmt.argument)) return stmt.argument;
|
|
4251
|
-
}
|
|
4252
|
-
return null;
|
|
4253
|
-
}
|
|
4254
|
-
function getHoistableRootEvent(attrName, expr, elementPath, context, selector) {
|
|
4255
|
-
if (elementPath.length !== 0 || !selector) return null;
|
|
4256
|
-
if (attrName.startsWith("data-") || attrName === "class" || attrName === "className" || attrName === "style" || attrName === "id")
|
|
4257
|
-
return null;
|
|
4258
|
-
const eventType = toGeaEventType(attrName);
|
|
4259
|
-
const directProp = resolvePropCallbackName(expr, context);
|
|
4260
|
-
if (directProp) return { eventType, propName: directProp, selector };
|
|
4261
|
-
const callExpr = extractSingleCallExpression(expr);
|
|
4262
|
-
if (!callExpr) return null;
|
|
4263
|
-
const propName = resolvePropCallbackName(callExpr.callee, context);
|
|
4264
|
-
if (!propName) return null;
|
|
4265
|
-
return { eventType, propName, selector };
|
|
4266
|
-
}
|
|
4267
|
-
function resolveImportPath(importer, source) {
|
|
4268
|
-
const base = resolve(dirname(importer), source);
|
|
4269
|
-
const candidates = [
|
|
4270
|
-
base,
|
|
4271
|
-
`${base}.js`,
|
|
4272
|
-
`${base}.jsx`,
|
|
4273
|
-
`${base}.ts`,
|
|
4274
|
-
`${base}.tsx`,
|
|
4275
|
-
resolve(base, "index.js"),
|
|
4276
|
-
resolve(base, "index.jsx"),
|
|
4277
|
-
resolve(base, "index.ts"),
|
|
4278
|
-
resolve(base, "index.tsx")
|
|
4279
|
-
];
|
|
4280
|
-
for (const candidate of candidates) {
|
|
4281
|
-
if (existsSync(candidate)) return candidate;
|
|
4282
|
-
}
|
|
4283
|
-
return null;
|
|
4284
|
-
}
|
|
4285
|
-
function getReturnedRootJSX(ast, componentClassName) {
|
|
4286
|
-
let found = null;
|
|
4287
|
-
for (const stmt of ast.program.body) {
|
|
4288
|
-
if (t9.isExportDefaultDeclaration(stmt)) {
|
|
4289
|
-
const decl = stmt.declaration;
|
|
4290
|
-
if (t9.isFunctionDeclaration(decl) && decl.body) {
|
|
4291
|
-
const ret = decl.body.body.find(
|
|
4292
|
-
(node) => t9.isReturnStatement(node) && node.argument && t9.isJSXElement(node.argument)
|
|
4293
|
-
);
|
|
4294
|
-
if (ret && t9.isReturnStatement(ret) && ret.argument && t9.isJSXElement(ret.argument)) {
|
|
4295
|
-
return { jsx: ret.argument, context: getPropContext(decl.params) };
|
|
4296
|
-
}
|
|
4297
|
-
}
|
|
4298
|
-
if (t9.isIdentifier(decl)) {
|
|
4299
|
-
for (const bodyStmt of ast.program.body) {
|
|
4300
|
-
if (!t9.isVariableDeclaration(bodyStmt)) continue;
|
|
4301
|
-
for (const dec of bodyStmt.declarations) {
|
|
4302
|
-
if (!t9.isIdentifier(dec.id, { name: decl.name })) continue;
|
|
4303
|
-
if (!dec.init || !t9.isArrowFunctionExpression(dec.init) && !t9.isFunctionExpression(dec.init)) continue;
|
|
4304
|
-
const fn = dec.init;
|
|
4305
|
-
if (t9.isJSXElement(fn.body)) return { jsx: fn.body, context: getPropContext(fn.params) };
|
|
4306
|
-
if (t9.isBlockStatement(fn.body)) {
|
|
4307
|
-
const ret = fn.body.body.find(
|
|
4308
|
-
(node) => t9.isReturnStatement(node) && node.argument && t9.isJSXElement(node.argument)
|
|
4309
|
-
);
|
|
4310
|
-
if (ret && t9.isReturnStatement(ret) && ret.argument && t9.isJSXElement(ret.argument)) {
|
|
4311
|
-
return { jsx: ret.argument, context: getPropContext(fn.params) };
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
}
|
|
4315
|
-
}
|
|
4316
|
-
}
|
|
4317
|
-
}
|
|
4318
|
-
if (componentClassName && t9.isExportDefaultDeclaration(stmt) && t9.isClassDeclaration(stmt.declaration) && t9.isIdentifier(stmt.declaration.id, { name: componentClassName })) {
|
|
4319
|
-
const templateMethod = stmt.declaration.body.body.find(
|
|
4320
|
-
(member) => t9.isClassMethod(member) && t9.isIdentifier(member.key) && member.key.name === "template"
|
|
4321
|
-
);
|
|
4322
|
-
if (!templateMethod || !t9.isBlockStatement(templateMethod.body)) return null;
|
|
4323
|
-
const ret = templateMethod.body.body.find(
|
|
4324
|
-
(node) => t9.isReturnStatement(node) && node.argument && t9.isJSXElement(node.argument)
|
|
4325
|
-
);
|
|
4326
|
-
if (ret && t9.isReturnStatement(ret) && ret.argument && t9.isJSXElement(ret.argument)) {
|
|
4327
|
-
return {
|
|
4328
|
-
jsx: ret.argument,
|
|
4329
|
-
context: getPropContext(templateMethod.params)
|
|
4330
|
-
};
|
|
4331
|
-
}
|
|
4332
|
-
}
|
|
4333
|
-
}
|
|
4334
|
-
for (const stmt of ast.program.body) {
|
|
4335
|
-
if (!componentClassName || !t9.isClassDeclaration(stmt) || !t9.isIdentifier(stmt.id, { name: componentClassName }))
|
|
4336
|
-
continue;
|
|
4337
|
-
const templateMethod = stmt.body.body.find(
|
|
4338
|
-
(member) => t9.isClassMethod(member) && t9.isIdentifier(member.key) && member.key.name === "template"
|
|
4339
|
-
);
|
|
4340
|
-
if (!templateMethod || !t9.isBlockStatement(templateMethod.body)) continue;
|
|
4341
|
-
const ret = templateMethod.body.body.find(
|
|
4342
|
-
(node) => t9.isReturnStatement(node) && node.argument && t9.isJSXElement(node.argument)
|
|
4343
|
-
);
|
|
4344
|
-
if (ret && t9.isReturnStatement(ret) && ret.argument && t9.isJSXElement(ret.argument)) {
|
|
4345
|
-
found = {
|
|
4346
|
-
jsx: ret.argument,
|
|
4347
|
-
context: getPropContext(templateMethod.params)
|
|
4348
|
-
};
|
|
4349
|
-
break;
|
|
4350
|
-
}
|
|
4351
|
-
}
|
|
4352
|
-
return found;
|
|
4353
|
-
}
|
|
4354
|
-
var hoistableRootEventCache = /* @__PURE__ */ new Map();
|
|
4355
|
-
function getHoistableRootEventsForImport(importer, source) {
|
|
4356
|
-
const resolved = resolveImportPath(importer, source);
|
|
4357
|
-
if (!resolved) return [];
|
|
4358
|
-
const cached = hoistableRootEventCache.get(resolved);
|
|
4359
|
-
if (cached) return cached;
|
|
4360
|
-
let result;
|
|
4361
|
-
try {
|
|
4362
|
-
const code = readFileSync(resolved, "utf8");
|
|
4363
|
-
const parsed = parseSource(code);
|
|
4364
|
-
if (!parsed) return [];
|
|
4365
|
-
const root = getReturnedRootJSX(parsed.ast, parsed.componentClassName);
|
|
4366
|
-
if (!root) return [];
|
|
4367
|
-
const selector = getRootClassSelector(root.jsx);
|
|
4368
|
-
if (!selector) return [];
|
|
4369
|
-
result = root.jsx.openingElement.attributes.flatMap((attr) => {
|
|
4370
|
-
if (!t9.isJSXAttribute(attr) || !t9.isJSXIdentifier(attr.name)) return [];
|
|
4371
|
-
if (!attr.value || !t9.isJSXExpressionContainer(attr.value) || t9.isJSXEmptyExpression(attr.value.expression)) {
|
|
4372
|
-
return [];
|
|
4373
|
-
}
|
|
4374
|
-
const meta = getHoistableRootEvent(
|
|
4375
|
-
attr.name.name,
|
|
4376
|
-
attr.value.expression,
|
|
4377
|
-
[],
|
|
4378
|
-
root.context,
|
|
4379
|
-
selector
|
|
4380
|
-
);
|
|
4381
|
-
return meta ? [meta] : [];
|
|
4382
|
-
});
|
|
4383
|
-
} catch (err) {
|
|
4384
|
-
console.warn(`[gea] Failed to analyze root events for ${resolved}:`, err instanceof Error ? err.message : err);
|
|
4385
|
-
result = [];
|
|
4386
|
-
}
|
|
4387
|
-
hoistableRootEventCache.set(resolved, result);
|
|
4388
|
-
return result;
|
|
4389
|
-
}
|
|
4390
|
-
|
|
4391
|
-
// src/transform-jsx.ts
|
|
4392
4433
|
var RESERVED_HTML_TAG_NAMES = /* @__PURE__ */ new Set([
|
|
4393
4434
|
"a",
|
|
4394
4435
|
"abbr",
|
|
@@ -4640,10 +4681,43 @@ function extractChildInstanceRef(expr) {
|
|
|
4640
4681
|
const instanceVar = memberExpr.property.name;
|
|
4641
4682
|
return { instanceVar, guardExpr: expr.left };
|
|
4642
4683
|
}
|
|
4684
|
+
function expressionContainsJSX(expr) {
|
|
4685
|
+
let found = false;
|
|
4686
|
+
const check = (node) => {
|
|
4687
|
+
if (found) return;
|
|
4688
|
+
if (t10.isJSXElement(node) || t10.isJSXFragment(node)) {
|
|
4689
|
+
found = true;
|
|
4690
|
+
return;
|
|
4691
|
+
}
|
|
4692
|
+
for (const key of t10.VISITOR_KEYS[node.type] || []) {
|
|
4693
|
+
const child = node[key];
|
|
4694
|
+
if (Array.isArray(child)) {
|
|
4695
|
+
for (const c of child) {
|
|
4696
|
+
if (c && typeof c === "object" && "type" in c) check(c);
|
|
4697
|
+
if (found) return;
|
|
4698
|
+
}
|
|
4699
|
+
} else if (child && typeof child === "object" && "type" in child) {
|
|
4700
|
+
check(child);
|
|
4701
|
+
}
|
|
4702
|
+
if (found) return;
|
|
4703
|
+
}
|
|
4704
|
+
};
|
|
4705
|
+
check(expr);
|
|
4706
|
+
return found;
|
|
4707
|
+
}
|
|
4708
|
+
function isChildrenPropAccess(expr) {
|
|
4709
|
+
if (t10.isMemberExpression(expr) && t10.isIdentifier(expr.property) && expr.property.name === "children" && t10.isIdentifier(expr.object) && expr.object.name === "props")
|
|
4710
|
+
return true;
|
|
4711
|
+
if (t10.isMemberExpression(expr) && t10.isIdentifier(expr.property) && expr.property.name === "children" && t10.isMemberExpression(expr.object) && t10.isThisExpression(expr.object.object) && t10.isIdentifier(expr.object.property) && expr.object.property.name === "props")
|
|
4712
|
+
return true;
|
|
4713
|
+
return false;
|
|
4714
|
+
}
|
|
4643
4715
|
function expressionMayBeFalsy(expr) {
|
|
4644
4716
|
if (t10.isLogicalExpression(expr) && expr.operator === "&&") return true;
|
|
4645
4717
|
if (t10.isConditionalExpression(expr)) return true;
|
|
4646
4718
|
if (t10.isBooleanLiteral(expr) && !expr.value) return true;
|
|
4719
|
+
if (t10.isOptionalMemberExpression(expr)) return true;
|
|
4720
|
+
if (t10.isOptionalCallExpression(expr)) return true;
|
|
4647
4721
|
return false;
|
|
4648
4722
|
}
|
|
4649
4723
|
function canBeBoolean(expr) {
|
|
@@ -4679,6 +4753,14 @@ function buildAttrSkipCondition(expr, rawExpr) {
|
|
|
4679
4753
|
function escapeHtml(str) {
|
|
4680
4754
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
4681
4755
|
}
|
|
4756
|
+
var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "data", "cite", "poster", "background"]);
|
|
4757
|
+
function wrapWithSanitizeAttr(attrName, expr) {
|
|
4758
|
+
if (!URL_ATTRS.has(attrName)) return expr;
|
|
4759
|
+
return t10.callExpression(t10.identifier("__sanitizeAttr"), [
|
|
4760
|
+
t10.stringLiteral(attrName),
|
|
4761
|
+
t10.callExpression(t10.identifier("String"), [expr])
|
|
4762
|
+
]);
|
|
4763
|
+
}
|
|
4682
4764
|
function getStaticStringValue(expr) {
|
|
4683
4765
|
if (t10.isStringLiteral(expr)) return expr.value;
|
|
4684
4766
|
if (t10.isTemplateLiteral(expr) && expr.expressions.length === 0) {
|
|
@@ -5130,6 +5212,7 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
5130
5212
|
}
|
|
5131
5213
|
let generatedEventSuffix;
|
|
5132
5214
|
let generatedEventToken;
|
|
5215
|
+
let dangerouslySetInnerHTMLExpr;
|
|
5133
5216
|
node.openingElement.attributes.forEach((attr) => {
|
|
5134
5217
|
if (t10.isJSXSpreadAttribute(attr)) {
|
|
5135
5218
|
const err = new Error(
|
|
@@ -5142,6 +5225,13 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
5142
5225
|
const attrName = attr.name.name;
|
|
5143
5226
|
if (attrName === "key") return;
|
|
5144
5227
|
if (attrName === "id" && hasBindingId) return;
|
|
5228
|
+
if (attrName === "dangerouslySetInnerHTML") {
|
|
5229
|
+
const dsiValue = attr.value;
|
|
5230
|
+
if (t10.isJSXExpressionContainer(dsiValue) && !t10.isJSXEmptyExpression(dsiValue.expression)) {
|
|
5231
|
+
dangerouslySetInnerHTMLExpr = dsiValue.expression;
|
|
5232
|
+
}
|
|
5233
|
+
return;
|
|
5234
|
+
}
|
|
5145
5235
|
if (attrName === "ref") {
|
|
5146
5236
|
const attrValue2 = attr.value;
|
|
5147
5237
|
if (t10.isJSXExpressionContainer(attrValue2) && !t10.isJSXEmptyExpression(attrValue2.expression) && ctx.refBindings && ctx.refCounter) {
|
|
@@ -5338,7 +5428,8 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
5338
5428
|
parts.push({ type: "string", value: html });
|
|
5339
5429
|
const expr = transformJSXExpression(rawExpr, ctx);
|
|
5340
5430
|
const skipCondition = buildAttrSkipCondition(expr, rawExpr);
|
|
5341
|
-
const
|
|
5431
|
+
const sanitizedExpr = wrapWithSanitizeAttr(propAttrName, expr);
|
|
5432
|
+
const templateExpr = propAttrName === "class" ? buildTrimmedClassValueExpression(expr) : sanitizedExpr;
|
|
5342
5433
|
if (t10.isBooleanLiteral(skipCondition) && !skipCondition.value) {
|
|
5343
5434
|
parts.push({ type: "string", value: ` ${propAttrName}="` });
|
|
5344
5435
|
parts.push({ type: "expression", value: templateExpr });
|
|
@@ -5367,7 +5458,12 @@ function processElement(node, parts, ctx, elementPath = []) {
|
|
|
5367
5458
|
html += ` ${propAttrName}`;
|
|
5368
5459
|
}
|
|
5369
5460
|
});
|
|
5370
|
-
if (
|
|
5461
|
+
if (dangerouslySetInnerHTMLExpr) {
|
|
5462
|
+
html += ">";
|
|
5463
|
+
parts.push({ type: "string", value: html });
|
|
5464
|
+
parts.push({ type: "expression", value: dangerouslySetInnerHTMLExpr });
|
|
5465
|
+
appendString(parts, `</${effectiveTag}>`);
|
|
5466
|
+
} else if (node.openingElement.selfClosing) {
|
|
5371
5467
|
if (isComp) {
|
|
5372
5468
|
parts.push({ type: "string", value: html + `></${effectiveTag}>` });
|
|
5373
5469
|
} else if (VOID_ELEMENTS.has(effectiveTag)) {
|
|
@@ -5472,7 +5568,11 @@ function processChildren(children, parts, ctx, elementPath, dcCursor, directChil
|
|
|
5472
5568
|
if (expressionMayBeFalsy(rawExpr)) {
|
|
5473
5569
|
expr = t10.logicalExpression("||", expr, t10.stringLiteral(""));
|
|
5474
5570
|
}
|
|
5475
|
-
|
|
5571
|
+
const skipEscape = childCallInfo || isChildrenPropAccess(rawExpr) || expressionContainsJSX(rawExpr) || ctx.inMapCallback;
|
|
5572
|
+
const safeExpr = skipEscape ? expr : t10.callExpression(t10.identifier("__escapeHtml"), [
|
|
5573
|
+
t10.callExpression(t10.identifier("String"), [expr])
|
|
5574
|
+
]);
|
|
5575
|
+
parts.push({ type: "expression", value: safeExpr });
|
|
5476
5576
|
}
|
|
5477
5577
|
}
|
|
5478
5578
|
});
|
|
@@ -5539,7 +5639,7 @@ import { appendToBody, id as id3, js as js2, jsMethod } from "eszter";
|
|
|
5539
5639
|
import { createRequire as createRequire6 } from "module";
|
|
5540
5640
|
var require7 = createRequire6(import.meta.url);
|
|
5541
5641
|
var traverse6 = require7("@babel/traverse").default;
|
|
5542
|
-
var
|
|
5642
|
+
var EVENT_NAMES2 = /* @__PURE__ */ new Set([
|
|
5543
5643
|
"click",
|
|
5544
5644
|
"dblclick",
|
|
5545
5645
|
"mousedown",
|
|
@@ -5623,7 +5723,7 @@ function buildDummyFromTree(tree, keyPathParts) {
|
|
|
5623
5723
|
t11.objectProperty(t11.identifier(key), buildDummyFromTree(value === true ? {} : value, keyPathParts.slice(1)))
|
|
5624
5724
|
);
|
|
5625
5725
|
} else if (value === true) {
|
|
5626
|
-
props.push(t11.objectProperty(t11.identifier(key), t11.stringLiteral("")));
|
|
5726
|
+
props.push(t11.objectProperty(t11.identifier(key), t11.stringLiteral(" ")));
|
|
5627
5727
|
} else {
|
|
5628
5728
|
props.push(t11.objectProperty(t11.identifier(key), buildDummyFromTree(value, null)));
|
|
5629
5729
|
}
|
|
@@ -5712,21 +5812,36 @@ function generatePatchItemMethod(arrayMap, templatePropNames, wholeParamName, te
|
|
|
5712
5812
|
for (const entry of patchedEntries) {
|
|
5713
5813
|
const navExpr = entry.childPath.length > 0 ? refMap.get(entry.childPath.join("_")) || buildElementNavExpr(elVar, entry.childPath) : elVar;
|
|
5714
5814
|
switch (entry.type) {
|
|
5715
|
-
case "className":
|
|
5815
|
+
case "className": {
|
|
5816
|
+
const classVal = t11.identifier("__cn");
|
|
5716
5817
|
body.push(
|
|
5717
|
-
t11.
|
|
5718
|
-
t11.
|
|
5719
|
-
|
|
5720
|
-
t11.memberExpression(navExpr, t11.identifier("className")),
|
|
5818
|
+
t11.variableDeclaration("var", [
|
|
5819
|
+
t11.variableDeclarator(
|
|
5820
|
+
classVal,
|
|
5721
5821
|
buildTrimmedClassValueExpression(t11.cloneNode(entry.expression, true))
|
|
5722
5822
|
)
|
|
5823
|
+
]),
|
|
5824
|
+
t11.ifStatement(
|
|
5825
|
+
t11.binaryExpression("!==", t11.memberExpression(navExpr, t11.identifier("className")), classVal),
|
|
5826
|
+
t11.expressionStatement(
|
|
5827
|
+
t11.assignmentExpression(
|
|
5828
|
+
"=",
|
|
5829
|
+
t11.memberExpression(t11.cloneNode(navExpr, true), t11.identifier("className")),
|
|
5830
|
+
classVal
|
|
5831
|
+
)
|
|
5832
|
+
)
|
|
5723
5833
|
)
|
|
5724
5834
|
);
|
|
5725
5835
|
break;
|
|
5836
|
+
}
|
|
5726
5837
|
case "text":
|
|
5727
5838
|
body.push(
|
|
5728
5839
|
t11.expressionStatement(
|
|
5729
|
-
t11.assignmentExpression(
|
|
5840
|
+
t11.assignmentExpression(
|
|
5841
|
+
"=",
|
|
5842
|
+
t11.memberExpression(t11.memberExpression(navExpr, t11.identifier("firstChild")), t11.identifier("nodeValue")),
|
|
5843
|
+
entry.expression
|
|
5844
|
+
)
|
|
5730
5845
|
)
|
|
5731
5846
|
);
|
|
5732
5847
|
break;
|
|
@@ -5803,12 +5918,27 @@ function generatePatchItemMethod(arrayMap, templatePropNames, wholeParamName, te
|
|
|
5803
5918
|
t11.stringLiteral(entry.attributeName)
|
|
5804
5919
|
])
|
|
5805
5920
|
),
|
|
5806
|
-
t11.
|
|
5807
|
-
t11.
|
|
5808
|
-
t11.
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5921
|
+
t11.blockStatement([
|
|
5922
|
+
t11.variableDeclaration("const", [
|
|
5923
|
+
t11.variableDeclarator(t11.identifier("__newAttr"), t11.callExpression(t11.identifier("String"), [attrVal]))
|
|
5924
|
+
]),
|
|
5925
|
+
t11.ifStatement(
|
|
5926
|
+
t11.binaryExpression(
|
|
5927
|
+
"!==",
|
|
5928
|
+
t11.callExpression(
|
|
5929
|
+
t11.memberExpression(t11.cloneNode(navExpr, true), t11.identifier("getAttribute")),
|
|
5930
|
+
[t11.stringLiteral(entry.attributeName)]
|
|
5931
|
+
),
|
|
5932
|
+
t11.identifier("__newAttr")
|
|
5933
|
+
),
|
|
5934
|
+
t11.expressionStatement(
|
|
5935
|
+
t11.callExpression(
|
|
5936
|
+
t11.memberExpression(t11.cloneNode(navExpr, true), t11.identifier("setAttribute")),
|
|
5937
|
+
[t11.stringLiteral(entry.attributeName), t11.identifier("__newAttr")]
|
|
5938
|
+
)
|
|
5939
|
+
)
|
|
5940
|
+
)
|
|
5941
|
+
])
|
|
5812
5942
|
)
|
|
5813
5943
|
);
|
|
5814
5944
|
}
|
|
@@ -5910,7 +6040,7 @@ function walkJSXForPatch(node, path, entries, rootIsComponent = false) {
|
|
|
5910
6040
|
for (const attr of node.openingElement.attributes) {
|
|
5911
6041
|
if (!t11.isJSXAttribute(attr) || !t11.isJSXIdentifier(attr.name)) continue;
|
|
5912
6042
|
const name = attr.name.name;
|
|
5913
|
-
if (name === "key" ||
|
|
6043
|
+
if (name === "key" || EVENT_NAMES2.has(name)) continue;
|
|
5914
6044
|
if (!t11.isJSXExpressionContainer(attr.value) || t11.isJSXEmptyExpression(attr.value.expression)) continue;
|
|
5915
6045
|
if (name === "class" || name === "className") {
|
|
5916
6046
|
entries.push({
|
|
@@ -6103,7 +6233,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
6103
6233
|
for (const attr of cloned.openingElement.attributes) {
|
|
6104
6234
|
if (!t11.isJSXAttribute(attr) || !t11.isJSXIdentifier(attr.name)) continue;
|
|
6105
6235
|
const propName = attr.name.name;
|
|
6106
|
-
if (propName === "key" ||
|
|
6236
|
+
if (propName === "key" || EVENT_NAMES2.has(propName)) continue;
|
|
6107
6237
|
if (!t11.isJSXExpressionContainer(attr.value) || t11.isJSXEmptyExpression(attr.value.expression)) continue;
|
|
6108
6238
|
const exprClone = t11.cloneNode(attr.value.expression, true);
|
|
6109
6239
|
const tempProg = t11.file(t11.program([t11.expressionStatement(exprClone)]));
|
|
@@ -6393,7 +6523,11 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
6393
6523
|
case "text":
|
|
6394
6524
|
body.push(
|
|
6395
6525
|
t11.expressionStatement(
|
|
6396
|
-
t11.assignmentExpression(
|
|
6526
|
+
t11.assignmentExpression(
|
|
6527
|
+
"=",
|
|
6528
|
+
t11.memberExpression(t11.memberExpression(navExpr, t11.identifier("firstChild")), t11.identifier("nodeValue")),
|
|
6529
|
+
entry.expression
|
|
6530
|
+
)
|
|
6397
6531
|
)
|
|
6398
6532
|
);
|
|
6399
6533
|
break;
|
|
@@ -6470,12 +6604,27 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
6470
6604
|
t11.stringLiteral(entry.attributeName)
|
|
6471
6605
|
])
|
|
6472
6606
|
),
|
|
6473
|
-
t11.
|
|
6474
|
-
t11.
|
|
6475
|
-
t11.
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6607
|
+
t11.blockStatement([
|
|
6608
|
+
t11.variableDeclaration("const", [
|
|
6609
|
+
t11.variableDeclarator(t11.identifier("__newAttr"), t11.callExpression(t11.identifier("String"), [attrVal]))
|
|
6610
|
+
]),
|
|
6611
|
+
t11.ifStatement(
|
|
6612
|
+
t11.binaryExpression(
|
|
6613
|
+
"!==",
|
|
6614
|
+
t11.callExpression(
|
|
6615
|
+
t11.memberExpression(t11.cloneNode(navExpr, true), t11.identifier("getAttribute")),
|
|
6616
|
+
[t11.stringLiteral(entry.attributeName)]
|
|
6617
|
+
),
|
|
6618
|
+
t11.identifier("__newAttr")
|
|
6619
|
+
),
|
|
6620
|
+
t11.expressionStatement(
|
|
6621
|
+
t11.callExpression(
|
|
6622
|
+
t11.memberExpression(t11.cloneNode(navExpr, true), t11.identifier("setAttribute")),
|
|
6623
|
+
[t11.stringLiteral(entry.attributeName), t11.identifier("__newAttr")]
|
|
6624
|
+
)
|
|
6625
|
+
)
|
|
6626
|
+
)
|
|
6627
|
+
])
|
|
6479
6628
|
)
|
|
6480
6629
|
);
|
|
6481
6630
|
}
|
|
@@ -6531,7 +6680,7 @@ function generateCreateItemMethod(arrayMap, templatePropNames, wholeParamName, t
|
|
|
6531
6680
|
for (const attr of cloned.openingElement.attributes) {
|
|
6532
6681
|
if (!t11.isJSXAttribute(attr) || !t11.isJSXIdentifier(attr.name)) continue;
|
|
6533
6682
|
const name = attr.name.name;
|
|
6534
|
-
if (name === "key" ||
|
|
6683
|
+
if (name === "key" || EVENT_NAMES2.has(name)) continue;
|
|
6535
6684
|
if (!t11.isJSXExpressionContainer(attr.value) || t11.isJSXEmptyExpression(attr.value.expression)) continue;
|
|
6536
6685
|
const exprClone = t11.cloneNode(attr.value.expression, true);
|
|
6537
6686
|
const tempProg = t11.file(t11.program([t11.expressionStatement(exprClone)]));
|
|
@@ -6609,38 +6758,6 @@ function branchContainsJSX(expr) {
|
|
|
6609
6758
|
}
|
|
6610
6759
|
|
|
6611
6760
|
// src/generate-clone.ts
|
|
6612
|
-
var EVENT_NAMES2 = /* @__PURE__ */ new Set([
|
|
6613
|
-
"click",
|
|
6614
|
-
"dblclick",
|
|
6615
|
-
"mousedown",
|
|
6616
|
-
"mouseup",
|
|
6617
|
-
"mouseover",
|
|
6618
|
-
"mouseout",
|
|
6619
|
-
"mousemove",
|
|
6620
|
-
"keydown",
|
|
6621
|
-
"keyup",
|
|
6622
|
-
"keypress",
|
|
6623
|
-
"focus",
|
|
6624
|
-
"blur",
|
|
6625
|
-
"input",
|
|
6626
|
-
"change",
|
|
6627
|
-
"submit",
|
|
6628
|
-
"scroll",
|
|
6629
|
-
"touchstart",
|
|
6630
|
-
"touchmove",
|
|
6631
|
-
"touchend",
|
|
6632
|
-
"tap",
|
|
6633
|
-
"longTap",
|
|
6634
|
-
"swipeRight",
|
|
6635
|
-
"swipeUp",
|
|
6636
|
-
"swipeLeft",
|
|
6637
|
-
"swipeDown",
|
|
6638
|
-
"dragstart",
|
|
6639
|
-
"dragend",
|
|
6640
|
-
"dragover",
|
|
6641
|
-
"dragleave",
|
|
6642
|
-
"drop"
|
|
6643
|
-
]);
|
|
6644
6761
|
var EVENT_TYPES2 = /* @__PURE__ */ new Set([
|
|
6645
6762
|
"click",
|
|
6646
6763
|
"dblclick",
|
|
@@ -6801,7 +6918,8 @@ function collectClonePatchEntries(node, path, entries, rootIsComponent = false)
|
|
|
6801
6918
|
for (const attr of node.openingElement.attributes) {
|
|
6802
6919
|
if (!t12.isJSXAttribute(attr) || !t12.isJSXIdentifier(attr.name)) continue;
|
|
6803
6920
|
const name = attr.name.name;
|
|
6804
|
-
if (name === "key" || name === "id" ||
|
|
6921
|
+
if (name === "key" || name === "id" || name === "ref" || EVENT_NAMES.has(name) || EVENT_NAMES.has(toGeaEventType(name)))
|
|
6922
|
+
continue;
|
|
6805
6923
|
if (!t12.isJSXExpressionContainer(attr.value) || t12.isJSXEmptyExpression(attr.value.expression)) continue;
|
|
6806
6924
|
if (name === "class" || name === "className") {
|
|
6807
6925
|
entries.push({
|
|
@@ -7385,30 +7503,7 @@ function getMapContextKey(ctx) {
|
|
|
7385
7503
|
}
|
|
7386
7504
|
function ensureMapItemHelper(classBody2, ctx, helperName) {
|
|
7387
7505
|
if (classBody2.body.some((m) => t13.isClassMethod(m) && t13.isIdentifier(m.key) && m.key.name === helperName)) return;
|
|
7388
|
-
const itemsExpr = (
|
|
7389
|
-
const [first] = ctx.arrayPathParts;
|
|
7390
|
-
const unresolvedMatch = first?.match(/^__unresolved_(\d+)$/);
|
|
7391
|
-
if (unresolvedMatch) {
|
|
7392
|
-
const mapIdx = Number(unresolvedMatch[1]);
|
|
7393
|
-
return t13.callExpression(
|
|
7394
|
-
t13.memberExpression(
|
|
7395
|
-
t13.memberExpression(
|
|
7396
|
-
t13.memberExpression(t13.thisExpression(), t13.identifier("__geaMaps")),
|
|
7397
|
-
t13.numericLiteral(mapIdx),
|
|
7398
|
-
true
|
|
7399
|
-
),
|
|
7400
|
-
t13.identifier("getItems")
|
|
7401
|
-
),
|
|
7402
|
-
[]
|
|
7403
|
-
);
|
|
7404
|
-
}
|
|
7405
|
-
const base = ctx.isImportedState ? t13.identifier(ctx.storeVar || "store") : t13.thisExpression();
|
|
7406
|
-
if (ctx.arrayPathParts.length === 0) return base;
|
|
7407
|
-
const [, ...rest] = ctx.arrayPathParts;
|
|
7408
|
-
const isIndex = /^\d+$/.test(first);
|
|
7409
|
-
const optionalFirst = ctx.isImportedState ? t13.memberExpression(base, isIndex ? t13.numericLiteral(Number(first)) : t13.identifier(first), isIndex) : t13.optionalMemberExpression(base, isIndex ? t13.numericLiteral(Number(first)) : t13.identifier(first), isIndex, true);
|
|
7410
|
-
return rest.length > 0 ? buildMemberChainFromParts(optionalFirst, rest) : optionalFirst;
|
|
7411
|
-
})();
|
|
7506
|
+
const itemsExpr = buildArrayItemsExpr(ctx);
|
|
7412
7507
|
const findPredicate = ctx.itemIdProperty && ctx.itemIdProperty !== ITEM_IS_KEY ? t13.arrowFunctionExpression(
|
|
7413
7508
|
[t13.identifier("__candidate")],
|
|
7414
7509
|
t13.binaryExpression(
|
|
@@ -7437,17 +7532,19 @@ function ensureMapItemHelper(classBody2, ctx, helperName) {
|
|
|
7437
7532
|
t13.identifier("__itemId")
|
|
7438
7533
|
)
|
|
7439
7534
|
);
|
|
7440
|
-
const method = jsMethod2`${id4(helperName)}(e) {
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7535
|
+
const method = jsMethod2`${id4(helperName)}(e) {}`;
|
|
7536
|
+
method.body.body.push(
|
|
7537
|
+
...buildGeaItemDomWalk(),
|
|
7538
|
+
...jsBlockBody`
|
|
7539
|
+
if (!__el) return null;
|
|
7540
|
+
if (__el.__geaItem) return __el.__geaItem;
|
|
7541
|
+
const __itemId = __el.__geaKey ?? (__el.getAttribute && __el.getAttribute('data-gea-item-id'));
|
|
7542
|
+
if (__itemId == null) return null;
|
|
7543
|
+
const __items = ${itemsExpr};
|
|
7544
|
+
const __arr = Array.isArray(__items) ? __items : Array.isArray(__items?.__getTarget) ? __items.__getTarget : [];
|
|
7545
|
+
return __arr.find(${findPredicate}) || __itemId;
|
|
7546
|
+
`
|
|
7547
|
+
);
|
|
7451
7548
|
classBody2.body.unshift(method);
|
|
7452
7549
|
}
|
|
7453
7550
|
function getLocalFunctionInSetup(name, setupStatements) {
|
|
@@ -7730,6 +7827,36 @@ function referencesIdentifier(nodes, name) {
|
|
|
7730
7827
|
}
|
|
7731
7828
|
return nodes.some(walk);
|
|
7732
7829
|
}
|
|
7830
|
+
function buildArrayItemsExpr(ctx, opts = {}) {
|
|
7831
|
+
const [first] = ctx.arrayPathParts;
|
|
7832
|
+
const unresolvedMatch = first?.match(/^__unresolved_(\d+)$/);
|
|
7833
|
+
if (unresolvedMatch) {
|
|
7834
|
+
const mapIdx = Number(unresolvedMatch[1]);
|
|
7835
|
+
return t13.callExpression(
|
|
7836
|
+
t13.memberExpression(
|
|
7837
|
+
t13.memberExpression(
|
|
7838
|
+
t13.memberExpression(t13.thisExpression(), t13.identifier("__geaMaps")),
|
|
7839
|
+
t13.numericLiteral(mapIdx),
|
|
7840
|
+
true
|
|
7841
|
+
),
|
|
7842
|
+
t13.identifier("getItems")
|
|
7843
|
+
),
|
|
7844
|
+
[]
|
|
7845
|
+
);
|
|
7846
|
+
}
|
|
7847
|
+
const base = ctx.isImportedState ? opts.raw ? t13.memberExpression(t13.identifier(ctx.storeVar || "store"), t13.identifier("__raw")) : t13.identifier(ctx.storeVar || "store") : t13.thisExpression();
|
|
7848
|
+
if (ctx.arrayPathParts.length === 0) return base;
|
|
7849
|
+
const [, ...rest] = ctx.arrayPathParts;
|
|
7850
|
+
const isIndex = /^\d+$/.test(first);
|
|
7851
|
+
const firstAccess = ctx.isImportedState ? t13.memberExpression(base, isIndex ? t13.numericLiteral(Number(first)) : t13.identifier(first), isIndex) : t13.optionalMemberExpression(base, isIndex ? t13.numericLiteral(Number(first)) : t13.identifier(first), isIndex, true);
|
|
7852
|
+
return rest.length > 0 ? buildMemberChainFromParts(firstAccess, rest) : firstAccess;
|
|
7853
|
+
}
|
|
7854
|
+
function buildGeaItemDomWalk() {
|
|
7855
|
+
return jsBlockBody`
|
|
7856
|
+
var __el = e.target;
|
|
7857
|
+
while (__el && __el.__geaKey == null && (!__el.getAttribute || !__el.getAttribute('data-gea-item-id'))) __el = __el.parentElement;
|
|
7858
|
+
`;
|
|
7859
|
+
}
|
|
7733
7860
|
function buildMapEventBody(handler, paramContext) {
|
|
7734
7861
|
const ctx = handler.mapContext;
|
|
7735
7862
|
const itemVar = ctx.itemVariable || "item";
|
|
@@ -7738,16 +7865,29 @@ function buildMapEventBody(handler, paramContext) {
|
|
|
7738
7865
|
extractHandlerBody(handler.handlerExpression, paramContext.propNames),
|
|
7739
7866
|
paramContext
|
|
7740
7867
|
);
|
|
7868
|
+
const needsItem = referencesIdentifier(handlerBody, itemVar);
|
|
7869
|
+
const needsIndex = !!(ctx.indexVariable && referencesIdentifier(handlerBody, ctx.indexVariable));
|
|
7870
|
+
if (needsIndex && !needsItem) {
|
|
7871
|
+
const rawArrayExpr = buildArrayItemsExpr(ctx, { raw: true });
|
|
7872
|
+
const preamble2 = [
|
|
7873
|
+
...buildGeaItemDomWalk(),
|
|
7874
|
+
...jsBlockBody`
|
|
7875
|
+
if (!__el || !__el.__geaItem) return;
|
|
7876
|
+
const ${id4(ctx.indexVariable)} = ${rawArrayExpr}.indexOf(__el.__geaItem);
|
|
7877
|
+
`
|
|
7878
|
+
];
|
|
7879
|
+
return [...preamble2, ...handlerBody];
|
|
7880
|
+
}
|
|
7741
7881
|
const preamble = jsBlockBody`
|
|
7742
7882
|
const ${id4(itemVar)} = this.${id4(helperName)}(e);
|
|
7743
7883
|
if (!${id4(itemVar)}) { return; }
|
|
7744
7884
|
`;
|
|
7745
|
-
if (
|
|
7885
|
+
if (needsIndex) {
|
|
7886
|
+
const rawArrayExpr = buildArrayItemsExpr(ctx, { raw: true });
|
|
7746
7887
|
preamble.push(
|
|
7888
|
+
...buildGeaItemDomWalk(),
|
|
7747
7889
|
...jsBlockBody`
|
|
7748
|
-
|
|
7749
|
-
while (__el && __el.__geaKey == null && (!__el.getAttribute || !__el.getAttribute('data-gea-item-id'))) __el = __el.parentElement;
|
|
7750
|
-
const ${id4(ctx.indexVariable)} = __el ? Array.prototype.indexOf.call(__el.parentNode.children, __el) : -1;
|
|
7890
|
+
const ${id4(ctx.indexVariable)} = __el ? ${rawArrayExpr}.indexOf(__el.__geaItem) : -1;
|
|
7751
7891
|
`
|
|
7752
7892
|
);
|
|
7753
7893
|
}
|
|
@@ -7809,7 +7949,7 @@ function getDirectPropMappings(child, templatePropNames) {
|
|
|
7809
7949
|
}
|
|
7810
7950
|
return mappings.length > 0 ? mappings : null;
|
|
7811
7951
|
}
|
|
7812
|
-
function injectChildComponents(ast, componentInstances, directForwardingChildren) {
|
|
7952
|
+
function injectChildComponents(ast, componentInstances, directForwardingChildren, className) {
|
|
7813
7953
|
if (componentInstances.size === 0) return;
|
|
7814
7954
|
const childComponents = Array.from(componentInstances.values()).flat();
|
|
7815
7955
|
const constructionOrder = [...childComponents].sort((a, b) => (b.dfsIndex ?? 0) - (a.dfsIndex ?? 0));
|
|
@@ -7819,6 +7959,7 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
|
|
|
7819
7959
|
traverse7(ast, {
|
|
7820
7960
|
ClassDeclaration(path) {
|
|
7821
7961
|
if (!t14.isIdentifier(path.node.superClass)) return;
|
|
7962
|
+
if (className && (!t14.isIdentifier(path.node.id) || path.node.id.name !== className)) return;
|
|
7822
7963
|
const existingCtor = path.node.body.body.find(
|
|
7823
7964
|
(m) => t14.isClassMethod(m) && t14.isIdentifier(m.key) && m.key.name === "constructor"
|
|
7824
7965
|
);
|
|
@@ -7894,10 +8035,14 @@ function injectChildComponents(ast, componentInstances, directForwardingChildren
|
|
|
7894
8035
|
}
|
|
7895
8036
|
});
|
|
7896
8037
|
}
|
|
7897
|
-
function injectComponentRegistrations(ast, componentInstances) {
|
|
8038
|
+
function injectComponentRegistrations(ast, componentInstances, className) {
|
|
7898
8039
|
traverse7(ast, {
|
|
7899
8040
|
ClassMethod(path) {
|
|
7900
8041
|
if (!t14.isIdentifier(path.node.key) || path.node.key.name !== "template") return;
|
|
8042
|
+
if (className) {
|
|
8043
|
+
const ownerClass = path.findParent((p) => t14.isClassDeclaration(p.node));
|
|
8044
|
+
if (ownerClass && t14.isIdentifier(ownerClass.node.id) && ownerClass.node.id.name !== className) return;
|
|
8045
|
+
}
|
|
7901
8046
|
const registrations = Array.from(componentInstances.keys()).map(
|
|
7902
8047
|
(tagName) => t14.expressionStatement(
|
|
7903
8048
|
t14.callExpression(t14.memberExpression(t14.identifier("Component"), t14.identifier("_register")), [
|
|
@@ -8159,7 +8304,7 @@ function buildSimpleUpdate(binding, param, stateRefs) {
|
|
|
8159
8304
|
}
|
|
8160
8305
|
if (binding.textNodeIndex !== void 0 && binding.type === "text") {
|
|
8161
8306
|
const idx = t15.numericLiteral(binding.textNodeIndex);
|
|
8162
|
-
return js3`if (${el}) {
|
|
8307
|
+
return js3`if (${el}) { let __tn = ${jsExpr2`${el}.childNodes[${idx}]`}; if (!__tn || __tn.nodeType !== 3) { __tn = document.createTextNode(${valueExpr}); ${jsExpr2`${el}.insertBefore(__tn, ${el}.childNodes[${idx}] || null)`}; } else if (__tn.nodeValue !== ${valueExpr}) { __tn.nodeValue = ${valueExpr}; } }`;
|
|
8163
8308
|
}
|
|
8164
8309
|
if (target === "textContent" && binding.bindingId && binding.bindingId !== "" && !binding.userIdExpr) {
|
|
8165
8310
|
const suffix = t15.stringLiteral(binding.bindingId);
|
|
@@ -8302,6 +8447,7 @@ function mergeObserveHandlers(bindings, stateRefs) {
|
|
|
8302
8447
|
import * as t17 from "@babel/types";
|
|
8303
8448
|
import { appendToBody as appendToBody3, id as id8, js as js4, jsBlockBody as jsBlockBody3, jsExpr as jsExpr3, jsMethod as jsMethod5 } from "eszter";
|
|
8304
8449
|
import { createRequire as createRequire9 } from "module";
|
|
8450
|
+
var URL_ATTRS2 = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "data", "cite", "poster", "background"]);
|
|
8305
8451
|
var require10 = createRequire9(import.meta.url);
|
|
8306
8452
|
var traverse9 = require10("@babel/traverse").default;
|
|
8307
8453
|
function getArrayPathParts(arrayMap) {
|
|
@@ -8414,12 +8560,32 @@ function buildPropPatcherFunction(binding, propName) {
|
|
|
8414
8560
|
t17.callExpression(t17.identifier("String"), [t17.identifier("__attrValue")])
|
|
8415
8561
|
)
|
|
8416
8562
|
)
|
|
8417
|
-
) : t17.
|
|
8418
|
-
t17.
|
|
8419
|
-
t17.
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8563
|
+
) : t17.blockStatement([
|
|
8564
|
+
t17.variableDeclaration("const", [
|
|
8565
|
+
t17.variableDeclarator(
|
|
8566
|
+
t17.identifier("__newAttr"),
|
|
8567
|
+
URL_ATTRS2.has(attrName) ? t17.callExpression(t17.identifier("__sanitizeAttr"), [
|
|
8568
|
+
t17.stringLiteral(attrName),
|
|
8569
|
+
t17.callExpression(t17.identifier("String"), [t17.identifier("__attrValue")])
|
|
8570
|
+
]) : t17.callExpression(t17.identifier("String"), [t17.identifier("__attrValue")])
|
|
8571
|
+
)
|
|
8572
|
+
]),
|
|
8573
|
+
t17.ifStatement(
|
|
8574
|
+
t17.binaryExpression(
|
|
8575
|
+
"!==",
|
|
8576
|
+
t17.callExpression(t17.memberExpression(t17.cloneNode(target, true), t17.identifier("getAttribute")), [
|
|
8577
|
+
t17.stringLiteral(attrName)
|
|
8578
|
+
]),
|
|
8579
|
+
t17.identifier("__newAttr")
|
|
8580
|
+
),
|
|
8581
|
+
t17.expressionStatement(
|
|
8582
|
+
t17.callExpression(t17.memberExpression(t17.cloneNode(target, true), t17.identifier("setAttribute")), [
|
|
8583
|
+
t17.stringLiteral(attrName),
|
|
8584
|
+
t17.identifier("__newAttr")
|
|
8585
|
+
])
|
|
8586
|
+
)
|
|
8587
|
+
)
|
|
8588
|
+
]);
|
|
8423
8589
|
return t17.arrowFunctionExpression(
|
|
8424
8590
|
[row, value],
|
|
8425
8591
|
t17.blockStatement([
|
|
@@ -8561,12 +8727,29 @@ function buildPatchEntryPropPatcher(entry) {
|
|
|
8561
8727
|
t17.callExpression(t17.identifier("String"), [t17.identifier("__attrValue")])
|
|
8562
8728
|
)
|
|
8563
8729
|
)
|
|
8564
|
-
) : t17.
|
|
8565
|
-
t17.
|
|
8566
|
-
t17.
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8730
|
+
) : t17.blockStatement([
|
|
8731
|
+
t17.variableDeclaration("const", [
|
|
8732
|
+
t17.variableDeclarator(
|
|
8733
|
+
t17.identifier("__newAttr"),
|
|
8734
|
+
t17.callExpression(t17.identifier("String"), [t17.identifier("__attrValue")])
|
|
8735
|
+
)
|
|
8736
|
+
]),
|
|
8737
|
+
t17.ifStatement(
|
|
8738
|
+
t17.binaryExpression(
|
|
8739
|
+
"!==",
|
|
8740
|
+
t17.callExpression(t17.memberExpression(t17.cloneNode(target, true), t17.identifier("getAttribute")), [
|
|
8741
|
+
t17.stringLiteral(attrName)
|
|
8742
|
+
]),
|
|
8743
|
+
t17.identifier("__newAttr")
|
|
8744
|
+
),
|
|
8745
|
+
t17.expressionStatement(
|
|
8746
|
+
t17.callExpression(t17.memberExpression(t17.cloneNode(target, true), t17.identifier("setAttribute")), [
|
|
8747
|
+
t17.stringLiteral(attrName),
|
|
8748
|
+
t17.identifier("__newAttr")
|
|
8749
|
+
])
|
|
8750
|
+
)
|
|
8751
|
+
)
|
|
8752
|
+
]);
|
|
8570
8753
|
return t17.arrowFunctionExpression(
|
|
8571
8754
|
[row, value, item],
|
|
8572
8755
|
t17.blockStatement([
|
|
@@ -9025,7 +9208,10 @@ function buildConditionalPatchStatement(binding, target, itemVariable) {
|
|
|
9025
9208
|
if (__attrValue == null || __attrValue === false) {
|
|
9026
9209
|
${jsExpr3`${target}.removeAttribute(${binding.attributeName || "class"})`};
|
|
9027
9210
|
} else {
|
|
9028
|
-
|
|
9211
|
+
const __newAttr = String(__attrValue);
|
|
9212
|
+
if (${jsExpr3`${target}.getAttribute(${binding.attributeName || "class"})`} !== __newAttr) {
|
|
9213
|
+
${jsExpr3`${target}.setAttribute(${binding.attributeName || "class"}, __newAttr)`};
|
|
9214
|
+
}
|
|
9029
9215
|
}
|
|
9030
9216
|
`
|
|
9031
9217
|
);
|
|
@@ -9753,6 +9939,7 @@ function generateComponentArrayResult(um, arrayPropName, imports, propNames, _cl
|
|
|
9753
9939
|
// src/apply-reactivity.ts
|
|
9754
9940
|
import { createRequire as createRequire12 } from "module";
|
|
9755
9941
|
var generate2 = "default" in babelGenerator ? babelGenerator.default : babelGenerator;
|
|
9942
|
+
var URL_ATTRS3 = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "data", "cite", "poster", "background"]);
|
|
9756
9943
|
var require13 = createRequire12(import.meta.url);
|
|
9757
9944
|
var traverse12 = require13("@babel/traverse").default;
|
|
9758
9945
|
var BOOLEAN_HTML_ATTRS = /* @__PURE__ */ new Set([
|
|
@@ -10198,31 +10385,63 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
10198
10385
|
const valueExpr = pb.expression && pb.setupStatements ? t20.identifier("__boundValue") : t20.identifier("value");
|
|
10199
10386
|
let updateStmt;
|
|
10200
10387
|
if (pb.type === "text" && pb.textNodeIndex !== void 0) {
|
|
10388
|
+
const tnIdx = t20.numericLiteral(pb.textNodeIndex);
|
|
10201
10389
|
const tnAccess = t20.memberExpression(
|
|
10202
10390
|
t20.memberExpression(t20.identifier("__el"), t20.identifier("childNodes")),
|
|
10203
|
-
t20.
|
|
10391
|
+
t20.cloneNode(tnIdx, true),
|
|
10204
10392
|
true
|
|
10205
10393
|
);
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
t20.
|
|
10209
|
-
|
|
10210
|
-
|
|
10394
|
+
const notTextNode = t20.logicalExpression(
|
|
10395
|
+
"||",
|
|
10396
|
+
t20.unaryExpression("!", t20.identifier("__tn")),
|
|
10397
|
+
t20.binaryExpression(
|
|
10398
|
+
"!==",
|
|
10399
|
+
t20.memberExpression(t20.identifier("__tn"), t20.identifier("nodeType")),
|
|
10400
|
+
t20.numericLiteral(3)
|
|
10401
|
+
)
|
|
10402
|
+
);
|
|
10403
|
+
const insertNewTextNode = t20.blockStatement([
|
|
10404
|
+
t20.expressionStatement(
|
|
10405
|
+
t20.assignmentExpression(
|
|
10406
|
+
"=",
|
|
10211
10407
|
t20.identifier("__tn"),
|
|
10212
|
-
t20.
|
|
10213
|
-
"!==",
|
|
10214
|
-
t20.memberExpression(t20.identifier("__tn"), t20.identifier("nodeValue")),
|
|
10215
|
-
valueExpr
|
|
10216
|
-
)
|
|
10217
|
-
),
|
|
10218
|
-
t20.expressionStatement(
|
|
10219
|
-
t20.assignmentExpression(
|
|
10220
|
-
"=",
|
|
10221
|
-
t20.memberExpression(t20.identifier("__tn"), t20.identifier("nodeValue")),
|
|
10408
|
+
t20.callExpression(t20.memberExpression(t20.identifier("document"), t20.identifier("createTextNode")), [
|
|
10222
10409
|
t20.cloneNode(valueExpr, true)
|
|
10410
|
+
])
|
|
10411
|
+
)
|
|
10412
|
+
),
|
|
10413
|
+
t20.expressionStatement(
|
|
10414
|
+
t20.callExpression(t20.memberExpression(t20.identifier("__el"), t20.identifier("insertBefore")), [
|
|
10415
|
+
t20.identifier("__tn"),
|
|
10416
|
+
t20.logicalExpression(
|
|
10417
|
+
"||",
|
|
10418
|
+
t20.memberExpression(
|
|
10419
|
+
t20.memberExpression(t20.identifier("__el"), t20.identifier("childNodes")),
|
|
10420
|
+
t20.cloneNode(tnIdx, true),
|
|
10421
|
+
true
|
|
10422
|
+
),
|
|
10423
|
+
t20.nullLiteral()
|
|
10223
10424
|
)
|
|
10425
|
+
])
|
|
10426
|
+
)
|
|
10427
|
+
]);
|
|
10428
|
+
const updateExisting = t20.ifStatement(
|
|
10429
|
+
t20.binaryExpression(
|
|
10430
|
+
"!==",
|
|
10431
|
+
t20.memberExpression(t20.identifier("__tn"), t20.identifier("nodeValue")),
|
|
10432
|
+
t20.cloneNode(valueExpr, true)
|
|
10433
|
+
),
|
|
10434
|
+
t20.expressionStatement(
|
|
10435
|
+
t20.assignmentExpression(
|
|
10436
|
+
"=",
|
|
10437
|
+
t20.memberExpression(t20.identifier("__tn"), t20.identifier("nodeValue")),
|
|
10438
|
+
t20.cloneNode(valueExpr, true)
|
|
10224
10439
|
)
|
|
10225
10440
|
)
|
|
10441
|
+
);
|
|
10442
|
+
updateStmt = t20.blockStatement([
|
|
10443
|
+
t20.variableDeclaration("let", [t20.variableDeclarator(t20.identifier("__tn"), tnAccess)]),
|
|
10444
|
+
t20.ifStatement(notTextNode, insertNewTextNode, updateExisting)
|
|
10226
10445
|
]);
|
|
10227
10446
|
} else if (pb.type === "text") {
|
|
10228
10447
|
const targetProp = pb.propName === "children" ? "innerHTML" : "textContent";
|
|
@@ -10352,6 +10571,41 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
10352
10571
|
} else if (pb.type === "attribute" && pb.attributeName) {
|
|
10353
10572
|
const attrName = pb.attributeName;
|
|
10354
10573
|
if (attrName === "style") {
|
|
10574
|
+
const cssTextExpr = t20.conditionalExpression(
|
|
10575
|
+
t20.binaryExpression("===", t20.unaryExpression("typeof", valueExpr), t20.stringLiteral("object")),
|
|
10576
|
+
t20.callExpression(
|
|
10577
|
+
t20.memberExpression(
|
|
10578
|
+
t20.callExpression(
|
|
10579
|
+
t20.memberExpression(
|
|
10580
|
+
t20.callExpression(t20.memberExpression(t20.identifier("Object"), t20.identifier("entries")), [
|
|
10581
|
+
valueExpr
|
|
10582
|
+
]),
|
|
10583
|
+
t20.identifier("map")
|
|
10584
|
+
),
|
|
10585
|
+
[
|
|
10586
|
+
t20.arrowFunctionExpression(
|
|
10587
|
+
[t20.arrayPattern([t20.identifier("k"), t20.identifier("v")])],
|
|
10588
|
+
t20.binaryExpression(
|
|
10589
|
+
"+",
|
|
10590
|
+
t20.binaryExpression(
|
|
10591
|
+
"+",
|
|
10592
|
+
t20.callExpression(t20.memberExpression(t20.identifier("k"), t20.identifier("replace")), [
|
|
10593
|
+
t20.regExpLiteral("[A-Z]", "g"),
|
|
10594
|
+
t20.stringLiteral("-$&")
|
|
10595
|
+
]),
|
|
10596
|
+
t20.stringLiteral(": ")
|
|
10597
|
+
),
|
|
10598
|
+
t20.identifier("v")
|
|
10599
|
+
)
|
|
10600
|
+
)
|
|
10601
|
+
]
|
|
10602
|
+
),
|
|
10603
|
+
t20.identifier("join")
|
|
10604
|
+
),
|
|
10605
|
+
[t20.stringLiteral("; ")]
|
|
10606
|
+
),
|
|
10607
|
+
t20.callExpression(t20.identifier("String"), [valueExpr])
|
|
10608
|
+
);
|
|
10355
10609
|
updateStmt = t20.ifStatement(
|
|
10356
10610
|
t20.logicalExpression(
|
|
10357
10611
|
"||",
|
|
@@ -10363,51 +10617,53 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
10363
10617
|
t20.stringLiteral("style")
|
|
10364
10618
|
])
|
|
10365
10619
|
),
|
|
10366
|
-
t20.
|
|
10367
|
-
t20.
|
|
10368
|
-
|
|
10369
|
-
t20.
|
|
10370
|
-
|
|
10371
|
-
t20.
|
|
10620
|
+
t20.blockStatement([
|
|
10621
|
+
t20.variableDeclaration("const", [t20.variableDeclarator(t20.identifier("__newCss"), cssTextExpr)]),
|
|
10622
|
+
t20.ifStatement(
|
|
10623
|
+
t20.binaryExpression(
|
|
10624
|
+
"!==",
|
|
10625
|
+
t20.memberExpression(
|
|
10626
|
+
t20.memberExpression(t20.identifier("__el"), t20.identifier("style")),
|
|
10627
|
+
t20.identifier("cssText")
|
|
10628
|
+
),
|
|
10629
|
+
t20.identifier("__newCss")
|
|
10372
10630
|
),
|
|
10373
|
-
t20.
|
|
10374
|
-
t20.
|
|
10375
|
-
|
|
10631
|
+
t20.expressionStatement(
|
|
10632
|
+
t20.assignmentExpression(
|
|
10633
|
+
"=",
|
|
10376
10634
|
t20.memberExpression(
|
|
10377
|
-
t20.
|
|
10378
|
-
|
|
10379
|
-
t20.callExpression(t20.memberExpression(t20.identifier("Object"), t20.identifier("entries")), [
|
|
10380
|
-
valueExpr
|
|
10381
|
-
]),
|
|
10382
|
-
t20.identifier("map")
|
|
10383
|
-
),
|
|
10384
|
-
[
|
|
10385
|
-
t20.arrowFunctionExpression(
|
|
10386
|
-
[t20.arrayPattern([t20.identifier("k"), t20.identifier("v")])],
|
|
10387
|
-
t20.binaryExpression(
|
|
10388
|
-
"+",
|
|
10389
|
-
t20.binaryExpression(
|
|
10390
|
-
"+",
|
|
10391
|
-
t20.callExpression(t20.memberExpression(t20.identifier("k"), t20.identifier("replace")), [
|
|
10392
|
-
t20.regExpLiteral("[A-Z]", "g"),
|
|
10393
|
-
t20.stringLiteral("-$&")
|
|
10394
|
-
]),
|
|
10395
|
-
t20.stringLiteral(": ")
|
|
10396
|
-
),
|
|
10397
|
-
t20.identifier("v")
|
|
10398
|
-
)
|
|
10399
|
-
)
|
|
10400
|
-
]
|
|
10401
|
-
),
|
|
10402
|
-
t20.identifier("join")
|
|
10635
|
+
t20.memberExpression(t20.identifier("__el"), t20.identifier("style")),
|
|
10636
|
+
t20.identifier("cssText")
|
|
10403
10637
|
),
|
|
10404
|
-
|
|
10405
|
-
)
|
|
10406
|
-
t20.callExpression(t20.identifier("String"), [valueExpr])
|
|
10638
|
+
t20.identifier("__newCss")
|
|
10639
|
+
)
|
|
10407
10640
|
)
|
|
10408
10641
|
)
|
|
10409
|
-
)
|
|
10642
|
+
])
|
|
10410
10643
|
);
|
|
10644
|
+
} else if (attrName === "dangerouslySetInnerHTML") {
|
|
10645
|
+
updateStmt = t20.blockStatement([
|
|
10646
|
+
t20.variableDeclaration("const", [
|
|
10647
|
+
t20.variableDeclarator(
|
|
10648
|
+
t20.identifier("__newHtml"),
|
|
10649
|
+
t20.callExpression(t20.identifier("String"), [valueExpr])
|
|
10650
|
+
)
|
|
10651
|
+
]),
|
|
10652
|
+
t20.ifStatement(
|
|
10653
|
+
t20.binaryExpression(
|
|
10654
|
+
"!==",
|
|
10655
|
+
t20.memberExpression(t20.identifier("__el"), t20.identifier("innerHTML")),
|
|
10656
|
+
t20.identifier("__newHtml")
|
|
10657
|
+
),
|
|
10658
|
+
t20.expressionStatement(
|
|
10659
|
+
t20.assignmentExpression(
|
|
10660
|
+
"=",
|
|
10661
|
+
t20.memberExpression(t20.identifier("__el"), t20.identifier("innerHTML")),
|
|
10662
|
+
t20.identifier("__newHtml")
|
|
10663
|
+
)
|
|
10664
|
+
)
|
|
10665
|
+
)
|
|
10666
|
+
]);
|
|
10411
10667
|
} else {
|
|
10412
10668
|
const isBooleanAttr = BOOLEAN_HTML_ATTRS.has(attrName);
|
|
10413
10669
|
const removeCondition = isBooleanAttr ? t20.unaryExpression("!", valueExpr) : t20.logicalExpression(
|
|
@@ -10415,6 +10671,10 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
10415
10671
|
t20.binaryExpression("===", valueExpr, t20.nullLiteral()),
|
|
10416
10672
|
t20.binaryExpression("===", valueExpr, t20.identifier("undefined"))
|
|
10417
10673
|
);
|
|
10674
|
+
const newAttrValueExpr = isBooleanAttr ? t20.stringLiteral("") : URL_ATTRS3.has(attrName) ? t20.callExpression(t20.identifier("__sanitizeAttr"), [
|
|
10675
|
+
t20.stringLiteral(attrName),
|
|
10676
|
+
t20.callExpression(t20.identifier("String"), [valueExpr])
|
|
10677
|
+
]) : t20.callExpression(t20.identifier("String"), [valueExpr]);
|
|
10418
10678
|
updateStmt = t20.ifStatement(
|
|
10419
10679
|
removeCondition,
|
|
10420
10680
|
t20.expressionStatement(
|
|
@@ -10422,12 +10682,24 @@ function applyStaticReactivity(ast, originalAST, className, sourceFile, imports,
|
|
|
10422
10682
|
t20.stringLiteral(attrName)
|
|
10423
10683
|
])
|
|
10424
10684
|
),
|
|
10425
|
-
t20.
|
|
10426
|
-
t20.
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10685
|
+
t20.blockStatement([
|
|
10686
|
+
t20.variableDeclaration("const", [t20.variableDeclarator(t20.identifier("__newAttr"), newAttrValueExpr)]),
|
|
10687
|
+
t20.ifStatement(
|
|
10688
|
+
t20.binaryExpression(
|
|
10689
|
+
"!==",
|
|
10690
|
+
t20.callExpression(t20.memberExpression(t20.identifier("__el"), t20.identifier("getAttribute")), [
|
|
10691
|
+
t20.stringLiteral(attrName)
|
|
10692
|
+
]),
|
|
10693
|
+
t20.identifier("__newAttr")
|
|
10694
|
+
),
|
|
10695
|
+
t20.expressionStatement(
|
|
10696
|
+
t20.callExpression(t20.memberExpression(t20.identifier("__el"), t20.identifier("setAttribute")), [
|
|
10697
|
+
t20.stringLiteral(attrName),
|
|
10698
|
+
t20.identifier("__newAttr")
|
|
10699
|
+
])
|
|
10700
|
+
)
|
|
10701
|
+
)
|
|
10702
|
+
])
|
|
10431
10703
|
);
|
|
10432
10704
|
}
|
|
10433
10705
|
} else {
|
|
@@ -13852,13 +14124,13 @@ function transformComponentFile(ast, imports, storeImports, className, sourceFil
|
|
|
13852
14124
|
child.guardSetupStatements = guardSetupStatements;
|
|
13853
14125
|
}
|
|
13854
14126
|
}
|
|
13855
|
-
injectChildComponents(ast, componentInstances, directForwardingSet);
|
|
14127
|
+
injectChildComponents(ast, componentInstances, directForwardingSet, className);
|
|
13856
14128
|
compiledChildren.push(...allChildren);
|
|
13857
14129
|
transformed = true;
|
|
13858
14130
|
}
|
|
13859
14131
|
if (allComponentInstances.size > 0) {
|
|
13860
14132
|
ensureComponentImport(ast, imports);
|
|
13861
|
-
injectComponentRegistrations(ast, allComponentInstances);
|
|
14133
|
+
injectComponentRegistrations(ast, allComponentInstances, className);
|
|
13862
14134
|
transformed = true;
|
|
13863
14135
|
}
|
|
13864
14136
|
if (transformed) {
|
|
@@ -14615,6 +14887,9 @@ ${entries.join(",\n")}
|
|
|
14615
14887
|
if (hasJSX) {
|
|
14616
14888
|
const originalAST = parseSource(code).ast;
|
|
14617
14889
|
if (componentClassNames.length > 0) {
|
|
14890
|
+
for (const cn of componentClassNames) {
|
|
14891
|
+
if (!imports.has(cn)) imports.set(cn, cleanId);
|
|
14892
|
+
}
|
|
14618
14893
|
for (const cn of componentClassNames) {
|
|
14619
14894
|
const result = transformComponentFile(
|
|
14620
14895
|
ast,
|
|
@@ -14668,6 +14943,8 @@ ${entries.join(",\n")}
|
|
|
14668
14943
|
if (hmrAdded) transformed = true;
|
|
14669
14944
|
}
|
|
14670
14945
|
if (!transformed) return null;
|
|
14946
|
+
ensureImport(ast, "@geajs/core", "__escapeHtml");
|
|
14947
|
+
ensureImport(ast, "@geajs/core", "__sanitizeAttr");
|
|
14671
14948
|
const output = generate3(ast, { sourceMaps: true, sourceFileName: cleanId }, code);
|
|
14672
14949
|
return { code: output.code, map: output.map };
|
|
14673
14950
|
} catch (error) {
|