@@ -67,8 +67,8 @@ jsModule (escapees, Module names exports imports stmts) =
6767 [ concatMap (\n -> globalAssign n $ n ++ " || {}") .
6868 map (intercalate ".") . drop 2 . inits $
6969 take (length modNames - 1) modNames
70− , "\nif (" ++ modName ++ ") throw \"Module name collision, '" ++
71− intercalate "." (tail modNames) ++ "' is already defined.\"; "
70+ , "\nif (" ++ modName ++ ") throw new Error(\"Module name collision, '" ++
71+ intercalate "." (tail modNames) ++ "' is already defined.\"); "
7272 , globalAssign modName $ jsFunc "" (defs ++ includes ++ body ++ export) ++ "()"
7373 , mainEquals $ modName ++ ".main" ]
7474 where modNames = if null names then ["Elm", "Main"]
@@ -102,7 +102,7 @@ getExports names stmts = ret . braces $ intercalate ",\n" (op : map fnPair fns)
102102
103103
104104jsImport (modul, how) =
105− concat [ "\ntry{\n if (!(" ++ modul ++ " instanceof Object)) throw 'module not found';\n} catch(e) {\n throw (\"Module '"
105+ concat [ "\ntry{\n if (!(" ++ modul ++ " instanceof Object)) throw new Error('module not found');\n} catch(e) {\n throw new Error(\"Module '"
106106 , drop 1 (dropWhile (/='.') modul)
107107 , "' is missing. Compile with --make flag or load missing "
108108 , "module in a separate JavaScript file.\");\n}" ] ++
@@ -253,8 +253,8 @@ formatMarkdown = concatMap f
253253
254254multiIfToJS span ps = format `liftM` mapM f ps
255255 where format cs = foldr (\c e -> parens $ c ++ " : " ++ e) err cs
256− err = concat [ "(function(){throw \"Non-exhaustive "
257− , "multi-way-if expression (", show span, ")\";}())" ]
256+ err = concat [ "(function(){throw new Error(\"Non-exhaustive "
257+ , "multi-way-if expression (", show span, ")\");}())" ]
258258 f (b,e) = do b' <- toJS' b
259259 e' <- toJS' e
260260 return (b' ++ " ? " ++ e')
@@ -282,8 +282,8 @@ matchToJS span (Match name clauses def) = do
282282 cases <- concat `liftM` mapM (clauseToJS span name) clauses
283283 finally <- matchToJS span def
284284 return $ concat [ "\nswitch(", name, "[0]){", indent cases, "\n}", finally ]
285−matchToJS span Fail = return ("\nthrow \"Non-exhaustive pattern match " ++
286− "in case expression (" ++ show span ++ ")\";")
285+matchToJS span Fail = return ("\nthrow new Error(\"Non-exhaustive pattern match " ++
286+ "in case expression (" ++ show span ++ ")\");")
287287matchToJS span Break = return "break;"
288288matchToJS span (Other e) = ret `liftM` toJS' e
289289matchToJS span (Seq ms) = concat `liftM` mapM (matchToJS span) ms