import * as ts from 'typescript'; import { TargetLanguage } from './languages'; import { AstHandler, AstRendererOptions } from './renderer'; import { TypeScriptSnippet } from './snippet'; import { TranslatedSnippet } from './tablets/tablets'; import { TypeScriptCompiler, CompilationResult } from './typescript/ts-compiler'; import { File } from './util'; export interface TranslateResult { translation: string; diagnostics: readonly RosettaDiagnostic[]; } export declare function translateTypeScript(source: File, visitor: AstHandler, options?: SnippetTranslatorOptions): TranslateResult; /** * Translate one or more TypeScript snippets into other languages * * Can be configured to fully typecheck the samples, or perform only syntactical * translation. */ export declare class Translator { #private; private readonly includeCompilerDiagnostics; private readonly compiler; get diagnostics(): readonly RosettaDiagnostic[]; constructor(includeCompilerDiagnostics: boolean); /** * Return the snippet translator for the given snippet * * We used to cache these, but each translator holds on to quite a bit of memory, * so we don't do that anymore. */ translatorFor(snippet: TypeScriptSnippet): SnippetTranslator; /** * Translates a single snippet in its own TS context. */ translate(snip: TypeScriptSnippet, languages?: readonly TargetLanguage[]): TranslatedSnippet; /** * Translates a batch of snippets, using a shared TS context. */ translateSnippets(snippets: TypeScriptSnippet[], languages?: readonly TargetLanguage[]): TranslatedSnippet[]; private translateBatch; private translateSnippet; } export interface ISnippetTranslator { readonly diagnostics: readonly ts.Diagnostic[]; readonly didSuccessfullyCompile: boolean | undefined; renderUsing(visitor: AstHandler): string; syntaxKindCounter(): Partial>; fqnsReferenced(): string[]; } export interface SnippetTranslatorOptions extends AstRendererOptions { /** * Re-use the given compiler if given */ readonly compiler?: TypeScriptCompiler; /** * Include compiler errors in return diagnostics * * If false, only translation diagnostics will be returned. * * @default false */ readonly includeCompilerDiagnostics?: boolean; } /** * Internal implementation of a single TypeScript snippet translator. * * Consumers should either use `SnippetTranslator` or `BatchSnippetTranslator`. */ declare class InternalSnippetTranslator implements ISnippetTranslator { private readonly compilation; private readonly options; readonly translateDiagnostics: ts.Diagnostic[]; readonly compileDiagnostics: ts.Diagnostic[]; private readonly visibleSpans; private readonly tryCompile; private readonly submoduleReferences; constructor(snippet: TypeScriptSnippet, compilation: CompilationResult, options: SnippetTranslatorOptions); /** * Returns a boolean if compilation was attempted, and undefined if it was not. */ get didSuccessfullyCompile(): boolean | undefined; renderUsing(visitor: AstHandler): string; syntaxKindCounter(): Partial>; fqnsReferenced(): string[]; get diagnostics(): readonly ts.Diagnostic[]; } /** * Translate a single TypeScript snippet */ export declare class SnippetTranslator extends InternalSnippetTranslator { constructor(snippet: TypeScriptSnippet, options?: SnippetTranslatorOptions); } export interface BatchSnippetTranslatorOptions extends SnippetTranslatorOptions { /** * What directory to pretend the file is in (system parameter) * * Attached when compiling a literate file, as they compile in * the location where they are stored. * * @default - current working directory */ readonly compilationDirectory?: string; } /** * Translate a single TypeScript snippet */ export declare class BatchSnippetTranslator { private readonly snippets; private readonly options; private readonly compilation; constructor(snippets: TypeScriptSnippet[], options?: BatchSnippetTranslatorOptions); [Symbol.iterator](): Generator<[TypeScriptSnippet, ISnippetTranslator], void, unknown>; } /** * A translation of a TypeScript diagnostic into a data-only representation for Rosetta * * We cannot use the original `ts.Diagnostic` since it holds on to way too much * state (the source file and by extension the entire parse tree), which grows * too big to be properly serialized by a worker and also takes too much memory. * * Reduce it down to only the information we need. */ export interface SnippetTimingInfo { readonly name: string; readonly snippetKey: string; readonly durationMs: number; } export interface RosettaDiagnostic { /** * If this is an error diagnostic or not */ readonly isError: boolean; /** * If the diagnostic was emitted from an assembly that has its 'strict' flag set */ readonly isFromStrictAssembly: boolean; /** * The formatted message, ready to be printed (will have colors and newlines in it) * * Ends in a newline. */ readonly formattedMessage: string; /** * Optional timing information for snippet translation */ readonly timingInfo?: SnippetTimingInfo; } export declare function makeRosettaDiagnostic(isError: boolean, formattedMessage: string): RosettaDiagnostic; export declare function makeTimingDiagnostic(snippetKey: string, name: string, durationMs: number): RosettaDiagnostic; export declare function extractTimingInfo(diagnostics: readonly RosettaDiagnostic[]): { timings: SnippetTimingInfo[]; diagnostics: RosettaDiagnostic[]; }; export declare function formatTimingTable(timings: SnippetTimingInfo[]): string; /** * Turn TypeScript diagnostics into Rosetta diagnostics */ export declare function rosettaDiagFromTypescript(diag: ts.Diagnostic): RosettaDiagnostic; export {}; //# sourceMappingURL=translate.d.ts.map