Skip to content

Commit f5731f3

Browse files
committed
Breakpoints in the for in statement
1 parent b97f876 commit f5731f3

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

src/services/breakpoints.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ module ts.BreakpointResolver {
100100
case SyntaxKind.ForStatement:
101101
return spanInForStatement(<ForStatement>node);
102102

103+
case SyntaxKind.ForInStatement:
104+
return spanInForInStatement(<ForInStatement>node);
105+
103106
case SyntaxKind.BinaryExpression:
104107
case SyntaxKind.PostfixOperator:
105108
case SyntaxKind.PrefixOperator:
@@ -142,6 +145,11 @@ module ts.BreakpointResolver {
142145
}
143146

144147
function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan {
148+
// If declaration of for in statement, just set the span in parent
149+
if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) {
150+
return spanInForInStatement(<ForInStatement>variableDeclaration.parent);
151+
}
152+
145153
var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement;
146154
var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((<ForStatement>variableDeclaration.parent).declarations, variableDeclaration);
147155
var declarations = isParentVariableStatement
@@ -243,6 +251,7 @@ module ts.BreakpointResolver {
243251
// Set on parent if on same line otherwise on first statement
244252
case SyntaxKind.WhileStatement:
245253
case SyntaxKind.IfStatement:
254+
case SyntaxKind.ForInStatement:
246255
return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]);
247256

248257
// Set span on previous token if it starts on same line otherwise on the first statement of the block
@@ -304,6 +313,10 @@ module ts.BreakpointResolver {
304313
}
305314
}
306315

316+
function spanInForInStatement(forInStatement: ForInStatement): TypeScript.TextSpan {
317+
return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement));
318+
}
319+
307320
function spanInExpression(expression: Expression): TypeScript.TextSpan {
308321
//TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) {
309322
// Set span as if on while keyword
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
1 >for (var x in String) {
3+
4+
~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: {"start":0,"length":21}
5+
>for (var x in String)
6+
>:=> (line 1, col 0) to (line 1, col 21)
7+
--------------------------------
8+
2 > WScript.Echo(x);
9+
10+
~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 44) SpanInfo: {"start":28,"length":15}
11+
>WScript.Echo(x)
12+
>:=> (line 2, col 4) to (line 2, col 19)
13+
--------------------------------
14+
3 >}
15+
16+
~~ => Pos: (45 to 46) SpanInfo: {"start":28,"length":15}
17+
>WScript.Echo(x)
18+
>:=> (line 2, col 4) to (line 2, col 19)
19+
--------------------------------
20+
4 >for (x in String) {
21+
22+
~~~~~~~~~~~~~~~~~~~~ => Pos: (47 to 66) SpanInfo: {"start":47,"length":17}
23+
>for (x in String)
24+
>:=> (line 4, col 0) to (line 4, col 17)
25+
--------------------------------
26+
5 > WScript.Echo(x);
27+
28+
~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 87) SpanInfo: {"start":71,"length":15}
29+
>WScript.Echo(x)
30+
>:=> (line 5, col 4) to (line 5, col 19)
31+
--------------------------------
32+
6 >}
33+
34+
~~ => Pos: (88 to 89) SpanInfo: {"start":71,"length":15}
35+
>WScript.Echo(x)
36+
>:=> (line 5, col 4) to (line 5, col 19)
37+
--------------------------------
38+
7 >for (var x2 in String)
39+
40+
~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (90 to 112) SpanInfo: {"start":90,"length":22}
41+
>for (var x2 in String)
42+
>:=> (line 7, col 0) to (line 7, col 22)
43+
--------------------------------
44+
8 >{
45+
46+
~~ => Pos: (113 to 114) SpanInfo: {"start":119,"length":16}
47+
>WScript.Echo(x2)
48+
>:=> (line 9, col 4) to (line 9, col 20)
49+
--------------------------------
50+
9 > WScript.Echo(x2);
51+
52+
~~~~~~~~~~~~~~~~~~~~~~ => Pos: (115 to 136) SpanInfo: {"start":119,"length":16}
53+
>WScript.Echo(x2)
54+
>:=> (line 9, col 4) to (line 9, col 20)
55+
--------------------------------
56+
10 >}
57+
58+
~~ => Pos: (137 to 138) SpanInfo: {"start":119,"length":16}
59+
>WScript.Echo(x2)
60+
>:=> (line 9, col 4) to (line 9, col 20)
61+
--------------------------------
62+
11 >for (x in String)
63+
64+
~~~~~~~~~~~~~~~~~~ => Pos: (139 to 156) SpanInfo: {"start":139,"length":17}
65+
>for (x in String)
66+
>:=> (line 11, col 0) to (line 11, col 17)
67+
--------------------------------
68+
12 >{
69+
70+
~~ => Pos: (157 to 158) SpanInfo: {"start":163,"length":15}
71+
>WScript.Echo(x)
72+
>:=> (line 13, col 4) to (line 13, col 19)
73+
--------------------------------
74+
13 > WScript.Echo(x);
75+
76+
~~~~~~~~~~~~~~~~~~~~~ => Pos: (159 to 179) SpanInfo: {"start":163,"length":15}
77+
>WScript.Echo(x)
78+
>:=> (line 13, col 4) to (line 13, col 19)
79+
--------------------------------
80+
14 >}
81+
~ => Pos: (180 to 180) SpanInfo: {"start":163,"length":15}
82+
>WScript.Echo(x)
83+
>:=> (line 13, col 4) to (line 13, col 19)
File renamed without changes.

0 commit comments

Comments
 (0)