Sanitize names for backing fields and private declarations in JS BE
See KT-1816
This commit is contained in:
@@ -322,7 +322,10 @@ class NameSuggestion {
|
||||
|
||||
@JvmStatic fun getPrivateMangledName(baseName: String, descriptor: CallableDescriptor): String {
|
||||
val ownerName = descriptor.containingDeclaration.fqNameUnsafe.asString()
|
||||
return getStableMangledName(baseName, ownerName + ":" + encodeSignature(descriptor))
|
||||
|
||||
// Base name presents here since name part gets sanitized, so we have to produce different suffixes to distinguish
|
||||
// between, say `.` and `;`.
|
||||
return getStableMangledName(sanitizeName(baseName), ownerName + "." + baseName + ":" + encodeSignature(descriptor))
|
||||
}
|
||||
|
||||
fun getInternalMangledName(suggestedName: String, forCalculateId: String): String {
|
||||
|
||||
@@ -1166,6 +1166,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("peculiarName.kt")
|
||||
public void testPeculiarName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/delegateProperty/peculiarName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyMetadata.kt")
|
||||
public void testPropertyMetadata() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/delegateProperty/propertyMetadata.kt");
|
||||
@@ -2536,6 +2542,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateDeclarations.kt")
|
||||
public void testPrivateDeclarations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/identifierClash/privateDeclarations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("useVariableOfNameOfFunction.kt")
|
||||
public void testUseVariableOfNameOfFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/identifierClash/useVariableOfNameOfFunction.kt");
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1006
|
||||
class X(private val x: String) {
|
||||
operator fun getValue(thisRef: Any?, property: Any): String = x
|
||||
}
|
||||
|
||||
class C {
|
||||
@JsName("a") val `;`: String by X("foo")
|
||||
|
||||
private val `.`: String by X("bar")
|
||||
|
||||
private val `@`: String by X("baz")
|
||||
|
||||
fun bar(): String = `.`
|
||||
|
||||
fun baz(): String = `@`
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
if (c.`;` != "foo") return "fail1: ${c.`;`}"
|
||||
if (c.bar() != "bar") return "fail2: ${c.bar()}"
|
||||
if (c.baz() != "baz") return "fail3: ${c.baz()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1000
|
||||
open class A {
|
||||
private val `.` = "A"
|
||||
private val `;` = "B"
|
||||
|
||||
private fun `@`() = "C"
|
||||
private fun `#`() = "D"
|
||||
|
||||
fun foo() = `.` + `;` + `@`() + `#`()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A().foo()
|
||||
if (x != "ABCD") return "fail: $x"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user