1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

LibJS: Make parsing import and export entries follow the spec

The big changes are:
- Allow strings as Module{Export, Import}Name
- Properly track declarations in default export statements

However, the spec is a little strange in that it allows function and
class declarations without a name in default export statements.
This is quite hard to fully implement without rewriting more of the
parser so for now this behavior is emulated by faking things with
function and class expressions. See the comments in
parse_export_statement for details on the hacks and where it goes wrong.
This commit is contained in:
davidot 2022-01-16 23:51:28 +01:00 committed by Linus Groh
parent 631bbcd00a
commit aca427fc8c
4 changed files with 278 additions and 73 deletions

View file

@ -4045,6 +4045,8 @@ Completion ImportStatement::execute(Interpreter& interpreter, GlobalObject& glob
return interpreter.vm().throw_completion<InternalError>(global_object, ErrorType::NotImplemented, "'import' in modules");
}
FlyString ExportStatement::local_name_for_default = "*default*";
// 16.2.3.7 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-exports-runtime-semantics-evaluation
Completion ExportStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
@ -4111,14 +4113,14 @@ void ImportStatement::dump(int indent) const
}
}
bool ExportStatement::has_export(StringView export_name) const
bool ExportStatement::has_export(FlyString const& export_name) const
{
return any_of(m_entries.begin(), m_entries.end(), [&](auto& entry) {
return entry.export_name == export_name;
});
}
bool ImportStatement::has_bound_name(StringView name) const
bool ImportStatement::has_bound_name(FlyString const& name) const
{
return any_of(m_entries.begin(), m_entries.end(), [&](auto& entry) {
return entry.local_name == name;