Search in sources :

Example 1 with JsProgram

use of org.jetbrains.kotlin.js.backend.ast.JsProgram in project kotlin by JetBrains.

the class K2JSTranslator method translate.

@NotNull
public TranslationResult translate(@NotNull List<KtFile> files, @NotNull MainCallParameters mainCallParameters, @Nullable JsAnalysisResult analysisResult) throws TranslationException {
    if (analysisResult == null) {
        analysisResult = TopDownAnalyzerFacadeForJS.analyzeFiles(files, config);
        ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    }
    BindingTrace bindingTrace = analysisResult.getBindingTrace();
    TopDownAnalyzerFacadeForJS.checkForErrors(files, bindingTrace.getBindingContext());
    ModuleDescriptor moduleDescriptor = analysisResult.getModuleDescriptor();
    Diagnostics diagnostics = bindingTrace.getBindingContext().getDiagnostics();
    TranslationContext context = Translation.generateAst(bindingTrace, files, mainCallParameters, moduleDescriptor, config);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    if (hasError(diagnostics))
        return new TranslationResult.Fail(diagnostics);
    JsProgram program = JsInliner.process(context);
    ResolveTemporaryNamesKt.resolveTemporaryNames(program);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    if (hasError(diagnostics))
        return new TranslationResult.Fail(diagnostics);
    CoroutineTransformer coroutineTransformer = new CoroutineTransformer(program);
    coroutineTransformer.accept(program);
    RemoveUnusedImportsKt.removeUnusedImports(program);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    if (hasError(diagnostics))
        return new TranslationResult.Fail(diagnostics);
    expandIsCalls(program, context);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    List<String> importedModules = new ArrayList<String>();
    for (StaticContext.ImportedModule module : context.getImportedModules()) {
        importedModules.add(module.getExternalName());
    }
    return new TranslationResult.Success(config, files, program, diagnostics, importedModules, moduleDescriptor, bindingTrace.getBindingContext());
}
Also used : BindingTrace(org.jetbrains.kotlin.resolve.BindingTrace) Diagnostics(org.jetbrains.kotlin.resolve.diagnostics.Diagnostics) CoroutineTransformer(org.jetbrains.kotlin.js.coroutine.CoroutineTransformer) ArrayList(java.util.ArrayList) JsProgram(org.jetbrains.kotlin.js.backend.ast.JsProgram) ModuleDescriptor(org.jetbrains.kotlin.descriptors.ModuleDescriptor) TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext) StaticContext(org.jetbrains.kotlin.js.translate.context.StaticContext) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 JsProgram (org.jetbrains.kotlin.js.backend.ast.JsProgram)1 CoroutineTransformer (org.jetbrains.kotlin.js.coroutine.CoroutineTransformer)1 StaticContext (org.jetbrains.kotlin.js.translate.context.StaticContext)1 TranslationContext (org.jetbrains.kotlin.js.translate.context.TranslationContext)1 BindingTrace (org.jetbrains.kotlin.resolve.BindingTrace)1 Diagnostics (org.jetbrains.kotlin.resolve.diagnostics.Diagnostics)1