From 9176ba5b2d948f8bf4c120a0ad3d89ba5292ebcd Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Wed, 7 Sep 2022 17:47:48 +0200 Subject: [PATCH] [JS IR] Don't set fileIdentity when embedding sources into sourcemaps (see the comment) --- .../js/transformers/irToJs/jsAstUtils.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt index e11189bf179..a706fe96d7d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt @@ -515,14 +515,23 @@ private inline fun T.addSourceInfoIfNeed(node: IrElement, context: } private fun JsLocation.withEmbeddedSource( + @Suppress("UNUSED_PARAMETER") context: JsGenerationContext -) = JsLocationWithEmbeddedSource(this, fileIdentity = context.currentFile) { - try { - InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8) - } catch (e: IOException) { - // TODO: If the source file is not available at path (e. g. it's an stdlib file), use heuristics to find it. - // If all heuristics fail, use dumpKotlinLike() on freshly deserialized IrFile. - null +): JsLocationWithEmbeddedSource { + // FIXME: fileIdentity is used to distinguish between different files with the same paths. + // For now we use the file's path to read its content, which makes fileIdentity useless. + // However, when we have a mechanism to reliably get the source code from an IrFile or IrFileEntry no matter what's stored + // in fileEntry.name (including the source code for external libraries or klibs with relative paths in them). + // Another issue is that JS AST serializer/deserializer ignores fileIdentity, which means that this will not work with incremental + // compilation. + return JsLocationWithEmbeddedSource(this, fileIdentity = null /*context.currentFile.fileEntry*/) { + try { + InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8) + } catch (e: IOException) { + // TODO: If the source file is not available at path (e. g. it's an stdlib file), use heuristics to find it. + // If all heuristics fail, use dumpKotlinLike() on freshly deserialized IrFile. + null + } } }