8000 Fix the breakpoint spans of call / new expressions · johnangularjs/TypeScript@681e354 · GitHub
[go: up one dir, main page]

Skip to content

Commit 681e354

Browse files
committed
Fix the breakpoint spans of call / new expressions
1 parent 843bdbb commit 681e354

22 files changed

+138
-735
lines changed

src/services/breakpoints.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,6 @@ namespace ts.BreakpointResolver {
7070

7171
function spanInNode(node: Node): TextSpan {
7272
if (node) {
73-
if (isExpression(node)) {
74-
switch (node.parent.kind) {
75-
case SyntaxKind.DoStatement:
76-
// Set span as if on while keyword
77-
return spanInPreviousNode(node);
78-
79-
case SyntaxKind.Decorator:
80-
// Set breakpoint on the decorator emit
81-
return spanInNode(node.parent);
82-
83-
case SyntaxKind.ForStatement:
84-
case SyntaxKind.ForOfStatement:
85-
// For now lets set the span on this expression, fix it later
86-
return textSpan(node);
87-
88-
case SyntaxKind.BinaryExpression:
89-
if ((<BinaryExpression>node.parent).operatorToken.kind === SyntaxKind.CommaToken) {
90-
// if this is comma expression, the breakpoint is possible in this expression
91-
return textSpan(node);
92-
}
93-
break;
94-
95-
case SyntaxKind.ArrowFunction:
96-
if ((<FunctionLikeDeclaration>node.parent).body === node) {
97-
// If this is body of arrow function, it is allowed to have the breakpoint
98-
return textSpan(node);
99-
}
100-
break;
101-
}
102-
}
103-
10473
switch (node.kind) {
10574
case SyntaxKind.VariableStatement:
10675
// Span on first variable declaration
@@ -221,8 +190,6 @@ namespace ts.BreakpointResolver {
221190
case SyntaxKind.ClassDeclaration:
222191
case SyntaxKind.EnumDeclaration:
223192
case SyntaxKind.EnumMember:
224-
case SyntaxKind.CallExpression:
225-
case SyntaxKind.NewExpression:
226193
case SyntaxKind.BindingElement:
227194
// span on complete node
228195
return textSpan(node);
@@ -286,14 +253,45 @@ namespace ts.BreakpointResolver {
286253
return spanInOfKeyword(node);
287254

288255
default:
256+
if (isExpression(node)) {
257+
switch (node.parent.kind) {
258+
case SyntaxKind.DoStatement:
259+
// Set span as if on while keyword
260+
return spanInPreviousNode(node);
261+
262+
case SyntaxKind.Decorator:
263+
// Set breakpoint on the decorator emit
264+
return spanInNode(node.parent);
265+
266+
case SyntaxKind.ForStatement:
267+
case SyntaxKind.ForOfStatement:
268+
// For now lets set the span on this expression, fix it later
269+
return textSpan(node);
270+
271+
case SyntaxKind.BinaryExpression:
272+
if ((<BinaryExpression>node.parent).operatorToken.kind === SyntaxKind.CommaToken) {
273+
// if this is comma expression, the breakpoint is possible in this expression
274+
return textSpan(node);
275+
}
276+
break;
277+
278+
case SyntaxKind.ArrowFunction:
279+
if ((<FunctionLikeDeclaration>node.parent).body === node) {
280+
// If this is body of arrow function, it is allowed to have the breakpoint
281+
return textSpan(node);
282+
}
283+
break;
284+
}
285+
}
286+
289287
// If this is name of property assignment, set breakpoint in the initializer
290288
if (node.parent.kind === SyntaxKind.PropertyAssignment && (<PropertyDeclaration>node.parent).name === node) {
291289
return spanInNode((<PropertyDeclaration>node.parent).initializer);
292290
}
293291

294292
// Breakpoint in type assertion goes to its operand
295293
if (node.parent.kind === SyntaxKind.TypeAssertionExpression && (<TypeAssertion>node.parent).type === node) {
296-
return spanInNode((<TypeAssertion>node.parent).expression);
294+
return spanInNextNode((<TypeAssertion>node.parent).type);
297295
}
298296

299297
// return type of function go to previous token
@@ -559,11 +557,16 @@ namespace ts.BreakpointResolver {
559557
}
560558

561559
function spanInOpenParenToken(node: Node): TextSpan {
562-
if (node.parent.kind === SyntaxKind.DoStatement) {
563-
// Go to while keyword and do action instead
560+
if (node.parent.kind === SyntaxKind.DoStatement || // Go to while keyword and do action instead
561+
node.parent.kind === SyntaxKind.CallExpression ||
562+
node.parent.kind === SyntaxKind.NewExpression) {
564563
return spanInPreviousNode(node);
565564
}
566565

566+
if (node.parent.kind === SyntaxKind.ParenthesizedExpression) {
567+
return spanInNextNode(node);
568+
}
569+
567570
// Default to parent node
568571
return spanInNode(node.parent);
569572
}
@@ -583,6 +586,9 @@ namespace ts.BreakpointResolver {
583586
case SyntaxKind.DoStatement:
584587
case SyntaxKind.ForStatement:
585588
case SyntaxKind.ForOfStatement:
589+
case SyntaxKind.CallExpression:
590+
case SyntaxKind.NewExpression:
591+
case SyntaxKind.ParenthesizedExpression:
586592
return spanInPreviousNode(node);
587593

588594
// Default to parent node
@@ -604,7 +610,7 @@ namespace ts.BreakpointResolver {
604610

605611
function spanInGreaterThanOrLessThanToken(node: Node): TextSpan {
606612
if (node.parent.kind === SyntaxKind.TypeAssertionExpression) {
607-
return spanInNode((<TypeAssertion>node.parent).expression);
613+
return spanInNextNode(node);
608614
}
609615

610616
return spanInNode(node.parent);

tests/baselines/reference/bpSpanDestructuringForArrayBindingPattern.baseline

Lines changed: 8 additions & 48 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,11 @@
120120
--------------------------------
121121
21 >for (let [, nameA] = getRobot(), i = 0; i < 1; i++) {
122122

123-
~~~~~~~~~~~~~~~~~~~~ => Pos: (499 to 518) SpanInfo: {"start":511,"length":5}
123+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (499 to 530) SpanInfo: {"start":511,"length":5}
124124
>nameA
125125
>:=> (line 21, col 12) to (line 21, col 17)
126126
21 >for (let [, nameA] = getRobot(), i = 0; i < 1; i++) {
127127

128-
~~~~~~~~~~~~ => Pos: (519 to 530) SpanInfo: {"start":520,"length":10}
129-
>getRobot()
130-
>:=> (line 21, col 21) to (line 21, col 31)
131-
21 >for (let [, nameA] = getRobot(), i = 0; i < 1; i++) {
132-
133128
~~~~~~~ => Pos: (531 to 537) SpanInfo: {"start":532,"length":5}
134129
>i = 0
135130
>:=> (line 21, col 33) to (line 21, col 38)
@@ -254,16 +249,11 @@
254249
>:=> (line 30, col 28) to (line 30, col 43)
255250
30 >for (let [, [primarySkillA, secondarySkillA]] = getMultiRobot(), i = 0; i < 1; i++) {
256251

257-
~~~=> Pos: (835 to 837) SpanInfo: {"start":803,"length":32}
252+
~~~~~~~~~~~~~~~~~~~~=> Pos: (835 to 854) SpanInfo: {"start":803,"length":32}
258253
>[primarySkillA, secondarySkillA]
259254
>:=> (line 30, col 12) to (line 30, col 44)
260255
30 >for (let [, [primarySkillA, secondarySkillA]] = getMultiRobot(), i = 0; i < 1; i++) {
261256

262-
~~~~~~~~~~~~~~~~~=> Pos: (838 to 854) SpanInfo: {"start":839,"length":15}
263-
>getMultiRobot()
264-
>:=> (line 30, col 48) to (line 30, col 63)
265-
30 >for (let [, [primarySkillA, secondarySkillA]] = getMultiRobot(), i = 0; i < 1; i++) {
266-
267257
~~~~~~~=> Pos: (855 to 861) SpanInfo: {"start":856,"length":5}
268258
>i = 0
269259
>:=> (line 30, col 65) to (line 30, col 70)
@@ -377,16 +367,11 @@
377367
--------------------------------
378368
40 >for (let [numberB] = getRobot(), i = 0; i < 1; i++) {
379369

380-
~~~~~~~~~~~~~~~~~~~~ => Pos: (1130 to 1149) SpanInfo: {"start":1140,"length":7}
370+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1130 to 1161) SpanInfo: {"start":1140,"length":7}
381371
>numberB
382372
>:=> (line 40, col 10) to (line 40, col 17)
383373
40 >for (let [numberB] = getRobot(), i = 0; i < 1; i++) {
384374

385-
~~~~~~~~~~~~ => Pos: (1150 to 1161) SpanInfo: {"start":1151,"length":10}
386-
>getRobot()
387-
>:=> (line 40, col 21) to (line 40, col 31)
388-
40 >for (let [numberB] = getRobot(), i = 0; i < 1; i++) {
389-
390375
~~~~~~~ => Pos: (1162 to 1168) SpanInfo: {"start":1163,"length":5}
391376
>i = 0
392377
>:=> (line 40, col 33) to (line 40, col 38)
@@ -481,16 +466,11 @@
481466
--------------------------------
482467
49 >for (let [nameB] = getMultiRobot(), i = 0; i < 1; i++) {
483468

484-
~~~~~~~~~~~~~~~~~~ => Pos: (1389 to 1406) SpanInfo: {"start":1399,"length":5}
469+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1389 to 1423) SpanInfo: {"start":1399,"length":5}
485470
>nameB
486471
>:=> (line 49, col 10) to (line 49, col 15)
487472
49 >for (let [nameB] = getMultiRobot(), i = 0; i < 1; i++) {
488473

489-
~~~~~~~~~~~~~~~~~ => Pos: (1407 to 1423) SpanInfo: {"start":1408,"length":15}
490-
>getMultiRobot()
491-
>:=> (line 49, col 19) to (line 49, col 34)
492-
49 >for (let [nameB] = getMultiRobot(), i = 0; i < 1; i++) {
493-
494474
~~~~~~~ => Pos: (1424 to 1430) SpanInfo: {"start":1425,"length":5}
495475
>i = 0
496476
>:=> (line 49, col 36) to (line 49, col 41)
@@ -609,16 +589,11 @@
609589
>:=> (line 59, col 20) to (line 59, col 26)
610590
59 >for (let [numberA2, nameA2, skillA2] = getRobot(), i = 0; i < 1; i++) {
611591

612-
~~~~~~~~~~~ => Pos: (1698 to 1708) SpanInfo: {"start":1699,"length":7}
592+
~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (1698 to 1720) SpanInfo: {"start":1699,"length":7}
613593
>skillA2
614594
>:=> (line 59, col 28) to (line 59, col 35)
615595
59 >for (let [numberA2, nameA2, skillA2] = getRobot(), i = 0; i < 1; i++) {
616596

617-
~~~~~~~~~~~~=> Pos: (1709 to 1720) SpanInfo: {"start":1710,"length":10}
618-
>getRobot()
619-
>:=> (line 59, col 39) to (line 59, col 49)
620-
59 >for (let [numberA2, nameA2, skillA2] = getRobot(), i = 0; i < 1; i++) {
621-
622597
~~~~~~~=> Pos: (1721 to 1727) SpanInfo: {"start":1722,"length":5}
623598
>i = 0
624599
>:=> (line 59, col 51) to (line 59, col 56)
@@ -753,16 +728,11 @@
753728
>:=> (line 68, col 34) to (line 68, col 49)
754729
68 >for (let [nameMA, [primarySkillA, secondarySkillA]] = getMultiRobot(), i = 0; i < 1; i++) {
755730

756-
~~~=> Pos: (2050 to 2052) SpanInfo: {"start":2018,"length":32}
731+
~~~~~~~~~~~~~~~~~~~~=> Pos: (2050 to 2069) SpanInfo: {"start":2018,"length":32}
757732
>[primarySkillA, secondarySkillA]
758733
>:=> (line 68, col 18) to (line 68, col 50)
759734
68 >for (let [nameMA, [primarySkillA, secondarySkillA]] = getMultiRobot(), i = 0; i < 1; i++) {
760735

761-
~~~~~~~~~~~~~~~~~=> Pos: (2053 to 2069) SpanInfo: {"start":2054,"length":15}
762-
>getMultiRobot()
763-
>:=> (line 68, col 54) to (line 68, col 69)
764-
68 >for (let [nameMA, [primarySkillA, secondarySkillA]] = getMultiRobot(), i = 0; i < 1; i++) {
765-
766736
~~~~~~~=> Pos: (2070 to 2076) SpanInfo: {"start":2071,"length":5}
767737
>i = 0
768738
>:=> (line 68, col 71) to (line 68, col 76)
@@ -886,16 +856,11 @@
886856
>:=> (line 78, col 10) to (line 78, col 18)
887857
78 >for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) {
888858

889-
~~~~~~~~~~~~~~~~~ => Pos: (2373 to 2389) SpanInfo: {"start":2374,"length":13}
859+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (2373 to 2401) SpanInfo: {"start":2374,"length":13}
890860
>...robotAInfo
891861
>:=> (line 78, col 20) to (line 78, col 33)
892862
78 >for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) {
893863

894-
~~~~~~~~~~~~=> Pos: (2390 to 2401) SpanInfo: {"start":2391,"length":10}
895-
>getRobot()
896-
>:=> (line 78, col 37) to (line 78, col 47)
897-
78 >for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) {
898-
899864
~~~~~~~=> Pos: (2402 to 2408) SpanInfo: {"start":2403,"length":5}
900865
>i = 0
901866
>:=> (line 78, col 49) to (line 78, col 54)
@@ -995,16 +960,11 @@
995960
--------------------------------
996961
87 >for (let [...multiRobotAInfo] = getMultiRobot(), i = 0; i < 1; i++) {
997962

998-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (2670 to 2700) SpanInfo: {"start":2680,"length":18}
963+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (2670 to 2717) SpanInfo: {"start":2680,"length":18}
999964
>...multiRobotAInfo
1000965
>:=> (line 87, col 10) to (line 87, col 28)
1001966
87 >for (let [...multiRobotAInfo] = getMultiRobot(), i = 0; i < 1; i++) {
1002967

1003-
~~~~~~~~~~~~~~~~~=> Pos: (2701 to 2717) SpanInfo: {"start":2702,"length":15}
1004-
>getMultiRobot()
1005-
>:=> (line 87, col 32) to (line 87, col 47)
1006-
87 >for (let [...multiRobotAInfo] = getMultiRobot(), i = 0; i < 1; i++) {
1007-
1008968
~~~~~~~=> Pos: (2718 to 2724) SpanInfo: {"start":2719,"length":5}
1009969
>i = 0
1010970
>:=> (line 87, col 49) to (line 87, col 54)

0 commit comments

Comments
 (0)
0