Skip to content

ES decorators bug with inheritance and --bundle #3768

Closed

Description

@markandrus

With esbuild 0.21.2, given the following file

// test.ts
class Foo {}

const bar = x => x

class Baz extends Foo {
  @bar
  baz() { return Baz }
}

console.log(new Baz().baz())

transforming without the --bundle flag works:

$ esbuild --target=es2022 test.ts >test.js
$ node test.js
[Function: Baz]

Specifying the --bundle flag fails:

$ esbuild --bundle --target=es2022 test.ts >test.js
$ node test.js
/private/tmp/decorator-issue/test.js:60
  __decorateElement(_init, 1, "baz", _baz_dec, _Baz);
                                               ^

ReferenceError: _Baz is not defined
    at /private/tmp/decorator-issue/test.js:60:48
    at Object.<anonymous> (/private/tmp/decorator-issue/test.js:62:3)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.12.2

Here is a repro on esbuild.github.io/try.

Activity

  1. added a commit that references this issue on May 15, 2024
    66b7c6d
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions