Breakpoints in the switch statement

This commit is contained in:
Sheetal Nandi 2014-10-17 20:13:55 -07:00
parent f5731f3e58
commit 5bdeaa9e6d
3 changed files with 194 additions and 0 deletions

View File

@ -103,6 +103,13 @@ module ts.BreakpointResolver {
case SyntaxKind.ForInStatement:
return spanInForInStatement(<ForInStatement>node);
case SyntaxKind.SwitchStatement:
return spanInSwitchStatement(<SwitchStatement>node);
case SyntaxKind.CaseClause:
case SyntaxKind.DefaultClause:
return spanInCaseOrDefaultClause(<CaseOrDefaultClause>node);
case SyntaxKind.BinaryExpression:
case SyntaxKind.PostfixOperator:
case SyntaxKind.PrefixOperator:
@ -317,6 +324,14 @@ module ts.BreakpointResolver {
return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement));
}
function spanInSwitchStatement(switchStatement: SwitchStatement): TypeScript.TextSpan {
return textSpan(switchStatement, findNextToken(switchStatement.expression, switchStatement));
}
function spanInCaseOrDefaultClause(caseOrDefaultClause: CaseOrDefaultClause): TypeScript.TextSpan {
return spanInNode(caseOrDefaultClause.statements[0]);
}
function spanInExpression(expression: Expression): TypeScript.TextSpan {
//TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) {
// Set span as if on while keyword
@ -354,6 +369,9 @@ module ts.BreakpointResolver {
case SyntaxKind.Block:
return spanInBlock(<Block>node.parent);
case SyntaxKind.SwitchStatement:
return spanInNodeIfStartsOnSameLine(node.parent, (<SwitchStatement>node.parent).clauses[0]);
// Default to parent node
default:
return spanInNode(node.parent);
@ -369,6 +387,15 @@ module ts.BreakpointResolver {
case SyntaxKind.Block:
return spanInLastStatementOfBlock(<Block>node.parent);
case SyntaxKind.SwitchStatement:
// breakpoint in last statement of the last clause
var switchStatement = <SwitchStatement>node.parent;
var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1];
if (lastClause) {
return spanInNode(lastClause.statements[lastClause.statements.length - 1]);
}
return undefined;
// Default to parent node
default:
return spanInNode(node.parent);

View File

@ -0,0 +1,167 @@
1 >var x = 10;
~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10}
>var x = 10
>:=> (line 1, col 0) to (line 1, col 10)
--------------------------------
2 >switch (x) {
~~~~~~~~~~~~~ => Pos: (12 to 24) SpanInfo: {"start":12,"length":10}
>switch (x)
>:=> (line 2, col 0) to (line 2, col 10)
--------------------------------
3 > case 5:
~~~~~~~~~~~~ => Pos: (25 to 36) SpanInfo: {"start":45,"length":3}
>x++
>:=> (line 4, col 8) to (line 4, col 11)
--------------------------------
4 > x++;
~~~~~~~~~~~~~ => Pos: (37 to 49) SpanInfo: {"start":45,"length":3}
>x++
>:=> (line 4, col 8) to (line 4, col 11)
--------------------------------
5 > break;
~~~~~~~~~~~~~~~ => Pos: (50 to 64) SpanInfo: {"start":58,"length":5}
>break
>:=> (line 5, col 8) to (line 5, col 13)
--------------------------------
6 > case 10:
~~~~~~~~~~~~~ => Pos: (65 to 77) SpanInfo: {"start":100,"length":3}
>x--
>:=> (line 8, col 12) to (line 8, col 15)
--------------------------------
7 > {
~~~~~~~~~~ => Pos: (78 to 87) SpanInfo: {"start":100,"length":3}
>x--
>:=> (line 8, col 12) to (line 8, col 15)
--------------------------------
8 > x--;
~~~~~~~~~~~~~~~~~ => Pos: (88 to 104) SpanInfo: {"start":100,"length":3}
>x--
>:=> (line 8, col 12) to (line 8, col 15)
--------------------------------
9 > break;
~~~~~~~~~~~~~~~~~~~ => Pos: (105 to 123) SpanInfo: {"start":117,"length":5}
>break
>:=> (line 9, col 12) to (line 9, col 17)
--------------------------------
10 > }
~~~~~~~~~~ => Pos: (124 to 133) SpanInfo: {"start":117,"length":5}
>break
>:=> (line 9, col 12) to (line 9, col 17)
--------------------------------
11 > default:
~~~~~~~~~~~~~ => Pos: (134 to 146) SpanInfo: {"start":155,"length":9}
>x = x *10
>:=> (line 12, col 8) to (line 12, col 17)
--------------------------------
12 > x = x *10;
~~~~~~~~~~~~~~~~~~~ => Pos: (147 to 165) SpanInfo: {"start":155,"length":9}
>x = x *10
>:=> (line 12, col 8) to (line 12, col 17)
--------------------------------
13 >}
~~ => Pos: (166 to 167) SpanInfo: {"start":155,"length":9}
>x = x *10
>:=> (line 12, col 8) to (line 12, col 17)
--------------------------------
14 >switch (x)
~~~~~~~~~~~ => Pos: (168 to 178) SpanInfo: {"start":168,"length":10}
>switch (x)
>:=> (line 14, col 0) to (line 14, col 10)
--------------------------------
15 >{
~~ => Pos: (179 to 180) SpanInfo: {"start":201,"length":3}
>x++
>:=> (line 17, col 8) to (line 17, col 11)
--------------------------------
16 > case 5:
~~~~~~~~~~~~ => Pos: (181 to 192) SpanInfo: {"start":201,"length":3}
>x++
>:=> (line 17, col 8) to (line 17, col 11)
--------------------------------
17 > x++;
~~~~~~~~~~~~~ => Pos: (193 to 205) SpanInfo: {"start":201,"length":3}
>x++
>:=> (line 17, col 8) to (line 17, col 11)
--------------------------------
18 > break;
~~~~~~~~~~~~~~~ => Pos: (206 to 220) SpanInfo: {"start":214,"length":5}
>break
>:=> (line 18, col 8) to (line 18, col 13)
--------------------------------
19 > case 10:
~~~~~~~~~~~~~ => Pos: (221 to 233) SpanInfo: {"start":256,"length":3}
>x--
>:=> (line 21, col 12) to (line 21, col 15)
--------------------------------
20 > {
~~~~~~~~~~ => Pos: (234 to 243) SpanInfo: {"start":256,"length":3}
>x--
>:=> (line 21, col 12) to (line 21, col 15)
--------------------------------
21 > x--;
~~~~~~~~~~~~~~~~~ => Pos: (244 to 260) SpanInfo: {"start":256,"length":3}
>x--
>:=> (line 21, col 12) to (line 21, col 15)
--------------------------------
22 > break;
~~~~~~~~~~~~~~~~~~~ => Pos: (261 to 279) SpanInfo: {"start":273,"length":5}
>break
>:=> (line 22, col 12) to (line 22, col 17)
--------------------------------
23 > }
~~~~~~~~~~ => Pos: (280 to 289) SpanInfo: {"start":273,"length":5}
>break
>:=> (line 22, col 12) to (line 22, col 17)
--------------------------------
24 > default:
~~~~~~~~~~~~~ => Pos: (290 to 302) SpanInfo: {"start":325,"length":10}
>x = x * 10
>:=> (line 26, col 12) to (line 26, col 22)
--------------------------------
25 > {
~~~~~~~~~~ => Pos: (303 to 312) SpanInfo: {"start":325,"length":10}
>x = x * 10
>:=> (line 26, col 12) to (line 26, col 22)
--------------------------------
26 > x = x * 10;
~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (313 to 336) SpanInfo: {"start":325,"length":10}
>x = x * 10
>:=> (line 26, col 12) to (line 26, col 22)
--------------------------------
27 > }
~~~~~~~~~~ => Pos: (337 to 346) SpanInfo: {"start":325,"length":10}
>x = x * 10
>:=> (line 26, col 12) to (line 26, col 22)
--------------------------------
28 >}
~ => Pos: (347 to 347) SpanInfo: {"start":325,"length":10}
>x = x * 10
>:=> (line 26, col 12) to (line 26, col 22)