Skip to content

[Bug]: Incorrect computed key evaluation order when a class has only class decorators #16341

@JLHwung

Description

@JLHwung

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const dummy = () => {}

const logs = [];

@dummy
class C {
  [(logs.push(1), 1)];
  static [(logs.push(2), 2)];
  [(logs.push(3), 3)];
}

console.log(logs);

REPL

Configuration file name

No response

Configuration

{
  "plugins": [
    ["proposal-decorators", { "version": "2023-11" }]
  ]
}

Current and expected behavior

7.24.0: it prints [2, 1, 3]
main: it prints [1, 3, 2]
expected: it should print [1, 2, 3]

Environment

REPL

Possible solution

No response

Additional context

As a workaround, you can add a dummy decorator to any class elements, then the evaluation order will be correct.
For example,

const dummy = () => {}

const logs = [];

@dummy
class C {
  @dummy
  [(logs.push(1), 1)];
  static [(logs.push(2), 2)];
  [(logs.push(3), 3)];
}

console.log(logs);

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