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:
@@ -493,9 +493,7 @@ module ts {
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
|
||||
@@ -4569,9 +4569,7 @@ module ts {
|
||||
case SyntaxKind.LabeledStatement:
|
||||
case SyntaxKind.ThrowStatement:
|
||||
case SyntaxKind.TryStatement:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
return forEachChild(node, isAssignedIn);
|
||||
}
|
||||
return false;
|
||||
@@ -8894,9 +8892,7 @@ module ts {
|
||||
case SyntaxKind.LabeledStatement:
|
||||
case SyntaxKind.ThrowStatement:
|
||||
case SyntaxKind.TryStatement:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
|
||||
@@ -3907,8 +3907,6 @@ module ts {
|
||||
case SyntaxKind.OmittedExpression:
|
||||
return;
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return emitBlock(<Block>node);
|
||||
case SyntaxKind.VariableStatement:
|
||||
|
||||
+14
-24
@@ -361,8 +361,6 @@ module ts {
|
||||
child((<ConditionalExpression>node).whenTrue) ||
|
||||
child((<ConditionalExpression>node).whenFalse);
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return children((<Block>node).statements);
|
||||
case SyntaxKind.SourceFile:
|
||||
@@ -492,9 +490,7 @@ module ts {
|
||||
case SyntaxKind.DefaultClause:
|
||||
case SyntaxKind.LabeledStatement:
|
||||
case SyntaxKind.TryStatement:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
return forEachChild(node, traverse);
|
||||
}
|
||||
}
|
||||
@@ -3529,8 +3525,8 @@ module ts {
|
||||
}
|
||||
|
||||
// STATEMENTS
|
||||
function parseBlock(kind: SyntaxKind, ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
||||
var node = <Block>createNode(kind);
|
||||
function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
||||
var node = <Block>createNode(SyntaxKind.Block);
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
|
||||
node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatement);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
@@ -3545,7 +3541,7 @@ module ts {
|
||||
var savedYieldContext = inYieldContext();
|
||||
setYieldContext(allowYield);
|
||||
|
||||
var block = parseBlock(SyntaxKind.Block, ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage);
|
||||
var block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage);
|
||||
|
||||
setYieldContext(savedYieldContext);
|
||||
|
||||
@@ -3739,25 +3735,19 @@ module ts {
|
||||
// TODO: Review for error recovery
|
||||
function parseTryStatement(): TryStatement {
|
||||
var node = <TryStatement>createNode(SyntaxKind.TryStatement);
|
||||
node.tryBlock = parseTokenAndBlock(SyntaxKind.TryKeyword);
|
||||
|
||||
parseExpected(SyntaxKind.TryKeyword);
|
||||
node.tryBlock = parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode*/ false);
|
||||
node.catchClause = token === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined;
|
||||
|
||||
// If we don't have a catch clause, then we must have a finally clause. Try to parse
|
||||
// one out no matter what.
|
||||
node.finallyBlock = !node.catchClause || token === SyntaxKind.FinallyKeyword
|
||||
? parseTokenAndBlock(SyntaxKind.FinallyKeyword)
|
||||
: undefined;
|
||||
return finishNode(node);
|
||||
}
|
||||
if (!node.catchClause || token === SyntaxKind.FinallyKeyword) {
|
||||
parseExpected(SyntaxKind.FinallyKeyword);
|
||||
node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode*/ false);
|
||||
}
|
||||
|
||||
function parseTokenAndBlock(token: SyntaxKind): Block {
|
||||
var pos = getNodePos();
|
||||
parseExpected(token);
|
||||
var result = parseBlock(
|
||||
token === SyntaxKind.TryKeyword ? SyntaxKind.TryBlock : SyntaxKind.FinallyBlock,
|
||||
/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false);
|
||||
result.pos = pos;
|
||||
return result;
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseCatchClause(): CatchClause {
|
||||
@@ -3767,7 +3757,7 @@ module ts {
|
||||
result.name = parseIdentifier();
|
||||
result.type = parseTypeAnnotation();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
result.block = parseBlock(SyntaxKind.Block, /* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false);
|
||||
result.block = parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode:*/ false);
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
@@ -3876,7 +3866,7 @@ module ts {
|
||||
function parseStatement(): Statement {
|
||||
switch (token) {
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseBlock(SyntaxKind.Block, /* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false);
|
||||
return parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode:*/ false);
|
||||
case SyntaxKind.VarKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
// const here should always be parsed as const declaration because of check in 'isStatement'
|
||||
@@ -4715,7 +4705,7 @@ module ts {
|
||||
inFunctionBlock = true;
|
||||
}
|
||||
var savedInBlock = inBlock;
|
||||
if (node.kind === SyntaxKind.Block || node.kind === SyntaxKind.TryBlock || node.kind === SyntaxKind.FinallyBlock) {
|
||||
if (node.kind === SyntaxKind.Block) {
|
||||
inBlock = true;
|
||||
}
|
||||
var savedInObjectLiteralExpression = inObjectLiteralExpression;
|
||||
|
||||
@@ -213,8 +213,6 @@ module ts {
|
||||
LabeledStatement,
|
||||
ThrowStatement,
|
||||
TryStatement,
|
||||
TryBlock,
|
||||
FinallyBlock,
|
||||
DebuggerStatement,
|
||||
VariableDeclaration,
|
||||
FunctionDeclaration,
|
||||
|
||||
@@ -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