@@ -185,18 +185,15 @@ valueToJs _ (Constructor _ _ (ProperName ctor) []) =
185185 , JSAssignment (JSAccessor "value" (JSVar ctor))
186186 (JSUnary JSNew $ JSApp (JSVar ctor) []) ]
187187valueToJs _ (Constructor _ _ (ProperName ctor) fields) =
188− return $ iife ctor [ makeConstructor ctor fields
189− , JSAssignment (JSAccessor "create" (JSVar ctor)) (makeCreateFn ctor fields)
190− ]
191− where
192− makeConstructor :: String -> [Ident] -> JS
193− makeConstructor ctorName fs =
194− let body = [ JSAssignment (JSAccessor (identToJs f) (JSVar "this")) (var f) | f <- fs ]
195− in JSFunction (Just ctorName) (identToJs `map` fs) (JSBlock body)
196− makeCreateFn :: String -> [Ident] -> JS
197− makeCreateFn ctorName fs =
198− let body = JSUnary JSNew $ JSApp (JSVar ctorName) (var `map` fs)
199− in foldr (\f inner -> JSFunction Nothing [identToJs f] (JSBlock [JSReturn inner])) body fields
188+ let constructor =
189+ let body = [ JSAssignment (JSAccessor (identToJs f) (JSVar "this")) (var f) | f <- fields ]
190+ in JSFunction (Just ctor) (identToJs `map` fields) (JSBlock body)
191+ createFn =
192+ let body = JSUnary JSNew $ JSApp (JSVar ctor) (var `map` fields)
193+ in foldr (\f inner -> JSFunction Nothing [identToJs f] (JSBlock [JSReturn inner])) body fields
194+ in return $ iife ctor [ constructor
195+ , JSAssignment (JSAccessor "create" (JSVar ctor)) createFn
196+ ]
200197iife :: String -> [JS] -> JS
201198iife v exprs = JSApp (JSFunction Nothing [] (JSBlock $ exprs ++ [JSReturn $ JSVar v])) []
202199