use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.
the class ArrayAccessTranslator method translateAsMethodCall.
@NotNull
private JsExpression translateAsMethodCall(@NotNull JsExpression arrayExpression, @Nullable JsExpression toSetTo) {
boolean isGetter = toSetTo == null;
TranslationContext context = context();
ResolvedCall<FunctionDescriptor> resolvedCall = BindingUtils.getResolvedCallForArrayAccess(bindingContext(), expression, isGetter);
if (!isGetter) {
context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
}
return CallTranslator.translate(context, resolvedCall, arrayExpression);
}
use of org.jetbrains.kotlin.js.translate.context.TranslationContext 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());
}
use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.
the class ExpressionVisitor method translateClassOrObject.
private static void translateClassOrObject(@NotNull KtClassOrObject declaration, @NotNull ClassDescriptor descriptor, @NotNull TranslationContext context) {
JsScope scope = context.getScopeForDescriptor(descriptor);
TranslationContext classContext = context.innerWithUsageTracker(scope, descriptor);
ClassTranslator.translate(declaration, classContext);
}
use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.
the class AccessTranslationUtils method getArrayAccessTranslator.
@NotNull
private static AccessTranslator getArrayAccessTranslator(@NotNull KtArrayAccessExpression expression, @NotNull TranslationContext context, boolean forceOrderOfEvaluation) {
TranslationContext accessArrayContext;
if (forceOrderOfEvaluation) {
Map<KtExpression, JsExpression> indexesMap = new LinkedHashMap<KtExpression, JsExpression>();
for (KtExpression indexExpression : expression.getIndexExpressions()) {
JsExpression jsIndexExpression = context.cacheExpressionIfNeeded(Translation.translateAsExpression(indexExpression, context));
indexesMap.put(indexExpression, jsIndexExpression);
}
accessArrayContext = context.innerContextWithAliasesForExpressions(indexesMap);
} else {
accessArrayContext = context;
}
return ArrayAccessTranslator.newInstance(expression, accessArrayContext);
}
Aggregations