From b65bbfd42dbe25ea790fb81f4922a3acc55be152 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Thu, 26 Jul 2018 14:37:52 +0200 Subject: [PATCH 1/2] correctly resolve Symbol of destructuring shorthand intializer Fixes: #21046 --- src/compiler/utilities.ts | 2 ++ .../reference/assignmentTypeNarrowing.types | 1 + ...checkDestructuringShorthandAssigment.types | 1 + .../destructuringAssignmentWithDefault.types | 1 + .../es5-asyncFunctionForOfStatements.symbols | 2 ++ ...ndPropertyAssignmentsInDestructuring.types | 10 ++++++++ ...opertyAssignmentsInDestructuring_ES6.types | 10 ++++++++ ...orObjectBindingPatternDefaultValues2.types | 24 +++++++++++++++++++ ...OfObjectBindingPatternDefaultValues2.types | 24 +++++++++++++++++++ 9 files changed, 75 insertions(+) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fbe37e73e9e..689e5cd2fef 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1633,6 +1633,8 @@ namespace ts { return true; case SyntaxKind.ExpressionWithTypeArguments: return (parent).expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent); + case SyntaxKind.ShorthandPropertyAssignment: + return (parent).objectAssignmentInitializer === node; default: return isExpressionNode(parent); } diff --git a/tests/baselines/reference/assignmentTypeNarrowing.types b/tests/baselines/reference/assignmentTypeNarrowing.types index 62d60fa2149..a945084a459 100644 --- a/tests/baselines/reference/assignmentTypeNarrowing.types +++ b/tests/baselines/reference/assignmentTypeNarrowing.types @@ -63,6 +63,7 @@ x; // number >{x = ""} = {x: true} : { x?: true; } >{x = ""} : { x?: string | number | boolean | RegExp; } >x : string | number | boolean | RegExp +>"" : "" >{x: true} : { x?: true; } >x : true >true : true diff --git a/tests/baselines/reference/checkDestructuringShorthandAssigment.types b/tests/baselines/reference/checkDestructuringShorthandAssigment.types index 9eccb886051..692b3a0f03f 100644 --- a/tests/baselines/reference/checkDestructuringShorthandAssigment.types +++ b/tests/baselines/reference/checkDestructuringShorthandAssigment.types @@ -13,5 +13,6 @@ Test(({ b = '5' } = {})); >{ b = '5' } = {} : { b?: any; } >{ b = '5' } : { [x: string]: any; b?: any; } >b : any +>'5' : "5" >{} : { b?: any; } diff --git a/tests/baselines/reference/destructuringAssignmentWithDefault.types b/tests/baselines/reference/destructuringAssignmentWithDefault.types index 658816a36e4..6347ccd0188 100644 --- a/tests/baselines/reference/destructuringAssignmentWithDefault.types +++ b/tests/baselines/reference/destructuringAssignmentWithDefault.types @@ -13,5 +13,6 @@ let x = 0; >{x = 1} = a : { x?: number | undefined; } >{x = 1} : { x?: number; } >x : number +>1 : 1 >a : { x?: number | undefined; } diff --git a/tests/baselines/reference/es5-asyncFunctionForOfStatements.symbols b/tests/baselines/reference/es5-asyncFunctionForOfStatements.symbols index 15742967e09..42901781526 100644 --- a/tests/baselines/reference/es5-asyncFunctionForOfStatements.symbols +++ b/tests/baselines/reference/es5-asyncFunctionForOfStatements.symbols @@ -169,6 +169,7 @@ async function forOfStatement17() { for ({ x = a } of await y) { z; } >x : Symbol(x, Decl(es5-asyncFunctionForOfStatements.ts, 71, 10)) +>a : Symbol(a, Decl(es5-asyncFunctionForOfStatements.ts, 0, 20)) >y : Symbol(y, Decl(es5-asyncFunctionForOfStatements.ts, 0, 14)) >z : Symbol(z, Decl(es5-asyncFunctionForOfStatements.ts, 0, 17)) } @@ -178,6 +179,7 @@ async function forOfStatement18() { for ({ x = a } of y) { await z; } >x : Symbol(x, Decl(es5-asyncFunctionForOfStatements.ts, 75, 10)) +>a : Symbol(a, Decl(es5-asyncFunctionForOfStatements.ts, 0, 20)) >y : Symbol(y, Decl(es5-asyncFunctionForOfStatements.ts, 0, 14)) >z : Symbol(z, Decl(es5-asyncFunctionForOfStatements.ts, 0, 17)) } diff --git a/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring.types b/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring.types index 80d14888052..b160cd31b12 100644 --- a/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring.types +++ b/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring.types @@ -9,6 +9,7 @@ for ({ s0 = 5 } of [{ s0: 1 }]) { >{ s0 = 5 } : { s0?: any; } >s0 : any +>5 : 5 >[{ s0: 1 }] : { s0: number; }[] >{ s0: 1 } : { s0: number; } >s0 : number @@ -45,6 +46,7 @@ for ({ s1 = 5 } of [{}]) { >{ s1 = 5 } : { s1?: any; } >s1 : any +>5 : 5 >[{}] : {}[] >{} : {} } @@ -78,6 +80,7 @@ for ({ s2 = 5 } of [{ s2: "" }]) { >{ s2 = 5 } : { s2?: any; } >s2 : any +>5 : 5 >[{ s2: "" }] : { s2: string; }[] >{ s2: "" } : { s2: string; } >s2 : string @@ -115,6 +118,7 @@ for ({ s3 = 5 } of [{ s3: "" }]) { >{ s3 = 5 } : { s3?: string; } >s3 : string +>5 : 5 >[{ s3: "" }] : { s3: string; }[] >{ s3: "" } : { s3: string; } >s3 : string @@ -154,6 +158,7 @@ >{ y = 5 } = { y: 1 } : { y?: number; } >{ y = 5 } : { y?: any; } >y : any +>5 : 5 >{ y: 1 } : { y?: number; } >y : number >1 : 1 @@ -193,6 +198,7 @@ >{ y0 = 5 } = { y0: 1 } : { y0?: number; } >{ y0 = 5 } : { y0?: number; } >y0 : number +>5 : 5 >{ y0: 1 } : { y0?: number; } >y0 : number >1 : 1 @@ -232,6 +238,7 @@ >{ y1 = 5 } = {} : { y1?: string; } >{ y1 = 5 } : { y1?: string; } >y1 : string +>5 : 5 >{} : { y1?: string; } }); @@ -269,6 +276,7 @@ >{ y2 = 5, y3 = { x: 1 } } = {} : { y2?: string; y3?: { x: string; }; } >{ y2 = 5, y3 = { x: 1 } } : { y2?: string; y3?: { x: string; }; } >y2 : string +>5 : 5 >y3 : { x: string; } >{ x: 1 } : { x: number; } >x : number @@ -318,6 +326,7 @@ >{ y4 = 5, y5 = { x: 1 } } = {} : { y4?: number; y5?: { x: number; }; } >{ y4 = 5, y5 = { x: 1 } } : { y4?: number; y5?: { x: number; }; } >y4 : number +>5 : 5 >y5 : { x: number; } >{ x: 1 } : { x: number; } >x : number @@ -411,6 +420,7 @@ >a : { s: any; } >{ s = 5 } : { s: any; } >s : any +>5 : 5 }); diff --git a/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring_ES6.types b/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring_ES6.types index 5e3d61d09b1..1cdc84e83ba 100644 --- a/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring_ES6.types +++ b/tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring_ES6.types @@ -9,6 +9,7 @@ for ({ s0 = 5 } of [{ s0: 1 }]) { >{ s0 = 5 } : { s0?: any; } >s0 : any +>5 : 5 >[{ s0: 1 }] : { s0: number; }[] >{ s0: 1 } : { s0: number; } >s0 : number @@ -45,6 +46,7 @@ for ({ s1 = 5 } of [{}]) { >{ s1 = 5 } : { s1?: any; } >s1 : any +>5 : 5 >[{}] : {}[] >{} : {} } @@ -78,6 +80,7 @@ for ({ s2 = 5 } of [{ s2: "" }]) { >{ s2 = 5 } : { s2?: any; } >s2 : any +>5 : 5 >[{ s2: "" }] : { s2: string; }[] >{ s2: "" } : { s2: string; } >s2 : string @@ -115,6 +118,7 @@ for ({ s3 = 5 } of [{ s3: "" }]) { >{ s3 = 5 } : { s3?: string; } >s3 : string +>5 : 5 >[{ s3: "" }] : { s3: string; }[] >{ s3: "" } : { s3: string; } >s3 : string @@ -154,6 +158,7 @@ >{ y = 5 } = { y: 1 } : { y?: number; } >{ y = 5 } : { y?: any; } >y : any +>5 : 5 >{ y: 1 } : { y?: number; } >y : number >1 : 1 @@ -193,6 +198,7 @@ >{ y0 = 5 } = { y0: 1 } : { y0?: number; } >{ y0 = 5 } : { y0?: number; } >y0 : number +>5 : 5 >{ y0: 1 } : { y0?: number; } >y0 : number >1 : 1 @@ -232,6 +238,7 @@ >{ y1 = 5 } = {} : { y1?: string; } >{ y1 = 5 } : { y1?: string; } >y1 : string +>5 : 5 >{} : { y1?: string; } }); @@ -269,6 +276,7 @@ >{ y2 = 5, y3 = { x: 1 } } = {} : { y2?: string; y3?: { x: string; }; } >{ y2 = 5, y3 = { x: 1 } } : { y2?: string; y3?: { x: string; }; } >y2 : string +>5 : 5 >y3 : { x: string; } >{ x: 1 } : { x: number; } >x : number @@ -318,6 +326,7 @@ >{ y4 = 5, y5 = { x: 1 } } = {} : { y4?: number; y5?: { x: number; }; } >{ y4 = 5, y5 = { x: 1 } } : { y4?: number; y5?: { x: number; }; } >y4 : number +>5 : 5 >y5 : { x: number; } >{ x: 1 } : { x: number; } >x : number @@ -411,6 +420,7 @@ >a : { s: any; } >{ s = 5 } : { s: any; } >s : any +>5 : 5 }); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.types b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.types index c5f2c806def..f2f584bec4a 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.types @@ -324,6 +324,7 @@ for ({ name = "noName" } = robot, i = 0; i < 1; i++) { >{ name = "noName" } = robot : Robot >{ name = "noName" } : { name?: string; } >name : string +>"noName" : "noName" >robot : Robot >i = 0 : 0 >i : number @@ -346,6 +347,7 @@ for ({ name = "noName" } = getRobot(), i = 0; i < 1; i++) { >{ name = "noName" } = getRobot() : Robot >{ name = "noName" } : { name?: string; } >name : string +>"noName" : "noName" >getRobot() : Robot >getRobot : () => Robot >i = 0 : 0 @@ -369,6 +371,7 @@ for ({ name = "noName" } = { name: "trimmer", skill: "trimming" }, i = 0; >{ name = "noName" } = { name: "trimmer", skill: "trimming" } : Robot >{ name = "noName" } : { name?: string; } >name : string +>"noName" : "noName" >{ name: "trimmer", skill: "trimming" } : Robot >Robot : Robot >{ name: "trimmer", skill: "trimming" } : { name: string; skill: string; } @@ -404,9 +407,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "none", secondary: "none" } >{ primary: "none", secondary: "none" } : { primary?: string; secondary?: string; } @@ -445,9 +450,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "none", secondary: "none" } >{ primary: "none", secondary: "none" } : { primary?: string; secondary?: string; } @@ -487,9 +494,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "none", secondary: "none" } >{ primary: "none", secondary: "none" } : { primary?: string; secondary?: string; } @@ -802,7 +811,9 @@ for ({ name = "noName", skill = "skill" } = robot, i = 0; i < 1; i++) { >{ name = "noName", skill = "skill" } = robot : Robot >{ name = "noName", skill = "skill" } : { name?: string; skill?: string; } >name : string +>"noName" : "noName" >skill : string +>"skill" : "skill" >robot : Robot >i = 0 : 0 >i : number @@ -825,7 +836,9 @@ for ({ name = "noName", skill = "skill" } = getRobot(), i = 0; i < 1; i++) { >{ name = "noName", skill = "skill" } = getRobot() : Robot >{ name = "noName", skill = "skill" } : { name?: string; skill?: string; } >name : string +>"noName" : "noName" >skill : string +>"skill" : "skill" >getRobot() : Robot >getRobot : () => Robot >i = 0 : 0 @@ -849,7 +862,9 @@ for ({ name = "noName", skill = "skill" } = { name: "trimmer", skill: "tr >{ name = "noName", skill = "skill" } = { name: "trimmer", skill: "trimming" } : Robot >{ name = "noName", skill = "skill" } : { name?: string; skill?: string; } >name : string +>"noName" : "noName" >skill : string +>"skill" : "skill" >{ name: "trimmer", skill: "trimming" } : Robot >Robot : Robot >{ name: "trimmer", skill: "trimming" } : { name: string; skill: string; } @@ -880,6 +895,7 @@ for ({ name = "noName", >name : string +>"noName" : "noName" skills: { >skills : { primary?: string; secondary?: string; } @@ -888,9 +904,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "none", secondary: "none" } >{ primary: "none", secondary: "none" } : { primary?: string; secondary?: string; } @@ -924,6 +942,7 @@ for ({ name = "noName", >name : string +>"noName" : "noName" skills: { >skills : { primary?: string; secondary?: string; } @@ -932,9 +951,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "none", secondary: "none" } >{ primary: "none", secondary: "none" } : { primary?: string; secondary?: string; } @@ -969,6 +990,7 @@ for ({ name = "noName", >name : string +>"noName" : "noName" skills: { >skills : { primary?: string; secondary?: string; } @@ -977,9 +999,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "none", secondary: "none" } >{ primary: "none", secondary: "none" } : { primary?: string; secondary?: string; } diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues2.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues2.types index c3d941870be..29d5076f405 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfObjectBindingPatternDefaultValues2.types @@ -273,6 +273,7 @@ for ({ skills: { primary: primaryA = "primary", secondary: secondaryA = "seconda for ({ name = "noName" } of robots) { >{ name = "noName" } : { name?: string; } >name : string +>"noName" : "noName" >robots : Robot[] console.log(nameA); @@ -285,6 +286,7 @@ for ({ name = "noName" } of robots) { for ({ name = "noName" } of getRobots()) { >{ name = "noName" } : { name?: string; } >name : string +>"noName" : "noName" >getRobots() : Robot[] >getRobots : () => Robot[] @@ -298,6 +300,7 @@ for ({ name = "noName" } of getRobots()) { for ({ name = "noName" } of [{ name: "mower", skill: "mowing" }, { name: "trimmer", skill: "trimming" }]) { >{ name = "noName" } : { name?: string; } >name : string +>"noName" : "noName" >[{ name: "mower", skill: "mowing" }, { name: "trimmer", skill: "trimming" }] : { name: string; skill: string; }[] >{ name: "mower", skill: "mowing" } : { name: string; skill: string; } >name : string @@ -327,9 +330,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "noSkill", secondary: "noSkill" } >{ primary: "noSkill", secondary: "noSkill" } : { primary?: string; secondary?: string; } @@ -358,9 +363,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "noSkill", secondary: "noSkill" } >{ primary: "noSkill", secondary: "noSkill" } : { primary?: string; secondary?: string; } @@ -390,9 +397,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "noSkill", secondary: "noSkill" } >{ primary: "noSkill", secondary: "noSkill" } : { primary?: string; secondary?: string; } @@ -657,7 +666,9 @@ for ({ for ({ name = "noName", skill = "noSkill" } of robots) { >{ name = "noName", skill = "noSkill" } : { name?: string; skill?: string; } >name : string +>"noName" : "noName" >skill : string +>"noSkill" : "noSkill" >robots : Robot[] console.log(nameA); @@ -670,7 +681,9 @@ for ({ name = "noName", skill = "noSkill" } of robots) { for ({ name = "noName", skill = "noSkill" } of getRobots()) { >{ name = "noName", skill = "noSkill" } : { name?: string; skill?: string; } >name : string +>"noName" : "noName" >skill : string +>"noSkill" : "noSkill" >getRobots() : Robot[] >getRobots : () => Robot[] @@ -684,7 +697,9 @@ for ({ name = "noName", skill = "noSkill" } of getRobots()) { for ({ name = "noName", skill = "noSkill" } of [{ name: "mower", skill: "mowing" }, { name: "trimmer", skill: "trimming" }]) { >{ name = "noName", skill = "noSkill" } : { name?: string; skill?: string; } >name : string +>"noName" : "noName" >skill : string +>"noSkill" : "noSkill" >[{ name: "mower", skill: "mowing" }, { name: "trimmer", skill: "trimming" }] : { name: string; skill: string; }[] >{ name: "mower", skill: "mowing" } : { name: string; skill: string; } >name : string @@ -709,6 +724,7 @@ for ({ name = "noName", >name : string +>"noName" : "noName" skills: { >skills : { primary?: string; secondary?: string; } @@ -717,9 +733,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "noSkill", secondary: "noSkill" } >{ primary: "noSkill", secondary: "noSkill" } : { primary?: string; secondary?: string; } @@ -743,6 +761,7 @@ for ({ name = "noName", >name : string +>"noName" : "noName" skills: { >skills : { primary?: string; secondary?: string; } @@ -751,9 +770,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "noSkill", secondary: "noSkill" } >{ primary: "noSkill", secondary: "noSkill" } : { primary?: string; secondary?: string; } @@ -778,6 +799,7 @@ for ({ name = "noName", >name : string +>"noName" : "noName" skills: { >skills : { primary?: string; secondary?: string; } @@ -786,9 +808,11 @@ for ({ primary = "primary", >primary : string +>"primary" : "primary" secondary = "secondary" >secondary : string +>"secondary" : "secondary" } = { primary: "noSkill", secondary: "noSkill" } >{ primary: "noSkill", secondary: "noSkill" } : { primary?: string; secondary?: string; } From d282c75e73959013985e031fda527edba53b1c8e Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Thu, 26 Jul 2018 18:09:51 +0200 Subject: [PATCH 2/2] add quickinfo test --- .../quickInfoForDestructuringShorthandInitializer.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoForDestructuringShorthandInitializer.ts diff --git a/tests/cases/fourslash/quickInfoForDestructuringShorthandInitializer.ts b/tests/cases/fourslash/quickInfoForDestructuringShorthandInitializer.ts new file mode 100644 index 00000000000..878c81be37f --- /dev/null +++ b/tests/cases/fourslash/quickInfoForDestructuringShorthandInitializer.ts @@ -0,0 +1,7 @@ +/// + +////let a = ''; +////let b: string; +////({b = /**/a} = {b: 'b'}); + +verify.quickInfoAt("", "let a: string");