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

[core] Use Babel assumptions instead of loose mode #37461

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
13 changes: 7 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ module.exports = function getBabelConfig(api) {
},
],
'babel-plugin-optimize-clsx',
// Need the following 3 proposals for all targets in .browserslistrc.
// With our usage the transpiled loose mode is equivalent to spec mode.
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
['@babel/plugin-proposal-object-rest-spread', { loose: true }],
[
'@babel/plugin-transform-runtime',
{
Expand Down Expand Up @@ -98,8 +92,15 @@ module.exports = function getBabelConfig(api) {
}

return {
// https://babeljs.io/docs/assumptions
assumptions: {
noDocumentAll: true,
// With our cose these assumptions are safe, and the
// resulting behavior is equivalent to spec mode.
setPublicClassFields: true,
privateFieldsAsProperties: true,
objectRestNoSymbols: true,
setSpreadProperties: true,
Copy link
Author

Choose a reason for hiding this comment

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

Feel free to go through https://babeljs.io/docs/assumptions and check if there is anything else you want to enable :)

Copy link
Author

Choose a reason for hiding this comment

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

One possible effect of this PR is that setSpreadProperties is applied more, because object spread is also compiled in some cases by the destructuring transform and you didn't enable loose mode in that plugin. Now all the object spreads are transformed with this assumption, regardless of which plugin actually does it.

},
presets,
plugins,
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
"@babel/cli": "^7.21.0",
"@babel/core": "^7.21.4",
"@babel/node": "^7.20.7",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-object-assign": "^7.18.6",
"@babel/plugin-transform-react-constant-elements": "^7.21.3",
"@babel/plugin-transform-runtime": "^7.21.4",
Expand Down