Skip to content

Commit

Permalink
Add test cases for ESM initialization problems (#7350)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid authored Dec 21, 2022
1 parent eed1e2c commit aa9425b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { c } from "./b.mjs";

sideEffectNoop(c);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const foo = "foo";

export { c } from "./c.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { foo } from "./b.mjs";

export const c = "c:" + foo;
27 changes: 27 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6191,6 +6191,33 @@ describe('javascript', function () {
assert.strictEqual(output.default, '4returned from bar');
});

it('should not affect ESM import order', async function () {
const b = await bundle(
path.join(__dirname, '/integration/js-import-initialization/a.mjs'),
);

await assert.rejects(
run(b),
new ReferenceError("Cannot access 'foo' before initialization"),
);
});

it('should not affect ESM import order with scope hoisting', async function () {
const b = await bundle(
path.join(__dirname, '/integration/js-import-initialization/a.mjs'),
{
defaultTargetOptions: {
shouldScopeHoist: true,
},
},
);

await assert.rejects(
run(b),
/^ReferenceError: Cannot access '(.+)' before initialization$/,
);
});

it('should produce working output with both scope hoisting and non scope hoisting targets', async function () {
let b = await bundle(
path.join(__dirname, '/integration/re-export-no-scope-hoist'),
Expand Down

0 comments on commit aa9425b

Please sign in to comment.