6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
import * as ts from 'typescript' ;
9
+
9
10
import { FileSystem } from '../../../src/ngtsc/file_system' ;
10
11
import { DecorationAnalyzer } from '../analysis/decoration_analyzer' ;
11
12
import { ModuleWithProvidersAnalyses , ModuleWithProvidersAnalyzer } from '../analysis/module_with_providers_analyzer' ;
@@ -27,8 +28,17 @@ import {Renderer} from '../rendering/renderer';
27
28
import { RenderingFormatter } from '../rendering/rendering_formatter' ;
28
29
import { UmdRenderingFormatter } from '../rendering/umd_rendering_formatter' ;
29
30
import { FileToWrite } from '../rendering/utils' ;
31
+
30
32
import { EntryPointBundle } from './entry_point_bundle' ;
31
33
34
+ export type TransformResult = {
35
+ success : true ; diagnostics : ts . Diagnostic [ ] ; transformedFiles : FileToWrite [ ] ;
36
+ } |
37
+ {
38
+ success : false ;
39
+ diagnostics : ts . Diagnostic [ ] ;
40
+ } ;
41
+
32
42
/**
33
43
* A Package is stored in a directory on disk and that directory can contain one or more package
34
44
* formats - e.g. fesm2015, UMD, etc. Additionally, each package provides typings (`.d.ts` files).
@@ -58,12 +68,17 @@ export class Transformer {
58
68
* @param bundle the bundle to transform.
59
69
* @returns information about the files that were transformed.
60
70
*/
61
- transform ( bundle : EntryPointBundle ) : FileToWrite [ ] {
71
+ transform ( bundle : EntryPointBundle ) : TransformResult {
62
72
const reflectionHost = this . getHost ( bundle ) ;
63
73
64
74
// Parse and analyze the files.
65
75
const { decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
66
- moduleWithProvidersAnalyses} = this . analyzeProgram ( reflectionHost , bundle ) ;
76
+ moduleWithProvidersAnalyses, diagnostics} = this . analyzeProgram ( reflectionHost , bundle ) ;
77
+
78
+ // Bail if the analysis produced any errors.
79
+ if ( hasErrors ( diagnostics ) ) {
80
+ return { success : false , diagnostics} ;
81
+ }
67
82
68
83
// Transform the source files and source maps.
69
84
const srcFormatter = this . getRenderingFormatter ( reflectionHost , bundle ) ;
@@ -81,7 +96,7 @@ export class Transformer {
81
96
renderedFiles = renderedFiles . concat ( renderedDtsFiles ) ;
82
97
}
83
98
84
- return renderedFiles ;
99
+ return { success : true , diagnostics , transformedFiles : renderedFiles } ;
85
100
}
86
101
87
102
getHost ( bundle : EntryPointBundle ) : NgccReflectionHost {
@@ -127,8 +142,10 @@ export class Transformer {
127
142
new SwitchMarkerAnalyzer ( reflectionHost , bundle . entryPoint . package ) ;
128
143
const switchMarkerAnalyses = switchMarkerAnalyzer . analyzeProgram ( bundle . src . program ) ;
129
144
130
- const decorationAnalyzer =
131
- new DecorationAnalyzer ( this . fs , bundle , reflectionHost , referencesRegistry ) ;
145
+ const diagnostics : ts . Diagnostic [ ] = [ ] ;
146
+ const decorationAnalyzer = new DecorationAnalyzer (
147
+ this . fs , bundle , reflectionHost , referencesRegistry ,
148
+ diagnostic => diagnostics . push ( diagnostic ) ) ;
132
149
const decorationAnalyses = decorationAnalyzer . analyzeProgram ( ) ;
133
150
134
151
const moduleWithProvidersAnalyzer =
@@ -142,14 +159,18 @@ export class Transformer {
142
159
privateDeclarationsAnalyzer . analyzeProgram ( bundle . src . program ) ;
143
160
144
161
return { decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
145
- moduleWithProvidersAnalyses} ;
162
+ moduleWithProvidersAnalyses, diagnostics } ;
146
163
}
147
164
}
148
165
166
+ export function hasErrors ( diagnostics : ts . Diagnostic [ ] ) {
167
+ return diagnostics . some ( d => d . category === ts . DiagnosticCategory . Error ) ;
168
+ }
149
169
150
170
interface ProgramAnalyses {
151
171
decorationAnalyses : Map < ts . SourceFile , CompiledFile > ;
152
172
switchMarkerAnalyses : SwitchMarkerAnalyses ;
153
173
privateDeclarationsAnalyses : ExportInfo [ ] ;
154
174
moduleWithProvidersAnalyses : ModuleWithProvidersAnalyses | null ;
175
+ diagnostics : ts . Diagnostic [ ] ;
155
176
}
0 commit comments