on master help sign in
Begin placing JS errors in the core libs instead of in the compiler.
3926066evancz
elm/src/Gen/CompileToJS.hs+2−5
@@ -238,12 +238,10 @@ formatMarkdown = concatMap f
238multiIfToJS span ps =
238multiIfToJS span ps =
239 case last ps of
239 case last ps of
240 (C _ _ (Var "otherwise"), e) -> toJS' e >>= \b -> format b (init ps)
240 (C _ _ (Var "otherwise"), e) -> toJS' e >>= \b -> format b (init ps)
241− _ -> format err ps
241+ _ -> format ("Elm.Error.If" ++ parens (quoted (show span))) ps
242 where
242 where
243 format base ps =
243 format base ps =
244 foldr (\c e -> parens $ c ++ " : " ++ e) base `liftM` mapM f ps
244 foldr (\c e -> parens $ c ++ " : " ++ e) base `liftM` mapM f ps
245− err = "throw new Error('Non-exhaustive multi-way-if expression (" ++
246− show span ++ ")')"
247 f (b,e) = do b' <- toJS' b
245 f (b,e) = do b' <- toJS' b
248 e' <- toJS' e
246 e' <- toJS' e
249 return (b' ++ " ? " ++ e')
247 return (b' ++ " ? " ++ e')
@@ -278,8 +276,7 @@ matchToJS span match =
278 do cases <- intercalate " : " `liftM` mapM (clauseToJS span name) clauses
276 do cases <- intercalate " : " `liftM` mapM (clauseToJS span name) clauses
279 finally <- matchToJS span def
277 finally <- matchToJS span def
280 return (sqnc cases finally)
278 return (sqnc cases finally)
281− Fail -> return ("throw new Error(\"Non-exhaustive pattern match " ++
279+ Fail -> return ("Elm.Error.Case" ++ parens (quoted (show span)))
282− "in case expression (" ++ show span ++ ")\")")
283 Break -> return "null"
280 Break -> return "null"
284 Other e -> toJS' e
281 Other e -> toJS' e
285 Seq ms -> foldr1 sqnc `liftM` mapM (matchToJS span) (dropEnd [] ms)
282 Seq ms -> foldr1 sqnc `liftM` mapM (matchToJS span) (dropEnd [] ms)