1/*
2 * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "generated/keywords.h"
17#include "lexer/keywordsUtil.h"
18#include "parser/context/parserContext.h"
19
20namespace ark::es2panda::lexer {
21
22KeywordString JSKeywords::Handle_as([[maybe_unused]] const KeywordsUtil &util, std::string_view src,
23                                    TokenType tokenType)
24{
25    return {src, TokenType::LITERAL_IDENT, tokenType};
26}
27
28KeywordString JSKeywords::Handle_await(const KeywordsUtil &util, std::string_view src, TokenType tokenType)
29{
30    const auto *parserContext = util.GetParserContext();
31
32    if (!parserContext->IsAsync() && !parserContext->IsModule()) {
33        return {src, TokenType::LITERAL_IDENT, tokenType};
34    }
35
36    util.CheckEscapedKeyword();
37
38    return {src, tokenType};
39}
40
41KeywordString JSKeywords::Handle_yield(const KeywordsUtil &util, std::string_view src, TokenType tokenType)
42{
43    const auto *parserContext = util.GetParserContext();
44
45    if (!parserContext->IsGenerator()) {
46        util.ThrowUnexpectedStrictModeReservedKeyword();
47    }
48
49    util.CheckEscapedKeyword();
50
51    return {src, tokenType};
52}
53
54KeywordString TSKeywords::Handle_as(const KeywordsUtil &util, std::string_view src, TokenType tokenType)
55{
56    return JSKeywords::Handle_as(util, src, tokenType);
57}
58
59KeywordString TSKeywords::Handle_await(const KeywordsUtil &util, std::string_view src, TokenType tokenType)
60{
61    return JSKeywords::Handle_await(util, src, tokenType);
62}
63
64KeywordString TSKeywords::Handle_yield(const KeywordsUtil &util, std::string_view src, TokenType tokenType)
65{
66    return JSKeywords::Handle_yield(util, src, tokenType);
67}
68
69KeywordString ASKeywords::Handle_as(const KeywordsUtil &util, std::string_view src, TokenType tokenType)
70{
71    return JSKeywords::Handle_as(util, src, tokenType);
72}
73
74}  // namespace ark::es2panda::lexer
75