[JS IR] Don't generate "import" statements for external interfaces
#KT-40964 fixed
This commit is contained in:
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -15,11 +15,10 @@ import org.jetbrains.kotlin.ir.backend.js.export.ExportedModule
|
||||
import org.jetbrains.kotlin.ir.backend.js.export.toTypeScript
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.StaticMembersLowering
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.ir.util.isInterface
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
@@ -358,6 +357,7 @@ class IrModuleToJsTransformer(
|
||||
file.declarations
|
||||
.asSequence()
|
||||
.filterIsInstance<IrDeclarationWithName>()
|
||||
.filter { !(it is IrClass && it.isInterface && it.isEffectivelyExternal()) }
|
||||
.forEach { declaration ->
|
||||
val declName = getNameForExternalDeclaration(declaration)
|
||||
importStatements.add(
|
||||
@@ -417,4 +417,4 @@ class IrModuleToJsTransformer(
|
||||
this += statements
|
||||
endRegion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -5232,6 +5232,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsModule/importCountUmd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaces.kt")
|
||||
public void testInterfaces() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelVarargFun.kt")
|
||||
public void testTopLevelVarargFun() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsModule/topLevelVarargFun.kt");
|
||||
@@ -5333,6 +5338,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/classes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaces.kt")
|
||||
public void testInterfaces() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/simple.kt");
|
||||
|
||||
+10
@@ -5232,6 +5232,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsModule/importCountUmd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaces.kt")
|
||||
public void testInterfaces() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelVarargFun.kt")
|
||||
public void testTopLevelVarargFun() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsModule/topLevelVarargFun.kt");
|
||||
@@ -5333,6 +5338,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/classes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaces.kt")
|
||||
public void testInterfaces() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/simple.kt");
|
||||
|
||||
+10
@@ -5247,6 +5247,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsModule/importCountUmd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaces.kt")
|
||||
public void testInterfaces() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelVarargFun.kt")
|
||||
public void testTopLevelVarargFun() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsModule/topLevelVarargFun.kt");
|
||||
@@ -5348,6 +5353,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/classes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("interfaces.kt")
|
||||
public void testInterfaces() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/simple.kt");
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1238
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// FILE: bar.kt
|
||||
@file:JsModule("lib")
|
||||
@file:JsQualifier("foo")
|
||||
package foo
|
||||
|
||||
external interface Bar {
|
||||
fun ping(): String
|
||||
}
|
||||
|
||||
// FILE: baz.kt
|
||||
@file:JsModule("lib")
|
||||
package boo
|
||||
|
||||
external interface Baz {
|
||||
fun pong(): Int
|
||||
}
|
||||
|
||||
// FILE: root.kt
|
||||
@file:JsModule("lib")
|
||||
import foo.Bar
|
||||
import boo.Baz
|
||||
|
||||
external val bar: Bar
|
||||
external val baz: Baz
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
if (bar.ping() != "ping" || baz.pong() != 194) return "Fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: test.js
|
||||
$kotlin_test_internal$.beginModule();
|
||||
module.exports = {
|
||||
bar : {
|
||||
ping() {
|
||||
return "ping"
|
||||
}
|
||||
},
|
||||
baz : {
|
||||
pong() {
|
||||
return 194
|
||||
}
|
||||
}
|
||||
};
|
||||
$kotlin_test_internal$.endModule("lib");
|
||||
@@ -0,0 +1,43 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1238
|
||||
// FILE: bar.kt
|
||||
@file:JsQualifier("foo")
|
||||
package foo
|
||||
|
||||
external interface Bar {
|
||||
fun ping(): String
|
||||
}
|
||||
|
||||
// FILE: baz.kt
|
||||
package boo
|
||||
|
||||
external interface Baz {
|
||||
fun pong(): Int
|
||||
}
|
||||
|
||||
// FILE: root.kt
|
||||
import foo.Bar
|
||||
import boo.Baz
|
||||
|
||||
external val bar: Bar
|
||||
external val baz: Baz
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
if (bar.ping() != "ping" || baz.pong() != 194) return "Fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: test.js
|
||||
|
||||
var bar = {
|
||||
ping() {
|
||||
return "ping"
|
||||
}
|
||||
};
|
||||
|
||||
var baz = {
|
||||
pong() {
|
||||
return 194
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user