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 1 commit
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
6 changes: 2 additions & 4 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
WriteFileCallback,
WriteFileCallbackData,
} from "./_namespaces/ts.js";
import { BuildInfoFileVersionMap } from "./types.js";
iisaduan marked this conversation as resolved.
Show resolved Hide resolved

/** @internal */
export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation {
Expand Down Expand Up @@ -2395,10 +2396,7 @@ export function getBuildInfoFileVersionMap(
program: IncrementalBuildInfo,
buildInfoPath: string,
host: Pick<ReadBuildProgramHost, "useCaseSensitiveFileNames" | "getCurrentDirectory">,
): {
fileInfos: Map<Path, string>;
roots: Map<Path, Path | undefined>;
} {
): BuildInfoFileVersionMap {
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
const fileInfos = new Map<Path, string>();
Expand Down
15 changes: 9 additions & 6 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
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,12 +1883,7 @@ export function parseCommandLineWorker(
diagnostics: ParseCommandLineWorkerDiagnostics,
commandLine: readonly string[],
readFile?: (path: string) => string | undefined,
): {
options: OptionsBase;
watchOptions: WatchOptions | undefined;
fileNames: string[];
errors: Diagnostic[];
} {
): BaseParsedCommandLine {
const options = {} as OptionsBase;
let watchOptions: WatchOptions | undefined;
const fileNames: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export namespace Debug {
export function type<T>(value: unknown): asserts value is T;
export function type(_value: unknown) {}

export function getFunctionName(func: AnyFunction): any {
export function getFunctionName(func: AnyFunction): string {
if (typeof func !== "function") {
return "";
}
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,12 @@ function getOutputPathWithoutChangingExt(
}

/** @internal */
export function getOutputDeclarationFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean, getCommonSourceDirectory = (): string => getCommonSourceDirectoryOfConfig(configFile, ignoreCase)): string {
export function getOutputDeclarationFileName(
inputFileName: string,
configFile: ParsedCommandLine,
ignoreCase: boolean,
getCommonSourceDirectory = (): string => getCommonSourceDirectoryOfConfig(configFile, ignoreCase),
): string {
return getOutputDeclarationFileNameWorker(inputFileName, configFile.options, ignoreCase, getCommonSourceDirectory);
}

Expand Down
8 changes: 2 additions & 6 deletions src/compiler/expressionToTypeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
PropertySignature,
SetAccessorDeclaration,
SignatureDeclaration,
SyntacticNodeBuilder,
SyntacticTypeNodeBuilderContext,
SyntacticTypeNodeBuilderResolver,
SyntaxKind,
Expand All @@ -69,12 +70,7 @@ import {
export function createSyntacticTypeNodeBuilder(
options: CompilerOptions,
resolver: SyntacticTypeNodeBuilderResolver,
): {
typeFromExpression: (node: Expression, context: SyntacticTypeNodeBuilderContext, isConstContext?: boolean, requiresAddingUndefined?: boolean, preserveLiterals?: boolean) => boolean | undefined;
serializeTypeOfDeclaration: (node: HasInferredType, context: SyntacticTypeNodeBuilderContext) => boolean | undefined;
serializeReturnTypeForSignature: (node: SignatureDeclaration | JSDocSignature, context: SyntacticTypeNodeBuilderContext) => boolean | undefined;
serializeTypeOfExpression: (expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) => boolean;
} {
): SyntacticNodeBuilder {
const strictNullChecks = getStrictOptionValue(options, "strictNullChecks");

return {
Expand Down
26 changes: 10 additions & 16 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,7 @@ function readPackageJsonTypesVersionPaths(jsonContent: PackageJson, state: Modul
let typeScriptVersion: Version | undefined;

/** @internal */
export function getPackageJsonTypesVersionsPaths(typesVersions: MapLike<MapLike<string[]>>): {
version: string;
paths: MapLike<string[]>;
} | undefined {
export function getPackageJsonTypesVersionsPaths(typesVersions: MapLike<MapLike<string[]>>): VersionPaths | undefined {
if (!typeScriptVersion) typeScriptVersion = new Version(version);

for (const key in typesVersions) {
Expand Down Expand Up @@ -1386,10 +1383,7 @@ export function createTypeReferenceDirectiveResolutionCache(
}

/** @internal */
export function getOptionsForLibraryResolution(options: CompilerOptions): {
moduleResolution: ModuleResolutionKind;
traceResolution: boolean | undefined;
} {
export function getOptionsForLibraryResolution(options: CompilerOptions): CompilerOptions {
return { moduleResolution: ModuleResolutionKind.Node10, traceResolution: options.traceResolution };
}

Expand Down Expand Up @@ -2683,18 +2677,18 @@ function loadModuleFromImports(extensions: Extensions, moduleName: string, direc
* From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 -
* "longest" has some nuance as to what "longest" means in the presence of pattern trailers
*/
export function comparePatternKeys(a: string, b: string): 1 | 0 | -1 {
export function comparePatternKeys(a: string, b: string): Comparison {
const aPatternIndex = a.indexOf("*");
const bPatternIndex = b.indexOf("*");
const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
if (baseLenA > baseLenB) return -1;
if (baseLenB > baseLenA) return 1;
if (aPatternIndex === -1) return 1;
if (bPatternIndex === -1) return -1;
if (a.length > b.length) return -1;
if (b.length > a.length) return 1;
return 0;
if (baseLenA > baseLenB) return Comparison.LessThan;
if (baseLenB > baseLenA) return Comparison.GreaterThan;
if (aPatternIndex === -1) return Comparison.GreaterThan;
if (bPatternIndex === -1) return Comparison.LessThan;
if (a.length > b.length) return Comparison.LessThan;
if (b.length > a.length) return Comparison.GreaterThan;
return Comparison.EqualTo;
}

function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined, moduleName: string, lookupTable: object, scope: PackageJsonInfo, isImports: boolean): SearchResult<Resolved> | undefined {
Expand Down
7 changes: 5 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1404,10 +1404,13 @@ export function updateSourceFile(sourceFile: SourceFile, newText: string, textCh
}

/** @internal */
export function parseIsolatedJSDocComment(content: string, start?: number, length?: number): {
export interface JsDocWithDiagnostics {
jsDoc: JSDoc;
diagnostics: Diagnostic[];
} | undefined {
}

/** @internal */
export function parseIsolatedJSDocComment(content: string, start?: number, length?: number): JsDocWithDiagnostics | undefined {
const result = Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
if (result && result.jsDoc) {
// because the jsDocComment was parsed out of the source file, it might
Expand Down
15 changes: 9 additions & 6 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,22 @@ export interface CompilerHostLikeForCache {
}

/** @internal */
export function changeCompilerHostLikeToUseCache(
host: CompilerHostLikeForCache,
toPath: (fileName: string) => Path,
getSourceFile?: CompilerHost["getSourceFile"],
): {
export interface CompilerHostLikeWithCache {
originalReadFile: (fileName: string, encoding?: string) => string | undefined;
originalFileExists: (fileName: string) => boolean;
originalDirectoryExists: ((directory: string) => boolean) | undefined;
originalCreateDirectory: ((directory: string) => void) | undefined;
originalWriteFile: WriteFileCallback | undefined;
getSourceFileWithCache: ((fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean) => SourceFile | undefined) | undefined;
readFileWithCache: (fileName: string) => string | undefined;
} {
}

/** @internal */
export function changeCompilerHostLikeToUseCache(
host: CompilerHostLikeForCache,
toPath: (fileName: string) => Path,
getSourceFile?: CompilerHost["getSourceFile"],
): CompilerHostLikeWithCache {
const originalReadFile = host.readFile;
const originalFileExists = host.fileExists;
const originalDirectoryExists = host.directoryExists;
Expand Down
14 changes: 11 additions & 3 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const charCodeToRegExpFlag = new Map<CharacterCodes, RegularExpressionFlags>([
[CharacterCodes.y, RegularExpressionFlags.Sticky],
]);

const regExpFlagToFirstAvailableLanguageVersion = new Map<RegularExpressionFlags, LanguageFeatureMinimumTarget>([
const regExpFlagToFirstAvailableLanguageVersion = new Map<RegularExpressionFlags, ScriptTarget>([
iisaduan marked this conversation as resolved.
Show resolved Hide resolved
[RegularExpressionFlags.HasIndices, LanguageFeatureMinimumTarget.RegularExpressionFlagsHasIndices],
[RegularExpressionFlags.DotAll, LanguageFeatureMinimumTarget.RegularExpressionFlagsDotAll],
[RegularExpressionFlags.Unicode, LanguageFeatureMinimumTarget.RegularExpressionFlagsUnicode],
Expand Down Expand Up @@ -1017,7 +1017,15 @@ const enum ClassSetExpressionType {
}

// Creates a scanner over a (possibly unspecified) range of a piece of text.
export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant: LanguageVariant = LanguageVariant.Standard, textInitial?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner {
export function createScanner(
languageVersion: ScriptTarget,
skipTrivia: boolean,
languageVariant: LanguageVariant = LanguageVariant.Standard,
textInitial?: string,
onError?: ErrorCallback,
start?: number,
length?: number,
): Scanner {
// Why var? It avoids TDZ checks in the runtime which can be costly.
// See: https://github.com/microsoft/TypeScript/issues/52924
/* eslint-disable no-var */
Expand Down Expand Up @@ -3599,7 +3607,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
}

function checkRegularExpressionFlagAvailability(flag: RegularExpressionFlags, size: number) {
const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag) as ScriptTarget | undefined;
const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag);
if (availableFrom && languageVersion < availableFrom) {
error(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, pos, size, getNameOfScriptTarget(availableFrom));
}
Expand Down
6 changes: 1 addition & 5 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ function createPollingIntervalBasedLevels(levels: Levels) {
const defaultChunkLevels: Levels = { Low: 32, Medium: 64, High: 256 };
let pollingChunkSize = createPollingIntervalBasedLevels(defaultChunkLevels);
/** @internal */
export let unchangedPollThresholds: {
250: number;
500: number;
2000: number;
} = createPollingIntervalBasedLevels(defaultChunkLevels);
export let unchangedPollThresholds: { [K in PollingInterval]: number; } = createPollingIntervalBasedLevels(defaultChunkLevels);

function setCustomPollingValues(system: System) {
if (!system.getEnvironmentVariable) {
Expand Down
7 changes: 2 additions & 5 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ import {
visitNodes,
VisitResult,
} from "../_namespaces/ts.js";
import { DeclarationTransformer } from "../types.js";
iisaduan marked this conversation as resolved.
Show resolved Hide resolved

/** @internal */
export function getDeclarationDiagnostics(
Expand Down Expand Up @@ -253,11 +254,7 @@ const declarationEmitInternalNodeBuilderFlags = InternalNodeBuilderFlags.AllowUn
*
* @internal
*/
export function transformDeclarations(context: TransformationContext): {
(node: Bundle): Bundle;
(node: SourceFile): SourceFile;
(node: SourceFile | Bundle): SourceFile | Bundle;
} {
export function transformDeclarations(context: TransformationContext): DeclarationTransformer {
const throwDiagnostic = () => Debug.fail("Diagnostic emitted without context");
let getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic = throwDiagnostic;
let needsDeclare = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
SyntaxKind,
TransformationContext,
transformECMAScriptModule,
Transformer,
transformModule,
} from "../../_namespaces/ts.js";

/** @internal */
export function transformImpliedNodeFormatDependentModule(context: TransformationContext): (node: SourceFile | Bundle) => SourceFile | Bundle {
export function transformImpliedNodeFormatDependentModule(context: TransformationContext): Transformer<SourceFile | Bundle> {
const previousOnSubstituteNode = context.onSubstituteNode;
const previousOnEmitNode = context.onEmitNode;

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ import {
takeWhile,
TextRange,
TransformationContext,
Transformer,
TransformFlags,
VariableDeclaration,
VariableStatement,
Expand Down Expand Up @@ -231,7 +232,7 @@ const enum ClassFacts {
}

/** @internal */
export function transformTypeScript(context: TransformationContext): (node: SourceFile | Bundle) => SourceFile | Bundle {
export function transformTypeScript(context: TransformationContext): Transformer<SourceFile | Bundle> {
const {
factory,
getEmitHelperFactory: emitHelpers,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class IdentifierNameMap<V> {
this._map.clear();
}

values(): IterableIterator<V> {
values(): MapIterator<V> {
return this._map.values();
}

Expand Down
19 changes: 16 additions & 3 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
assertType,
BuilderProgram,
BuildInfo,
BuildInfoFileVersionMap,
CancellationToken,
canJsonReportNoInputFiles,
changeCompilerHostLikeToUseCache,
Expand Down Expand Up @@ -301,13 +302,25 @@ function createSolutionBuilderHostBase<T extends BuilderProgram>(system: System,
return host;
}

export function createSolutionBuilderHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system: System = sys, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportErrorSummary?: ReportEmitErrorSummary): SolutionBuilderHost<T> {
export function createSolutionBuilderHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(
system: System = sys,
createProgram?: CreateProgram<T>,
reportDiagnostic?: DiagnosticReporter,
reportSolutionBuilderStatus?: DiagnosticReporter,
reportErrorSummary?: ReportEmitErrorSummary,
): SolutionBuilderHost<T> {
const host = createSolutionBuilderHostBase(system, createProgram, reportDiagnostic, reportSolutionBuilderStatus) as SolutionBuilderHost<T>;
host.reportErrorSummary = reportErrorSummary;
return host;
}

export function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(system: System = sys, createProgram?: CreateProgram<T>, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter, reportWatchStatus?: WatchStatusReporter): SolutionBuilderWithWatchHost<T> {
export function createSolutionBuilderWithWatchHost<T extends BuilderProgram = EmitAndSemanticDiagnosticsBuilderProgram>(
system: System = sys,
createProgram?: CreateProgram<T>,
reportDiagnostic?: DiagnosticReporter,
reportSolutionBuilderStatus?: DiagnosticReporter,
reportWatchStatus?: WatchStatusReporter,
): SolutionBuilderWithWatchHost<T> {
const host = createSolutionBuilderHostBase(system, createProgram, reportDiagnostic, reportSolutionBuilderStatus) as SolutionBuilderWithWatchHost<T>;
const watchHost = createWatchHost(system, reportWatchStatus);
copyProperties(host, watchHost);
Expand Down Expand Up @@ -1601,7 +1614,7 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
/** True if input file has changed timestamp but text is not changed, we can then do only timestamp updates on output to make it look up-to-date later */
let pseudoInputUpToDate = false;
const seenRoots = new Set<Path>();
let buildInfoVersionMap: ReturnType<typeof getBuildInfoFileVersionMap> | undefined;
let buildInfoVersionMap: BuildInfoFileVersionMap | undefined;
// Get timestamps of input files
for (const inputFile of project.fileNames) {
const inputTime = getModifiedTime(state, inputFile);
Expand Down
Loading