Skip to content

[Bug]: Decorators | Error when calling super in constructor of extended class when decorating accessors. #16383

@jkonowitch

Description

@jkonowitch

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/register or @babel/node

Input code

Babel REPL Repro

Throws the following error

/repl.ts: Cannot read properties of undefined (reading 'name')
function decorate() {
  return function (target, context) {}
}

class Test {
  @decorate()
  accessor foo = 42;

  constructor() {
  	console.log('hello');
  }
}

new Test()

class TestChild extends Test {
  @decorate()
  accessor bar = 1;

  constructor() {
    super();
  }
}

const r = new TestChild();

Configuration file name

babel.config.json

Configuration

{
  "$schema": "https://json.schemastore.org/babelrc.json",
  "plugins": [["@babel/plugin-proposal-decorators", { "version": "2023-11" }]],
  "presets": [
    ["@babel/preset-env", { "targets": { "node": "current" } }],
    "@babel/preset-typescript"
  ]
}

Current and expected behavior

Expected Behavior: Code compiles without issue
Actual Behavior: Error

Environment

  • Babel Version 7.24.1
  • Environment: REPL & Node v20.10

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Spec: DecoratorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions