10000 feat(typescript-estree): throw error when CatchClause param contains … · StyleShit/typescript-eslint@544fd77 · GitHub
[go: up one dir, main page]

Skip to content

Commit 544fd77

Browse files
authored
feat(typescript-estree): throw error when CatchClause param contains initializer (typescript-eslint#8183)
1 parent ca00388 commit 544fd77

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try {
2+
}
3+
catch (e = 1) {
4+
}

packages/ast-spec/src/special/CatchClause/fixtures/_error_/with-initializer/snapshots/1-TSESTree-Error.shot

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ast-spec/src/special/CatchClause/fixtures/_error_/with-initializer/snapshots/2-Babel-Error.shot

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ast-spec/src/special/CatchClause/fixtures/_error_/with-initializer/snapshots/3-Alignment-Error.shot

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/typescript-estree/src/convert.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,12 @@ export class Converter {
887887
});
888888

889889
case SyntaxKind.CatchClause:
890+
if (node.variableDeclaration?.initializer) {
891+
this.#throwError(
892+
node.variableDeclaration.initializer,
893+
'Catch clause variable cannot have an initializer.',
894+
);
895+
}
890896
return this.createNode<TSESTree.CatchClause>(node, {
891897
type: AST_NODE_TYPES.CatchClause,
892898
param: node.variableDeclaration

0 commit comments

Comments
 (0)
0