-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignored catch parameter #17517
Ignored catch parameter #17517
Changes from 11 commits
b17bd97
99c662b
b917eb0
148a494
e349943
90ea10e
c65e5a1
de38ef7
58c8a2c
81fb3f7
dbdbb05
1926285
053b708
d5c24f3
f9e85ec
4f3e13a
3da1a53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4778,11 +4778,12 @@ 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditionally setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ |
||
parseExpected(SyntaxKind.CloseParenToken); | ||
} | ||
|
||
parseExpected(SyntaxKind.CloseParenToken); | ||
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false); | ||
return finishNode(result); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 clauses should always be present when downleveling ES2015 code."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ |
||
if (isBindingPattern(node.variableDeclaration.name)) { | ||
const temp = createTempVariable(/*recordTempVariable*/ undefined); | ||
const newVariableDeclaration = createVariableDeclaration(temp); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(createTempVariable(/*recordTempVariable*/ undefined)), node.block); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
function* doFoo(foo: any) {
try {
throw "whatever";
}
catch {
try {
throw "again"
}
catch {
for await (const c of foo) {
c;
}
}
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @weswigham is correct, you should recursively visit the block of the catch clause. |
||
} | ||
return visitEachChild(node, visitor, context); | ||
} | ||
|
||
/** | ||
* Visits a BinaryExpression that contains a destructuring assignment. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1807,8 +1807,8 @@ namespace ts { | |
|
||
export interface CatchClause extends Node { | ||
kind: SyntaxKind.CatchClause; | ||
parent?: TryStatement; | ||
variableDeclaration: VariableDeclaration; | ||
parent?: TryStatement; // We make this optional to parse missing try statements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is unnecessary. We only re-introduce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ |
||
variableDeclaration?: VariableDeclaration; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ |
||
block: Block; | ||
} | ||
|
||
|
@@ -4001,7 +4001,6 @@ namespace ts { | |
ContainsBindingPattern = 1 << 23, | ||
ContainsYield = 1 << 24, | ||
ContainsHoistedDeclarationOrCompletion = 1 << 25, | ||
|
||
ContainsDynamicImport = 1 << 26, | ||
|
||
// Please leave this as 1 << 29. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//// [emitter.ignoredCatchParameter.esnext.ts] | ||
function fn() { | ||
try {} catch {} | ||
} | ||
|
||
|
||
//// [emitter.ignoredCatchParameter.esnext.js] | ||
function fn() { | ||
try { } | ||
catch { } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/conformance/emitter/esnext/noCatchParameter/emitter.ignoredCatchParameter.esnext.ts === | ||
function fn() { | ||
>fn : Symbol(fn, Decl(emitter.ignoredCatchParameter.esnext.ts, 0, 0)) | ||
|
||
try {} catch {} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/conformance/emitter/esnext/noCatchParameter/emitter.ignoredCatchParameter.esnext.ts === | ||
function fn() { | ||
>fn : () => void | ||
|
||
try {} catch {} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
//// [tryStatements.ts] | ||
function fn() { | ||
try { | ||
try { } catch { } | ||
|
||
} catch (x) { | ||
var x: any; | ||
} | ||
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 (x) { | ||
var x; | ||
} | ||
try { } | ||
finally { } | ||
try { } | ||
catch (_b) { } | ||
finally { } | ||
try { } | ||
catch (z) { } | ||
finally { } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
|
||
function fn() { | ||
try { | ||
try { } catch { } | ||
|
||
} catch (x) { | ||
var x: any; | ||
} | ||
try { } catch (x) { var x: any; } | ||
|
||
try { } finally { } | ||
|
||
try { }catch(z){ } finally { } | ||
try { } catch { } finally { } | ||
|
||
try { } catch(z) { } finally { } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional on this line is no longer required since you are checking
node.variableDeclaration
on 2134.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️