JS: prevent compiler from importing module more than once if not necessary. See KT-15260

This commit is contained in:
Alexey Andreev
2016-12-22 13:19:07 +03:00
committed by Alexey Andreev
parent 1ecd957981
commit 9b4b7960d3
7 changed files with 93 additions and 7 deletions
@@ -0,0 +1,12 @@
__beginModule__();
module.exports = function(param) {
switch (typeof param) {
case "number":
return "a";
case "string":
return "b";
default:
return "c";
}
};
__endModule__("lib");
@@ -0,0 +1,17 @@
// MODULE_KIND: COMMON_JS
// FUNCTION_CALLED_TIMES: require count=2
@JsModule("lib")
external fun f(x: Int): String
@JsModule("lib")
external fun f(x: String): String
@JsModule("lib")
external fun g(x: Boolean): String
fun box(): String {
val result = f(23) + f("foo") + g(true)
if (result != "abc") return "fail: $result"
return "OK"
}
@@ -0,0 +1,11 @@
var f = function(param) {
switch (typeof param) {
case "number":
return "a";
case "string":
return "b";
default:
return "c";
}
};
var g = f;
@@ -0,0 +1,21 @@
// MODULE_KIND: UMD
// NO_JS_MODULE_SYSTEM
// FUNCTION_CALLED_TIMES: require count=3
@JsModule("lib")
@JsNonModule
external fun f(x: Int): String
@JsModule("lib")
@JsNonModule
external fun f(x: String): String
@JsModule("lib")
@JsNonModule
external fun g(x: Boolean): String
fun box(): String {
val result = f(23) + f("foo") + g(true)
if (result != "abc") return "fail: $result"
return "OK"
}