Skip to content

Commit fce6206

Browse files
Copilotjakebailey
andauthored
Fix panic for rest properties in catch binding when targeting ES2017 (#3927)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent 6dd27e5 commit fce6206

6 files changed

Lines changed: 72 additions & 1 deletion

File tree

internal/transformers/estransforms/objectrestspread.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func (ch *objectRestSpreadTransformer) visitCatchClause(node *ast.CatchClause) *
387387
block := ch.Visitor().VisitNode(node.Block)
388388
if visitedBindings != nil {
389389
var decls []*ast.Node
390-
if visitedBindings.Kind&ast.KindSyntaxList != 0 {
390+
if visitedBindings.Kind == ast.KindSyntaxList {
391391
decls = visitedBindings.AsSyntaxList().Children
392392
} else {
393393
decls = []*ast.Node{visitedBindings}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
catchClauseRestProperties.ts(3,15): error TS2700: Rest types may only be created from object types.
2+
3+
4+
==== catchClauseRestProperties.ts (1 errors) ====
5+
try {
6+
// ...
7+
} catch ({ ...rest }) {
8+
~~~~
9+
!!! error TS2700: Rest types may only be created from object types.
10+
// ...
11+
}
12+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [tests/cases/compiler/catchClauseRestProperties.ts] ////
2+
3+
//// [catchClauseRestProperties.ts]
4+
try {
5+
// ...
6+
} catch ({ ...rest }) {
7+
// ...
8+
}
9+
10+
11+
//// [catchClauseRestProperties.js]
12+
"use strict";
13+
var __rest = (this && this.__rest) || function (s, e) {
14+
var t = {};
15+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16+
t[p] = s[p];
17+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
18+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20+
t[p[i]] = s[p[i]];
21+
}
22+
return t;
23+
};
24+
try {
25+
// ...
26+
}
27+
catch (_a) {
28+
var rest = __rest(_a, []);
29+
// ...
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/catchClauseRestProperties.ts] ////
2+
3+
=== catchClauseRestProperties.ts ===
4+
try {
5+
// ...
6+
} catch ({ ...rest }) {
7+
>rest : Symbol(rest, Decl(catchClauseRestProperties.ts, 2, 10))
8+
9+
// ...
10+
}
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/catchClauseRestProperties.ts] ////
2+
3+
=== catchClauseRestProperties.ts ===
4+
try {
5+
// ...
6+
} catch ({ ...rest }) {
7+
>rest : any
8+
9+
// ...
10+
}
11+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @target: es2017
2+
3+
try {
4+
// ...
5+
} catch ({ ...rest }) {
6+
// ...
7+
}

0 commit comments

Comments
 (0)