refactor(compiler): don’t use the `OfflineCompiler` in extract_i18n

This commit is contained in:
Tobias Bosch 2016-10-18 08:09:43 -07:00 committed by Alex Rickabaugh
parent acda82c1ed
commit c951822c35
2 changed files with 15 additions and 21 deletions

View File

@ -179,21 +179,22 @@ export class CodeGenerator {
logBindingUpdate: false, logBindingUpdate: false,
useJit: false useJit: false
}); });
const normalizer = new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config); const normalizer =
new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
const expressionParser = new compiler.Parser(new compiler.Lexer()); const expressionParser = new compiler.Parser(new compiler.Lexer());
const elementSchemaRegistry = new compiler.DomElementSchemaRegistry(); const elementSchemaRegistry = new compiler.DomElementSchemaRegistry();
const console = new Console(); const console = new Console();
const tmplParser = const tmplParser = new compiler.TemplateParser(
new compiler.TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, console, []); expressionParser, elementSchemaRegistry, htmlParser, console, []);
const resolver = new compiler.CompileMetadataResolver( const resolver = new compiler.CompileMetadataResolver(
new compiler.NgModuleResolver(staticReflector), new compiler.NgModuleResolver(staticReflector),
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
elementSchemaRegistry, staticReflector); elementSchemaRegistry, staticReflector);
// TODO(vicb): do not pass cliOptions.i18nFormat here // TODO(vicb): do not pass cliOptions.i18nFormat here
const offlineCompiler = new compiler.OfflineCompiler( const offlineCompiler = new compiler.OfflineCompiler(
resolver, normalizer, tmplParser, new compiler.StyleCompiler(urlResolver), new compiler.ViewCompiler(config), resolver, normalizer, tmplParser, new compiler.StyleCompiler(urlResolver),
new compiler.NgModuleCompiler(), new compiler.TypeScriptEmitter(reflectorHost), cliOptions.locale, new compiler.ViewCompiler(config), new compiler.NgModuleCompiler(),
cliOptions.i18nFormat); new compiler.TypeScriptEmitter(reflectorHost), cliOptions.locale, cliOptions.i18nFormat);
return new CodeGenerator( return new CodeGenerator(
options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost); options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost);

View File

@ -29,7 +29,7 @@ import {StaticReflector, StaticSymbol} from './static_reflector';
function extract( function extract(
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions, ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
program: ts.Program, host: ts.CompilerHost) { program: ts.Program, host: ts.CompilerHost) {
const htmlParser = new compiler.I18NHtmlParser(new HtmlParser()); const htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser());
const extractor = Extractor.create(ngOptions, cliOptions.i18nFormat, program, host, htmlParser); const extractor = Extractor.create(ngOptions, cliOptions.i18nFormat, program, host, htmlParser);
const bundlePromise: Promise<compiler.MessageBundle> = extractor.extract(); const bundlePromise: Promise<compiler.MessageBundle> = extractor.extract();
@ -62,9 +62,9 @@ export class Extractor {
constructor( constructor(
private program: ts.Program, public host: ts.CompilerHost, private program: ts.Program, public host: ts.CompilerHost,
private staticReflector: StaticReflector, private messageBundle: compiler.MessageBundle, private staticReflector: StaticReflector, private messageBundle: compiler.MessageBundle,
private reflectorHost: ReflectorHost, private metadataResolver: compiler.CompileMetadataResolver, private reflectorHost: ReflectorHost,
private directiveNormalizer: compiler.DirectiveNormalizer, private metadataResolver: compiler.CompileMetadataResolver,
private compiler: compiler.OfflineCompiler) {} private directiveNormalizer: compiler.DirectiveNormalizer) {}
private readFileMetadata(absSourcePath: string): FileMetadata { private readFileMetadata(absSourcePath: string): FileMetadata {
const moduleMetadata = this.staticReflector.getModuleMetadata(absSourcePath); const moduleMetadata = this.staticReflector.getModuleMetadata(absSourcePath);
@ -104,7 +104,7 @@ export class Extractor {
ngModules.push(...fileMeta.ngModules); ngModules.push(...fileMeta.ngModules);
return ngModules; return ngModules;
}, <StaticSymbol[]>[]); }, <StaticSymbol[]>[]);
const analyzedNgModules = this.compiler.analyzeModules(ngModules); const analyzedNgModules = compiler.analyzeModules(ngModules, this.metadataResolver);
const errors: compiler.ParseError[] = []; const errors: compiler.ParseError[] = [];
let bundlePromise = let bundlePromise =
@ -167,26 +167,19 @@ export class Extractor {
useJit: false useJit: false
}); });
const normalizer = new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config); const normalizer =
const expressionParser = new compiler.Parser(new compiler.Lexer()); new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
const elementSchemaRegistry = new compiler.DomElementSchemaRegistry(); const elementSchemaRegistry = new compiler.DomElementSchemaRegistry();
const console = new Console();
const tmplParser =
new compiler.TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, console, []);
const resolver = new compiler.CompileMetadataResolver( const resolver = new compiler.CompileMetadataResolver(
new compiler.NgModuleResolver(staticReflector), new compiler.NgModuleResolver(staticReflector),
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
elementSchemaRegistry, staticReflector); elementSchemaRegistry, staticReflector);
const offlineCompiler = new compiler.OfflineCompiler(
resolver, normalizer, tmplParser, new compiler.StyleCompiler(urlResolver), new compiler.ViewCompiler(config),
new compiler.NgModuleCompiler(), new compiler.TypeScriptEmitter(reflectorHost), null, null);
// TODO(vicb): implicit tags & attributes // TODO(vicb): implicit tags & attributes
let messageBundle = new compiler.MessageBundle(htmlParser, [], {}); let messageBundle = new compiler.MessageBundle(htmlParser, [], {});
return new Extractor( return new Extractor(
program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer, program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer);
offlineCompiler);
} }
} }