Repository: babel/babel (TypeScript)

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

- [X] Would you like to work on a fix?

### How are you using Babel?

Programmatic API (`babel.transform`, `babel.parse`)

### Input code

```js
const dummy = () => {}

const logs = [];

@dummy
class C {
  [(logs.push(1), 1)];
  static [(logs.push(2), 2)];
  [(logs.push(3), 3)];
}

console.log(logs);
```

[REPL](https://babel.dev/repl#?browsers=chrome%2032&build=&builtIns=false&corejs=3.21&spec=false&loose=true&code_lz=MYewdgzgLgBAJgVwLZIJ4wLwwBQEpMB8MA3gL4BQ5oksANiAOYSYwDaAugNyUACiKqKrQCGEZgGES5GG2z0mAOgAOCCAAtsARlwAaGNq7SY0YVACWwWfIjLVGgEy6YjwzNZzGNleuwBmJ_6GFFTgECC0AKYK8h5MuJxAA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=false&targets=&version=7.24.0&externalPlugins=%40babel%2Fplugin-proposal-decorators%407.23.3&assumptions=%7B%7D)

### Configuration file name

_No response_

### Configuration

```json
{
  "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,

```js
const dummy = () => {}

const logs = [];

@dummy
class C {
  @dummy
  [(logs.push(1), 1)];
  static [(logs.push(2), 2)];
  [(logs.push(3), 3)];
}

console.log(logs);
```


Hints:
Hey @JLHwung! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant [Slack community](https://babeljs.slack.com) that typically always has someone willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite.

Patch:
diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts
--- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts
+++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts
@@ -1219,6 +1219,7 @@ function transformClass(
   let classDecorationsFlag = 0;
   let classDecorations: t.Expression[] = [];
   let classDecorationsId: t.Identifier;
+  let computedKeyAssignments: t.AssignmentExpression[] = [];
   if (classDecorators) {
     classInitLocal = generateLetUidIdentifier(scopeParent, "initClass");
     needsDeclaraionForClassBinding = path.isClassDeclaration();
@@ -1249,6 +1250,40 @@ function transformClass(
         classAssignments,
       );
     }
+
+    if (!hasElementDecorators) {
+      // Sync body paths as non-decorated computed accessors have been transpiled
+      // to getter-setter pairs.
+      for (const element of path.get("body.body")) {
+        const { node } = element;
+        const isComputed = "computed" in node && node.computed;
+        if (isComputed) {
+          if (element.isClassProperty({ static: true })) {
+            if (!element.get("key").isConstantExpression()) {
+              const key = (node as t.ClassProperty).key;
+              const maybeAssignment = memoiseComputedKey(
+                key,
+                scopeParent,
+                scopeParent.generateUid("computedKey"),
+              );
+              if (maybeAssignment != null) {
+                // If it is a static computed field within a decorated class, we move the computed key
+                // into `computedKeyAssignments` which will be then moved into the non-static class,
+                // to ensure that the evaluation order and private environment are correct
+                node.key = t.cloneNode(maybeAssignment.left);
+                computedKeyAssignments.push(maybeAssignment);
+              }
+            }
+          } else if (computedKeyAssignments.length > 0) {
+            prependExpressionsToComputedKey(
+              computedKeyAssignments,
+              element as NodePath<ClassElementCanHaveComputedKeys>,
+            );
+            computedKeyAssignments = [];
+          }
+        }
+      }
+    }
   } else {
     if (!path.node.id) {
       path.node.id = path.scope.generateUidIdentifier("Class");
@@ -1259,7 +1294,6 @@ function transformClass(
   let lastInstancePrivateName: t.PrivateName;
   let needsInstancePrivateBrandCheck = false;
 
-  let computedKeyAssignments: t.AssignmentExpression[] = [];
   let fieldInitializerExpressions = [];
   let staticFieldInitializerExpressions: t.Expression[] = [];
 


Test patch:
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-private-environment-super/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-private-environment-super/exec.js
--- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-private-environment-super/exec.js
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes--to-es2015/replacement-static-private-environment-super/exec.js
@@ -36,3 +36,72 @@
   }
   expect([...A].map(fn => fn(b)).join()).toBe("B#x,B#x");
 }
+
+{
+  "different private/super access in a non-decorated static method";
+
+  let b;
+
+  const idFactory = (hint) => {
+    return class { static ["id" + hint](v) { return v } }
+  }
+
+  class C extends idFactory("C") { #x = "C#x"; }
+
+  const dec = (b) => {
+    originalB = b;
+    return C;
+  }
+
+  class A extends idFactory("A") {
+    #x = "A#x";
+    static *[Symbol.iterator]() {
+      @dec
+      class B extends idFactory("B") {
+        #x = "B#x";
+        static [(yield super.idA(o => o.#x), Symbol.iterator)] = function* () {
+          yield (o => o.#x);
+        }
+      }
+      b = new originalB();
+      yield* B;
+    }
+  }
+  expect([...A].map(fn => fn(b)).join()).toBe("B#x,B#x");
+}
+
+{
+  "different private/super access in a decorated static method";
+
+  const dummy = () => {};
+
+  let b;
+
+  const idFactory = (hint) => {
+    return class { static ["id" + hint](v) { return v } }
+  }
+
+  class C extends idFactory("C") { #x = "C#x"; }
+
+  const dec = (b) => {
+    originalB = b;
+    return C;
+  }
+
+  class A extends idFactory("A") {
+    #x = "A#x";
+    static *[Symbol.iterator]() {
+      @dec
+      class B extends idFactory("B") {
+        #x = "B#x";
+        @(yield super.idA(o => o.#x), dummy)
+        static [(yield super.idA(o => o.#x), Symbol.iterator)] = function* () {
+          yield (o => o.#x);
+        }
+      }
+      b = new originalB();
+      yield* B;
+    }
+  }
+  expect([...A].map(fn => fn(b)).join()).toBe("B#x,B#x,B#x");
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/.replacement-static-private-environment-super-2/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/.replacement-static-private-environment-super-2/exec.js
deleted file mode 100644
--- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/.replacement-static-private-environment-super-2/exec.js
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "different private/super access in a static method";
-
-  let b;
-
-  const idFactory = (hint) => {
-    return class { static ["id" + hint](v) { return v } }
-  }
-
-  class C extends idFactory("C") { #x = "C#x"; }
-
-  const dec = (b) => {
-    originalB = b;
-    return C;
-  }
-
-  const fns = [];
-
-  class A extends idFactory("A") {
-    #x = "A#x";
-    static {
-      @dec
-      class B extends idFactory("B") {
-        #x = "B#x";
-        static [(fns.push(super.idA(o => o.#x)), "iter")] = () => {
-          fns.push(o => o.#x);
-        }
-      }
-      b = new originalB();
-      B.iter();
-    }
-  }
-  expect(fns.map(fn => fn(b)).join()).toBe("B#x,B#x");
-}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-private-environment-super/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-private-environment-super/exec.js
--- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-private-environment-super/exec.js
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-classes/replacement-static-private-environment-super/exec.js
@@ -36,3 +36,72 @@
   }
   expect([...A].map(fn => fn(b)).join()).toBe("B#x,B#x");
 }
+
+{
+  "different private/super access in a non-decorated static method";
+
+  let b;
+
+  const idFactory = (hint) => {
+    return class { static ["id" + hint](v) { return v } }
+  }
+
+  class C extends idFactory("C") { #x = "C#x"; }
+
+  const dec = (b) => {
+    originalB = b;
+    return C;
+  }
+
+  class A extends idFactory("A") {
+    #x = "A#x";
+    static *[Symbol.iterator]() {
+      @dec
+      class B extends idFactory("B") {
+        #x = "B#x";
+        static [(yield super.idA(o => o.#x), Symbol.iterator)] = function* () {
+          yield (o => o.#x);
+        }
+      }
+      b = new originalB();
+      yield* B;
+    }
+  }
+  expect([...A].map(fn => fn(b)).join()).toBe("B#x,B#x");
+}
+
+{
+  "different private/super access in a decorated static method";
+
+  const dummy = () => {};
+
+  let b;
+
+  const idFactory = (hint) => {
+    return class { static ["id" + hint](v) { return v } }
+  }
+
+  class C extends idFactory("C") { #x = "C#x"; }
+
+  const dec = (b) => {
+    originalB = b;
+    return C;
+  }
+
+  class A extends idFactory("A") {
+    #x = "A#x";
+    static *[Symbol.iterator]() {
+      @dec
+      class B extends idFactory("B") {
+        #x = "B#x";
+        @(yield super.idA(o => o.#x), dummy)
+        static [(yield super.idA(o => o.#x), Symbol.iterator)] = function* () {
+          yield (o => o.#x);
+        }
+      }
+      b = new originalB();
+      yield* B;
+    }
+  }
+  expect([...A].map(fn => fn(b)).join()).toBe("B#x,B#x,B#x");
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/exec.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/exec.js
@@ -0,0 +1,118 @@
+const classDec1 = (log) => (cls, ctxClass) => {
+  log.push("c2");
+  ctxClass.addInitializer(() => log.push("c5"));
+  ctxClass.addInitializer(() => log.push("c6"));
+};
+const classDec2 = (log) => (cls, ctxClass) => {
+  log.push("c1");
+  ctxClass.addInitializer(() => log.push("c3"));
+  ctxClass.addInitializer(() => log.push("c4"));
+};
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    async [log.push("k2")](v) {};
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    get [log.push("k1")]() {};
+    static [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    accessor [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static set [log.push("k1")](v) {};
+    [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    static [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/input.js
@@ -0,0 +1,118 @@
+const classDec1 = (log) => (cls, ctxClass) => {
+  log.push("c2");
+  ctxClass.addInitializer(() => log.push("c5"));
+  ctxClass.addInitializer(() => log.push("c6"));
+};
+const classDec2 = (log) => (cls, ctxClass) => {
+  log.push("c1");
+  ctxClass.addInitializer(() => log.push("c3"));
+  ctxClass.addInitializer(() => log.push("c4"));
+};
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    async [log.push("k2")](v) {};
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    get [log.push("k1")]() {};
+    static [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    accessor [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static set [log.push("k1")](v) {};
+    [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    static [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/options.json
@@ -0,0 +1,3 @@
+{
+  "minNodeVersion": "7.6.0"
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering--to-es2015/class-decorators-without-element-decorators/output.js
@@ -0,0 +1,155 @@
+const classDec1 = log => (cls, ctxClass) => {
+  log.push("c2");
+  ctxClass.addInitializer(() => log.push("c5"));
+  ctxClass.addInitializer(() => log.push("c6"));
+};
+const classDec2 = log => (cls, ctxClass) => {
+  log.push("c1");
+  ctxClass.addInitializer(() => log.push("c3"));
+  ctxClass.addInitializer(() => log.push("c4"));
+};
+{
+  var _C2;
+  let _initClass, _classDecs, _log$push, _log$push2, _log$push3;
+  const log = [];
+  _classDecs = [classDec1(log), classDec2(log)];
+  let _C;
+  _log$push = log.push("k1");
+  _log$push2 = log.push("k2");
+  _log$push3 = log.push("k3");
+  class C {
+    constructor() {
+      babelHelpers.defineProperty(this, _log$push, void 0);
+      babelHelpers.defineProperty(this, _log$push2, void 0);
+      babelHelpers.defineProperty(this, _log$push3, void 0);
+    }
+  }
+  _C2 = C;
+  [_C, _initClass] = babelHelpers.applyDecs2311(_C2, _classDecs, []).c;
+  _initClass();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  var _Class, _C5;
+  let _initClass2, _classDecs2, _computedKey, _C4, _ref, _log$push4;
+  const log = [];
+  _classDecs2 = [classDec1(log), classDec2(log)];
+  let _C3;
+  new (_C4 = (_ref = (_computedKey = log.push("k1"), log.push("k2")), _log$push4 = log.push("k3"), (_C5 = class C {
+    constructor() {
+      babelHelpers.defineProperty(this, _log$push4, void 0);
+    }
+    async [_ref](v) {}
+  }, [_C3, _initClass2] = babelHelpers.applyDecs2311(_C5, _classDecs2, []).c, _C5)), (_Class = class extends babelHelpers.identity {
+    constructor() {
+      (super(_C3), babelHelpers.defineProperty(this, _computedKey, void 0)), _initClass2();
+    }
+  }, babelHelpers.defineProperty(_Class, _C4, void 0), _Class))();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  var _Class2, _C8;
+  let _initClass3, _classDecs3, _computedKey3, _C7, _log$push5, _ref2;
+  const log = [];
+  _classDecs3 = [classDec1(log), classDec2(log)];
+  let _C6;
+  new (_C7 = (_log$push5 = log.push("k1"), _ref2 = (_computedKey3 = log.push("k2"), log.push("k3")), (_C8 = class C {
+    constructor() {
+      babelHelpers.defineProperty(this, _ref2, void 0);
+    }
+    get [_log$push5]() {}
+  }, [_C6, _initClass3] = babelHelpers.applyDecs2311(_C8, _classDecs3, []).c, _C8)), (_Class2 = class extends babelHelpers.identity {
+    constructor() {
+      (super(_C6), babelHelpers.defineProperty(this, _computedKey3, void 0)), _initClass3();
+    }
+  }, babelHelpers.defineProperty(_Class2, _C7, void 0), _Class2))();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  var _Class3, _C11, _A;
+  let _computedKey5, _initClass4, _classDecs4, _computedKey6, _C10, _log$push6, _ref3;
+  const log = [];
+  _classDecs4 = [classDec1(log), classDec2(log)];
+  let _C9;
+  new (_C10 = (_A = /*#__PURE__*/new WeakMap(), _log$push6 = log.push("k1"), _computedKey5 = babelHelpers.toPropertyKey(log.push("k2")), _ref3 = (_computedKey6 = log.push("k3"), _computedKey5), (_C11 = class C {
+    constructor() {
+      babelHelpers.defineProperty(this, _log$push6, void 0);
+      babelHelpers.classPrivateFieldInitSpec(this, _A, void 0);
+    }
+    get [_computedKey5]() {
+      return babelHelpers.classPrivateFieldGet2(_A, this);
+    }
+    set [_ref3](v) {
+      babelHelpers.classPrivateFieldSet2(_A, this, v);
+    }
+  }, [_C9, _initClass4] = babelHelpers.applyDecs2311(_C11, _classDecs4, []).c, _C11)), (_Class3 = class extends babelHelpers.identity {
+    constructor() {
+      (super(_C9), babelHelpers.defineProperty(this, _computedKey6, void 0)), _initClass4();
+    }
+  }, babelHelpers.defineProperty(_Class3, _C10, void 0), _Class3))();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  var _Class4, _C14;
+  let _initClass5, _classDecs5, _computedKey10, _computedKey11, _C13, _log$push7, _ref4;
+  const log = [];
+  _classDecs5 = [classDec1(log), classDec2(log)];
+  let _C12;
+  new (_C13 = (_log$push7 = log.push("k1"), _ref4 = (_computedKey11 = log.push("k2"), _computedKey10 = log.push("k3"), _computedKey11), (_C14 = class C {
+    constructor() {
+      babelHelpers.defineProperty(this, _ref4, void 0);
+    }
+    static set [_log$push7](v) {}
+  }, [_C12, _initClass5] = babelHelpers.applyDecs2311(_C14, _classDecs5, []).c, _C14)), (_Class4 = class extends babelHelpers.identity {
+    constructor() {
+      (super(_C12), babelHelpers.defineProperty(this, _computedKey10, void 0)), _initClass5();
+    }
+  }, babelHelpers.defineProperty(_Class4, _C13, void 0), _Class4))();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  var _Class5, _C17;
+  let _initClass6, _classDecs6, _computedKey13, _computedKey14, _computedKey15, _C16, _ref5;
+  const log = [];
+  _classDecs6 = [classDec1(log), classDec2(log)];
+  let _C15;
+  new (_C16 = (_ref5 = (_computedKey13 = log.push("k1"), _computedKey14 = log.push("k2"), _computedKey15 = log.push("k3"), "_"), (_C17 = class C {}, babelHelpers.defineProperty(_C17, _ref5, void 0), (() => {
+    delete _C17._;
+    [_C15, _initClass6] = babelHelpers.applyDecs2311(_C17, _classDecs6, []).c;
+  })(), _C17)), (_Class5 = class extends babelHelpers.identity {
+    constructor() {
+      (super(_C15), babelHelpers.defineProperty(this, _computedKey13, void 0), babelHelpers.defineProperty(this, _computedKey14, void 0), babelHelpers.defineProperty(this, _computedKey15, void 0)), _initClass6();
+    }
+  }, babelHelpers.defineProperty(_Class5, _C16, void 0), _Class5))();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/exec.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/exec.js
@@ -0,0 +1,118 @@
+const classDec1 = (log) => (cls, ctxClass) => {
+  log.push("c2");
+  ctxClass.addInitializer(() => log.push("c5"));
+  ctxClass.addInitializer(() => log.push("c6"));
+};
+const classDec2 = (log) => (cls, ctxClass) => {
+  log.push("c1");
+  ctxClass.addInitializer(() => log.push("c3"));
+  ctxClass.addInitializer(() => log.push("c4"));
+};
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    async [log.push("k2")](v) {};
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    get [log.push("k1")]() {};
+    static [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    accessor [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static set [log.push("k1")](v) {};
+    [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    static [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/input.js
@@ -0,0 +1,118 @@
+const classDec1 = (log) => (cls, ctxClass) => {
+  log.push("c2");
+  ctxClass.addInitializer(() => log.push("c5"));
+  ctxClass.addInitializer(() => log.push("c6"));
+};
+const classDec2 = (log) => (cls, ctxClass) => {
+  log.push("c1");
+  ctxClass.addInitializer(() => log.push("c3"));
+  ctxClass.addInitializer(() => log.push("c4"));
+};
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    async [log.push("k2")](v) {};
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    get [log.push("k1")]() {};
+    static [log.push("k2")];
+    [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    [log.push("k1")];
+    accessor [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static set [log.push("k1")](v) {};
+    [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
+
+{
+  const log = [];
+
+  @classDec1(log)
+  @classDec2(log)
+  class C {
+    static [log.push("k1")];
+    static [log.push("k2")];
+    static [log.push("k3")];
+  }
+
+  expect(log.join()).toBe(
+    "k1,k2,k3," + // ClassElementEvaluation
+      "c1,c2," + // ApplyDecoratorsToClassDefinition
+      "c3,c4,c5,c6", // classExtraInitializers
+  );
+}
diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-11-ordering/class-decorators-without-element-decorators/output.js
@@ -0,0 +1,166 @@
+const classDec1 = log => (cls, ctxClass) => {
+  log.push("c2");
+  ctxClass.addInitializer(() => log.push("c5"));
+  ctxClass.addInitializer(() => log.push("c6"));
+};
+const classDec2 = log => (cls, ctxClass) => {
+  log.push("c1");
+  ctxClass.addInitializer(() => log.push("c3"));
+  ctxClass.addInitializer(() => log.push("c4"));
+};
+{
+  let _initClass, _classDecs;
+  const log = [];
+  _classDecs = [classDec1(log), classDec2(log)];
+  let _C;
+  class C {
+    static {
+      [_C, _initClass] = babelHelpers.applyDecs2311(this, _classDecs, []).c;
+    }
+    [log.push("k1")];
+    [log.push("k2")];
+    [log.push("k3")];
+    static {
+      _initClass();
+    }
+  }
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  let _initClass2, _classDecs2, _computedKey;
+  const log = [];
+  _classDecs2 = [classDec1(log), classDec2(log)];
+  let _C2;
+  new class extends babelHelpers.identity {
+    static [class C {
+      static {
+        [_C2, _initClass2] = babelHelpers.applyDecs2311(this, _classDecs2, []).c;
+      }
+      async [(_computedKey = log.push("k1"), log.push("k2"))](v) {}
+      [log.push("k3")];
+    }];
+    [_computedKey];
+    constructor() {
+      super(_C2), _initClass2();
+    }
+  }();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  let _initClass3, _classDecs3, _computedKey2;
+  const log = [];
+  _classDecs3 = [classDec1(log), classDec2(log)];
+  let _C3;
+  new class extends babelHelpers.identity {
+    static [class C {
+      static {
+        [_C3, _initClass3] = babelHelpers.applyDecs2311(this, _classDecs3, []).c;
+      }
+      get [log.push("k1")]() {}
+      [(_computedKey2 = log.push("k2"), log.push("k3"))];
+    }];
+    [_computedKey2];
+    constructor() {
+      super(_C3), _initClass3();
+    }
+  }();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  let _computedKey3, _initClass4, _classDecs4, _computedKey4;
+  const log = [];
+  _classDecs4 = [classDec1(log), classDec2(log)];
+  let _C4;
+  new class extends babelHelpers.identity {
+    static [class C {
+      static {
+        [_C4, _initClass4] = babelHelpers.applyDecs2311(this, _classDecs4, []).c;
+      }
+      [log.push("k1")];
+      #A;
+      get [_computedKey3 = babelHelpers.toPropertyKey(log.push("k2"))]() {
+        return this.#A;
+      }
+      set [(_computedKey4 = log.push("k3"), _computedKey3)](v) {
+        this.#A = v;
+      }
+    }];
+    [_computedKey4];
+    constructor() {
+      super(_C4), _initClass4();
+    }
+  }();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  let _initClass5, _classDecs5, _computedKey6, _computedKey7;
+  const log = [];
+  _classDecs5 = [classDec1(log), classDec2(log)];
+  let _C5;
+  new class extends babelHelpers.identity {
+    static [class C {
+      static {
+        [_C5, _initClass5] = babelHelpers.applyDecs2311(this, _classDecs5, []).c;
+      }
+      static set [log.push("k1")](v) {}
+      [(_computedKey7 = log.push("k2"), _computedKey6 = log.push("k3"), _computedKey7)];
+    }];
+    [_computedKey6];
+    constructor() {
+      super(_C5), _initClass5();
+    }
+  }();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}
+{
+  let _initClass6, _classDecs6, _computedKey8, _computedKey9, _computedKey10;
+  const log = [];
+  _classDecs6 = [classDec1(log), classDec2(log)];
+  let _C6;
+  new class extends babelHelpers.identity {
+    static [class C {
+      static [(_computedKey8 = log.push("k1"), _computedKey9 = log.push("k2"), _computedKey10 = log.push("k3"), "_")];
+      static {
+        delete this._;
+        [_C6, _initClass6] = babelHelpers.applyDecs2311(this, _classDecs6, []).c;
+      }
+    }];
+    [_computedKey8];
+    [_computedKey9];
+    [_computedKey10];
+    constructor() {
+      super(_C6), _initClass6();
+    }
+  }();
+  expect(log.join()).toBe("k1,k2,k3," +
+  // ClassElementEvaluation
+  "c1,c2," +
+  // ApplyDecoratorsToClassDefinition
+  "c3,c4,c5,c6" // classExtraInitializers
+  );
+}