Addresses CR comment

This commit is contained in:
Tingan Ho
2017-08-02 20:13:43 +02:00
parent 053b708bf1
commit d5c24f3cd3
5 changed files with 9 additions and 5 deletions

View File

@@ -2134,7 +2134,7 @@ namespace ts {
if (node.variableDeclaration) {
writeToken(SyntaxKind.OpenParenToken, openParenPos);
emit(node.variableDeclaration);
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration ? node.variableDeclaration.end : openParenPos);
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration.end);
write(" ");
}
emit(node.block);

View File

@@ -2128,14 +2128,14 @@ namespace ts {
: node;
}
export function createCatchClause(variableDeclaration: string | VariableDeclaration, block: Block) {
export function createCatchClause(variableDeclaration: string | VariableDeclaration | undefined, block: Block) {
const node = <CatchClause>createSynthesizedNode(SyntaxKind.CatchClause);
node.variableDeclaration = typeof variableDeclaration === "string" ? createVariableDeclaration(variableDeclaration) : variableDeclaration;
node.block = block;
return node;
}
export function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration, block: Block) {
export function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block) {
return node.variableDeclaration !== variableDeclaration
|| node.block !== block
? updateNode(createCatchClause(variableDeclaration, block), node)

View File

@@ -4783,6 +4783,10 @@ namespace ts {
result.variableDeclaration = parseVariableDeclaration();
parseExpected(SyntaxKind.CloseParenToken);
}
else {
// Keep shape of node to not avoid degrading performance.
result.variableDeclaration = undefined;
}
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
return finishNode(result);

View File

@@ -3173,7 +3173,7 @@ namespace ts {
function visitCatchClause(node: CatchClause): CatchClause {
const ancestorFacts = enterSubtree(HierarchyFacts.BlockScopeExcludes, HierarchyFacts.BlockScopeIncludes);
let updated: CatchClause;
Debug.assert(!!node.variableDeclaration, "Catch clauses should always be present when downleveling ES2015 code.");
Debug.assert(!!node.variableDeclaration, "Catch clause variable should always be present when downleveling ES2015.");
if (isBindingPattern(node.variableDeclaration.name)) {
const temp = createTempVariable(/*recordTempVariable*/ undefined);
const newVariableDeclaration = createVariableDeclaration(temp);

View File

@@ -1807,7 +1807,7 @@ namespace ts {
export interface CatchClause extends Node {
kind: SyntaxKind.CatchClause;
parent?: TryStatement; // We make this optional to parse missing try statements
parent?: TryStatement;
variableDeclaration?: VariableDeclaration;
block: Block;
}