@@ -1027,7 +1027,7 @@ extractLocalConstructors js =
1028 extractLocalConstructors' :: JS -> [JS]
1028 extractLocalConstructors' :: JS -> [JS]
1029 extractLocalConstructors' js@(JSAlloc fun (Just (JSFunction args body))) =
1029 extractLocalConstructors' js@(JSAlloc fun (Just (JSFunction args body))) =
1030− map allocCon cons ++ [foldr (uncurry jsSubst) js (reverse cons)]
1030+ addCons cons [foldr (uncurry jsSubst) js (reverse cons)]
1032 cons :: [(JS, JS)]
1032 cons :: [(JS, JS)]
1033 cons = zipWith genName (foldJS match (++) [] body) [1..]
1033 cons = zipWith genName (foldJS match (++) [] body) [1..]
@@ -1043,6 +1043,24 @@ extractLocalConstructors js =
1043 | otherwise = []
1043 | otherwise = []
1046+ addCons :: [(JS, JS)] -> [JS] -> [JS]
1048+ addCons (con@(_, name):cons) js
1049+ | sum (map (countOccur name) js) > 0 =
1050+ addCons cons ((allocCon con) : js)
1055+ countOccur :: JS -> JS -> Int
1056+ countOccur ident js = foldJS match (+) 0 js
1046 allocCon :: (JS, JS) -> JS
1064 allocCon :: (JS, JS) -> JS
1047 allocCon (js, JSIdent name) =
1065 allocCon (js, JSIdent name) =
1048 JSAlloc name (Just js)
1066 JSAlloc name (Just js)