mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +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:
1 parent
12f8bfb687
commit
b692ea9b66
20 files changed
+117
-127
No files matched your search
+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;
|
||||
|
||||
Reference in new issue
Block a user