1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

LibJS: Add a mode to parse JS as a module

In a module strict mode should be enabled at the start of parsing and we
allow import and export statements.
This commit is contained in:
davidot 2021-08-14 17:30:37 +02:00 committed by Linus Groh
parent d6d7d11590
commit 7613c22b06
8 changed files with 38 additions and 15 deletions

View file

@ -194,7 +194,7 @@ inline void TestRunnerGlobalObject::initialize_global_object()
}
}
inline AK::Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path)
inline AK::Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path, JS::Program::Type program_type = JS::Program::Type::Script)
{
auto file = Core::File::construct(file_path);
auto result = file->open(Core::OpenMode::ReadOnly);
@ -207,7 +207,7 @@ inline AK::Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const Stri
String test_file_string(reinterpret_cast<const char*>(contents.data()), contents.size());
file->close();
auto parser = JS::Parser(JS::Lexer(test_file_string));
auto parser = JS::Parser(JS::Lexer(test_file_string), program_type);
auto program = parser.parse_program();
if (parser.has_errors()) {