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
17 changes: 11 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ module.exports = function getBabelConfig(api) {
debug: process.env.MUI_BUILD_VERBOSE === 'true',
modules: useESModules ? false : 'commonjs',
shippedProposals: api.env('modern'),
include: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
],
},
],
[
Expand All @@ -62,12 +66,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 +96,15 @@ module.exports = function getBabelConfig(api) {
}

return {
// https://babeljs.io/docs/assumptions
assumptions: {
noDocumentAll: true,
// With our case 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