@@ -19,33 +19,34 @@ import {CompileMetadataResolver, HtmlParser, DirectiveNormalizer, Lexer, Parser,
1919import { ReflectorHost } from './reflector_host' ;
2020import { StaticAndDynamicReflectionCapabilities } from './static_reflection_capabilities' ;
2121
22-
2322function extract (
2423 ngOptions : tsc . AngularCompilerOptions , program : ts . Program , host : ts . CompilerHost ) {
2524 return Extractor . create ( ngOptions , program , host ) . extract ( ) ;
2625}
2726
28- const GENERATED_FILES = / \. n g f a c t o r y \. t s $ | \. c s s \. t s $ | \. c s s \. s h i m \. t s $ / ;
27+ const _dirPaths = new Map < compiler . CompileDirectiveMetadata , string > ( ) ;
28+
29+ const _GENERATED_FILES = / \. n g f a c t o r y \. t s $ | \. c s s \. t s $ | \. c s s \. s h i m \. t s $ / ;
2930
3031class Extractor {
3132 constructor (
32- private options : tsc . AngularCompilerOptions , private program : ts . Program ,
33+ private _options : tsc . AngularCompilerOptions , private _program : ts . Program ,
3334 public host : ts . CompilerHost , private staticReflector : StaticReflector ,
34- private resolver : CompileMetadataResolver , private compiler : compiler . OfflineCompiler ,
35- private reflectorHost : ReflectorHost , private _extractor : MessageExtractor ) { }
35+ private _resolver : CompileMetadataResolver , private _compiler : compiler . OfflineCompiler ,
36+ private _reflectorHost : ReflectorHost , private _extractor : MessageExtractor ) { }
3637
37- private extractCmpMessages ( metadatas : compiler . CompileDirectiveMetadata [ ] ) :
38+ private _extractCmpMessages ( metadatas : compiler . CompileDirectiveMetadata [ ] ) :
3839 Promise < ExtractionResult > {
3940 if ( ! metadatas || ! metadatas . length ) {
4041 return null ;
4142 }
4243
4344 const normalize = ( metadata : compiler . CompileDirectiveMetadata ) => {
4445 const directiveType = metadata . type . runtime ;
45- const directives = this . resolver . getViewDirectivesMetadata ( directiveType ) ;
46- return Promise . all ( directives . map ( d => this . compiler . normalizeDirectiveMetadata ( d ) ) )
46+ const directives = this . _resolver . getViewDirectivesMetadata ( directiveType ) ;
47+ return Promise . all ( directives . map ( d => this . _compiler . normalizeDirectiveMetadata ( d ) ) )
4748 . then ( normalizedDirectives => {
48- const pipes = this . resolver . getViewPipesMetadata ( directiveType ) ;
49+ const pipes = this . _resolver . getViewPipesMetadata ( directiveType ) ;
4950 return new compiler . NormalizedComponentWithViewDirectives (
5051 metadata , normalizedDirectives , pipes ) ;
5152 } ) ;
@@ -56,8 +57,8 @@ class Extractor {
5657 let messages : Message [ ] = [ ] ;
5758 let errors : ParseError [ ] = [ ] ;
5859 cmps . forEach ( cmp => {
59- // TODO(vicb): url
60- let result = this . _extractor . extract ( cmp . component . template . template , ' url' ) ;
60+ let url = _dirPaths . get ( cmp . component ) ;
61+ let result = this . _extractor . extract ( cmp . component . template . template , url ) ;
6162 errors = errors . concat ( result . errors ) ;
6263 messages = messages . concat ( result . messages ) ;
6364 } ) ;
@@ -67,7 +68,7 @@ class Extractor {
6768 } ) ;
6869 }
6970
70- private readComponents ( absSourcePath : string ) {
71+ private _readComponents ( absSourcePath : string ) : Promise < compiler . CompileDirectiveMetadata > [ ] {
7172 const result : Promise < compiler . CompileDirectiveMetadata > [ ] = [ ] ;
7273 const metadata = this . staticReflector . getModuleMetadata ( absSourcePath ) ;
7374 if ( ! metadata ) {
@@ -80,26 +81,29 @@ class Extractor {
8081 return result ;
8182 }
8283 for ( const symbol of symbols ) {
83- const staticType = this . reflectorHost . findDeclaration ( absSourcePath , symbol , absSourcePath ) ;
84+ const staticType = this . _reflectorHost . findDeclaration ( absSourcePath , symbol , absSourcePath ) ;
8485 let directive : compiler . CompileDirectiveMetadata ;
85- directive = this . resolver . maybeGetDirectiveMetadata ( < any > staticType ) ;
86+ directive = this . _resolver . maybeGetDirectiveMetadata ( < any > staticType ) ;
8687
87- if ( ! directive || ! directive . isComponent ) {
88- continue ;
88+ if ( directive && directive . isComponent ) {
89+ let promise = this . _compiler . normalizeDirectiveMetadata ( directive ) ;
90+ promise . then ( md => _dirPaths . set ( md , absSourcePath ) ) ;
91+ result . push ( promise ) ;
8992 }
90- result . push ( this . compiler . normalizeDirectiveMetadata ( directive ) ) ;
9193 }
9294 return result ;
9395 }
9496
9597 extract ( ) : Promise < any > {
96- const promises = this . program . getSourceFiles ( )
98+ _dirPaths . clear ( ) ;
99+
100+ const promises = this . _program . getSourceFiles ( )
97101 . map ( sf => sf . fileName )
98- . filter ( f => ! GENERATED_FILES . test ( f ) )
102+ . filter ( f => ! _GENERATED_FILES . test ( f ) )
99103 . map (
100104 ( absSourcePath : string ) : Promise < any > =>
101- Promise . all ( this . readComponents ( absSourcePath ) )
102- . then ( metadatas => this . extractCmpMessages ( metadatas ) )
105+ Promise . all ( this . _readComponents ( absSourcePath ) )
106+ . then ( metadatas => this . _extractCmpMessages ( metadatas ) )
103107 . catch ( e => console . error ( e . stack ) ) ) ;
104108
105109 let messages : Message [ ] = [ ] ;
@@ -112,12 +116,12 @@ class Extractor {
112116 } ) ;
113117
114118 if ( errors . length ) {
115- throw errors ;
119+ throw new Error ( errors . map ( e => e . toString ( ) ) . join ( '\n' ) ) ;
116120 }
117121
118122 messages = removeDuplicates ( messages ) ;
119123
120- let genPath = path . join ( this . options . genDir , 'messages.xmb' ) ;
124+ let genPath = path . join ( this . _options . genDir , 'messages.xmb' ) ;
121125 let msgBundle = serializeXmb ( messages ) ;
122126
123127 this . host . writeFile ( genPath , msgBundle , false ) ;
0 commit comments