1/**
2 * Copyright (c) 2021-2024 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#ifndef ES2PANDA_IR_TS_MODULE_BLOCK_H
17#define ES2PANDA_IR_TS_MODULE_BLOCK_H
18
19#include "varbinder/scope.h"
20#include "ir/statement.h"
21
22namespace ark::es2panda::ir {
23class TSModuleBlock : public Statement {
24public:
25    explicit TSModuleBlock(ArenaVector<Statement *> &&statements)
26        : Statement(AstNodeType::TS_MODULE_BLOCK), statements_(std::move(statements))
27    {
28    }
29
30    [[nodiscard]] bool IsScopeBearer() const noexcept override
31    {
32        return true;
33    }
34
35    [[nodiscard]] varbinder::Scope *Scope() const noexcept override
36    {
37        return scope_;
38    }
39
40    void SetScope(varbinder::LocalScope *scope)
41    {
42        ASSERT(scope_ == nullptr);
43        scope_ = scope;
44    }
45
46    void ClearScope() noexcept override
47    {
48        scope_ = nullptr;
49    }
50
51    const ArenaVector<Statement *> &Statements() const
52    {
53        return statements_;
54    }
55
56    void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
57    void Iterate(const NodeTraverser &cb) const override;
58    void Dump(ir::AstDumper *dumper) const override;
59    void Dump(ir::SrcDumper *dumper) const override;
60    void Compile([[maybe_unused]] compiler::PandaGen *pg) const override;
61    void Compile(compiler::ETSGen *etsg) const override;
62    checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override;
63    checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override;
64
65    void Accept(ASTVisitorT *v) override
66    {
67        v->Accept(this);
68    }
69
70private:
71    varbinder::LocalScope *scope_ {nullptr};
72    ArenaVector<Statement *> statements_;
73};
74}  // namespace ark::es2panda::ir
75
76#endif
77