Skip to content

bug: error declaring a class with static private method as expression #1498

@privatenumber

Description

@privatenumber

Description

When declaring a class with a static private method as an expression, it throws a type error at run time.

Reproduction

$ echo '(class { static #x() {} })' | npx esbuild --target=es2015 | node
[stdin]:2
  if (member.has(obj))
             ^

TypeError: Cannot read property 'has' of undefined
    at __privateAdd ([stdin]:2:14)
    at [stdin]:7:1
    at Script.runInThisContext (vm.js:133:18)
    at Object.runInThisContext (vm.js:310:38)
    at internal/process/execution.js:77:19
    at [stdin]-wrapper:6:22
    at evalScript (internal/process/execution.js:76:60)
    at internal/main/eval_stdin.js:29:5
    at Socket.<anonymous> (internal/process/execution.js:205:5)
    at Socket.emit (events.js:327:22)

Other info

Seems it was introduced in v0.11.20, as it worked in v0.11.19:

$ echo '(class { static #x() {} })' | npx [email protected] --target=es2015 | node

Credits to @PrettyWood for finding the bug in privatenumber/esbuild-loader#186

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