Skip to content

Commit 6b75ce2

Browse files
authored
Completely remove Push type (#52133)
1 parent 941b30c commit 6b75ce2

15 files changed

+57
-89
lines changed

src/compiler/commandLineParser.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ import {
9898
PrefixUnaryExpression,
9999
ProjectReference,
100100
PropertyName,
101-
Push,
102101
removeTrailingDirectorySeparator,
103102
returnTrue,
104103
ScriptTarget,
@@ -1699,12 +1698,12 @@ function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType
16991698
}
17001699

17011700
/** @internal */
1702-
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Push<Diagnostic>) {
1701+
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
17031702
return convertJsonOptionOfCustomType(opt, trimString(value || ""), errors);
17041703
}
17051704

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

2257-
function convertConfigFileToObject(sourceFile: JsonSourceFile, errors: Push<Diagnostic>, reportOptionsErrors: boolean, optionsIterator: JsonConversionNotifier | undefined): any {
2256+
function convertConfigFileToObject(sourceFile: JsonSourceFile, errors: Diagnostic[], reportOptionsErrors: boolean, optionsIterator: JsonConversionNotifier | undefined): any {
22582257
const rootExpression: Expression | undefined = sourceFile.statements[0]?.expression;
22592258
const knownRootOptions = reportOptionsErrors ? getTsconfigRootOptionsMap() : undefined;
22602259
if (rootExpression && rootExpression.kind !== SyntaxKind.ObjectLiteralExpression) {
@@ -2295,7 +2294,7 @@ export function convertToObject(sourceFile: JsonSourceFile, errors: Diagnostic[]
22952294
export function convertToObjectWorker(
22962295
sourceFile: JsonSourceFile,
22972296
rootExpression: Expression | undefined,
2298-
errors: Push<Diagnostic>,
2297+
errors: Diagnostic[],
22992298
returnValue: boolean,
23002299
knownRootOptions: CommandLineOption | undefined,
23012300
jsonConversionNotifier: JsonConversionNotifier | undefined): any {
@@ -3248,7 +3247,7 @@ function parseOwnConfigOfJson(
32483247
host: ParseConfigHost,
32493248
basePath: string,
32503249
configFileName: string | undefined,
3251-
errors: Push<Diagnostic>
3250+
errors: Diagnostic[]
32523251
): ParsedTsconfig {
32533252
if (hasProperty(json, "excludes")) {
32543253
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
@@ -3290,7 +3289,7 @@ function parseOwnConfigOfJsonSourceFile(
32903289
host: ParseConfigHost,
32913290
basePath: string,
32923291
configFileName: string | undefined,
3293-
errors: Push<Diagnostic>
3292+
errors: Diagnostic[]
32943293
): ParsedTsconfig {
32953294
const options = getDefaultCompilerOptions(configFileName);
32963295
let typeAcquisition: TypeAcquisition | undefined;
@@ -3376,7 +3375,7 @@ function getExtendsConfigPath(
33763375
extendedConfig: string,
33773376
host: ParseConfigHost,
33783377
basePath: string,
3379-
errors: Push<Diagnostic>,
3378+
errors: Diagnostic[],
33803379
createDiagnostic: (message: DiagnosticMessage, arg1?: string) => Diagnostic) {
33813380
extendedConfig = normalizeSlashes(extendedConfig);
33823381
if (isRootedDiskPath(extendedConfig) || startsWith(extendedConfig, "./") || startsWith(extendedConfig, "../")) {
@@ -3450,7 +3449,7 @@ function getExtendedConfig(
34503449
return extendedConfig!;
34513450
}
34523451

3453-
function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Push<Diagnostic>): boolean {
3452+
function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Diagnostic[]): boolean {
34543453
if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) {
34553454
return false;
34563455
}
@@ -3478,7 +3477,7 @@ function getDefaultCompilerOptions(configFileName?: string) {
34783477
}
34793478

34803479
function convertCompilerOptionsFromJsonWorker(jsonOptions: any,
3481-
basePath: string, errors: Push<Diagnostic>, configFileName?: string): CompilerOptions {
3480+
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {
34823481

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

34953494
function convertTypeAcquisitionFromJsonWorker(jsonOptions: any,
3496-
basePath: string, errors: Push<Diagnostic>, configFileName?: string): TypeAcquisition {
3495+
basePath: string, errors: Diagnostic[], configFileName?: string): TypeAcquisition {
34973496

34983497
const options = getDefaultTypeAcquisition(configFileName);
34993498
convertOptionsFromJson(getCommandLineTypeAcquisitionMap(), jsonOptions, basePath, options, typeAcquisitionDidYouMeanDiagnostics, errors);
35003499
return options;
35013500
}
35023501

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

35073506
function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>, jsonOptions: any, basePath: string,
3508-
defaultOptions: undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Push<Diagnostic>): WatchOptions | undefined;
3507+
defaultOptions: undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Diagnostic[]): WatchOptions | undefined;
35093508
function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>, jsonOptions: any, basePath: string,
3510-
defaultOptions: CompilerOptions | TypeAcquisition, diagnostics: DidYouMeanOptionsDiagnostics, errors: Push<Diagnostic>): CompilerOptions | TypeAcquisition;
3509+
defaultOptions: CompilerOptions | TypeAcquisition, diagnostics: DidYouMeanOptionsDiagnostics, errors: Diagnostic[]): CompilerOptions | TypeAcquisition;
35113510
function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>, jsonOptions: any, basePath: string,
3512-
defaultOptions: CompilerOptions | TypeAcquisition | WatchOptions | undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Push<Diagnostic>) {
3511+
defaultOptions: CompilerOptions | TypeAcquisition | WatchOptions | undefined, diagnostics: DidYouMeanOptionsDiagnostics, errors: Diagnostic[]) {
35133512

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

35303529
/** @internal */
3531-
export function convertJsonOption(opt: CommandLineOption, value: any, basePath: string, errors: Push<Diagnostic>): CompilerOptionsValue {
3530+
export function convertJsonOption(opt: CommandLineOption, value: any, basePath: string, errors: Diagnostic[]): CompilerOptionsValue {
35323531
if (isCompilerOptionsValue(opt, value)) {
35333532
const optType = opt.type;
35343533
if ((optType === "list") && isArray(value)) {
@@ -3576,15 +3575,15 @@ function normalizeNonListOptionValue(option: CommandLineOption, basePath: string
35763575
return value;
35773576
}
35783577

3579-
function validateJsonOptionValue<T extends CompilerOptionsValue>(opt: CommandLineOption, value: T, errors: Push<Diagnostic>): T | undefined {
3578+
function validateJsonOptionValue<T extends CompilerOptionsValue>(opt: CommandLineOption, value: T, errors: Diagnostic[]): T | undefined {
35803579
if (isNullOrUndefined(value)) return undefined;
35813580
const d = opt.extraValidation?.(value);
35823581
if (!d) return value;
35833582
errors.push(createCompilerDiagnostic(...d));
35843583
return undefined;
35853584
}
35863585

3587-
function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value: string, errors: Push<Diagnostic>) {
3586+
function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
35883587
if (isNullOrUndefined(value)) return undefined;
35893588
const key = value.toLowerCase();
35903589
const val = opt.type.get(key);
@@ -3596,7 +3595,7 @@ function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value
35963595
}
35973596
}
35983597

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

@@ -3793,7 +3792,7 @@ function matchesExcludeWorker(
37933792
return !hasExtension(pathToCheck) && excludeRegex.test(ensureTrailingDirectorySeparator(pathToCheck));
37943793
}
37953794

3796-
function validateSpecs(specs: readonly string[], errors: Push<Diagnostic>, disallowTrailingRecursion: boolean, jsonSourceFile: TsConfigSourceFile | undefined, specKey: string): readonly string[] {
3795+
function validateSpecs(specs: readonly string[], errors: Diagnostic[], disallowTrailingRecursion: boolean, jsonSourceFile: TsConfigSourceFile | undefined, specKey: string): readonly string[] {
37973796
return specs.filter(spec => {
37983797
if (!isString(spec)) return false;
37993798
const diag = specToDiagnostic(spec, disallowTrailingRecursion);

src/compiler/core.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
EqualityComparer,
88
isWhiteSpaceLike,
99
MapLike,
10-
Push,
1110
Queue,
1211
SortedArray,
1312
SortedReadonlyArray,
@@ -1001,14 +1000,13 @@ export function append<T>(to: T[] | undefined, value: T): T[];
10011000
/** @internal */
10021001
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined;
10031002
/** @internal */
1004-
export function append<T>(to: Push<T>, value: T | undefined): void;
1003+
export function append<T>(to: T[], value: T | undefined): void;
10051004
/** @internal */
1006-
export function append<T>(to: Push<T> | T[] | undefined, value: T | undefined): T[] | undefined {
1007-
// If to is Push<T>, return value is void, so safe to cast to T[].
1005+
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
10081006
if (value === undefined) return to as T[];
10091007
if (to === undefined) return [value];
10101008
to.push(value);
1011-
return to as T[];
1009+
return to;
10121010
}
10131011

10141012
/**
@@ -1883,12 +1881,6 @@ export function cast<TOut extends TIn, TIn = any>(value: TIn | undefined, test:
18831881
*/
18841882
export function noop(_?: unknown): void { }
18851883

1886-
/** @internal */
1887-
export const noopPush: Push<any> = {
1888-
push: noop,
1889-
length: 0
1890-
};
1891-
18921884
/**
18931885
* Do nothing and return false
18941886
*

src/compiler/corePublic.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ export interface Collection<K> extends ReadonlyCollection<K> {
4444
clear(): void;
4545
}
4646

47-
/**
48-
* Array that is only intended to be pushed to, never read.
49-
*
50-
* @internal
51-
*/
52-
export interface Push<T> {
53-
push(...values: T[]): void;
54-
readonly length: number;
55-
}
56-
5747
/** @internal */
5848
export type EqualityComparer<T> = (a: T, b: T) => boolean;
5949

src/compiler/factory/nodeFactory.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ import {
372372
pseudoBigIntToString,
373373
PunctuationSyntaxKind,
374374
PunctuationToken,
375-
Push,
376375
QualifiedName,
377376
QuestionDotToken,
378377
QuestionToken,
@@ -6439,7 +6438,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
64396438
return createGlobalMethodCall("Reflect", "set", receiver ? [target, propertyKey, value, receiver] : [target, propertyKey, value]);
64406439
}
64416440

6442-
function tryAddPropertyAssignment(properties: Push<PropertyAssignment>, propertyName: string, expression: Expression | undefined) {
6441+
function tryAddPropertyAssignment(properties: PropertyAssignment[], propertyName: string, expression: Expression | undefined) {
64436442
if (expression) {
64446443
properties.push(createPropertyAssignment(propertyName, expression));
64456444
return true;
@@ -6760,7 +6759,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
67606759
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
67616760
* @param visitor Optional callback used to visit any custom prologue directives.
67626761
*/
6763-
function copyPrologue(source: readonly Statement[], target: Push<Statement>, ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult<Node>): number {
6762+
function copyPrologue(source: readonly Statement[], target: Statement[], ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult<Node>): number {
67646763
const offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
67656764
return copyCustomPrologue(source, target, offset, visitor);
67666765
}
@@ -6781,7 +6780,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
67816780
* @param ensureUseStrict boolean determining whether the function need to add prologue-directives
67826781
* @returns Count of how many directive statements were copied.
67836782
*/
6784-
function copyStandardPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset = 0, ensureUseStrict?: boolean): number {
6783+
function copyStandardPrologue(source: readonly Statement[], target: Statement[], statementOffset = 0, ensureUseStrict?: boolean): number {
67856784
Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
67866785
let foundUseStrict = false;
67876786
const numStatements = source.length;
@@ -6811,9 +6810,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
68116810
* @param statementOffset The offset at which to begin the copy.
68126811
* @param visitor Optional callback used to visit any custom prologue directives.
68136812
*/
6814-
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number;
6815-
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number | undefined;
6816-
function copyCustomPrologue(source: readonly Statement[], target: Push<Statement>, statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter: (node: Statement) => boolean = returnTrue): number | undefined {
6813+
function copyCustomPrologue(source: readonly Statement[], target: Statement[], statementOffset: number, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number;
6814+
function copyCustomPrologue(source: readonly Statement[], target: Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter?: (node: Statement) => boolean): number | undefined;
6815+
function copyCustomPrologue(source: readonly Statement[], target: Statement[], statementOffset: number | undefined, visitor?: (node: Node) => VisitResult<Node>, filter: (node: Statement) => boolean = returnTrue): number | undefined {
68176816
const numStatements = source.length;
68186817
while (statementOffset !== undefined && statementOffset < numStatements) {
68196818
const statement = source[statementOffset];

src/compiler/moduleNameResolver.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import {
7272
moduleResolutionOptionDeclarations,
7373
moduleResolutionSupportsPackageJsonExportsAndImports,
7474
noop,
75-
noopPush,
7675
normalizePath,
7776
normalizeSlashes,
7877
PackageId,
@@ -82,7 +81,6 @@ import {
8281
Pattern,
8382
patternText,
8483
perfLogger,
85-
Push,
8684
readJson,
8785
removeExtension,
8886
removeFileExtension,
@@ -285,8 +283,8 @@ export interface ModuleResolutionState {
285283
host: ModuleResolutionHost;
286284
compilerOptions: CompilerOptions;
287285
traceEnabled: boolean;
288-
failedLookupLocations: Push<string>;
289-
affectingLocations: Push<string>;
286+
failedLookupLocations: string[] | undefined;
287+
affectingLocations: string[] | undefined;
290288
resultFromCache?: ResolvedModuleWithFailedLookupLocations;
291289
packageJsonInfoCache: PackageJsonInfoCache | undefined;
292290
features: NodeResolutionFeatures;
@@ -2045,7 +2043,7 @@ function tryFileLookup(fileName: string, onlyRecordFailures: boolean, state: Mod
20452043
}
20462044
}
20472045
}
2048-
state.failedLookupLocations.push(fileName);
2046+
state.failedLookupLocations?.push(fileName);
20492047
return undefined;
20502048
}
20512049

@@ -2171,8 +2169,8 @@ export function getTemporaryModuleResolutionState(packageJsonInfoCache: PackageJ
21712169
host,
21722170
compilerOptions: options,
21732171
traceEnabled: isTraceEnabled(options, host),
2174-
failedLookupLocations: noopPush,
2175-
affectingLocations: noopPush,
2172+
failedLookupLocations: undefined,
2173+
affectingLocations: undefined,
21762174
packageJsonInfoCache,
21772175
features: NodeResolutionFeatures.None,
21782176
conditions: emptyArray,
@@ -2227,22 +2225,22 @@ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures:
22272225
const { host, traceEnabled } = state;
22282226
const packageJsonPath = combinePaths(packageDirectory, "package.json");
22292227
if (onlyRecordFailures) {
2230-
state.failedLookupLocations.push(packageJsonPath);
2228+
state.failedLookupLocations?.push(packageJsonPath);
22312229
return undefined;
22322230
}
22332231

22342232
const existing = state.packageJsonInfoCache?.getPackageJsonInfo(packageJsonPath);
22352233
if (existing !== undefined) {
22362234
if (typeof existing !== "boolean") {
22372235
if (traceEnabled) trace(host, Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath);
2238-
state.affectingLocations.push(packageJsonPath);
2236+
state.affectingLocations?.push(packageJsonPath);
22392237
return existing.packageDirectory === packageDirectory ?
22402238
existing :
22412239
{ packageDirectory, contents: existing.contents };
22422240
}
22432241
else {
22442242
if (existing && traceEnabled) trace(host, Diagnostics.File_0_does_not_exist_according_to_earlier_cached_lookups, packageJsonPath);
2245-
state.failedLookupLocations.push(packageJsonPath);
2243+
state.failedLookupLocations?.push(packageJsonPath);
22462244
return undefined;
22472245
}
22482246
}
@@ -2254,7 +2252,7 @@ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures:
22542252
}
22552253
const result: PackageJsonInfo = { packageDirectory, contents: { packageJsonContent, versionPaths: undefined, resolvedEntrypoints: undefined } };
22562254
state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, result);
2257-
state.affectingLocations.push(packageJsonPath);
2255+
state.affectingLocations?.push(packageJsonPath);
22582256
return result;
22592257
}
22602258
else {
@@ -2263,7 +2261,7 @@ export function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures:
22632261
}
22642262
state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, directoryExists);
22652263
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
2266-
state.failedLookupLocations.push(packageJsonPath);
2264+
state.failedLookupLocations?.push(packageJsonPath);
22672265
}
22682266
}
22692267

0 commit comments

Comments
 (0)