You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
this.#field not rewritten in class field initializers when class has @decorated accessor #28118
actual behavior: SyntaxError: Cannot reference undeclared private names: "#name"
additional info:
When a class contains a @decorated accessor, Bun lowers all private #fields to WeakMap-based helpers (__privateAdd / __privateGet). The rewrite is correct inside methods and the constructor body, but missed inside class field initializer expressions. This affects all field initializer expressions (arrow functions, template literals, plain expressions).
The bare accessor (without decorator) path already does the right thing. It only lowers the accessor field and keeps other #private fields intact. I think the @decorated accessor path should do the same.
Confirmed still present on 1.4.0-canary.1, and it is not limited to accessor decorators. Any decorated member triggers the private lowering, and the rewrite also misses these two shapes:
Undecorated field initializer in a class with a decorated method:
functiondecorator(){return(v,ctx)=>{};}classFoo{static #m =function(tag){return{ Foo, tag };};
@decorator()test(){return"t";}fromInit=o?.make().Foo.#m("init");// left verbatim, #m's declaration was lowered away}
Private field initializer whose function body references another private (the initializer is moved into a constructor-injected __privateAdd, but its body is not rewritten):
Both fail with SyntaxError: Cannot reference undeclared private names. Mechanically: field initializers are moved into constructor injection statements (and static blocks) during phases that run before the private-access rewrite pass, and those statement lists are not included in the rewrite targets in src/js_parser/lower/lower_decorators.rs.
Activity
lvivski commentedon Mar 14, 2026
The bare
accessor(without decorator) path already does the right thing. It only lowers the accessor field and keeps other#privatefields intact. I think the@decorated accessorpath should do the same.fix(transpiler): rewrite private field refs in class field initialize…
Rewrite private references in moved field initializers as well
robobun commentedon Jun 5, 2026
Confirmed still present on
1.4.0-canary.1, and it is not limited toaccessordecorators. Any decorated member triggers the private lowering, and the rewrite also misses these two shapes:Undecorated field initializer in a class with a decorated method:
Private field initializer whose function body references another private (the initializer is moved into a constructor-injected
__privateAdd, but its body is not rewritten):Both fail with
SyntaxError: Cannot reference undeclared private names. Mechanically: field initializers are moved into constructor injection statements (and static blocks) during phases that run before the private-access rewrite pass, and those statement lists are not included in the rewrite targets insrc/js_parser/lower/lower_decorators.rs.js_parser: lower standard decorators without moving class members
js_parser: lower standard decorators without moving class members (ov…
js_parser: lower standard decorators without moving class members (ov…