[JS IR] make using the original parameter names possible
This commit is contained in:
committed by
TeamCityServer
parent
e342ade00a
commit
f413d7fd75
+2
-1
@@ -12,12 +12,13 @@ import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
|
||||
class IrFileToJsTransformer : BaseIrElementToJsNodeTransformer<JsBlock, JsStaticContext> {
|
||||
class IrFileToJsTransformer(private val useBareParameterNames: Boolean = false) : BaseIrElementToJsNodeTransformer<JsBlock, JsStaticContext> {
|
||||
override fun visitFile(declaration: IrFile, data: JsStaticContext): JsBlock {
|
||||
val fileContext = JsGenerationContext(
|
||||
currentFile = declaration,
|
||||
currentFunction = null,
|
||||
staticContext = data,
|
||||
useBareParameterNames = useBareParameterNames
|
||||
)
|
||||
val block = JsGlobalBlock()
|
||||
|
||||
|
||||
+11
-7
@@ -10,11 +10,8 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.util.isSuspend
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsName
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNameRef
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsScope
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsThisRef
|
||||
|
||||
val emptyScope: JsScope
|
||||
get() = object : JsScope("nil") {
|
||||
@@ -28,7 +25,8 @@ class JsGenerationContext(
|
||||
val currentFunction: IrFunction?,
|
||||
val staticContext: JsStaticContext,
|
||||
val localNames: LocalNameGenerator? = null,
|
||||
private val nameCache: MutableMap<IrElement, JsName> = mutableMapOf()
|
||||
private val nameCache: MutableMap<IrElement, JsName> = mutableMapOf(),
|
||||
private val useBareParameterNames: Boolean = false,
|
||||
): IrNamer by staticContext {
|
||||
fun newFile(file: IrFile, func: IrFunction? = null, localNames: LocalNameGenerator? = null): JsGenerationContext {
|
||||
return JsGenerationContext(
|
||||
@@ -37,6 +35,7 @@ class JsGenerationContext(
|
||||
staticContext = staticContext,
|
||||
localNames = localNames,
|
||||
nameCache = nameCache,
|
||||
useBareParameterNames = useBareParameterNames,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -47,14 +46,19 @@ class JsGenerationContext(
|
||||
staticContext = staticContext,
|
||||
localNames = localNames,
|
||||
nameCache = nameCache,
|
||||
useBareParameterNames = useBareParameterNames,
|
||||
)
|
||||
}
|
||||
|
||||
fun getNameForValueDeclaration(declaration: IrDeclarationWithName): JsName {
|
||||
return nameCache.getOrPut(declaration) {
|
||||
val name = localNames!!.variableNames.names[declaration]
|
||||
?: error("Variable name is not found ${declaration.name}")
|
||||
JsName(name, true)
|
||||
if (useBareParameterNames) {
|
||||
JsName(sanitizeName(declaration.name.asString()), true)
|
||||
} else {
|
||||
val name = localNames!!.variableNames.names[declaration]
|
||||
?: error("Variable name is not found ${declaration.name}")
|
||||
JsName(name, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user