[JS IR] In file:JsModule top level with fresh names
This commit is contained in:
committed by
TeamCityServer
parent
600e1725cb
commit
ead0b50107
+1
-1
@@ -365,7 +365,7 @@ class IrModuleToJsTransformer(
|
||||
.forEach { declaration ->
|
||||
val declName = getNameForExternalDeclaration(declaration)
|
||||
importStatements.add(
|
||||
JsVars(JsVars.JsVar(declName, JsNameRef(declName, qualifiedReference)))
|
||||
JsVars(JsVars.JsVar(declName, JsNameRef(declaration.getJsNameOrKotlinName().identifier, qualifiedReference)))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||
import org.jetbrains.kotlin.ir.expressions.IrWhen
|
||||
import org.jetbrains.kotlin.ir.types.isUnit
|
||||
import org.jetbrains.kotlin.ir.util.file
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
@@ -285,8 +286,13 @@ class NameTables(
|
||||
return
|
||||
|
||||
// TODO: Handle JsQualifier
|
||||
declaration.isEffectivelyExternal() && (declaration.getJsModule() == null || declaration.isJsNonModule()) ->
|
||||
globalNames.declareStableName(declaration, declaration.getJsNameOrKotlinName().identifier)
|
||||
declaration.isEffectivelyExternal() && (declaration.getJsModule() == null || declaration.isJsNonModule()) -> {
|
||||
if (declaration.file.getJsModule() != null) {
|
||||
globalNames.declareFreshName(declaration, declaration.name.asString())
|
||||
} else {
|
||||
globalNames.declareStableName(declaration, declaration.getJsNameOrKotlinName().identifier)
|
||||
}
|
||||
}
|
||||
|
||||
else ->
|
||||
globalNames.declareFreshName(declaration, declaration.name.asString())
|
||||
|
||||
Generated
+15
@@ -5354,6 +5354,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsName/classes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultJsName.kt")
|
||||
public void testDefaultJsName() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/defaultJsName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritFromRenamedNativeClass.kt")
|
||||
public void testInheritFromRenamedNativeClass() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/inheritFromRenamedNativeClass.kt");
|
||||
@@ -5374,6 +5379,16 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jsTopLevelClashes.kt")
|
||||
public void testJsTopLevelClashes() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/jsTopLevelClashes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jsTopLevelRenameReserved.kt")
|
||||
public void testJsTopLevelRenameReserved() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/jsTopLevelRenameReserved.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overriddenMethod.kt")
|
||||
public void testOverriddenMethod() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/overriddenMethod.kt");
|
||||
|
||||
+15
@@ -5354,6 +5354,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsName/classes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultJsName.kt")
|
||||
public void testDefaultJsName() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/defaultJsName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritFromRenamedNativeClass.kt")
|
||||
public void testInheritFromRenamedNativeClass() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/inheritFromRenamedNativeClass.kt");
|
||||
@@ -5374,6 +5379,16 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jsTopLevelClashes.kt")
|
||||
public void testJsTopLevelClashes() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/jsTopLevelClashes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jsTopLevelRenameReserved.kt")
|
||||
public void testJsTopLevelRenameReserved() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/jsTopLevelRenameReserved.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overriddenMethod.kt")
|
||||
public void testOverriddenMethod() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/overriddenMethod.kt");
|
||||
|
||||
+15
@@ -5364,6 +5364,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsName/classes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultJsName.kt")
|
||||
public void testDefaultJsName() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/defaultJsName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inheritFromRenamedNativeClass.kt")
|
||||
public void testInheritFromRenamedNativeClass() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/inheritFromRenamedNativeClass.kt");
|
||||
@@ -5384,6 +5389,16 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jsTopLevelClashes.kt")
|
||||
public void testJsTopLevelClashes() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/jsTopLevelClashes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jsTopLevelRenameReserved.kt")
|
||||
public void testJsTopLevelRenameReserved() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/jsTopLevelRenameReserved.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overriddenMethod.kt")
|
||||
public void testOverriddenMethod() throws Exception {
|
||||
runTest("js/js.translator/testData/box/jsName/overriddenMethod.kt");
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// MODULE: main
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// FILE: lib.kt
|
||||
@file:JsModule("foo")
|
||||
package lib
|
||||
|
||||
@JsName("default")
|
||||
external val foo: Int
|
||||
|
||||
@JsName("for")
|
||||
external val bar: String
|
||||
|
||||
// FILE: lib2.kt
|
||||
@file:JsModule("bar")
|
||||
package lib
|
||||
|
||||
@JsName("default")
|
||||
external fun foo(): Int
|
||||
|
||||
// FILE: main.kt
|
||||
package main
|
||||
|
||||
import lib.*
|
||||
|
||||
fun box(): String {
|
||||
if (foo != 23 || bar != "hello" || foo() != 23) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: hello.js
|
||||
|
||||
$kotlin_test_internal$.beginModule("foo");
|
||||
module.exports = {
|
||||
"default": 23,
|
||||
"for": "hello"
|
||||
}
|
||||
$kotlin_test_internal$.endModule("foo");
|
||||
|
||||
$kotlin_test_internal$.beginModule("bar");
|
||||
module.exports = {
|
||||
"default": function() {
|
||||
return 23
|
||||
}
|
||||
}
|
||||
$kotlin_test_internal$.endModule("bar");
|
||||
@@ -0,0 +1,39 @@
|
||||
// MODULE: main
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// FILE: lib.kt
|
||||
@file:JsModule("foo")
|
||||
package lib
|
||||
|
||||
@JsName("test")
|
||||
external val foo: Int
|
||||
|
||||
// FILE: lib2.kt
|
||||
@file:JsModule("bar")
|
||||
package lib
|
||||
|
||||
@JsName("test")
|
||||
external val bar: Int
|
||||
|
||||
// FILE: main.kt
|
||||
package main
|
||||
|
||||
import lib.*
|
||||
|
||||
fun box(): String {
|
||||
if (foo != 23 || bar != 45) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: hello.js
|
||||
|
||||
$kotlin_test_internal$.beginModule("foo");
|
||||
module.exports = {
|
||||
"test": 23
|
||||
}
|
||||
$kotlin_test_internal$.endModule("foo");
|
||||
|
||||
$kotlin_test_internal$.beginModule("bar");
|
||||
module.exports = {
|
||||
"test": 45
|
||||
}
|
||||
$kotlin_test_internal$.endModule("bar");
|
||||
@@ -0,0 +1,27 @@
|
||||
// MODULE: main
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// FILE: lib.kt
|
||||
@file:JsModule("foo")
|
||||
package lib
|
||||
|
||||
@JsName("eval")
|
||||
external val foo: Int
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
package main
|
||||
|
||||
import lib.*
|
||||
|
||||
fun box(): String {
|
||||
if (foo != 23 || eval("false")) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: hello.js
|
||||
|
||||
$kotlin_test_internal$.beginModule("foo");
|
||||
module.exports = {
|
||||
"eval": 23
|
||||
}
|
||||
$kotlin_test_internal$.endModule("foo");
|
||||
Reference in New Issue
Block a user