@@ -3,40 +3,50 @@ import * as util from "../util";
33
44const allBindings = "x, y, z, rest" ;
55const testCases = [
6- { binding : "{ x }" , value : { x : true } } ,
7- { binding : "{ x, y }" , value : { x : false , y : true } } ,
8- { binding : "{ x: z, y }" , value : { x : true , y : false } } ,
9- { binding : "{ x: { x, y }, z }" , value : { x : { x : true , y : false } , z : false } } ,
10- { binding : "{ x, y = true }" , value : { x : false , y : false } } ,
11- { binding : "{ x = true }" , value : { } } ,
12- { binding : "{ x, y = true }" , value : { x : false } } ,
13- { binding : "{ ...rest }" , value : { } } ,
14- { binding : "{ x, ...rest }" , value : { x : "x" } } ,
15- { binding : "{ x, ...rest }" , value : { x : "x" , y : "y" , z : "z" } } ,
16- { binding : "{ x, ...y }" , value : { x : "x" , y : "y" , z : "z" } } ,
17- { binding : "{ x: y, ...z }" , value : { x : "x" , y : "y" , z : "z" } } ,
18-
19- { binding : "[]" , value : [ ] } ,
20- { binding : "[x, y]" , value : [ "x" , "y" ] } ,
21- { binding : "[x, , y]" , value : [ "x" , "" , "y" ] } ,
22- { binding : "[x = true]" , value : [ false ] } ,
23- { binding : "[[x, y]]" , value : [ [ "x" , "y" ] ] } ,
24- { binding : "[x, ...rest]" , value : [ "x" ] } ,
25- { binding : "[x, ...rest]" , value : [ "x" , "y" , "z" ] } ,
26-
27- { binding : "{ y: [z = true] }" , value : { y : [ false ] } } ,
28- { binding : "{ x: [x, y] }" , value : { x : [ "x" , "y" ] } } ,
29- { binding : "{ x: [{ y }] }" , value : { x : [ { y : "y" } ] } } ,
30- ] . map ( ( { binding, value } ) => ( { binding, value : util . formatCode ( value ) } ) ) ;
6+ { binding : "{ x }" , type : "{ x: boolean }" , value : { x : true } } ,
7+ { binding : "{ x, y }" , type : "{ x: boolean, y: boolean }" , value : { x : false , y : true } } ,
8+ { binding : "{ x: z, y }" , type : "{ x: boolean, y?: boolean, z?: boolean }" , value : { x : true , y : false } } ,
9+ {
10+ binding : "{ x: { x, y }, z }" ,
11+ type : "{ x: { x: boolean, y: boolean }, z: boolean }" ,
12+ value : { x : { x : true , y : false } , z : false } ,
13+ } ,
14+ { binding : "{ x, y = true }" , type : "{ x: boolean, y?: boolean }" , value : { x : false , y : false } } ,
15+ { binding : "{ x = true }" , type : "{ x?: boolean }" , value : { } } ,
16+ { binding : "{ x, y = true }" , type : "{ x: boolean, y?: boolean }" , value : { x : false } } ,
17+ { binding : "{ ...rest }" , type : "any" , value : { } } ,
18+ { binding : "{ x, ...rest }" , type : "any" , value : { x : "x" } } ,
19+ { binding : "{ x, ...rest }" , type : "any" , value : { x : "x" , y : "y" , z : "z" } } ,
20+ { binding : "{ x, ...y }" , type : "any" , value : { x : "x" , y : "y" , z : "z" } } ,
21+ { binding : "{ x: y, ...z }" , type : "any" , value : { x : "x" , y : "y" , z : "z" } } ,
22+
23+ { binding : "[]" , type : "boolean[]" , value : [ ] } ,
24+ { binding : "[x, y]" , type : "[string, string]" , value : [ "x" , "y" ] } ,
25+ { binding : "[x, , y]" , type : "string[]" , value : [ "x" , "" , "y" ] } ,
26+ { binding : "[x = true]" , type : "boolean[]" , value : [ false ] } ,
27+ { binding : "[x = true]" , type : "boolean[]" , value : [ ] } ,
28+ { binding : "[[x, y]]" , type : "Array<string[]>" , value : [ [ "x" , "y" ] ] } ,
29+ { binding : "[x, ...rest]" , type : "string[]" , value : [ "x" ] } ,
30+ { binding : "[x, ...rest]" , type : "string[]" , value : [ "x" , "y" , "z" ] } ,
31+
32+ { binding : "{ y: [z = true] }" , type : "{ y: boolean[] }" , value : { y : [ false ] } } ,
33+ { binding : "{ y: [z = true] }" , type : "{ y: boolean[] }" , value : { y : [ ] } } ,
34+ { binding : "{ x: [x, y] }" , type : "{ x: [string, string] }" , value : { x : [ "x" , "y" ] } } ,
35+ { binding : "{ x: [{ y }] }" , type : "{ x: [{ y: string }] }" , value : { x : [ { y : "y" } ] } } ,
36+ ] . map ( ( { binding, type, value } ) => ( { binding, type, value : util . formatCode ( value ) } ) ) ;
3137
3238test . each ( [
3339 ...testCases ,
34- { binding : "{ x, y }, z" , value : "{ x: false, y: false }, true" } ,
35- { binding : "{ x, y }, { z }" , value : "{ x: false, y: false }, { z: true }" } ,
36- ] ) ( "in function parameter (%p)" , ( { binding, value } ) => {
40+ { binding : "{ x, y }" , type : "{ x: boolean, y: boolean }, z: boolean" , value : "{ x: false, y: false }, true" } ,
41+ {
42+ binding : "{ x, y }" ,
43+ type : "{ x: boolean, y: boolean }, { z }: { z: boolean }" ,
44+ value : "{ x: false, y: false }, { z: true }" ,
45+ } ,
46+ ] ) ( "in function parameter (%p)" , ( { binding, type, value } ) => {
3747 util . testFunction `
3848 let ${ allBindings } ;
39- function test(${ binding } ) {
49+ function test(${ binding } : ${ type } ) {
4050 return { ${ allBindings } };
4151 }
4252
0 commit comments