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YACb,KAAK,MAAM,CAAC;YACZ,KAAK,QAAQ;gBACX,MAAM,CAAC,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,0BAAuB,UAAU,OAAG,CAAC,CAAC;IACxD,CAAC;IAEM,gBAAM,GAAb,UACI,OAAmC,EAAE,OAAmB,EAAE,cAA+B,EACzF,MAAoB,EAAE,mBAAyC,EAC/D,cAA6B;QAC/B,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;YACpB,IAAM,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;YACzE,IAAM,OAAO,GAAG,mBAAmB,IAAI,IAAI,2CAA2B,CAAC,cAAc,CAAC,CAAC;YACvF,cAAc,GAAG,cAAc,GAAG,IAAI,kDAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;gBACrD,IAAI,4BAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAChF,CAAC;QAEM,IAAA,iFAAsB,CAA8D;QAE3F,MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACtF,CAAC;IACH,gBAAC;AAAD,CAAC,AAnFD,IAmFC;AAnFY,8BAAS","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/**\n * Extract i18n messages from source code\n */\n// Must be imported first, because Angular decorators throw on load.\nimport 'reflect-metadata';\n\nimport * as compiler from '@angular/compiler';\nimport * as tsc from '@angular/tsc-wrapped';\nimport * as path from 'path';\nimport * as ts from 'typescript';\n\nimport {CompilerHost, CompilerHostContext, ModuleResolutionHostAdapter} from './compiler_host';\nimport {PathMappedCompilerHost} from './path_mapped_compiler_host';\n\nexport class Extractor {\n  constructor(\n      private options: tsc.AngularCompilerOptions, private ngExtractor: compiler.Extractor,\n      public host: ts.CompilerHost, private ngCompilerHost: CompilerHost,\n      private program: ts.Program) {}\n\n  extract(formatName: string, outFile: string|null): Promise<string[]> {\n    // Checks the format and returns the extension\n    const ext = this.getExtension(formatName);\n\n    const promiseBundle = this.extractBundle();\n\n    return promiseBundle.then(bundle => {\n      const content = this.serialize(bundle, formatName);\n      const dstFile = outFile || `messages.${ext}`;\n      const dstPath = path.join(this.options.genDir !, dstFile);\n      this.host.writeFile(dstPath, content, false);\n      return [dstPath];\n    });\n  }\n\n  extractBundle(): Promise<compiler.MessageBundle> {\n    const files = this.program.getSourceFiles().map(\n        sf => this.ngCompilerHost.getCanonicalFileName(sf.fileName));\n\n    return this.ngExtractor.extract(files);\n  }\n\n  serialize(bundle: compiler.MessageBundle, formatName: string): string {\n    const format = formatName.toLowerCase();\n    let serializer: compiler.Serializer;\n\n    switch (format) {\n      case 'xmb':\n        serializer = new compiler.Xmb();\n        break;\n      case 'xliff2':\n      case 'xlf2':\n        serializer = new compiler.Xliff2();\n        break;\n      case 'xlf':\n      case 'xliff':\n      default:\n        serializer = new compiler.Xliff();\n    }\n    return bundle.write(\n        serializer, (sourcePath: string) => this.options.basePath ?\n            path.relative(this.options.basePath, sourcePath) :\n            sourcePath);\n  }\n\n  getExtension(formatName: string): string {\n    const format = (formatName || 'xlf').toLowerCase();\n\n    switch (format) {\n      case 'xmb':\n        return 'xmb';\n      case 'xlf':\n      case 'xlif':\n      case 'xliff':\n      case 'xlf2':\n      case 'xliff2':\n        return 'xlf';\n    }\n\n    throw new Error(`Unsupported format \"${formatName}\"`);\n  }\n\n  static create(\n      options: tsc.AngularCompilerOptions, program: ts.Program, tsCompilerHost: ts.CompilerHost,\n      locale?: string|null, compilerHostContext?: CompilerHostContext,\n      ngCompilerHost?: CompilerHost): Extractor {\n    if (!ngCompilerHost) {\n      const usePathMapping = !!options.rootDirs && options.rootDirs.length > 0;\n      const context = compilerHostContext || new ModuleResolutionHostAdapter(tsCompilerHost);\n      ngCompilerHost = usePathMapping ? new PathMappedCompilerHost(program, options, context) :\n                                        new CompilerHost(program, options, context);\n    }\n\n    const {extractor: ngExtractor} = compiler.Extractor.create(ngCompilerHost, locale || null);\n\n    return new Extractor(options, ngExtractor, tsCompilerHost, ngCompilerHost, program);\n  }\n}\n"]}
(12-12/30)