Skip to content

Commit

Permalink
Disable GCC when in release mode AND using ES module kind (#65)
Browse files Browse the repository at this point in the history
* Disable GCC when in release mode AND using ES module kind

* Add test
  • Loading branch information
keynmol authored May 22, 2024
1 parent 05c15ae commit 6d10edd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cli/src/org/scalajs/cli/Scalajsld.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
58 changes: 58 additions & 0 deletions tests/test/src/org/scalajs/cli/tests/Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6d10edd

Please sign in to comment.