Skip to content

Commit c973b9b

Browse files
committed
Merge branch 'master' into fix-35584
2 parents de23735 + 38da7c6 commit c973b9b

File tree

1,144 files changed

+103822
-8302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,144 files changed

+103822
-8302
lines changed

.github/issue_template.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

package-lock.json

Lines changed: 133 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"@types/source-map-support": "latest",
5454
"@types/through2": "latest",
5555
"@types/xml2js": "^0.4.0",
56-
"@typescript-eslint/eslint-plugin": "4.5.0",
57-
"@typescript-eslint/experimental-utils": "4.5.0",
58-
"@typescript-eslint/parser": "4.5.0",
56+
"@typescript-eslint/eslint-plugin": "^4.19.0",
57+
"@typescript-eslint/experimental-utils": "^4.19.0",
58+
"@typescript-eslint/parser": "^4.19.0",
5959
"async": "latest",
6060
"azure-devops-node-api": "^10.1.0",
6161
"browser-resolve": "^1.11.2",
@@ -94,7 +94,7 @@
9494
"remove-internal": "^2.9.2",
9595
"source-map-support": "latest",
9696
"through2": "latest",
97-
"typescript": "^4.0.0-dev.20200624",
97+
"typescript": "^4.2.3",
9898
"vinyl": "latest",
9999
"vinyl-sourcemaps-apply": "latest",
100100
"xml2js": "^0.4.19"
@@ -129,6 +129,5 @@
129129
},
130130
"volta": {
131131
"node": "14.15.5"
132-
},
133-
"dependencies": {}
132+
}
134133
}

src/compiler/builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ namespace ts {
169169
/**
170170
* Create the state so that we can iterate on changedFiles/affected files
171171
*/
172-
function createBuilderProgramState(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderProgramState>): BuilderProgramState {
173-
const state = BuilderState.create(newProgram, getCanonicalFileName, oldState) as BuilderProgramState;
172+
function createBuilderProgramState(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState: Readonly<ReusableBuilderProgramState> | undefined, disableUseFileVersionAsSignature: boolean | undefined): BuilderProgramState {
173+
const state = BuilderState.create(newProgram, getCanonicalFileName, oldState, disableUseFileVersionAsSignature) as BuilderProgramState;
174174
state.program = newProgram;
175175
const compilerOptions = newProgram.getCompilerOptions();
176176
state.compilerOptions = compilerOptions;
@@ -947,7 +947,7 @@ namespace ts {
947947
* Computing hash to for signature verification
948948
*/
949949
const computeHash = maybeBind(host, host.createHash);
950-
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState);
950+
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState, host.disableUseFileVersionAsSignature);
951951
let backupState: BuilderProgramState | undefined;
952952
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state, getCanonicalFileName);
953953

src/compiler/builderPublic.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ namespace ts {
1515
* this callback if present would be used to write files
1616
*/
1717
writeFile?: WriteFileCallback;
18+
/**
19+
* disable using source file version as signature for testing
20+
*/
21+
/*@internal*/
22+
disableUseFileVersionAsSignature?: boolean;
1823
}
1924

2025
/**

src/compiler/builderState.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ namespace ts {
4545
* Otherwise undefined
4646
*/
4747
readonly exportedModulesMap: ESMap<Path, BuilderState.ReferencedSet> | undefined;
48+
49+
/**
50+
* true if file version is used as signature
51+
* This helps in delaying the calculation of the d.ts hash as version for the file till reasonable time
52+
*/
53+
useFileVersionAsSignature: boolean;
4854
/**
4955
* Map of files that have already called update signature.
5056
* That means hence forth these files are assumed to have
@@ -202,7 +208,7 @@ namespace ts {
202208
/**
203209
* Creates the state of file references and signature for the new program from oldState if it is safe
204210
*/
205-
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>): BuilderState {
211+
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<ReusableBuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
206212
const fileInfos = new Map<Path, FileInfo>();
207213
const referencedMap = newProgram.getCompilerOptions().module !== ModuleKind.None ? new Map<Path, ReferencedSet>() : undefined;
208214
const exportedModulesMap = referencedMap ? new Map<Path, ReferencedSet>() : undefined;
@@ -236,7 +242,8 @@ namespace ts {
236242
fileInfos,
237243
referencedMap,
238244
exportedModulesMap,
239-
hasCalledUpdateShapeSignature
245+
hasCalledUpdateShapeSignature,
246+
useFileVersionAsSignature: !disableUseFileVersionAsSignature && !useOldState
240247
};
241248
}
242249

@@ -258,6 +265,7 @@ namespace ts {
258265
referencedMap: state.referencedMap && new Map(state.referencedMap),
259266
exportedModulesMap: state.exportedModulesMap && new Map(state.exportedModulesMap),
260267
hasCalledUpdateShapeSignature: new Set(state.hasCalledUpdateShapeSignature),
268+
useFileVersionAsSignature: state.useFileVersionAsSignature,
261269
};
262270
}
263271

@@ -316,16 +324,8 @@ namespace ts {
316324
if (!info) return Debug.fail();
317325

318326
const prevSignature = info.signature;
319-
let latestSignature: string;
320-
if (sourceFile.isDeclarationFile) {
321-
latestSignature = sourceFile.version;
322-
if (exportedModulesMapCache && latestSignature !== prevSignature) {
323-
// All the references in this file are exported
324-
const references = state.referencedMap ? state.referencedMap.get(sourceFile.resolvedPath) : undefined;
325-
exportedModulesMapCache.set(sourceFile.resolvedPath, references || false);
326-
}
327-
}
328-
else {
327+
let latestSignature: string | undefined;
328+
if (!sourceFile.isDeclarationFile && !state.useFileVersionAsSignature) {
329329
const emitOutput = getFileEmitOutput(
330330
programOfThisState,
331331
sourceFile,
@@ -334,25 +334,26 @@ namespace ts {
334334
/*customTransformers*/ undefined,
335335
/*forceDtsEmit*/ true
336336
);
337-
const firstDts = emitOutput.outputFiles &&
338-
programOfThisState.getCompilerOptions().declarationMap ?
339-
emitOutput.outputFiles.length > 1 ? emitOutput.outputFiles[1] : undefined :
340-
emitOutput.outputFiles.length > 0 ? emitOutput.outputFiles[0] : undefined;
337+
const firstDts = firstOrUndefined(emitOutput.outputFiles);
341338
if (firstDts) {
342339
Debug.assert(fileExtensionIs(firstDts.name, Extension.Dts), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
343340
latestSignature = (computeHash || generateDjb2Hash)(firstDts.text);
344341
if (exportedModulesMapCache && latestSignature !== prevSignature) {
345342
updateExportedModules(sourceFile, emitOutput.exportedModulesFromDeclarationEmit, exportedModulesMapCache);
346343
}
347344
}
348-
else {
349-
latestSignature = prevSignature!; // TODO: GH#18217
345+
}
346+
// Default is to use file version as signature
347+
if (latestSignature === undefined) {
348+
latestSignature = sourceFile.version;
349+
if (exportedModulesMapCache && latestSignature !== prevSignature) {
350+
// All the references in this file are exported
351+
const references = state.referencedMap ? state.referencedMap.get(sourceFile.resolvedPath) : undefined;
352+
exportedModulesMapCache.set(sourceFile.resolvedPath, references || false);
350353
}
351-
352354
}
353355
cacheToUpdateSignature.set(sourceFile.resolvedPath, latestSignature);
354-
355-
return !prevSignature || latestSignature !== prevSignature;
356+
return latestSignature !== prevSignature;
356357
}
357358

358359
/**
@@ -479,7 +480,7 @@ namespace ts {
479480
*/
480481
function isFileAffectingGlobalScope(sourceFile: SourceFile) {
481482
return containsGlobalScopeAugmentation(sourceFile) ||
482-
!isExternalModule(sourceFile) && !containsOnlyAmbientModules(sourceFile);
483+
!isExternalOrCommonJsModule(sourceFile) && !containsOnlyAmbientModules(sourceFile);
483484
}
484485

485486
/**

0 commit comments

Comments
 (0)