Search in sources :

Example 1 with LocalFunctionCollector

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();
}
Also used : LocalFunctionCollector(org.jetbrains.kotlin.js.translate.expression.LocalFunctionCollector) HashMap(java.util.HashMap) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 LocalFunctionCollector (org.jetbrains.kotlin.js.translate.expression.LocalFunctionCollector)1