@@ -78,6 +78,7 @@ data JS = JSRaw String
7878 | JSCond [(JS, JS)]
7979 | JSTernary JS JS JS
8080 | JSParens JS
81+ | JSWhile JS JS
8182 deriving Eq
8283
8384
@@ -196,6 +197,10 @@ compileJS (JSTernary cond true false) =
196197compileJS (JSParens js) =
197198 "(" ++ compileJS js ++ ")"
198199
200+compileJS (JSWhile cond body) =
201+ "while (" ++ compileJS cond ++ ") {\n"
202+ ++ compileJS body
203+ ++ "\n}"
199204
200205jsTailcall :: JS -> JS
201206jsTailcall call =
@@ -301,6 +306,8 @@ foldJS tr add acc js =
301306 add (tr js) $ fold val
302307 | JSCond conds <- js =
303308 add (tr js) $ foldl' add acc $ map (uncurry add . (fold *** fold)) conds
309+ | JSWhile cond body <- js =
310+ add (tr js) $ add (fold cond) (fold body)
304311 | otherwise =
305312 tr js
306313
@@ -327,6 +334,7 @@ transformJS tr js =
327334 | JSCond conds <- js = JSCond $ map (tr *** tr) conds
328335 | JSTernary c t f <- js = JSTernary (tr c) (tr t) (tr f)
329336 | JSParens val <- js = JSParens $ tr val
337+ | JSWhile cond body <- js = JSWhile(tr cond) (tr body)
330338 | otherwise = js
331339
332340