Skip to content

Commit b71c45a

Browse files
committed
Removing some unnecessary methods from host and function parameters
1 parent 2475bf2 commit b71c45a

File tree

8 files changed

+74
-124
lines changed

8 files changed

+74
-124
lines changed

src/compiler/builder.ts

Lines changed: 47 additions & 72 deletions
Large diffs are not rendered by default.

src/compiler/builderPublic.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ namespace ts {
22
export type AffectedFileResult<T> = { result: T; affected: SourceFile | Program; } | undefined;
33

44
export interface BuilderProgramHost {
5-
/**
6-
* return true if file names are treated with case sensitivity
7-
*/
8-
useCaseSensitiveFileNames(): boolean;
95
/**
106
* If provided this would be used this hash instead of actual file shape text for detecting changes
117
*/
@@ -25,13 +21,11 @@ namespace ts {
2521
*/
2622
/*@internal*/
2723
storeFilesChangingSignatureDuringEmit?: boolean;
28-
/**
29-
* Gets the current time
30-
*/
31-
/*@internal*/
32-
now?(): Date;
3324
}
3425

26+
/*@internal*/
27+
export type HostForComputeHash = Pick<BuilderProgramHost, "createHash">;
28+
3529
/**
3630
* Builder to manage the program state changes
3731
*/

src/compiler/builderState.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ namespace ts {
148148
return false;
149149
}
150150

151-
/**
152-
* Compute the hash to store the shape of the file
153-
*/
154-
export type ComputeHash = ((data: string) => string) | undefined;
155-
156151
function getReferencedFilesFromImportedModuleSymbol(symbol: Symbol): Path[] {
157152
return mapDefined(symbol.declarations, declaration => getSourceFileOfNode(declaration)?.resolvedPath);
158153
}
@@ -262,11 +257,12 @@ namespace ts {
262257
/**
263258
* Creates the state of file references and signature for the new program from oldState if it is safe
264259
*/
265-
export function create(newProgram: Program, getCanonicalFileName: GetCanonicalFileName, oldState?: Readonly<BuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
260+
export function create(newProgram: Program, oldState?: Readonly<BuilderState>, disableUseFileVersionAsSignature?: boolean): BuilderState {
266261
const fileInfos = new Map<Path, FileInfo>();
267262
const referencedMap = newProgram.getCompilerOptions().module !== ModuleKind.None ? createManyToManyPathMap() : undefined;
268263
const exportedModulesMap = referencedMap ? createManyToManyPathMap() : undefined;
269264
const useOldState = canReuseOldState(referencedMap, oldState);
265+
const getCanonicalFileName = createGetCanonicalFileName(newProgram.useCaseSensitiveFileNames());
270266

271267
// Ensure source files have parent pointers set
272268
newProgram.getTypeChecker();
@@ -326,16 +322,14 @@ namespace ts {
326322
programOfThisState: Program,
327323
path: Path,
328324
cancellationToken: CancellationToken | undefined,
329-
computeHash: ComputeHash,
330-
getCanonicalFileName: GetCanonicalFileName,
325+
host: HostForComputeHash,
331326
): readonly SourceFile[] {
332327
const result = getFilesAffectedByWithOldState(
333328
state,
334329
programOfThisState,
335330
path,
336331
cancellationToken,
337-
computeHash,
338-
getCanonicalFileName,
332+
host,
339333
);
340334
state.oldSignatures?.clear();
341335
state.oldExportedModulesMap?.clear();
@@ -347,19 +341,18 @@ namespace ts {
347341
programOfThisState: Program,
348342
path: Path,
349343
cancellationToken: CancellationToken | undefined,
350-
computeHash: ComputeHash,
351-
getCanonicalFileName: GetCanonicalFileName,
344+
host: HostForComputeHash,
352345
): readonly SourceFile[] {
353346
const sourceFile = programOfThisState.getSourceFileByPath(path);
354347
if (!sourceFile) {
355348
return emptyArray;
356349
}
357350

358-
if (!updateShapeSignature(state, programOfThisState, sourceFile, cancellationToken, computeHash, getCanonicalFileName)) {
351+
if (!updateShapeSignature(state, programOfThisState, sourceFile, cancellationToken, host)) {
359352
return [sourceFile];
360353
}
361354

362-
return (state.referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit)(state, programOfThisState, sourceFile, cancellationToken, computeHash, getCanonicalFileName);
355+
return (state.referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit)(state, programOfThisState, sourceFile, cancellationToken, host);
363356
}
364357

365358
export function updateSignatureOfFile(state: BuilderState, signature: string | undefined, path: Path) {
@@ -375,8 +368,7 @@ namespace ts {
375368
programOfThisState: Program,
376369
sourceFile: SourceFile,
377370
cancellationToken: CancellationToken | undefined,
378-
computeHash: ComputeHash,
379-
getCanonicalFileName: GetCanonicalFileName,
371+
host: HostForComputeHash,
380372
useFileVersionAsSignature = state.useFileVersionAsSignature
381373
) {
382374
// If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
@@ -393,8 +385,8 @@ namespace ts {
393385
latestSignature = computeSignatureWithDiagnostics(
394386
sourceFile,
395387
text,
396-
computeHash,
397-
getCanonicalFileName,
388+
host,
389+
createGetCanonicalFileName(programOfThisState.useCaseSensitiveFileNames()),
398390
data,
399391
);
400392
if (latestSignature !== prevSignature) {
@@ -590,8 +582,7 @@ namespace ts {
590582
programOfThisState: Program,
591583
sourceFileWithUpdatedShape: SourceFile,
592584
cancellationToken: CancellationToken | undefined,
593-
computeHash: ComputeHash,
594-
getCanonicalFileName: GetCanonicalFileName,
585+
host: HostForComputeHash,
595586
) {
596587
if (isFileAffectingGlobalScope(sourceFileWithUpdatedShape)) {
597588
return getAllFilesExcludingDefaultLibraryFile(state, programOfThisState, sourceFileWithUpdatedShape);
@@ -615,7 +606,7 @@ namespace ts {
615606
if (!seenFileNamesMap.has(currentPath)) {
616607
const currentSourceFile = programOfThisState.getSourceFileByPath(currentPath)!;
617608
seenFileNamesMap.set(currentPath, currentSourceFile);
618-
if (currentSourceFile && updateShapeSignature(state, programOfThisState, currentSourceFile, cancellationToken, computeHash, getCanonicalFileName)) {
609+
if (currentSourceFile && updateShapeSignature(state, programOfThisState, currentSourceFile, cancellationToken, host)) {
619610
queue.push(...getReferencedByPaths(state, currentSourceFile.resolvedPath));
620611
}
621612
}

src/compiler/emitter.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ namespace ts {
554554
if (sourceMapFilePath) {
555555
const sourceMap = sourceMapGenerator.toString();
556556
writeFile(host, emitterDiagnostics, sourceMapFilePath, sourceMap, /*writeByteOrderMark*/ false, sourceFiles);
557-
if (printer.bundleFileInfo) printer.bundleFileInfo.mapHash = computeSignature(sourceMap, maybeBind(host, host.createHash));
557+
if (printer.bundleFileInfo) printer.bundleFileInfo.mapHash = computeSignature(sourceMap, host);
558558
}
559559
}
560560
else {
@@ -566,7 +566,7 @@ namespace ts {
566566
writeFile(host, emitterDiagnostics, jsFilePath, text, !!compilerOptions.emitBOM, sourceFiles, { sourceMapUrlPos, diagnostics: transform.diagnostics });
567567
// We store the hash of the text written in the buildinfo to ensure that text of the referenced d.ts file is same as whats in the buildinfo
568568
// This is needed because incremental can be toggled between two runs and we might use stale file text to do text manipulation in prepend mode
569-
if (printer.bundleFileInfo) printer.bundleFileInfo.hash = computeSignature(text, maybeBind(host, host.createHash));
569+
if (printer.bundleFileInfo) printer.bundleFileInfo.hash = computeSignature(text, host);
570570

571571
// Reset state
572572
writer.clear();
@@ -749,7 +749,6 @@ namespace ts {
749749
getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined,
750750
customTransformers?: CustomTransformers
751751
): EmitUsingBuildInfoResult {
752-
const createHash = maybeBind(host, host.createHash);
753752
const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false);
754753
let buildInfo: BuildInfo;
755754
if (host.getBuildInfo) {
@@ -768,20 +767,20 @@ namespace ts {
768767
const jsFileText = host.readFile(Debug.checkDefined(jsFilePath));
769768
if (!jsFileText) return jsFilePath!;
770769
// If the jsFileText is not same has what it was created with, tsbuildinfo is stale so dont use it
771-
if (computeSignature(jsFileText, createHash) !== buildInfo.bundle.js.hash) return jsFilePath!;
770+
if (computeSignature(jsFileText, host) !== buildInfo.bundle.js.hash) return jsFilePath!;
772771
const sourceMapText = sourceMapFilePath && host.readFile(sourceMapFilePath);
773772
// error if no source map or for now if inline sourcemap
774773
if ((sourceMapFilePath && !sourceMapText) || config.options.inlineSourceMap) return sourceMapFilePath || "inline sourcemap decoding";
775-
if (sourceMapFilePath && computeSignature(sourceMapText!, createHash) !== buildInfo.bundle.js.mapHash) return sourceMapFilePath;
774+
if (sourceMapFilePath && computeSignature(sourceMapText!, host) !== buildInfo.bundle.js.mapHash) return sourceMapFilePath;
776775

777776
// read declaration text
778777
const declarationText = declarationFilePath && host.readFile(declarationFilePath);
779778
if (declarationFilePath && !declarationText) return declarationFilePath;
780-
if (declarationFilePath && computeSignature(declarationText!, createHash) !== buildInfo.bundle.dts!.hash) return declarationFilePath;
779+
if (declarationFilePath && computeSignature(declarationText!, host) !== buildInfo.bundle.dts!.hash) return declarationFilePath;
781780
const declarationMapText = declarationMapPath && host.readFile(declarationMapPath);
782781
// error if no source map or for now if inline sourcemap
783782
if ((declarationMapPath && !declarationMapText) || config.options.inlineSourceMap) return declarationMapPath || "inline sourcemap decoding";
784-
if (declarationMapPath && computeSignature(declarationMapText!, createHash) !== buildInfo.bundle.dts!.mapHash) return declarationMapPath;
783+
if (declarationMapPath && computeSignature(declarationMapText!, host) !== buildInfo.bundle.dts!.mapHash) return declarationMapPath;
785784

786785
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath!, host.getCurrentDirectory()));
787786
const ownPrependInput = createInputFiles(
@@ -830,7 +829,7 @@ namespace ts {
830829
newBuildInfo.program = buildInfo.program;
831830
if (newBuildInfo.program && changedDtsText !== undefined && config.options.composite) {
832831
// Update the output signature
833-
(newBuildInfo.program as ProgramBundleEmitBuildInfo).outSignature = computeSignature(changedDtsText, createHash, changedDtsData);
832+
(newBuildInfo.program as ProgramBundleEmitBuildInfo).outSignature = computeSignature(changedDtsText, host, changedDtsData);
834833
}
835834
// Update sourceFileInfo
836835
const { js, dts, sourceFiles } = buildInfo.bundle!;
@@ -862,7 +861,7 @@ namespace ts {
862861
getSourceFileFromReference: returnUndefined,
863862
redirectTargetsMap: createMultiMap(),
864863
getFileIncludeReasons: notImplemented,
865-
createHash,
864+
createHash: maybeBind(host, host.createHash),
866865
};
867866
emitFiles(
868867
notImplementedResolver,

src/server/project.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,14 @@ namespace ts.server {
703703
return [];
704704
}
705705
updateProjectIfDirty(this);
706-
this.builderState = BuilderState.create(this.program!, this.projectService.toCanonicalFileName, this.builderState, /*disableUseFileVersionAsSignature*/ true);
706+
this.builderState = BuilderState.create(this.program!, this.builderState, /*disableUseFileVersionAsSignature*/ true);
707707
return mapDefined(
708708
BuilderState.getFilesAffectedBy(
709709
this.builderState,
710710
this.program!,
711711
scriptInfo.path,
712712
this.cancellationToken,
713-
maybeBind(this.projectService.host, this.projectService.host.createHash),
714-
this.getCanonicalFileName,
713+
this.projectService.host,
715714
),
716715
sourceFile => this.shouldEmitFile(this.projectService.getScriptInfoForPath(sourceFile.path)) ? sourceFile.fileName : undefined
717716
);

src/testRunner/unittests/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace ts {
7272
});
7373

7474
function makeAssertChanges(getProgram: () => Program): (fileNames: readonly string[]) => void {
75-
const host: BuilderProgramHost = { useCaseSensitiveFileNames: returnTrue };
75+
const host: BuilderProgramHost = {};
7676
let builderProgram: EmitAndSemanticDiagnosticsBuilderProgram | undefined;
7777
return fileNames => {
7878
const program = getProgram();
@@ -86,7 +86,7 @@ namespace ts {
8686
}
8787

8888
function makeAssertChangesWithCancellationToken(getProgram: () => Program): (fileNames: readonly string[], cancelAfterEmitLength?: number) => void {
89-
const host: BuilderProgramHost = { useCaseSensitiveFileNames: returnTrue };
89+
const host: BuilderProgramHost = {};
9090
let builderProgram: EmitAndSemanticDiagnosticsBuilderProgram | undefined;
9191
let cancel = false;
9292
const cancellationToken: CancellationToken = {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5237,10 +5237,6 @@ declare namespace ts {
52375237
affected: SourceFile | Program;
52385238
} | undefined;
52395239
interface BuilderProgramHost {
5240-
/**
5241-
* return true if file names are treated with case sensitivity
5242-
*/
5243-
useCaseSensitiveFileNames(): boolean;
52445240
/**
52455241
* If provided this would be used this hash instead of actual file shape text for detecting changes
52465242
*/

tests/baselines/reference/api/typescript.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5237,10 +5237,6 @@ declare namespace ts {
52375237
affected: SourceFile | Program;
52385238
} | undefined;
52395239
interface BuilderProgramHost {
5240-
/**
5241-
* return true if file names are treated with case sensitivity
5242-
*/
5243-
useCaseSensitiveFileNames(): boolean;
52445240
/**
52455241
* If provided this would be used this hash instead of actual file shape text for detecting changes
52465242
*/

0 commit comments

Comments
 (0)