feat(compiler): Ignore `TSInterfaceDeclaration` (#30314)
## Summary The following was not supported: ```ts function A() { interface C { id: number; } return 0; } ``` Message: > Todo: (BuildHIR::lowerStatement) Handle TSInterfaceDeclaration statements (2:4) Playground: https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAggBQCURwAOsUXpjgjGgIaJEDC1dR-DACbIimKAFsARiwDcfIgF95MBDljEADHMwKQCoA This PR fixes that. ## How did you test this change? Added a test.
Niklas Mollenhauer committed
Jul 11, 2024 at 04:11 UTC
6587fe19338d22076b9c0fe50185717218b4a8bc
3 files changed
+48
-1
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
+1
-1
@@ -1332,6 +1332,7 @@ function lowerStatement(
1332
return;
1333
}
1334
case "TypeAlias":
1335
+ case "TSInterfaceDeclaration":
1336
case "TSTypeAliasDeclaration": {
1337
// We do not preserve type annotations/syntax through transformation
1338
return;
@@ -1358,7 +1359,6 @@ function lowerStatement(
1359
case "TSEnumDeclaration":
1360
case "TSExportAssignment":
1361
case "TSImportEqualsDeclaration":
1361
- case "TSInterfaceDeclaration":
1362
case "TSModuleDeclaration":
1363
case "TSNamespaceExportDeclaration":
1364
case "WithStatement": {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md
new
+35
@@ -0,0 +1,35 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Foo() {
6
+ type X = number;
7
+ interface Bar {
8
+ baz: number;
9
+ }
10
+ return 0;
11
+}
12
+
13
+export const FIXTURE_ENTRYPOINT = {
14
+ fn: Foo,
15
+ params: [],
16
+};
17
+
18
+```
19
+
20
+## Code
21
+
22
+```javascript
23
+function Foo() {
24
+ return 0;
25
+}
26
+
27
+export const FIXTURE_ENTRYPOINT = {
28
+ fn: Foo,
29
+ params: [],
30
+};
31
+
32
+```
33
+
34
+### Eval output
35
+(kind: ok) 0
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.ts
new
+12
@@ -0,0 +1,12 @@
1
+function Foo() {
2
+ type X = number;
3
+ interface Bar {
4
+ baz: number;
5
+ }
6
+ return 0;
7
+}
8
+
9
+export const FIXTURE_ENTRYPOINT = {
10
+ fn: Foo,
11
+ params: [],
12
+};