Skip to content

Commit

Permalink
Replace module.require in scope hoisting (#2875)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored and devongovett committed May 8, 2019
1 parent f3990f3 commit a50ddd5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
@@ -1,6 +1,7 @@
output = {
id: module.id,
hot: module.hot,
moduleRequire: module.require,
type: typeof module,
exports: exports,
exportsType: typeof exports,
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -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');
Expand Down
7 changes: 7 additions & 0 deletions packages/core/parcel-bundler/src/scope-hoisting/hoist.js
Expand Up @@ -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'));
}
Expand Down

0 comments on commit a50ddd5

Please sign in to comment.