diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index aa42d1b251..45880f855f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2924,7 +2924,7 @@ namespace ts { if (!node.variableDeclaration) { transformFlags |= TransformFlags.AssertESNext; } - else if (/* node.variableDeclaration && */ isBindingPattern(node.variableDeclaration.name)) { + else if (isBindingPattern(node.variableDeclaration.name)) { transformFlags |= TransformFlags.AssertES2015; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6d07025a41..f3979d8044 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20885,17 +20885,6 @@ namespace ts { } } } - else if (/* !catchClause.variableDeclaration && */ languageVersion < ScriptTarget.ESNext) { - const blockLocals = catchClause.block.locals; - if (blockLocals) { - forEachKey(blockLocals, caughtName => { - if (caughtName === "_ignoredCatchParameter") { - const localSymbol = blockLocals.get(caughtName); - grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Duplicate_identifier_ignoredCatchParameter_Compiler_uses_the_parameter_declaration_ignoredCatchParameter_to_bind_ignored_catched_exceptions); - } - }); - } - } checkBlock(catchClause.block); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fbd91f3390..3b4b0ddf66 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2196,10 +2196,6 @@ "category": "Error", "code": 2713 }, - "Duplicate identifier '_ignoredCatchParameter'. Compiler uses the parameter declaration '_ignoredCatchParameter' to bind ignored catched exceptions.": { - "category": "Error", - "code": 2714 - }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index ebfd0b0069..41e68baa52 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -3173,7 +3173,8 @@ namespace ts { function visitCatchClause(node: CatchClause): CatchClause { const ancestorFacts = enterSubtree(HierarchyFacts.BlockScopeExcludes, HierarchyFacts.BlockScopeIncludes); let updated: CatchClause; - if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) { + Debug.assert(!!node.variableDeclaration, "Catch clauses should always be present when downleveling ES2015 code."); + if (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 597b9d55b1..11e79ae9ee 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -216,7 +216,7 @@ namespace ts { function visitCatchClause(node: CatchClause): CatchClause { if (!node.variableDeclaration) { - return updateCatchClause(node, createVariableDeclaration("_ignoredCatchParameter"), node.block); + return updateCatchClause(node, createVariableDeclaration(createTempVariable(/*recordTempVariable*/ undefined)), node.block); } return visitEachChild(node, visitor, context); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c97020c114..9cf8e6fdf0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1807,7 +1807,7 @@ namespace ts { export interface CatchClause extends Node { kind: SyntaxKind.CatchClause; - parent?: TryStatement; // We parse missing try statements + parent?: TryStatement; // We make this optional to parse missing try statements variableDeclaration?: VariableDeclaration; block: Block; } diff --git a/tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts b/tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts index 6ecdfe1065..c838cf45f6 100644 --- a/tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts +++ b/tests/cases/conformance/statements/tryStatements/invalidTryStatements.ts @@ -8,10 +8,5 @@ function fn() { try { } catch (z: any) { } try { } catch (a: number) { } try { } catch (y: string) { } - - - try { } catch { - let _ignoredCatchParameter; // Should error since we downlevel emit this variable. - } }