@@ -1031,7 +1031,7 @@ extractLocalConstructors js =
1032 extractLocalConstructors' :: JS -> [JS]
1032 extractLocalConstructors' :: JS -> [JS]
1033 extractLocalConstructors' js@(JSAlloc fun (Just (JSFunction args body))) =
1033 extractLocalConstructors' js@(JSAlloc fun (Just (JSFunction args body))) =
1034− map allocCon cons ++ [foldr (uncurry jsSubst) js (reverse cons)]
1034+ addCons cons [foldr (uncurry jsSubst) js (reverse cons)]
1036 cons :: [(JS, JS)]
1036 cons :: [(JS, JS)]
1037 cons = zipWith genName (foldJS match (++) [] body) [1..]
1037 cons = zipWith genName (foldJS match (++) [] body) [1..]
@@ -1047,6 +1047,24 @@ extractLocalConstructors js =
1047 | otherwise = []
1047 | otherwise = []
1050+ addCons :: [(JS, JS)] -> [JS] -> [JS]
1052+ addCons (con@(_, name):cons) js
1053+ | sum (map (countOccur name) js) > 0 =
1054+ addCons cons ((allocCon con) : js)
1059+ countOccur :: JS -> JS -> Int
1060+ countOccur ident js = foldJS match (+) 0 js
1050 allocCon :: (JS, JS) -> JS
1068 allocCon :: (JS, JS) -> JS
1051 allocCon (js, JSIdent name) =
1069 allocCon (js, JSIdent name) =
1052 JSAlloc name (Just js)
1070 JSAlloc name (Just js)