From a50ddd5ee18bbf2a70033fb118e6ec3a93a4ed97 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Wed, 8 May 2019 06:22:43 +0200 Subject: [PATCH] Replace module.require in scope hoisting (#2875) --- .../integration/scope-hoisting/commonjs/module-object/a.js | 1 + packages/core/integration-tests/test/scope-hoisting.js | 1 + packages/core/parcel-bundler/src/scope-hoisting/hoist.js | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/module-object/a.js b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/module-object/a.js index 8e7e26c9669..40b62603807 100644 --- a/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/module-object/a.js +++ b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/module-object/a.js @@ -1,6 +1,7 @@ output = { id: module.id, hot: module.hot, + moduleRequire: module.require, type: typeof module, exports: exports, exportsType: typeof exports, diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index 81e565308b8..a119671bee8 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -908,6 +908,7 @@ describe('scope hoisting', function() { let output = await run(b); assert.equal(output.id, b.entryAsset.id); assert.equal(output.hot, null); + assert.equal(output.moduleRequire, null); assert.equal(output.type, 'object'); assert.deepEqual(output.exports, {}); assert.equal(output.exportsType, 'object'); diff --git a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js index 2fb83bd236c..95d7ed2cfb3 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js @@ -191,6 +191,13 @@ module.exports = { path.replaceWith(t.identifier('null')); } + if ( + t.matchesPattern(path.node, 'module.require') && + asset.options.target !== 'node' + ) { + path.replaceWith(t.identifier('null')); + } + if (t.matchesPattern(path.node, 'module.bundle')) { path.replaceWith(t.identifier('require')); }