[JS] Support the 'names' field in sourcemaps

This commit is contained in:
Sergej Jaskiewicz
2022-09-29 15:06:42 +02:00
committed by Space Team
parent 227864c6ec
commit 1d0025c3cf
9 changed files with 92 additions and 31 deletions
@@ -522,17 +522,17 @@ object JsAstUtils {
}
}
internal fun <T : JsNode> T.withSource(node: IrElement, context: JsGenerationContext): T {
addSourceInfoIfNeed(node, context)
internal fun <T : JsNode> T.withSource(node: IrElement, context: JsGenerationContext, originalName: String? = null): T {
addSourceInfoIfNeed(node, context, originalName)
return this
}
@Suppress("NOTHING_TO_INLINE")
private inline fun <T : JsNode> T.addSourceInfoIfNeed(node: IrElement, context: JsGenerationContext) {
private inline fun <T : JsNode> T.addSourceInfoIfNeed(node: IrElement, context: JsGenerationContext, originalName: String?) {
val sourceMapsInfo = context.staticContext.backendContext.sourceMapsInfo ?: return
val location = context.getLocationForIrElement(node) ?: return
val location = context.getLocationForIrElement(node, originalName) ?: return
val isNodeFromCurrentModule = context.currentFile.module.descriptor == context.staticContext.backendContext.module
@@ -87,9 +87,9 @@ class JsGenerationContext(
fun checkIfHasAssociatedJsCode(symbol: IrFunctionSymbol): Boolean = staticContext.backendContext.getJsCodeForFunction(symbol) != null
fun getLocationForIrElement(irElement: IrElement): JsLocation? {
fun getLocationForIrElement(irElement: IrElement, originalName: String? = null): JsLocation? {
return locationCache.getOrPut(irElement.startOffset) {
irElement.getSourceInfo(currentFile.fileEntry) ?: return null
}
}.copy(name = originalName)
}
}