[JS IR] Don't use full paths when generating comments with a path for file blocks

This commit is contained in:
Zalim Bashorov
2019-11-20 22:57:32 +03:00
parent c05c07f243
commit 3fa431e114
3 changed files with 33 additions and 10 deletions
@@ -44,6 +44,7 @@ class IrModuleToJsTransformer(
statements.addWithComment("block: pre-declaration", preDeclarationBlock)
val generateFilePaths = backendContext.configuration.getBoolean(JSConfigurationKeys.GENERATE_COMMENTS_WITH_FILE_PATH)
val pathPrefixMap = backendContext.configuration.getMap(JSConfigurationKeys.FILE_PATHS_PREFIX_MAP)
module.files.forEach {
val fileStatements = it.accept(IrFileToJsTransformer(), context).statements
@@ -55,7 +56,13 @@ class IrModuleToJsTransformer(
}
if (generateRegionComments || generateFilePaths) {
startComment += "file: ${it.path}"
val originalPath = it.path
val path = pathPrefixMap.entries
.find { (k, _) -> originalPath.startsWith(k) }
?.let { (k, v) -> v + originalPath.substring(k.length) }
?: originalPath
startComment += "file: $path"
}
if (startComment.isNotEmpty()) {