Skip to content

Commit d5c24f3

Browse files
committed
Addresses CR comment
1 parent 053b708 commit d5c24f3

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ namespace ts {
21342134
if (node.variableDeclaration) {
21352135
writeToken(SyntaxKind.OpenParenToken, openParenPos);
21362136
emit(node.variableDeclaration);
2137-
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration ? node.variableDeclaration.end : openParenPos);
2137+
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration.end);
21382138
write(" ");
21392139
}
21402140
emit(node.block);

src/compiler/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,14 +2128,14 @@ namespace ts {
21282128
: node;
21292129
}
21302130

2131-
export function createCatchClause(variableDeclaration: string | VariableDeclaration, block: Block) {
2131+
export function createCatchClause(variableDeclaration: string | VariableDeclaration | undefined, block: Block) {
21322132
const node = <CatchClause>createSynthesizedNode(SyntaxKind.CatchClause);
21332133
node.variableDeclaration = typeof variableDeclaration === "string" ? createVariableDeclaration(variableDeclaration) : variableDeclaration;
21342134
node.block = block;
21352135
return node;
21362136
}
21372137

2138-
export function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration, block: Block) {
2138+
export function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block) {
21392139
return node.variableDeclaration !== variableDeclaration
21402140
|| node.block !== block
21412141
? updateNode(createCatchClause(variableDeclaration, block), node)

src/compiler/parser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4783,6 +4783,10 @@ namespace ts {
47834783
result.variableDeclaration = parseVariableDeclaration();
47844784
parseExpected(SyntaxKind.CloseParenToken);
47854785
}
4786+
else {
4787+
// Keep shape of node to not avoid degrading performance.
4788+
result.variableDeclaration = undefined;
4789+
}
47864790

47874791
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
47884792
return finishNode(result);

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ namespace ts {
31733173
function visitCatchClause(node: CatchClause): CatchClause {
31743174
const ancestorFacts = enterSubtree(HierarchyFacts.BlockScopeExcludes, HierarchyFacts.BlockScopeIncludes);
31753175
let updated: CatchClause;
3176-
Debug.assert(!!node.variableDeclaration, "Catch clauses should always be present when downleveling ES2015 code.");
3176+
Debug.assert(!!node.variableDeclaration, "Catch clause variable should always be present when downleveling ES2015.");
31773177
if (isBindingPattern(node.variableDeclaration.name)) {
31783178
const temp = createTempVariable(/*recordTempVariable*/ undefined);
31793179
const newVariableDeclaration = createVariableDeclaration(temp);

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ namespace ts {
18071807

18081808
export interface CatchClause extends Node {
18091809
kind: SyntaxKind.CatchClause;
1810-
parent?: TryStatement; // We make this optional to parse missing try statements
1810+
parent?: TryStatement;
18111811
variableDeclaration?: VariableDeclaration;
18121812
block: Block;
18131813
}

0 commit comments

Comments
 (0)