SourceTextModule.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/SourceTextModule.h>
  7. namespace JS {
  8. // 16.2.1.6.1 ParseModule ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parsemodule
  9. Result<NonnullRefPtr<SourceTextModule>, Vector<Parser::Error>> SourceTextModule::parse(StringView source_text, Realm& realm, [[maybe_unused]] StringView filename)
  10. {
  11. // 1. Let body be ParseText(sourceText, Module).
  12. auto parser = Parser(Lexer(source_text, filename), Program::Type::Module);
  13. auto body = parser.parse_program();
  14. // 2. If body is a List of errors, return body.
  15. if (parser.has_errors())
  16. return parser.errors();
  17. // FIXME: Implement the rest of ParseModule.
  18. return adopt_ref(*new SourceTextModule(realm, move(body)));
  19. }
  20. SourceTextModule::SourceTextModule(Realm& realm, NonnullRefPtr<Program> program)
  21. : Module(realm)
  22. , m_ecmascript_code(move(program))
  23. {
  24. }
  25. SourceTextModule::~SourceTextModule()
  26. {
  27. }
  28. }