7
7
* found in the LICENSE file at https://angular.io/license
8
8
*/
9
9
10
- import { AotCompiler , AotCompilerHost , AotCompilerOptions , EmitterVisitorContext , FormattedMessageChain , GeneratedFile , MessageBundle , NgAnalyzedFile , NgAnalyzedModules , ParseSourceSpan , PartialModule , Position , Serializer , TypeScriptEmitter , Xliff , Xliff2 , Xmb , core , createAotCompiler , getParseErrors , isFormattedError , isSyntaxError } from '@angular/compiler' ;
10
+ import { AotCompiler , AotCompilerHost , AotCompilerOptions , EmitterVisitorContext , FormattedMessageChain , GeneratedFile , MessageBundle , NgAnalyzedFile , NgAnalyzedFileWithInjectables , NgAnalyzedModules , ParseSourceSpan , PartialModule , Position , Serializer , TypeScriptEmitter , Xliff , Xliff2 , Xmb , core , createAotCompiler , getParseErrors , isFormattedError , isSyntaxError } from '@angular/compiler' ;
11
11
import * as fs from 'fs' ;
12
12
import * as path from 'path' ;
13
13
import * as ts from 'typescript' ;
@@ -22,7 +22,7 @@ import {MetadataCache, MetadataTransformer} from './metadata_cache';
22
22
import { getAngularEmitterTransformFactory } from './node_emitter_transform' ;
23
23
import { PartialModuleMetadataTransformer } from './r3_metadata_transform' ;
24
24
import { getAngularClassTransformerFactory } from './r3_transform' ;
25
- import { GENERATED_FILES , StructureIsReused , createMessageDiagnostic , isInRootDir , ngToTsDiagnostic , tsStructureIsReused , userError } from './util' ;
25
+ import { DTS , GENERATED_FILES , StructureIsReused , TS , createMessageDiagnostic , isInRootDir , ngToTsDiagnostic , tsStructureIsReused , userError } from './util' ;
26
26
27
27
28
28
@@ -62,6 +62,7 @@ class AngularCompilerProgram implements Program {
62
62
private _hostAdapter : TsCompilerAotCompilerTypeCheckHostAdapter ;
63
63
private _tsProgram : ts . Program ;
64
64
private _analyzedModules : NgAnalyzedModules | undefined ;
65
+ private _analyzedInjectables : NgAnalyzedFileWithInjectables [ ] | undefined ;
65
66
private _structuralDiagnostics : Diagnostic [ ] | undefined ;
66
67
private _programWithStubs : ts . Program | undefined ;
67
68
private _optionsDiagnostics : Diagnostic [ ] = [ ] ;
@@ -191,12 +192,12 @@ class AngularCompilerProgram implements Program {
191
192
}
192
193
return Promise . resolve ( )
193
194
. then ( ( ) => {
194
- const { tmpProgram, sourceFiles, rootNames} = this . _createProgramWithBasicStubs ( ) ;
195
+ const { tmpProgram, sourceFiles, tsFiles , rootNames} = this . _createProgramWithBasicStubs ( ) ;
195
196
return this . compiler . loadFilesAsync ( sourceFiles ) . then ( analyzedModules => {
196
197
if ( this . _analyzedModules ) {
197
198
throw new Error ( 'Angular structure loaded both synchronously and asynchronously' ) ;
198
199
}
199
- this . _updateProgramWithTypeCheckStubs ( tmpProgram , analyzedModules , rootNames ) ;
200
+ this . _updateProgramWithTypeCheckStubs ( tmpProgram , analyzedModules , [ ] , rootNames ) ;
200
201
} ) ;
201
202
} )
202
203
. catch ( e => this . _createProgramOnError ( e ) ) ;
@@ -304,8 +305,12 @@ class AngularCompilerProgram implements Program {
304
305
}
305
306
this . writeFile ( outFileName , outData , writeByteOrderMark , onError , genFile , sourceFiles ) ;
306
307
} ;
307
- const tsCustomTransformers = this . calculateTransforms (
308
- genFileByFileName , /* partialModules */ undefined , customTransformers ) ;
308
+
309
+ const modules = this . _analyzedInjectables &&
310
+ this . compiler . emitAllPartialModules2 ( this . _analyzedInjectables ) ;
311
+
312
+ const tsCustomTransformers =
313
+ this . calculateTransforms ( genFileByFileName , modules , customTransformers ) ;
309
314
const emitOnlyDtsFiles = ( emitFlags & ( EmitFlags . DTS | EmitFlags . JS ) ) == EmitFlags . DTS ;
310
315
// Restore the original references before we emit so TypeScript doesn't emit
311
316
// a reference to the .d.ts file.
@@ -491,9 +496,11 @@ class AngularCompilerProgram implements Program {
491
496
return ;
492
497
}
493
498
try {
494
- const { tmpProgram, sourceFiles, rootNames} = this . _createProgramWithBasicStubs ( ) ;
495
- const analyzedModules = this . compiler . loadFilesSync ( sourceFiles ) ;
496
- this . _updateProgramWithTypeCheckStubs ( tmpProgram , analyzedModules , rootNames ) ;
499
+ const { tmpProgram, sourceFiles, tsFiles, rootNames} = this . _createProgramWithBasicStubs ( ) ;
500
+ const { analyzedModules, analyzedInjectables} =
501
+ this . compiler . loadFilesSync ( sourceFiles , tsFiles ) ;
502
+ this . _updateProgramWithTypeCheckStubs (
503
+ tmpProgram , analyzedModules , analyzedInjectables , rootNames ) ;
497
504
} catch ( e ) {
498
505
this . _createProgramOnError ( e ) ;
499
506
}
@@ -520,6 +527,7 @@ class AngularCompilerProgram implements Program {
520
527
tmpProgram : ts . Program ,
521
528
rootNames : string [ ] ,
522
529
sourceFiles : string [ ] ,
530
+ tsFiles : string [ ] ,
523
531
} {
524
532
if ( this . _analyzedModules ) {
525
533
throw new Error ( `Internal Error: already initialized!` ) ;
@@ -553,17 +561,23 @@ class AngularCompilerProgram implements Program {
553
561
554
562
const tmpProgram = ts . createProgram ( rootNames , this . options , this . hostAdapter , oldTsProgram ) ;
555
563
const sourceFiles : string [ ] = [ ] ;
564
+ const tsFiles : string [ ] = [ ] ;
556
565
tmpProgram . getSourceFiles ( ) . forEach ( sf => {
557
566
if ( this . hostAdapter . isSourceFile ( sf . fileName ) ) {
558
567
sourceFiles . push ( sf . fileName ) ;
559
568
}
569
+ if ( TS . test ( sf . fileName ) && ! DTS . test ( sf . fileName ) ) {
570
+ tsFiles . push ( sf . fileName ) ;
571
+ }
560
572
} ) ;
561
- return { tmpProgram, sourceFiles, rootNames} ;
573
+ return { tmpProgram, sourceFiles, tsFiles , rootNames} ;
562
574
}
563
575
564
576
private _updateProgramWithTypeCheckStubs (
565
- tmpProgram : ts . Program , analyzedModules : NgAnalyzedModules , rootNames : string [ ] ) {
577
+ tmpProgram : ts . Program , analyzedModules : NgAnalyzedModules ,
578
+ analyzedInjectables : NgAnalyzedFileWithInjectables [ ] , rootNames : string [ ] ) {
566
579
this . _analyzedModules = analyzedModules ;
580
+ this . _analyzedInjectables = analyzedInjectables ;
567
581
tmpProgram . getSourceFiles ( ) . forEach ( sf => {
568
582
if ( sf . fileName . endsWith ( '.ngfactory.ts' ) ) {
569
583
const { generate, baseFileName} = this . hostAdapter . shouldGenerateFile ( sf . fileName ) ;
0 commit comments