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

Disable GCC when in release mode AND using ES module kind #65

Merged
merged 2 commits into from
May 22, 2024
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
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
Loading