diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index e0d01ea0884..b5ec4299e03 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -565,8 +565,15 @@ void Parser::parse_module(Program& program) if (name == exported_name) found = true; }); + for (auto& import : program.imports()) { + if (import.has_bound_name(exported_name)) { + found = true; + break; + } + } + if (!found) - syntax_error(String::formatted("'{}' is not declared", exported_name)); + syntax_error(String::formatted("'{}' in export is not declared", exported_name), export_statement.source_range().start); } } } diff --git a/Userland/Libraries/LibJS/Tests/modules/basic-modules.js b/Userland/Libraries/LibJS/Tests/modules/basic-modules.js index 2dad8a834b2..cf662213fdc 100644 --- a/Userland/Libraries/LibJS/Tests/modules/basic-modules.js +++ b/Userland/Libraries/LibJS/Tests/modules/basic-modules.js @@ -190,6 +190,10 @@ describe("in- and exports", () => { test("can have multiple star imports even from the same file", () => { expectModulePassed("./multiple-star-imports.mjs"); }); + + test("can export namespace via binding", () => { + expectModulePassed("./re-export-namespace-via-binding.mjs"); + }); }); describe("loops", () => { diff --git a/Userland/Libraries/LibJS/Tests/modules/re-export-namespace-via-binding.mjs b/Userland/Libraries/LibJS/Tests/modules/re-export-namespace-via-binding.mjs new file mode 100644 index 00000000000..91d5fcc606a --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/modules/re-export-namespace-via-binding.mjs @@ -0,0 +1,7 @@ +import * as namespace from "./default-and-star-export.mjs"; +import { "*" as fromStar } from "./default-and-star-export.mjs"; +export { namespace }; + +import { namespace as nm } from "./re-export-namespace-via-binding.mjs"; + +export const passed = nm === namespace && fromStar === namespace["*"];