JS: declare names for native declaration in root scope, to avoid clashing between inner names and global native names. Fix KT-14806
This commit is contained in:
@@ -5552,6 +5552,18 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nativeAndTopLevelFunction.kt")
|
||||||
|
public void testNativeAndTopLevelFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/nameClashes/nativeAndTopLevelFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nativeDeclarationAndLocalVar.kt")
|
||||||
|
public void testNativeDeclarationAndLocalVar() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/nameClashes/nativeDeclarationAndLocalVar.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadExtension.kt")
|
@TestMetadata("overloadExtension.kt")
|
||||||
public void testOverloadExtension() throws Exception {
|
public void testOverloadExtension() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/nameClashes/overloadExtension.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/nameClashes/overloadExtension.kt");
|
||||||
|
|||||||
@@ -352,6 +352,10 @@ public final class StaticContext {
|
|||||||
if (DynamicCallsKt.isDynamic(suggested.getDescriptor())) {
|
if (DynamicCallsKt.isDynamic(suggested.getDescriptor())) {
|
||||||
scope = JsDynamicScope.INSTANCE;
|
scope = JsDynamicScope.INSTANCE;
|
||||||
}
|
}
|
||||||
|
else if (AnnotationsUtils.isPredefinedObject(suggested.getDescriptor()) &&
|
||||||
|
DescriptorUtils.isTopLevelDeclaration(suggested.getDescriptor())) {
|
||||||
|
scope = rootScope;
|
||||||
|
}
|
||||||
|
|
||||||
List<JsName> names = new ArrayList<JsName>();
|
List<JsName> names = new ArrayList<JsName>();
|
||||||
if (suggested.getStable()) {
|
if (suggested.getStable()) {
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ fun box(): String {
|
|||||||
assertEquals("A::foo", f())
|
assertEquals("A::foo", f())
|
||||||
assertEquals("B::boo", g())
|
assertEquals("B::boo", g())
|
||||||
|
|
||||||
val fs = js("B\$far\$lambda").toString() as String
|
val fs: String = js("B\$far\$lambda").toString()
|
||||||
val gs = (js("B\$gar\$lambda").toString() as String).replaceAll("boo", "foo").replaceAll("gar", "far")
|
val gs = (js("B\$gar\$lambda").toString() as String).replaceAll("boo", "foo").replaceAll("gar", "far")
|
||||||
|
|
||||||
assertEquals(gs, fs)
|
assertEquals(gs, fs)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function foo() {
|
||||||
|
return "O";
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
@native fun foo(ignore: dynamic): String
|
||||||
|
|
||||||
|
@JsName("foo")
|
||||||
|
fun foo() = "K"
|
||||||
|
|
||||||
|
fun box() = foo(0) + foo()
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
function foo() {
|
||||||
|
return "global foo;";
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
return "global bar;";
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
@native fun foo(): dynamic
|
||||||
|
|
||||||
|
@native fun bar(): dynamic
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val foo = "local foo;"
|
||||||
|
val bar = "local bar;"
|
||||||
|
val result = foo + test.bar() + test.foo() + bar
|
||||||
|
if (result != "local foo;global bar;global foo;local bar;") return "fail: $result"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user