Skip to content

Commit

Permalink
fix(ui-babel-preset): ensure runtime helper is used for _objectSpread
Browse files Browse the repository at this point in the history
because of babel/babel#10261 if you don't 
speficiy a version of @babel/helpers to use, it will default to 
7.0.0-beta.0 which doesn't have _objectSpread

TEST PLAN:
* Before checking this out, 
* run babel to transpile a file that uses
  object spread syntax, like `const foo = {...bar}`
* you should see inline _objectSpread helpers like what is currently
  on npm. see for example:
https://unpkg.com/browse/@instructure/ui-a11y@6.10.0/es/Dialog/index.js
  (See how that has a _objectSpread inlined in it?)

* with this checked out, 
* run yarn build
* Look at: packages/ui-a11y/es/Dialog/index.js
* it should not have an inline _objectSpread function, but should
  Instead have a line like
  import _objectSpread2 from "@babel/runtime/helpers/esm/objectSpread2"
  


Change-Id: I1a65ae85789848ad0702e43aafdc5580210942eb
Reviewed-on: https://gerrit.instructure.com/208612
Tested-by: Jenkins
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
QA-Review: Daniel Sasaki <dsasaki@instructure.com>
QA-Review: Steve Jensen <sejensen@instructure.com>
Product-Review: Steve Jensen <sejensen@instructure.com>
Visual-Regression-Test: Steve Jensen <sejensen@instructure.com>
  • Loading branch information
Ryan Shaw authored and serikjensen committed Sep 9, 2019
1 parent c2e4e7d commit 2eb42d7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/ui-babel-preset/lib/index.js
Expand Up @@ -54,6 +54,18 @@ module.exports = function (context, opts = {
])
}

// Work around https://github.com/babel/babel/issues/10261, which causes
// Babel to not use the runtime helpers for things like _objectSpread.
// Remove this once that babel issue is fixed
let babelHelperVersion = {}
try {
// eslint-disable-next-line import/no-extraneous-dependencies
const version = require('@babel/helpers/package.json').version
babelHelperVersion.version = version
} catch (e) {
// if something goes wrong, continue and don't try to explicitly set a helper version
}

plugins = plugins.concat([
require('babel-plugin-macros'),
require('@babel/plugin-transform-destructuring').default,
Expand All @@ -62,6 +74,7 @@ module.exports = function (context, opts = {
require('@babel/plugin-proposal-export-default-from').default,
[require('@babel/plugin-proposal-object-rest-spread').default, { useBuiltIns: true }],
[require('@babel/plugin-transform-runtime').default, {
...babelHelperVersion,
corejs: false,
regenerator: true,
helpers: true,
Expand Down

0 comments on commit 2eb42d7

Please sign in to comment.