diff --git a/tests/baselines/reference/bestChoiceType.js b/tests/baselines/reference/bestChoiceType.js new file mode 100644 index 00000000000..0c1bf5df2d4 --- /dev/null +++ b/tests/baselines/reference/bestChoiceType.js @@ -0,0 +1,35 @@ +//// [bestChoiceType.ts] + +// Repro from #10041 + +(''.match(/ /) || []).map(s => s.toLowerCase()); + +// Similar cases + +function f1() { + let x = ''.match(/ /); + let y = x || []; + let z = y.map(s => s.toLowerCase()); +} + +function f2() { + let x = ''.match(/ /); + let y = x ? x : []; + let z = y.map(s => s.toLowerCase()); +} + + +//// [bestChoiceType.js] +// Repro from #10041 +(''.match(/ /) || []).map(function (s) { return s.toLowerCase(); }); +// Similar cases +function f1() { + var x = ''.match(/ /); + var y = x || []; + var z = y.map(function (s) { return s.toLowerCase(); }); +} +function f2() { + var x = ''.match(/ /); + var y = x ? x : []; + var z = y.map(function (s) { return s.toLowerCase(); }); +} diff --git a/tests/baselines/reference/bestChoiceType.symbols b/tests/baselines/reference/bestChoiceType.symbols new file mode 100644 index 00000000000..25f7de2eeda --- /dev/null +++ b/tests/baselines/reference/bestChoiceType.symbols @@ -0,0 +1,63 @@ +=== tests/cases/compiler/bestChoiceType.ts === + +// Repro from #10041 + +(''.match(/ /) || []).map(s => s.toLowerCase()); +>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26)) +>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + +// Similar cases + +function f1() { +>f1 : Symbol(f1, Decl(bestChoiceType.ts, 3, 48)) + + let x = ''.match(/ /); +>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7)) +>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + let y = x || []; +>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7)) +>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7)) + + let z = y.map(s => s.toLowerCase()); +>z : Symbol(z, Decl(bestChoiceType.ts, 10, 7)) +>y.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>s : Symbol(s, Decl(bestChoiceType.ts, 10, 18)) +>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>s : Symbol(s, Decl(bestChoiceType.ts, 10, 18)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +} + +function f2() { +>f2 : Symbol(f2, Decl(bestChoiceType.ts, 11, 1)) + + let x = ''.match(/ /); +>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7)) +>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + let y = x ? x : []; +>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7)) +>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7)) +>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7)) + + let z = y.map(s => s.toLowerCase()); +>z : Symbol(z, Decl(bestChoiceType.ts, 16, 7)) +>y.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>s : Symbol(s, Decl(bestChoiceType.ts, 16, 18)) +>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>s : Symbol(s, Decl(bestChoiceType.ts, 16, 18)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +} + diff --git a/tests/baselines/reference/bestChoiceType.types b/tests/baselines/reference/bestChoiceType.types new file mode 100644 index 00000000000..f88cf64e5a2 --- /dev/null +++ b/tests/baselines/reference/bestChoiceType.types @@ -0,0 +1,88 @@ +=== tests/cases/compiler/bestChoiceType.ts === + +// Repro from #10041 + +(''.match(/ /) || []).map(s => s.toLowerCase()); +>(''.match(/ /) || []).map(s => s.toLowerCase()) : string[] +>(''.match(/ /) || []).map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>(''.match(/ /) || []) : RegExpMatchArray +>''.match(/ /) || [] : RegExpMatchArray +>''.match(/ /) : RegExpMatchArray | null +>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; } +>'' : string +>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; } +>/ / : RegExp +>[] : never[] +>map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>s => s.toLowerCase() : (s: string) => string +>s : string +>s.toLowerCase() : string +>s.toLowerCase : () => string +>s : string +>toLowerCase : () => string + +// Similar cases + +function f1() { +>f1 : () => void + + let x = ''.match(/ /); +>x : RegExpMatchArray | null +>''.match(/ /) : RegExpMatchArray | null +>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; } +>'' : string +>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; } +>/ / : RegExp + + let y = x || []; +>y : RegExpMatchArray +>x || [] : RegExpMatchArray +>x : RegExpMatchArray | null +>[] : never[] + + let z = y.map(s => s.toLowerCase()); +>z : string[] +>y.map(s => s.toLowerCase()) : string[] +>y.map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>y : RegExpMatchArray +>map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>s => s.toLowerCase() : (s: string) => string +>s : string +>s.toLowerCase() : string +>s.toLowerCase : () => string +>s : string +>toLowerCase : () => string +} + +function f2() { +>f2 : () => void + + let x = ''.match(/ /); +>x : RegExpMatchArray | null +>''.match(/ /) : RegExpMatchArray | null +>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; } +>'' : string +>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; } +>/ / : RegExp + + let y = x ? x : []; +>y : RegExpMatchArray +>x ? x : [] : RegExpMatchArray +>x : RegExpMatchArray | null +>x : RegExpMatchArray +>[] : never[] + + let z = y.map(s => s.toLowerCase()); +>z : string[] +>y.map(s => s.toLowerCase()) : string[] +>y.map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>y : RegExpMatchArray +>map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>s => s.toLowerCase() : (s: string) => string +>s : string +>s.toLowerCase() : string +>s.toLowerCase : () => string +>s : string +>toLowerCase : () => string +} +