diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts index 77b860051d..5f26d0e6a9 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts @@ -227,7 +227,7 @@ function lowerStatement( builder: HIRBuilder, stmtPath: NodePath, label: string | null = null -): undefined { +): void { const stmtNode = stmtPath.node; switch (stmtNode.type) { case "ThrowStatement": { @@ -1285,6 +1285,11 @@ function lowerStatement( return; } + case "TypeAlias": + case "TSTypeAliasDeclaration": { + // We do not preserve type annotations/syntax through transformation + return; + } case "ClassDeclaration": case "DeclareClass": case "DeclareExportAllDeclaration": @@ -1303,7 +1308,6 @@ function lowerStatement( case "ImportDeclaration": case "InterfaceDeclaration": case "OpaqueType": - case "TypeAlias": case "TSDeclareFunction": case "TSEnumDeclaration": case "TSExportAssignment": @@ -1311,7 +1315,6 @@ function lowerStatement( case "TSInterfaceDeclaration": case "TSModuleDeclaration": case "TSNamespaceExportDeclaration": - case "TSTypeAliasDeclaration": case "WithStatement": { builder.errors.push({ reason: `(BuildHIR::lowerStatement) Handle ${stmtPath.type} statements`, diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-declaration.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-declaration.expect.md new file mode 100644 index 0000000000..1648afe274 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-declaration.expect.md @@ -0,0 +1,44 @@ + +## Input + +```javascript +function Component(props) { + type User = { name: string }; + const user: User = { name: props.name }; + return user; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ name: "Mofei" }], +}; + +``` + +## Code + +```javascript +import { unstable_useMemoCache as useMemoCache } from "react"; +function Component(props) { + const $ = useMemoCache(2); + let t0; + if ($[0] !== props.name) { + t0 = { name: props.name }; + $[0] = props.name; + $[1] = t0; + } else { + t0 = $[1]; + } + const user = t0; + return user; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ name: "Mofei" }], +}; + +``` + +### Eval output +(kind: ok) {"name":"Mofei"} \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-declaration.ts b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-declaration.ts new file mode 100644 index 0000000000..0fa78d9001 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-declaration.ts @@ -0,0 +1,10 @@ +function Component(props) { + type User = { name: string }; + const user: User = { name: props.name }; + return user; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ name: "Mofei" }], +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias.flow.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias.flow.expect.md new file mode 100644 index 0000000000..a987e40e28 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias.flow.expect.md @@ -0,0 +1,44 @@ + +## Input + +```javascript +// @flow +function Component(props) { + type User = {name: string}; + const user: User = {name: props.name}; + return user; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{name: 'Mofei'}], +}; +``` + +## Code + +```javascript +import { unstable_useMemoCache as useMemoCache } from "react"; +function Component(props) { + const $ = useMemoCache(2); + let t0; + if ($[0] !== props.name) { + t0 = { name: props.name }; + $[0] = props.name; + $[1] = t0; + } else { + t0 = $[1]; + } + const user = t0; + return user; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ name: "Mofei" }], +}; + +``` + +### Eval output +(kind: ok) {"name":"Mofei"} \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias.flow.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias.flow.js new file mode 100644 index 0000000000..d5baed67ca --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias.flow.js @@ -0,0 +1,11 @@ +// @flow +function Component(props) { + type User = {name: string}; + const user: User = {name: props.name}; + return user; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{name: 'Mofei'}], +}; \ No newline at end of file