[JS IR] Preparing for introducing sourcemap as another compilation output

* Rename `JsCode` to `CompilationOutputs`.
* Rename members of CompilerResult.

#KT-46551 In Progress
This commit is contained in:
Zalim Bashorov
2021-07-01 20:39:16 +03:00
committed by teamcityserver
parent d9b7230144
commit 64c6d852de
4 changed files with 19 additions and 19 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -284,8 +284,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
), ),
) )
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!! val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.outputsAfterDce!! else compiledModule.outputs!!
outputFile.writeText(jsCode.mainModule) outputFile.writeText(jsCode.jsCode)
jsCode.dependencies.forEach { (name, content) -> jsCode.dependencies.forEach { (name, content) ->
outputFile.resolveSibling("$name.js").writeText(content) outputFile.resolveSibling("$name.js").writeText(content)
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -27,12 +27,12 @@ import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
class CompilerResult( class CompilerResult(
val jsCode: JsCode?, val outputs: CompilationOutputs?,
val dceJsCode: JsCode?, val outputsAfterDce: CompilationOutputs?,
val tsDefinitions: String? = null val tsDefinitions: String? = null
) )
class JsCode(val mainModule: String, val dependencies: Iterable<Pair<String, String>> = emptyList()) class CompilationOutputs(val jsCode: String, val dependencies: Iterable<Pair<String, String>> = emptyList())
fun compile( fun compile(
project: Project, project: Project,
@@ -174,5 +174,5 @@ fun generateJsCode(
jsPhases.invokeToplevel(PhaseConfig(jsPhases), context, listOf(moduleFragment)) jsPhases.invokeToplevel(PhaseConfig(jsPhases), context, listOf(moduleFragment))
val transformer = IrModuleToJsTransformer(context, null, true, nameTables) val transformer = IrModuleToJsTransformer(context, null, true, nameTables)
return transformer.generateModule(listOf(moduleFragment)).jsCode!!.mainModule return transformer.generateModule(listOf(moduleFragment)).outputs!!.jsCode
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
import org.jetbrains.kotlin.ir.backend.js.CompilerResult import org.jetbrains.kotlin.ir.backend.js.CompilerResult
import org.jetbrains.kotlin.ir.backend.js.JsCode import org.jetbrains.kotlin.ir.backend.js.CompilationOutputs
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.backend.js.eliminateDeadDeclarations import org.jetbrains.kotlin.ir.backend.js.eliminateDeadDeclarations
import org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator import org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator
@@ -72,7 +72,7 @@ class IrModuleToJsTransformer(
return CompilerResult(jsCode, dceJsCode, dts) return CompilerResult(jsCode, dceJsCode, dts)
} }
private fun generateWrappedModuleBody(modules: Iterable<IrModuleFragment>, exportedModule: ExportedModule, namer: NameTables): JsCode { private fun generateWrappedModuleBody(modules: Iterable<IrModuleFragment>, exportedModule: ExportedModule, namer: NameTables): CompilationOutputs {
if (multiModule) { if (multiModule) {
val refInfo = buildCrossModuleReferenceInfo(modules) val refInfo = buildCrossModuleReferenceInfo(modules)
@@ -104,9 +104,9 @@ class IrModuleToJsTransformer(
) )
}.reversed() }.reversed()
return JsCode(mainModule, dependencies) return CompilationOutputs(mainModule, dependencies)
} else { } else {
return JsCode( return CompilationOutputs(
generateWrappedModuleBody2( generateWrappedModuleBody2(
modules, modules,
emptyList(), emptyList(),
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -162,9 +162,9 @@ abstract class BasicIrBoxTest(
verifySignatures = !skipMangleVerification verifySignatures = !skipMangleVerification
) )
compiledModule.jsCode!!.writeTo(outputFile, config) compiledModule.outputs!!.writeTo(outputFile, config)
compiledModule.dceJsCode?.writeTo(dceOutputFile, config) compiledModule.outputsAfterDce?.writeTo(dceOutputFile, config)
if (generateDts) { if (generateDts) {
val dtsFile = outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts")!! val dtsFile = outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts")!!
@@ -192,7 +192,7 @@ abstract class BasicIrBoxTest(
safeExternalBoolean = safeExternalBoolean, safeExternalBoolean = safeExternalBoolean,
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic, safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic,
verifySignatures = !skipMangleVerification verifySignatures = !skipMangleVerification
).jsCode!!.writeTo(pirOutputFile, config) ).outputs!!.writeTo(pirOutputFile, config)
} }
} else { } else {
generateKLib( generateKLib(
@@ -223,9 +223,9 @@ abstract class BasicIrBoxTest(
return all.filter { it.name in phases }.toSet() return all.filter { it.name in phases }.toSet()
} }
private fun JsCode.writeTo(outputFile: File, config: JsConfig) { private fun CompilationOutputs.writeTo(outputFile: File, config: JsConfig) {
val wrappedCode = val wrappedCode =
wrapWithModuleEmulationMarkers(mainModule, moduleId = config.moduleId, moduleKind = config.moduleKind) wrapWithModuleEmulationMarkers(jsCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
outputFile.write(wrappedCode) outputFile.write(wrappedCode)
val dependencyPaths = mutableListOf<String>() val dependencyPaths = mutableListOf<String>()