@@ -67,8 +67,8 @@ jsModule (escapees, Module names exports imports stmts) =
67 [ concatMap (\n -> globalAssign n $ n ++ " || {}") .
67 [ concatMap (\n -> globalAssign n $ n ++ " || {}") .
68 map (intercalate ".") . drop 2 . inits $
68 map (intercalate ".") . drop 2 . inits $
69 take (length modNames - 1) modNames
69 take (length modNames - 1) modNames
70− , "\nif (" ++ modName ++ ") throw \"Module name collision, '" ++
70+ , "\nif (" ++ modName ++ ") throw new Error(\"Module name collision, '" ++
71− intercalate "." (tail modNames) ++ "' is already defined.\"; "
71+ intercalate "." (tail modNames) ++ "' is already defined.\"); "
72 , globalAssign modName $ jsFunc "" (defs ++ includes ++ body ++ export) ++ "()"
72 , globalAssign modName $ jsFunc "" (defs ++ includes ++ body ++ export) ++ "()"
73 , mainEquals $ modName ++ ".main" ]
73 , mainEquals $ modName ++ ".main" ]
74 where modNames = if null names then ["Elm", "Main"]
74 where modNames = if null names then ["Elm", "Main"]
@@ -102,7 +102,7 @@ getExports names stmts = ret . braces $ intercalate ",\n" (op : map fnPair fns)
104jsImport (modul, how) =
104jsImport (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 '"
106 , drop 1 (dropWhile (/='.') modul)
106 , drop 1 (dropWhile (/='.') modul)
107 , "' is missing. Compile with --make flag or load missing "
107 , "' is missing. Compile with --make flag or load missing "
108 , "module in a separate JavaScript file.\");\n}" ] ++
108 , "module in a separate JavaScript file.\");\n}" ] ++
@@ -253,8 +253,8 @@ formatMarkdown = concatMap f
254multiIfToJS span ps = format `liftM` mapM f ps
254multiIfToJS span ps = format `liftM` mapM f ps
255 where format cs = foldr (\c e -> parens $ c ++ " : " ++ e) err cs
255 where format cs = foldr (\c e -> parens $ c ++ " : " ++ e) err cs
256− err = concat [ "(function(){throw \"Non-exhaustive "
256+ err = concat [ "(function(){throw new Error(\"Non-exhaustive "
257− , "multi-way-if expression (", show span, ")\";}())" ]
257+ , "multi-way-if expression (", show span, ")\");}())" ]
258 f (b,e) = do b' <- toJS' b
258 f (b,e) = do b' <- toJS' b
259 e' <- toJS' e
259 e' <- toJS' e
260 return (b' ++ " ? " ++ e')
260 return (b' ++ " ? " ++ e')
@@ -282,8 +282,8 @@ matchToJS span (Match name clauses def) = do
282 cases <- concat `liftM` mapM (clauseToJS span name) clauses
282 cases <- concat `liftM` mapM (clauseToJS span name) clauses
283 finally <- matchToJS span def
283 finally <- matchToJS span def
284 return $ concat [ "\nswitch(", name, "[0]){", indent cases, "\n}", finally ]
284 return $ concat [ "\nswitch(", name, "[0]){", indent cases, "\n}", finally ]
285−matchToJS span Fail = return ("\nthrow \"Non-exhaustive pattern match " ++
285+matchToJS span Fail = return ("\nthrow new Error(\"Non-exhaustive pattern match " ++
286− "in case expression (" ++ show span ++ ")\";")
286+ "in case expression (" ++ show span ++ ")\");")
287matchToJS span Break = return "break;"
287matchToJS span Break = return "break;"
288matchToJS span (Other e) = ret `liftM` toJS' e
288matchToJS span (Other e) = ret `liftM` toJS' e
289matchToJS span (Seq ms) = concat `liftM` mapM (matchToJS span) ms
289matchToJS span (Seq ms) = concat `liftM` mapM (matchToJS span) ms