From 54c00cc588f2511983845dcf624b27739ec33e3c Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 6 Dec 2022 16:17:50 +0100 Subject: [PATCH] [Sourcemap] Add an ability to provide outputColumn to SourceMap3Builder#addMapping instead of using getCurrentOutputColumn The ability will be used later by wasm backend while generating sourcemap. --- .../kotlin/js/sourceMap/SourceMap3Builder.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.kt b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.kt index ffe03aaed8b..d370f5c0452 100644 --- a/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.kt +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.kt @@ -125,6 +125,18 @@ class SourceMap3Builder( sourceLine: Int, sourceColumn: Int, name: String?, + ) { + addMapping(source, fileIdentity, sourceContent, sourceLine, sourceColumn, name, getCurrentOutputColumn()) + } + + fun addMapping( + source: String, + fileIdentity: Any?, + sourceContent: Supplier, + sourceLine: Int, + sourceColumn: Int, + name: String?, + outputColumn: Int ) { val sourceIndex = getSourceIndex(source.replace(File.separatorChar, '/'), fileIdentity, sourceContent) @@ -138,7 +150,7 @@ class SourceMap3Builder( return } - startMapping() + startMapping(outputColumn) Base64VLQ.encode(out, sourceIndex - previousSourceIndex) previousSourceIndex = sourceIndex @@ -159,19 +171,17 @@ class SourceMap3Builder( override fun addEmptyMapping() { if (!currentMappingIsEmpty) { - startMapping() + startMapping(getCurrentOutputColumn()) currentMappingIsEmpty = true } } - private fun startMapping() { + private fun startMapping(column: Int) { val newGroupStarted = previousGeneratedColumn == -1 if (newGroupStarted) { previousGeneratedColumn = 0 } - val column = getCurrentOutputColumn() - val columnDiff = column - previousGeneratedColumn if (!newGroupStarted) { out.append(',')