Skip to content

Commit a047d20

Browse files
committed
Breakpoint span in the doStatement
1 parent abb0acc commit a047d20

3 files changed

Lines changed: 145 additions & 4 deletions

File tree

src/services/breakpoints.ts

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ module ts.BreakpointResolver {
6565
case SyntaxKind.FunctionBlock:
6666
return spanInFirstStatementOfBlock(<Block>node);
6767

68+
case SyntaxKind.Block:
69+
return spanInBlock(<Block>node);
70+
6871
case SyntaxKind.ExpressionStatement:
6972
return spanInExpressionStatement(<ExpressionStatement>node);
7073

@@ -74,6 +77,9 @@ module ts.BreakpointResolver {
7477
case SyntaxKind.WhileStatement:
7578
return spanInWhileStatement(<WhileStatement>node);
7679

80+
case SyntaxKind.DoStatement:
81+
return spanInDoStatement(<DoStatement>node);
82+
7783
// Tokens:
7884
case SyntaxKind.SemicolonToken:
7985
case SyntaxKind.EndOfFileToken:
@@ -88,12 +94,27 @@ module ts.BreakpointResolver {
8894
case SyntaxKind.CloseBraceToken:
8995
return spanInCloseBraceToken(node);
9096

97+
case SyntaxKind.OpenParenToken:
98+
return spanInOpenParenToken(node);
99+
91100
case SyntaxKind.CloseParenToken:
92101
return spanInCloseParenToken(node);
93102

94103
case SyntaxKind.ColonToken:
95104
return spanInColonToken(node);
96105

106+
// Keywords:
107+
case SyntaxKind.WhileKeyword:
108+
return spanInWhileKeyword(node);
109+
110+
case SyntaxKind.BinaryExpression:
111+
//TODO (pick this up later) for now lets fix do-while baseline
112+
if (node.parent.kind === SyntaxKind.DoStatement) {
113+
// Set span as if on while keyword
114+
return spanInPreviousNode(node);
115+
}
116+
// Default action for now
117+
97118
default:
98119
// Default go to parent to set the breakpoint
99120
return spanInNode(node.parent);
@@ -210,6 +231,10 @@ module ts.BreakpointResolver {
210231
return textSpan(whileStatement, findNextToken(whileStatement.expression, whileStatement));
211232
}
212233

234+
function spanInDoStatement(doStatement: DoStatement): TypeScript.TextSpan {
235+
return spanInNode(doStatement.statement);
236+
}
237+
213238
// Tokens:
214239
function spanInCommaToken(node: Node): TypeScript.TextSpan {
215240
switch (node.parent.kind) {
@@ -253,11 +278,33 @@ module ts.BreakpointResolver {
253278
}
254279
}
255280

281+
function spanInOpenParenToken(node: Node): TypeScript.TextSpan {
282+
if (node.parent.kind === SyntaxKind.DoStatement) {
283+
// Go to while keyword and do action instead
284+
return spanInPreviousNode(node);
285+
}
286+
287+
// Default to parent node
288+
return spanInNode(node.parent);
289+
}
290+
256291
function spanInCloseParenToken(node: Node): TypeScript.TextSpan {
257292
// Is this close paren token of parameter list, set span in previous token
258-
if (isAnyFunction(node.parent) ||
259-
node.parent.kind === SyntaxKind.WhileStatement) {
260-
return spanInPreviousNode(node);
293+
switch (node.parent.kind) {
294+
case SyntaxKind.FunctionExpression:
295+
case SyntaxKind.FunctionDeclaration:
296+
case SyntaxKind.ArrowFunction:
297+
case SyntaxKind.Method:
298+
case SyntaxKind.GetAccessor:
299+
case SyntaxKind.SetAccessor:
300+
case SyntaxKind.Constructor:
301+
case SyntaxKind.WhileStatement:
302+
case SyntaxKind.DoStatement:
303+
return spanInPreviousNode(node);
304+
305+
// Default to parent node
306+
default:
307+
return spanInNode(node.parent);
261308
}
262309

263310
// Default to parent node
@@ -272,6 +319,16 @@ module ts.BreakpointResolver {
272319

273320
return spanInNode(node.parent);
274321
}
322+
323+
function spanInWhileKeyword(node: Node): TypeScript.TextSpan {
324+
if (node.parent.kind === SyntaxKind.DoStatement) {
325+
// Set span on while expression
326+
return textSpan(node, findNextToken((<DoStatement>node.parent).expression, node.parent));
327+
}
328+
329+
// Default to parent node
330+
return spanInNode(node.parent);
331+
}
275332
}
276333
}
277334
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
1 >var i = 0;
3+
4+
~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":9}
5+
>var i = 0
6+
>:=> (line 1, col 0) to (line 1, col 9)
7+
--------------------------------
8+
2 >do
9+
10+
~~~ => Pos: (11 to 13) SpanInfo: {"start":20,"length":3}
11+
>i++
12+
>:=> (line 4, col 4) to (line 4, col 7)
13+
--------------------------------
14+
3 >{
15+
16+
~~ => Pos: (14 to 15) SpanInfo: {"start":20,"length":3}
17+
>i++
18+
>:=> (line 4, col 4) to (line 4, col 7)
19+
--------------------------------
20+
4 > i++;
21+
22+
~~~~~~~~~ => Pos: (16 to 24) SpanInfo: {"start":20,"length":3}
23+
>i++
24+
>:=> (line 4, col 4) to (line 4, col 7)
25+
--------------------------------
26+
5 >} while (i < 10);
27+
28+
~ => Pos: (25 to 25) SpanInfo: {"start":20,"length":3}
29+
>i++
30+
>:=> (line 4, col 4) to (line 4, col 7)
31+
5 >} while (i < 10);
32+
33+
~~~~~~~~~~~~~~~~~ => Pos: (26 to 42) SpanInfo: {"start":27,"length":14}
34+
>while (i < 10)
35+
>:=> (line 5, col 2) to (line 5, col 16)
36+
--------------------------------
37+
6 >do {
38+
39+
~~~~~ => Pos: (43 to 47) SpanInfo: {"start":52,"length":3}
40+
>i++
41+
>:=> (line 7, col 4) to (line 7, col 7)
42+
--------------------------------
43+
7 > i++;
44+
45+
~~~~~~~~~ => Pos: (48 to 56) SpanInfo: {"start":52,"length":3}
46+
>i++
47+
>:=> (line 7, col 4) to (line 7, col 7)
48+
--------------------------------
49+
8 >} while (i < 20);
50+
51+
~ => Pos: (57 to 57) SpanInfo: {"start":52,"length":3}
52+
>i++
53+
>:=> (line 7, col 4) to (line 7, col 7)
54+
8 >} while (i < 20);
55+
56+
~~~~~~~~~~~~~~~~~ => Pos: (58 to 74) SpanInfo: {"start":59,"length":14}
57+
>while (i < 20)
58+
>:=> (line 8, col 2) to (line 8, col 16)
59+
--------------------------------
60+
9 >do {
61+
62+
~~~~~ => Pos: (75 to 79) SpanInfo: {"start":84,"length":3}
63+
>i++
64+
>:=> (line 10, col 4) to (line 10, col 7)
65+
--------------------------------
66+
10 > i++;
67+
68+
~~~~~~~~~ => Pos: (80 to 88) SpanInfo: {"start":84,"length":3}
69+
>i++
70+
>:=> (line 10, col 4) to (line 10, col 7)
71+
--------------------------------
72+
11 >}
73+
74+
~~~ => Pos: (89 to 91) SpanInfo: {"start":84,"length":3}
75+
>i++
76+
>:=> (line 10, col 4) to (line 10, col 7)
77+
--------------------------------
78+
12 >while (i < 30);
79+
~~~~~~~~~~~~~~~ => Pos: (92 to 106) SpanInfo: {"start":92,"length":14}
80+
>while (i < 30)
81+
>:=> (line 12, col 0) to (line 12, col 14)

tests/cases/fourslash_old/breakpointValidationDo.ts renamed to tests/cases/fourslash/breakpointValidationDo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
////do {
1111
//// i++;
1212
////} while (i < 20);
13-
13+
////do {
14+
//// i++;
15+
////}
16+
////while (i < 30);
1417
verify.baselineCurrentFileBreakpointLocations();

0 commit comments

Comments
 (0)