Skip to content

Commit

Permalink
Cherry pick PR 57887 into release-5.4 (#57898)
Browse files Browse the repository at this point in the history
Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
  • Loading branch information
jakebailey and weswigham authored Mar 28, 2024
1 parent 896947e commit 3caec2c
Show file tree
Hide file tree
Showing 160 changed files with 494 additions and 384 deletions.
18 changes: 13 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6306,7 +6306,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult {
function getMeaningOfEntityNameReference(entityName: EntityNameOrEntityNameExpression): SymbolFlags {
// get symbol of the first identifier of the entityName
let meaning: SymbolFlags;
if (
Expand All @@ -6319,7 +6319,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
else if (
entityName.kind === SyntaxKind.QualifiedName || entityName.kind === SyntaxKind.PropertyAccessExpression ||
entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration
entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ||
(entityName.parent.kind === SyntaxKind.QualifiedName && (entityName.parent as QualifiedName).left === entityName) ||
(entityName.parent.kind === SyntaxKind.PropertyAccessExpression && (entityName.parent as PropertyAccessExpression).expression === entityName) ||
(entityName.parent.kind === SyntaxKind.ElementAccessExpression && (entityName.parent as ElementAccessExpression).expression === entityName)
) {
// Left identifier from type reference or TypeAlias
// Entity name of the import declaration
Expand All @@ -6329,7 +6332,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Type Reference or TypeAlias entity = Identifier
meaning = SymbolFlags.Type;
}
return meaning;
}

function isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult {
const meaning = getMeaningOfEntityNameReference(entityName);
const firstIdentifier = getFirstIdentifier(entityName);
const symbol = resolveName(enclosingDeclaration, firstIdentifier.escapedText, meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
if (symbol && symbol.flags & SymbolFlags.TypeParameter && meaning & SymbolFlags.Type) {
Expand Down Expand Up @@ -8512,13 +8519,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
introducesError = true;
return { introducesError, node };
}
const sym = resolveEntityName(leftmost, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
const meaning = getMeaningOfEntityNameReference(node);
const sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
if (sym) {
if (isSymbolAccessible(sym, context.enclosingDeclaration, SymbolFlags.All, /*shouldComputeAliasesToMakeVisible*/ false).accessibility !== SymbolAccessibility.Accessible) {
if (isSymbolAccessible(sym, context.enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ false).accessibility !== SymbolAccessibility.Accessible) {
introducesError = true;
}
else {
context.tracker.trackSymbol(sym, context.enclosingDeclaration, SymbolFlags.All);
context.tracker.trackSymbol(sym, context.enclosingDeclaration, meaning);
includePrivateSymbol?.(sym);
}
if (isIdentifier(node)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ParameterList5.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

=== ParameterList5.ts ===
function A(): (public B) => C {
>A : () => (B: any) => C
>A : () => (public B) => C
>B : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// from webpack/lib/Compilation.js and filed at #26427
/** @param {{ [s: string]: number }} map */
function mappy(map) {}
>mappy : (map: { [s: string]: number; }) => void
>mappy : (map: { [s: string]: number;}) => void
>map : { [s: string]: number; }

export class C {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/anonterface.types
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module M {
>C : C

m(fn:{ (n:number):string; },n2:number):string {
>m : (fn: (n: number) => string, n2: number) => string
>m : (fn: { (n: number): string;}, n2: number) => string
>fn : (n: number) => string
>n : number
>n2 : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var r3 = foo3(a); // any
>a : any

declare function foo12(x: (x) => number): (x) => number;
>foo12 : { (x: (x: any) => number): (x: any) => number; (x: any): any; }
>foo12 : { (x: (x) => number): (x) => number; (x: any): any; }
>x : (x: any) => number
>x : any
>x : any
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/arrayLiteralContextualType.types
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function foo(animals: IAnimal[]) { }
>animals : IAnimal[]

function bar(animals: { [n: number]: IAnimal }) { }
>bar : (animals: { [n: number]: IAnimal; }) => void
>bar : (animals: { [n: number]: IAnimal;}) => void
>animals : { [n: number]: IAnimal; }
>n : number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var a17: {

};
var a18: {
>a18 : { (x: { (a: number): number; (a: string): string; }): any[]; (x: { (a: boolean): boolean; (a: Date): Date; }): any[]; }
>a18 : { (x: { (a: number): number; (a: string): string;}): any[]; (x: { (a: boolean): boolean; (a: Date): Date;}): any[]; }

(x: {
>x : { (a: number): number; (a: string): string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Errors {
>b : number

var a16: {
>a16 : { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }
>a16 : { (x: { (a: number): number; (a?: number): number;}): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean;}): boolean[]; }

(x: {
>x : { (a: number): number; (a?: number): number; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var a17: {

};
var a18: {
>a18 : { new (x: { new (a: number): number; new (a: string): string; }): any[]; new (x: { new (a: boolean): boolean; new (a: Date): Date; }): any[]; }
>a18 : { new (x: { new (a: number): number; new (a: string): string;}): any[]; new (x: { new (a: boolean): boolean; new (a: Date): Date;}): any[]; }

new (x: {
>x : { new (a: number): number; new (a: string): string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Errors {
>b : number

var a16: {
>a16 : { new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }
>a16 : { new (x: { new (a: number): number; new (a?: number): number;}): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean;}): boolean[]; }

new (x: {
>x : { new (a: number): number; new (a?: number): number; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ h(async v => v ? (def) => { } : Promise.reject());

// repro from #29196
const increment: (
>increment : (num: number, str: string) => string | Promise<string | ((s: string) => any)>
>increment : (num: number, str: string) => Promise<((s: string) => any) | string> | string

num: number,
>num : number
Expand All @@ -130,7 +130,7 @@ const increment: (
}

const increment2: (
>increment2 : (num: number, str: string) => Promise<string | ((s: string) => any)>
>increment2 : (num: number, str: string) => Promise<((s: string) => any) | string>

num: number,
>num : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
declare namespace Windows.Foundation {
interface IPromise<TResult> {
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
>then : { <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => U_1) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>then : { <U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => U_1) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>success : ((value: TResult) => IPromise<U>) | undefined
>value : TResult
>error : ((error: any) => IPromise<U>) | undefined
Expand All @@ -13,7 +13,7 @@ declare namespace Windows.Foundation {
>progress : any

then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>success : ((value: TResult) => IPromise<U>) | undefined
>value : TResult
>error : ((error: any) => U) | undefined
Expand All @@ -22,7 +22,7 @@ declare namespace Windows.Foundation {
>progress : any

then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>success : ((value: TResult) => U) | undefined
>value : TResult
>error : ((error: any) => IPromise<U>) | undefined
Expand All @@ -31,7 +31,7 @@ declare namespace Windows.Foundation {
>progress : any

then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => IPromise<U_3>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; }
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => IPromise<U_3>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; <U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; }
>success : ((value: TResult) => U) | undefined
>value : TResult
>error : ((error: any) => U) | undefined
Expand All @@ -40,7 +40,7 @@ declare namespace Windows.Foundation {
>progress : any

done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;
>done : <U>(success?: ((value: TResult) => any) | undefined, error?: ((error: any) => any) | undefined, progress?: ((progress: any) => void) | undefined) => void
>done : <U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void) => void
>success : ((value: TResult) => any) | undefined
>value : TResult
>error : ((error: any) => any) | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare const foo: ["a", string, number] | ["b", string, boolean];
>foo : ["a", string, number] | ["b", string, boolean]

export function test(arg: { index?: number }) {
>test : (arg: { index?: number | undefined; }) => void
>test : (arg: { index?: number;}) => void
>arg : { index?: number | undefined; }
>index : number | undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ interface A { // T

};
a18: {
>a18 : { (x: { (a: number): number; (a: string): string; }): any[]; (x: { (a: boolean): boolean; (a: Date): Date; }): any[]; }
>a18 : { (x: { (a: number): number; (a: string): string;}): any[]; (x: { (a: boolean): boolean; (a: Date): Date;}): any[]; }

(x: {
>x : { (a: number): number; (a: string): string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Errors {
>b : number

a16: {
>a16 : { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }
>a16 : { (x: { (a: number): number; (a?: number): number;}): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean;}): boolean[]; }

// type of parameter is overload set which means we can't do inference based on this type
(x: {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/callsOnComplexSignatures.types
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ function test2() {

interface Messages {
readonly foo: (options: { [key: string]: any, b: number }) => string;
>foo : (options: { [key: string]: any; b: number; }) => string
>foo : (options: { [key: string]: any; b: number;}) => string
>options : { [key: string]: any; b: number; }
>key : string
>b : number

readonly bar: (options: { [key: string]: any, a: string }) => string;
>bar : (options: { [key: string]: any; a: string; }) => string
>bar : (options: { [key: string]: any; a: string;}) => string
>options : { [key: string]: any; a: string; }
>key : string
>a : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/collisionArgumentsInType.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var v12: (arguments: number, ...restParameters) => void; // no error - no code g
>restParameters : any[]

var v2: {
>v2 : { (arguments: number, ...restParameters: any[]): any; new (arguments: number, ...restParameters: any[]): any; foo(arguments: number, ...restParameters: any[]): any; prop: (arguments: number, ...restParameters: any[]) => void; }
>v2 : { (arguments: number, ...restParameters: any[]): any; new (arguments: number, ...restParameters: any[]): any; foo(arguments: number, ...restParameters: any[]): any; prop: (arguments: number, ...restParameters) => void; }

(arguments: number, ...restParameters); // no error - no code gen
>arguments : number
Expand All @@ -33,7 +33,7 @@ var v2: {
>restParameters : any[]
}
var v21: {
>v21 : { (i: number, ...arguments: any[]): any; new (i: number, ...arguments: any[]): any; foo(i: number, ...arguments: any[]): any; prop: (i: number, ...arguments: any[]) => void; }
>v21 : { (i: number, ...arguments: any[]): any; new (i: number, ...arguments: any[]): any; foo(i: number, ...arguments: any[]): any; prop: (i: number, ...arguments) => void; }

(i: number, ...arguments); // no error - no code gen
>i : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var v1: (_i: number, ...restParameters) => void; // no error - no code gen
>restParameters : any[]

var v2: {
>v2 : { (_i: number, ...restParameters: any[]): any; new (_i: number, ...restParameters: any[]): any; foo(_i: number, ...restParameters: any[]): any; prop: (_i: number, ...restParameters: any[]) => void; }
>v2 : { (_i: number, ...restParameters: any[]): any; new (_i: number, ...restParameters: any[]): any; foo(_i: number, ...restParameters: any[]): any; prop: (_i: number, ...restParameters) => void; }

(_i: number, ...restParameters); // no error - no code gen
>_i : number
Expand Down
Loading

0 comments on commit 3caec2c

Please sign in to comment.