diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java b/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java index 5c248c7e938..58002768d41 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/translate/utils/AnnotationsUtils.java @@ -100,6 +100,9 @@ public final class AnnotationsUtils { continue; } String name = getNameForAnnotatedObject(descriptor, annotation); + if (name == null) { + name = getJsName(descriptor); + } return name != null ? name : descriptor.getName().asString(); } } diff --git a/js/js.translator/testData/native/cases/jsName.kt b/js/js.translator/testData/native/cases/jsName.kt new file mode 100644 index 00000000000..b3a0b3c9d83 --- /dev/null +++ b/js/js.translator/testData/native/cases/jsName.kt @@ -0,0 +1,36 @@ +package foo + +@JsName("bar") @native fun foo(): Int = noImpl + +@JsName("baz") @native val prop: Int get() = noImpl + +@JsName("B") @native class A { + @JsName("g") fun f(): Int = noImpl + + @JsName("q") val p: Int get() = noImpl + + companion object { + @JsName("g") fun f(): Int = noImpl + + @JsName("q") val p: Int get() = noImpl + } +} + +@JsName("P") @native object O { + fun f(): Int = noImpl +} + +fun box(): String { + assertEquals(23, foo()) + assertEquals(123, prop) + + assertEquals(42, A().f()) + assertEquals(32, A().p) + + assertEquals(142, A.f()) + assertEquals(132, A.p) + + assertEquals(222, O.f()) + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/native/native/jsName.js b/js/js.translator/testData/native/native/jsName.js new file mode 100644 index 00000000000..a8ed6b3d7fc --- /dev/null +++ b/js/js.translator/testData/native/native/jsName.js @@ -0,0 +1,13 @@ +var bar = function() { return 23; }; +var baz = 123; + +function B() { + this.q = 32; +} +B.prototype.g = function() { return 42; }; +B.q = 132; +B.g = function() { return 142; }; + +var P = { + f: function() { return 222; } +}; \ No newline at end of file