* Create the state so that we can iterate on changedFiles/affected files
(newProgram, getCanonicalFileName, oldState, disableUseFileVersionAsSignature)
| 120073 | * Create the state so that we can iterate on changedFiles/affected files |
| 120074 | */ |
| 120075 | function createBuilderProgramState(newProgram, getCanonicalFileName, oldState, disableUseFileVersionAsSignature) { |
| 120076 | var state = ts.BuilderState.create(newProgram, getCanonicalFileName, oldState, disableUseFileVersionAsSignature); |
| 120077 | state.program = newProgram; |
| 120078 | var compilerOptions = newProgram.getCompilerOptions(); |
| 120079 | state.compilerOptions = compilerOptions; |
| 120080 | // With --out or --outFile, any change affects all semantic diagnostics so no need to cache them |
| 120081 | if (!ts.outFile(compilerOptions)) { |
| 120082 | state.semanticDiagnosticsPerFile = new ts.Map(); |
| 120083 | } |
| 120084 | state.changedFilesSet = new ts.Set(); |
| 120085 | var useOldState = ts.BuilderState.canReuseOldState(state.referencedMap, oldState); |
| 120086 | var oldCompilerOptions = useOldState ? oldState.compilerOptions : undefined; |
| 120087 | var canCopySemanticDiagnostics = useOldState && oldState.semanticDiagnosticsPerFile && !!state.semanticDiagnosticsPerFile && |
| 120088 | !ts.compilerOptionsAffectSemanticDiagnostics(compilerOptions, oldCompilerOptions); |
| 120089 | if (useOldState) { |
| 120090 | // Verify the sanity of old state |
| 120091 | if (!oldState.currentChangedFilePath) { |
| 120092 | var affectedSignatures = oldState.currentAffectedFilesSignatures; |
| 120093 | ts.Debug.assert(!oldState.affectedFiles && (!affectedSignatures || !affectedSignatures.size), "Cannot reuse if only few affected files of currentChangedFile were iterated"); |
| 120094 | } |
| 120095 | var changedFilesSet = oldState.changedFilesSet; |
| 120096 | if (canCopySemanticDiagnostics) { |
| 120097 | ts.Debug.assert(!changedFilesSet || !ts.forEachKey(changedFilesSet, function (path) { return oldState.semanticDiagnosticsPerFile.has(path); }), "Semantic diagnostics shouldnt be available for changed files"); |
| 120098 | } |
| 120099 | // Copy old state's changed files set |
| 120100 | changedFilesSet === null || changedFilesSet === void 0 ? void 0 : changedFilesSet.forEach(function (value) { return state.changedFilesSet.add(value); }); |
| 120101 | if (!ts.outFile(compilerOptions) && oldState.affectedFilesPendingEmit) { |
| 120102 | state.affectedFilesPendingEmit = oldState.affectedFilesPendingEmit.slice(); |
| 120103 | state.affectedFilesPendingEmitKind = oldState.affectedFilesPendingEmitKind && new ts.Map(oldState.affectedFilesPendingEmitKind); |
| 120104 | state.affectedFilesPendingEmitIndex = oldState.affectedFilesPendingEmitIndex; |
| 120105 | state.seenAffectedFiles = new ts.Set(); |
| 120106 | } |
| 120107 | } |
| 120108 | // Update changed files and copy semantic diagnostics if we can |
| 120109 | var referencedMap = state.referencedMap; |
| 120110 | var oldReferencedMap = useOldState ? oldState.referencedMap : undefined; |
| 120111 | var copyDeclarationFileDiagnostics = canCopySemanticDiagnostics && !compilerOptions.skipLibCheck === !oldCompilerOptions.skipLibCheck; |
| 120112 | var copyLibFileDiagnostics = copyDeclarationFileDiagnostics && !compilerOptions.skipDefaultLibCheck === !oldCompilerOptions.skipDefaultLibCheck; |
| 120113 | state.fileInfos.forEach(function (info, sourceFilePath) { |
| 120114 | var oldInfo; |
| 120115 | var newReferences; |
| 120116 | // if not using old state, every file is changed |
| 120117 | if (!useOldState || |
| 120118 | // File wasn't present in old state |
| 120119 | !(oldInfo = oldState.fileInfos.get(sourceFilePath)) || |
| 120120 | // versions dont match |
| 120121 | oldInfo.version !== info.version || |
| 120122 | // Referenced files changed |
| 120123 | !hasSameKeys(newReferences = referencedMap && referencedMap.getValues(sourceFilePath), oldReferencedMap && oldReferencedMap.getValues(sourceFilePath)) || |
| 120124 | // Referenced file was deleted in the new program |
| 120125 | newReferences && ts.forEachKey(newReferences, function (path) { return !state.fileInfos.has(path) && oldState.fileInfos.has(path); })) { |
| 120126 | // Register file as changed file and do not copy semantic diagnostics, since all changed files need to be re-evaluated |
| 120127 | state.changedFilesSet.add(sourceFilePath); |
| 120128 | } |
| 120129 | else if (canCopySemanticDiagnostics) { |
| 120130 | var sourceFile = newProgram.getSourceFileByPath(sourceFilePath); |
| 120131 | if (sourceFile.isDeclarationFile && !copyDeclarationFileDiagnostics) |
| 120132 | return; |
no test coverage detected
searching dependent graphs…