From 18ab7e9b392ee015169f57145c4e7805dbceda46 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 5 Dec 2017 13:34:50 -0500 Subject: [PATCH] Enable useBuiltIns option when compiling for modern JS environments. Background: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime#usebuiltins https://github.com/meteor/babel/commit/242538dea13dd4600e2ba2fc1d3bd7d242e35304 https://github.com/meteor/babel/commit/855d5dda803316ccfae755e091555acaab9c6957 --- packages/babel-compiler/babel-compiler.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/babel-compiler/babel-compiler.js b/packages/babel-compiler/babel-compiler.js index 0b5818e579..7526ec0f51 100644 --- a/packages/babel-compiler/babel-compiler.js +++ b/packages/babel-compiler/babel-compiler.js @@ -71,13 +71,26 @@ BCp.processOneFileForTarget = function (inputFile, source) { ! excludedFileExtensionPattern.test(inputFilePath)) { var extraFeatures = Object.assign({}, this.extraFeatures); + var arch = inputFile.getArch(); - if (inputFile.getArch().startsWith("os.")) { + if (arch.startsWith("os.")) { // Start with a much simpler set of Babel presets and plugins if // we're compiling for Node 8. extraFeatures.nodeMajorVersion = parseInt(process.versions.node); } + if (arch !== "web.browser.legacy") { + extraFeatures.runtime = { + // Import Babel helpers from @babel/runtime/helpers/builtin/* + // instead of @babel/runtime/helpers/* to prevent those helper + // modules from importing anything from core-js. The polyfills and + // shims provided by core-js are not needed in modern JS + // environments (browsers and Node), and will be polyfilled by the + // ecmascript-runtime-{client,server} packages anyway. + useBuiltIns: true + }; + } + if (! extraFeatures.hasOwnProperty("jscript")) { // Perform some additional transformations to improve compatibility // in older browsers (e.g. wrapping named function expressions, per