KT-12877: reorganize JS module tests to support different module systems. Test JsModule in conjunction with JsNonModule and plain module type

This commit is contained in:
Alexey Andreev
2016-07-04 15:32:02 +03:00
committed by Alexey Andreev
parent 0238b182cc
commit 08a7f9c298
9 changed files with 30 additions and 84 deletions
@@ -4994,6 +4994,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("externalFunctionPlain.kt")
public void testExternalFunctionPlain() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/jsModule/externalFunctionPlain.kt");
doTest(fileName);
}
@TestMetadata("externalObject.kt")
public void testExternalObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/jsModule/externalObject.kt");
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.serialization.js.ModuleKind;
import java.util.*;
@@ -249,15 +250,17 @@ public final class StaticContext {
return result != null ? result : pureFqn(Namer.getRootPackageName(), null);
}
String moduleName = AnnotationsUtils.getModuleName(suggested.getDescriptor());
if (moduleName != null) {
return JsAstUtils.pureFqn(getModuleInternalName(moduleName), null);
}
if (config.getModuleKind() != ModuleKind.PLAIN) {
String moduleName = AnnotationsUtils.getModuleName(suggested.getDescriptor());
if (moduleName != null) {
return JsAstUtils.pureFqn(getModuleInternalName(moduleName), null);
}
if (isNativeObject(suggested.getDescriptor())) {
String fileModuleName = AnnotationsUtils.getFileModuleName(getBindingContext(), suggested.getDescriptor());
if (fileModuleName != null) {
return pureFqn(getNameForDescriptor(suggested.getDescriptor()), pureFqn(getModuleInternalName(fileModuleName), null));
if (isNativeObject(suggested.getDescriptor())) {
String fileModuleName = AnnotationsUtils.getFileModuleName(getBindingContext(), suggested.getDescriptor());
if (fileModuleName != null) {
return pureFqn(getNameForDescriptor(suggested.getDescriptor()), pureFqn(getModuleInternalName(fileModuleName), null));
}
}
}
@@ -0,0 +1,3 @@
function foo(y) {
return 23 + y;
}
@@ -0,0 +1,10 @@
package foo
@JsModule("lib")
@JsNonModule
@native fun foo(y: Int): Int = noImpl
fun box(): String {
assertEquals(65, foo(42))
return "OK"
}
@@ -1,18 +0,0 @@
@file:JsModule("lib")
package foo
@native class A(@native val x: Int = noImpl) {
@native fun foo(y: Int): Int = noImpl
}
@native object B {
@native val x: Int = noImpl
@native fun foo(y: Int): Int = noImpl
}
@native fun foo(y: Int): Int = noImpl
@native val bar: Int = noImpl
@native var mbar: Int = noImpl
@@ -1,20 +0,0 @@
package foo
fun box(): String {
val a = A(23)
assertEquals(23, a.x)
assertEquals(65, a.foo(42))
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(42))
assertEquals(423, bar)
assertEquals(12345, C.f())
mbar = 523
assertEquals(523, mbar)
return "OK"
}
@@ -1,2 +0,0 @@
lib->
main->lib
@@ -1,18 +0,0 @@
@file:JsModule("native-lib")
package foo
@native class A(@native val x: Int = noImpl) {
@native fun foo(y: Int): Int = noImpl
}
@native object B {
@native val x: Int = noImpl
@native fun foo(y: Int): Int = noImpl
}
@native fun foo(y: Int): Int = noImpl
@native val bar: Int = noImpl
@native var mbar: Int = noImpl
@@ -1,18 +0,0 @@
package foo
fun box(): String {
val a = A(23)
assertEquals(23, a.x)
assertEquals(65, a.foo(42))
assertEquals(123, B.x)
assertEquals(265, B.foo(142))
assertEquals(365, foo(42))
assertEquals(423, bar)
mbar = 523
assertEquals(523, mbar)
return "OK"
}