import * as ts from 'typescript'; import { ImportSummary } from './base'; export interface TranspilerOptions { /** * Fail on the first error, do not collect multiple. Allows easier debugging as stack traces lead * directly to the offending line. */ failFast?: boolean; /** * Output TypeScript semantic diagnostics when facade generation fails and TS errors could be the * reason for the failure. When falsey, semantic diagnostics will never be output. */ semanticDiagnostics?: boolean; /** * Skip running dart-format on the output. This is useful for large files (like dom.d.ts) since * the node package version of dart-format is significantly slower than the version in the SDK. */ skipFormatting?: boolean; /** * Specify the module name (e.g.) d3 instead of determining the module name from the d.ts files. * This is useful for libraries that assume they will be loaded with a JS module loader but that * Dart needs to load without a module loader until Dart supports JS module loaders. */ moduleName?: string; /** * A base path to relativize absolute file paths against. This is useful for library name * generation (see above) and nicer file names in error messages. */ basePath?: string; /** * Enforce conventions of public/private keyword and underscore prefix */ enforceUnderscoreConventions?: boolean; /** * Sets a root path to look for typings used by the facade converter. */ typingsRoot?: string; /** * Generate browser API facades instead of importing them from dart:html. */ generateHTML?: boolean; /** * Rename types to avoid conflicts in cases where a variable and a type have the exact same name, * but it is not clear if they are related or not. */ renameConflictingTypes?: boolean; /** * Do not assume that all properties declared on the anonymous types of top level variable * declarations are static. */ explicitStatic?: boolean; /** * Emit anonymous tags on all classes that have neither constructors nor static members. */ trustJSTypes?: boolean; /** * Experimental option to emit the source file ASTs as JSON after performing preliminary * processing that makes the format compatible with Dart. */ toJSON?: boolean; /** * Experimental JS Interop specific option to promote properties with function * types to methods instead of properties with a function type. This the makes * the Dart code more readable at the cost of disallowing setting the value of * the property. * Example JS library that benifits from this option: * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/chartjs/chart.d.ts */ promoteFunctionLikeMembers?: boolean; } export declare const COMPILER_OPTIONS: ts.CompilerOptions; /** * Context to ouput code into. */ export declare const enum OutputContext { Import = 0, Header = 1, Default = 2 } export declare class Transpiler { private options; private outputs; private outputStack; private currentFile; /** * Map of import library path to a Set of identifier names being imported. */ imports: Map; /** * Map containing AST nodes that we have removed or replaced. This is safer than modifying the AST * directly. */ nodeSubstitutions: Map; private lastCommentIdx; private errors; private transpilers; private declarationTranspiler; private fc; private typeArgumentDepth; constructor(options?: TranspilerOptions); /** * Transpiles the given files to Dart. * @param fileNames The input files. * @param destination Location to write files to. Outputs file contents to stdout if absent. */ transpile(fileNames: string[], destination?: string): void; translateProgram(program: ts.Program, entryPoints: string[]): Map; /** * Preliminary processing of source files to make them compatible with Dart. * * Propagates namespace export declarations and merges related classes and variables. * * @param fileNames The input files. * @param sourceFileMap A map that is used to access SourceFiles by their file names. The * normalized files will be stored in this map. * @param compilerHost The TS compiler host. */ normalizeSourceFiles(fileNames: Set, sourceFileMap: Map, compilerHost: ts.CompilerHost): void; /** * Check for namespace export declarations and propagate them to all modules they export. * * Namespace export declarations are used to declare UMD modules. The syntax for * them is 'export as namespace MyNamespace;'. This means that exported members of module * MyNamespace can be accessed through the global variable 'MyNamespace' within script files. Or * within source files, by importing them like you would import other modular libraries. */ private propagateNamespaceExportDeclarations; getCompilerOptions(): ts.CompilerOptions; private createCompilerHost; getOutputPath(filePath: string, destinationRoot: string): string; pushContext(context: OutputContext): void; popContext(): void; private translate; private convertToJSON; private formatCode; private checkForErrors; /** * Returns `filePath`, relativized to the program's `basePath`. * @param filePath Optional path to relativize, defaults to the current file's path. */ getRelativeFileName(filePath?: string): string; getDartFileName(filePath?: string): string; getJSONFileName(filePath?: string): string; isJsModuleFile(): boolean; private get currentOutput(); emit(s: string): void; emitNoSpace(s: string): void; maybeLineBreak(): void; enterCodeComment(): void; exitCodeComment(): void; enterTypeArgument(): void; exitTypeArgument(): void; get insideTypeArgument(): boolean; emitType(s: string, comment: string): void; get insideCodeComment(): boolean; reportError(n: ts.Node, message: string): void; visit(node: ts.Node): void; private normalizeSlashes; private translateComment; } export declare function getModuleResolver(compilerHost: ts.CompilerHost): (moduleNames: string[], containingFile: string) => ts.ResolvedModule[];