From 15bd101110ab9a8277d523ae4fb7ff32af73e5ed Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Thu, 16 Jun 2022 04:21:44 -0700 Subject: [PATCH] [JS IR] Fix sourcemap path mapping in compiler tests for Windows --- .../test/handlers/JsSourceMapPathRewriter.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsSourceMapPathRewriter.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsSourceMapPathRewriter.kt index a29b84c6fec..eed005a13ba 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsSourceMapPathRewriter.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsSourceMapPathRewriter.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.js.test.handlers import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.TranslationMode import org.jetbrains.kotlin.js.parser.sourcemaps.* +import org.jetbrains.kotlin.test.model.TestFile import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator import org.jetbrains.kotlin.test.services.jsLibraryProvider @@ -37,20 +38,21 @@ class JsSourceMapPathRewriter(testServices: TestServices) : AbstractJsArtifactsC val dependencies = JsEnvironmentConfigurator.getAllRecursiveDependenciesFor(module, testServices) SourceMap.replaceSources(sourceMapFile) { path -> - allTestFiles.find { it.name == path }?.originalFile?.absolutePath?.let { - return@replaceSources it - } - - tryToMapLibrarySourceFile(dependencies, path)?.let { - return@replaceSources it - } - - path + tryToMapTestFile(allTestFiles, path) + ?: tryToMapLibrarySourceFile(dependencies, path) + ?: path } } } } + private fun tryToMapTestFile(allTestFiles: Iterable, sourceMapPath: String): String? { + val testFile = allTestFiles.find { it.name == sourceMapPath } + ?: allTestFiles.find { "/${it.name}" == sourceMapPath } + ?: return null + return testFile.originalFile.absolutePath + } + /** * Some heuristics to find the library source file that this [sourceMapPath] should point to. * May not work in 100% of cases, but should be good enough for our tests.