summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/AST.h
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2021-12-20 15:29:25 +0100
committerLinus Groh <mail@linusgroh.de>2021-12-21 14:04:23 +0100
commitbe3b8064878f2d253e6f1dea41c3ca2174593bb5 (patch)
treee6ea9a0882bbb3aaf38aa590cb070301d8c7c866 /Userland/Libraries/LibJS/AST.h
parent81312986fe07496e3d35e1d7d10d20d9aba8d1fb (diff)
downloadserenity-be3b8064878f2d253e6f1dea41c3ca2174593bb5.zip
LibJS: Parse assert clauses of in- and export statements
Based on proposal: https://tc39.es/proposal-import-assertions Since imports are not supported yet this is not functional.
Diffstat (limited to 'Userland/Libraries/LibJS/AST.h')
-rw-r--r--Userland/Libraries/LibJS/AST.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h
index ea508a5ff6..9c55e214ed 100644
--- a/Userland/Libraries/LibJS/AST.h
+++ b/Userland/Libraries/LibJS/AST.h
@@ -217,6 +217,29 @@ private:
NonnullRefPtrVector<FunctionDeclaration> m_functions_hoistable_with_annexB_extension;
};
+// 2.9 ModuleRequest Records, https://tc39.es/proposal-import-assertions/#sec-modulerequest-record
+struct ModuleRequest {
+ struct Assertion {
+ String key;
+ String value;
+ };
+
+ ModuleRequest() = default;
+
+ explicit ModuleRequest(String specifier)
+ : module_specifier(move(specifier))
+ {
+ }
+
+ void add_assertion(String key, String value)
+ {
+ assertions.empend(move(key), move(value));
+ }
+
+ String module_specifier; // [[Specifier]]
+ Vector<Assertion> assertions; // [[Assertions]]
+};
+
class ImportStatement final : public Statement {
public:
struct ImportEntry {
@@ -224,9 +247,9 @@ public:
String local_name;
};
- explicit ImportStatement(SourceRange source_range, StringView from_module, Vector<ImportEntry> entries = {})
+ explicit ImportStatement(SourceRange source_range, ModuleRequest from_module, Vector<ImportEntry> entries = {})
: Statement(source_range)
- , m_module_request(from_module)
+ , m_module_request(move(from_module))
, m_entries(move(entries))
{
}
@@ -238,14 +261,14 @@ public:
bool has_bound_name(StringView name) const;
private:
- String m_module_request;
+ ModuleRequest m_module_request;
Vector<ImportEntry> m_entries;
};
class ExportStatement final : public Statement {
public:
struct ExportEntry {
- enum Kind {
+ enum class Kind {
ModuleRequest,
LocalExport
} kind;
@@ -253,13 +276,13 @@ public:
String export_name;
// Only if module request
- String module_request;
+ ModuleRequest module_request;
// Has just one of ones below
String local_or_import_name;
ExportEntry(String export_name, String local_name)
- : kind(LocalExport)
+ : kind(Kind::LocalExport)
, export_name(move(export_name))
, local_or_import_name(move(local_name))
{