Skip to content

Commit 16a833c

Browse files
committed
fix: mangle catch clause identifiers (#156)
1 parent 5dd3d93 commit 16a833c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/webcrack/src/transforms/mangle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ function inferName(path: NodePath<t.Identifier>): string {
5757
const init = path.parentPath.get('init');
5858
const suffix = (init.isExpression() && generateExpressionName(init)) || '';
5959
return generateUid(path.scope, 'v' + titleCase(suffix));
60+
} else if (path.parentPath.isCatchClause()) {
61+
return generateUid(path.scope, 'e');
6062
} else if (path.parentPath.isArrayPattern()) {
6163
return generateUid(path.scope, 'v');
6264
} else {

packages/webcrack/test/mangle.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ test('parameters', () => {
8989
`).toMatchInlineSnapshot(`(p, p2, p3) => p + p2 + p3;`);
9090
expectJS('(x = 1) => x;').toMatchInlineSnapshot(`(p = 1) => p;`);
9191
});
92+
93+
test('try-catch', () => {
94+
expectJS(`
95+
try {} catch (x) {}
96+
`).toMatchInlineSnapshot(`
97+
try {} catch (e) {}
98+
`);
99+
});

0 commit comments

Comments
 (0)