Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Reordering of logical expressions #30678

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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}],
};