aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-04-17 15:26:18 -0700
committerGravatar GitHub <noreply@github.com> 2023-04-17 15:26:18 -0700
commit1ce60275d083665ce0988969c2e97c5fae8daa95 (patch)
treeecd1887548bb59d0da39e58ba5dc9c7bd325a024
parent93a43c8fc1864e8460839fc952763a31115fae20 (diff)
downloadbun-1ce60275d083665ce0988969c2e97c5fae8daa95.tar.gz
bun-1ce60275d083665ce0988969c2e97c5fae8daa95.tar.zst
bun-1ce60275d083665ce0988969c2e97c5fae8daa95.zip
fix typescript decorators with index and number keys (#2677)
* handle index property key case * non-method number property * tests for property keys
-rw-r--r--src/js_parser.zig5
-rw-r--r--test/bundler/decorators.test.ts31
2 files changed, 34 insertions, 2 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig
index afa91a48a..f596c2dcd 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -19001,7 +19001,8 @@ fn NewParser_(
.e_identifier => |k| p.newExpr(E.Identifier{ .ref = k.ref }, loc),
.e_number => |k| p.newExpr(E.Number{ .value = k.value }, loc),
.e_string => |k| p.newExpr(E.String{ .data = k.data }, loc),
- else => undefined,
+ .e_index => |k| p.newExpr(E.Index{ .target = k.target, .index = k.index }, loc),
+ else => unreachable,
};
const descriptor_kind: f64 = if (!prop.flags.contains(.is_method)) 2 else 1;
@@ -19042,7 +19043,7 @@ fn NewParser_(
target = p.newExpr(E.This{}, prop.key.?.loc);
}
- if (prop.flags.contains(.is_computed)) {
+ if (prop.flags.contains(.is_computed) or prop.key.?.data == .e_number) {
target = p.newExpr(E.Index{
.target = target,
.index = prop.key.?,
diff --git a/test/bundler/decorators.test.ts b/test/bundler/decorators.test.ts
index 134ae73ac..8769ea2bc 100644
--- a/test/bundler/decorators.test.ts
+++ b/test/bundler/decorators.test.ts
@@ -706,6 +706,37 @@ test("only class decorator", () => {
expect(a).toBe(1);
});
+test("decorators with different property key types", () => {
+ function d1(x) {
+ return function (target, propertyKey) {
+ expect(propertyKey).toBeDefined();
+ expect(propertyKey).toBe(x);
+ };
+ }
+ function foo(x, y, z) {
+ class A {
+ @d1(arguments[0])
+ [arguments[0]]() {}
+ @d1(y)
+ [y] = 10;
+ @d1(z)
+ [arguments[2]] = 20;
+ @d1("string")
+ "string" = 30;
+ @d1("string method")
+ "string method"() {}
+ @d1(12e3)
+ 12e3 = "number key";
+ @d1(12e3 + 1)
+ [12e3 + 1]() {}
+ }
+
+ return A;
+ }
+
+ let A = foo("a", "b", "c");
+});
+
test("only property decorators", () => {
let a = 0;
class A {