Skip to content

Commit adcc685

Browse files
committed
Fix the array binding pattern breakpoint span of variable declaration statement
1 parent 960e8a7 commit adcc685

5 files changed

Lines changed: 37 additions & 77 deletions

src/services/breakpoints.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ namespace ts.BreakpointResolver {
245245

246246
case SyntaxKind.CloseBraceToken:
247247
return spanInCloseBraceToken(node);
248+
249+
case SyntaxKind.CloseBracketToken:
250+
return spanInCloseBracketToken(node);
248251

249252
case SyntaxKind.OpenParenToken:
250253
return spanInOpenParenToken(node);
@@ -512,6 +515,19 @@ namespace ts.BreakpointResolver {
512515
}
513516
}
514517

518+
function spanInCloseBracketToken(node: Node): TextSpan {
519+
switch (node.parent.kind) {
520+
case SyntaxKind.ArrayBindingPattern:
521+
// Breakpoint in last binding element or binding pattern if it contains no elements
522+
let bindingPattern = <BindingPattern>node.parent;
523+
return spanInNode(lastOrUndefined(bindingPattern.elements) || bindingPattern);
524+
525+
// Default to parent node
526+
default:
527+
return spanInNode(node.parent);
528+
}
529+
}
530+
515531
function spanInOpenParenToken(node: Node): TextSpan {
516532
if (node.parent.kind === SyntaxKind.DoStatement) {
517533
// Go to while keyword and do action instead

tests/baselines/reference/bpSpanDestructuringVariableStatementArrayBindingPattern.baseline

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,9 @@
5151
>:=> (line 9, col 15) to (line 9, col 21)
5252
9 >let [numberA2, nameA2, skillA2] = robotA;
5353

54-
~~~~~~~~ => Pos: (254 to 261) SpanInfo: {"start":255,"length":7}
54+
~~~~~~~~~~~~~~~~~~~~ => Pos: (254 to 273) SpanInfo: {"start":255,"length":7}
5555
>skillA2
5656
>:=> (line 9, col 23) to (line 9, col 30)
57-
9 >let [numberA2, nameA2, skillA2] = robotA;
58-
59-
~~~~~~~~~~~~ => Pos: (262 to 273) SpanInfo: {"start":237,"length":8}
60-
>numberA2
61-
>:=> (line 9, col 5) to (line 9, col 13)
6257
--------------------------------
6358
10 >let [numberC2] = [3, "edging", "Trimming edges"];
6459

@@ -78,24 +73,15 @@
7873
>:=> (line 11, col 14) to (line 11, col 19)
7974
11 >let [numberC, nameC, skillC] = [3, "edging", "Trimming edges"];
8075

81-
~~~~~~~ => Pos: (344 to 350) SpanInfo: {"start":345,"length":6}
76+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (344 to 387) SpanInfo: {"start":345,"length":6}
8277
>skillC
8378
>:=> (line 11, col 21) to (line 11, col 27)
84-
11 >let [numberC, nameC, skillC] = [3, "edging", "Trimming edges"];
85-
86-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (351 to 387) SpanInfo: {"start":329,"length":7}
87-
>numberC
88-
>:=> (line 11, col 5) to (line 11, col 12)
8979
--------------------------------
9080
12 >let [numberA3, ...robotAInfo] = robotA;
9181
~~~~~~~~~~~~~~ => Pos: (388 to 401) SpanInfo: {"start":393,"length":8}
9282
>numberA3
9383
>:=> (line 12, col 5) to (line 12, col 13)
9484
12 >let [numberA3, ...robotAInfo] = robotA;
95-
~~~~~~~~~~~~~~ => Pos: (402 to 415) SpanInfo: {"start":403,"length":13}
85+
~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (402 to 426) SpanInfo: {"start":403,"length":13}
9686
>...robotAInfo
97-
>:=> (line 12, col 15) to (line 12, col 28)
98-
12 >let [numberA3, ...robotAInfo] = robotA;
99-
~~~~~~~~~~~ => Pos: (416 to 426) SpanInfo: {"start":393,"length":8}
100-
>numberA3
101-
>:=> (line 12, col 5) to (line 12, col 13)
87+
>:=> (line 12, col 15) to (line 12, col 28)

tests/baselines/reference/bpSpanDestructuringVariableStatementArrayBindingPattern2.baseline

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,14 @@
5555
>:=> (line 10, col 14) to (line 10, col 27)
5656
10 >let [nameMA, [primarySkillA, secondarySkillA]] = multiRobotA;
5757

58-
~~~~~~~~~~~~~~~~ => Pos: (331 to 346) SpanInfo: {"start":332,"length":15}
58+
~~~~~~~~~~~~~~~~~ => Pos: (331 to 347) SpanInfo: {"start":332,"length":15}
5959
>secondarySkillA
6060
>:=> (line 10, col 29) to (line 10, col 44)
6161
10 >let [nameMA, [primarySkillA, secondarySkillA]] = multiRobotA;
6262

63-
~ => Pos: (347 to 347) SpanInfo: {"start":317,"length":13}
64-
>primarySkillA
65-
>:=> (line 10, col 14) to (line 10, col 27)
66-
10 >let [nameMA, [primarySkillA, secondarySkillA]] = multiRobotA;
67-
68-
~~~~~~~~~~~~~~~~~=> Pos: (348 to 364) SpanInfo: {"start":308,"length":6}
69-
>nameMA
70-
>:=> (line 10, col 5) to (line 10, col 11)
63+
~~~~~~~~~~~~~~~~~=> Pos: (348 to 364) SpanInfo: {"start":316,"length":32}
64+
>[primarySkillA, secondarySkillA]
65+
>:=> (line 10, col 13) to (line 10, col 45)
7166
--------------------------------
7267
11 >
7368

@@ -91,19 +86,14 @@
9186
>:=> (line 13, col 15) to (line 13, col 28)
9287
13 >let [nameMC2, [primarySkillC, secondarySkillC]] = ["roomba", ["vaccum", "mopping"]];
9388

94-
~~~~~~~~~~~~~~~~ => Pos: (445 to 460) SpanInfo: {"start":446,"length":15}
89+
~~~~~~~~~~~~~~~~~=> Pos: (445 to 461) SpanInfo: {"start":446,"length":15}
9590
>secondarySkillC
9691
>:=> (line 13, col 30) to (line 13, col 45)
9792
13 >let [nameMC2, [primarySkillC, secondarySkillC]] = ["roomba", ["vaccum", "mopping"]];
9893

99-
~=> Pos: (461 to 461) SpanInfo: {"start":431,"length":13}
100-
>primarySkillC
101-
>:=> (line 13, col 15) to (line 13, col 28)
102-
13 >let [nameMC2, [primarySkillC, secondarySkillC]] = ["roomba", ["vaccum", "mopping"]];
103-
104-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (462 to 500) SpanInfo: {"start":421,"length":7}
105-
>nameMC2
106-
>:=> (line 13, col 5) to (line 13, col 12)
94+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (462 to 500) SpanInfo: {"start":430,"length":32}
95+
>[primarySkillC, secondarySkillC]
96+
>:=> (line 13, col 14) to (line 13, col 46)
10797
--------------------------------
10898
14 >
10999

tests/baselines/reference/bpSpanDestructuringVariableStatementArrayBindingPatternDefaultValues.baseline

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,9 @@
5151
>:=> (line 9, col 20) to (line 9, col 37)
5252
9 >let [numberA2 = -1, nameA2 = "noName", skillA2 = "noSkill"] = robotA;
5353

54-
~~~~~~~~~~~~~~~~~~~~=> Pos: (286 to 305) SpanInfo: {"start":287,"length":19}
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (286 to 317) SpanInfo: {"start":287,"length":19}
5555
>skillA2 = "noSkill"
5656
>:=> (line 9, col 39) to (line 9, col 58)
57-
9 >let [numberA2 = -1, nameA2 = "noName", skillA2 = "noSkill"] = robotA;
58-
59-
~~~~~~~~~~~~=> Pos: (306 to 317) SpanInfo: {"start":253,"length":13}
60-
>numberA2 = -1
61-
>:=> (line 9, col 5) to (line 9, col 18)
6257
--------------------------------
6358
10 >let [numberC2 = -1] = [3, "edging", "Trimming edges"];
6459

@@ -78,24 +73,15 @@
7873
>:=> (line 11, col 19) to (line 11, col 35)
7974
11 >let [numberC = -1, nameC = "noName", skillC = "noSkill"] = [3, "edging", "Trimming edges"];
8075

81-
~~~~~~~~~~~~~~~~~~~=> Pos: (409 to 427) SpanInfo: {"start":410,"length":18}
76+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (409 to 464) SpanInfo: {"start":410,"length":18}
8277
>skillC = "noSkill"
8378
>:=> (line 11, col 37) to (line 11, col 55)
84-
11 >let [numberC = -1, nameC = "noName", skillC = "noSkill"] = [3, "edging", "Trimming edges"];
85-
86-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (428 to 464) SpanInfo: {"start":378,"length":12}
87-
>numberC = -1
88-
>:=> (line 11, col 5) to (line 11, col 17)
8979
--------------------------------
9080
12 >let [numberA3 = -1, ...robotAInfo] = robotA;
9181
~~~~~~~~~~~~~~~~~~~ => Pos: (465 to 483) SpanInfo: {"start":470,"length":13}
9282
>numberA3 = -1
9383
>:=> (line 12, col 5) to (line 12, col 18)
9484
12 >let [numberA3 = -1, ...robotAInfo] = robotA;
95-
~~~~~~~~~~~~~~ => Pos: (484 to 497) SpanInfo: {"start":485,"length":13}
85+
~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (484 to 508) SpanInfo: {"start":485,"length":13}
9686
>...robotAInfo
97-
>:=> (line 12, col 20) to (line 12, col 33)
98-
12 >let [numberA3 = -1, ...robotAInfo] = robotA;
99-
~~~~~~~~~~~ => Pos: (498 to 508) SpanInfo: {"start":470,"length":13}
100-
>numberA3 = -1
101-
>:=> (line 12, col 5) to (line 12, col 18)
87+
>:=> (line 12, col 20) to (line 12, col 33)

tests/baselines/reference/bpSpanDestructuringVariableStatementArrayBindingPatternDefaultValues2.baseline

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,14 @@
5151
>:=> (line 9, col 25) to (line 9, col 50)
5252
9 >let [nameMA = "noName", [primarySkillA = "noSkill", secondarySkillA = "noSkill"] = ["noSkill", "noSkill"]] = multiRobotA;
5353

54-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (382 to 409) SpanInfo: {"start":383,"length":27}
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (382 to 410) SpanInfo: {"start":383,"length":27}
5555
>secondarySkillA = "noSkill"
5656
>:=> (line 9, col 52) to (line 9, col 79)
5757
9 >let [nameMA = "noName", [primarySkillA = "noSkill", secondarySkillA = "noSkill"] = ["noSkill", "noSkill"]] = multiRobotA;
5858

59-
~=> Pos: (410 to 410) SpanInfo: {"start":356,"length":25}
60-
>primarySkillA = "noSkill"
61-
>:=> (line 9, col 25) to (line 9, col 50)
62-
9 >let [nameMA = "noName", [primarySkillA = "noSkill", secondarySkillA = "noSkill"] = ["noSkill", "noSkill"]] = multiRobotA;
63-
64-
~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (411 to 435) SpanInfo: {"start":355,"length":81}
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (411 to 452) SpanInfo: {"start":355,"length":81}
6560
>[primarySkillA = "noSkill", secondarySkillA = "noSkill"] = ["noSkill", "noSkill"]
6661
>:=> (line 9, col 24) to (line 9, col 105)
67-
9 >let [nameMA = "noName", [primarySkillA = "noSkill", secondarySkillA = "noSkill"] = ["noSkill", "noSkill"]] = multiRobotA;
68-
69-
~~~~~~~~~~~~~~~~~=> Pos: (436 to 452) SpanInfo: {"start":336,"length":17}
70-
>nameMA = "noName"
71-
>:=> (line 9, col 5) to (line 9, col 22)
7262
--------------------------------
7363
10 >let [nameMC = "noName" ] = ["roomba", ["vaccum", "mopping"]];
7464

@@ -85,18 +75,10 @@
8575
>primarySkillC = "noSkill"
8676
>:=> (line 11, col 26) to (line 11, col 51)
8777
11 >let [nameMC2 = "noName", [primarySkillC = "noSkill", secondarySkillC = "noSkill"] = ["noSkill", "noSkill"]] = ["roomba", ["vaccum", "mopping"]];
88-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (567 to 594) SpanInfo: {"start":568,"length":27}
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (567 to 595) SpanInfo: {"start":568,"length":27}
8979
>secondarySkillC = "noSkill"
9080
>:=> (line 11, col 53) to (line 11, col 80)
9181
11 >let [nameMC2 = "noName", [primarySkillC = "noSkill", secondarySkillC = "noSkill"] = ["noSkill", "noSkill"]] = ["roomba", ["vaccum", "mopping"]];
92-
~=> Pos: (595 to 595) SpanInfo: {"start":541,"length":25}
93-
>primarySkillC = "noSkill"
94-
>:=> (line 11, col 26) to (line 11, col 51)
95-
11 >let [nameMC2 = "noName", [primarySkillC = "noSkill", secondarySkillC = "noSkill"] = ["noSkill", "noSkill"]] = ["roomba", ["vaccum", "mopping"]];
96-
~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (596 to 620) SpanInfo: {"start":540,"length":81}
82+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (596 to 658) SpanInfo: {"start":540,"length":81}
9783
>[primarySkillC = "noSkill", secondarySkillC = "noSkill"] = ["noSkill", "noSkill"]
98-
>:=> (line 11, col 25) to (line 11, col 106)
99-
11 >let [nameMC2 = "noName", [primarySkillC = "noSkill", secondarySkillC = "noSkill"] = ["noSkill", "noSkill"]] = ["roomba", ["vaccum", "mopping"]];
100-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (621 to 658) SpanInfo: {"start":520,"length":18}
101-
>nameMC2 = "noName"
102-
>:=> (line 11, col 5) to (line 11, col 23)
84+
>:=> (line 11, col 25) to (line 11, col 106)

0 commit comments

Comments
 (0)