@@ -317,11 +317,12 @@ qualifiedToJS _ f (Qualified _ a) = JSVar $ identToJs (f a)
317317bindersToJs :: (Functor m, Applicative m, Monad m) => Options -> ModuleName -> Environment -> [CaseAlternative] -> [JS] -> SupplyT m JS
318318bindersToJs opts m e binders vals = do
319319 valNames <- replicateM (length vals) freshName
320+ let assignments = zipWith JSVariableIntroduction valNames (map Just vals)
320321 jss <- forM binders $ \(CaseAlternative bs grd result) -> do
321322 ret <- valueToJs opts m e result
322323 go valNames [JSReturn ret] bs grd
323− return $ JSApp (JSFunction Nothing valNames (JSBlock (concat jss ++ [JSThrow $ JSUnary JSNew $ JSApp (JSVar "Error") $ [(JSStringLiteral "Failed pattern match")]])))
324− vals
324+ return $ JSApp (JSFunction Nothing [] (JSBlock (assignments ++ concat jss ++ [JSThrow $ JSUnary JSNew $ JSApp (JSVar "Error") $ [JSStringLiteral "Failed pattern match"]])))
325+ []
325326 where
326327 go :: (Functor m, Applicative m, Monad m) => [String] -> [JS] -> [Binder] -> Maybe Guard -> SupplyT m [JS]
327328 go _ done [] Nothing = return done