@@ -108,10 +108,9 @@ declToJs opts mp (BindingGroupDeclaration vals) e = do
108108 return $ Just jss
109109declToJs _ _ (DataDeclaration _ _ ctors) _ = do
110110 return $ Just $ flip concatMap ctors $ \(pn@(ProperName ctor), tys) ->
111− let _ctor = '_' : ctor
112− in [ makeConstructor _ctor (length tys)
113− , JSVariableIntroduction ctor (Just (go pn 0 (length tys) []))
114− ]
111+ [ makeConstructor ctor (length tys)
112+ , JSAssignment (JSAccessor "create" (JSVar ctor)) (go pn 0 (length tys) [])
113+ ]
115114 where
116115 makeConstructor :: String -> Int -> JS
117116 makeConstructor ctorName n =
@@ -120,7 +119,7 @@ declToJs _ _ (DataDeclaration _ _ ctors) _ = do
120119 body = [ JSAssignment (JSAccessor arg (JSVar "this")) (JSVar arg) | arg <- args ]
121120 in JSFunction (Just ctorName) args (JSBlock body)
122121 go :: ProperName -> Int -> Int -> [JS] -> JS
123− go pn _ 0 values = JSApp (JSNew (JSVar ('_' : runProperName pn))) (reverse values)
122+ go pn _ 0 values = JSApp (JSNew (JSVar (runProperName pn))) (reverse values)
124123 go pn index n values =
125124 JSFunction Nothing ["value" ++ show index]
126125 (JSBlock [JSReturn (go pn (index + 1) (n - 1) (JSVar ("value" ++ show index) : values))])
@@ -156,7 +155,7 @@ declToJs _ _ _ _ = return Nothing
156155-- Generate key//value pairs for an object literal exporting values from a module.
157156--
158157exportToJs :: DeclarationRef -> [(String, JS)]
159−exportToJs (TypeRef _ (Just dctors)) = concatMap ((\n -> [('_' : n, var (Ident ('_' : n))), (n, var (Ident n))]) . runProperName) dctors
158+exportToJs (TypeRef _ (Just dctors)) = map ((\n -> (n, var (Ident n))) . runProperName) dctors
160159exportToJs (ValueRef name) = [(runIdent name, var name)]
161160exportToJs (TypeInstanceRef name) = [(runIdent name, var name)]
162161exportToJs (TypeClassRef name) = [(runProperName name, var $ Ident $ runProperName name)]
@@ -199,7 +198,7 @@ valueToJs opts m e (ObjectUpdate o ps) = do
199198 obj <- valueToJs opts m e o
200199 sts <- mapM (sndM (valueToJs opts m e)) ps
201200 extendObj obj sts
202−valueToJs _ m _ (Constructor name) = return $ qualifiedToJS m (Ident . runProperName) name
201+valueToJs _ m _ (Constructor name) = return $ JSAccessor "create" $ qualifiedToJS m (Ident . runProperName) name
203202valueToJs opts m e (Case values binders) = do
204203 vals <- mapM (valueToJs opts m e) values
205204 bindersToJs opts m e binders vals
@@ -329,18 +328,16 @@ binderToJs _ _ varName done (BooleanBinder False) =
329328 return [JSIfElse (JSUnary Not (JSVar varName)) (JSBlock done) Nothing]
330329binderToJs _ _ varName done (VarBinder ident) =
331330 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : done)
332−binderToJs m e varName done (ConstructorBinder ctor@(Qualified ctorModule (ProperName ctorName)) bs) = do
331+binderToJs m e varName done (ConstructorBinder ctor bs) = do
333332 js <- go 0 done bs
334333 if isOnlyConstructor e ctor
335334 then
336335 return js
337336 else
338− return [JSIfElse (JSInstanceOf (JSVar varName) (qualifiedToJS m (Ident . runProperName) _ctor))
337+ return [JSIfElse (JSInstanceOf (JSVar varName) (qualifiedToJS m (Ident . runProperName) ctor))
339338 (JSBlock js)
340339 Nothing]
341340 where
342− _ctor :: Qualified ProperName
343− _ctor = Qualified ctorModule (ProperName ('_' : ctorName))
344341 go :: (Functor m, Applicative m, Monad m) => Integer -> [JS] -> [Binder] -> SupplyT m [JS]
345342 go _ done' [] = return done'
346343 go index done' (binder:bs') = do