diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index fc62884e333..e5dc722d7ea 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -70,6 +70,9 @@ module ts.BreakpointResolver { return spanInFirstStatementOfBlock(node); case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: return spanInBlock(node); case SyntaxKind.ExpressionStatement: @@ -110,6 +113,12 @@ module ts.BreakpointResolver { case SyntaxKind.DefaultClause: return spanInCaseOrDefaultClause(node); + case SyntaxKind.TryStatement: + return spanInTryStatement(node); + + case SyntaxKind.ThrowStatement: + return spanInThrowStatement(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -143,6 +152,8 @@ module ts.BreakpointResolver { return spanInWhileKeyword(node); case SyntaxKind.ElseKeyword: + case SyntaxKind.CatchKeyword: + case SyntaxKind.FinallyKeyword: return spanInNextNode(node); default: @@ -332,6 +343,14 @@ module ts.BreakpointResolver { return spanInNode(caseOrDefaultClause.statements[0]); } + function spanInTryStatement(tryStatement: TryStatement): TypeScript.TextSpan { + return spanInBlock(tryStatement.tryBlock); + } + + function spanInThrowStatement(throwStatement: ThrowStatement): TypeScript.TextSpan { + return textSpan(throwStatement, throwStatement.expression); + } + 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 @@ -367,6 +386,9 @@ module ts.BreakpointResolver { return spanInFirstStatementOfBlock(node.parent); case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: return spanInBlock(node.parent); case SyntaxKind.SwitchStatement: @@ -385,6 +407,9 @@ module ts.BreakpointResolver { return textSpan(node); case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: return spanInLastStatementOfBlock(node.parent); case SyntaxKind.SwitchStatement: diff --git a/tests/baselines/reference/bpSpan_tryCatchFinally.baseline b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline new file mode 100644 index 00000000000..69e2fb0e136 --- /dev/null +++ b/tests/baselines/reference/bpSpan_tryCatchFinally.baseline @@ -0,0 +1,135 @@ + +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 >try { + + ~~~~~~ => Pos: (12 to 17) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +3 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (18 to 32) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +-------------------------------- +4 >} catch (e) { + + ~ => Pos: (33 to 33) SpanInfo: {"start":22,"length":9} + >x = x + 1 + >:=> (line 3, col 4) to (line 3, col 13) +4 >} catch (e) { + + ~~~~~~~~~~~~~ => Pos: (34 to 46) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +-------------------------------- +5 > x = x - 1; + + ~~~~~~~~~~~~~~~ => Pos: (47 to 61) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +-------------------------------- +6 >} finally { + + ~ => Pos: (62 to 62) SpanInfo: {"start":51,"length":9} + >x = x - 1 + >:=> (line 5, col 4) to (line 5, col 13) +6 >} finally { + + ~~~~~~~~~~~ => Pos: (63 to 73) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +7 > x = x * 10; + + ~~~~~~~~~~~~~~~~ => Pos: (74 to 89) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +8 >} + + ~~ => Pos: (90 to 91) SpanInfo: {"start":78,"length":10} + >x = x * 10 + >:=> (line 7, col 4) to (line 7, col 14) +-------------------------------- +9 >try + + ~~~~ => Pos: (92 to 95) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +10 >{ + + ~~ => Pos: (96 to 97) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +11 > x = x + 1; + + ~~~~~~~~~~~~~~~ => Pos: (98 to 112) SpanInfo: {"start":102,"length":9} + >x = x + 1 + >:=> (line 11, col 4) to (line 11, col 13) +-------------------------------- +12 > throw new Error(); + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (113 to 135) SpanInfo: {"start":117,"length":17} + >throw new Error() + >:=> (line 12, col 4) to (line 12, col 21) +-------------------------------- +13 >} + + ~~ => Pos: (136 to 137) SpanInfo: {"start":117,"length":17} + >throw new Error() + >:=> (line 12, col 4) to (line 12, col 21) +-------------------------------- +14 >catch (e) + + ~~~~~~~~~~ => Pos: (138 to 147) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +15 >{ + + ~~ => Pos: (148 to 149) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +16 > x = x - 1; + + ~~~~~~~~~~~~~~~ => Pos: (150 to 164) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +17 >} + + ~~ => Pos: (165 to 166) SpanInfo: {"start":154,"length":9} + >x = x - 1 + >:=> (line 16, col 4) to (line 16, col 13) +-------------------------------- +18 >finally + + ~~~~~~~~ => Pos: (167 to 174) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +19 >{ + + ~~ => Pos: (175 to 176) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +20 > x = x * 10; + + ~~~~~~~~~~~~~~~~ => Pos: (177 to 192) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) +-------------------------------- +21 >} + ~ => Pos: (193 to 193) SpanInfo: {"start":181,"length":10} + >x = x * 10 + >:=> (line 20, col 4) to (line 20, col 14) \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts b/tests/cases/fourslash/breakpointValidationTryCatchFinally.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts rename to tests/cases/fourslash/breakpointValidationTryCatchFinally.ts