From 01d4ce25e2de1df4ff9f94ce2750100114e9bffc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 2 Sep 2014 16:53:03 -0700 Subject: [PATCH] Breakpoints in enum declaration --- src/services/breakpoints.ts | 21 ++++ .../baselines/reference/bpSpan_enums.baseline | 101 ++++++++++++++++++ .../breakpointValidationEnums.ts | 6 ++ 3 files changed, 128 insertions(+) create mode 100644 tests/baselines/reference/bpSpan_enums.baseline rename tests/cases/{fourslash_old => fourslash}/breakpointValidationEnums.ts (63%) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index c5b7dd5a150..6a450ca62dc 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -125,6 +125,12 @@ module ts.BreakpointResolver { case SyntaxKind.ImportDeclaration: return spanInImportDeclaration(node); + case SyntaxKind.EnumDeclaration: + return spanInEnumDeclaration(node); + + case SyntaxKind.EnumMember: + return spanInEnumMember(node); + case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: case SyntaxKind.PrefixOperator: @@ -365,6 +371,19 @@ module ts.BreakpointResolver { return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); } + function spanInEnumDeclaration(enumDeclaration: EnumDeclaration): TypeScript.TextSpan { + if (enumDeclaration.members.length) { + return spanInEnumMember(enumDeclaration.members[0]); + } + + // On close brace + return spanInNode(enumDeclaration.getLastToken(sourceFile)); + } + + function spanInEnumMember(enumMember: EnumMember) { + return textSpan(enumMember); + } + 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 @@ -385,6 +404,7 @@ module ts.BreakpointResolver { switch (node.parent.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.VariableStatement: + case SyntaxKind.EnumDeclaration: return spanInPreviousNode(node); // Default to parent node @@ -417,6 +437,7 @@ module ts.BreakpointResolver { function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionBlock: + case SyntaxKind.EnumDeclaration: // Span on close brace token return textSpan(node); diff --git a/tests/baselines/reference/bpSpan_enums.baseline b/tests/baselines/reference/bpSpan_enums.baseline new file mode 100644 index 00000000000..c239d421da5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_enums.baseline @@ -0,0 +1,101 @@ + +1 >enum e { + + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":13,"length":1} + >x + >:=> (line 2, col 4) to (line 2, col 5) +-------------------------------- +2 > x, + + ~~~~~~~ => Pos: (9 to 15) SpanInfo: {"start":13,"length":1} + >x + >:=> (line 2, col 4) to (line 2, col 5) +-------------------------------- +3 > y, + + ~~~~~~~ => Pos: (16 to 22) SpanInfo: {"start":20,"length":1} + >y + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 > x + + ~~~~~~ => Pos: (23 to 28) SpanInfo: {"start":27,"length":1} + >x + >:=> (line 4, col 4) to (line 4, col 5) +-------------------------------- +5 >} + + ~~ => Pos: (29 to 30) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 5, col 0) to (line 5, col 1) +-------------------------------- +6 >enum e2 { + + ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":45,"length":6} + >x = 10 + >:=> (line 7, col 4) to (line 7, col 10) +-------------------------------- +7 > x = 10, + + ~~~~~~~~~~~~ => Pos: (41 to 52) SpanInfo: {"start":45,"length":6} + >x = 10 + >:=> (line 7, col 4) to (line 7, col 10) +-------------------------------- +8 > y = 10, + + ~~~~~~~~~~~~ => Pos: (53 to 64) SpanInfo: {"start":57,"length":6} + >y = 10 + >:=> (line 8, col 4) to (line 8, col 10) +-------------------------------- +9 > z, + + ~~~~~~~ => Pos: (65 to 71) SpanInfo: {"start":69,"length":1} + >z + >:=> (line 9, col 4) to (line 9, col 5) +-------------------------------- +10 > x2 + + ~~~~~~~ => Pos: (72 to 78) SpanInfo: {"start":76,"length":2} + >x2 + >:=> (line 10, col 4) to (line 10, col 6) +-------------------------------- +11 >} + + ~~ => Pos: (79 to 80) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 11, col 0) to (line 11, col 1) +-------------------------------- +12 >enum e3 { + + ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":91,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +13 >} + + ~~ => Pos: (91 to 92) SpanInfo: {"start":91,"length":1} + >} + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >declare enum e4 { + + ~~~~~~~~~~~~~~~~~~ => Pos: (93 to 110) SpanInfo: undefined +-------------------------------- +15 > x, + + ~~~~~~~ => Pos: (111 to 117) SpanInfo: undefined +-------------------------------- +16 > y, + + ~~~~~~~ => Pos: (118 to 124) SpanInfo: undefined +-------------------------------- +17 > z, + + ~~~~~~~ => Pos: (125 to 131) SpanInfo: undefined +-------------------------------- +18 > x2 + + ~~~~~~~ => Pos: (132 to 138) SpanInfo: undefined +-------------------------------- +19 >} + ~ => Pos: (139 to 139) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash_old/breakpointValidationEnums.ts b/tests/cases/fourslash/breakpointValidationEnums.ts similarity index 63% rename from tests/cases/fourslash_old/breakpointValidationEnums.ts rename to tests/cases/fourslash/breakpointValidationEnums.ts index 4423941b1e4..cd0dbbdfb23 100644 --- a/tests/cases/fourslash_old/breakpointValidationEnums.ts +++ b/tests/cases/fourslash/breakpointValidationEnums.ts @@ -15,5 +15,11 @@ ////} ////enum e3 { ////} +////declare enum e4 { +//// x, +//// y, +//// z, +//// x2 +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file