Skip to content

Commit

Permalink
Change: throw on export all declaration (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 authored Aug 11, 2024
1 parent 388ce63 commit fdd2c03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/import-to-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ function analyzeExportNamed(node, code, getName, tempNames, constBindings) {
return true;
}

function analyzeExportAll(node, code, getName) {
const name = getName(node.source.value);
if (!name) {
return;
}
throw new Error("Cannot export all properties from an external variable");
}

function writeDynamicImport(code, node, content) {
code.overwrite(node.start, node.end, content);
}
Expand Down Expand Up @@ -140,6 +148,8 @@ async function importToGlobals({ast, code, getName, getDynamicWrapper, constBind
isTouched = analyzeImport(node, bindings, code, getName, globals) || isTouched;
} else if (node.type === "ExportNamedDeclaration") {
isTouched = analyzeExportNamed(node, code, getName, tempNames, constBindings) || isTouched;
} else if (node.type === "ExportAllDeclaration") {
analyzeExportAll(node, code, getName, tempNames, constBindings);
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ describe("main", () => {
})
);

it("export all", () =>
withDir(`
- entry.js: |
export * from "foo";
`, async resolve => {
await assert.rejects(bundle(resolve("entry.js"), {foo: "FOO"}), {
message: /Cannot export all/
});
})
);

it("need an extra assignment when exporting globals", () =>
withDir(`
- entry.js: |
Expand Down

0 comments on commit fdd2c03

Please sign in to comment.