mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Breakpoints for while statement
This commit is contained in:
parent
35cdea1a0e
commit
abb0acc639
@ -36,10 +36,11 @@ module ts.BreakpointResolver {
|
||||
return TypeScript.TextSpan.fromBounds(startNode.getStart(), (endNode || startNode).getEnd());
|
||||
}
|
||||
|
||||
function spanInNodeIfStartsOnSameLine(node: Node): TypeScript.TextSpan {
|
||||
function spanInNodeIfStartsOnSameLine(node: Node, otherwiseOnNode?: Node): TypeScript.TextSpan {
|
||||
if (node && sourceFile.getLineAndCharacterFromPosition(position).line === sourceFile.getLineAndCharacterFromPosition(node.getStart()).line) {
|
||||
return spanInNode(node);
|
||||
}
|
||||
return spanInNode(otherwiseOnNode);
|
||||
}
|
||||
|
||||
function spanInPreviousNode(node: Node): TypeScript.TextSpan {
|
||||
@ -62,7 +63,7 @@ module ts.BreakpointResolver {
|
||||
return spanInFunctionDeclaration(<FunctionDeclaration>node);
|
||||
|
||||
case SyntaxKind.FunctionBlock:
|
||||
return spanInBlock(<Block>node);
|
||||
return spanInFirstStatementOfBlock(<Block>node);
|
||||
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
return spanInExpressionStatement(<ExpressionStatement>node);
|
||||
@ -70,6 +71,9 @@ module ts.BreakpointResolver {
|
||||
case SyntaxKind.ReturnStatement:
|
||||
return spanInReturnStatement(<ReturnStatement>node);
|
||||
|
||||
case SyntaxKind.WhileStatement:
|
||||
return spanInWhileStatement(<WhileStatement>node);
|
||||
|
||||
// Tokens:
|
||||
case SyntaxKind.SemicolonToken:
|
||||
case SyntaxKind.EndOfFileToken:
|
||||
@ -173,11 +177,27 @@ module ts.BreakpointResolver {
|
||||
return spanInNode(functionDeclaration.body);
|
||||
}
|
||||
|
||||
function spanInBlock(block: Block): TypeScript.TextSpan {
|
||||
function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan {
|
||||
// Set breakpoint in first statement
|
||||
return spanInNode(block.statements[0]);
|
||||
}
|
||||
|
||||
function spanInLastStatementOfBlock(block: Block): TypeScript.TextSpan {
|
||||
// Set breakpoint in first statement
|
||||
return spanInNode(block.statements[block.statements.length - 1]);
|
||||
}
|
||||
|
||||
function spanInBlock(block: Block): TypeScript.TextSpan {
|
||||
switch (block.parent.kind) {
|
||||
// Set on parent if on same line otherwise on first statement
|
||||
case SyntaxKind.WhileStatement:
|
||||
return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]);
|
||||
}
|
||||
|
||||
// Default action is to set on first statement
|
||||
return spanInFirstStatementOfBlock(block);
|
||||
}
|
||||
|
||||
function spanInExpressionStatement(expressionStatement: ExpressionStatement): TypeScript.TextSpan {
|
||||
return textSpan(expressionStatement.expression);
|
||||
}
|
||||
@ -186,6 +206,10 @@ module ts.BreakpointResolver {
|
||||
return textSpan(returnStatement.getChildAt(0, sourceFile), returnStatement.expression);
|
||||
}
|
||||
|
||||
function spanInWhileStatement(whileStatement: WhileStatement): TypeScript.TextSpan {
|
||||
return textSpan(whileStatement, findNextToken(whileStatement.expression, whileStatement));
|
||||
}
|
||||
|
||||
// Tokens:
|
||||
function spanInCommaToken(node: Node): TypeScript.TextSpan {
|
||||
switch (node.parent.kind) {
|
||||
@ -202,6 +226,10 @@ module ts.BreakpointResolver {
|
||||
function spanInOpenBraceToken(node: Node): TypeScript.TextSpan {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.FunctionBlock:
|
||||
// Span on first statement
|
||||
return spanInFirstStatementOfBlock(<Block>node.parent);
|
||||
|
||||
case SyntaxKind.Block:
|
||||
return spanInBlock(<Block>node.parent);
|
||||
|
||||
// Default to parent node
|
||||
@ -216,6 +244,9 @@ module ts.BreakpointResolver {
|
||||
// Span on close brace token
|
||||
return textSpan(node);
|
||||
|
||||
case SyntaxKind.Block:
|
||||
return spanInLastStatementOfBlock(<Block>node.parent);
|
||||
|
||||
// Default to parent node
|
||||
default:
|
||||
return spanInNode(node.parent);
|
||||
@ -224,7 +255,8 @@ module ts.BreakpointResolver {
|
||||
|
||||
function spanInCloseParenToken(node: Node): TypeScript.TextSpan {
|
||||
// Is this close paren token of parameter list, set span in previous token
|
||||
if (isAnyFunction(node.parent)) {
|
||||
if (isAnyFunction(node.parent) ||
|
||||
node.parent.kind === SyntaxKind.WhileStatement) {
|
||||
return spanInPreviousNode(node);
|
||||
}
|
||||
|
||||
|
||||
70
tests/baselines/reference/bpSpan_while.baseline
Normal file
70
tests/baselines/reference/bpSpan_while.baseline
Normal file
@ -0,0 +1,70 @@
|
||||
|
||||
1 >var a = 10;
|
||||
|
||||
~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10}
|
||||
>var a = 10
|
||||
>:=> (line 1, col 0) to (line 1, col 10)
|
||||
--------------------------------
|
||||
2 >while (a == 10) {
|
||||
|
||||
~~~~~~~~~~~~~~~~~~ => Pos: (12 to 29) SpanInfo: {"start":12,"length":15}
|
||||
>while (a == 10)
|
||||
>:=> (line 2, col 0) to (line 2, col 15)
|
||||
--------------------------------
|
||||
3 > a++;
|
||||
|
||||
~~~~~~~~~ => Pos: (30 to 38) SpanInfo: {"start":34,"length":3}
|
||||
>a++
|
||||
>:=> (line 3, col 4) to (line 3, col 7)
|
||||
--------------------------------
|
||||
4 >}
|
||||
|
||||
~~ => Pos: (39 to 40) SpanInfo: {"start":34,"length":3}
|
||||
>a++
|
||||
>:=> (line 3, col 4) to (line 3, col 7)
|
||||
--------------------------------
|
||||
5 >while (a == 10)
|
||||
|
||||
~~~~~~~~~~~~~~~~~ => Pos: (41 to 57) SpanInfo: {"start":41,"length":15}
|
||||
>while (a == 10)
|
||||
>:=> (line 5, col 0) to (line 5, col 15)
|
||||
--------------------------------
|
||||
6 >{
|
||||
|
||||
~~ => Pos: (58 to 59) SpanInfo: {"start":64,"length":3}
|
||||
>a++
|
||||
>:=> (line 7, col 4) to (line 7, col 7)
|
||||
--------------------------------
|
||||
7 > a++;
|
||||
|
||||
~~~~~~~~~ => Pos: (60 to 68) SpanInfo: {"start":64,"length":3}
|
||||
>a++
|
||||
>:=> (line 7, col 4) to (line 7, col 7)
|
||||
--------------------------------
|
||||
8 >}
|
||||
|
||||
~~ => Pos: (69 to 70) SpanInfo: {"start":64,"length":3}
|
||||
>a++
|
||||
>:=> (line 7, col 4) to (line 7, col 7)
|
||||
--------------------------------
|
||||
9 >while (a == 10) a++;
|
||||
|
||||
~~~~~~~~~~~~~~~ => Pos: (71 to 85) SpanInfo: {"start":71,"length":15}
|
||||
>while (a == 10)
|
||||
>:=> (line 9, col 0) to (line 9, col 15)
|
||||
9 >while (a == 10) a++;
|
||||
|
||||
~~~~~~~ => Pos: (86 to 92) SpanInfo: {"start":88,"length":3}
|
||||
>a++
|
||||
>:=> (line 9, col 17) to (line 9, col 20)
|
||||
--------------------------------
|
||||
10 >while (a == 10)
|
||||
|
||||
~~~~~~~~~~~~~~~~~ => Pos: (93 to 109) SpanInfo: {"start":93,"length":15}
|
||||
>while (a == 10)
|
||||
>:=> (line 10, col 0) to (line 10, col 15)
|
||||
--------------------------------
|
||||
11 > a++;
|
||||
~~~~~~~~ => Pos: (110 to 117) SpanInfo: {"start":114,"length":3}
|
||||
>a++
|
||||
>:=> (line 11, col 4) to (line 11, col 7)
|
||||
@ -10,4 +10,7 @@
|
||||
////{
|
||||
//// a++;
|
||||
////}
|
||||
////while (a == 10) a++;
|
||||
////while (a == 10)
|
||||
//// a++;
|
||||
verify.baselineCurrentFileBreakpointLocations();
|
||||
Loading…
x
Reference in New Issue
Block a user