From eda0627119da34b4edcd3819f5f2608ae9780f0a Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Thu, 31 Mar 2022 15:05:45 -0700 Subject: [PATCH] Add test for wrapping assets, even if the first ancestor is not --- .../es6/multiple-ancestors-wrap/index.js | 4 ++++ .../shouldBeWrapped.js | 1 + .../es6/multiple-ancestors-wrap/wraps.js | 5 +++++ .../integration-tests/test/scope-hoisting.js | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/index.js create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/shouldBeWrapped.js create mode 100644 packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/wraps.js diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/index.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/index.js new file mode 100644 index 00000000000..ebf8b39436c --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/index.js @@ -0,0 +1,4 @@ +import value from './shouldBeWrapped'; +import otherValue from './wraps'; + +output = [value, otherValue]; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/shouldBeWrapped.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/shouldBeWrapped.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/shouldBeWrapped.js @@ -0,0 +1 @@ +export default 42; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/wraps.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/wraps.js new file mode 100644 index 00000000000..96d9fbd4023 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/multiple-ancestors-wrap/wraps.js @@ -0,0 +1,5 @@ +import value from './shouldBeWrapped'; + +eval('void 0'); + +export default value + 1; diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js index b1632bfc83e..39592f262c4 100644 --- a/packages/core/integration-tests/test/scope-hoisting.js +++ b/packages/core/integration-tests/test/scope-hoisting.js @@ -1003,6 +1003,27 @@ describe('scope hoisting', function () { assert.deepEqual(output, ['a', true]); }); + it('wraps an asset if any of its ancestors is wrapped, even if one is not', async function () { + let b = await bundle( + path.join( + __dirname, + '/integration/scope-hoisting/es6/multiple-ancestors-wrap/index.js', + ), + ); + + let contents = await outputFS.readFile( + b.getBundles()[0].filePath, + 'utf8', + ); + assert.strictEqual( + contents.match(/parcelRequire.register\(/g).length, + 2 /* once for parent asset, once for child wrapped asset */, + ); + + let output = await run(b); + assert.deepEqual(output, [42, 43]); + }); + it('supports importing from a wrapped asset with multiple bailouts', async function () { let b = await bundle( path.join(