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Aa,CAAC,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE3E,IAAM,cAAc,GAAG,eAAe,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACrE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,oCAAkC,UAAY,CAAC,CAAC;YAC7D,MAAM,CAAC;QACT,CAAC;QAED,IAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAE5C,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,CAAC;QACT,CAAC;QAED,GAAG,CAAC,CAAiB,UAAqB,EAArB,KAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAArB,cAAqB,EAArB,IAAqB,CAAC;YAAtC,IAAM,MAAM,SAAA;YACf,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC;gBAC/D,qEAAqE;gBACrE,QAAQ,CAAC;YACX,CAAC;YACD,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;SACnF;IACH,CAAC,CAAC,CAAC;IAEP,MAAM,CAAC,aAAa,CAAC;AACvB,CAAC;AApCe,6BAAqB,wBAoCpC,CAAA","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * Transform template html and css into executable code.\n * Intended to be used in a build step.\n */\nimport * as compiler from '@angular/compiler';\nimport {ViewEncapsulation} from '@angular/core';\nimport {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';\nimport {readFileSync} from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\n\nimport {PathMappedReflectorHost} from './path_mapped_reflector_host';\nimport {Console} from './private_import_core';\nimport {ReflectorHost, ReflectorHostContext} from './reflector_host';\nimport {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';\nimport {StaticReflector, StaticReflectorHost, StaticSymbol} from './static_reflector';\n\nconst GENERATED_FILES = /\\.ngfactory\\.ts$|\\.css\\.ts$|\\.css\\.shim\\.ts$/;\nconst GENERATED_OR_DTS_FILES = /\\.d\\.ts$|\\.ngfactory\\.ts$|\\.css\\.ts$|\\.css\\.shim\\.ts$/;\n\nconst PREAMBLE = `/**\n * @fileoverview This file is generated by the Angular 2 template compiler.\n * Do not edit.\n * @suppress {suspiciousCode,uselessCode,missingProperties}\n */\n /* tslint:disable */\n\n`;\n\nexport class CodeGenerator {\n constructor(\n private options: AngularCompilerOptions, private program: ts.Program,\n public host: ts.CompilerHost, private staticReflector: StaticReflector,\n private compiler: compiler.OfflineCompiler, private reflectorHost: StaticReflectorHost) {}\n\n // Write codegen in a directory structure matching the sources.\n private calculateEmitPath(filePath: string): string {\n let root = this.options.basePath;\n for (const eachRootDir of this.options.rootDirs || []) {\n if (this.options.trace) {\n console.error(`Check if ${filePath} is under rootDirs element ${eachRootDir}`);\n }\n if (path.relative(eachRootDir, filePath).indexOf('.') !== 0) {\n root = eachRootDir;\n }\n }\n\n // transplant the codegen path to be inside the `genDir`\n let relativePath: string = path.relative(root, filePath);\n while (relativePath.startsWith('..' + path.sep)) {\n // Strip out any `..` path such as: `../node_modules/@foo` as we want to put everything\n // into `genDir`.\n relativePath = relativePath.substr(3);\n }\n\n return path.join(this.options.genDir, relativePath);\n }\n\n codegen(options: {transitiveModules: boolean}): Promise<any> {\n const staticSymbols =\n extractProgramSymbols(this.program, this.staticReflector, this.reflectorHost, this.options);\n\n return this.compiler.compileModules(staticSymbols, options).then(generatedModules => {\n generatedModules.forEach(generatedModule => {\n const sourceFile = this.program.getSourceFile(generatedModule.fileUrl);\n const emitPath = this.calculateEmitPath(generatedModule.moduleUrl);\n this.host.writeFile(\n emitPath, PREAMBLE + generatedModule.source, false, () => {}, [sourceFile]);\n });\n });\n }\n\n static create(\n options: AngularCompilerOptions, cliOptions: NgcCliOptions, program: ts.Program,\n compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext,\n resourceLoader?: compiler.ResourceLoader, reflectorHost?: ReflectorHost): CodeGenerator {\n resourceLoader = resourceLoader || {\n get: (s: string) => {\n if (!compilerHost.fileExists(s)) {\n // TODO: We should really have a test for error cases like this!\n throw new Error(`Compilation failed. Resource file not found: ${s}`);\n }\n return Promise.resolve(compilerHost.readFile(s));\n }\n };\n const transFile = cliOptions.i18nFile;\n const locale = cliOptions.locale;\n let transContent: string = '';\n if (transFile) {\n if (!locale) {\n throw new Error(\n `The translation file (${transFile}) locale must be provided. Use the --locale option.`);\n }\n transContent = readFileSync(transFile, 'utf8');\n }\n\n const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver();\n if (!reflectorHost) {\n const usePathMapping = !!options.rootDirs && options.rootDirs.length > 0;\n reflectorHost = usePathMapping ?\n new PathMappedReflectorHost(program, compilerHost, options, reflectorHostContext) :\n new ReflectorHost(program, compilerHost, options, reflectorHostContext);\n }\n const staticReflector = new StaticReflector(reflectorHost);\n StaticAndDynamicReflectionCapabilities.install(staticReflector);\n const htmlParser =\n new compiler.I18NHtmlParser(new compiler.HtmlParser(), transContent, cliOptions.i18nFormat);\n const config = new compiler.CompilerConfig({\n genDebugInfo: options.debug === true,\n defaultEncapsulation: ViewEncapsulation.Emulated,\n logBindingUpdate: false,\n useJit: false\n });\n const normalizer =\n new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);\n const expressionParser = new compiler.Parser(new compiler.Lexer());\n const elementSchemaRegistry = new compiler.DomElementSchemaRegistry();\n const console = new Console();\n const tmplParser = new compiler.TemplateParser(\n expressionParser, elementSchemaRegistry, htmlParser, console, []);\n const resolver = new compiler.CompileMetadataResolver(\n new compiler.NgModuleResolver(staticReflector),\n new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),\n elementSchemaRegistry, normalizer, staticReflector);\n // TODO(vicb): do not pass cliOptions.i18nFormat here\n const offlineCompiler = new compiler.OfflineCompiler(\n resolver, tmplParser, new compiler.StyleCompiler(urlResolver),\n new compiler.ViewCompiler(config, elementSchemaRegistry),\n new compiler.DirectiveWrapperCompiler(\n config, expressionParser, elementSchemaRegistry, console),\n new compiler.NgModuleCompiler(), new compiler.TypeScriptEmitter(reflectorHost),\n cliOptions.locale, cliOptions.i18nFormat,\n new compiler.AnimationParser(elementSchemaRegistry));\n\n return new CodeGenerator(\n options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost);\n }\n}\n\nexport function extractProgramSymbols(\n program: ts.Program, staticReflector: StaticReflector, reflectorHost: StaticReflectorHost,\n options: AngularCompilerOptions): StaticSymbol[] {\n // Compare with false since the default should be true\n const skipFileNames =\n options.generateCodeForLibraries === false ? GENERATED_OR_DTS_FILES : GENERATED_FILES;\n\n const staticSymbols: StaticSymbol[] = [];\n\n program.getSourceFiles()\n .filter(sourceFile => !skipFileNames.test(sourceFile.fileName))\n .forEach(sourceFile => {\n const absSrcPath = reflectorHost.getCanonicalFileName(sourceFile.fileName);\n\n const moduleMetadata = staticReflector.getModuleMetadata(absSrcPath);\n if (!moduleMetadata) {\n console.warn(`WARNING: no metadata found for ${absSrcPath}`);\n return;\n }\n\n const metadata = moduleMetadata['metadata'];\n\n if (!metadata) {\n return;\n }\n\n for (const symbol of Object.keys(metadata)) {\n if (metadata[symbol] && metadata[symbol].__symbolic == 'error') {\n // Ignore symbols that are only included to record error information.\n continue;\n }\n staticSymbols.push(reflectorHost.findDeclaration(absSrcPath, symbol, absSrcPath));\n }\n });\n\n return staticSymbols;\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}
\No newline at end of file