Skip to content
Merged
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
39 changes: 19 additions & 20 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ import {
PrefixUnaryExpression,
ProjectReference,
PropertyName,
Push,
removeTrailingDirectorySeparator,
returnTrue,
ScriptTarget,
Expand Down Expand Up @@ -1699,12 +1698,12 @@ function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType
}

/** @internal */
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Push<Diagnostic>) {
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
return convertJsonOptionOfCustomType(opt, trimString(value || ""), errors);
}

/** @internal */
export function parseListTypeOption(opt: CommandLineOptionOfListType, value = "", errors: Push<Diagnostic>): string | (string | number)[] | undefined {
export function parseListTypeOption(opt: CommandLineOptionOfListType, value = "", errors: Diagnostic[]): string | (string | number)[] | undefined {
value = trimString(value);
if (startsWith(value, "-")) {
return undefined;
Expand Down Expand Up @@ -2254,7 +2253,7 @@ export interface JsonConversionNotifier {
onSetUnknownOptionKeyValueInRoot(key: string, keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression): void;
}

function convertConfigFileToObject(sourceFile: JsonSourceFile, errors: Push<Diagnostic>, reportOptionsErrors: boolean, optionsIterator: JsonConversionNotifier | undefined): any {
function convertConfigFileToObject(sourceFile: JsonSourceFile, errors: Diagnostic[], reportOptionsErrors: boolean, optionsIterator: JsonConversionNotifier | undefined): any {
const rootExpression: Expression | undefined = sourceFile.statements[0]?.expression;
const knownRootOptions = reportOptionsErrors ? getTsconfigRootOptionsMap() : undefined;
if (rootExpression && rootExpression.kind !== SyntaxKind.ObjectLiteralExpression) {
Expand Down Expand Up @@ -2295,7 +2294,7 @@ export function convertToObject(sourceFile: JsonSourceFile, errors: Diagnostic[]
export function convertToObjectWorker(
sourceFile: JsonSourceFile,
rootExpression: Expression | undefined,
errors: Push<Diagnostic>,
errors: Diagnostic[],
returnValue: boolean,
knownRootOptions: CommandLineOption | undefined,
jsonConversionNotifier: JsonConversionNotifier | undefined): any {
Expand Down Expand Up @@ -3248,7 +3247,7 @@ function parseOwnConfigOfJson(
host: ParseConfigHost,
basePath: string,
configFileName: string | undefined,
errors: Push<Diagnostic>
errors: Diagnostic[]
): ParsedTsconfig {
if (hasProperty(json, "excludes")) {
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
Expand Down Expand Up @@ -3290,7 +3289,7 @@ function parseOwnConfigOfJsonSourceFile(
host: ParseConfigHost,
basePath: string,
configFileName: string | undefined,
errors: Push<Diagnostic>
errors: Diagnostic[]
): ParsedTsconfig {
const options = getDefaultCompilerOptions(configFileName);
let typeAcquisition: TypeAcquisition | undefined;
Expand Down Expand Up @@ -3376,7 +3375,7 @@ function getExtendsConfigPath(
extendedConfig: string,
host: ParseConfigHost,
basePath: string,
errors: Push<Diagnostic>,
errors: Diagnostic[],
createDiagnostic: (message: DiagnosticMessage, arg1?: string) => Diagnostic) {
extendedConfig = normalizeSlashes(extendedConfig);
if (isRootedDiskPath(extendedConfig) || startsWith(extendedConfig, "./") || startsWith(extendedConfig, "../")) {
Expand Down Expand Up @@ -3450,7 +3449,7 @@ function getExtendedConfig(
return extendedConfig!;
}

function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Push<Diagnostic>): boolean {
function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Diagnostic[]): boolean {
if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) {
return false;
}
Expand Down Expand Up @@ -3478,7 +3477,7 @@ function getDefaultCompilerOptions(configFileName?: string) {
}

function convertCompilerOptionsFromJsonWorker(jsonOptions: any,
basePath: string, errors: Push<Diagnostic>, configFileName?: string): CompilerOptions {
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {

const options = getDefaultCompilerOptions(configFileName);
convertOptionsFromJson(getCommandLineCompilerOptionsMap(), jsonOptions, basePath, options, compilerOptionsDidYouMeanDiagnostics, errors);
Expand All @@ -3493,23 +3492,23 @@ function getDefaultTypeAcquisition(configFileName?: string): TypeAcquisition {
}

function convertTypeAcquisitionFromJsonWorker(jsonOptions: any,
basePath: string, errors: Push<Diagnostic>, configFileName?: string): TypeAcquisition {
basePath: string, errors: Diagnostic[], configFileName?: string): TypeAcquisition {

const options = getDefaultTypeAcquisition(configFileName);
convertOptionsFromJson(getCommandLineTypeAcquisitionMap(), jsonOptions, basePath, options, typeAcquisitionDidYouMeanDiagnostics, errors);
return options;
}

function convertWatchOptionsFromJsonWorker(jsonOptions: any, basePath: string, errors: Push<Diagnostic>): WatchOptions | undefined {
function convertWatchOptionsFromJsonWorker(jsonOptions: any, basePath: string, errors: Diagnostic[]): WatchOptions | undefined {
return convertOptionsFromJson(getCommandLineWatchOptionsMap(), jsonOptions, basePath, /*defaultOptions*/ undefined, watchOptionsDidYouMeanDiagnostics, errors);
}

function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>, jsonOptions: any, basePath: string,
defaultOptions: undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Push<Diagnostic>): WatchOptions | undefined;
defaultOptions: undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Diagnostic[]): WatchOptions | undefined;
function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>, jsonOptions: any, basePath: string,
defaultOptions: CompilerOptions | TypeAcquisition, diagnostics: DidYouMeanOptionsDiagnostics, errors: Push<Diagnostic>): CompilerOptions | TypeAcquisition;
defaultOptions: CompilerOptions | TypeAcquisition, diagnostics: DidYouMeanOptionsDiagnostics, errors: Diagnostic[]): CompilerOptions | TypeAcquisition;
function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>, jsonOptions: any, basePath: string,
defaultOptions: CompilerOptions | TypeAcquisition | WatchOptions | undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Push<Diagnostic>) {
defaultOptions: CompilerOptions | TypeAcquisition | WatchOptions | undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Diagnostic[]) {

if (!jsonOptions) {
return;
Expand All @@ -3528,7 +3527,7 @@ function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>,
}

/** @internal */
export function convertJsonOption(opt: CommandLineOption, value: any, basePath: string, errors: Push<Diagnostic>): CompilerOptionsValue {
export function convertJsonOption(opt: CommandLineOption, value: any, basePath: string, errors: Diagnostic[]): CompilerOptionsValue {
if (isCompilerOptionsValue(opt, value)) {
const optType = opt.type;
if ((optType === "list") && isArray(value)) {
Expand Down Expand Up @@ -3576,15 +3575,15 @@ function normalizeNonListOptionValue(option: CommandLineOption, basePath: string
return value;
}

function validateJsonOptionValue<T extends CompilerOptionsValue>(opt: CommandLineOption, value: T, errors: Push<Diagnostic>): T | undefined {
function validateJsonOptionValue<T extends CompilerOptionsValue>(opt: CommandLineOption, value: T, errors: Diagnostic[]): T | undefined {
if (isNullOrUndefined(value)) return undefined;
const d = opt.extraValidation?.(value);
if (!d) return value;
errors.push(createCompilerDiagnostic(...d));
return undefined;
}

function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value: string, errors: Push<Diagnostic>) {
function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
if (isNullOrUndefined(value)) return undefined;
const key = value.toLowerCase();
const val = opt.type.get(key);
Expand All @@ -3596,7 +3595,7 @@ function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value
}
}

function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: readonly any[], basePath: string, errors: Push<Diagnostic>): any[] {
function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: readonly any[], basePath: string, errors: Diagnostic[]): any[] {
return filter(map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => option.listPreserveFalsyValues ? true : !!v);
}

Expand Down Expand Up @@ -3793,7 +3792,7 @@ function matchesExcludeWorker(
return !hasExtension(pathToCheck) && excludeRegex.test(ensureTrailingDirectorySeparator(pathToCheck));
}

function validateSpecs(specs: readonly string[], errors: Push<Diagnostic>, disallowTrailingRecursion: boolean, jsonSourceFile: TsConfigSourceFile | undefined, specKey: string): readonly string[] {
function validateSpecs(specs: readonly string[], errors: Diagnostic[], disallowTrailingRecursion: boolean, jsonSourceFile: TsConfigSourceFile | undefined, specKey: string): readonly string[] {
return specs.filter(spec => {
if (!isString(spec)) return false;
const diag = specToDiagnostic(spec, disallowTrailingRecursion);
Expand Down
14 changes: 3 additions & 11 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
EqualityComparer,
isWhiteSpaceLike,
MapLike,
Push,
Queue,
SortedArray,
SortedReadonlyArray,
Expand Down Expand Up @@ -1001,14 +1000,13 @@ export function append<T>(to: T[] | undefined, value: T): T[];
/** @internal */
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined;
/** @internal */
export function append<T>(to: Push<T>, value: T | undefined): void;
export function append<T>(to: T[], value: T | undefined): void;
/** @internal */
export function append<T>(to: Push<T> | T[] | undefined, value: T | undefined): T[] | undefined {
// If to is Push<T>, return value is void, so safe to cast to T[].
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
if (value === undefined) return to as T[];
if (to === undefined) return [value];
to.push(value);
return to as T[];
return to;
}

/**
Expand Down Expand Up @@ -1887,12 +1885,6 @@ export function cast<TOut extends TIn, TIn = any>(value: TIn | undefined, test:
*/
export function noop(_?: unknown): void { }

/** @internal */
export const noopPush: Push<any> = {
push: noop,
length: 0
};

/**
* Do nothing and return false
*
Expand Down
10 changes: 0 additions & 10 deletions src/compiler/corePublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ export interface Collection<K> extends ReadonlyCollection<K> {
clear(): void;
}

/**
* Array that is only intended to be pushed to, never read.
*
* @internal
*/
export interface Push<T> {
push(...values: T[]): void;
readonly length: number;
}

/** @internal */
export type EqualityComparer<T> = (a: T, b: T) => boolean;

Expand Down
13 changes: 6 additions & 7 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ import {
pseudoBigIntToString,
PunctuationSyntaxKind,
PunctuationToken,
Push,
QualifiedName,
QuestionDotToken,
QuestionToken,
Expand Down Expand Up @@ -6439,7 +6438,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
return createGlobalMethodCall("Reflect", "set", receiver ? [target, propertyKey, value, receiver] : [target, propertyKey, value]);
}

function tryAddPropertyAssignment(properties: Push<PropertyAssignment>, propertyName: string, expression: Expression | undefined) {
function tryAddPropertyAssignment(properties: PropertyAssignment[], propertyName: string, expression: Expression | undefined) {
if (expression) {
properties.push(createPropertyAssignment(propertyName, expression));
return true;
Expand Down Expand Up @@ -6760,7 +6759,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
* @param visitor Optional callback used to visit any custom prologue directives.
*/
function copyPrologue(source: readonly Statement[], target: Push<Statement>, ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult<Node>): number {
function copyPrologue(source: readonly Statement[], target: Statement[], ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult<Node>): number {
const offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
return copyCustomPrologue(source, target, offset, visitor);
}
Expand All @@ -6781,7 +6780,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
* @returns Count of how many directive statements were copied.
*/
function copyStandardPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset = 0, ensureUseStrict?: boolean): number {
function copyStandardPrologue(source: readonly Statement[], target: Statement[], statementOffset = 0, ensureUseStrict?: boolean): number {
Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
let foundUseStrict = false;
const numStatements = source.length;
Expand Down Expand Up @@ -6811,9 +6810,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
* @param statementOffset The offset at which to begin the copy.
* @param visitor Optional callback used to visit any custom prologue directives.
*/
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number;
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number | undefined;
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter: (node: Statement) => boolean = returnTrue): number | undefined {
function copyCustomPrologue(source: readonly Statement[], target: Statement[], statementOffset: number, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number;
function copyCustomPrologue(source: readonly Statement[], target: Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number | undefined;
function copyCustomPrologue(source: readonly Statement[], target: Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter: (node: Statement) => boolean = returnTrue): number | undefined {
const numStatements = source.length;
while (statementOffset !== undefined && statementOffset < numStatements) {
const statement = source[statementOffset];
Expand Down
22 changes: 10 additions & 12 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import {
moduleResolutionOptionDeclarations,
moduleResolutionSupportsPackageJsonExportsAndImports,
noop,
noopPush,
normalizePath,
normalizeSlashes,
PackageId,
Expand All @@ -82,7 +81,6 @@ import {
Pattern,
patternText,
perfLogger,
Push,
readJson,
removeExtension,
removeFileExtension,
Expand Down Expand Up @@ -285,8 +283,8 @@ export interface ModuleResolutionState {
host: ModuleResolutionHost;
compilerOptions: CompilerOptions;
traceEnabled: boolean;
failedLookupLocations: Push<string>;
affectingLocations: Push<string>;
failedLookupLocations: string[] | undefined;
affectingLocations: string[] | undefined;
resultFromCache?: ResolvedModuleWithFailedLookupLocations;
packageJsonInfoCache: PackageJsonInfoCache | undefined;
features: NodeResolutionFeatures;
Expand Down Expand Up @@ -2045,7 +2043,7 @@ function tryFileLookup(fileName: string, onlyRecordFailures: boolean, state: Mod
}
}
}
state.failedLookupLocations.push(fileName);
state.failedLookupLocations?.push(fileName);
return undefined;
}

Expand Down Expand Up @@ -2171,8 +2169,8 @@ export function getTemporaryModuleResolutionState(packageJsonInfoCache: PackageJ
host,
compilerOptions: options,
traceEnabled: isTraceEnabled(options, host),
failedLookupLocations: noopPush,
affectingLocations: noopPush,
failedLookupLocations: undefined,
affectingLocations: undefined,
packageJsonInfoCache,
features: NodeResolutionFeatures.None,
conditions: emptyArray,
Expand Down Expand Up @@ -2227,22 +2225,22 @@ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures:
const { host, traceEnabled } = state;
const packageJsonPath = combinePaths(packageDirectory, "package.json");
if (onlyRecordFailures) {
state.failedLookupLocations.push(packageJsonPath);
state.failedLookupLocations?.push(packageJsonPath);
return undefined;
}

const existing = state.packageJsonInfoCache?.getPackageJsonInfo(packageJsonPath);
if (existing !== undefined) {
if (typeof existing !== "boolean") {
if (traceEnabled) trace(host, Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath);
state.affectingLocations.push(packageJsonPath);
state.affectingLocations?.push(packageJsonPath);
return existing.packageDirectory === packageDirectory ?
existing :
{ packageDirectory, contents: existing.contents };
}
else {
if (existing && traceEnabled) trace(host, Diagnostics.File_0_does_not_exist_according_to_earlier_cached_lookups, packageJsonPath);
state.failedLookupLocations.push(packageJsonPath);
state.failedLookupLocations?.push(packageJsonPath);
return undefined;
}
}
Expand All @@ -2254,7 +2252,7 @@ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures:
}
const result: PackageJsonInfo = { packageDirectory, contents: { packageJsonContent, versionPaths: undefined, resolvedEntrypoints: undefined } };
state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, result);
state.affectingLocations.push(packageJsonPath);
state.affectingLocations?.push(packageJsonPath);
return result;
}
else {
Expand All @@ -2263,7 +2261,7 @@ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures:
}
state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, directoryExists);
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
state.failedLookupLocations.push(packageJsonPath);
state.failedLookupLocations?.push(packageJsonPath);
}
}

Expand Down
Loading