File tree Expand file tree Collapse file tree 3 files changed +75
-0
lines changed
compiler/packages/babel-plugin-react-compiler/src
__tests__/fixtures/compiler Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,21 @@ const UNTYPED_GLOBALS: Set<string> = new Set([
87
87
] ) ;
88
88
89
89
const TYPED_GLOBALS : Array < [ string , BuiltInType ] > = [
90
+ [
91
+ 'Object' ,
92
+ addObject ( DEFAULT_SHAPES , 'Object' , [
93
+ [
94
+ 'keys' ,
95
+ addFunction ( DEFAULT_SHAPES , [ ] , {
96
+ positionalParams : [ Effect . Read ] ,
97
+ restParam : null ,
98
+ returnType : { kind : 'Object' , shapeId : BuiltInArrayId } ,
99
+ calleeEffect : Effect . Read ,
100
+ returnValueKind : ValueKind . Mutable ,
101
+ } ) ,
102
+ ] ,
103
+ ] ) ,
104
+ ] ,
90
105
[
91
106
'Array' ,
92
107
addObject ( DEFAULT_SHAPES , 'Array' , [
Original file line number Diff line number Diff line change
1
+
2
+ ## Input
3
+
4
+ ``` javascript
5
+ import {arrayPush } from ' shared-runtime' ;
6
+
7
+ function useFoo ({a, b}) {
8
+ const obj = {a};
9
+ arrayPush (Object .keys (obj), b);
10
+ return obj;
11
+ }
12
+ export const FIXTURE_ENTRYPOINT = {
13
+ fn: useFoo,
14
+ params: [{a: 2 , b: 3 }],
15
+ };
16
+
17
+ ```
18
+
19
+ ## Code
20
+
21
+ ``` javascript
22
+ import { c as _c } from " react/compiler-runtime" ;
23
+ import { arrayPush } from " shared-runtime" ;
24
+
25
+ function useFoo (t0 ) {
26
+ const $ = _c (2 );
27
+ const { a , b } = t0;
28
+ let t1;
29
+ if ($[0 ] !== a) {
30
+ t1 = { a };
31
+ $[0 ] = a;
32
+ $[1 ] = t1;
33
+ } else {
34
+ t1 = $[1 ];
35
+ }
36
+ const obj = t1;
37
+ arrayPush (Object .keys (obj), b);
38
+ return obj;
39
+ }
40
+
41
+ export const FIXTURE_ENTRYPOINT = {
42
+ fn: useFoo,
43
+ params: [{ a: 2 , b: 3 }],
44
+ };
45
+
46
+ ```
47
+
48
+ ### Eval output
49
+ (kind: ok) {"a":2}
Original file line number Diff line number Diff line change
1
+ import { arrayPush } from 'shared-runtime' ;
2
+
3
+ function useFoo ( { a, b} ) {
4
+ const obj = { a} ;
5
+ arrayPush ( Object . keys ( obj ) , b ) ;
6
+ return obj ;
7
+ }
8
+ export const FIXTURE_ENTRYPOINT = {
9
+ fn : useFoo ,
10
+ params : [ { a : 2 , b : 3 } ] ,
11
+ } ;
You can’t perform that action at this time.
0 commit comments