Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Tell @babel/plugin-transform-runtime the @babel/runtime version.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jul 6, 2019
1 parent fc3107f commit 49e13e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion options.js
Expand Up @@ -7,6 +7,7 @@ require = function require(id) {
return getESModule(exports) && exports.default || exports;
};

const babelRuntimeVersion = require("@babel/runtime/package.json").version;
const babelPresetMeteor = require("babel-preset-meteor");
const babelPresetMeteorModern = require("babel-preset-meteor/modern");
const reifyPlugin = require("reify/plugins/babel");
Expand Down Expand Up @@ -147,7 +148,18 @@ function getRuntimeTransform(features) {

// Import helpers from the babel-runtime package rather than redefining
// them at the top of each module.
return require("@babel/plugin-transform-runtime");
return [require("@babel/plugin-transform-runtime"), {
// Necessary to enable importing helpers like objectSpread:
// https://github.com/babel/babel/pull/10170#issuecomment-508936150
version: babelRuntimeVersion,
// Use @babel/runtime/helpers/*.js:
helpers: true,
// Do not use @babel/runtime/helpers/esm/*.js:
useESModules: false,
// Do not import from @babel/runtime-corejs2
// or @babel/runtime-corejs3:
corejs: false,
}];
}

function getDefaultsForNode8(features) {
Expand Down
12 changes: 12 additions & 0 deletions test/tests.js
Expand Up @@ -329,6 +329,18 @@ describe("meteor-babel", () => {
'}',
].join("\n"));
});

it("imports @babel/runtime/helpers/objectSpread when appropriate", () => {
const result = meteorBabel.compile(
"console.log({ a, ...bs, c, ...ds, e })",
meteorBabel.getDefaultOptions(),
);
assert.notStrictEqual(
result.code.indexOf('module.link("@babel/runtime/helpers/objectSpread'),
-1,
result.code,
);
});
});

describe("Babel", function() {
Expand Down

0 comments on commit 49e13e7

Please sign in to comment.