From 271d00084f0fae5827ba85e7dd739c478691f509 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Mon, 1 Apr 2019 22:58:34 +0200 Subject: [PATCH 1/2] Replace module.require in scope hoisting --- packages/core/parcel-bundler/src/scope-hoisting/hoist.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js index 27f6bfe3352..d0449f80d73 100644 --- a/packages/core/parcel-bundler/src/scope-hoisting/hoist.js +++ b/packages/core/parcel-bundler/src/scope-hoisting/hoist.js @@ -189,6 +189,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')); } From 655aae24a6ef2afc39df35ac9de6b2a2f8e4fa75 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 7 May 2019 20:56:04 -0700 Subject: [PATCH 2/2] Add test --- .../test/integration/scope-hoisting/commonjs/module-object/a.js | 1 + packages/core/integration-tests/test/scope-hoisting.js | 1 + 2 files changed, 2 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');