From 64c6d852de6d459c866100e63f31496195e98563 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Thu, 1 Jul 2021 20:39:16 +0300 Subject: [PATCH] [JS IR] Preparing for introducing sourcemap as another compilation output * Rename `JsCode` to `CompilationOutputs`. * Rename members of CompilerResult. #KT-46551 In Progress --- .../org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 6 +++--- .../org/jetbrains/kotlin/ir/backend/js/compiler.kt | 10 +++++----- .../transformers/irToJs/IrModuleToJsTransformer.kt | 10 +++++----- .../org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt | 12 ++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index e8b00d321bb..02434c03820 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -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. */ @@ -284,8 +284,8 @@ class K2JsIrCompiler : CLICompiler() { ), ) - val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!! - outputFile.writeText(jsCode.mainModule) + val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.outputsAfterDce!! else compiledModule.outputs!! + outputFile.writeText(jsCode.jsCode) jsCode.dependencies.forEach { (name, content) -> outputFile.resolveSibling("$name.js").writeText(content) } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index 8af7076d130..703553003be 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -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. */ @@ -27,12 +27,12 @@ import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult import org.jetbrains.kotlin.name.FqName class CompilerResult( - val jsCode: JsCode?, - val dceJsCode: JsCode?, + val outputs: CompilationOutputs?, + val outputsAfterDce: CompilationOutputs?, val tsDefinitions: String? = null ) -class JsCode(val mainModule: String, val dependencies: Iterable> = emptyList()) +class CompilationOutputs(val jsCode: String, val dependencies: Iterable> = emptyList()) fun compile( project: Project, @@ -174,5 +174,5 @@ fun generateJsCode( jsPhases.invokeToplevel(PhaseConfig(jsPhases), context, listOf(moduleFragment)) val transformer = IrModuleToJsTransformer(context, null, true, nameTables) - return transformer.generateModule(listOf(moduleFragment)).jsCode!!.mainModule + return transformer.generateModule(listOf(moduleFragment)).outputs!!.jsCode } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt index 90c465aef27..a1f3ab9dbde 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrModuleToJsTransformer.kt @@ -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. */ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs 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.eliminateDeadDeclarations import org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator @@ -72,7 +72,7 @@ class IrModuleToJsTransformer( return CompilerResult(jsCode, dceJsCode, dts) } - private fun generateWrappedModuleBody(modules: Iterable, exportedModule: ExportedModule, namer: NameTables): JsCode { + private fun generateWrappedModuleBody(modules: Iterable, exportedModule: ExportedModule, namer: NameTables): CompilationOutputs { if (multiModule) { val refInfo = buildCrossModuleReferenceInfo(modules) @@ -104,9 +104,9 @@ class IrModuleToJsTransformer( ) }.reversed() - return JsCode(mainModule, dependencies) + return CompilationOutputs(mainModule, dependencies) } else { - return JsCode( + return CompilationOutputs( generateWrappedModuleBody2( modules, emptyList(), diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 2244221750f..8499f8bcabe 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -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. */ @@ -162,9 +162,9 @@ abstract class BasicIrBoxTest( verifySignatures = !skipMangleVerification ) - compiledModule.jsCode!!.writeTo(outputFile, config) + compiledModule.outputs!!.writeTo(outputFile, config) - compiledModule.dceJsCode?.writeTo(dceOutputFile, config) + compiledModule.outputsAfterDce?.writeTo(dceOutputFile, config) if (generateDts) { val dtsFile = outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts")!! @@ -192,7 +192,7 @@ abstract class BasicIrBoxTest( safeExternalBoolean = safeExternalBoolean, safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic, verifySignatures = !skipMangleVerification - ).jsCode!!.writeTo(pirOutputFile, config) + ).outputs!!.writeTo(pirOutputFile, config) } } else { generateKLib( @@ -223,9 +223,9 @@ abstract class BasicIrBoxTest( 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 = - wrapWithModuleEmulationMarkers(mainModule, moduleId = config.moduleId, moduleKind = config.moduleKind) + wrapWithModuleEmulationMarkers(jsCode, moduleId = config.moduleId, moduleKind = config.moduleKind) outputFile.write(wrappedCode) val dependencyPaths = mutableListOf()