1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:17: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

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@serenityos.org>
* Copyright (c) 2021, David Tuin <davidot@serenityos.org>
* Copyright (c) 2021-2022, David Tuin <davidot@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -214,7 +214,7 @@ private:
RefPtr<BindingPattern> synthesize_binding_pattern(Expression const& expression);
Token next_token() const;
Token next_token(size_t steps = 1) const;
void check_identifier_name_for_assignment_validity(StringView, bool force_strict = false);
@ -225,7 +225,9 @@ private:
bool parse_directive(ScopeNode& body);
void parse_statement_list(ScopeNode& output_node, AllowLabelledFunction allow_labelled_functions = AllowLabelledFunction::No);
void parse_assert_clause(ModuleRequest& request);
FlyString consume_string_value();
ModuleRequest parse_module_request();
struct RulePosition {
AK_MAKE_NONCOPYABLE(RulePosition);