git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix issue with extern member declarations returning functions.
5248e03Phil Freeman
examples/passing/ExternMember.pursnew file+5
@@ -0,0 +1,5 @@
1+module ExternMember where
2+
3+foreign import member "length" length :: String -> Number
4+
5+foreign import member "concat" concat :: forall a. [a] -> [a] -> [a]
purescript.cabal+1−1
@@ -1,5 +1,5 @@
1name: purescript
1name: purescript
2−version: 0.2.9.1
2+version: 0.2.9.2
3cabal-version: >=1.8
3cabal-version: >=1.8
4build-type: Simple
4build-type: Simple
5license: MIT
5license: MIT
src/Language/PureScript/CodeGen/JS.hs+18−3
@@ -53,9 +53,24 @@ declToJs opts mp (BindingGroupDeclaration vals) e =
53 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
53 [ JSVariableIntroduction ident (Just (valueToJs opts mp e val)),
54 setProperty (identToJs ident) (JSVar ident) mp ]
54 setProperty (identToJs ident) (JSVar ident) mp ]
55 ) vals
55 ) vals
56−declToJs _ mp (ExternMemberDeclaration member ident _) _ =
56+declToJs _ mp (ExternMemberDeclaration member ident ty) _
57+ | returnsFunction ty =
57− Just [ JSFunction (Just ident) [Ident "value"] (JSBlock [JSReturn (JSAccessor member (JSVar (Ident "value")))]),
58+ Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
59+ [ JSReturn $ JSApp (JSAccessor "bind" (JSAccessor member (JSVar (Ident "value")))) [JSVar (Ident "value")]
60+ ]),
61+ setProperty (show ident) (JSVar ident) mp ]
62+ | otherwise =
63+ Just [ JSFunction (Just ident) [Ident "value"] (JSBlock
64+ [ JSReturn $ JSAccessor member (JSVar (Ident "value"))
65+ ]),
58− setProperty (show ident) (JSVar ident) mp ]
66+ setProperty (show ident) (JSVar ident) mp ]
67+ where
68+ returnsFunction (Function _ ret) = isFunction ret
69+ returnsFunction (ForAll _ ty') = returnsFunction ty'
70+ returnsFunction _ = error "Expected function type in declToJs"
71+ isFunction (Function _ _) = True
72+ isFunction (ForAll _ ty') = isFunction ty'
73+ isFunction _ = False
59declToJs _ mp (DataDeclaration _ _ ctors) _ =
74declToJs _ mp (DataDeclaration _ _ ctors) _ =
60 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->
75 Just $ flip concatMap ctors $ \(pn@(ProperName ctor), maybeTy) ->
61 let
76 let