From 6c2515830f4c12c20fc1064ee5958dfa7b280eb2 Mon Sep 17 00:00:00 2001 From: Julien Dramaix Date: Tue, 28 Nov 2023 13:53:24 -0800 Subject: [PATCH] Do not mangle the `value` field of JsEnum. This is a special field for JsEnum type and J2CL transpiler relies on the name in the JsInterop restriction checker. PiperOrigin-RevId: 586094417 --- .../j2cl/transpiler/backend/kotlin/Names.kt | 3 ++- .../readable/java/jsenum/output_kt/Main.kt.txt | 18 +++++++++--------- .../nativejstypes/output_kt/NativeEnum.kt.txt | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/transpiler/java/com/google/j2cl/transpiler/backend/kotlin/Names.kt b/transpiler/java/com/google/j2cl/transpiler/backend/kotlin/Names.kt index c6ab92c919..a9e172859c 100644 --- a/transpiler/java/com/google/j2cl/transpiler/backend/kotlin/Names.kt +++ b/transpiler/java/com/google/j2cl/transpiler/backend/kotlin/Names.kt @@ -16,6 +16,7 @@ package com.google.j2cl.transpiler.backend.kotlin import com.google.j2cl.transpiler.ast.ArrayTypeDescriptor +import com.google.j2cl.transpiler.ast.AstUtils import com.google.j2cl.transpiler.ast.CompilationUnit import com.google.j2cl.transpiler.ast.DeclaredTypeDescriptor import com.google.j2cl.transpiler.ast.Field @@ -48,7 +49,7 @@ internal val CompilationUnit.topLevelQualifiedNamesSet: Set /** Kotlin mangled name for this member descriptor. */ internal val MemberDescriptor.ktMangledName: String - get() = ktName + ktNameSuffix + get() = if (AstUtils.isJsEnumCustomValueField(this)) name!! else ktName + ktNameSuffix /** Kotlin name suffix for this member descriptor. */ private val MemberDescriptor.ktNameSuffix: String diff --git a/transpiler/javatests/com/google/j2cl/readable/java/jsenum/output_kt/Main.kt.txt b/transpiler/javatests/com/google/j2cl/readable/java/jsenum/output_kt/Main.kt.txt index 89f7ec8ed9..c6891f7bef 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/jsenum/output_kt/Main.kt.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/jsenum/output_kt/Main.kt.txt @@ -180,15 +180,15 @@ open class Main { ELEVEN(11); @JvmField - internal var value_private_2: Int = 0 + internal var value: Int = 0 @ObjCName("getValue") fun getValue(): Int { - return this.value_private_2 + return this.value } constructor(value: Int) { - this.value_private_2 = value + this.value = value } } @@ -198,15 +198,15 @@ open class Main { THREE("THREE"); @JvmField - internal var value_private_2: String? = null + internal var value: String? = null @ObjCName("getValue") fun getValue(): String? { - return this.value_private_2 + return this.value } constructor(value: String?) { - this.value_private_2 = value + this.value = value } } @@ -216,15 +216,15 @@ open class Main { THREE("THREE"); @JvmField - internal var value_private_2: String + internal var value: String @ObjCName("getValue") fun getValue(): String? { - return this.value_private_2 + return this.value } constructor(value: String?) { - this.value_private_2 = value!! + this.value = value!! } } diff --git a/transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/output_kt/NativeEnum.kt.txt b/transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/output_kt/NativeEnum.kt.txt index 2608611675..a3c442debc 100644 --- a/transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/output_kt/NativeEnum.kt.txt +++ b/transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/output_kt/NativeEnum.kt.txt @@ -33,5 +33,5 @@ enum class NativeEnum { OK; @JvmField - internal var value_pp_nativejstypes: String? = null + internal var value: String? = null }