2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @license
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Copyright Google Inc. All Rights Reserved.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Use of this source code is governed by an MIT-style license that can be
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * found in the LICENSE file at https://angular.io/license
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-25 23:26:49 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {MissingTranslationStrategy, ViewEncapsulation} from '@angular/core';
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {AnimationParser} from '../animation/animation_parser';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {CompilerConfig} from '../config';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {DirectiveNormalizer} from '../directive_normalizer';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {DirectiveResolver} from '../directive_resolver';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {DirectiveWrapperCompiler} from '../directive_wrapper_compiler';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {Lexer} from '../expression_parser/lexer';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {Parser} from '../expression_parser/parser';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {I18NHtmlParser} from '../i18n/i18n_html_parser';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {CompileMetadataResolver} from '../metadata_resolver';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {HtmlParser} from '../ml_parser/html_parser';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {NgModuleCompiler} from '../ng_module_compiler';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {NgModuleResolver} from '../ng_module_resolver';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {TypeScriptEmitter} from '../output/ts_emitter';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {PipeResolver} from '../pipe_resolver';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {Console} from '../private_import_core';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {DomElementSchemaRegistry} from '../schema/dom_element_schema_registry';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {StyleCompiler} from '../style_compiler';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {TemplateParser} from '../template_parser/template_parser';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {createOfflineCompileUrlResolver} from '../url_resolver';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {ViewCompiler} from '../view_compiler/view_compiler';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {AotCompiler} from './compiler';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {AotCompilerHost} from './compiler_host';
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 13:57:25 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {AotCompilerOptions} from './compiler_options';
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {StaticReflector} from './static_reflector';
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-27 09:36:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {StaticSymbol, StaticSymbolCache} from './static_symbol';
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-15 09:12:40 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {StaticSymbolResolver} from './static_symbol_resolver';
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-29 15:36:33 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {AotSummaryResolver} from './summary_resolver';
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-15 09:12:40 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-27 09:36:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Creates a new AotCompiler based on options and a host.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-17 12:24:33 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCompilerOptions):
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {compiler: AotCompiler, reflector: StaticReflector} {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  let translations: string = options.translations || '';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const urlResolver = createOfflineCompileUrlResolver();
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-15 09:12:40 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const symbolCache = new StaticSymbolCache();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const summaryResolver = new AotSummaryResolver(compilerHost, symbolCache);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const symbolResolver = new StaticSymbolResolver(compilerHost, symbolCache, summaryResolver);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const staticReflector = new StaticReflector(symbolResolver);
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  StaticAndDynamicReflectionCapabilities.install(staticReflector);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-25 23:26:49 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const console = new Console();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const htmlParser = new I18NHtmlParser(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      new HtmlParser(), translations, options.i18nFormat, MissingTranslationStrategy.Warning,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      console);
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const config = new CompilerConfig({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    genDebugInfo: options.debug === true,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    defaultEncapsulation: ViewEncapsulation.Emulated,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    logBindingUpdate: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    useJit: false
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const normalizer = new DirectiveNormalizer(
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-17 12:24:33 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      {get: (url: string) => compilerHost.loadResource(url)}, urlResolver, htmlParser, config);
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const expressionParser = new Parser(new Lexer());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const elementSchemaRegistry = new DomElementSchemaRegistry();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const tmplParser =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      new TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, console, []);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const resolver = new CompileMetadataResolver(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      new NgModuleResolver(staticReflector), new DirectiveResolver(staticReflector),
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-29 15:36:33 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      new PipeResolver(staticReflector), summaryResolver, elementSchemaRegistry, normalizer,
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-27 09:36:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      symbolCache, staticReflector);
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  // TODO(vicb): do not pass options.i18nFormat here
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-27 09:36:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const importResolver = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getImportAs: (symbol: StaticSymbol) => symbolResolver.getImportAs(symbol),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    fileNameToModuleName: (fileName: string, containingFilePath: string) =>
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-30 15:32:08 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                              compilerHost.fileNameToModuleName(fileName, containingFilePath),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getTypeArity: (symbol: StaticSymbol) => symbolResolver.getTypeArity(symbol)
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-27 09:36:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  };
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const compiler = new AotCompiler(
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-15 09:12:40 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      compilerHost, resolver, tmplParser, new StyleCompiler(urlResolver),
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      new ViewCompiler(config, elementSchemaRegistry),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      new DirectiveWrapperCompiler(config, expressionParser, elementSchemaRegistry, console),
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-27 09:36:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      new NgModuleCompiler(), new TypeScriptEmitter(importResolver), summaryResolver,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      options.locale, options.i18nFormat, new AnimationParser(elementSchemaRegistry),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      symbolResolver);
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-15 11:13:20 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return {compiler, reflector: staticReflector};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |