Skip to content

Commit 7425aed

Browse files
committed
Breakpoints for if else construct
1 parent 71e96be commit 7425aed

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

src/services/breakpoints.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ module ts.BreakpointResolver {
4747
return spanInNode(findPrecedingToken(node.pos, sourceFile));
4848
}
4949

50+
function spanInNextNode(node: Node): TypeScript.TextSpan {
51+
return spanInNode(findNextToken(node, node.parent));
52+
}
53+
5054
function spanInNode(node: Node): TypeScript.TextSpan {
5155
if (node) {
5256
switch (node.kind) {
@@ -83,6 +87,9 @@ module ts.BreakpointResolver {
8387
case SyntaxKind.DebuggerStatement:
8488
return spanInDebuggerStatement(node);
8589

90+
case SyntaxKind.IfStatement:
91+
return spanInIfStatement(<IfStatement>node);
92+
8693
// Tokens:
8794
case SyntaxKind.SemicolonToken:
8895
case SyntaxKind.EndOfFileToken:
@@ -110,6 +117,9 @@ module ts.BreakpointResolver {
110117
case SyntaxKind.WhileKeyword:
111118
return spanInWhileKeyword(node);
112119

120+
case SyntaxKind.ElseKeyword:
121+
return spanInNextNode(node);
122+
113123
case SyntaxKind.BinaryExpression:
114124
//TODO (pick this up later) for now lets fix do-while baseline
115125
if (node.parent.kind === SyntaxKind.DoStatement) {
@@ -215,6 +225,7 @@ module ts.BreakpointResolver {
215225
switch (block.parent.kind) {
216226
// Set on parent if on same line otherwise on first statement
217227
case SyntaxKind.WhileStatement:
228+
case SyntaxKind.IfStatement:
218229
return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]);
219230
}
220231

@@ -243,6 +254,11 @@ module ts.BreakpointResolver {
243254
return textSpan(node.getChildAt(0, sourceFile));
244255
}
245256

257+
function spanInIfStatement(ifStatement: IfStatement): TypeScript.TextSpan {
258+
// set on if(..) span
259+
return textSpan(ifStatement, findNextToken(ifStatement.expression, ifStatement));
260+
}
261+
246262
// Tokens:
247263
function spanInCommaToken(node: Node): TypeScript.TextSpan {
248264
switch (node.parent.kind) {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
1 >var i = 10;
3+
4+
~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10}
5+
>var i = 10
6+
>:=> (line 1, col 0) to (line 1, col 10)
7+
--------------------------------
8+
2 >if (i == 10) {
9+
10+
~~~~~~~~~~~~~~~ => Pos: (12 to 26) SpanInfo: {"start":12,"length":12}
11+
>if (i == 10)
12+
>:=> (line 2, col 0) to (line 2, col 12)
13+
--------------------------------
14+
3 > i++;
15+
16+
~~~~~~~~~ => Pos: (27 to 35) SpanInfo: {"start":31,"length":3}
17+
>i++
18+
>:=> (line 3, col 4) to (line 3, col 7)
19+
--------------------------------
20+
4 >} else
21+
22+
~ => Pos: (36 to 36) SpanInfo: {"start":31,"length":3}
23+
>i++
24+
>:=> (line 3, col 4) to (line 3, col 7)
25+
4 >} else
26+
27+
~~~~~~ => Pos: (37 to 42) SpanInfo: undefined
28+
--------------------------------
29+
5 >{
30+
31+
~~ => Pos: (43 to 44) SpanInfo: undefined
32+
--------------------------------
33+
6 >}
34+
35+
~~ => Pos: (45 to 46) SpanInfo: undefined
36+
--------------------------------
37+
7 >if (i == 10)
38+
39+
~~~~~~~~~~~~~ => Pos: (47 to 59) SpanInfo: {"start":47,"length":12}
40+
>if (i == 10)
41+
>:=> (line 7, col 0) to (line 7, col 12)
42+
--------------------------------
43+
8 >{
44+
45+
~~ => Pos: (60 to 61) SpanInfo: {"start":66,"length":3}
46+
>i++
47+
>:=> (line 9, col 4) to (line 9, col 7)
48+
--------------------------------
49+
9 > i++;
50+
51+
~~~~~~~~~ => Pos: (62 to 70) SpanInfo: {"start":66,"length":3}
52+
>i++
53+
>:=> (line 9, col 4) to (line 9, col 7)
54+
--------------------------------
55+
10 >}
56+
57+
~~ => Pos: (71 to 72) SpanInfo: {"start":66,"length":3}
58+
>i++
59+
>:=> (line 9, col 4) to (line 9, col 7)
60+
--------------------------------
61+
11 >else if (i == 20) {
62+
63+
~~~~~~~~~~~~~~~~~~~~ => Pos: (73 to 92) SpanInfo: {"start":78,"length":12}
64+
>if (i == 20)
65+
>:=> (line 11, col 5) to (line 11, col 17)
66+
--------------------------------
67+
12 > i--;
68+
69+
~~~~~~~~~ => Pos: (93 to 101) SpanInfo: {"start":97,"length":3}
70+
>i--
71+
>:=> (line 12, col 4) to (line 12, col 7)
72+
--------------------------------
73+
13 >} else if (i == 30) {
74+
75+
~ => Pos: (102 to 102) SpanInfo: {"start":97,"length":3}
76+
>i--
77+
>:=> (line 12, col 4) to (line 12, col 7)
78+
13 >} else if (i == 30) {
79+
80+
~~~~~~~~~~~~~~~~~~~~~ => Pos: (103 to 123) SpanInfo: {"start":109,"length":12}
81+
>if (i == 30)
82+
>:=> (line 13, col 7) to (line 13, col 19)
83+
--------------------------------
84+
14 > i += 70;
85+
86+
~~~~~~~~~~~~~ => Pos: (124 to 136) SpanInfo: {"start":128,"length":7}
87+
>i += 70
88+
>:=> (line 14, col 4) to (line 14, col 11)
89+
--------------------------------
90+
15 >} else {
91+
92+
~ => Pos: (137 to 137) SpanInfo: {"start":128,"length":7}
93+
>i += 70
94+
>:=> (line 14, col 4) to (line 14, col 11)
95+
15 >} else {
96+
97+
~~~~~~~~ => Pos: (138 to 145) SpanInfo: {"start":150,"length":3}
98+
>i--
99+
>:=> (line 16, col 4) to (line 16, col 7)
100+
--------------------------------
101+
16 > i--;
102+
103+
~~~~~~~~~ => Pos: (146 to 154) SpanInfo: {"start":150,"length":3}
104+
>i--
105+
>:=> (line 16, col 4) to (line 16, col 7)
106+
--------------------------------
107+
17 >}
108+
~ => Pos: (155 to 155) SpanInfo: {"start":150,"length":3}
109+
>i--
110+
>:=> (line 16, col 4) to (line 16, col 7)

0 commit comments

Comments
 (0)