@@ -187,7 +187,7 @@ type snapshot struct {
187
187
fileInfos map [tspath.Path ]* fileInfo
188
188
options * core.CompilerOptions
189
189
// Contains the map of ReferencedSet=Referenced files of the file if module emit is enabled
190
- referencedMap * collections.ManyToManyMap [tspath.Path , tspath.Path ]
190
+ referencedMap collections.ManyToManyMap [tspath.Path , tspath.Path ]
191
191
// Cache of semantic diagnostics for files with their Path being the key
192
192
semanticDiagnosticsPerFile map [tspath.Path ]* diagnosticsOrBuildInfoDiagnosticsWithFileName
193
193
// Cache of dts emit diagnostics for files with their Path being the key
@@ -214,16 +214,6 @@ type snapshot struct {
214
214
allFilesExcludingDefaultLibraryFile []* ast.SourceFile
215
215
}
216
216
217
- func (s * snapshot ) tracksReferences () bool {
218
- return s .options .Module != core .ModuleKindNone
219
- }
220
-
221
- func (s * snapshot ) createReferenceMap () {
222
- if s .tracksReferences () {
223
- s .referencedMap = & collections.ManyToManyMap [tspath.Path , tspath.Path ]{}
224
- }
225
- }
226
-
227
217
func (s * snapshot ) createEmitSignaturesMap () {
228
218
if s .emitSignatures == nil && s .options .Composite .IsTrue () {
229
219
s .emitSignatures = make (map [tspath.Path ]* emitSignature )
@@ -274,16 +264,14 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
274
264
options : program .Options (),
275
265
semanticDiagnosticsPerFile : make (map [tspath.Path ]* diagnosticsOrBuildInfoDiagnosticsWithFileName , len (files )),
276
266
}
277
- snapshot .createReferenceMap ()
278
267
if oldProgram != nil && snapshot .options .Composite .IsTrue () {
279
268
snapshot .latestChangedDtsFile = oldProgram .snapshot .latestChangedDtsFile
280
269
}
281
270
if snapshot .options .NoCheck .IsTrue () {
282
271
snapshot .checkPending = true
283
272
}
284
273
285
- canUseStateFromOldProgram := oldProgram != nil && snapshot .tracksReferences () == oldProgram .snapshot .tracksReferences ()
286
- if canUseStateFromOldProgram {
274
+ if oldProgram != nil {
287
275
// Copy old snapshot's changed files set
288
276
snapshot .changedFilesSet = oldProgram .snapshot .changedFilesSet .Clone ()
289
277
if len (oldProgram .snapshot .affectedFilesPendingEmit ) != 0 {
@@ -295,7 +283,7 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
295
283
snapshot .buildInfoEmitPending = snapshot .options .IsIncremental ()
296
284
}
297
285
298
- canCopySemanticDiagnostics := canUseStateFromOldProgram &&
286
+ canCopySemanticDiagnostics := oldProgram != nil &&
299
287
! tsoptions .CompilerOptionsAffectSemanticDiagnostics (oldProgram .snapshot .options , program .Options ())
300
288
// We can only reuse emit signatures (i.e. .d.ts signatures) if the .d.ts file is unchanged,
301
289
// which will eg be depedent on change in options like declarationDir and outDir options are unchanged.
@@ -317,30 +305,24 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
317
305
impliedNodeFormat := program .GetSourceFileMetaData (file .Path ()).ImpliedNodeFormat
318
306
affectsGlobalScope := fileAffectsGlobalScope (file )
319
307
var signature string
320
- var newReferences * collections.Set [tspath.Path ]
321
- if snapshot .referencedMap != nil {
322
- newReferences = getReferencedFiles (program , file )
323
- if newReferences != nil {
324
- snapshot .referencedMap .Add (file .Path (), newReferences )
325
- }
308
+ newReferences := getReferencedFiles (program , file )
309
+ if newReferences != nil {
310
+ snapshot .referencedMap .Add (file .Path (), newReferences )
326
311
}
327
- if canUseStateFromOldProgram {
312
+ if oldProgram != nil {
328
313
if oldFileInfo , ok := oldProgram .snapshot .fileInfos [file .Path ()]; ok {
329
314
signature = oldFileInfo .signature
330
315
if oldFileInfo .version == version || oldFileInfo .affectsGlobalScope != affectsGlobalScope || oldFileInfo .impliedNodeFormat != impliedNodeFormat {
331
316
snapshot .addFileToChangeSet (file .Path ())
332
- } else if snapshot .referencedMap != nil {
333
- oldReferences , _ := oldProgram .snapshot .referencedMap .GetValues (file .Path ())
317
+ } else if oldReferences , _ := oldProgram .snapshot .referencedMap .GetValues (file .Path ()); ! newReferences .Equals (oldReferences ) {
334
318
// Referenced files changed
335
- if ! newReferences .Equals (oldReferences ) {
336
- snapshot .addFileToChangeSet (file .Path ())
337
- } else {
338
- for refPath := range newReferences .Keys () {
339
- if program .GetSourceFileByPath (refPath ) == nil {
340
- // Referenced file was deleted in the new program
341
- snapshot .addFileToChangeSet (file .Path ())
342
- break
343
- }
319
+ snapshot .addFileToChangeSet (file .Path ())
320
+ } else if newReferences != nil {
321
+ for refPath := range newReferences .Keys () {
322
+ if program .GetSourceFileByPath (refPath ) == nil {
323
+ // Referenced file was deleted in the new program
324
+ snapshot .addFileToChangeSet (file .Path ())
325
+ break
344
326
}
345
327
}
346
328
}
@@ -381,7 +363,7 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
381
363
impliedNodeFormat : impliedNodeFormat ,
382
364
}
383
365
}
384
- if canUseStateFromOldProgram {
366
+ if oldProgram != nil {
385
367
// If the global file is removed, add all files as changed
386
368
allFilesExcludingDefaultLibraryFileAddedToChangeSet := false
387
369
for filePath , oldInfo := range oldProgram .snapshot .fileInfos {
@@ -417,11 +399,10 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
417
399
snapshot .buildInfoEmitPending = true
418
400
}
419
401
}
420
- }
421
- if canUseStateFromOldProgram &&
422
- len (snapshot .semanticDiagnosticsPerFile ) != len (snapshot .fileInfos ) &&
423
- oldProgram .snapshot .checkPending != snapshot .checkPending {
424
- snapshot .buildInfoEmitPending = true
402
+ if len (snapshot .semanticDiagnosticsPerFile ) != len (snapshot .fileInfos ) &&
403
+ oldProgram .snapshot .checkPending != snapshot .checkPending {
404
+ snapshot .buildInfoEmitPending = true
405
+ }
425
406
}
426
407
return snapshot
427
408
}
0 commit comments