Skip to content

static_initializer prop #47399

Open

Description

@hyuzea

What version of Bun is running?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

..

What is the expected behavior?

No response

What do you see instead?

Uncaught TypeError: Cannot convert undefined to a BigInt
at BigInt ()
at <instance_members_initializer> (editor.bun.js:32744:9)
at new FocusedElement (editor.bun.js:32745:14)
at <static_initializer> (editor.bun.js:32743:17)

Additional information

esbuild can bundle this but bun't

class FocusedElement {
        public readonly key = (BigInt(this.byte) << 1n) | (this.char ? 1n : 0n);
	constructor(
		public readonly char: boolean,
		public readonly byte: number,
	) {}
}

Activity

  1. robobun commented on Oct 29, 2026

    @robobun
    Collaborator

    Reproduced with {"compilerOptions":{"target":"ES2020"}} in tsconfig.json: bun a.ts throws where tsc and esbuild print 11n. Bun ignores target when it picks the useDefineForClassFields default.
    Fix drafted in #47401. It waits for a maintainer decision on whether target should imply that default (see the question below).

  2. robobun commented on Oct 29, 2026

    @robobun
    Collaborator

    This needs a maintainer decision before the fix can land. @Jarred-Sumner

    The report reduces to this: Bun reads only an explicit useDefineForClassFields from tsconfig.json. tsc and esbuild also derive its default from target: false below ES2022, true from ES2022 on. With {"compilerOptions":{"target":"ES2020"}} and no flag, tsc 6.0.2 and esbuild 0.21.5 print 11n for the class in this report. Bun throws. Without a tsconfig, or with target at ES2022 or above, all three throw, so that case is not a bug.

    #47401 (a port of #40924) makes Bun derive the default from target in the transpiler, the bundler, Bun.Transpiler and the AOT checker. Two things in the repo say the current behavior is deliberate:

    The question: should a target below ES2022 with no explicit flag imply [[Set]] class fields, as tsc and esbuild do? If yes, #47401 is ready for review. If no, I will close it, and the workaround is "useDefineForClassFields": false in compilerOptions.

    One cost of "yes": with [[Set]] semantics Bun inserts the field assignments after the first top-level super() statement. A constructor whose super() is inside if/else then throws ReferenceError at new. That gap exists today with the explicit flag. tsc rejects that shape with TS2376, esbuild wraps the nested super() calls. A target below ES2022 is far more common than the explicit flag, so "yes" should close that gap in the same change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions