module Language.PureScript.CodeGen.JS.Optimizer.Blocks
( collapseNestedBlocks
, collapseNestedIfs
) where
import Language.PureScript.CodeGen.JS.AST
collapseNestedBlocks :: JS -> JS
collapseNestedBlocks = everywhereOnJS collapse
where
collapse :: JS -> JS
collapse (JSBlock sts) = JSBlock (concatMap go sts)
collapse js = js
go :: JS -> [JS]
go (JSBlock sts) = sts
go s = [s]
collapseNestedIfs :: JS -> JS
collapseNestedIfs = everywhereOnJS collapse
where
collapse :: JS -> JS
collapse (JSIfElse cond1 (JSBlock [JSIfElse cond2 body Nothing]) Nothing) =
JSIfElse (JSBinary And cond1 cond2) body Nothing
collapse js = js