Skip to content

[compiler] Make CompilerError compatible with reflection - #32539

Merged
poteto merged 1 commit into
mainfrom
pr32539
Mar 6, 2025
Merged

poteto merged 1 commit into
mainfrom
pr32539

Conversation

@poteto

@poteto poteto commented Mar 6, 2025

Copy link
Copy Markdown
Collaborator

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.

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.

This branch was successfully deployed

1 active deployment
Preview — 0e2a52a4 Deployed Mar 6, 2025 by vercel[bot]
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