/src/hermes/lib/Parser/JSParser.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #include "hermes/Parser/JSParser.h" |
9 | | |
10 | | #include "JSParserImpl.h" |
11 | | |
12 | | namespace hermes { |
13 | | namespace parser { |
14 | | JSParser::JSParser(Context &context, std::unique_ptr<llvh::MemoryBuffer> input) |
15 | 93 | : impl_(std::make_shared<detail::JSParserImpl>(context, std::move(input))) { |
16 | 93 | } |
17 | | |
18 | | JSParser::JSParser(Context &context, uint32_t bufferId, ParserPass pass) |
19 | 76 | : impl_(std::make_shared<detail::JSParserImpl>(context, bufferId, pass)) {} |
20 | | |
21 | 244 | JSParser::~JSParser() = default; |
22 | | |
23 | 0 | Context &JSParser::getContext() { |
24 | 0 | return impl_->getContext(); |
25 | 0 | } |
26 | | |
27 | 0 | bool JSParser::isStrictMode() const { |
28 | 0 | return impl_->isStrictMode(); |
29 | 0 | } |
30 | | |
31 | 0 | void JSParser::setStrictMode(bool mode) { |
32 | 0 | return impl_->setStrictMode(mode); |
33 | 0 | } |
34 | | |
35 | | /// \return the source URL from the magic comment, or an empty string if there |
36 | | /// was no magic comment. |
37 | 0 | llvh::StringRef JSParser::getSourceURL() const { |
38 | 0 | return impl_->getLexer().getSourceURL(); |
39 | 0 | } |
40 | | |
41 | | /// \return the source mapping URL from the magic comment, or an empty string |
42 | | /// if there was no magic comment. |
43 | 0 | llvh::StringRef JSParser::getSourceMappingURL() const { |
44 | 0 | return impl_->getLexer().getSourceMappingURL(); |
45 | 0 | } |
46 | | |
47 | 169 | void JSParser::registerMagicURLs(MCFlag::Type flags) const { |
48 | | #ifdef STATIC_HERMES |
49 | | uint32_t bufId = impl_->getLexer().getBufferId(); |
50 | | SourceErrorManager &sm = impl_->getContext().getSourceErrorManager(); |
51 | | if (flags & MCFlag::SourceURL) |
52 | | sm.setSourceUrl(bufId, getSourceURL()); |
53 | | if (flags & MCFlag::SourceMappingURL) |
54 | | sm.setSourceMappingUrl(bufId, getSourceMappingURL()); |
55 | | #endif |
56 | 169 | } |
57 | | |
58 | 0 | llvh::ArrayRef<StoredComment> JSParser::getStoredComments() const { |
59 | 0 | return impl_->getLexer().getStoredComments(); |
60 | 0 | } |
61 | | |
62 | 0 | std::vector<StoredComment> JSParser::moveStoredComments() const { |
63 | 0 | return impl_->getLexer().moveStoredComments(); |
64 | 0 | } |
65 | | |
66 | 0 | llvh::ArrayRef<StoredToken> JSParser::getStoredTokens() const { |
67 | 0 | return impl_->getLexer().getStoredTokens(); |
68 | 0 | } |
69 | | |
70 | 0 | void JSParser::setStoreComments(bool storeComments) { |
71 | 0 | impl_->getLexer().setStoreComments(storeComments); |
72 | 0 | } |
73 | | |
74 | 0 | void JSParser::setStoreTokens(bool storeTokens) { |
75 | 0 | impl_->getLexer().setStoreTokens(storeTokens); |
76 | 0 | } |
77 | | |
78 | 76 | bool JSParser::getUseStaticBuiltin() const { |
79 | 76 | return impl_->getUseStaticBuiltin(); |
80 | 76 | } |
81 | | |
82 | 169 | llvh::Optional<ESTree::ProgramNode *> JSParser::parse() { |
83 | 169 | return impl_->parse(); |
84 | 169 | } |
85 | | |
86 | 0 | void JSParser::seek(SMLoc startPos) { |
87 | 0 | return impl_->seek(startPos); |
88 | 0 | } |
89 | | |
90 | | std::unique_ptr<JSParser> JSParser::preParseBuffer( |
91 | | Context &context, |
92 | 102 | uint32_t bufferId) { |
93 | 102 | if (auto preParser = |
94 | 102 | detail::JSParserImpl::preParseBuffer(context, bufferId)) { |
95 | 75 | return std::unique_ptr<JSParser>(new JSParser(std::move(preParser))); |
96 | 75 | } else { |
97 | 27 | return nullptr; |
98 | 27 | } |
99 | 102 | } |
100 | | |
101 | | llvh::Optional<ESTree::NodePtr> JSParser::parseLazyFunction( |
102 | | ESTree::NodeKind kind, |
103 | | bool paramYield, |
104 | | bool paramAwait, |
105 | 0 | SMLoc start) { |
106 | 0 | return impl_->parseLazyFunction(kind, paramYield, paramAwait, start); |
107 | 0 | } |
108 | | } // namespace parser |
109 | | } // namespace hermes |