Support type alias syntax

"Support" in the sense of dropping these on the floor and compiling, rather than 
bailing out with a todo. 

We already don't make any guarantees about which type annotations we'll preserve 
through to the output, so it seems fine for now to just drop type aliases.
This commit is contained in:
Joe Savona
2024-03-13 22:17:19 -07:00
parent 1b5ae0638e
commit 459679f91e
5 changed files with 115 additions and 3 deletions
@@ -227,7 +227,7 @@ function lowerStatement(
builder: HIRBuilder,
stmtPath: NodePath<t.Statement>,
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`,
@@ -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"}
@@ -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" }],
};
@@ -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"}
@@ -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'}],
};