chocola 1.4.1 → 1.4.2
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.
|
@@ -94,7 +94,8 @@ export function processComponentElement(
|
|
|
94
94
|
cssScopes,
|
|
95
95
|
cssScopesMap,
|
|
96
96
|
scopedStyles,
|
|
97
|
-
renderChain = []
|
|
97
|
+
renderChain = [],
|
|
98
|
+
staticCtxRegistry
|
|
98
99
|
) {
|
|
99
100
|
const tagName = element.tagName.toLowerCase();
|
|
100
101
|
const compName = tagName + ".js";
|
|
@@ -103,7 +104,13 @@ export function processComponentElement(
|
|
|
103
104
|
if (!instance || instance === undefined) return false;
|
|
104
105
|
if (renderChain && renderChain.includes(compName)) return false;
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
let ctx;
|
|
108
|
+
if (staticCtxRegistry && staticCtxRegistry.has(element)) {
|
|
109
|
+
ctx = staticCtxRegistry.get(element);
|
|
110
|
+
} else {
|
|
111
|
+
ctx = extractContextFromElement(element);
|
|
112
|
+
staticCtxRegistry && staticCtxRegistry.set(element, ctx);
|
|
113
|
+
}
|
|
107
114
|
const srcInnerHtml = element.innerHTML;
|
|
108
115
|
|
|
109
116
|
const ctxProxy = new Proxy(ctx, {
|
|
@@ -131,7 +138,13 @@ export function processComponentElement(
|
|
|
131
138
|
if (reservedAttrs.includes(attribute.name)) return;
|
|
132
139
|
attribute.value = attribute.value.replace(
|
|
133
140
|
/\{([^}]+)\}/g,
|
|
134
|
-
(_,
|
|
141
|
+
(_, expr) => {
|
|
142
|
+
try {
|
|
143
|
+
return Function("ctx", `with(ctx) { return (${expr}); }`)(ctxProxy);
|
|
144
|
+
} catch {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
135
148
|
);
|
|
136
149
|
});
|
|
137
150
|
|
|
@@ -145,16 +158,16 @@ export function processComponentElement(
|
|
|
145
158
|
cssScopes,
|
|
146
159
|
cssScopesMap,
|
|
147
160
|
scopedStyles,
|
|
148
|
-
renderChain.concat(compName)
|
|
161
|
+
renderChain.concat(compName),
|
|
162
|
+
staticCtxRegistry
|
|
149
163
|
);
|
|
150
164
|
|
|
151
165
|
["if", "del-if"].forEach(statement => {
|
|
152
166
|
const statAtt = child.getAttribute(statement);
|
|
153
167
|
if (!statAtt) return;
|
|
154
168
|
const expr = statAtt.slice(1, -1);
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
if (!fn()) {
|
|
169
|
+
const fn = new Function("ctx", `with(ctx) { return (${expr}); }`);
|
|
170
|
+
if (!fn(ctxProxy)) {
|
|
158
171
|
if (statement === "if") child.style.display = "none";
|
|
159
172
|
if (statement === "del-if") child.remove();
|
|
160
173
|
}
|
|
@@ -244,9 +257,10 @@ export function processAllComponents(appElements, loadedComponents) {
|
|
|
244
257
|
let cssScopes = [];
|
|
245
258
|
let cssScopesMap = new Map();
|
|
246
259
|
let scopedStyles = [];
|
|
260
|
+
let staticCtxRegistry = new Map();
|
|
247
261
|
|
|
248
262
|
appElements.forEach(el => {
|
|
249
|
-
processComponentElement(el, loadedComponents, runtimeChunks, compIdColl, letterState, runtimeMap, cssScopes, cssScopesMap, scopedStyles);
|
|
263
|
+
processComponentElement(el, loadedComponents, runtimeChunks, compIdColl, letterState, runtimeMap, cssScopes, cssScopesMap, scopedStyles, [], staticCtxRegistry);
|
|
250
264
|
});
|
|
251
265
|
const runtimeScript = runtimeChunks.join("\n");
|
|
252
266
|
const hasComponents = runtimeChunks.length > 0;
|