mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
[compiler] Reordering of logical expressions
ghstack-source-id: ad484f97451c65a2642618bfb9d540d6a53a19a6 Pull Request resolved: https://github.com/facebook/react/pull/30678
This commit is contained in:
@@ -2847,6 +2847,21 @@ function isReorderableExpression(
|
||||
allowLocalIdentifiers,
|
||||
);
|
||||
}
|
||||
case 'LogicalExpression': {
|
||||
const logical = expr as NodePath<t.LogicalExpression>;
|
||||
return (
|
||||
isReorderableExpression(
|
||||
builder,
|
||||
logical.get('left'),
|
||||
allowLocalIdentifiers,
|
||||
) &&
|
||||
isReorderableExpression(
|
||||
builder,
|
||||
logical.get('right'),
|
||||
allowLocalIdentifiers,
|
||||
)
|
||||
);
|
||||
}
|
||||
case 'ConditionalExpression': {
|
||||
const conditional = expr as NodePath<t.ConditionalExpression>;
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
//@flow
|
||||
|
||||
const foo = undefined;
|
||||
|
||||
component C(...{scope = foo ?? null}: any) {
|
||||
return scope;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: C,
|
||||
params: [{scope: undefined}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
const foo = undefined;
|
||||
|
||||
function C(t0) {
|
||||
const { scope: t1 } = t0;
|
||||
const scope = t1 === undefined ? (foo ?? null) : t1;
|
||||
return scope;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: C,
|
||||
params: [{ scope: undefined }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) null
|
||||
@@ -0,0 +1,12 @@
|
||||
//@flow
|
||||
|
||||
const foo = undefined;
|
||||
|
||||
component C(...{scope = foo ?? null}: any) {
|
||||
return scope;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: C,
|
||||
params: [{scope: undefined}],
|
||||
};
|
||||
Reference in New Issue
Block a user