[JS IR] Emit original names for local vars to sourcemaps

#KT-35655 Fixed
This commit is contained in:
Sergej Jaskiewicz
2022-11-01 19:19:25 +01:00
committed by Space Team
parent 8efa72ca36
commit 7b7c517dbb
114 changed files with 1970 additions and 376 deletions
@@ -26,3 +26,32 @@ class CodePosition(val line: Int, val offset: Int) : Comparable<CodePosition> {
override fun toString(): String = "($line, $offset)"
}
/**
* Calculates an offset from the start of a text for a position,
* defined by line and offset in that line.
*/
fun String.offsetOf(position: CodePosition): Int {
var i = 0
var lineCount = 0
var offsetInLine = 0
while (i < length) {
val c = this[i]
if (lineCount == position.line && offsetInLine == position.offset) {
return i
}
i++
offsetInLine++
if (Utils.isEndOfLine(c.code)) {
offsetInLine = 0
lineCount++
assert(lineCount <= position.line)
}
}
return length
}