File tree Expand file tree Collapse file tree 5 files changed +115
-3
lines changed
compiler/packages/babel-plugin-react-forget/src
__tests__/fixtures/compiler Expand file tree Collapse file tree 5 files changed +115
-3
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ function lowerStatement(
227227 builder : HIRBuilder ,
228228 stmtPath : NodePath < t . Statement > ,
229229 label : string | null = null
230- ) : undefined {
230+ ) : void {
231231 const stmtNode = stmtPath . node ;
232232 switch ( stmtNode . type ) {
233233 case "ThrowStatement" : {
@@ -1285,6 +1285,11 @@ function lowerStatement(
12851285
12861286 return ;
12871287 }
1288+ case "TypeAlias" :
1289+ case "TSTypeAliasDeclaration" : {
1290+ // We do not preserve type annotations/syntax through transformation
1291+ return ;
1292+ }
12881293 case "ClassDeclaration" :
12891294 case "DeclareClass" :
12901295 case "DeclareExportAllDeclaration" :
@@ -1303,15 +1308,13 @@ function lowerStatement(
13031308 case "ImportDeclaration" :
13041309 case "InterfaceDeclaration" :
13051310 case "OpaqueType" :
1306- case "TypeAlias" :
13071311 case "TSDeclareFunction" :
13081312 case "TSEnumDeclaration" :
13091313 case "TSExportAssignment" :
13101314 case "TSImportEqualsDeclaration" :
13111315 case "TSInterfaceDeclaration" :
13121316 case "TSModuleDeclaration" :
13131317 case "TSNamespaceExportDeclaration" :
1314- case "TSTypeAliasDeclaration" :
13151318 case "WithStatement" : {
13161319 builder . errors . push ( {
13171320 reason : `(BuildHIR::lowerStatement) Handle ${ stmtPath . type } statements` ,
Original file line number Diff line number Diff line change 1+
2+ ## Input
3+
4+ ``` javascript
5+ function Component (props ) {
6+ type User = { name: string };
7+ const user: User = { name: props .name };
8+ return user;
9+ }
10+
11+ export const FIXTURE_ENTRYPOINT = {
12+ fn: Component,
13+ params: [{ name: " Mofei" }],
14+ };
15+
16+ ```
17+
18+ ## Code
19+
20+ ``` javascript
21+ import { unstable_useMemoCache as useMemoCache } from " react" ;
22+ function Component (props ) {
23+ const $ = useMemoCache (2 );
24+ let t0;
25+ if ($[0 ] !== props .name ) {
26+ t0 = { name: props .name };
27+ $[0 ] = props .name ;
28+ $[1 ] = t0;
29+ } else {
30+ t0 = $[1 ];
31+ }
32+ const user = t0;
33+ return user;
34+ }
35+
36+ export const FIXTURE_ENTRYPOINT = {
37+ fn: Component,
38+ params: [{ name: " Mofei" }],
39+ };
40+
41+ ```
42+
43+ ### Eval output
44+ (kind: ok) {"name":"Mofei"}
Original file line number Diff line number Diff line change 1+ function Component ( props ) {
2+ type User = { name : string } ;
3+ const user : User = { name : props . name } ;
4+ return user ;
5+ }
6+
7+ export const FIXTURE_ENTRYPOINT = {
8+ fn : Component ,
9+ params : [ { name : "Mofei" } ] ,
10+ } ;
Original file line number Diff line number Diff line change 1+
2+ ## Input
3+
4+ ``` javascript
5+ // @flow
6+ function Component (props ) {
7+ type User = {name: string};
8+ const user: User = {name: props .name };
9+ return user;
10+ }
11+
12+ export const FIXTURE_ENTRYPOINT = {
13+ fn: Component,
14+ params: [{name: ' Mofei' }],
15+ };
16+ ```
17+
18+ ## Code
19+
20+ ``` javascript
21+ import { unstable_useMemoCache as useMemoCache } from " react" ;
22+ function Component (props ) {
23+ const $ = useMemoCache (2 );
24+ let t0;
25+ if ($[0 ] !== props .name ) {
26+ t0 = { name: props .name };
27+ $[0 ] = props .name ;
28+ $[1 ] = t0;
29+ } else {
30+ t0 = $[1 ];
31+ }
32+ const user = t0;
33+ return user;
34+ }
35+
36+ export const FIXTURE_ENTRYPOINT = {
37+ fn: Component,
38+ params: [{ name: " Mofei" }],
39+ };
40+
41+ ```
42+
43+ ### Eval output
44+ (kind: ok) {"name":"Mofei"}
Original file line number Diff line number Diff line change 1+ // @flow
2+ function Component ( props ) {
3+ type User = { name : string } ;
4+ const user : User = { name : props . name } ;
5+ return user ;
6+ }
7+
8+ export const FIXTURE_ENTRYPOINT = {
9+ fn : Component ,
10+ params : [ { name : 'Mofei' } ] ,
11+ } ;
You can’t perform that action at this time.
0 commit comments