Skip to content

Commit 52eaa7b

Browse files
iisaduansheetalkamatandrewbranch
authored
Enable --isolatedDeclarations on TS codebase (microsoft#59635)
Co-authored-by: Sheetal Nandi <[email protected]> Co-authored-by: Andrew Branch <[email protected]>
1 parent 89e004f commit 52eaa7b

File tree

136 files changed

+1924
-1591
lines changed

Some content is hidden

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

136 files changed

+1924
-1591
lines changed

eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export default tseslint.config(
118118
"@typescript-eslint/ban-ts-comment": "off",
119119
"@typescript-eslint/class-literal-property-style": "off",
120120
"@typescript-eslint/consistent-indexed-object-style": "off",
121+
"@typescript-eslint/consistent-generic-constructors": "off",
121122
"@typescript-eslint/no-duplicate-enum-values": "off",
122123
"@typescript-eslint/no-empty-function": "off",
123124
"@typescript-eslint/no-namespace": "off",

scripts/processDiagnosticMessages.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function buildInfoFileOutput(messageTable, inputFilePathRel) {
9292
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };",
9393
"}",
9494
"",
95+
"/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion*/", // type assertions are needed for isolatedDeclarations
9596
"/** @internal */",
9697
"export const Diagnostics = {",
9798
];
@@ -101,7 +102,7 @@ function buildInfoFileOutput(messageTable, inputFilePathRel) {
101102
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${!reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : ""}, /*elidedInCompatabilityPyramid*/ ${elidedInCompatabilityPyramid}` : "";
102103
const argReportsDeprecated = reportsDeprecated ? `${!argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : ""}, /*reportsDeprecated*/ ${reportsDeprecated}` : "";
103104

104-
result.push(` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),`);
105+
result.push(` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}) as DiagnosticMessage,`);
105106
});
106107

107108
result.push("};");

src/compiler/binder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ export function createFlowNode(flags: FlowFlags, node: unknown, antecedent: Flow
509509
const binder = /* @__PURE__ */ createBinder();
510510

511511
/** @internal */
512-
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
512+
export function bindSourceFile(file: SourceFile, options: CompilerOptions): void {
513513
performance.mark("beforeBind");
514514
binder(file, options);
515515
performance.mark("afterBind");

src/compiler/builder.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
BuilderProgramHost,
99
BuilderState,
1010
BuildInfo,
11+
BuildInfoFileVersionMap,
1112
CancellationToken,
1213
CommandLineOption,
1314
compareStringsCaseSensitive,
@@ -277,7 +278,7 @@ function toBuilderProgramStateWithDefinedProgram(state: ReusableBuilderProgramSt
277278
*
278279
* @internal
279280
*/
280-
export function getBuilderFileEmit(options: CompilerOptions) {
281+
export function getBuilderFileEmit(options: CompilerOptions): BuilderFileEmit {
281282
let result = BuilderFileEmit.Js;
282283
if (options.sourceMap) result = result | BuilderFileEmit.JsMap;
283284
if (options.inlineSourceMap) result = result | BuilderFileEmit.JsInlineMap;
@@ -733,7 +734,7 @@ export function getPendingEmitKindWithSeen(
733734
seenOldOptionsOrEmitKind: CompilerOptions | BuilderFileEmit | undefined,
734735
emitOnlyDtsFiles: boolean | undefined,
735736
isForDtsErrors: boolean,
736-
) {
737+
): BuilderFileEmit {
737738
let pendingKind = getPendingEmitKind(optionsOrEmitKind, seenOldOptionsOrEmitKind);
738739
if (emitOnlyDtsFiles) pendingKind = pendingKind & BuilderFileEmit.AllDts;
739740
if (isForDtsErrors) pendingKind = pendingKind & BuilderFileEmit.DtsErrors;
@@ -1623,7 +1624,7 @@ export function computeSignatureWithDiagnostics(
16231624
text: string,
16241625
host: HostForComputeHash,
16251626
data: WriteFileCallbackData | undefined,
1626-
) {
1627+
): string {
16271628
text = getTextHandlingSourceMapForSignature(text, data);
16281629
let sourceFileDirectory: string | undefined;
16291630
if (data?.diagnostics?.length) {
@@ -2395,7 +2396,7 @@ export function getBuildInfoFileVersionMap(
23952396
program: IncrementalBuildInfo,
23962397
buildInfoPath: string,
23972398
host: Pick<ReadBuildProgramHost, "useCaseSensitiveFileNames" | "getCurrentDirectory">,
2398-
) {
2399+
): BuildInfoFileVersionMap {
23992400
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
24002401
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
24012402
const fileInfos = new Map<Path, string>();
@@ -2440,7 +2441,7 @@ export function getNonIncrementalBuildInfoRoots(
24402441
buildInfo: BuildInfo,
24412442
buildInfoPath: string,
24422443
host: Pick<ReadBuildProgramHost, "useCaseSensitiveFileNames" | "getCurrentDirectory">,
2443-
) {
2444+
): Path[] | undefined {
24442445
if (!isNonIncrementalBuildInfo(buildInfo)) return undefined;
24452446
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
24462447
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());

src/compiler/builderState.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ export namespace BuilderState {
292292
/**
293293
* Returns true if oldState is reusable, that is the emitKind = module/non module has not changed
294294
*/
295-
export function canReuseOldState(newReferencedMap: ReadonlyManyToManyPathMap | undefined, oldState: BuilderState | undefined) {
295+
export function canReuseOldState(newReferencedMap: ReadonlyManyToManyPathMap | undefined, oldState: BuilderState | undefined): boolean | undefined {
296296
return oldState && !oldState.referencedMap === !newReferencedMap;
297297
}
298298

299-
export function createReferencedMap(options: CompilerOptions) {
299+
export function createReferencedMap(options: CompilerOptions): ManyToManyPathMap | undefined {
300300
return options.module !== ModuleKind.None && !options.outFile ?
301301
createManyToManyPathMap() :
302302
undefined;
@@ -346,7 +346,7 @@ export namespace BuilderState {
346346
/**
347347
* Releases needed properties
348348
*/
349-
export function releaseCache(state: BuilderState) {
349+
export function releaseCache(state: BuilderState): void {
350350
state.allFilesExcludingDefaultLibraryFile = undefined;
351351
state.allFileNames = undefined;
352352
}
@@ -391,7 +391,7 @@ export namespace BuilderState {
391391
return (state.referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit)(state, programOfThisState, sourceFile, cancellationToken, host);
392392
}
393393

394-
export function updateSignatureOfFile(state: BuilderState, signature: string | undefined, path: Path) {
394+
export function updateSignatureOfFile(state: BuilderState, signature: string | undefined, path: Path): void {
395395
state.fileInfos.get(path)!.signature = signature;
396396
(state.hasCalledUpdateShapeSignature ||= new Set()).add(path);
397397
}
@@ -402,7 +402,7 @@ export namespace BuilderState {
402402
cancellationToken: CancellationToken | undefined,
403403
host: HostForComputeHash,
404404
onNewSignature: (signature: string, sourceFiles: readonly SourceFile[]) => void,
405-
) {
405+
): void {
406406
programOfThisState.emit(
407407
sourceFile,
408408
(fileName, text, _writeByteOrderMark, _onError, sourceFiles, data) => {
@@ -434,8 +434,8 @@ export namespace BuilderState {
434434
sourceFile: SourceFile,
435435
cancellationToken: CancellationToken | undefined,
436436
host: HostForComputeHash,
437-
useFileVersionAsSignature = state.useFileVersionAsSignature,
438-
) {
437+
useFileVersionAsSignature: boolean | undefined = state.useFileVersionAsSignature,
438+
): boolean {
439439
// If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
440440
if (state.hasCalledUpdateShapeSignature?.has(sourceFile.resolvedPath)) return false;
441441

@@ -507,7 +507,7 @@ export namespace BuilderState {
507507
/**
508508
* Gets the files referenced by the the file path
509509
*/
510-
export function getReferencedByPaths(state: Readonly<BuilderState>, referencedFilePath: Path) {
510+
export function getReferencedByPaths(state: Readonly<BuilderState>, referencedFilePath: Path): Path[] {
511511
const keys = state.referencedMap!.getKeys(referencedFilePath);
512512
return keys ? arrayFrom(keys.keys()) : [];
513513
}

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ export function getSymbolId(symbol: Symbol): SymbolId {
14501450
}
14511451

14521452
/** @internal */
1453-
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
1453+
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean {
14541454
const moduleState = getModuleInstanceState(node);
14551455
return moduleState === ModuleInstanceState.Instantiated ||
14561456
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
@@ -52709,7 +52709,7 @@ function getIterationTypesKeyFromIterationTypeKind(typeKind: IterationTypeKind)
5270952709
}
5271052710

5271152711
/** @internal */
52712-
export function signatureHasRestParameter(s: Signature) {
52712+
export function signatureHasRestParameter(s: Signature): boolean {
5271352713
return !!(s.flags & SignatureFlags.HasRestParameter);
5271452714
}
5271552715

src/compiler/commandLineParser.ts

+22-14
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const jsxOptionMap = new Map(Object.entries({
138138
}));
139139

140140
/** @internal */
141-
export const inverseJsxOptionMap = new Map(mapIterator(jsxOptionMap.entries(), ([key, value]: [string, JsxEmit]) => ["" + value, key] as const));
141+
export const inverseJsxOptionMap: Map<string, string> = new Map(mapIterator(jsxOptionMap.entries(), ([key, value]: [string, JsxEmit]) => ["" + value, key] as const));
142142

143143
// NOTE: The order here is important to default lib ordering as entries will have the same
144144
// order in the generated program (see `getDefaultLibPriority` in program.ts). This
@@ -248,15 +248,15 @@ const libEntries: [string, string][] = [
248248
*
249249
* @internal
250250
*/
251-
export const libs = libEntries.map(entry => entry[0]);
251+
export const libs: string[] = libEntries.map(entry => entry[0]);
252252

253253
/**
254254
* A map of lib names to lib files. This map is used both for parsing the "lib" command line
255255
* option as well as for resolving lib reference directives.
256256
*
257257
* @internal
258258
*/
259-
export const libMap = new Map(libEntries);
259+
export const libMap: Map<string, string> = new Map(libEntries);
260260

261261
// Watch related options
262262

@@ -1800,7 +1800,7 @@ function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType
18001800
}
18011801

18021802
/** @internal */
1803-
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string | undefined, errors: Diagnostic[]) {
1803+
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string | undefined, errors: Diagnostic[]): string | number | undefined {
18041804
return convertJsonOptionOfCustomType(opt, (value ?? "").trim(), errors);
18051805
}
18061806

@@ -1835,6 +1835,14 @@ export interface OptionsBase {
18351835
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
18361836
}
18371837

1838+
/** @internal */
1839+
export interface BaseParsedCommandLine {
1840+
options: OptionsBase;
1841+
watchOptions: WatchOptions | undefined;
1842+
fileNames: string[];
1843+
errors: Diagnostic[];
1844+
}
1845+
18381846
/** @internal */
18391847
export interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
18401848
getOptionsNameMap: () => OptionsNameMap;
@@ -1875,7 +1883,7 @@ export function parseCommandLineWorker(
18751883
diagnostics: ParseCommandLineWorkerDiagnostics,
18761884
commandLine: readonly string[],
18771885
readFile?: (path: string) => string | undefined,
1878-
) {
1886+
): BaseParsedCommandLine {
18791887
const options = {} as OptionsBase;
18801888
let watchOptions: WatchOptions | undefined;
18811889
const fileNames: string[] = [];
@@ -2602,11 +2610,11 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
26022610
const providedKeys = new Set(optionMap.keys());
26032611
const impliedCompilerOptions: Record<string, CompilerOptionsValue> = {};
26042612
for (const option in computedOptions) {
2605-
if (!providedKeys.has(option) && some(computedOptions[option as keyof typeof computedOptions].dependencies, dep => providedKeys.has(dep))) {
2606-
const implied = computedOptions[option as keyof typeof computedOptions].computeValue(configParseResult.options);
2607-
const defaultValue = computedOptions[option as keyof typeof computedOptions].computeValue({});
2613+
if (!providedKeys.has(option) && some(computedOptions[option].dependencies, dep => providedKeys.has(dep))) {
2614+
const implied = computedOptions[option].computeValue(configParseResult.options);
2615+
const defaultValue = computedOptions[option].computeValue({});
26082616
if (implied !== defaultValue) {
2609-
impliedCompilerOptions[option] = computedOptions[option as keyof typeof computedOptions].computeValue(configParseResult.options);
2617+
impliedCompilerOptions[option] = computedOptions[option].computeValue(configParseResult.options);
26102618
}
26112619
}
26122620
}
@@ -2866,7 +2874,7 @@ export function generateTSConfig(options: CompilerOptions, fileNames: readonly s
28662874
}
28672875

28682876
/** @internal */
2869-
export function convertToOptionsWithAbsolutePaths(options: CompilerOptions, toAbsolutePath: (path: string) => string) {
2877+
export function convertToOptionsWithAbsolutePaths(options: CompilerOptions, toAbsolutePath: (path: string) => string): CompilerOptions {
28702878
const result: CompilerOptions = {};
28712879
const optionsNameMap = getOptionsNameMap().optionsNameMap;
28722880

@@ -2927,7 +2935,7 @@ export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceF
29272935
}
29282936

29292937
/** @internal */
2930-
export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile | undefined) {
2938+
export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile | undefined): void {
29312939
if (configFile) {
29322940
Object.defineProperty(options, "configFile", { enumerable: false, writable: false, value: configFile });
29332941
}
@@ -3243,12 +3251,12 @@ function shouldReportNoInputFiles(fileNames: string[], canJsonReportNoInutFiles:
32433251
}
32443252

32453253
/** @internal */
3246-
export function canJsonReportNoInputFiles(raw: any) {
3254+
export function canJsonReportNoInputFiles(raw: any): boolean {
32473255
return !hasProperty(raw, "files") && !hasProperty(raw, "references");
32483256
}
32493257

32503258
/** @internal */
3251-
export function updateErrorForNoInputFiles(fileNames: string[], configFileName: string, configFileSpecs: ConfigFileSpecs, configParseDiagnostics: Diagnostic[], canJsonReportNoInutFiles: boolean) {
3259+
export function updateErrorForNoInputFiles(fileNames: string[], configFileName: string, configFileSpecs: ConfigFileSpecs, configParseDiagnostics: Diagnostic[], canJsonReportNoInutFiles: boolean): boolean {
32523260
const existingErrors = configParseDiagnostics.length;
32533261
if (shouldReportNoInputFiles(fileNames, canJsonReportNoInutFiles)) {
32543262
configParseDiagnostics.push(getErrorForNoInputFiles(configFileSpecs, configFileName));
@@ -3943,7 +3951,7 @@ export function matchesExclude(
39433951
excludeSpecs: readonly string[] | undefined,
39443952
useCaseSensitiveFileNames: boolean,
39453953
currentDirectory: string,
3946-
) {
3954+
): boolean {
39473955
return matchesExcludeWorker(
39483956
pathToCheck,
39493957
filter(excludeSpecs, spec => !invalidDotDotAfterRecursiveWildcard(spec)),

0 commit comments

Comments
 (0)