mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Remove TryBlock and FinallyBlock.
They break the rule that syntactically identical constructs use the same syntax kind. This prevents node reuse in incremental parsing.
This commit is contained in:
@@ -108,8 +108,6 @@ module ts.BreakpointResolver {
|
||||
return spanInFunctionBlock(<Block>node);
|
||||
}
|
||||
// Fall through
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return spanInBlock(<Block>node);
|
||||
|
||||
@@ -429,9 +427,7 @@ module ts.BreakpointResolver {
|
||||
}
|
||||
// fall through.
|
||||
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
return spanInNode((<Block>node.parent).statements[(<Block>node.parent).statements.length - 1]);;
|
||||
|
||||
case SyntaxKind.SwitchStatement:
|
||||
|
||||
@@ -154,8 +154,6 @@ module ts.formatting {
|
||||
return body && body.kind === SyntaxKind.Block && rangeContainsRange((<Block>body).statements, node);
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return rangeContainsRange((<Block>parent).statements, node);
|
||||
case SyntaxKind.CatchClause:
|
||||
@@ -932,9 +930,6 @@ module ts.formatting {
|
||||
function isSomeBlock(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -525,8 +525,6 @@ module ts.formatting {
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return true;
|
||||
}
|
||||
@@ -580,9 +578,7 @@ module ts.formatting {
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return true;
|
||||
@@ -603,7 +599,6 @@ module ts.formatting {
|
||||
// TODO
|
||||
// case SyntaxKind.ElseClause:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
@@ -84,25 +84,43 @@ module ts {
|
||||
parent.kind === SyntaxKind.CatchClause) {
|
||||
|
||||
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// Block was a standalone block. In this case we want to only collapse
|
||||
// the span of the block, independent of any parent span.
|
||||
var span = TextSpan.fromBounds(n.getStart(), n.end);
|
||||
elements.push({
|
||||
textSpan: span,
|
||||
hintSpan: span,
|
||||
bannerText: collapseText,
|
||||
autoCollapse: autoCollapse(n)
|
||||
});
|
||||
|
||||
if (parent.kind === SyntaxKind.TryStatement) {
|
||||
// Could be the try-block, or the finally-block.
|
||||
var tryStatement = <TryStatement>parent;
|
||||
if (tryStatement.tryBlock === n) {
|
||||
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
|
||||
break;
|
||||
}
|
||||
else if (tryStatement.finallyBlock === n) {
|
||||
var children = tryStatement.getChildren();
|
||||
for (var i = 0, m = children.length; i < m; i++) {
|
||||
if (children[i].kind === SyntaxKind.FinallyKeyword) {
|
||||
addOutliningSpan(children[i], openBrace, closeBrace, autoCollapse(n));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fall through.
|
||||
}
|
||||
|
||||
// Block was a standalone block. In this case we want to only collapse
|
||||
// the span of the block, independent of any parent span.
|
||||
var span = TextSpan.fromBounds(n.getStart(), n.end);
|
||||
elements.push({
|
||||
textSpan: span,
|
||||
hintSpan: span,
|
||||
bannerText: collapseText,
|
||||
autoCollapse: autoCollapse(n)
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Fallthrough.
|
||||
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n));
|
||||
|
||||
@@ -3418,13 +3418,17 @@ module ts {
|
||||
return getThrowOccurrences(<ThrowStatement>node.parent);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.TryKeyword:
|
||||
case SyntaxKind.CatchKeyword:
|
||||
case SyntaxKind.FinallyKeyword:
|
||||
if (hasKind(parent(parent(node)), SyntaxKind.TryStatement)) {
|
||||
return getTryCatchFinallyOccurrences(<TryStatement>node.parent.parent);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.TryKeyword:
|
||||
case SyntaxKind.FinallyKeyword:
|
||||
if (hasKind(parent(node), SyntaxKind.TryStatement)) {
|
||||
return getTryCatchFinallyOccurrences(<TryStatement>node.parent);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.SwitchKeyword:
|
||||
if (hasKind(node.parent, SyntaxKind.SwitchStatement)) {
|
||||
return getSwitchCaseDefaultOccurrences(<SwitchStatement>node.parent);
|
||||
@@ -3658,7 +3662,12 @@ module ts {
|
||||
}
|
||||
|
||||
if (tryStatement.finallyBlock) {
|
||||
pushKeywordIf(keywords, tryStatement.finallyBlock.getFirstToken(), SyntaxKind.FinallyKeyword);
|
||||
var children = tryStatement.getChildren();
|
||||
for (var i = 0, n = children.length; i < n; i++) {
|
||||
if (pushKeywordIf(keywords, children[i], SyntaxKind.FinallyKeyword)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map(keywords, getReferenceEntryFromNode);
|
||||
|
||||
@@ -327,8 +327,6 @@ module ts.formatting {
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
@@ -403,7 +401,6 @@ module ts.formatting {
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
|
||||
Reference in New Issue
Block a user