mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #17517 from tinganho/IgnoredCatchParameter
Ignored catch parameter
This commit is contained in:
commit
75c8ecb2f1
@ -2921,7 +2921,10 @@ namespace ts {
|
||||
function computeCatchClause(node: CatchClause, subtreeFlags: TransformFlags) {
|
||||
let transformFlags = subtreeFlags;
|
||||
|
||||
if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) {
|
||||
if (!node.variableDeclaration) {
|
||||
transformFlags |= TransformFlags.AssertESNext;
|
||||
}
|
||||
else if (isBindingPattern(node.variableDeclaration.name)) {
|
||||
transformFlags |= TransformFlags.AssertES2015;
|
||||
}
|
||||
|
||||
|
||||
@ -481,7 +481,7 @@ namespace ts {
|
||||
Type,
|
||||
ResolvedBaseConstructorType,
|
||||
DeclaredType,
|
||||
ResolvedReturnType
|
||||
ResolvedReturnType,
|
||||
}
|
||||
|
||||
const enum CheckMode {
|
||||
|
||||
@ -2133,10 +2133,12 @@ namespace ts {
|
||||
function emitCatchClause(node: CatchClause) {
|
||||
const openParenPos = writeToken(SyntaxKind.CatchKeyword, node.pos);
|
||||
write(" ");
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emit(node.variableDeclaration);
|
||||
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration ? node.variableDeclaration.end : openParenPos);
|
||||
write(" ");
|
||||
if (node.variableDeclaration) {
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emit(node.variableDeclaration);
|
||||
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration.end);
|
||||
write(" ");
|
||||
}
|
||||
emit(node.block);
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -4799,11 +4799,16 @@ namespace ts {
|
||||
function parseCatchClause(): CatchClause {
|
||||
const result = <CatchClause>createNode(SyntaxKind.CatchClause);
|
||||
parseExpected(SyntaxKind.CatchKeyword);
|
||||
if (parseExpected(SyntaxKind.OpenParenToken)) {
|
||||
|
||||
if (parseOptional(SyntaxKind.OpenParenToken)) {
|
||||
result.variableDeclaration = parseVariableDeclaration();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
}
|
||||
else {
|
||||
// Keep shape of node to avoid degrading performance.
|
||||
result.variableDeclaration = undefined;
|
||||
}
|
||||
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
|
||||
return finishNode(result);
|
||||
}
|
||||
|
||||
@ -2491,7 +2491,7 @@ namespace ts {
|
||||
const catchVariable = getGeneratedNameForNode(errorRecord);
|
||||
const returnMethod = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
const values = createValuesHelper(context, expression, node.expression);
|
||||
const next = createCall(createPropertyAccess(iterator, "next" ), /*typeArguments*/ undefined, []);
|
||||
const next = createCall(createPropertyAccess(iterator, "next"), /*typeArguments*/ undefined, []);
|
||||
|
||||
hoistVariableDeclaration(errorRecord);
|
||||
hoistVariableDeclaration(returnMethod);
|
||||
@ -3173,6 +3173,7 @@ namespace ts {
|
||||
function visitCatchClause(node: CatchClause): CatchClause {
|
||||
const ancestorFacts = enterSubtree(HierarchyFacts.BlockScopeExcludes, HierarchyFacts.BlockScopeIncludes);
|
||||
let updated: CatchClause;
|
||||
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);
|
||||
|
||||
@ -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,17 @@ namespace ts {
|
||||
return visitEachChild(node, noDestructuringValue ? visitorNoDestructuringValue : visitor, context);
|
||||
}
|
||||
|
||||
function visitCatchClause(node: CatchClause): CatchClause {
|
||||
if (!node.variableDeclaration) {
|
||||
return updateCatchClause(
|
||||
node,
|
||||
createVariableDeclaration(createTempVariable(/*recordTempVariable*/ undefined)),
|
||||
visitNode(node.block, visitor, isBlock)
|
||||
);
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a BinaryExpression that contains a destructuring assignment.
|
||||
*
|
||||
|
||||
@ -1808,7 +1808,7 @@ namespace ts {
|
||||
export interface CatchClause extends Node {
|
||||
kind: SyntaxKind.CatchClause;
|
||||
parent?: TryStatement;
|
||||
variableDeclaration: VariableDeclaration;
|
||||
variableDeclaration?: VariableDeclaration;
|
||||
block: Block;
|
||||
}
|
||||
|
||||
@ -4020,7 +4020,6 @@ namespace ts {
|
||||
ContainsBindingPattern = 1 << 23,
|
||||
ContainsYield = 1 << 24,
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 25,
|
||||
|
||||
ContainsDynamicImport = 1 << 26,
|
||||
|
||||
// Please leave this as 1 << 29.
|
||||
|
||||
@ -34,7 +34,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(138,13): error T
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(141,32): error TS1005: '{' expected.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(143,13): error TS1005: 'try' expected.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,24): error TS1109: Expression expected.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,30): error TS1005: '(' expected.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,30): error TS1005: '{' expected.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,31): error TS2304: Cannot find name 'Property'.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(166,13): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'.
|
||||
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(180,40): error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead.
|
||||
@ -323,7 +323,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
|
||||
~~~~~
|
||||
!!! error TS1109: Expression expected.
|
||||
~
|
||||
!!! error TS1005: '(' expected.
|
||||
!!! error TS1005: '{' expected.
|
||||
~~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'Property'.
|
||||
retVal += c.Member();
|
||||
|
||||
@ -441,7 +441,7 @@ var BasicFeatures = (function () {
|
||||
var xx = c;
|
||||
retVal += ;
|
||||
try { }
|
||||
catch () { }
|
||||
catch (_a) { }
|
||||
Property;
|
||||
retVal += c.Member();
|
||||
retVal += xx.Foo() ? 0 : 1;
|
||||
|
||||
22
tests/baselines/reference/emitter.noCatchBinding.esnext.js
Normal file
22
tests/baselines/reference/emitter.noCatchBinding.esnext.js
Normal file
@ -0,0 +1,22 @@
|
||||
//// [emitter.noCatchBinding.esnext.ts]
|
||||
function f() {
|
||||
try { } catch { }
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { } finally { }
|
||||
}
|
||||
|
||||
//// [emitter.noCatchBinding.esnext.js]
|
||||
function f() {
|
||||
try { }
|
||||
catch { }
|
||||
try { }
|
||||
catch {
|
||||
try { }
|
||||
catch { }
|
||||
}
|
||||
try { }
|
||||
catch { }
|
||||
finally { }
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
=== tests/cases/conformance/emitter/esnext/noCatchBinding/emitter.noCatchBinding.esnext.ts ===
|
||||
function f() {
|
||||
>f : Symbol(f, Decl(emitter.noCatchBinding.esnext.ts, 0, 0))
|
||||
|
||||
try { } catch { }
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { } finally { }
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
=== tests/cases/conformance/emitter/esnext/noCatchBinding/emitter.noCatchBinding.esnext.ts ===
|
||||
function f() {
|
||||
>f : () => void
|
||||
|
||||
try { } catch { }
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { } finally { }
|
||||
}
|
||||
@ -1,24 +1,23 @@
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(3,13): error TS1005: '(' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(6,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(12,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(13,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(22,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(26,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(2,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(6,12): error TS1005: 'finally' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(10,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(11,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(15,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(17,5): error TS1005: 'try' expected.
|
||||
tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(19,20): error TS1003: Identifier expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts (6 errors) ====
|
||||
==== tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts (7 errors) ====
|
||||
function fn() {
|
||||
try {
|
||||
} catch { // syntax error, missing '(x)'
|
||||
~
|
||||
!!! error TS1005: '(' expected.
|
||||
}
|
||||
|
||||
catch(x) { } // error missing try
|
||||
~~~~~
|
||||
!!! error TS1005: 'try' expected.
|
||||
|
||||
finally{ } // potential error; can be absorbed by the 'catch'
|
||||
finally { } // potential error; can be absorbed by the 'catch'
|
||||
|
||||
try { }; // error missing finally
|
||||
~
|
||||
!!! error TS1005: 'finally' expected.
|
||||
}
|
||||
|
||||
function fn2() {
|
||||
@ -28,22 +27,18 @@ tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts(26,5):
|
||||
catch (x) { } // error missing try
|
||||
~~~~~
|
||||
!!! error TS1005: 'try' expected.
|
||||
|
||||
try { } finally { } // statement is here, so the 'catch' clause above doesn't absorb errors from the 'finally' clause below
|
||||
|
||||
// no error
|
||||
try {
|
||||
}
|
||||
finally {
|
||||
}
|
||||
|
||||
// error missing try
|
||||
finally {
|
||||
finally { } // error missing try
|
||||
~~~~~~~
|
||||
!!! error TS1005: 'try' expected.
|
||||
}
|
||||
|
||||
// error missing try
|
||||
catch (x) {
|
||||
|
||||
catch (x) { } // error missing try
|
||||
~~~~~
|
||||
!!! error TS1005: 'try' expected.
|
||||
}
|
||||
|
||||
try { } catch () { } // error missing catch binding
|
||||
~
|
||||
!!! error TS1003: Identifier expected.
|
||||
}
|
||||
@ -1,43 +1,34 @@
|
||||
//// [invalidTryStatements2.ts]
|
||||
function fn() {
|
||||
try {
|
||||
} catch { // syntax error, missing '(x)'
|
||||
}
|
||||
|
||||
catch(x) { } // error missing try
|
||||
|
||||
finally{ } // potential error; can be absorbed by the 'catch'
|
||||
finally { } // potential error; can be absorbed by the 'catch'
|
||||
|
||||
try { }; // error missing finally
|
||||
}
|
||||
|
||||
function fn2() {
|
||||
finally { } // error missing try
|
||||
catch (x) { } // error missing try
|
||||
|
||||
try { } finally { } // statement is here, so the 'catch' clause above doesn't absorb errors from the 'finally' clause below
|
||||
|
||||
// no error
|
||||
try {
|
||||
}
|
||||
finally {
|
||||
}
|
||||
finally { } // error missing try
|
||||
|
||||
catch (x) { } // error missing try
|
||||
|
||||
// error missing try
|
||||
finally {
|
||||
}
|
||||
|
||||
// error missing try
|
||||
catch (x) {
|
||||
}
|
||||
try { } catch () { } // error missing catch binding
|
||||
}
|
||||
|
||||
//// [invalidTryStatements2.js]
|
||||
function fn() {
|
||||
try {
|
||||
}
|
||||
catch () {
|
||||
}
|
||||
try {
|
||||
}
|
||||
catch (x) { } // error missing try
|
||||
finally { } // potential error; can be absorbed by the 'catch'
|
||||
try { }
|
||||
finally { }
|
||||
; // error missing finally
|
||||
}
|
||||
function fn2() {
|
||||
try {
|
||||
@ -46,19 +37,14 @@ function fn2() {
|
||||
try {
|
||||
}
|
||||
catch (x) { } // error missing try
|
||||
// no error
|
||||
try { }
|
||||
finally { } // statement is here, so the 'catch' clause above doesn't absorb errors from the 'finally' clause below
|
||||
try {
|
||||
}
|
||||
finally {
|
||||
}
|
||||
// error missing try
|
||||
finally { } // error missing try
|
||||
try {
|
||||
}
|
||||
finally {
|
||||
}
|
||||
// error missing try
|
||||
try {
|
||||
}
|
||||
catch (x) {
|
||||
}
|
||||
catch (x) { } // error missing try
|
||||
try { }
|
||||
catch () { } // error missing catch binding
|
||||
}
|
||||
|
||||
@ -1,26 +1,47 @@
|
||||
//// [tryStatements.ts]
|
||||
function fn() {
|
||||
try {
|
||||
try { } catch { }
|
||||
|
||||
} catch (x) {
|
||||
var x: any;
|
||||
try { } catch {
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { }
|
||||
}
|
||||
|
||||
try { } catch (x) { var x: any; }
|
||||
|
||||
try { } finally { }
|
||||
|
||||
try { }catch(z){ } finally { }
|
||||
try { } catch { } finally { }
|
||||
|
||||
try { } catch (z) { } finally { }
|
||||
}
|
||||
|
||||
//// [tryStatements.js]
|
||||
function fn() {
|
||||
try {
|
||||
try { }
|
||||
catch (_a) { }
|
||||
try { }
|
||||
catch (_b) {
|
||||
try { }
|
||||
catch (_c) {
|
||||
try { }
|
||||
catch (_d) { }
|
||||
}
|
||||
try { }
|
||||
catch (_e) { }
|
||||
}
|
||||
try { }
|
||||
catch (x) {
|
||||
var x;
|
||||
}
|
||||
try { }
|
||||
finally { }
|
||||
try { }
|
||||
catch (_f) { }
|
||||
finally { }
|
||||
try { }
|
||||
catch (z) { }
|
||||
finally { }
|
||||
}
|
||||
|
||||
@ -2,17 +2,23 @@
|
||||
function fn() {
|
||||
>fn : Symbol(fn, Decl(tryStatements.ts, 0, 0))
|
||||
|
||||
try {
|
||||
try { } catch { }
|
||||
|
||||
} catch (x) {
|
||||
>x : Symbol(x, Decl(tryStatements.ts, 3, 13))
|
||||
|
||||
var x: any;
|
||||
>x : Symbol(x, Decl(tryStatements.ts, 4, 11))
|
||||
try { } catch {
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { }
|
||||
}
|
||||
|
||||
try { } catch (x) { var x: any; }
|
||||
>x : Symbol(x, Decl(tryStatements.ts, 10, 19))
|
||||
>x : Symbol(x, Decl(tryStatements.ts, 10, 27))
|
||||
|
||||
try { } finally { }
|
||||
|
||||
try { }catch(z){ } finally { }
|
||||
>z : Symbol(z, Decl(tryStatements.ts, 9, 17))
|
||||
try { } catch { } finally { }
|
||||
|
||||
try { } catch (z) { } finally { }
|
||||
>z : Symbol(z, Decl(tryStatements.ts, 16, 19))
|
||||
}
|
||||
|
||||
@ -2,17 +2,23 @@
|
||||
function fn() {
|
||||
>fn : () => void
|
||||
|
||||
try {
|
||||
try { } catch { }
|
||||
|
||||
} catch (x) {
|
||||
>x : any
|
||||
|
||||
var x: any;
|
||||
>x : any
|
||||
try { } catch {
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { }
|
||||
}
|
||||
|
||||
try { } catch (x) { var x: any; }
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
try { } finally { }
|
||||
|
||||
try { }catch(z){ } finally { }
|
||||
try { } catch { } finally { }
|
||||
|
||||
try { } catch (z) { } finally { }
|
||||
>z : any
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
// @target: esnext
|
||||
function f() {
|
||||
try { } catch { }
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { } finally { }
|
||||
}
|
||||
@ -1,28 +1,20 @@
|
||||
function fn() {
|
||||
try {
|
||||
} catch { // syntax error, missing '(x)'
|
||||
}
|
||||
|
||||
catch(x) { } // error missing try
|
||||
|
||||
finally{ } // potential error; can be absorbed by the 'catch'
|
||||
finally { } // potential error; can be absorbed by the 'catch'
|
||||
|
||||
try { }; // error missing finally
|
||||
}
|
||||
|
||||
function fn2() {
|
||||
finally { } // error missing try
|
||||
catch (x) { } // error missing try
|
||||
|
||||
try { } finally { } // statement is here, so the 'catch' clause above doesn't absorb errors from the 'finally' clause below
|
||||
|
||||
// no error
|
||||
try {
|
||||
}
|
||||
finally {
|
||||
}
|
||||
finally { } // error missing try
|
||||
|
||||
catch (x) { } // error missing try
|
||||
|
||||
// error missing try
|
||||
finally {
|
||||
}
|
||||
|
||||
// error missing try
|
||||
catch (x) {
|
||||
}
|
||||
try { } catch () { } // error missing catch binding
|
||||
}
|
||||
@ -1,11 +1,19 @@
|
||||
function fn() {
|
||||
try {
|
||||
|
||||
} catch (x) {
|
||||
var x: any;
|
||||
function fn() {
|
||||
try { } catch { }
|
||||
|
||||
try { } catch {
|
||||
try { } catch {
|
||||
try { } catch { }
|
||||
}
|
||||
try { } catch { }
|
||||
}
|
||||
|
||||
try { } catch (x) { var x: any; }
|
||||
|
||||
try { } finally { }
|
||||
|
||||
try { }catch(z){ } finally { }
|
||||
try { } catch { } finally { }
|
||||
|
||||
try { } catch (z) { } finally { }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user