Repository: babel/babel (TypeScript)

Issue:
[Bug]: `in` operator in computed field
### 💻

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

### How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

### Input code

```js
class x { [ 0 in 0 ] ; } 
```

### Configuration file name

_No response_

### Configuration

_No response_

### Current and expected behavior

The input program is expected to throw TypeError but the transpiled program terminates without any error.
```console
$ node
Welcome to Node.js v18.11.0.
Type ".help" for more information.
> class x { [ 0 in 0 ] ; }
Uncaught TypeError: Cannot use 'in' operator to search for '0' in 0
```
By the way, the transpiled code throws error lazily (after calling `new x`):
```console
$ node
Welcome to Node.js v18.11.0.
Type ".help" for more information.
> `transpiled code`
undefined // no error
> new x
Uncaught TypeError: Cannot use 'in' operator to search for '0' in 0
    at new x (REPL39:5:27)
```

### Environment

[Reproductions on Babel's own REPL](https://babeljs.io/repl#?browsers=&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYGwhgzhAEAe0G9oG1oAZoEsB27oF1oBuaAXyA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=script&lineWrap=true&presets=env%2Creact%2Cstage-2&prettier=true&targets=&version=7.20.0&externalPlugins=&assumptions=%7B%7D)

### Possible solution

_No response_

### Additional context

_No response_


Hints:
Hey @p51lee! 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-traverse/src/path/introspection.ts b/packages/babel-traverse/src/path/introspection.ts
--- a/packages/babel-traverse/src/path/introspection.ts
+++ b/packages/babel-traverse/src/path/introspection.ts
@@ -634,7 +634,10 @@ export function isConstantExpression(this: NodePath): boolean {
   }
 
   if (this.isBinaryExpression()) {
+    const { operator } = this.node;
     return (
+      operator !== "in" &&
+      operator !== "instanceof" &&
       this.get("left").isConstantExpression() &&
       this.get("right").isConstantExpression()
     );


Test patch:
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/exec.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/exec.js
@@ -0,0 +1,7 @@
+expect(() => {
+  class X { [0 in 0]; }
+}).toThrow();
+
+expect(() => {
+  class X { [0 instanceof 0]; }
+}).toThrow();
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/input.js
@@ -0,0 +1,4 @@
+class X {
+  [ 0 in 0 ];
+  [ 0 instanceof 0 ];
+}
\ No newline at end of file
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/options.json
@@ -0,0 +1,3 @@
+{
+  "plugins": ["proposal-class-properties"]
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/15098/output.js
@@ -0,0 +1,9 @@
+let _ref, _ref2;
+_ref = 0 in 0;
+_ref2 = 0 instanceof 0;
+class X {
+  constructor() {
+    babelHelpers.defineProperty(this, _ref, void 0);
+    babelHelpers.defineProperty(this, _ref2, void 0);
+  }
+}