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

Id option b #4

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
"/** @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}) satisfies DiagnosticMessage as DiagnosticMessage,`);
});

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
13 changes: 8 additions & 5 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,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 +733,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 +1623,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 +2395,10 @@ export function getBuildInfoFileVersionMap(
program: IncrementalBuildInfo,
buildInfoPath: string,
host: Pick<ReadBuildProgramHost, "useCaseSensitiveFileNames" | "getCurrentDirectory">,
) {
): {
fileInfos: Map<Path, string>;
roots: Map<Path, Path | undefined>;
} {
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
const fileInfos = new Map<Path, string>();
Expand Down Expand Up @@ -2440,7 +2443,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 @@ -1449,7 +1449,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 @@ -52687,7 +52687,7 @@ function getIterationTypesKeyFromIterationTypeKind(typeKind: IterationTypeKind)
}

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

Expand Down
25 changes: 15 additions & 10 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<string, string>(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<string, string>(libEntries);

// Watch related options

Expand Down Expand Up @@ -1797,7 +1797,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 @@ -1864,7 +1864,12 @@ export function parseCommandLineWorker(
diagnostics: ParseCommandLineWorkerDiagnostics,
commandLine: readonly string[],
readFile?: (path: string) => string | undefined,
) {
): {
options: OptionsBase;
watchOptions: WatchOptions | undefined;
fileNames: string[];
errors: Diagnostic[];
} {
const options = {} as OptionsBase;
let watchOptions: WatchOptions | undefined;
const fileNames: string[] = [];
Expand Down Expand Up @@ -2856,7 +2861,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 @@ -2917,7 +2922,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 @@ -3234,12 +3239,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 @@ -3927,7 +3932,7 @@ export function matchesExclude(
excludeSpecs: readonly string[] | undefined,
useCaseSensitiveFileNames: boolean,
currentDirectory: string,
) {
): boolean {
return matchesExcludeWorker(
pathToCheck,
filter(excludeSpecs, spec => !invalidDotDotAfterRecursiveWildcard(spec)),
Expand Down
Loading
Loading