[JS IR] switch to the IC Ir2Js and fix tests
This commit is contained in:
committed by
TeamCityServer
parent
4386a800c8
commit
ef4ef8c930
+1
-1
@@ -101,7 +101,7 @@ class ExportModelToJsStatements(
|
||||
val newNameSpace = if (namespace != null)
|
||||
jsElementAccess(declaration.name, namespace)
|
||||
else
|
||||
JsNameRef(Namer.PROTOTYPE_NAME, declaration.name)
|
||||
JsNameRef(Namer.PROTOTYPE_NAME, namer.getNameForClass(declaration.ir).makeRef())
|
||||
val name = namer.getNameForStaticDeclaration(declaration.ir)
|
||||
val klassExport =
|
||||
if (esModules) {
|
||||
|
||||
+18
-7
@@ -33,7 +33,7 @@ class JsNameLinkingNamer(private val context: JsIrBackendContext) : IrNamerBase(
|
||||
val jsModule: String? = declaration.getJsModule()
|
||||
val maybeParentFile: IrFile? = declaration.parent as? IrFile
|
||||
val fileJsModule: String? = maybeParentFile?.getJsModule()
|
||||
val jsQualifier: String? = maybeParentFile?.getJsQualifier()
|
||||
val jsQualifier: List<JsName>? = maybeParentFile?.getJsQualifier()?.split('.')?.map { JsName(it, false) }
|
||||
|
||||
when {
|
||||
jsModule != null -> {
|
||||
@@ -44,19 +44,22 @@ class JsNameLinkingNamer(private val context: JsIrBackendContext) : IrNamerBase(
|
||||
|
||||
fileJsModule != null -> {
|
||||
if (declaration !in nameMap) {
|
||||
val moduleName = JsName("\$module\$$jsModule", true)
|
||||
val moduleName = JsName(sanitizeName("\$module\$$fileJsModule"), true)
|
||||
importedModules += JsImportedModule(fileJsModule, moduleName, null)
|
||||
val qualifiedReference =
|
||||
if (jsQualifier == null) moduleName.makeRef() else JsNameRef(jsQualifier, moduleName.makeRef())
|
||||
imports[declaration] = JsNameRef(declaration.getJsNameOrKotlinName().identifier, qualifiedReference)
|
||||
if (jsQualifier == null) moduleName.makeRef() else (listOf(moduleName) + jsQualifier).makeRef()
|
||||
imports[declaration] = jsElementAccess(declaration.getJsNameOrKotlinName().identifier, qualifiedReference)
|
||||
return declaration.getName()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
var name = declaration.getJsNameOrKotlinName().identifier
|
||||
if (jsQualifier != null)
|
||||
name = "$jsQualifier.$name"
|
||||
val name = declaration.getJsNameOrKotlinName().identifier
|
||||
|
||||
if (jsQualifier != null) {
|
||||
imports[declaration] = jsElementAccess(name, jsQualifier.makeRef())
|
||||
return declaration.getName()
|
||||
}
|
||||
|
||||
return name.toJsName(temporary = false)
|
||||
}
|
||||
@@ -117,4 +120,12 @@ private fun IrField.safeName(): String {
|
||||
return sanitizeName(name.asString()).let {
|
||||
if (it.lastOrNull()!!.isDigit()) it + "_" else it // Avoid name clashes
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<JsName>.makeRef(): JsNameRef {
|
||||
var result = this[0].makeRef()
|
||||
for (i in 1 until this.size) {
|
||||
result = JsNameRef(this[i], result)
|
||||
}
|
||||
return result
|
||||
}
|
||||
-15
@@ -8,21 +8,6 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
|
||||
fun JsNode.resolveTemporaryNames() {
|
||||
object : JsVisitorWithContextImpl() {
|
||||
override fun endVisit(x: JsNameRef, ctx: JsContext<JsNode>) {
|
||||
x.name?.ident?.let {
|
||||
if (it.contains('.')) {
|
||||
val parts = it.split('.').map { JsName(it, false) }
|
||||
var result = JsNameRef(parts[0])
|
||||
for (i in 1 until parts.size) {
|
||||
result = JsNameRef(parts[i], result)
|
||||
}
|
||||
ctx.replaceMe(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.accept(this)
|
||||
|
||||
val renamings = resolveNames()
|
||||
accept(object : RecursiveJsVisitor() {
|
||||
override fun visitElement(node: JsNode) {
|
||||
|
||||
@@ -57,7 +57,7 @@ abstract class AbstractJsIrTest(
|
||||
if (getBoolean("kotlin.js.ir.klibMainModule")) +JsEnvironmentConfigurationDirectives.KLIB_MAIN_MODULE
|
||||
if (getBoolean("kotlin.js.ir.perModule")) +JsEnvironmentConfigurationDirectives.PER_MODULE
|
||||
if (getBoolean("kotlin.js.ir.dce", true)) +JsEnvironmentConfigurationDirectives.RUN_IR_DCE
|
||||
if (getBoolean("kotlin.js.ir.newIr2Js", false)) +JsEnvironmentConfigurationDirectives.RUN_NEW_IR_2_JS
|
||||
if (getBoolean("kotlin.js.ir.newIr2Js", true)) +JsEnvironmentConfigurationDirectives.RUN_NEW_IR_2_JS
|
||||
-JsEnvironmentConfigurationDirectives.GENERATE_NODE_JS_RUNNER
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -16,8 +16,13 @@ fun box(): String {
|
||||
// DCE preventing
|
||||
val b = B()
|
||||
|
||||
assertEquals("function", js("typeof A['\$invalid inner']"))
|
||||
assertEquals(js("undefined"), js("B['\$invalid inner']"))
|
||||
val aCtor = A::class.js.asDynamic()
|
||||
val bCtor = B::class.js.asDynamic()
|
||||
|
||||
assertEquals("function", typeOf(aCtor["\$invalid inner"]))
|
||||
assertEquals(js("undefined"), bCtor["\$invalid inner"])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
private fun typeOf(t: Any): String = js("typeof t")
|
||||
@@ -1,5 +1,4 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1285
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
package foo
|
||||
|
||||
|
||||
+4
-4
@@ -6,10 +6,6 @@ declare namespace JS_TESTS {
|
||||
interface ExportedInternalInterface {
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
interface FileLevelExportedExternalInterface {
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
const exportedVal: number;
|
||||
function exportedFun(): number;
|
||||
@@ -18,6 +14,10 @@ declare namespace JS_TESTS {
|
||||
get value(): number;
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
interface FileLevelExportedExternalInterface {
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
const fileLevelExportedVal: number;
|
||||
function fileLevelExportedFun(): number;
|
||||
|
||||
Reference in New Issue
Block a user