Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for ESM initialization problems #7350

Merged
merged 6 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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