@@ -28,6 +28,7 @@ import Fay.Types
2828import Control.Applicative
2929import Control.Monad.Error
3030import Control.Monad.RWS
31+ import qualified Data.Char as Char
3132import Language.Haskell.Exts.Annotated
3233import Language.Haskell.Names
3334
@@ -276,18 +277,18 @@ compileEnumFromThenTo a b z = do
276277compileRecConstr :: S. QName -> [S. FieldUpdate ] -> Compile JsExp
277278compileRecConstr name fieldUpdates = do
278279 -- var obj = new $_Type()
279- let unQualName = unQualify $ unAnn name
280+ let unQualName = withIdent lowerFirst . unQualify $ unAnn name
280281 qname <- unsafeResolveName name
281282 let record = JsVar (JsNameVar unQualName) (JsNew (JsConstructor qname) [] )
282283 setFields <- liftM concat (forM fieldUpdates (updateStmt name))
283- return $ JsApp (JsFun Nothing [] (record: setFields) (Just $ JsName $ JsNameVar $ unQualify $ unAnn name)) []
284+ return $ JsApp (JsFun Nothing [] (record: setFields) (Just . JsName . JsNameVar . withIdent lowerFirst . unQualify $ unAnn name)) []
284285 where
285286 -- updateStmt :: QName a -> S.FieldUpdate -> Compile [JsStmt]
286287 updateStmt (unAnn -> o) (FieldUpdate _ (unAnn -> field) value) = do
287288 exp <- compileExp value
288- return [JsSetProp (JsNameVar $ unQualify o) (JsNameVar $ unQualify field) exp ]
289- updateStmt name (FieldWildcard (wildcardFields -> fields)) = do
290- return $ for fields $ \ fieldName -> JsSetProp (JsNameVar $ unAnn name )
289+ return [JsSetProp (JsNameVar $ withIdent lowerFirst $ unQualify o) (JsNameVar $ unQualify field) exp ]
290+ updateStmt o (FieldWildcard (wildcardFields -> fields)) = do
291+ return $ for fields $ \ fieldName -> JsSetProp (JsNameVar . withIdent lowerFirst . unQualify . unAnn $ o )
291292 (JsNameVar fieldName)
292293 (JsName $ JsNameVar fieldName)
293294 -- I couldn't find a code that generates (FieldUpdate (FieldPun ..))
@@ -296,6 +297,9 @@ compileRecConstr name fieldUpdates = do
296297 wildcardFields l = case l of
297298 Scoped (RecExpWildcard es) _ -> map (unQualify . origName2QName) . map fst $ es
298299 _ -> []
300+ lowerFirst :: String -> String
301+ lowerFirst " " = " "
302+ lowerFirst (x: xs) = ' _' : Char. toLower x : xs
299303
300304-- | Compile a record update.
301305compileRecUpdate :: S. Exp -> [S. FieldUpdate ] -> Compile JsExp
0 commit comments