[JS IR] Perform optimizations on the generated JS code

The patch adopts and reuses the optimizations from the legacy backend.

The optimizations remove useless temporary variables,
statements and simplify generated JS code.

The optimizations can be disabled by `-Xoptimize-generated-js=false`.

Related to KT-51139
This commit is contained in:
Alexander Korepanov
2023-04-11 20:04:28 +02:00
committed by Space Team
parent 84b5af3c89
commit 79d378f2bd
87 changed files with 173 additions and 224 deletions
@@ -48,6 +48,7 @@ fun copyK2JSCompilerArguments(from: K2JSCompilerArguments, to: K2JSCompilerArgum
to.moduleKind = from.moduleKind
to.moduleName = from.moduleName
to.noStdlib = from.noStdlib
to.optimizeGeneratedJs = from.optimizeGeneratedJs
to.outputDir = from.outputDir
to.outputFile = from.outputFile
to.outputPostfix = from.outputPostfix
@@ -605,6 +605,16 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
field = value
}
@Argument(
value = "-Xoptimize-generated-js",
description = "Perform additional optimizations on the generated JS code"
)
var optimizeGeneratedJs = true
set(value) {
checkFrozen()
field = value
}
private fun MessageCollector.deprecationWarn(value: Boolean, defaultValue: Boolean, name: String) {
if (value != defaultValue) {
report(CompilerMessageSeverity.WARNING, "'$name' is deprecated and ignored, it will be removed in a future release")