From f5a04b086d5e4a4450413aff3b351b32f0800523 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Wed, 26 Jul 2023 15:44:03 -0700 Subject: [PATCH 1/2] return the prop if there are decorators --- src/js_ast.zig | 1 + src/js_parser.zig | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js_ast.zig b/src/js_ast.zig index b5f47474afb5a8..358fe3197e17a0 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -840,6 +840,7 @@ pub const G = struct { get, set, spread, + declare, class_static_block, pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { diff --git a/src/js_parser.zig b/src/js_parser.zig index 6390dfdbaabbb7..af818788e7cdb5 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -12062,7 +12062,14 @@ fn NewParser_( // https://github.com/oven-sh/bun/issues/1907 if (opts.is_class and is_typescript_enabled and strings.eqlComptime(raw, "declare")) { const scope_index = p.scopes_in_order.items.len; - _ = try p.parseProperty(kind, opts, null); + if (try p.parseProperty(kind, opts, null)) |_prop| { + var prop = _prop; + if (prop.kind == .normal and prop.value == null and opts.ts_decorators.len > 0) { + prop.kind = .declare; + return prop; + } + } + p.discardScopesUpTo(scope_index); return null; } From 95bc099c6989d1568ff3400572ed7e33ff398562 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Wed, 26 Jul 2023 15:52:20 -0700 Subject: [PATCH 2/2] test and comment --- src/js_parser.zig | 2 ++ test/transpiler/decorators.test.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/js_parser.zig b/src/js_parser.zig index af818788e7cdb5..076815e542932a 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -19519,6 +19519,8 @@ fn NewParser_( } } + // TODO: prop.kind == .declare and prop.value == null + if (prop.ts_decorators.len > 0) { const loc = prop.key.?.loc; const descriptor_key = switch (prop.key.?.data) { diff --git a/test/transpiler/decorators.test.ts b/test/transpiler/decorators.test.ts index 100ecc3bc9d431..885391800d08fd 100644 --- a/test/transpiler/decorators.test.ts +++ b/test/transpiler/decorators.test.ts @@ -998,3 +998,23 @@ test("export default class Named works", () => { test("export default class works (anonymous name)", () => { expect(new DecoratedAnonClass()["methoddecorated"]).toBe(true); }); + +test("decorator and declare", () => { + let counter = 0; + function d1(t) { + t(); + } + class A { + @d1(() => { + counter++; + }) + declare a: number; + + m() { + counter++; + } + } + + new A(); + expect(counter).toBe(1); +});