Skip to content

Commit

Permalink
Do not mangle the value field of JsEnum.
Browse files Browse the repository at this point in the history
This is a special field for JsEnum type and J2CL transpiler relies on the name in the JsInterop restriction checker.

PiperOrigin-RevId: 586094417
  • Loading branch information
jDramaix authored and copybara-github committed Nov 28, 2023
1 parent 1db7ed0 commit 6c25158
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,7 +49,7 @@ internal val CompilationUnit.topLevelQualifiedNamesSet: Set<String>

/** 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand All @@ -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!!
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ enum class NativeEnum {
OK;

@JvmField
internal var value_pp_nativejstypes: String? = null
internal var value: String? = null
}

0 comments on commit 6c25158

Please sign in to comment.