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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove @babel/plugin-proposal-object-rest-spread #31

Merged

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Dec 24, 2022

The @babel/preset-env is already handling object-rest-spread and by the looks of it with our browserslist target we no longer need it.

This results in a pretty nice bundlesize decrease in generated JS 馃槍
Before:

function Component(_ref) {
  let { foobar } = _ref,
    props = _objectWithoutProperties(_ref, _excluded)

  return jsx(FooBar, _objectSpread({ foobaz: true }, props))
}

const _excluded = ['foobar']
function _toPrimitive(input, hint) {
  if (typeof input !== 'object' || input === null) return input
  var prim = input[Symbol.toPrimitive]
  if (prim !== undefined) {
    var res = prim.call(input, hint || 'default')
    if (typeof res !== 'object') return res
    throw new TypeError('@@toPrimitive must return a primitive value.')
  }
  return (hint === 'string' ? String : Number)(input)
}
function _toPropertyKey(arg) {
  var key = _toPrimitive(arg, 'string')
  return typeof key === 'symbol' ? key : String(key)
}
function _defineProperty(obj, key, value) {
  key = _toPropertyKey(key)
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true,
    })
  } else {
    obj[key] = value
  }
  return obj
}
function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object)
  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object)
    enumerableOnly &&
      (symbols = symbols.filter(function (sym) {
        return Object.getOwnPropertyDescriptor(object, sym).enumerable
      })),
      keys.push.apply(keys, symbols)
  }
  return keys
}
function _objectSpread(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = null != arguments[i] ? arguments[i] : {}
    i % 2
      ? ownKeys(Object(source), !0).forEach(function (key) {
          _defineProperty(target, key, source[key])
        })
      : Object.getOwnPropertyDescriptors
      ? Object.defineProperties(
          target,
          Object.getOwnPropertyDescriptors(source)
        )
      : ownKeys(Object(source)).forEach(function (key) {
          Object.defineProperty(
            target,
            key,
            Object.getOwnPropertyDescriptor(source, key)
          )
        })
  }
  return target
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {}
  var target = _objectWithoutPropertiesLoose(source, excluded)
  var key, i
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source)
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i]
      if (excluded.indexOf(key) >= 0) continue
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue
      target[key] = source[key]
    }
  }
  return target
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {}
  var target = {}
  var sourceKeys = Object.keys(source)
  var key, i
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i]
    if (excluded.indexOf(key) >= 0) continue
    target[key] = source[key]
  }
  return target
}

After:

function Component({ foobar, ...props }) {
  return jsx(FooBar, { foobaz: true, ...props })
}

@stipsan stipsan force-pushed the fix-remove-@babel/plugin-proposal-object-rest-spread branch 2 times, most recently from a838e93 to 4891dde Compare December 30, 2022 22:55
@mariuslundgard
Copy link
Member

I believe there was some issues with this in Webpack 3 / Studio v2, particularly with the @sanity/portable-text-editor package.

@stipsan
Copy link
Member Author

stipsan commented Jan 2, 2023

Then it's best if that package adds this babel plugin in its own package.config.ts? So every other package don't have to pay the bundle price 馃槄

@mariuslundgard mariuslundgard force-pushed the fix-remove-@babel/plugin-proposal-object-rest-spread branch from 695b897 to 680e669 Compare January 4, 2023 22:26
@mariuslundgard mariuslundgard merged commit 44b8aad into main Jan 4, 2023
@mariuslundgard mariuslundgard deleted the fix-remove-@babel/plugin-proposal-object-rest-spread branch January 4, 2023 22:31
@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2023

馃帀 This PR is included in version 2.1.1 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants