Repository: babel/babel (TypeScript)

Issue:
[Bug]: (Babel transpilation fail) Duplicated name in class static block should be allowed
### 💻

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

### How are you using Babel?

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

### Input code

```js
class x { static { var x = 42; } }
```

### Configuration file name

_No response_

### Configuration

_No response_

### Current and expected behavior

The input code has no problem, but Babel throws error while transpiling the code.
```
$ node
Welcome to Node.js v18.11.0.
Type ".help" for more information.
> class x { static { var x = 42; } }
undefined
```

### Environment

[Reproduction on Babel's own REPL](https://babeljs.io/repl#?browsers=&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYGwhgzhAEAe0G9oQC5hQS2I6A3MATnNALzQAsATANzQC-9QA&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-parser/src/util/scopeflags.ts b/packages/babel-parser/src/util/scopeflags.ts
--- a/packages/babel-parser/src/util/scopeflags.ts
+++ b/packages/babel-parser/src/util/scopeflags.ts
@@ -10,7 +10,7 @@ export const SCOPE_OTHER        = 0b000000000,
              SCOPE_CLASS        = 0b001000000,
              SCOPE_STATIC_BLOCK = 0b010000000,
              SCOPE_TS_MODULE    = 0b100000000,
-             SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_TS_MODULE;
+             SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_STATIC_BLOCK | SCOPE_TS_MODULE;
 
 export type ScopeFlags =
   | typeof SCOPE_OTHER


Test patch:
diff --git a/packages/babel-parser/test/fixtures/es2022/class-static-block/re-declare-var/input.js b/packages/babel-parser/test/fixtures/es2022/class-static-block/re-declare-var/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-parser/test/fixtures/es2022/class-static-block/re-declare-var/input.js
@@ -0,0 +1,2 @@
+const y = 1;
+class x { static { var x = 42; var y; } }
diff --git a/packages/babel-parser/test/fixtures/es2022/class-static-block/re-declare-var/output.json b/packages/babel-parser/test/fixtures/es2022/class-static-block/re-declare-var/output.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-parser/test/fixtures/es2022/class-static-block/re-declare-var/output.json
@@ -0,0 +1,102 @@
+{
+  "type": "File",
+  "start":0,"end":54,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":41,"index":54}},
+  "program": {
+    "type": "Program",
+    "start":0,"end":54,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":41,"index":54}},
+    "sourceType": "script",
+    "interpreter": null,
+    "body": [
+      {
+        "type": "VariableDeclaration",
+        "start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}},
+        "declarations": [
+          {
+            "type": "VariableDeclarator",
+            "start":6,"end":11,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":11,"index":11}},
+            "id": {
+              "type": "Identifier",
+              "start":6,"end":7,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":7,"index":7},"identifierName":"y"},
+              "name": "y"
+            },
+            "init": {
+              "type": "NumericLiteral",
+              "start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11}},
+              "extra": {
+                "rawValue": 1,
+                "raw": "1"
+              },
+              "value": 1
+            }
+          }
+        ],
+        "kind": "const"
+      },
+      {
+        "type": "ClassDeclaration",
+        "start":13,"end":54,"loc":{"start":{"line":2,"column":0,"index":13},"end":{"line":2,"column":41,"index":54}},
+        "id": {
+          "type": "Identifier",
+          "start":19,"end":20,"loc":{"start":{"line":2,"column":6,"index":19},"end":{"line":2,"column":7,"index":20},"identifierName":"x"},
+          "name": "x"
+        },
+        "superClass": null,
+        "body": {
+          "type": "ClassBody",
+          "start":21,"end":54,"loc":{"start":{"line":2,"column":8,"index":21},"end":{"line":2,"column":41,"index":54}},
+          "body": [
+            {
+              "type": "StaticBlock",
+              "start":23,"end":52,"loc":{"start":{"line":2,"column":10,"index":23},"end":{"line":2,"column":39,"index":52}},
+              "body": [
+                {
+                  "type": "VariableDeclaration",
+                  "start":32,"end":43,"loc":{"start":{"line":2,"column":19,"index":32},"end":{"line":2,"column":30,"index":43}},
+                  "declarations": [
+                    {
+                      "type": "VariableDeclarator",
+                      "start":36,"end":42,"loc":{"start":{"line":2,"column":23,"index":36},"end":{"line":2,"column":29,"index":42}},
+                      "id": {
+                        "type": "Identifier",
+                        "start":36,"end":37,"loc":{"start":{"line":2,"column":23,"index":36},"end":{"line":2,"column":24,"index":37},"identifierName":"x"},
+                        "name": "x"
+                      },
+                      "init": {
+                        "type": "NumericLiteral",
+                        "start":40,"end":42,"loc":{"start":{"line":2,"column":27,"index":40},"end":{"line":2,"column":29,"index":42}},
+                        "extra": {
+                          "rawValue": 42,
+                          "raw": "42"
+                        },
+                        "value": 42
+                      }
+                    }
+                  ],
+                  "kind": "var"
+                },
+                {
+                  "type": "VariableDeclaration",
+                  "start":44,"end":50,"loc":{"start":{"line":2,"column":31,"index":44},"end":{"line":2,"column":37,"index":50}},
+                  "declarations": [
+                    {
+                      "type": "VariableDeclarator",
+                      "start":48,"end":49,"loc":{"start":{"line":2,"column":35,"index":48},"end":{"line":2,"column":36,"index":49}},
+                      "id": {
+                        "type": "Identifier",
+                        "start":48,"end":49,"loc":{"start":{"line":2,"column":35,"index":48},"end":{"line":2,"column":36,"index":49},"identifierName":"y"},
+                        "name": "y"
+                      },
+                      "init": null
+                    }
+                  ],
+                  "kind": "var"
+                }
+              ]
+            }
+          ]
+        }
+      }
+    ],
+    "directives": []
+  }
+}