[JS IR] Don't set fileIdentity when embedding sources into sourcemaps

(see the comment)
This commit is contained in:
Sergej Jaskiewicz
2022-09-07 17:47:48 +02:00
committed by Space
parent 64465480a3
commit 9176ba5b2d
@@ -515,8 +515,16 @@ private inline fun <T : JsNode> T.addSourceInfoIfNeed(node: IrElement, context:
} }
private fun JsLocation.withEmbeddedSource( private fun JsLocation.withEmbeddedSource(
@Suppress("UNUSED_PARAMETER")
context: JsGenerationContext context: JsGenerationContext
) = JsLocationWithEmbeddedSource(this, fileIdentity = context.currentFile) { ): 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 { try {
InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8) InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8)
} catch (e: IOException) { } catch (e: IOException) {
@@ -525,6 +533,7 @@ private fun JsLocation.withEmbeddedSource(
null null
} }
} }
}
fun IrElement.getSourceInfo(container: IrDeclaration): JsLocation? { fun IrElement.getSourceInfo(container: IrDeclaration): JsLocation? {
val fileEntry = container.fileOrNull?.fileEntry ?: return null val fileEntry = container.fileOrNull?.fileEntry ?: return null