Skip to content

this.#field not rewritten in class field initializers when class has @decorated accessor #28118

@lvivski

Description

@lvivski

bun version: 1.3.10

example:

function id(
  value: ClassAccessorDecoratorTarget<any, any>,
  context: ClassAccessorDecoratorContext,
): ClassAccessorDecoratorResult<any, any> {
  return value
}

class Broken {
  @id accessor label: string = ''
  #name = 'hello'
  #callback = () => this.#name
  run() { return this.#callback() }
}

console.log(new Broken().run())

expected behavior:
hello

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).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions