@@ -76,21 +76,21 @@ bindersToJs binders val = do
7676binderToJs :: String -> [JS] -> Binder -> Gen [JS]
7777binderToJs varName done NullBinder = return done
7878binderToJs varName done (StringBinder str) =
79− return [JSIfElse (JSBinary EqualTo (JSVar (Ident varName)) (JSStringLiteral str)) done Nothing]
79+ return [JSIfElse (JSBinary EqualTo (JSVar (Ident varName)) (JSStringLiteral str)) (JSBlock done) Nothing]
8080binderToJs varName done (NumberBinder num) =
81− return [JSIfElse (JSBinary EqualTo (JSVar (Ident varName)) (JSNumericLiteral num)) done Nothing]
81+ return [JSIfElse (JSBinary EqualTo (JSVar (Ident varName)) (JSNumericLiteral num)) (JSBlock done) Nothing]
8282binderToJs varName done (BooleanBinder True) =
83− return [JSIfElse (JSVar (Ident varName)) done Nothing]
83+ return [JSIfElse (JSVar (Ident varName)) (JSBlock done) Nothing]
8484binderToJs varName done (BooleanBinder False) =
85− return [JSIfElse (JSUnary Not (JSVar (Ident varName))) done Nothing]
85+ return [JSIfElse (JSUnary Not (JSVar (Ident varName))) (JSBlock done) Nothing]
8686binderToJs varName done (VarBinder ident) =
8787 return (JSVariableIntroduction ident (JSVar (Ident varName)) : done)
8888binderToJs varName done (NullaryBinder ctor) =
89− return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar (Ident varName))) (JSStringLiteral ctor)) done Nothing]
89+ return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar (Ident varName))) (JSStringLiteral ctor)) (JSBlock done) Nothing]
9090binderToJs varName done (UnaryBinder ctor b) = do
9191 value <- fresh
9292 js <- binderToJs value done b
93− return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar (Ident varName))) (JSStringLiteral ctor)) (JSVariableIntroduction (Ident value) (JSAccessor "value" (JSVar (Ident varName))) : js) Nothing]
93+ return [JSIfElse (JSBinary EqualTo (JSAccessor "ctor" (JSVar (Ident varName))) (JSStringLiteral ctor)) (JSBlock (JSVariableIntroduction (Ident value) (JSAccessor "value" (JSVar (Ident varName))) : js)) Nothing]
9494binderToJs varName done (ObjectBinder bs) = go done bs
9595 where
9696 go :: [JS] -> [(String, Binder)] -> Gen [JS]
@@ -102,7 +102,7 @@ binderToJs varName done (ObjectBinder bs) = go done bs
102102 return (JSVariableIntroduction (Ident propVar) (JSAccessor prop (JSVar (Ident varName))) : js)
103103binderToJs varName done (ArrayBinder bs rest) = do
104104 js <- go done rest 0 bs
105− return [JSIfElse (JSBinary cmp (JSAccessor "length" (JSVar (Ident varName))) (JSNumericLiteral (Left (fromIntegral $ length bs)))) js Nothing]
105+ return [JSIfElse (JSBinary cmp (JSAccessor "length" (JSVar (Ident varName))) (JSNumericLiteral (Left (fromIntegral $ length bs)))) (JSBlock js) Nothing]
106106 where
107107 cmp :: BinaryOperator
108108 cmp = maybe EqualTo (const GreaterThanOrEqualTo) rest
@@ -122,18 +122,18 @@ binderToJs varName done (NamedBinder ident binder) = do
122122 return (JSVariableIntroduction ident (JSVar (Ident varName)) : js)
123123binderToJs varName done (GuardedBinder cond binder) = binderToJs varName done' binder
124124 where
125− done' = [JSIfElse (valueToJs cond) done Nothing]
125+ done' = [JSIfElse (valueToJs cond) (JSBlock done) Nothing]
126126
127127statementToJs :: Statement -> JS
128128statementToJs (VariableIntroduction ident value) = JSVariableIntroduction ident (valueToJs value)
129129statementToJs (Assignment target value) = JSAssignment target (valueToJs value)
130−statementToJs (While cond sts) = JSWhile (valueToJs cond) (map statementToJs sts)
131−statementToJs (For ident start end sts) = JSFor ident (valueToJs start) (valueToJs end) (map statementToJs sts)
130+statementToJs (While cond sts) = JSWhile (valueToJs cond) (JSBlock (map statementToJs sts))
131+statementToJs (For ident start end sts) = JSFor ident (valueToJs start) (valueToJs end) (JSBlock (map statementToJs sts))
132132statementToJs (ForEach ident arr sts) = JSApp (JSAccessor "forEach" (valueToJs arr)) [JSFunction Nothing [ident] (JSBlock (map statementToJs sts))]
133133statementToJs (If ifst) = ifToJs ifst
134134 where
135135 ifToJs :: IfStatement -> JS
136− ifToJs (IfStatement cond thens elses) = JSIfElse (valueToJs cond) (map statementToJs thens) (fmap elseToJs elses)
136+ ifToJs (IfStatement cond thens elses) = JSIfElse (valueToJs cond) (JSBlock (map statementToJs thens)) (fmap elseToJs elses)
137137 elseToJs :: ElseStatement -> JS
138138 elseToJs (Else sts) = JSBlock (map statementToJs sts)
139139 elseToJs (ElseIf ifst) = ifToJs ifst