@@ -36,12 +36,19 @@ import Language.PureScript.Types
3636
3737moduleToJs :: Options -> Module -> Environment -> [JS]
3838moduleToJs opts (Module pname@(ProperName name) decls) env =
39+ let
40+ rawDecls = mapMaybe filterRawDecls decls
41+ in
42+ map JSRaw rawDecls ++
3943 [ JSVariableIntroduction (Ident name) Nothing
4044 , JSApp (JSFunction Nothing [Ident name]
4145 (JSBlock (concat $ mapMaybe (\decl -> declToJs opts (ModuleName pname) decl env) decls)))
4246 [JSAssignment (JSAssignVariable (Ident name))
4347 (JSBinary Or (JSVar (Ident name)) (JSObjectLiteral []))]
4448 ]
49+ where
50+ filterRawDecls (ExternDeclaration _ (Just js) _) = Just js
51+ filterRawDecls _ = Nothing
4552
4653declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
4754declToJs opts mp (ValueDeclaration ident _ _ val) e =
@@ -52,24 +59,6 @@ declToJs opts mp (BindingGroupDeclaration vals) e =
5259 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
5360 setProperty (identToJs ident) (JSVar ident) mp ]
5461 ) vals
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")]
59− ]),
60− setProperty (show ident) (JSVar ident) mp ]
61− | otherwise =
62− Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
63− [ JSReturn $ JSAccessor member (JSVar (Ident "value"))
64− ]),
65− setProperty (show ident) (JSVar ident) mp ]
66− where
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'
72− isFunction _ = False
7362declToJs _ mp (DataDeclaration _ _ ctors) _ =
7463 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->
7564 let