@@ -69,18 +69,15 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
69
69
private _reflectorHost ! : ReflectorHost ;
70
70
// TODO(issue/24571): remove '!'.
71
71
private _checker ! : ts . TypeChecker | null ;
72
- private _typeCache : Symbol [ ] = [ ] ;
73
72
private context : string | undefined ;
74
73
private lastProgram : ts . Program | undefined ;
75
74
private modulesOutOfDate : boolean = true ;
76
75
// TODO(issue/24571): remove '!'.
77
76
private analyzedModules ! : NgAnalyzedModules | null ;
78
- // TODO(issue/24571): remove '!'.
79
- private fileToComponent ! : Map < string , StaticSymbol > | null ;
77
+ private fileToComponent = new Map < string , StaticSymbol > ( ) ;
80
78
// TODO(issue/24571): remove '!'.
81
79
private templateReferences ! : string [ ] | null ;
82
- // TODO(issue/24571): remove '!'.
83
- private collectedErrors ! : Map < string , any [ ] > | null ;
80
+ private collectedErrors = new Map < string , any [ ] > ( ) ;
84
81
private fileVersions = new Map < string , string > ( ) ;
85
82
86
83
constructor ( private host : ts . LanguageServiceHost , private tsService : ts . LanguageService ) { }
@@ -132,7 +129,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
132
129
} else {
133
130
this . ensureTemplateMap ( ) ;
134
131
// TODO: Cannocalize the file?
135
- const componentType = this . fileToComponent ! . get ( fileName ) ;
132
+ const componentType = this . fileToComponent . get ( fileName ) ;
136
133
if ( componentType ) {
137
134
return this . getSourceFromType (
138
135
fileName , this . host . getScriptVersion ( fileName ) , componentType ) ;
@@ -168,7 +165,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
168
165
169
166
getTemplates ( fileName : string ) : TemplateSources {
170
167
this . ensureTemplateMap ( ) ;
171
- const componentType = this . fileToComponent ! . get ( fileName ) ;
168
+ const componentType = this . fileToComponent . get ( fileName ) ;
172
169
if ( componentType ) {
173
170
const templateSource = this . getTemplateAt ( fileName , 0 ) ;
174
171
if ( templateSource ) {
@@ -224,7 +221,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
224
221
this . analyzedModules = null ;
225
222
this . _reflector = null ;
226
223
this . templateReferences = null ;
227
- this . fileToComponent = null ;
224
+ this . fileToComponent . clear ( ) ;
228
225
this . ensureAnalyzedModules ( ) ;
229
226
this . modulesOutOfDate = false ;
230
227
}
@@ -274,15 +271,13 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
274
271
275
272
private clearCaches ( ) {
276
273
this . _checker = null ;
277
- this . _typeCache = [ ] ;
278
274
this . _resolver = null ;
279
- this . collectedErrors = null ;
275
+ this . collectedErrors . clear ( ) ;
280
276
this . modulesOutOfDate = true ;
281
277
}
282
278
283
279
private ensureTemplateMap ( ) {
284
- if ( ! this . fileToComponent || ! this . templateReferences ) {
285
- const fileToComponent = new Map < string , StaticSymbol > ( ) ;
280
+ if ( ! this . templateReferences ) {
286
281
const templateReference : string [ ] = [ ] ;
287
282
const ngModuleSummary = this . getAnalyzedModules ( ) ;
288
283
const urlResolver = createOfflineCompileUrlResolver ( ) ;
@@ -293,12 +288,11 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
293
288
const templateName = urlResolver . resolve (
294
289
this . reflector . componentModuleUrl ( directive . reference ) ,
295
290
metadata . template . templateUrl ) ;
296
- fileToComponent . set ( templateName , directive . reference ) ;
291
+ this . fileToComponent . set ( templateName , directive . reference ) ;
297
292
templateReference . push ( templateName ) ;
298
293
}
299
294
}
300
295
}
301
- this . fileToComponent = fileToComponent ;
302
296
this . templateReferences = templateReference ;
303
297
}
304
298
}
@@ -412,11 +406,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
412
406
413
407
private collectError ( error : any , filePath : string | null ) {
414
408
if ( filePath ) {
415
- let errorMap = this . collectedErrors ;
416
- if ( ! errorMap || ! this . collectedErrors ) {
417
- errorMap = this . collectedErrors = new Map ( ) ;
418
- }
419
- let errors = errorMap . get ( filePath ) ;
409
+ let errors = this . collectedErrors . get ( filePath ) ;
420
410
if ( ! errors ) {
421
411
errors = [ ] ;
422
412
this . collectedErrors . set ( filePath , errors ) ;
@@ -517,7 +507,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
517
507
}
518
508
519
509
private getCollectedErrors ( defaultSpan : Span , sourceFile : ts . SourceFile ) : DeclarationError [ ] {
520
- const errors = ( this . collectedErrors && this . collectedErrors . get ( sourceFile . fileName ) ) ;
510
+ const errors = this . collectedErrors . get ( sourceFile . fileName ) ;
521
511
return ( errors && errors . map ( ( e : any ) => {
522
512
const line = e . line || ( e . position && e . position . line ) ;
523
513
const column = e . column || ( e . position && e . position . column ) ;
0 commit comments