JS_IR: fix property name generation

This commit is contained in:
Dmitry Petrov
2019-02-28 14:58:56 +03:00
parent 04fad012a0
commit 8b4dab7c25
2 changed files with 9 additions and 6 deletions
@@ -43,12 +43,11 @@ class JsGenerationContext {
this.currentFunction = func this.currentFunction = func
} }
fun getNameForDeclaration(declaration: IrDeclaration): JsName = when (declaration) { fun getNameForDeclaration(declaration: IrDeclaration): JsName =
is IrSymbolOwner -> getNameForSymbol(declaration.symbol) if (declaration is IrSymbolOwner)
// Properties don't have symbols. Handling them separately: getNameForSymbol(declaration.symbol)
is IrProperty -> currentScope.declareName(declaration.getJsName() ?: declaration.name.identifier) else
else -> error("Unsupported") error("Unsupported")
}
fun getNameForSymbol(symbol: IrSymbol): JsName = staticContext.getNameForSymbol(symbol, this) fun getNameForSymbol(symbol: IrSymbol): JsName = staticContext.getNameForSymbol(symbol, this)
fun getNameForType(type: IrType): JsName = staticContext.getNameForType(type, this) fun getNameForType(type: IrType): JsName = staticContext.getNameForType(type, this)
@@ -47,6 +47,10 @@ class SimpleNameGenerator : NameGenerator {
val declarationName = declaration.getJsNameOrKotlinName().asString() val declarationName = declaration.getJsNameOrKotlinName().asString()
if (declaration is IrProperty) {
return context.currentScope.declareName(declaration.getJsNameOrKotlinName().asString())
}
if (declaration is IrSimpleFunction && declaration.origin == JsLoweredDeclarationOrigin.BRIDGE_TO_EXTERNAL_FUNCTION) { if (declaration is IrSimpleFunction && declaration.origin == JsLoweredDeclarationOrigin.BRIDGE_TO_EXTERNAL_FUNCTION) {
return nameDeclarator(declarationName) return nameDeclarator(declarationName)
} }