1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | "use strict";
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | require('reflect-metadata');
|
14 | var compiler = require('@angular/compiler');
|
15 | var core_1 = require('@angular/core');
|
16 | var codegen_1 = require('./codegen');
|
17 | var reflector_host_1 = require('./reflector_host');
|
18 | var static_reflection_capabilities_1 = require('./static_reflection_capabilities');
|
19 | var static_reflector_1 = require('./static_reflector');
|
20 | var Extractor = (function () {
|
21 | function Extractor(options, program, host, staticReflector, messageBundle, reflectorHost, metadataResolver) {
|
22 | this.options = options;
|
23 | this.program = program;
|
24 | this.host = host;
|
25 | this.staticReflector = staticReflector;
|
26 | this.messageBundle = messageBundle;
|
27 | this.reflectorHost = reflectorHost;
|
28 | this.metadataResolver = metadataResolver;
|
29 | }
|
30 | Extractor.prototype.extract = function () {
|
31 | var _this = this;
|
32 | var programSymbols = codegen_1.extractProgramSymbols(this.program, this.staticReflector, this.reflectorHost, this.options);
|
33 | var _a = compiler.analyzeAndValidateNgModules(programSymbols, { transitiveModules: true }, this.metadataResolver), ngModules = _a.ngModules, files = _a.files;
|
34 | return compiler.loadNgModuleDirectives(ngModules).then(function () {
|
35 | var errors = [];
|
36 | files.forEach(function (file) {
|
37 | var compMetas = [];
|
38 | file.directives.forEach(function (directiveType) {
|
39 | var dirMeta = _this.metadataResolver.getDirectiveMetadata(directiveType);
|
40 | if (dirMeta && dirMeta.isComponent) {
|
41 | compMetas.push(dirMeta);
|
42 | }
|
43 | });
|
44 | compMetas.forEach(function (compMeta) {
|
45 | var html = compMeta.template.template;
|
46 | var interpolationConfig = compiler.InterpolationConfig.fromArray(compMeta.template.interpolation);
|
47 | errors.push.apply(errors, _this.messageBundle.updateFromTemplate(html, file.srcUrl, interpolationConfig));
|
48 | });
|
49 | });
|
50 | if (errors.length) {
|
51 | throw new Error(errors.map(function (e) { return e.toString(); }).join('\n'));
|
52 | }
|
53 | return _this.messageBundle;
|
54 | });
|
55 | };
|
56 | Extractor.create = function (options, translationsFormat, program, compilerHost, resourceLoader, reflectorHost) {
|
57 | var htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser());
|
58 | var urlResolver = compiler.createOfflineCompileUrlResolver();
|
59 | if (!reflectorHost)
|
60 | reflectorHost = new reflector_host_1.ReflectorHost(program, compilerHost, options);
|
61 | var staticReflector = new static_reflector_1.StaticReflector(reflectorHost);
|
62 | static_reflection_capabilities_1.StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
63 | var config = new compiler.CompilerConfig({
|
64 | genDebugInfo: options.debug === true,
|
65 | defaultEncapsulation: core_1.ViewEncapsulation.Emulated,
|
66 | logBindingUpdate: false,
|
67 | useJit: false
|
68 | });
|
69 | var normalizer = new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config);
|
70 | var elementSchemaRegistry = new compiler.DomElementSchemaRegistry();
|
71 | var resolver = new compiler.CompileMetadataResolver(new compiler.NgModuleResolver(staticReflector), new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), elementSchemaRegistry, normalizer, staticReflector);
|
72 |
|
73 | var messageBundle = new compiler.MessageBundle(htmlParser, [], {});
|
74 | return new Extractor(options, program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver);
|
75 | };
|
76 | return Extractor;
|
77 | }());
|
78 | exports.Extractor = Extractor;
|
79 |
|
\ | No newline at end of file |