@@ -36,12 +36,19 @@ import Language.PureScript.Types
37moduleToJs :: Options -> Module -> Environment -> [JS]
37moduleToJs :: Options -> Module -> Environment -> [JS]
38moduleToJs opts (Module pname@(ProperName name) decls) env =
38moduleToJs opts (Module pname@(ProperName name) decls) env =
40+ rawDecls = mapMaybe filterRawDecls decls
42+ map JSRaw rawDecls ++
39 [ JSVariableIntroduction (Ident name) Nothing
43 [ JSVariableIntroduction (Ident name) Nothing
40 , JSApp (JSFunction Nothing [Ident name]
44 , JSApp (JSFunction Nothing [Ident name]
41 (JSBlock (concat $ mapMaybe (\decl -> declToJs opts (ModuleName pname) decl env) decls)))
45 (JSBlock (concat $ mapMaybe (\decl -> declToJs opts (ModuleName pname) decl env) decls)))
42 [JSAssignment (JSAssignVariable (Ident name))
46 [JSAssignment (JSAssignVariable (Ident name))
43 (JSBinary Or (JSVar (Ident name)) (JSObjectLiteral []))]
47 (JSBinary Or (JSVar (Ident name)) (JSObjectLiteral []))]
50+ filterRawDecls (ExternDeclaration _ (Just js) _) = Just js
51+ filterRawDecls _ = Nothing
46declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
53declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
47declToJs opts mp (ValueDeclaration ident _ _ val) e =
54declToJs opts mp (ValueDeclaration ident _ _ val) e =
@@ -52,24 +59,6 @@ declToJs opts mp (BindingGroupDeclaration vals) e =
52 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
59 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
53 setProperty (identToJs ident) (JSVar ident) mp ]
60 setProperty (identToJs ident) (JSVar ident) mp ]
55−declToJs _ mp (ExternMemberDeclaration member ident ty) _
56− | returnsFunction ty =
57− Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
58− [ JSReturn $ JSApp (JSAccessor "bind" (JSAccessor member (JSVar (Ident "value")))) [JSVar (Ident "value")]
60− setProperty (show ident) (JSVar ident) mp ]
62− Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
63− [ JSReturn $ JSAccessor member (JSVar (Ident "value"))
65− setProperty (show ident) (JSVar ident) mp ]
67− returnsFunction (Function _ ret) = isFunction ret
68− returnsFunction (ForAll _ ty') = returnsFunction ty'
69− returnsFunction _ = error "Expected function type in declToJs"
70− isFunction (Function _ _) = True
71− isFunction (ForAll _ ty') = isFunction ty'
73declToJs _ mp (DataDeclaration _ _ ctors) _ =
62declToJs _ mp (DataDeclaration _ _ ctors) _ =
74 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->
63 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->