@@ -254,9 +254,10 @@ qualifiedToJS _ f (Qualified _ a) = JSVar $ identToJs (f a)
254bindersToJs :: Options -> ModuleName -> Environment -> [CaseAlternative] -> [JS] -> JS
254bindersToJs :: Options -> ModuleName -> Environment -> [CaseAlternative] -> [JS] -> JS
255bindersToJs opts m e binders vals = runGen (map identToJs (S.unusedNames usedNames)) $ do
255bindersToJs opts m e binders vals = runGen (map identToJs (S.unusedNames usedNames)) $ do
256 valNames <- replicateM (length vals) fresh
256 valNames <- replicateM (length vals) fresh
257+ let assignments = zipWith JSVariableIntroduction valNames (map Just vals)
257 jss <- forM binders $ \(CaseAlternative bs grd result) -> go valNames [JSReturn (valueToJs opts m (bindNames m (concatMap binderNames bs) e) result)] bs grd
258 jss <- forM binders $ \(CaseAlternative bs grd result) -> go valNames [JSReturn (valueToJs opts m (bindNames m (concatMap binderNames bs) e) result)] bs grd
258− return $ JSApp (JSFunction Nothing valNames (JSBlock (concat jss ++ [JSThrow (JSStringLiteral "Failed pattern match")])))
259+ return $ JSApp (JSFunction Nothing [] (JSBlock (assignments ++ concat jss ++ [JSThrow (JSStringLiteral "Failed pattern match")])))
261 usedNames = concatMap usedNamesJS vals ++ concatMap S.usedNamesCaseAlternative binders
262 usedNames = concatMap usedNamesJS vals ++ concatMap S.usedNamesCaseAlternative binders