From 36a8eef2f8222b6dc6d40844fefdff94e34c1a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Thu, 29 Sep 2022 23:32:49 +0200 Subject: [PATCH] mangler: don't output multiple objects in presence of multiple methods and a class all with the same name --- .../internal/scalajs/transforms/Mangler.scala | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala index 46a596946e..b90904ee7e 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala @@ -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)