Skip to content

Commit

Permalink
mangler: don't output multiple objects in presence of multiple method…
Browse files Browse the repository at this point in the history
…s and a class all with the same name
  • Loading branch information
oyvindberg committed Sep 29, 2022
1 parent 2830197 commit 36a8eef
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,28 @@ object Mangler extends TreeTransformation {
})
.filter(_.tpe =/= TypeRef.JsAny)

shortcut.foldLeft(
mod.copy(
annotations = Empty,
parents = Empty,
members = rewrittenMembers ++ IArray.fromOption(hatOpt),
comments = mod.comments,
),
) {
val mod1 = mod.copy(
annotations = Empty,
parents = Empty,
members = rewrittenMembers ++ IArray.fromOption(hatOpt),
comments = mod.comments,
)

// plug a hole where if there is a class and multiple functions all with the same name, the functions
// will all be rewritten to an object. this recombines them
val mod2 = {
val newMembers = IArray.fromTraversable(mod1.index).flatMap {
case (_, sameName) =>
val (mods, rest) = sameName.partitionCollect { case x: ModuleTree => x }
if (mods.length > 1) {
val mod = mods.head.copy(members = mods.flatMap(_.members))
mod +: rest
} else sameName
}
mod1.copy(members = newMembers)
}

shortcut.foldLeft(mod2) {
case (mod, field) =>
// implement the `Shortcut` trait for some nicer syntax
val parent = TypeRef(QualifiedName.Shortcut)
Expand Down

0 comments on commit 36a8eef

Please sign in to comment.