diff options
author | davidot <davidot@serenityos.org> | 2022-09-01 23:13:45 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-02 02:07:37 +0100 |
commit | faf1430ce46917725a9dd2fa0304c7498eff35ae (patch) | |
tree | 1197af030ae3f5d6d41ba22196185ea274c12ef1 /Userland/Libraries | |
parent | 462c6df24b8b86867ccd9297f83fc4cf9662b71f (diff) | |
download | serenity-faf1430ce46917725a9dd2fa0304c7498eff35ae.zip |
LibJS: Allow exporting any imported bindings
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/modules/basic-modules.js | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/modules/re-export-namespace-via-binding.mjs | 7 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index e0d01ea088..b5ec4299e0 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 2dad8a834b..cf662213fd 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 0000000000..91d5fcc606 --- /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["*"]; |