From 7425aedd592d1dd268a427bf1ac59a0407948fdc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Oct 2014 15:45:17 -0700 Subject: [PATCH] Breakpoints for if else construct --- src/services/breakpoints.ts | 16 +++ .../reference/bpSpan_ifElse.baseline | 110 ++++++++++++++++++ .../breakpointValidationIfElse.ts | 0 3 files changed, 126 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_ifElse.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationIfElse.ts (100%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 56146b9d60d..4398b559f66 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -47,6 +47,10 @@ module ts.BreakpointResolver { return spanInNode(findPrecedingToken(node.pos, sourceFile)); } + function spanInNextNode(node: Node): TypeScript.TextSpan { + return spanInNode(findNextToken(node, node.parent)); + } + function spanInNode(node: Node): TypeScript.TextSpan { if (node) { switch (node.kind) { @@ -83,6 +87,9 @@ module ts.BreakpointResolver { case SyntaxKind.DebuggerStatement: return spanInDebuggerStatement(node); + case SyntaxKind.IfStatement: + return spanInIfStatement(node); + // Tokens: case SyntaxKind.SemicolonToken: case SyntaxKind.EndOfFileToken: @@ -110,6 +117,9 @@ module ts.BreakpointResolver { case SyntaxKind.WhileKeyword: return spanInWhileKeyword(node); + case SyntaxKind.ElseKeyword: + return spanInNextNode(node); + case SyntaxKind.BinaryExpression: //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { @@ -215,6 +225,7 @@ module ts.BreakpointResolver { switch (block.parent.kind) { // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: + case SyntaxKind.IfStatement: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); } @@ -243,6 +254,11 @@ module ts.BreakpointResolver { return textSpan(node.getChildAt(0, sourceFile)); } + function spanInIfStatement(ifStatement: IfStatement): TypeScript.TextSpan { + // set on if(..) span + return textSpan(ifStatement, findNextToken(ifStatement.expression, ifStatement)); + } + // Tokens: function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { diff --git a/tests/baselines/reference/bpSpan_ifElse.baseline b/tests/baselines/reference/bpSpan_ifElse.baseline new file mode 100644 index 00000000000..c325ade25f0 --- /dev/null +++ b/tests/baselines/reference/bpSpan_ifElse.baseline @@ -0,0 +1,110 @@ + +1 >var i = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var i = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 >if (i == 10) { + + ~~~~~~~~~~~~~~~ => Pos: (12 to 26) SpanInfo: {"start":12,"length":12} + >if (i == 10) + >:=> (line 2, col 0) to (line 2, col 12) +-------------------------------- +3 > i++; + + ~~~~~~~~~ => Pos: (27 to 35) SpanInfo: {"start":31,"length":3} + >i++ + >:=> (line 3, col 4) to (line 3, col 7) +-------------------------------- +4 >} else + + ~ => Pos: (36 to 36) SpanInfo: {"start":31,"length":3} + >i++ + >:=> (line 3, col 4) to (line 3, col 7) +4 >} else + + ~~~~~~ => Pos: (37 to 42) SpanInfo: undefined +-------------------------------- +5 >{ + + ~~ => Pos: (43 to 44) SpanInfo: undefined +-------------------------------- +6 >} + + ~~ => Pos: (45 to 46) SpanInfo: undefined +-------------------------------- +7 >if (i == 10) + + ~~~~~~~~~~~~~ => Pos: (47 to 59) SpanInfo: {"start":47,"length":12} + >if (i == 10) + >:=> (line 7, col 0) to (line 7, col 12) +-------------------------------- +8 >{ + + ~~ => Pos: (60 to 61) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +9 > i++; + + ~~~~~~~~~ => Pos: (62 to 70) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +10 >} + + ~~ => Pos: (71 to 72) SpanInfo: {"start":66,"length":3} + >i++ + >:=> (line 9, col 4) to (line 9, col 7) +-------------------------------- +11 >else if (i == 20) { + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (73 to 92) SpanInfo: {"start":78,"length":12} + >if (i == 20) + >:=> (line 11, col 5) to (line 11, col 17) +-------------------------------- +12 > i--; + + ~~~~~~~~~ => Pos: (93 to 101) SpanInfo: {"start":97,"length":3} + >i-- + >:=> (line 12, col 4) to (line 12, col 7) +-------------------------------- +13 >} else if (i == 30) { + + ~ => Pos: (102 to 102) SpanInfo: {"start":97,"length":3} + >i-- + >:=> (line 12, col 4) to (line 12, col 7) +13 >} else if (i == 30) { + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (103 to 123) SpanInfo: {"start":109,"length":12} + >if (i == 30) + >:=> (line 13, col 7) to (line 13, col 19) +-------------------------------- +14 > i += 70; + + ~~~~~~~~~~~~~ => Pos: (124 to 136) SpanInfo: {"start":128,"length":7} + >i += 70 + >:=> (line 14, col 4) to (line 14, col 11) +-------------------------------- +15 >} else { + + ~ => Pos: (137 to 137) SpanInfo: {"start":128,"length":7} + >i += 70 + >:=> (line 14, col 4) to (line 14, col 11) +15 >} else { + + ~~~~~~~~ => Pos: (138 to 145) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +16 > i--; + + ~~~~~~~~~ => Pos: (146 to 154) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) +-------------------------------- +17 >} + ~ => Pos: (155 to 155) SpanInfo: {"start":150,"length":3} + >i-- + >:=> (line 16, col 4) to (line 16, col 7) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationIfElse.ts b/tests/cases/fourslash/breakpointValidationIfElse.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationIfElse.ts rename to tests/cases/fourslash/breakpointValidationIfElse.ts