Skip to content

[compiler] Make CompilerError compatible with reflection #32539

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

Merged
merged 1 commit into from
Mar 6, 2025
Merged

Conversation

poteto
Copy link
Member

@poteto poteto commented Mar 6, 2025

In #32416, @michaelfaith discovered that

if (process.env.NODE_ENV === 'production') {
would fail on the merged compiler eslint rule.

Upon further investigation I discovered that our CompilerError implementation doesn't play nicely with Reflect, so Reflect.construct would fail as .toString would error:

TypeError: Cannot read properties of undefined (reading 'map')
          at _CompilerError.toString (/Users/.../code/react/node_modules/babel-plugin-react-compiler/src/CompilerError.ts:200:25)
          at _CompilerError.get message [as message] (/Users/.../code/react/node_modules/babel-plugin-react-compiler/src/CompilerError.ts:194:17)
          at Object.construct (/Users/.../code/react/scripts/jest/setupTests.js:153:52)

I tested this fix using my local copy of the built babel-plugin-react-compiler to verify that this fixes those tests.

In #32416, @michaelfaith discovered that https://github.com/facebook/react/blob/029e8bd618af23fbdd9efdac565ad81f7d4640d8/scripts/jest/setupTests.js#L82 would fail on the merged compiler eslint rule.

Upon further investigation I discovered that our CompilerError implementation doesn't play nicely with Reflect, so `Reflect.construct` would fail as `.toString` would error:

```
TypeError: Cannot read properties of undefined (reading 'map')
          at _CompilerError.toString (/Users/.../code/react/node_modules/babel-plugin-react-compiler/src/CompilerError.ts:200:25)
          at _CompilerError.get message [as message] (/Users/.../code/react/node_modules/babel-plugin-react-compiler/src/CompilerError.ts:194:17)
          at Object.construct (/Users/.../code/react/scripts/jest/setupTests.js:153:52)
```

I tested this fix using my local copy of the built babel-plugin-react-compiler to verify that this fixes those tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants