From 6587fe19338d22076b9c0fe50185717218b4a8bc Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Thu, 11 Jul 2024 04:11:04 +0200 Subject: [PATCH] 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. --- .../src/HIR/BuildHIR.ts | 2 +- .../ignore-inner-interface-types.expect.md | 35 +++++++++++++++++++ .../compiler/ignore-inner-interface-types.ts | 12 +++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.ts diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts index e5a067018dac9..233a5e4b32fc6 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -1332,6 +1332,7 @@ function lowerStatement( return; } case "TypeAlias": + case "TSInterfaceDeclaration": case "TSTypeAliasDeclaration": { // We do not preserve type annotations/syntax through transformation return; @@ -1358,7 +1359,6 @@ function lowerStatement( case "TSEnumDeclaration": case "TSExportAssignment": case "TSImportEqualsDeclaration": - case "TSInterfaceDeclaration": case "TSModuleDeclaration": case "TSNamespaceExportDeclaration": case "WithStatement": { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md new file mode 100644 index 0000000000000..b4d8a4155c3b3 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md @@ -0,0 +1,35 @@ + +## Input + +```javascript +function Foo() { + type X = number; + interface Bar { + baz: number; + } + return 0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], +}; + +``` + +## Code + +```javascript +function Foo() { + return 0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], +}; + +``` + +### Eval output +(kind: ok) 0 \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.ts b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.ts new file mode 100644 index 0000000000000..4330642bcf7a6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.ts @@ -0,0 +1,12 @@ +function Foo() { + type X = number; + interface Bar { + baz: number; + } + return 0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], +};