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;