Repository: babel/babel (TypeScript)

Issue:
[Bug]: Could not transpile code with enabled preset-env 
### 💻

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

### How are you using Babel?

@babel/cli

### Input code


```js
export class Number {
  static type = "number";
}
```

### Configuration file name

_No response_

### Configuration

_No response_

### Current and expected behavior

throw error 
```
We don't know what to do with this node type. We were previously a Statement but we can't fit in here?
```
transpile code this accordingly babel/preset-env

### Environment

https://babeljs.io/repl/#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=false&spec=false&loose=false&code_lz=KYDwDg9gTgLgBAYwDYEMDOa4DkCuBbAI2CjgG8AoOONGFGASwThgE8xg4BeOAIgDt8RKDwDc5AL7kgA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact&prettier=false&targets=&version=7.20.6&externalPlugins=&assumptions=%7B%7D

### Possible solution

_No response_

### Additional context

but this code works
```js
class Number {
  static type = "number";
}
export {Number}
```


Hints:
Hey @Mavrin! 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.
I noticed that code doesn't work when class name is name one of javascript type `String`, `Number`, `Symbol`

Patch:
diff --git a/packages/babel-traverse/src/path/modification.ts b/packages/babel-traverse/src/path/modification.ts
--- a/packages/babel-traverse/src/path/modification.ts
+++ b/packages/babel-traverse/src/path/modification.ts
@@ -13,6 +13,7 @@ import {
   expressionStatement,
   isAssignmentExpression,
   isCallExpression,
+  isExportNamedDeclaration,
   isExpression,
   isIdentifier,
   isSequenceExpression,
@@ -34,12 +35,19 @@ export function insertBefore(
 
   const nodes = this._verifyNodeList(nodes_);
 
-  const { parentPath } = this;
+  const { parentPath, parent } = this;
 
   if (
     parentPath.isExpressionStatement() ||
     parentPath.isLabeledStatement() ||
-    parentPath.isExportNamedDeclaration() ||
+    // https://github.com/babel/babel/issues/15293
+    // When Babel transforms `export class String { field }`, the class properties plugin will inject the defineProperty
+    // helper, which depends on the builtins e.g. String, Number, Symbol, etc. To prevent them from being shadowed by local
+    // exports, the helper injector replaces the named export into `class _String { field }; export { _String as String }`,
+    // with `parentPath` here changed to the moved ClassDeclaration, causing rare inconsistency between `parent` and `parentPath`.
+    // Here we retrieve the parent type from the `parent` property. This is a temporary fix and we should revisit when
+    // helpers should get injected.
+    isExportNamedDeclaration(parent) ||
     (parentPath.isExportDefaultDeclaration() && this.isDeclaration())
   ) {
     return parentPath.insertBefore(nodes);
@@ -169,11 +177,12 @@ export function insertAfter(
 
   const nodes = this._verifyNodeList(nodes_);
 
-  const { parentPath } = this;
+  const { parentPath, parent } = this;
   if (
     parentPath.isExpressionStatement() ||
     parentPath.isLabeledStatement() ||
-    parentPath.isExportNamedDeclaration() ||
+    // see insertBefore
+    isExportNamedDeclaration(parent) ||
     (parentPath.isExportDefaultDeclaration() && this.isDeclaration())
   ) {
     return parentPath.insertAfter(


Test patch:
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/input.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/input.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/input.mjs
@@ -0,0 +1,3 @@
+export class TypeError {
+  #message
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/options.json
@@ -0,0 +1,4 @@
+{
+  "plugins": ["proposal-class-properties"],
+  "externalHelpers": false
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/output.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/class-shadow-builtins/output.mjs
@@ -0,0 +1,12 @@
+function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
+function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
+var _message = /*#__PURE__*/new WeakMap();
+class _TypeError {
+  constructor() {
+    _classPrivateFieldInitSpec(this, _message, {
+      writable: true,
+      value: void 0
+    });
+  }
+}
+export { _TypeError as TypeError };
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/input.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/input.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/input.mjs
@@ -0,0 +1,3 @@
+export class TypeError {
+  #message
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/options.json
@@ -0,0 +1,4 @@
+{
+  "plugins": ["proposal-class-properties"],
+  "externalHelpers": false
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/output.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/class-shadow-builtins/output.mjs
@@ -0,0 +1,12 @@
+function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
+function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
+var _message = /*#__PURE__*/new WeakMap();
+class _TypeError {
+  constructor() {
+    _classPrivateFieldInitSpec(this, _message, {
+      writable: true,
+      value: void 0
+    });
+  }
+}
+export { _TypeError as TypeError };
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/input.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/input.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/input.mjs
@@ -0,0 +1,3 @@
+export class TypeError {
+  message
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/options.json
@@ -0,0 +1,4 @@
+{
+  "plugins": ["proposal-class-properties"],
+  "externalHelpers": false
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/output.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/class-shadow-builtins/output.mjs
@@ -0,0 +1,9 @@
+function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
+function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
+function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
+class _TypeError {
+  constructor() {
+    _defineProperty(this, "message", void 0);
+  }
+}
+export { _TypeError as TypeError };
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/input.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/input.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/input.mjs
@@ -0,0 +1,3 @@
+export class TypeError {
+  message
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/options.json
@@ -0,0 +1,4 @@
+{
+  "plugins": ["proposal-class-properties"],
+  "externalHelpers": false
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/output.mjs
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/class-shadow-builtins/output.mjs
@@ -0,0 +1,9 @@
+function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
+function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
+function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
+class _TypeError {
+  constructor() {
+    _defineProperty(this, "message", void 0);
+  }
+}
+export { _TypeError as TypeError };