introduce CaseBlock as a block-scoped container for switch statements

This commit is contained in:
Vladimir Matveev
2015-03-10 17:50:54 -07:00
parent f747e5a1f9
commit efcf0e6f57
22 changed files with 389 additions and 187 deletions
+5 -5
View File
@@ -416,8 +416,8 @@ module ts.BreakpointResolver {
var classDeclaration = <ClassDeclaration>node.parent;
return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile));
case SyntaxKind.SwitchStatement:
return spanInNodeIfStartsOnSameLine(node.parent, (<SwitchStatement>node.parent).clauses[0]);
case SyntaxKind.CaseBlock:
return spanInNodeIfStartsOnSameLine(node.parent.parent, (<CaseBlock>node.parent).clauses[0]);
}
// Default to parent node
@@ -447,10 +447,10 @@ module ts.BreakpointResolver {
case SyntaxKind.CatchClause:
return spanInNode((<Block>node.parent).statements[(<Block>node.parent).statements.length - 1]);;
case SyntaxKind.SwitchStatement:
case SyntaxKind.CaseBlock:
// breakpoint in last statement of the last clause
var switchStatement = <SwitchStatement>node.parent;
var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1];
var caseBlock = <CaseBlock>node.parent;
var lastClause = caseBlock.clauses[caseBlock.clauses.length - 1];
if (lastClause) {
return spanInNode(lastClause.statements[lastClause.statements.length - 1]);
}
+1 -1
View File
@@ -541,7 +541,7 @@ module ts.formatting {
switch (node.kind) {
case SyntaxKind.Block:
case SyntaxKind.SwitchStatement:
case SyntaxKind.CaseBlock:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ModuleBlock:
return true;
+2 -2
View File
@@ -357,7 +357,7 @@ module ts.formatting {
case SyntaxKind.ModuleBlock:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.TypeLiteral:
case SyntaxKind.SwitchStatement:
case SyntaxKind.CaseBlock:
case SyntaxKind.DefaultClause:
case SyntaxKind.CaseClause:
case SyntaxKind.ParenthesizedExpression:
@@ -431,7 +431,7 @@ module ts.formatting {
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.Block:
case SyntaxKind.ModuleBlock:
case SyntaxKind.SwitchStatement:
case SyntaxKind.CaseBlock:
return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile);
case SyntaxKind.CatchClause:
return isCompletedNode((<CatchClause>n).block, sourceFile);
+1 -1
View File
@@ -104,7 +104,7 @@ module ts {
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.SwitchStatement:
case SyntaxKind.CaseBlock:
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n));
+3 -3
View File
@@ -3619,8 +3619,8 @@ module ts {
break;
case SyntaxKind.CaseKeyword:
case SyntaxKind.DefaultKeyword:
if (hasKind(parent(parent(node)), SyntaxKind.SwitchStatement)) {
return getSwitchCaseDefaultOccurrences(<SwitchStatement>node.parent.parent);
if (hasKind(parent(parent(parent(node))), SyntaxKind.SwitchStatement)) {
return getSwitchCaseDefaultOccurrences(<SwitchStatement>node.parent.parent.parent);
}
break;
case SyntaxKind.BreakKeyword:
@@ -3887,7 +3887,7 @@ module ts {
pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword);
// Go through each clause in the switch statement, collecting the 'case'/'default' keywords.
forEach(switchStatement.clauses, clause => {
forEach(switchStatement.caseBlock.clauses, clause => {
pushKeywordIf(keywords, clause.getFirstToken(), SyntaxKind.CaseKeyword, SyntaxKind.DefaultKeyword);
var breaksAndContinues = aggregateAllBreakAndContinueStatements(clause);