Skip to content

Commit

Permalink
optim: add assumptions to Babel config, mirroring previous config
Browse files Browse the repository at this point in the history
- previously used Babel 6's preset-stage-2, which, in Babel 7, is the
  equivalent of turning on `loose` in `proposal-class-properties`:
  https://github.com/babel/babel/tree/v7.5.5/packages/babel-preset-stage-2

- top-level `assumptions` replace the old `loose` configurations:
  https://github.com/babel/rfcs/blob/main/rfcs/0003-top-level-assumptions.md#assumptions-list

- this makes the minified UMD size ~20% smaller, very close to the size
  it was previously w/ Babel 6
  - basically the size increase was, in part, due to added
    spec-compliancy cases
    - and we don't actually need that stricter spec-compliancy in this
      codebase's small usage, so we can add "assumptions" to have the
      compiler optimize more by skipping some checks / edge cases that
      are unnecessary in this case

- as a double-check measure, I compared the old package's minified UMD
  to see if it had the helpers in it
  - this was a bit hard to do as it was minified after all, but I was
    able to more-or-less correlate all the helpers with either error
    messages in the helper code (which can't be minified), or specific
    methods or properties that aren't normally touched (e.g.
    `enumerable`)
    - prev minified UMD: https://unpkg.com/[email protected]/build/index.js
    - Babel helper code: https://github.com/babel/babel/blob/a24c1d047e6db77c32d9505c6876897b4c3689d2/packages/babel-helpers/src/helpers.ts#L207

  - this looks be a good bit closer to the old build's results, but
    should still be wary of possible legacy compat issues and note that
    in the release notes
    - in particular, the implicit update to `compat-table` that happened
      during upgrading of the build system, which would change what
      `defaults` means for `browserslist` etc
  • Loading branch information
agilgur5 committed May 18, 2022
1 parent b14060c commit bcf3c3f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module.exports = api => {
if (isTest) presetEnv[1] = { ...presetEnv[1], ...jestTargets }

return {
// @ts-expect-error -- @types/babel__core doesn't specify assumptions yet
assumptions: {
// optimizations equivalent to previous Babel 6 "loose" behavior for preset-stage-2 (https://github.com/babel/rfcs/blob/main/rfcs/0003-top-level-assumptions.md#assumptions-list, https://github.com/babel/babel/tree/v7.5.5/packages/babel-preset-stage-2)
setPublicClassFields: true,
constantSuper: true
},
presets: [
presetEnv,
'@babel/preset-typescript',
Expand Down

0 comments on commit bcf3c3f

Please sign in to comment.