[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) {
|
||||
|
||||
Reference in New Issue
Block a user