Skip to content

Commit 8e60bac

Browse files
committed
[compiler] Reordering of logical expressions
ghstack-source-id: ad484f9 Pull Request resolved: #30678
1 parent f6d1df6 commit 8e60bac

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,21 @@ function isReorderableExpression(
28472847
allowLocalIdentifiers,
28482848
);
28492849
}
2850+
case 'LogicalExpression': {
2851+
const logical = expr as NodePath<t.LogicalExpression>;
2852+
return (
2853+
isReorderableExpression(
2854+
builder,
2855+
logical.get('left'),
2856+
allowLocalIdentifiers,
2857+
) &&
2858+
isReorderableExpression(
2859+
builder,
2860+
logical.get('right'),
2861+
allowLocalIdentifiers,
2862+
)
2863+
);
2864+
}
28502865
case 'ConditionalExpression': {
28512866
const conditional = expr as NodePath<t.ConditionalExpression>;
28522867
return (
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
## Input
3+
4+
```javascript
5+
//@flow
6+
7+
const foo = undefined;
8+
9+
component C(...{scope = foo ?? null}: any) {
10+
return scope;
11+
}
12+
13+
export const FIXTURE_ENTRYPOINT = {
14+
fn: C,
15+
params: [{scope: undefined}],
16+
};
17+
18+
```
19+
20+
## Code
21+
22+
```javascript
23+
const foo = undefined;
24+
25+
function C(t0) {
26+
const { scope: t1 } = t0;
27+
const scope = t1 === undefined ? (foo ?? null) : t1;
28+
return scope;
29+
}
30+
31+
export const FIXTURE_ENTRYPOINT = {
32+
fn: C,
33+
params: [{ scope: undefined }],
34+
};
35+
36+
```
37+
38+
### Eval output
39+
(kind: ok) null
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@flow
2+
3+
const foo = undefined;
4+
5+
component C(...{scope = foo ?? null}: any) {
6+
return scope;
7+
}
8+
9+
export const FIXTURE_ENTRYPOINT = {
10+
fn: C,
11+
params: [{scope: undefined}],
12+
};

0 commit comments

Comments
 (0)