diff --git a/src/compilerEs/fan/ast/JsExpr.fan b/src/compilerEs/fan/ast/JsExpr.fan index a1847ca84..f3594fc7a 100644 --- a/src/compilerEs/fan/ast/JsExpr.fan +++ b/src/compilerEs/fan/ast/JsExpr.fan @@ -267,6 +267,19 @@ class JsExpr : JsNode leave := x.leave isAssign := x.assignTarget != null + // convert binary expressions assigning or testing for equivalence to + // synthetic str "_once_" to undefined + if (lhs.expr is FieldExpr) + { + fe := (FieldExpr)lhs.expr + if (rhs.expr.id === ExprId.strLiteral && rhs.expr->val == "_once_") + { + lhs.write + js.w(" ${symbol} undefined", loc) + return + } + } + if (isAssign && lhs.expr is FieldExpr) { fe := (FieldExpr)lhs.expr diff --git a/src/compilerEs/fan/ast/JsType.fan b/src/compilerEs/fan/ast/JsType.fan index 35ec6dbef..2a4912b35 100644 --- a/src/compilerEs/fan/ast/JsType.fan +++ b/src/compilerEs/fan/ast/JsType.fan @@ -235,6 +235,9 @@ class JsType : JsNode private static Str fieldDefVal(FieldDef f) { + // initialize once fields to undefined + if (f.isOnce) return "undefined" + defVal := "null" fieldType := f.fieldType if (!fieldType.isNullable)