From 0320d49ddca48780006d7de004deda8008d31786 Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Mon, 23 May 2022 21:54:03 +0300 Subject: [PATCH] [JS IR] Generate sourcemaps for JS IR tests --- .../src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 6 +----- .../src/org/jetbrains/kotlin/ir/backend/js/compiler.kt | 9 +++++++++ .../kotlin/js/test/converters/JsIrBackendFacade.kt | 4 ++++ 3 files changed, 14 insertions(+), 5 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 928ac465959..3f6214553c4 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 @@ -458,11 +458,7 @@ class K2JsIrCompiler : CLICompiler() { private fun File.write(outputs: CompilationOutputs) { writeText(outputs.jsCode) - outputs.sourceMap?.let { - val mapFile = resolveSibling("$name.map") - appendText("\n//# sourceMappingURL=${mapFile.name}") - mapFile.writeText(it) - } + outputs.writeSourceMapIfPresent(this) } override fun setupPlatformSpecificArgumentsAndServices( 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 673f815c9f7..a2b9ae39865 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 @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.js.backend.ast.JsProgram import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.RuntimeDiagnostic import org.jetbrains.kotlin.name.FqName +import java.io.File class CompilerResult( val outputs: Map, @@ -167,3 +168,11 @@ fun generateJsCode( val transformer = IrModuleToJsTransformer(context, null, true, nameTables) return transformer.generateModule(listOf(moduleFragment)).outputs[TranslationMode.FULL]!!.jsCode } + +fun CompilationOutputs.writeSourceMapIfPresent(outputJsFile: File) { + sourceMap?.let { + val mapFile = outputJsFile.resolveSibling("${outputJsFile.name}.map") + outputJsFile.appendText("\n//# sourceMappingURL=${mapFile.name}\n") + mapFile.writeText(it) + } +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt index da5602bba0e..930828d0905 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt @@ -326,6 +326,10 @@ class JsIrBackendFacade( val wrappedCode = ClassicJsBackendFacade.wrapWithModuleEmulationMarkers(jsCode, moduleId = moduleId, moduleKind = moduleKind) outputFile.write(wrappedCode) + if (moduleKind == ModuleKind.PLAIN) { + writeSourceMapIfPresent(outputFile) + } + dependencies.forEach { (moduleId, outputs) -> val moduleWrappedCode = ClassicJsBackendFacade.wrapWithModuleEmulationMarkers(outputs.jsCode, moduleKind, moduleId) outputFile.augmentWithModuleName(moduleId).write(moduleWrappedCode)