Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable --isolatedDeclarations on TS codebase #59635

Merged
merged 28 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3ddb26a
turn on compiler flag
iisaduan Aug 5, 2024
49676b5
mostly generated by quickfixes (some formatting)
iisaduan Aug 13, 2024
6e50be8
update generate diagnostic messages script to provide type for Diagno…
iisaduan Aug 13, 2024
6a6c1f9
update ScriptTarget and LanguageFeatureMinimumTarget enums
iisaduan Aug 13, 2024
6c6c89a
generated codefixes on services
iisaduan Aug 13, 2024
7567038
generated codefixes on server
iisaduan Aug 13, 2024
4c1bc99
generated codefixes harness
iisaduan Aug 13, 2024
5c13c8d
lint
iisaduan Aug 13, 2024
4e5524b
update generateDiagnosticMessages script for eslint
iisaduan Aug 13, 2024
0bd2108
generated codefixes harness 2
iisaduan Aug 13, 2024
eeb6165
generated codefixes testrunner
iisaduan Aug 13, 2024
58a7fcf
update baselines
iisaduan Aug 13, 2024
326123f
remove extra generated ts.
iisaduan Aug 13, 2024
303d726
make commentpragma type
iisaduan Aug 13, 2024
7d3ccb3
update baselines
iisaduan Aug 14, 2024
b89abd1
add as const and reduce duplications
iisaduan Aug 14, 2024
c6220d4
Merge branch 'main' of https://github.com/microsoft/TypeScript into a…
iisaduan Sep 12, 2024
ad0fb2a
add missing type annotations from merge
iisaduan Sep 12, 2024
f595704
fix tests
iisaduan Sep 12, 2024
fc90f11
update iterators for 5.6
iisaduan Sep 12, 2024
14860a3
refactor types
iisaduan Sep 13, 2024
2bc5c90
fix function
iisaduan Sep 13, 2024
de60e62
address comments, remove extra lines
iisaduan Sep 13, 2024
27bede6
use languageFeatures index
iisaduan Sep 13, 2024
f498dcb
Update src/testRunner/unittests/helpers/contents.ts with options object
iisaduan Sep 13, 2024
1c559c4
Simplify computed options
andrewbranch Sep 13, 2024
6296b14
remove eslint rule
iisaduan Sep 13, 2024
bea7205
comments
iisaduan Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default tseslint.config(
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/class-literal-property-style": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-generic-constructors": "off",
"@typescript-eslint/no-duplicate-enum-values": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-namespace": "off",
Expand Down
3 changes: 2 additions & 1 deletion scripts/processDiagnosticMessages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function buildInfoFileOutput(messageTable, inputFilePathRel) {
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };",
"}",
"",
"/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion*/", // type assertions are needed for isolatedDeclarations
iisaduan marked this conversation as resolved.
Show resolved Hide resolved
"/** @internal */",
"export const Diagnostics = {",
];
Expand All @@ -101,7 +102,7 @@ function buildInfoFileOutput(messageTable, inputFilePathRel) {
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${!reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : ""}, /*elidedInCompatabilityPyramid*/ ${elidedInCompatabilityPyramid}` : "";
const argReportsDeprecated = reportsDeprecated ? `${!argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : ""}, /*reportsDeprecated*/ ${reportsDeprecated}` : "";

result.push(` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),`);
result.push(` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}) as DiagnosticMessage,`);
iisaduan marked this conversation as resolved.
Show resolved Hide resolved
});

result.push("};");
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export function createFlowNode(flags: FlowFlags, node: unknown, antecedent: Flow
const binder = /* @__PURE__ */ createBinder();

/** @internal */
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
export function bindSourceFile(file: SourceFile, options: CompilerOptions): void {
performance.mark("beforeBind");
binder(file, options);
performance.mark("afterBind");
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BuilderProgramHost,
BuilderState,
BuildInfo,
BuildInfoFileVersionMap,
CancellationToken,
CommandLineOption,
compareStringsCaseSensitive,
Expand Down Expand Up @@ -277,7 +278,7 @@ function toBuilderProgramStateWithDefinedProgram(state: ReusableBuilderProgramSt
*
* @internal
*/
export function getBuilderFileEmit(options: CompilerOptions) {
export function getBuilderFileEmit(options: CompilerOptions): BuilderFileEmit {
let result = BuilderFileEmit.Js;
if (options.sourceMap) result = result | BuilderFileEmit.JsMap;
if (options.inlineSourceMap) result = result | BuilderFileEmit.JsInlineMap;
Expand Down Expand Up @@ -733,7 +734,7 @@ export function getPendingEmitKindWithSeen(
seenOldOptionsOrEmitKind: CompilerOptions | BuilderFileEmit | undefined,
emitOnlyDtsFiles: boolean | undefined,
isForDtsErrors: boolean,
) {
): BuilderFileEmit {
let pendingKind = getPendingEmitKind(optionsOrEmitKind, seenOldOptionsOrEmitKind);
if (emitOnlyDtsFiles) pendingKind = pendingKind & BuilderFileEmit.AllDts;
if (isForDtsErrors) pendingKind = pendingKind & BuilderFileEmit.DtsErrors;
Expand Down Expand Up @@ -1623,7 +1624,7 @@ export function computeSignatureWithDiagnostics(
text: string,
host: HostForComputeHash,
data: WriteFileCallbackData | undefined,
) {
): string {
text = getTextHandlingSourceMapForSignature(text, data);
let sourceFileDirectory: string | undefined;
if (data?.diagnostics?.length) {
Expand Down Expand Up @@ -2395,7 +2396,7 @@ export function getBuildInfoFileVersionMap(
program: IncrementalBuildInfo,
buildInfoPath: string,
host: Pick<ReadBuildProgramHost, "useCaseSensitiveFileNames" | "getCurrentDirectory">,
) {
): BuildInfoFileVersionMap {
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
const fileInfos = new Map<Path, string>();
Expand Down Expand Up @@ -2440,7 +2441,7 @@ export function getNonIncrementalBuildInfoRoots(
buildInfo: BuildInfo,
buildInfoPath: string,
host: Pick<ReadBuildProgramHost, "useCaseSensitiveFileNames" | "getCurrentDirectory">,
) {
): Path[] | undefined {
if (!isNonIncrementalBuildInfo(buildInfo)) return undefined;
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
Expand Down
16 changes: 8 additions & 8 deletions src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ export namespace BuilderState {
/**
* Returns true if oldState is reusable, that is the emitKind = module/non module has not changed
*/
export function canReuseOldState(newReferencedMap: ReadonlyManyToManyPathMap | undefined, oldState: BuilderState | undefined) {
export function canReuseOldState(newReferencedMap: ReadonlyManyToManyPathMap | undefined, oldState: BuilderState | undefined): boolean | undefined {
return oldState && !oldState.referencedMap === !newReferencedMap;
}

export function createReferencedMap(options: CompilerOptions) {
export function createReferencedMap(options: CompilerOptions): ManyToManyPathMap | undefined {
return options.module !== ModuleKind.None && !options.outFile ?
createManyToManyPathMap() :
undefined;
Expand Down Expand Up @@ -346,7 +346,7 @@ export namespace BuilderState {
/**
* Releases needed properties
*/
export function releaseCache(state: BuilderState) {
export function releaseCache(state: BuilderState): void {
state.allFilesExcludingDefaultLibraryFile = undefined;
state.allFileNames = undefined;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ export namespace BuilderState {
return (state.referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit)(state, programOfThisState, sourceFile, cancellationToken, host);
}

export function updateSignatureOfFile(state: BuilderState, signature: string | undefined, path: Path) {
export function updateSignatureOfFile(state: BuilderState, signature: string | undefined, path: Path): void {
state.fileInfos.get(path)!.signature = signature;
(state.hasCalledUpdateShapeSignature ||= new Set()).add(path);
}
Expand All @@ -402,7 +402,7 @@ export namespace BuilderState {
cancellationToken: CancellationToken | undefined,
host: HostForComputeHash,
onNewSignature: (signature: string, sourceFiles: readonly SourceFile[]) => void,
) {
): void {
programOfThisState.emit(
sourceFile,
(fileName, text, _writeByteOrderMark, _onError, sourceFiles, data) => {
Expand Down Expand Up @@ -434,8 +434,8 @@ export namespace BuilderState {
sourceFile: SourceFile,
cancellationToken: CancellationToken | undefined,
host: HostForComputeHash,
useFileVersionAsSignature = state.useFileVersionAsSignature,
) {
useFileVersionAsSignature: boolean | undefined = state.useFileVersionAsSignature,
): boolean {
// If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
if (state.hasCalledUpdateShapeSignature?.has(sourceFile.resolvedPath)) return false;

Expand Down Expand Up @@ -507,7 +507,7 @@ export namespace BuilderState {
/**
* Gets the files referenced by the the file path
*/
export function getReferencedByPaths(state: Readonly<BuilderState>, referencedFilePath: Path) {
export function getReferencedByPaths(state: Readonly<BuilderState>, referencedFilePath: Path): Path[] {
const keys = state.referencedMap!.getKeys(referencedFilePath);
return keys ? arrayFrom(keys.keys()) : [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ export function getSymbolId(symbol: Symbol): SymbolId {
}

/** @internal */
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean {
const moduleState = getModuleInstanceState(node);
return moduleState === ModuleInstanceState.Instantiated ||
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
Expand Down Expand Up @@ -52709,7 +52709,7 @@ function getIterationTypesKeyFromIterationTypeKind(typeKind: IterationTypeKind)
}

/** @internal */
export function signatureHasRestParameter(s: Signature) {
export function signatureHasRestParameter(s: Signature): boolean {
return !!(s.flags & SignatureFlags.HasRestParameter);
}

Expand Down
36 changes: 22 additions & 14 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const jsxOptionMap = new Map(Object.entries({
}));

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

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

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

// Watch related options

Expand Down Expand Up @@ -1800,7 +1800,7 @@ function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType
}

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

Expand Down Expand Up @@ -1835,6 +1835,14 @@ export interface OptionsBase {
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
}

/** @internal */
export interface BaseParsedCommandLine {
options: OptionsBase;
watchOptions: WatchOptions | undefined;
fileNames: string[];
errors: Diagnostic[];
}

/** @internal */
export interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
getOptionsNameMap: () => OptionsNameMap;
Expand Down Expand Up @@ -1875,7 +1883,7 @@ export function parseCommandLineWorker(
diagnostics: ParseCommandLineWorkerDiagnostics,
commandLine: readonly string[],
readFile?: (path: string) => string | undefined,
) {
): BaseParsedCommandLine {
const options = {} as OptionsBase;
let watchOptions: WatchOptions | undefined;
const fileNames: string[] = [];
Expand Down Expand Up @@ -2602,11 +2610,11 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
const providedKeys = new Set(optionMap.keys());
const impliedCompilerOptions: Record<string, CompilerOptionsValue> = {};
for (const option in computedOptions) {
if (!providedKeys.has(option) && some(computedOptions[option as keyof typeof computedOptions].dependencies, dep => providedKeys.has(dep))) {
const implied = computedOptions[option as keyof typeof computedOptions].computeValue(configParseResult.options);
const defaultValue = computedOptions[option as keyof typeof computedOptions].computeValue({});
if (!providedKeys.has(option) && some(computedOptions[option].dependencies, dep => providedKeys.has(dep))) {
const implied = computedOptions[option].computeValue(configParseResult.options);
const defaultValue = computedOptions[option].computeValue({});
if (implied !== defaultValue) {
impliedCompilerOptions[option] = computedOptions[option as keyof typeof computedOptions].computeValue(configParseResult.options);
impliedCompilerOptions[option] = computedOptions[option].computeValue(configParseResult.options);
}
}
}
Expand Down Expand Up @@ -2866,7 +2874,7 @@ export function generateTSConfig(options: CompilerOptions, fileNames: readonly s
}

/** @internal */
export function convertToOptionsWithAbsolutePaths(options: CompilerOptions, toAbsolutePath: (path: string) => string) {
export function convertToOptionsWithAbsolutePaths(options: CompilerOptions, toAbsolutePath: (path: string) => string): CompilerOptions {
const result: CompilerOptions = {};
const optionsNameMap = getOptionsNameMap().optionsNameMap;

Expand Down Expand Up @@ -2927,7 +2935,7 @@ export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceF
}

/** @internal */
export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile | undefined) {
export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile | undefined): void {
if (configFile) {
Object.defineProperty(options, "configFile", { enumerable: false, writable: false, value: configFile });
}
Expand Down Expand Up @@ -3243,12 +3251,12 @@ function shouldReportNoInputFiles(fileNames: string[], canJsonReportNoInutFiles:
}

/** @internal */
export function canJsonReportNoInputFiles(raw: any) {
export function canJsonReportNoInputFiles(raw: any): boolean {
return !hasProperty(raw, "files") && !hasProperty(raw, "references");
}

/** @internal */
export function updateErrorForNoInputFiles(fileNames: string[], configFileName: string, configFileSpecs: ConfigFileSpecs, configParseDiagnostics: Diagnostic[], canJsonReportNoInutFiles: boolean) {
export function updateErrorForNoInputFiles(fileNames: string[], configFileName: string, configFileSpecs: ConfigFileSpecs, configParseDiagnostics: Diagnostic[], canJsonReportNoInutFiles: boolean): boolean {
const existingErrors = configParseDiagnostics.length;
if (shouldReportNoInputFiles(fileNames, canJsonReportNoInutFiles)) {
configParseDiagnostics.push(getErrorForNoInputFiles(configFileSpecs, configFileName));
Expand Down Expand Up @@ -3943,7 +3951,7 @@ export function matchesExclude(
excludeSpecs: readonly string[] | undefined,
useCaseSensitiveFileNames: boolean,
currentDirectory: string,
) {
): boolean {
return matchesExcludeWorker(
pathToCheck,
filter(excludeSpecs, spec => !invalidDotDotAfterRecursiveWildcard(spec)),
Expand Down
Loading