diff --git a/cli/src/org/scalajs/cli/Scalajsld.scala b/cli/src/org/scalajs/cli/Scalajsld.scala index 05140c6..4daac42 100644 --- a/cli/src/org/scalajs/cli/Scalajsld.scala +++ b/cli/src/org/scalajs/cli/Scalajsld.scala @@ -294,11 +294,15 @@ object Scalajsld { val semantics = if (options.fullOpt) options.semantics.optimized else options.semantics + val moduleSplitStyle = ModuleSplitStyleRead.moduleSplitStyleRead( options.moduleSplitStyle, options.smallModuleForPackages ) + val useClosure = options.fullOpt && options.moduleKind != ModuleKind.ESModule + + val config = StandardConfig() .withSemantics(semantics) .withModuleKind(options.moduleKind) @@ -310,10 +314,11 @@ object Scalajsld { .withParallel(true) .withSourceMap(options.sourceMap) .withRelativizeSourceMapBase(options.relativizeSourceMap) - .withClosureCompiler(options.fullOpt) + .withClosureCompiler(useClosure) .withPrettyPrint(options.prettyPrint) .withBatchMode(true) .withJSHeader(options.jsHeader) + .withMinify(options.fullOpt) val linker = StandardImpl.linker(config) val logger = new ScalaConsoleLogger(options.logLevel) diff --git a/tests/test/src/org/scalajs/cli/tests/Tests.scala b/tests/test/src/org/scalajs/cli/tests/Tests.scala index 9b1f4a7..d7f31cc 100644 --- a/tests/test/src/org/scalajs/cli/tests/Tests.scala +++ b/tests/test/src/org/scalajs/cli/tests/Tests.scala @@ -273,6 +273,64 @@ class Tests extends munit.FunSuite { os.proc("node", "test.js").call(cwd = dir, check = true) } + + test("using fullLinkJS with ES modules succeeds") { + val dir = os.temp.dir() + os.write( + dir / "foo.scala", + """object Foo { + | def main(args: Array[String]): Unit = { + | val s = "Hello" + | println("Hello" + s.charAt(5)) + | } + | + | class A + |} + |""".stripMargin + ) + + val scalaJsLibraryCp = getScalaJsLibraryCp(dir) + + os.makeDir.all(dir / "bin") + os.proc( + "cs", + "launch", + "scalac:2.13.14", + "--", + "-classpath", + scalaJsLibraryCp, + s"-Xplugin:${getScalaJsCompilerPlugin(dir)}", + "-d", + "bin", + "foo.scala" + ).call(cwd = dir, stdin = os.Inherit, stdout = os.Inherit) + + val res = os + .proc( + launcher, + "--stdlib", + scalaJsLibraryCp, + "-s", + "--moduleKind", + "ESModule", + "--fullOpt", + "-o", + "test.js", + "-mm", + "Foo.main", + "bin" + ) + .call(cwd = dir, mergeErrIntoOut = true) + + val testJsSize = os.size(dir / "test.js") + val testJsMapSize = os.size(dir / "test.js.map") + assert(testJsSize > 0) + assert(testJsMapSize > 0) + + os.proc("node", "test.js").call(cwd = dir, check = true) + } + + test("fastLinkJs mode throws") { val dir = os.temp.dir() os.write(