fix: conditional classes, dynamic params, HMR and formatter

This commit is contained in:
2026-07-14 11:56:43 +05:30
parent 420706ca3b
commit 71480bb229
6 changed files with 240 additions and 17 deletions
+39
View File
@@ -199,6 +199,45 @@ export const REACTIVE_RUNTIME = String.raw`
});
});
// Conditional class bindings emitted as:
// data-wrn-class-*='["class-name","expression"]'
var classBindNodes = [el].concat(
Array.prototype.slice.call(el.querySelectorAll("*")),
);
classBindNodes.forEach(function (node) {
if (!owns(node)) return;
Array.prototype.slice.call(node.attributes).forEach(function (marker) {
if (marker.name.indexOf("data-wrn-class-") !== 0) return;
var binding;
try {
binding = JSON.parse(marker.value);
} catch (e) {
return;
}
if (!binding || binding.length !== 2) return;
var className = binding[0];
var expression = binding[1];
reactive(function () {
var enabled = false;
try {
enabled = !!evalExpr(expression);
} catch (e) {
enabled = false;
}
node.classList.toggle(className, enabled);
});
});
});
// Reactive ordinary attributes emitted by the compiler. Each marker stores
// [attributeName, originalTemplate], preserving an SSR value while allowing
// state changes to update type, aria-*, class, href, and other attributes.