From 148a494c90d0849ad94de02f34975dd8960e22be Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Sun, 30 Jul 2017 10:31:31 +0200 Subject: [PATCH] Adds transformers for ignored catch parameter --- src/compiler/transformers/es2015.ts | 2 +- src/compiler/transformers/esnext.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index f97de018d4a..ebfd0b0069f 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -3173,7 +3173,7 @@ namespace ts { function visitCatchClause(node: CatchClause): CatchClause { const ancestorFacts = enterSubtree(HierarchyFacts.BlockScopeExcludes, HierarchyFacts.BlockScopeIncludes); let updated: CatchClause; - if (isBindingPattern(node.variableDeclaration.name)) { + if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) { const temp = createTempVariable(/*recordTempVariable*/ undefined); const newVariableDeclaration = createVariableDeclaration(temp); setTextRange(newVariableDeclaration, node.variableDeclaration); diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 3d884001932..597b9d55b16 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -101,6 +101,8 @@ namespace ts { return visitExpressionStatement(node as ExpressionStatement); case SyntaxKind.ParenthesizedExpression: return visitParenthesizedExpression(node as ParenthesizedExpression, noDestructuringValue); + case SyntaxKind.CatchClause: + return visitCatchClause(node as CatchClause); default: return visitEachChild(node, visitor, context); } @@ -212,6 +214,13 @@ namespace ts { return visitEachChild(node, noDestructuringValue ? visitorNoDestructuringValue : visitor, context); } + function visitCatchClause(node: CatchClause): CatchClause { + if (!node.variableDeclaration) { + return updateCatchClause(node, createVariableDeclaration("_ignoredCatchParameter"), node.block); + } + return visitEachChild(node, visitor, context); + } + /** * Visits a BinaryExpression that contains a destructuring assignment. *