refactor(compiler): add createAotCompiler
factory
Also adds 2 more methods to the `AotCompilerHost`: - `loadResource` - `resolveFileToImport`
This commit is contained in:

committed by
Chuck Jazdzewski

parent
484119e59f
commit
2235048432
@ -12,10 +12,10 @@ import {isBlank, isPresent} from '../facade/lang';
|
||||
import {EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
|
||||
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
|
||||
import * as o from './output_ast';
|
||||
import {ImportGenerator} from './path_util';
|
||||
import {ImportResolver} from './path_util';
|
||||
|
||||
export class JavaScriptEmitter implements OutputEmitter {
|
||||
constructor(private _importGenerator: ImportGenerator) {}
|
||||
constructor(private _importGenerator: ImportResolver) {}
|
||||
emitStatements(moduleUrl: string, stmts: o.Statement[], exportedVars: string[]): string {
|
||||
const converter = new JsEmitterVisitor(moduleUrl);
|
||||
const ctx = EmitterVisitorContext.createRoot(exportedVars);
|
||||
@ -25,7 +25,7 @@ export class JavaScriptEmitter implements OutputEmitter {
|
||||
// Note: can't write the real word for import as it screws up system.js auto detection...
|
||||
srcParts.push(
|
||||
`var ${prefix} = req` +
|
||||
`uire('${this._importGenerator.getImportPath(moduleUrl, importedModuleUrl)}');`);
|
||||
`uire('${this._importGenerator.resolveFileToImport(importedModuleUrl, moduleUrl)}');`);
|
||||
});
|
||||
srcParts.push(ctx.toSource());
|
||||
return srcParts.join('\n');
|
||||
|
@ -9,6 +9,6 @@
|
||||
/**
|
||||
* Interface that defines how import statements should be generated.
|
||||
*/
|
||||
export abstract class ImportGenerator {
|
||||
abstract getImportPath(moduleUrlStr: string, importedUrlStr: string): string;
|
||||
export abstract class ImportResolver {
|
||||
abstract resolveFileToImport(importedFilePath: string, containingFilePath: string): string;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import {isBlank, isPresent} from '../facade/lang';
|
||||
|
||||
import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
|
||||
import * as o from './output_ast';
|
||||
import {ImportGenerator} from './path_util';
|
||||
import {ImportResolver} from './path_util';
|
||||
|
||||
const _debugModuleUrl = '/debug/lib';
|
||||
|
||||
@ -37,7 +37,7 @@ export function debugOutputAstAsTypeScript(ast: o.Statement | o.Expression | o.T
|
||||
}
|
||||
|
||||
export class TypeScriptEmitter implements OutputEmitter {
|
||||
constructor(private _importGenerator: ImportGenerator) {}
|
||||
constructor(private _importGenerator: ImportResolver) {}
|
||||
emitStatements(moduleUrl: string, stmts: o.Statement[], exportedVars: string[]): string {
|
||||
const converter = new _TsEmitterVisitor(moduleUrl);
|
||||
const ctx = EmitterVisitorContext.createRoot(exportedVars);
|
||||
@ -47,7 +47,7 @@ export class TypeScriptEmitter implements OutputEmitter {
|
||||
// Note: can't write the real word for import as it screws up system.js auto detection...
|
||||
srcParts.push(
|
||||
`imp` +
|
||||
`ort * as ${prefix} from '${this._importGenerator.getImportPath(moduleUrl, importedModuleUrl)}';`);
|
||||
`ort * as ${prefix} from '${this._importGenerator.resolveFileToImport(importedModuleUrl, moduleUrl)}';`);
|
||||
});
|
||||
srcParts.push(ctx.toSource());
|
||||
return srcParts.join('\n');
|
||||
|
Reference in New Issue
Block a user