[JS IR] Fix sourcemap path mapping in compiler tests for Windows

This commit is contained in:
Sergej Jaskiewicz
2022-06-16 04:21:44 -07:00
committed by Space
parent 1241565cce
commit 15bd101110
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.js.test.handlers
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.TranslationMode import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.TranslationMode
import org.jetbrains.kotlin.js.parser.sourcemaps.* 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.TestServices
import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator
import org.jetbrains.kotlin.test.services.jsLibraryProvider import org.jetbrains.kotlin.test.services.jsLibraryProvider
@@ -37,20 +38,21 @@ class JsSourceMapPathRewriter(testServices: TestServices) : AbstractJsArtifactsC
val dependencies = JsEnvironmentConfigurator.getAllRecursiveDependenciesFor(module, testServices) val dependencies = JsEnvironmentConfigurator.getAllRecursiveDependenciesFor(module, testServices)
SourceMap.replaceSources(sourceMapFile) { path -> SourceMap.replaceSources(sourceMapFile) { path ->
allTestFiles.find { it.name == path }?.originalFile?.absolutePath?.let { tryToMapTestFile(allTestFiles, path)
return@replaceSources it ?: tryToMapLibrarySourceFile(dependencies, path)
} ?: path
tryToMapLibrarySourceFile(dependencies, path)?.let {
return@replaceSources it
}
path
} }
} }
} }
} }
private fun tryToMapTestFile(allTestFiles: Iterable<TestFile>, 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. * 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. * May not work in 100% of cases, but should be good enough for our tests.