From 81fb3f702a9322139d433570d01f1dcde9abb729 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Tue, 1 Aug 2017 22:10:12 +0200 Subject: [PATCH] Addresses CR feedback --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 11 ----------- src/compiler/diagnosticMessages.json | 4 ---- src/compiler/transformers/es2015.ts | 3 ++- src/compiler/transformers/esnext.ts | 2 +- src/compiler/types.ts | 2 +- .../statements/tryStatements/invalidTryStatements.ts | 5 ----- 7 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index aa42d1b251b..45880f855fd 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 6d07025a41f..f3979d80441 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 fbd91f33905..3b4b0ddf667 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 ebfd0b0069f..41e68baa523 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 597b9d55b16..11e79ae9eeb 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 c97020c1142..9cf8e6fdf00 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 6ecdfe10656..c838cf45f69 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. - } }