Breakpoint span on module and its name is set on whole declaration if it is instantiated

This commit is contained in:
Sheetal Nandi
2014-10-21 12:55:46 -07:00
parent a410133039
commit b72b3ac850
6 changed files with 291 additions and 34 deletions

View File

@@ -146,7 +146,7 @@ module ts.BreakpointResolver {
case SyntaxKind.ForStatement:
return spanInForStatement(<ForStatement>node);
case SyntaxKind.ForInStatement:
// span on for (a in ...)
return textSpan(node, findNextToken((<ForInStatement>node).expression, node));
@@ -176,6 +176,12 @@ module ts.BreakpointResolver {
// import statement without including semicolon
return textSpan(node, (<ImportDeclaration>node).entityName || (<ImportDeclaration>node).externalModuleName);
case SyntaxKind.ModuleDeclaration:
// span on complete module if it is instantiated
if (!isInstantiated(node)) {
return undefined;
}
case SyntaxKind.EnumDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.CallExpression:
@@ -183,10 +189,6 @@ module ts.BreakpointResolver {
// span on complete node
return textSpan(node);
case SyntaxKind.ModuleDeclaration:
// span in module body
return spanInNode((<ModuleDeclaration>node).body);
case SyntaxKind.ClassDeclaration:
return spanInClassDeclaration(<ClassDeclaration>node);
@@ -349,6 +351,11 @@ module ts.BreakpointResolver {
function spanInBlock(block: Block): TypeScript.TextSpan {
switch (block.parent.kind) {
case SyntaxKind.ModuleDeclaration:
if (!isInstantiated(block.parent)) {
return undefined;
}
// Set on parent if on same line otherwise on first statement
case SyntaxKind.WhileStatement:
case SyntaxKind.IfStatement:
@@ -405,22 +412,18 @@ module ts.BreakpointResolver {
function spanInCloseBraceToken(node: Node): TypeScript.TextSpan {
switch (node.parent.kind) {
case SyntaxKind.ModuleBlock:
// If this is not instantiated module block no bp span
if (!isInstantiated(node.parent.parent)) {
return undefined;
}
case SyntaxKind.FunctionBlock:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ClassDeclaration:
// Span on close brace token
return textSpan(node);
case SyntaxKind.ModuleBlock:
var moduleBlock = <Block>node.parent;
if (moduleBlock.statements.length || // there are statements in the module block
moduleBlock.parent.parent.kind === SyntaxKind.ModuleDeclaration) { // this is a dotted module body
return textSpan(node);
}
// No span
return;
case SyntaxKind.Block:
case SyntaxKind.TryBlock:
case SyntaxKind.CatchBlock:

View File

@@ -1,9 +1,84 @@
1 >module Foo.Bar {
~~~~~~~~~~~~~~~~~ => Pos: (0 to 16) SpanInfo: {"start":21,"length":12}
>"use strict"
>:=> (line 2, col 4) to (line 2, col 16)
~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":881}
>module Foo.Bar {
> "use strict";
>
> class Greeter {
> constructor(public greeting: string) {
> }
>
> greet() {
> return "<h1>" + this.greeting + "</h1>";
> }
> }
>
>
> function foo(greeting: string): Greeter {
> return new Greeter(greeting);
> }
>
> var greeter = new Greeter("Hello, world!");
> var str = greeter.greet();
>
> function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) {
> var greeters: Greeter[] = []; /* inline block comment */
> greeters[0] = new Greeter(greeting);
> for (var i = 0; i < restGreetings.length; i++) {
> greeters.push(new Greeter(restGreetings[i]));
> }
>
> return greeters;
> }
>
> var b = foo2("Hello", "World", "!");
> // This is simple signle line comment
> for (var j = 0; j < b.length; j++) {
> b[j].greet();
> }
>}
>:=> (line 1, col 0) to (line 36, col 1)
1 >module Foo.Bar {
~~~~~~ => Pos: (11 to 16) SpanInfo: {"start":11,"length":870}
>Bar {
> "use strict";
>
> class Greeter {
> constructor(public greeting: string) {
> }
>
> greet() {
> return "<h1>" + this.greeting + "</h1>";
> }
> }
>
>
> function foo(greeting: string): Greeter {
> return new Greeter(greeting);
> }
>
> var greeter = new Greeter("Hello, world!");
> var str = greeter.greet();
>
> function foo2(greeting: string, ...restGreetings /* more greeting */: string[]) {
> var greeters: Greeter[] = []; /* inline block comment */
> greeters[0] = new Greeter(greeting);
> for (var i = 0; i < restGreetings.length; i++) {
> greeters.push(new Greeter(restGreetings[i]));
> }
>
> return greeters;
> }
>
> var b = foo2("Hello", "World", "!");
> // This is simple signle line comment
> for (var j = 0; j < b.length; j++) {
> b[j].greet();
> }
>}
>:=> (line 1, col 11) to (line 36, col 1)
--------------------------------
2 > "use strict";

View File

@@ -1,9 +1,12 @@
1 >module m {
~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":29,"length":1}
~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":0,"length":32}
>module m {
> class c {
> }
>}
>:=> (line 3, col 4) to (line 3, col 5)
>:=> (line 1, col 0) to (line 4, col 1)
--------------------------------
2 > class c {

View File

@@ -88,6 +88,4 @@
~~~~~~ => Pos: (472 to 477) SpanInfo: undefined
--------------------------------
23 >}
~ => Pos: (478 to 478) SpanInfo: {"start":478,"length":1}
>}
>:=> (line 23, col 0) to (line 23, col 1)
~ => Pos: (478 to 478) SpanInfo: undefined

View File

@@ -1,9 +1,12 @@
1 >module m2 {
~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":16,"length":10}
>var a = 10
>:=> (line 2, col 4) to (line 2, col 14)
~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":38}
>module m2 {
> var a = 10;
> a++;
>}
>:=> (line 1, col 0) to (line 4, col 1)
--------------------------------
2 > var a = 10;
@@ -25,15 +28,25 @@
--------------------------------
5 >module m3 {
~~~~~~~~~~~~ => Pos: (39 to 50) SpanInfo: {"start":75,"length":17}
>export var x = 30
>:=> (line 7, col 8) to (line 7, col 25)
~~~~~~~~~~~~ => Pos: (39 to 50) SpanInfo: {"start":39,"length":118}
>module m3 {
> module m4 {
> export var x = 30;
> }
>
> export function foo() {
> return m4.x;
> }
>}
>:=> (line 5, col 0) to (line 13, col 1)
--------------------------------
6 > module m4 {
~~~~~~~~~~~~~~~~ => Pos: (51 to 66) SpanInfo: {"start":75,"length":17}
>export var x = 30
>:=> (line 7, col 8) to (line 7, col 25)
~~~~~~~~~~~~~~~~ => Pos: (51 to 66) SpanInfo: {"start":55,"length":44}
>module m4 {
> export var x = 30;
> }
>:=> (line 6, col 4) to (line 8, col 5)
--------------------------------
7 > export var x = 30;
@@ -70,6 +83,148 @@
>:=> (line 12, col 4) to (line 12, col 5)
--------------------------------
13 >}
~ => Pos: (156 to 156) SpanInfo: {"start":156,"length":1}
~~ => Pos: (156 to 157) SpanInfo: {"start":156,"length":1}
>}
>:=> (line 13, col 0) to (line 13, col 1)
>:=> (line 13, col 0) to (line 13, col 1)
--------------------------------
14 >module m4 {
~~~~~~~~~~~~ => Pos: (158 to 169) SpanInfo: undefined
--------------------------------
15 > interface I { }
~~~~~~~~~~~~~~~~~~~~ => Pos: (170 to 189) SpanInfo: undefined
--------------------------------
16 >}
~~ => Pos: (190 to 191) SpanInfo: undefined
--------------------------------
17 >module m12
~~~~~~~~~~~ => Pos: (192 to 202) SpanInfo: {"start":192,"length":39}
>module m12
>{
> var a = 10;
> a++;
>}
>:=> (line 17, col 0) to (line 21, col 1)
--------------------------------
18 >{
~~ => Pos: (203 to 204) SpanInfo: {"start":209,"length":10}
>var a = 10
>:=> (line 19, col 4) to (line 19, col 14)
--------------------------------
19 > var a = 10;
~~~~~~~~~~~~~~~~ => Pos: (205 to 220) SpanInfo: {"start":209,"length":10}
>var a = 10
>:=> (line 19, col 4) to (line 19, col 14)
--------------------------------
20 > a++;
~~~~~~~~~ => Pos: (221 to 229) SpanInfo: {"start":225,"length":3}
>a++
>:=> (line 20, col 4) to (line 20, col 7)
--------------------------------
21 >}
~~ => Pos: (230 to 231) SpanInfo: {"start":230,"length":1}
>}
>:=> (line 21, col 0) to (line 21, col 1)
--------------------------------
22 >module m13
~~~~~~~~~~~ => Pos: (232 to 242) SpanInfo: {"start":232,"length":125}
>module m13
>{
> module m14
> {
> export var x = 30;
> }
>
> export function foo() {
> return m4.x;
> }
>}
>:=> (line 22, col 0) to (line 32, col 1)
--------------------------------
23 >{
~~ => Pos: (243 to 244) SpanInfo: {"start":249,"length":50}
>module m14
> {
> export var x = 30;
> }
>:=> (line 24, col 4) to (line 27, col 5)
--------------------------------
24 > module m14
~~~~~~~~~~~~~~~~ => Pos: (245 to 260) SpanInfo: {"start":249,"length":50}
>module m14
> {
> export var x = 30;
> }
>:=> (line 24, col 4) to (line 27, col 5)
--------------------------------
25 > {
~~~~~~ => Pos: (261 to 266) SpanInfo: {"start":275,"length":17}
>export var x = 30
>:=> (line 26, col 8) to (line 26, col 25)
--------------------------------
26 > export var x = 30;
~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (267 to 293) SpanInfo: {"start":275,"length":17}
>export var x = 30
>:=> (line 26, col 8) to (line 26, col 25)
--------------------------------
27 > }
~~~~~~ => Pos: (294 to 299) SpanInfo: {"start":298,"length":1}
>}
>:=> (line 27, col 4) to (line 27, col 5)
--------------------------------
28 >
~ => Pos: (300 to 300) SpanInfo: undefined
--------------------------------
29 > export function foo() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":337,"length":11}
>return m4.x
>:=> (line 30, col 8) to (line 30, col 19)
--------------------------------
30 > return m4.x;
~~~~~~~~~~~~~~~~~~~~~ => Pos: (329 to 349) SpanInfo: {"start":337,"length":11}
>return m4.x
>:=> (line 30, col 8) to (line 30, col 19)
--------------------------------
31 > }
~~~~~~ => Pos: (350 to 355) SpanInfo: {"start":354,"length":1}
>}
>:=> (line 31, col 4) to (line 31, col 5)
--------------------------------
32 >}
~~ => Pos: (356 to 357) SpanInfo: {"start":356,"length":1}
>}
>:=> (line 32, col 0) to (line 32, col 1)
--------------------------------
33 >module m14
~~~~~~~~~~~~ => Pos: (358 to 369) SpanInfo: undefined
--------------------------------
34 >{
~~ => Pos: (370 to 371) SpanInfo: undefined
--------------------------------
35 > interface I { }
~~~~~~~~~~~~~~~~~~~~ => Pos: (372 to 391) SpanInfo: undefined
--------------------------------
36 >}
~ => Pos: (392 to 392) SpanInfo: undefined

View File

@@ -15,5 +15,28 @@
//// return m4.x;
//// }
////}
////module m4 {
//// interface I { }
////}
////module m12
////{
//// var a = 10;
//// a++;
////}
////module m13
////{
//// module m14
//// {
//// export var x = 30;
//// }
////
//// export function foo() {
//// return m4.x;
//// }
////}
////module m14
////{
//// interface I { }
////}
verify.baselineCurrentFileBreakpointLocations();