diff options
-rw-r--r-- | src/js_parser.zig | 5 | ||||
-rw-r--r-- | test/bundler/decorators.test.ts | 31 |
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 { |