Skip to content

Conversation

@henryqdineen
Copy link
Contributor

Summary

The TSAsExpression and TSNonNullExpression nodes are supported by lowerExpression() but isReorderableExpression() does not check if they can be reordered. This PR updates isReorderableExpression() to handle these two node types by adding cases that fall through to the existing TypeCastExpression case.

We ran react-compiler-healthcheck at scale on several of our repos and found dozens of (BuildHIR::node.lowerReorderableExpression) Expression type `TSAsExpression` cannot be safely reordered errors and a handful for TSNonNullExpression.

How did you test this change?

In this case I added two fixture tests

@meta-cla meta-cla bot added the CLA Signed label Jul 14, 2025
Copy link
Member

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The changes make sense. A small nit on the test fixture. It would be nice to change this (lest someone say "but there's a test fixture that uses it, it must be allowed!"), but we can land as-is if you like.

@@ -0,0 +1,8 @@
export const Component = ({theme = localStorage.getItem('theme')!}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's just an example, but localStorage is a mutable data source that isn't safe to read from in a component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @josephsavona. I ammended my commit to remove the localStorage usage from the fixture. I was struggling to come up with a contrived example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome thanks!

…lity

The TSAsExpression and TSNonNullExpression nodes are supported by `lowerExpression()` but `isReorderableExpression()` does not check if they can be reordered.
@henryqdineen henryqdineen force-pushed the hqd-compiler-reorder-ts-as-non-null branch from 4fdc852 to 46e9417 Compare July 15, 2025 14:50
@josephsavona josephsavona merged commit fe81314 into facebook:main Jul 15, 2025
22 checks passed
@josephsavona
Copy link
Member

Thanks again, @henryqdineen!

github-actions bot pushed a commit that referenced this pull request Jul 15, 2025
#33788)

## Summary

The `TSAsExpression` and `TSNonNullExpression` nodes are supported by
`lowerExpression()` but `isReorderableExpression()` does not check if
they can be reordered. This PR updates `isReorderableExpression()` to
handle these two node types by adding cases that fall through to the
existing `TypeCastExpression` case.

We ran `react-compiler-healthcheck` at scale on several of our repos and
found dozens of `` (BuildHIR::node.lowerReorderableExpression)
Expression type `TSAsExpression` cannot be safely reordered`` errors and
a handful for `TSNonNullExpression`.

## How did you test this change?

In this case I added two fixture tests

DiffTrain build for [fe81314](fe81314)
github-actions bot pushed a commit that referenced this pull request Jul 15, 2025
#33788)

## Summary

The `TSAsExpression` and `TSNonNullExpression` nodes are supported by
`lowerExpression()` but `isReorderableExpression()` does not check if
they can be reordered. This PR updates `isReorderableExpression()` to
handle these two node types by adding cases that fall through to the
existing `TypeCastExpression` case.

We ran `react-compiler-healthcheck` at scale on several of our repos and
found dozens of `` (BuildHIR::node.lowerReorderableExpression)
Expression type `TSAsExpression` cannot be safely reordered`` errors and
a handful for `TSNonNullExpression`.

## How did you test this change?

In this case I added two fixture tests

DiffTrain build for [fe81314](fe81314)
github-actions bot pushed a commit to code/lib-react that referenced this pull request Jul 20, 2025
facebook#33788)

## Summary

The `TSAsExpression` and `TSNonNullExpression` nodes are supported by
`lowerExpression()` but `isReorderableExpression()` does not check if
they can be reordered. This PR updates `isReorderableExpression()` to
handle these two node types by adding cases that fall through to the
existing `TypeCastExpression` case.

We ran `react-compiler-healthcheck` at scale on several of our repos and
found dozens of `` (BuildHIR::node.lowerReorderableExpression)
Expression type `TSAsExpression` cannot be safely reordered`` errors and
a handful for `TSNonNullExpression`.

## How did you test this change?

In this case I added two fixture tests

DiffTrain build for [fe81314](facebook@fe81314)
github-actions bot pushed a commit to code/lib-react that referenced this pull request Jul 20, 2025
facebook#33788)

## Summary

The `TSAsExpression` and `TSNonNullExpression` nodes are supported by
`lowerExpression()` but `isReorderableExpression()` does not check if
they can be reordered. This PR updates `isReorderableExpression()` to
handle these two node types by adding cases that fall through to the
existing `TypeCastExpression` case.

We ran `react-compiler-healthcheck` at scale on several of our repos and
found dozens of `` (BuildHIR::node.lowerReorderableExpression)
Expression type `TSAsExpression` cannot be safely reordered`` errors and
a handful for `TSNonNullExpression`.

## How did you test this change?

In this case I added two fixture tests

DiffTrain build for [fe81314](facebook@fe81314)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants