Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESModule to Scala.js #1415

Merged
merged 1 commit into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ object JsBridge {
val moduleKind = config.kind match {
case ModuleKindJS.NoModule => ModuleKind.NoModule
case ModuleKindJS.CommonJSModule => ModuleKind.CommonJSModule
case ModuleKindJS.ESModule => ModuleKind.ESModule
}

val enableOptimizer = config.mode == LinkerMode.Release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ object JsBridge {
val moduleKind = config.kind match {
case ModuleKindJS.NoModule => ScalaJSModuleKind.NoModule
case ModuleKindJS.CommonJSModule => ScalaJSModuleKind.CommonJSModule
case ModuleKindJS.ESModule => ScalaJSModuleKind.ESModule
}

val cache = StandardImpl.irFileCache().newCache
Expand Down Expand Up @@ -131,6 +132,7 @@ object JsBridge {
val input = jsConfig.kind match {
case ModuleKindJS.NoModule => Input.Script(jsPath)
case ModuleKindJS.CommonJSModule => Input.CommonJSModule(jsPath)
case ModuleKindJS.ESModule => Input.ESModule(jsPath)
}

val testConfig = TestAdapter.Config().withLogger(new Logger(logger))
Expand Down
2 changes: 2 additions & 0 deletions config/src/main/scala-2.10/bloop/config/ConfigCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ object ConfigCodecs {
override final def apply(m: ModuleKindJS): Json = m match {
case m @ ModuleKindJS.NoModule => Json.fromString(m.id)
case m @ ModuleKindJS.CommonJSModule => Json.fromString(m.id)
case m @ ModuleKindJS.ESModule => Json.fromString(m.id)
}
}

Expand All @@ -81,6 +82,7 @@ object ConfigCodecs {
c.as[String].flatMap {
case ModuleKindJS.NoModule.id => Right(ModuleKindJS.NoModule)
case ModuleKindJS.CommonJSModule.id => Right(ModuleKindJS.CommonJSModule)
case ModuleKindJS.ESModule.id => Right(ModuleKindJS.ESModule)
case _ =>
val msg = s"Expected module kind ${ModuleKindJS.All.map(s => s"'$s'").mkString(", ")})"
Left(DecodingFailure(msg, c.history))
Expand Down
2 changes: 2 additions & 0 deletions config/src/main/scala-2.11-13/bloop/config/ConfigCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ object ConfigCodecs {
val str = x match {
case Config.ModuleKindJS.CommonJSModule => Config.ModuleKindJS.CommonJSModule.id
case Config.ModuleKindJS.NoModule => Config.ModuleKindJS.NoModule.id
case Config.ModuleKindJS.ESModule => Config.ModuleKindJS.ESModule.id
}
out.writeVal(str)
}
Expand All @@ -102,6 +103,7 @@ object ConfigCodecs {
in.readString(null) match {
case Config.ModuleKindJS.CommonJSModule.id => Config.ModuleKindJS.CommonJSModule
case Config.ModuleKindJS.NoModule.id => Config.ModuleKindJS.NoModule
case Config.ModuleKindJS.ESModule.id => Config.ModuleKindJS.ESModule
case _ =>
in.decodeError(
s"Expected linker mode ${Config.ModuleKindJS.All.mkString("'", "', '", "'")}"
Expand Down
3 changes: 2 additions & 1 deletion config/src/main/scala/bloop/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ object Config {
object ModuleKindJS {
case object NoModule extends ModuleKindJS("none")
case object CommonJSModule extends ModuleKindJS("commonjs")
val All = List(NoModule.id, CommonJSModule.id)
case object ESModule extends ModuleKindJS("esmodule")
val All = List(NoModule.id, CommonJSModule.id, ESModule.id)
}

case class JsConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ object BloopDefaults {

private final val NoJSModule = "NoModule"
private final val CommonJSModule = "CommonJSModule"
private final val ESModule = "ESModule"

/**
* Create a "proxy" for a setting that will allow us to inspect its value even though
Expand Down Expand Up @@ -303,6 +304,7 @@ object BloopDefaults {
stageSetting.value.toString match {
case "Some(NoModule)" => Some(NoJSModule)
case "Some(CommonJSModule)" => Some(CommonJSModule)
case "Some(ESModule)" => Some(ESModule)
case _ => None
}
}
Expand Down Expand Up @@ -777,6 +779,7 @@ object BloopDefaults {
val scalaJsModule = BloopKeys.bloopScalaJSModuleKind.value match {
case Some(NoJSModule) => Config.ModuleKindJS.NoModule
case Some(CommonJSModule) => Config.ModuleKindJS.CommonJSModule
case Some(ESModule) => Config.ModuleKindJS.ESModule
case _ => emptyScalaJs.kind
}

Expand Down