From adce40d38d8a098519d6299187a29939c728ebbc Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Tue, 22 May 2018 07:59:45 -0700 Subject: [PATCH] Do not use spread operator in require.js implementation Reviewed By: jeanlauliac Differential Revision: D8074917 fbshipit-source-id: e7c4dca7955f7aeda8b59d2039e857f79168410b --- .../lib/polyfills/__tests__/require-test.js | 18 ++++++++++-------- packages/metro/src/lib/polyfills/require.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/metro/src/lib/polyfills/__tests__/require-test.js b/packages/metro/src/lib/polyfills/__tests__/require-test.js index 47852306..be9f5fbc 100644 --- a/packages/metro/src/lib/polyfills/__tests__/require-test.js +++ b/packages/metro/src/lib/polyfills/__tests__/require-test.js @@ -18,17 +18,13 @@ const fs = require('fs'); const {transformSync} = require('@babel/core'); -// from: metro/packages/metro-babel-register/babel-register.js - -const PLUGINS = [ - '@babel/plugin-transform-flow-strip-types', - '@babel/plugin-proposal-object-rest-spread', - '@babel/plugin-proposal-class-properties', -]; +// Include the external-helpers plugin to be able to detect if they're +// needed when transforming the requirejs implementation. +const PLUGINS = ['@babel/plugin-external-helpers']; function createBabelConfig() { return { - presets: [], + presets: [require.resolve('babel-preset-react-native')], plugins: PLUGINS.map(require), retainLines: true, sourceMaps: 'inline', @@ -56,6 +52,12 @@ describe('require', () => { moduleSystem = {}; }); + it('does not need any babel helper logic', () => { + // Super-simple check to validate that no babel helpers are used. + // This check will need to be updated if https://fburl.com/6z0y2kf8 changes. + expect(moduleSystemCode.includes('babelHelpers')).toBe(false); + }); + it('works with plain bundles', () => { createModuleSystem(moduleSystem, false); expect(moduleSystem.require).not.toBeUndefined(); diff --git a/packages/metro/src/lib/polyfills/require.js b/packages/metro/src/lib/polyfills/require.js index a78cad5c..6b466f40 100644 --- a/packages/metro/src/lib/polyfills/require.js +++ b/packages/metro/src/lib/polyfills/require.js @@ -326,7 +326,7 @@ if (__DEV__) { return false; } - parents.push(...inverseDependencies[notAccepted[i]]); + parents.push.apply(parents, inverseDependencies[notAccepted[i]]); } return parents.length == 0;