use of org.jetbrains.kotlin.js.translate.expression.LocalFunctionCollector in project kotlin by JetBrains.
the class FunctionBodyTranslator method translateFunctionBody.
@NotNull
public static JsBlock translateFunctionBody(@NotNull FunctionDescriptor descriptor, @NotNull KtDeclarationWithBody declarationWithBody, @NotNull TranslationContext functionBodyContext) {
Map<DeclarationDescriptor, JsExpression> aliases = new HashMap<DeclarationDescriptor, JsExpression>();
LocalFunctionCollector functionCollector = new LocalFunctionCollector(functionBodyContext.bindingContext());
declarationWithBody.acceptChildren(functionCollector, null);
for (FunctionDescriptor localFunction : functionCollector.getFunctions()) {
String localIdent = localFunction.getName().isSpecial() ? "lambda" : localFunction.getName().asString();
JsName localName = functionBodyContext.scope().getParent().declareTemporaryName(NameSuggestion.sanitizeName(localIdent));
MetadataProperties.setDescriptor(localName, localFunction);
JsExpression alias = JsAstUtils.pureFqn(localName, null);
aliases.put(localFunction, alias);
}
if (!aliases.isEmpty()) {
functionBodyContext = functionBodyContext.innerContextWithDescriptorsAliased(aliases);
}
return (new FunctionBodyTranslator(descriptor, declarationWithBody, functionBodyContext)).translate();
}
Aggregations