es5processor.d.ts 2.76 KB
Newer Older
jatuporn Tonggasem's avatar
jatuporn Tonggasem committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
/// <amd-module name="tsickle/src/es5processor" />
import { ModulesManifest } from './modules_manifest';
import * as ts from './typescript';
export interface Es5ProcessorHost {
    /**
     * Takes a context (the current file) and the path of the file to import
     *  and generates a googmodule module name
     */
    pathToModuleName(context: string, importPath: string): string;
    /**
     * If we do googmodule processing, we polyfill module.id, since that's
     * part of ES6 modules.  This function determines what the module.id will be
     * for each file.
     */
    fileNameToModuleId(fileName: string): string;
    /** Whether to convert CommonJS module syntax to `goog.module` Closure imports. */
    googmodule?: boolean;
    /** Whether the emit targets ES5 or ES6+. */
    es5Mode?: boolean;
    /** expand "import 'foo';" to "import 'foo/index';" if it points to an index file. */
    convertIndexImportShorthand?: boolean;
    /**
     * An additional prelude to insert in front of the emitted code, e.g. to import a shared library.
     */
    prelude?: string;
    options: ts.CompilerOptions;
    host: ts.ModuleResolutionHost;
}
/**
 * Extracts the namespace part of a goog: import, or returns null if the given
 * import is not a goog: import.
 */
export declare function extractGoogNamespaceImport(tsImport: string): string | null;
/**
 * Convert from implicit `import {} from 'pkg'` to `import {} from 'pkg/index'.
 * TypeScript supports the shorthand, but not all ES6 module loaders do.
 * Workaround for https://github.com/Microsoft/TypeScript/issues/12597
 */
export declare function resolveIndexShorthand(host: {
    options: ts.CompilerOptions;
    host: ts.ModuleResolutionHost;
}, fileName: string, imported: string): string;
/**
 * Converts TypeScript's JS+CommonJS output to Closure goog.module etc.
 * For use as a postprocessing step *after* TypeScript emits JavaScript.
 *
 * @param fileName The source file name.
 * @param moduleId The "module id", a module-identifying string that is
 *     the value module.id in the scope of the module.
 * @param pathToModuleName A function that maps a filesystem .ts path to a
 *     Closure module name, as found in a goog.require('...') statement.
 *     The context parameter is the referencing file, used for resolving
 *     imports with relative paths like "import * as foo from '../foo';".
 * @param prelude An additional prelude to insert after the `goog.module` call,
 *     e.g. with additional imports or requires.
 */
export declare function processES5(host: Es5ProcessorHost, fileName: string, content: string): {
    output: string;
    referencedModules: string[];
};
export declare function convertCommonJsToGoogModuleIfNeeded(host: Es5ProcessorHost, modulesManifest: ModulesManifest, fileName: string, content: string): string;