[FIX] compiler: dynamic value on inputs doesn't turn 0 into empty string

In #1161, we fixed blockdom treating 0 as falsy when patching a value,
which would result in an empty attribute. It turns out that there is
another place where we had the same fallback, which is when we compute a
dynamic attribute value, so while blockdom had the ability to set the
value to 0, when using a dynamic attribute value we would never give it
0 as a value. This commit changes the fallback strategy for dynamic
attribute values to be the same as the one in blockdom.

closes #1358
This commit is contained in:
Samuel Degueldre
2023-02-24 13:53:21 +01:00
committed by Géry Debongnie
parent 276c8a0295
commit a35b9814c0
5 changed files with 73 additions and 9 deletions
+2 -2
View File
@@ -580,8 +580,8 @@ export class CodeGenerator {
if (attrName && isProp(ast.tag, attrName)) {
// we force a new string or new boolean to bypass the equality check in blockdom when patching same value
if (attrName === "value") {
// When the expression is falsy, fall back to an empty string
expr = `new String((${expr}) || "")`;
// When the expression is falsy (except 0), fall back to an empty string
expr = `new String((${expr}) === 0 ? 0 : ((${expr}) || ""))`;
} else {
expr = `new Boolean(${expr})`;
}