From 43679d241f117cfd04bdf631d4d33be9e6c9e3a0 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Thu, 26 Sep 2019 16:04:39 -0700 Subject: [PATCH] Add tests --- tests/baselines/reference/arrayConcat2.js | 29 +++++++++ .../baselines/reference/arrayConcat2.symbols | 42 ++++++++++++ tests/baselines/reference/arrayConcat2.types | 65 ++++++++++++++++++- tests/baselines/reference/arrayFlat.js | 15 +++++ tests/baselines/reference/arrayFlat.symbols | 20 ++++++ tests/baselines/reference/arrayFlat.types | 31 +++++++++ tests/baselines/reference/arrayFlatMap.js | 10 +++ .../baselines/reference/arrayFlatMap.symbols | 16 +++++ tests/baselines/reference/arrayFlatMap.types | 22 +++++++ tests/cases/compiler/arrayConcat2.ts | 19 ++++++ tests/cases/compiler/arrayFlat.ts | 8 +++ tests/cases/compiler/arrayFlatMap.ts | 6 ++ 12 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/arrayFlat.js create mode 100644 tests/baselines/reference/arrayFlat.symbols create mode 100644 tests/baselines/reference/arrayFlat.types create mode 100644 tests/cases/compiler/arrayFlat.ts diff --git a/tests/baselines/reference/arrayConcat2.js b/tests/baselines/reference/arrayConcat2.js index 8db2d62e1d357..f99bac7d524dc 100644 --- a/tests/baselines/reference/arrayConcat2.js +++ b/tests/baselines/reference/arrayConcat2.js @@ -6,6 +6,24 @@ a.concat('Hello'); var b = new Array(); b.concat('hello'); + +const expected1: undefined = undefined as Flatten; + +// #19535 + +let [actual2] = (undefined as unknown as string[][]).concat([""]); +const expected2: string | string[] = actual2; +actual2 = undefined as unknown as string | string[]; + +// #26378 + +let [actual3] = [""].concat([1]); +const expected3: string | number = actual3; +actual3 = undefined as unknown as string | number; + +// #26976 + +[].concat([""]); //// [arrayConcat2.js] @@ -14,3 +32,14 @@ a.concat("hello", 'world'); a.concat('Hello'); var b = new Array(); b.concat('hello'); +var expected1 = undefined; +// #19535 +var actual2 = undefined.concat([""])[0]; +var expected2 = actual2; +actual2 = undefined; +// #26378 +var actual3 = [""].concat([1])[0]; +var expected3 = actual3; +actual3 = undefined; +// #26976 +[].concat([""]); diff --git a/tests/baselines/reference/arrayConcat2.symbols b/tests/baselines/reference/arrayConcat2.symbols index 7da42f6dfcb5e..32ab6b979c35b 100644 --- a/tests/baselines/reference/arrayConcat2.symbols +++ b/tests/baselines/reference/arrayConcat2.symbols @@ -21,3 +21,45 @@ b.concat('hello'); >b : Symbol(b, Decl(arrayConcat2.ts, 5, 3)) >concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +const expected1: undefined = undefined as Flatten; +>expected1 : Symbol(expected1, Decl(arrayConcat2.ts, 8, 5)) +>undefined : Symbol(undefined) +>Flatten : Symbol(Flatten, Decl(lib.es5.d.ts, --, --)) + +// #19535 + +let [actual2] = (undefined as unknown as string[][]).concat([""]); +>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5)) +>(undefined as unknown as string[][]).concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>undefined : Symbol(undefined) +>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +const expected2: string | string[] = actual2; +>expected2 : Symbol(expected2, Decl(arrayConcat2.ts, 13, 5)) +>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5)) + +actual2 = undefined as unknown as string | string[]; +>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5)) +>undefined : Symbol(undefined) + +// #26378 + +let [actual3] = [""].concat([1]); +>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5)) +>[""].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +const expected3: string | number = actual3; +>expected3 : Symbol(expected3, Decl(arrayConcat2.ts, 19, 5)) +>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5)) + +actual3 = undefined as unknown as string | number; +>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5)) +>undefined : Symbol(undefined) + +// #26976 + +[].concat([""]); +>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/arrayConcat2.types b/tests/baselines/reference/arrayConcat2.types index cc52bf3b513d4..aec5044070b14 100644 --- a/tests/baselines/reference/arrayConcat2.types +++ b/tests/baselines/reference/arrayConcat2.types @@ -1,7 +1,7 @@ === tests/cases/compiler/arrayConcat2.ts === var a: string[] = []; >a : string[] ->[] : undefined[] +>[] : never[] a.concat("hello", 'world'); >a.concat("hello", 'world') : string[] @@ -30,3 +30,66 @@ b.concat('hello'); >concat : { (...items: ConcatArray[]): string[]; (...items: U): (string | Flatten)[]; } >'hello' : "hello" +const expected1: undefined = undefined as Flatten; +>expected1 : undefined +>undefined as Flatten : undefined +>undefined : undefined + +// #19535 + +let [actual2] = (undefined as unknown as string[][]).concat([""]); +>actual2 : string | string[] +>(undefined as unknown as string[][]).concat([""]) : (string | string[])[] +>(undefined as unknown as string[][]).concat : { (...items: ConcatArray[]): string[][]; (...items: U): (string[] | Flatten)[]; } +>(undefined as unknown as string[][]) : string[][] +>undefined as unknown as string[][] : string[][] +>undefined as unknown : unknown +>undefined : undefined +>concat : { (...items: ConcatArray[]): string[][]; (...items: U): (string[] | Flatten)[]; } +>[""] : string[] +>"" : "" + +const expected2: string | string[] = actual2; +>expected2 : string | string[] +>actual2 : string | string[] + +actual2 = undefined as unknown as string | string[]; +>actual2 = undefined as unknown as string | string[] : string | string[] +>actual2 : string | string[] +>undefined as unknown as string | string[] : string | string[] +>undefined as unknown : unknown +>undefined : undefined + +// #26378 + +let [actual3] = [""].concat([1]); +>actual3 : string | number +>[""].concat([1]) : (string | number)[] +>[""].concat : { (...items: ConcatArray[]): string[]; (...items: U): (string | Flatten)[]; } +>[""] : string[] +>"" : "" +>concat : { (...items: ConcatArray[]): string[]; (...items: U): (string | Flatten)[]; } +>[1] : number[] +>1 : 1 + +const expected3: string | number = actual3; +>expected3 : string | number +>actual3 : string | number + +actual3 = undefined as unknown as string | number; +>actual3 = undefined as unknown as string | number : string | number +>actual3 : string | number +>undefined as unknown as string | number : string | number +>undefined as unknown : unknown +>undefined : undefined + +// #26976 + +[].concat([""]); +>[].concat([""]) : string[] +>[].concat : { (...items: ConcatArray[]): never[]; (...items: U): Flatten[]; } +>[] : never[] +>concat : { (...items: ConcatArray[]): never[]; (...items: U): Flatten[]; } +>[""] : string[] +>"" : "" + diff --git a/tests/baselines/reference/arrayFlat.js b/tests/baselines/reference/arrayFlat.js new file mode 100644 index 0000000000000..c10760083c90d --- /dev/null +++ b/tests/baselines/reference/arrayFlat.js @@ -0,0 +1,15 @@ +//// [arrayFlat.ts] +// #24579 and #29604 + +let [actual] = [[""], [1]].flat(); +const expected: string | number = actual; +actual = undefined as string | number; +const f: any extends typeof actual ? true : false = false; + + +//// [arrayFlat.js] +// #24579 and #29604 +var actual = [[""], [1]].flat()[0]; +var expected = actual; +actual = undefined; +var f = false; diff --git a/tests/baselines/reference/arrayFlat.symbols b/tests/baselines/reference/arrayFlat.symbols new file mode 100644 index 0000000000000..4442a3a468798 --- /dev/null +++ b/tests/baselines/reference/arrayFlat.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/arrayFlat.ts === +// #24579 and #29604 + +let [actual] = [[""], [1]].flat(); +>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5)) +>[[""], [1]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more) +>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more) + +const expected: string | number = actual; +>expected : Symbol(expected, Decl(arrayFlat.ts, 3, 5)) +>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5)) + +actual = undefined as string | number; +>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5)) +>undefined : Symbol(undefined) + +const f: any extends typeof actual ? true : false = false; +>f : Symbol(f, Decl(arrayFlat.ts, 5, 5)) +>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5)) + diff --git a/tests/baselines/reference/arrayFlat.types b/tests/baselines/reference/arrayFlat.types new file mode 100644 index 0000000000000..c7349cc1e2836 --- /dev/null +++ b/tests/baselines/reference/arrayFlat.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/arrayFlat.ts === +// #24579 and #29604 + +let [actual] = [[""], [1]].flat(); +>actual : string | number +>[[""], [1]].flat() : (string | number)[] +>[[""], [1]].flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string[] | number[])[] | (string | number)[]; } +>[[""], [1]] : (string[] | number[])[] +>[""] : string[] +>"" : "" +>[1] : number[] +>1 : 1 +>flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string[] | number[])[] | (string | number)[]; } + +const expected: string | number = actual; +>expected : string | number +>actual : string | number + +actual = undefined as string | number; +>actual = undefined as string | number : string | number +>actual : string | number +>undefined as string | number : string | number +>undefined : undefined + +const f: any extends typeof actual ? true : false = false; +>f : boolean +>actual : string | number +>true : true +>false : false +>false : false + diff --git a/tests/baselines/reference/arrayFlatMap.js b/tests/baselines/reference/arrayFlatMap.js index 3c35cedc1f3be..fcff1c9ed3ce3 100644 --- a/tests/baselines/reference/arrayFlatMap.js +++ b/tests/baselines/reference/arrayFlatMap.js @@ -3,6 +3,12 @@ const array: number[] = []; const readonlyArray: ReadonlyArray = []; array.flatMap((): ReadonlyArray => []); // ok readonlyArray.flatMap((): ReadonlyArray => []); // ok + +// #19535 + +let [actual] = [""].flatMap(undefined as () => string[] | string[][]); +const expected: string | string[] = actual; +actual = undefined as string | string[]; //// [arrayFlatMap.js] @@ -10,3 +16,7 @@ var array = []; var readonlyArray = []; array.flatMap(function () { return []; }); // ok readonlyArray.flatMap(function () { return []; }); // ok +// #19535 +var actual = [""].flatMap(undefined)[0]; +var expected = actual; +actual = undefined; diff --git a/tests/baselines/reference/arrayFlatMap.symbols b/tests/baselines/reference/arrayFlatMap.symbols index b3a8d55721acd..c520e68ed0f50 100644 --- a/tests/baselines/reference/arrayFlatMap.symbols +++ b/tests/baselines/reference/arrayFlatMap.symbols @@ -18,3 +18,19 @@ readonlyArray.flatMap((): ReadonlyArray => []); // ok >flatMap : Symbol(ReadonlyArray.flatMap, Decl(lib.es2019.array.d.ts, --, --)) >ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --)) +// #19535 + +let [actual] = [""].flatMap(undefined as () => string[] | string[][]); +>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5)) +>[""].flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --)) +>flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --)) +>undefined : Symbol(undefined) + +const expected: string | string[] = actual; +>expected : Symbol(expected, Decl(arrayFlatMap.ts, 8, 5)) +>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5)) + +actual = undefined as string | string[]; +>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/arrayFlatMap.types b/tests/baselines/reference/arrayFlatMap.types index 0f812b1820d94..80f786a57c0ab 100644 --- a/tests/baselines/reference/arrayFlatMap.types +++ b/tests/baselines/reference/arrayFlatMap.types @@ -23,3 +23,25 @@ readonlyArray.flatMap((): ReadonlyArray => []); // ok >(): ReadonlyArray => [] : () => readonly number[] >[] : undefined[] +// #19535 + +let [actual] = [""].flatMap(undefined as () => string[] | string[][]); +>actual : string | string[] +>[""].flatMap(undefined as () => string[] | string[][]) : (string | string[])[] +>[""].flatMap : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => Flatten[] +>[""] : string[] +>"" : "" +>flatMap : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => Flatten[] +>undefined as () => string[] | string[][] : () => string[] | string[][] +>undefined : undefined + +const expected: string | string[] = actual; +>expected : string | string[] +>actual : string | string[] + +actual = undefined as string | string[]; +>actual = undefined as string | string[] : string | string[] +>actual : string | string[] +>undefined as string | string[] : string | string[] +>undefined : undefined + diff --git a/tests/cases/compiler/arrayConcat2.ts b/tests/cases/compiler/arrayConcat2.ts index e69730a63a37c..e3cbd6318c24d 100644 --- a/tests/cases/compiler/arrayConcat2.ts +++ b/tests/cases/compiler/arrayConcat2.ts @@ -5,3 +5,22 @@ a.concat('Hello'); var b = new Array(); b.concat('hello'); + +const expected1: undefined = undefined as Flatten; + +// #19535 + +let [actual2] = (undefined as unknown as string[][]).concat([""]); +const expected2: string | string[] = actual2; +actual2 = undefined as unknown as string | string[]; + +// #26378 + +let [actual3] = [""].concat([1]); +const expected3: string | number = actual3; +actual3 = undefined as unknown as string | number; + +// #26976 + +// @strictNullChecks: true +[].concat([""]); diff --git a/tests/cases/compiler/arrayFlat.ts b/tests/cases/compiler/arrayFlat.ts new file mode 100644 index 0000000000000..38bb821e6429c --- /dev/null +++ b/tests/cases/compiler/arrayFlat.ts @@ -0,0 +1,8 @@ +// @lib: es2019 + +// #24579 and #29604 + +let [actual] = [[""], [1]].flat(); +const expected: string | number = actual; +actual = undefined as string | number; +const f: any extends typeof actual ? true : false = false; diff --git a/tests/cases/compiler/arrayFlatMap.ts b/tests/cases/compiler/arrayFlatMap.ts index 98f84e7877363..60a2fef1cc447 100644 --- a/tests/cases/compiler/arrayFlatMap.ts +++ b/tests/cases/compiler/arrayFlatMap.ts @@ -4,3 +4,9 @@ const array: number[] = []; const readonlyArray: ReadonlyArray = []; array.flatMap((): ReadonlyArray => []); // ok readonlyArray.flatMap((): ReadonlyArray => []); // ok + +// #19535 + +let [actual] = [""].flatMap(undefined as () => string[] | string[][]); +const expected: string | string[] = actual; +actual = undefined as string | string[];