[JS IR] Generate 'names' entries for functions in sourcemaps
This commit is contained in:
committed by
Space Team
parent
1d0025c3cf
commit
d9681caf0c
+27
-7
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins
|
||||
import org.jetbrains.kotlin.ir.backend.js.sourceMapsInfo
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -24,6 +21,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.common.isValidES5Identifier
|
||||
import org.jetbrains.kotlin.js.config.SourceMapNamesPolicy
|
||||
import org.jetbrains.kotlin.js.config.SourceMapSourceEmbedding
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
@@ -119,6 +117,7 @@ fun translateFunction(declaration: IrFunction, name: JsName?, context: JsGenerat
|
||||
val body = declaration.body?.accept(IrElementToJsStatementTransformer(), functionContext) as? JsBlock ?: JsBlock()
|
||||
|
||||
val function = JsFunction(emptyScope, body, "member function ${name ?: "annon"}")
|
||||
.withSource(declaration, context, useNameOf = declaration)
|
||||
|
||||
function.name = name
|
||||
|
||||
@@ -522,16 +521,18 @@ object JsAstUtils {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun <T : JsNode> T.withSource(node: IrElement, context: JsGenerationContext, originalName: String? = null): T {
|
||||
addSourceInfoIfNeed(node, context, originalName)
|
||||
internal fun <T : JsNode> T.withSource(node: IrElement, context: JsGenerationContext, useNameOf: IrDeclarationWithName? = null): T {
|
||||
addSourceInfoIfNeed(node, context, useNameOf)
|
||||
return this
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun <T : JsNode> T.addSourceInfoIfNeed(node: IrElement, context: JsGenerationContext, originalName: String?) {
|
||||
private inline fun <T : JsNode> T.addSourceInfoIfNeed(node: IrElement, context: JsGenerationContext, useNameOf: IrDeclarationWithName?) {
|
||||
|
||||
val sourceMapsInfo = context.staticContext.backendContext.sourceMapsInfo ?: return
|
||||
|
||||
val originalName = useNameOf?.originalNameForUseInSourceMap(sourceMapsInfo.namesPolicy)
|
||||
|
||||
val location = context.getLocationForIrElement(node, originalName) ?: return
|
||||
|
||||
val isNodeFromCurrentModule = context.currentFile.module.descriptor == context.staticContext.backendContext.module
|
||||
@@ -579,3 +580,22 @@ fun IrElement.getSourceInfo(fileEntry: IrFileEntry): JsLocation? {
|
||||
val startColumn = fileEntry.getColumnNumber(startOffset)
|
||||
return JsLocation(path, startLine, startColumn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a name of the original Kotlin declaration, or null, if it is a compiler generated declaration.
|
||||
*/
|
||||
private fun IrDeclarationWithName.originalNameForUseInSourceMap(policy: SourceMapNamesPolicy): String? {
|
||||
if (policy == SourceMapNamesPolicy.NO) return null
|
||||
when (this) {
|
||||
is IrField -> correspondingPropertySymbol?.let {
|
||||
return it.owner.originalNameForUseInSourceMap(policy)
|
||||
}
|
||||
|
||||
is IrFunction -> if (policy == SourceMapNamesPolicy.FULLY_QUALIFIED_NAMES) {
|
||||
fqNameWhenAvailable?.let {
|
||||
return it.asString()
|
||||
}
|
||||
}
|
||||
}
|
||||
return name.asString()
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,5 +18,5 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:6 box
|
||||
// test.kt:3 eval_0
|
||||
// test.kt:7 box$lambda
|
||||
// test.kt:3 eval
|
||||
// test.kt:7 box$lambda
|
||||
+1
-1
@@ -30,5 +30,5 @@ fun box() {
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:9 box
|
||||
// test.kt:11 box
|
||||
// test.kt:4 protoOf.foo_26di_k$
|
||||
// test.kt:4 foo
|
||||
// test.kt:5 box
|
||||
+2
-1
@@ -23,6 +23,7 @@ fun f(block: () -> Unit) {
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:3 box
|
||||
// test.kt:4 box
|
||||
// test.kt:4 box$lambda
|
||||
// test.kt:4 box
|
||||
// test.kt:10 f
|
||||
// test.kt:5
|
||||
// test.kt:5 box$lambda$lambda
|
||||
+3
-3
@@ -32,9 +32,9 @@ fun box() {
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:9 box
|
||||
// test.kt:10 box
|
||||
// test.kt:4 protoOf.foo_26di_k$
|
||||
// test.kt:4 foo
|
||||
// test.kt:11 box
|
||||
// test.kt:4 protoOf.foo_26di_k$
|
||||
// test.kt:4 foo
|
||||
// test.kt:5 box
|
||||
// test.kt:13 box
|
||||
// test.kt:5 box
|
||||
// test.kt:5 box
|
||||
+2
-2
@@ -36,5 +36,5 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:12 box
|
||||
// test.kt:4 A
|
||||
// test.kt:14 box
|
||||
// test.kt:4 <init>
|
||||
// test.kt:14 box
|
||||
+3
-3
@@ -40,9 +40,9 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:14 box
|
||||
// test.kt:5 Companion_19
|
||||
// test.kt:6 Companion_19
|
||||
// test.kt:5 <init>
|
||||
// test.kt:6 <init>
|
||||
// test.kt:15 box
|
||||
// test.kt:16 box
|
||||
// test.kt:16 box
|
||||
// test.kt:8 protoOf.foo_26di_k$
|
||||
// test.kt:8 foo
|
||||
+4
-4
@@ -34,10 +34,10 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:6 box
|
||||
// test.kt:3 A
|
||||
// test.kt:3 <init>
|
||||
// test.kt:7 box
|
||||
// test.kt:3 A
|
||||
// test.kt:3 <init>
|
||||
// test.kt:10 box
|
||||
// test.kt:3 A
|
||||
// test.kt:3 <init>
|
||||
// test.kt:12 box
|
||||
// test.kt:3 A
|
||||
// test.kt:3 <init>
|
||||
+5
-5
@@ -188,7 +188,7 @@ class O<T>(i: T) {
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:4 box
|
||||
// test.kt:5 box
|
||||
// test.kt:20 C
|
||||
// test.kt:20 <init>
|
||||
// test.kt:6 box
|
||||
// test.kt:22 D_init_$Init$
|
||||
// test.kt:7 box
|
||||
@@ -200,10 +200,10 @@ class O<T>(i: T) {
|
||||
// test.kt:33 G_init_$Init$
|
||||
// test.kt:34 G_init_$Init$
|
||||
// test.kt:10 box
|
||||
// test.kt:39 J
|
||||
// test.kt:39 <init>
|
||||
// test.kt:11 box
|
||||
// test.kt:42 K
|
||||
// test.kt:44 K
|
||||
// test.kt:42 <init>
|
||||
// test.kt:44 <init>
|
||||
// test.kt:12 box
|
||||
// test.kt:48 L_init_$Init$
|
||||
// test.kt:53 L
|
||||
@@ -218,4 +218,4 @@ class O<T>(i: T) {
|
||||
// test.kt:66 N_init_$Init$
|
||||
// test.kt:15 box
|
||||
// test.kt:16 box
|
||||
// test.kt:73 O_init_$Init$
|
||||
// test.kt:73 O_init_$Init$
|
||||
+33
-33
@@ -62,53 +62,53 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:13 box
|
||||
// test.kt:3 D
|
||||
// test.kt:3 D
|
||||
// test.kt:3 <init>
|
||||
// test.kt:3 <init>
|
||||
// test.kt:14 box
|
||||
// test.kt:3 D
|
||||
// test.kt:3 D
|
||||
// test.kt:3 <init>
|
||||
// test.kt:3 <init>
|
||||
// test.kt:14 box
|
||||
// test.kt:1 protoOf.equals
|
||||
// test.kt:1 protoOf.equals
|
||||
// test.kt:1 protoOf.equals
|
||||
// test.kt:1 protoOf.equals
|
||||
// test.kt:1 protoOf.equals
|
||||
// test.kt:1 protoOf.equals
|
||||
// test.kt:1 equals
|
||||
// test.kt:1 equals
|
||||
// test.kt:1 equals
|
||||
// test.kt:1 equals
|
||||
// test.kt:1 equals
|
||||
// test.kt:1 equals
|
||||
// test.kt:15 box
|
||||
// test.kt:1 protoOf.hashCode
|
||||
// test.kt:1 protoOf.hashCode
|
||||
// test.kt:1 hashCode
|
||||
// test.kt:1 hashCode
|
||||
// test.kt:16 box
|
||||
// test.kt:1 protoOf.toString
|
||||
// test.kt:1 toString
|
||||
// test.kt:17 box
|
||||
// test.kt:17 box
|
||||
// test.kt:1 protoOf.component1_7eebsc_k$
|
||||
// test.kt:1 component1
|
||||
// test.kt:17 box
|
||||
// test.kt:1 protoOf.component2_7eebsb_k$
|
||||
// test.kt:1 component2
|
||||
// test.kt:18 box
|
||||
// test.kt:1 protoOf.copy$default_roih85_k$
|
||||
// test.kt:1 protoOf.copy$default_roih85_k$
|
||||
// test.kt:1 protoOf.copy$default_roih85_k$
|
||||
// test.kt:1 protoOf.copy_t8q04r_k$
|
||||
// test.kt:3 D
|
||||
// test.kt:3 D
|
||||
// test.kt:1 copy$default
|
||||
// test.kt:1 copy$default
|
||||
// test.kt:1 copy$default
|
||||
// test.kt:1 copy
|
||||
// test.kt:3 <init>
|
||||
// test.kt:3 <init>
|
||||
// test.kt:19 box
|
||||
// test.kt:5 E
|
||||
// test.kt:5 E
|
||||
// test.kt:5 <init>
|
||||
// test.kt:5 <init>
|
||||
// test.kt:20 box
|
||||
// test.kt:5 E
|
||||
// test.kt:5 E
|
||||
// test.kt:5 <init>
|
||||
// test.kt:5 <init>
|
||||
// test.kt:20 box
|
||||
// test.kt:7 protoOf.equals
|
||||
// test.kt:7 equals
|
||||
// test.kt:21 box
|
||||
// test.kt:8 protoOf.hashCode
|
||||
// test.kt:8 hashCode
|
||||
// test.kt:22 box
|
||||
// test.kt:6 protoOf.toString
|
||||
// test.kt:6 toString
|
||||
// test.kt:23 box
|
||||
// test.kt:23 box
|
||||
// test.kt:1 protoOf.component1_7eebsc_k$
|
||||
// test.kt:1 component1
|
||||
// test.kt:23 box
|
||||
// test.kt:1 protoOf.component2_7eebsb_k$
|
||||
// test.kt:1 component2
|
||||
// test.kt:24 box
|
||||
// test.kt:9 protoOf.copy_1tks5_k$
|
||||
// test.kt:5 E
|
||||
// test.kt:5 E
|
||||
// test.kt:9 copy
|
||||
// test.kt:5 <init>
|
||||
// test.kt:5 <init>
|
||||
+5
-5
@@ -26,8 +26,8 @@ fun box() {
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:11 box
|
||||
// test.kt:11 box
|
||||
// test.kt:6 protoOf.foo$default_ourpn2_k$
|
||||
// test.kt:4 protoOf.computeParam_vubdyi_k$
|
||||
// test.kt:6 protoOf.foo$default_ourpn2_k$
|
||||
// test.kt:6 protoOf.foo$default_ourpn2_k$
|
||||
// test.kt:6 protoOf.foo$default_ourpn2_k$
|
||||
// test.kt:6 foo$default
|
||||
// test.kt:4 computeParam
|
||||
// test.kt:6 foo$default
|
||||
// test.kt:6 foo$default
|
||||
// test.kt:6 foo$default
|
||||
+6
-5
@@ -54,11 +54,12 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:22 box
|
||||
// test.kt:11 E
|
||||
// test.kt:11 E
|
||||
// test.kt:11 <init>
|
||||
// test.kt:11 <init>
|
||||
// test.kt:22 box
|
||||
// test.kt:9 protoOf.foo_26di_k$
|
||||
// test.kt:9 foo
|
||||
// test.kt:7 E$foo$lambda
|
||||
// test.kt:15 E2_initEntries
|
||||
// test.kt:14 E2
|
||||
// test.kt:14 <init>
|
||||
// test.kt:17 E2_initEntries
|
||||
// test.kt:14 E2
|
||||
// test.kt:14 <init>
|
||||
@@ -35,4 +35,4 @@ fun foo(f: () -> Unit) {
|
||||
// test.kt:5 box$lambda
|
||||
// test.kt:8 box
|
||||
// test.kt:14 foo
|
||||
// test.kt:9 box$lambda_0
|
||||
// test.kt:9 box$lambda
|
||||
+10
-10
@@ -109,18 +109,18 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:48 box
|
||||
// test.kt:7 Foo
|
||||
// test.kt:7 <init>
|
||||
// test.kt:45 x
|
||||
// test.kt:49 box
|
||||
// test.kt:13 Bar
|
||||
// test.kt:17 Bar
|
||||
// test.kt:13 <init>
|
||||
// test.kt:17 <init>
|
||||
// test.kt:50 box
|
||||
// test.kt:23 Boo
|
||||
// test.kt:26 Boo
|
||||
// test.kt:23 <init>
|
||||
// test.kt:26 <init>
|
||||
// test.kt:45 x
|
||||
// test.kt:29 Boo
|
||||
// test.kt:29 <init>
|
||||
// test.kt:51 box
|
||||
// test.kt:34 Zoo
|
||||
// test.kt:36 Zoo
|
||||
// test.kt:39 Zoo
|
||||
// test.kt:42 Zoo
|
||||
// test.kt:34 <init>
|
||||
// test.kt:36 <init>
|
||||
// test.kt:39 <init>
|
||||
// test.kt:42 <init>
|
||||
+6
-6
@@ -54,10 +54,10 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:29 box
|
||||
// test.kt:8 Companion_19
|
||||
// test.kt:11 Companion_19
|
||||
// test.kt:8 <init>
|
||||
// test.kt:11 <init>
|
||||
// test.kt:26 x
|
||||
// test.kt:13 Companion_19
|
||||
// test.kt:16 Companion_19
|
||||
// test.kt:21 Companion_19
|
||||
// test.kt:30 box
|
||||
// test.kt:13 <init>
|
||||
// test.kt:16 <init>
|
||||
// test.kt:21 <init>
|
||||
// test.kt:30 box
|
||||
+2
-2
@@ -27,5 +27,5 @@ fun box() {
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:15 box
|
||||
// test.kt:5 A
|
||||
// test.kt:15 box
|
||||
// test.kt:5 <init>
|
||||
// test.kt:15 box
|
||||
+1
-1
@@ -45,4 +45,4 @@ fun baz(v:(() -> Unit)) {
|
||||
// test.kt:5 box
|
||||
// test.kt:6 box
|
||||
// test3.kt:14 baz
|
||||
// test1.kt:8 box$lambda_0
|
||||
// test1.kt:8 box$lambda
|
||||
@@ -32,7 +32,8 @@ fun g() {}
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:3 box
|
||||
// test.kt:4 box
|
||||
// test.kt:4 g$ref
|
||||
// test.kt:4 box
|
||||
// test.kt:8 f
|
||||
// test.kt:4 l
|
||||
// test.kt:4 l
|
||||
// test.kt:4 g$ref$lambda
|
||||
// test.kt:4 g$ref$lambda
|
||||
+1
-1
@@ -22,4 +22,4 @@ fun box() {
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:11 box
|
||||
// test.kt:11 box
|
||||
// test.kt:6 protoOf.get_prop_wosl9o_k$
|
||||
// test.kt:6 <get-prop>
|
||||
@@ -19,7 +19,7 @@ suspend fun box() {
|
||||
// test.kt:11 box
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:8 protoOf.doResume_5yljmg_k$
|
||||
// test.kt:8 doResume
|
||||
// test.kt:4 foo
|
||||
// test.kt:4 foo
|
||||
// test.kt:9 box$lambda
|
||||
// test.kt:9 box$lambda
|
||||
Reference in New Issue
Block a user