Breakpoints in classes

This commit is contained in:
Sheetal Nandi
2014-10-20 23:05:35 -07:00
parent b54d20d52b
commit 330065fdeb
7 changed files with 197 additions and 18 deletions
+34 -14
View File
@@ -58,16 +58,21 @@ module ts.BreakpointResolver {
return spanInVariableStatement(<VariableStatement>node);
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
return spanInVariableDeclaration(<VariableDeclaration>node);
case SyntaxKind.Parameter:
return spanInParameterDeclaration(<ParameterDeclaration>node);
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Method:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.Constructor:
return spanInFunctionDeclaration(<FunctionDeclaration>node);
case SyntaxKind.FunctionBlock:
return spanInFirstStatementOfBlock(<Block>node);
return spanInFunctionBlock(<Block>node);
case SyntaxKind.Block:
case SyntaxKind.TryBlock:
@@ -136,8 +141,7 @@ module ts.BreakpointResolver {
return spanInModuleDeclaration(<ModuleDeclaration>node);
case SyntaxKind.ClassDeclaration:
// TODO
return;
return spanInClassDeclaration(<ClassDeclaration>node);
case SyntaxKind.BinaryExpression:
case SyntaxKind.PostfixOperator:
@@ -274,6 +278,15 @@ module ts.BreakpointResolver {
return spanInNode(functionDeclaration.body);
}
function spanInFunctionBlock(block: Block): TypeScript.TextSpan {
if (block.statements.length) {
return spanInFirstStatementOfBlock(block);
}
// On close parenthesis
return spanInNode(block.getLastToken());
}
function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan {
// Set breakpoint in first statement
return spanInNode(block.statements[0]);
@@ -396,6 +409,14 @@ module ts.BreakpointResolver {
return spanInNode(moduleDeclaration.body);
}
function spanInClassDeclaration(classDeclaration: ClassDeclaration): TypeScript.TextSpan {
if (classDeclaration.members.length) {
return spanInNode(classDeclaration.members[0]);
}
return spanInNode(classDeclaration.getLastToken());
}
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
@@ -415,6 +436,10 @@ module ts.BreakpointResolver {
function spanInCommaToken(node: Node): TypeScript.TextSpan {
switch (node.parent.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Method:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.Constructor:
case SyntaxKind.VariableStatement:
case SyntaxKind.EnumDeclaration:
return spanInPreviousNode(node);
@@ -426,24 +451,19 @@ 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.SwitchStatement:
return spanInNodeIfStartsOnSameLine(node.parent, (<SwitchStatement>node.parent).clauses[0]);
// Default to parent node
default:
return spanInNode(node.parent);
if (node.parent.kind === SyntaxKind.SwitchStatement) {
return spanInNodeIfStartsOnSameLine(node.parent, (<SwitchStatement>node.parent).clauses[0]);
}
// Default to parent node
return spanInNode(node.parent);
}
function spanInCloseBraceToken(node: Node): TypeScript.TextSpan {
switch (node.parent.kind) {
case SyntaxKind.FunctionBlock:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ClassDeclaration:
// Span on close brace token
return textSpan(node);
@@ -0,0 +1,120 @@
1 >class Greeter {
~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":79,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
--------------------------------
2 > constructor(public greeting: string, ...b: string[]) {
~~~~~~~~~~~~~~~~ => Pos: (16 to 31) SpanInfo: {"start":79,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
2 > constructor(public greeting: string, ...b: string[]) {
~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (32 to 55) SpanInfo: {"start":32,"length":23}
>public greeting: string
>:=> (line 2, col 16) to (line 2, col 39)
2 > constructor(public greeting: string, ...b: string[]) {
~~~~~~~~~~~~~~~~=> Pos: (56 to 71) SpanInfo: {"start":57,"length":14}
>...b: string[]
>:=> (line 2, col 41) to (line 2, col 55)
2 > constructor(public greeting: string, ...b: string[]) {
~~~=> Pos: (72 to 74) SpanInfo: {"start":79,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
--------------------------------
3 > }
~~~~~~ => Pos: (75 to 80) SpanInfo: {"start":79,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
--------------------------------
4 > greet() {
~~~~~~~~~~~~~~ => Pos: (81 to 94) SpanInfo: {"start":103,"length":39}
>return "<h1>" + this.greeting + "</h1>"
>:=> (line 5, col 8) to (line 5, col 47)
--------------------------------
5 > return "<h1>" + this.greeting + "</h1>";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (95 to 143) SpanInfo: {"start":103,"length":39}
>return "<h1>" + this.greeting + "</h1>"
>:=> (line 5, col 8) to (line 5, col 47)
--------------------------------
6 > }
~~~~~~ => Pos: (144 to 149) SpanInfo: {"start":148,"length":1}
>}
>:=> (line 6, col 4) to (line 6, col 5)
--------------------------------
7 > private x: string;
~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (150 to 172) SpanInfo: undefined
--------------------------------
8 > private x1: number = 10;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (173 to 201) SpanInfo: {"start":177,"length":24}
>private x1: number = 10;
>:=> (line 8, col 4) to (line 8, col 28)
--------------------------------
9 > private fn() {
~~~~~~~~~~~~~~~~~~~ => Pos: (202 to 220) SpanInfo: {"start":229,"length":20}
>return this.greeting
>:=> (line 10, col 8) to (line 10, col 28)
--------------------------------
10 > return this.greeting;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (221 to 250) SpanInfo: {"start":229,"length":20}
>return this.greeting
>:=> (line 10, col 8) to (line 10, col 28)
--------------------------------
11 > }
~~~~~~ => Pos: (251 to 256) SpanInfo: {"start":255,"length":1}
>}
>:=> (line 11, col 4) to (line 11, col 5)
--------------------------------
12 > get greetings() {
~~~~~~~~~~~~~~~~~~~~~~ => Pos: (257 to 278) SpanInfo: {"start":287,"length":20}
>return this.greeting
>:=> (line 13, col 8) to (line 13, col 28)
--------------------------------
13 > return this.greeting;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (279 to 308) SpanInfo: {"start":287,"length":20}
>return this.greeting
>:=> (line 13, col 8) to (line 13, col 28)
--------------------------------
14 > }
~~~~~~ => Pos: (309 to 314) SpanInfo: {"start":313,"length":1}
>}
>:=> (line 14, col 4) to (line 14, col 5)
--------------------------------
15 > set greetings(greetings: string) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (315 to 353) SpanInfo: {"start":362,"length":25}
>this.greeting = greetings
>:=> (line 16, col 8) to (line 16, col 33)
--------------------------------
16 > this.greeting = greetings;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (354 to 388) SpanInfo: {"start":362,"length":25}
>this.greeting = greetings
>:=> (line 16, col 8) to (line 16, col 33)
--------------------------------
17 > }
~~~~~~ => Pos: (389 to 394) SpanInfo: {"start":393,"length":1}
>}
>:=> (line 17, col 4) to (line 17, col 5)
--------------------------------
18 >}
~ => Pos: (395 to 395) SpanInfo: {"start":395,"length":1}
>}
>:=> (line 18, col 0) to (line 18, col 1)
@@ -0,0 +1,31 @@
1 >declare class Greeter {
~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: undefined
--------------------------------
2 > public greeting: string;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 52) SpanInfo: undefined
--------------------------------
3 > constructor(greeting: string, ...b: string[]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (53 to 103) SpanInfo: undefined
--------------------------------
4 > greet(): string;
~~~~~~~~~~~~~~~~~~~~~ => Pos: (104 to 124) SpanInfo: undefined
--------------------------------
5 > private val;
~~~~~~~~~~~~~~~~~ => Pos: (125 to 141) SpanInfo: undefined
--------------------------------
6 > static x: number;
~~~~~~~~~~~~~~~~~~~~~~ => Pos: (142 to 163) SpanInfo: undefined
--------------------------------
7 > static fn(a: number, ...b:string[]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (164 to 204) SpanInfo: undefined
--------------------------------
8 >}
~ => Pos: (205 to 205) SpanInfo: undefined
@@ -9,7 +9,9 @@
--------------------------------
3 >}
~~ => Pos: (24 to 25) SpanInfo: undefined
~~ => Pos: (24 to 25) SpanInfo: {"start":24,"length":1}
>}
>:=> (line 3, col 0) to (line 3, col 1)
--------------------------------
4 >export = a;
~~~~~~~~~~~ => Pos: (26 to 36) SpanInfo: {"start":26,"length":10}
@@ -1,15 +1,21 @@
1 >module m {
~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: undefined
~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":29,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
--------------------------------
2 > class c {
~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: undefined
~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: {"start":29,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
--------------------------------
3 > }
~~~~~~ => Pos: (25 to 30) SpanInfo: undefined
~~~~~~ => Pos: (25 to 30) SpanInfo: {"start":29,"length":1}
>}
>:=> (line 3, col 4) to (line 3, col 5)
--------------------------------
4 >}