From f5731f3e5850cf2beafe7f7038e039985dbaf38d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 2 Sep 2014 14:59:01 -0700 Subject: [PATCH] Breakpoints in the for in statement --- src/services/breakpoints.ts | 13 +++ .../baselines/reference/bpSpan_forIn.baseline | 83 +++++++++++++++++++ .../breakpointValidationForIn.ts | 0 3 files changed, 96 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_forIn.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationForIn.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 5235fd2829c..49483e87546 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -100,6 +100,9 @@ module ts.BreakpointResolver { case SyntaxKind.ForStatement: return spanInForStatement(node); + case SyntaxKind.ForInStatement: + return spanInForInStatement(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -142,6 +145,11 @@ module ts.BreakpointResolver { } function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TypeScript.TextSpan { + // If declaration of for in statement, just set the span in parent + if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) { + return spanInForInStatement(variableDeclaration.parent); + } + var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((variableDeclaration.parent).declarations, variableDeclaration); var declarations = isParentVariableStatement @@ -243,6 +251,7 @@ module ts.BreakpointResolver { // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: case SyntaxKind.IfStatement: + case SyntaxKind.ForInStatement: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); // 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 { } } + function spanInForInStatement(forInStatement: ForInStatement): TypeScript.TextSpan { + return textSpan(forInStatement, findNextToken(forInStatement.expression, forInStatement)); + } + 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 diff --git a/tests/baselines/reference/bpSpan_forIn.baseline b/tests/baselines/reference/bpSpan_forIn.baseline new file mode 100644 index 00000000000..5c2e6b6d01e --- /dev/null +++ b/tests/baselines/reference/bpSpan_forIn.baseline @@ -0,0 +1,83 @@ + +1 >for (var x in String) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: {"start":0,"length":21} + >for (var x in String) + >:=> (line 1, col 0) to (line 1, col 21) +-------------------------------- +2 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 44) SpanInfo: {"start":28,"length":15} + >WScript.Echo(x) + >:=> (line 2, col 4) to (line 2, col 19) +-------------------------------- +3 >} + + ~~ => Pos: (45 to 46) SpanInfo: {"start":28,"length":15} + >WScript.Echo(x) + >:=> (line 2, col 4) to (line 2, col 19) +-------------------------------- +4 >for (x in String) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (47 to 66) SpanInfo: {"start":47,"length":17} + >for (x in String) + >:=> (line 4, col 0) to (line 4, col 17) +-------------------------------- +5 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 87) SpanInfo: {"start":71,"length":15} + >WScript.Echo(x) + >:=> (line 5, col 4) to (line 5, col 19) +-------------------------------- +6 >} + + ~~ => Pos: (88 to 89) SpanInfo: {"start":71,"length":15} + >WScript.Echo(x) + >:=> (line 5, col 4) to (line 5, col 19) +-------------------------------- +7 >for (var x2 in String) + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (90 to 112) SpanInfo: {"start":90,"length":22} + >for (var x2 in String) + >:=> (line 7, col 0) to (line 7, col 22) +-------------------------------- +8 >{ + + ~~ => Pos: (113 to 114) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +9 > WScript.Echo(x2); + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (115 to 136) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +10 >} + + ~~ => Pos: (137 to 138) SpanInfo: {"start":119,"length":16} + >WScript.Echo(x2) + >:=> (line 9, col 4) to (line 9, col 20) +-------------------------------- +11 >for (x in String) + + ~~~~~~~~~~~~~~~~~~ => Pos: (139 to 156) SpanInfo: {"start":139,"length":17} + >for (x in String) + >:=> (line 11, col 0) to (line 11, col 17) +-------------------------------- +12 >{ + + ~~ => Pos: (157 to 158) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +13 > WScript.Echo(x); + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (159 to 179) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) +-------------------------------- +14 >} + ~ => Pos: (180 to 180) SpanInfo: {"start":163,"length":15} + >WScript.Echo(x) + >:=> (line 13, col 4) to (line 13, col 19) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationForIn.ts b/tests/cases/fourslash/breakpointValidationForIn.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationForIn.ts rename to tests/cases/fourslash/breakpointValidationForIn.ts