• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "etsModule.h"
17 #include "utils/arena_containers.h"
18 
19 namespace ark::es2panda::ir {
20 
Dump(ir::SrcDumper * dumper) const21 void ETSModule::Dump(ir::SrcDumper *dumper) const
22 {
23     if (IsNamespace()) {
24         if (IsExported()) {
25             dumper->Add("export ");
26         }
27 
28         if (IsDefaultExported()) {
29             dumper->Add("export default ");
30         }
31 
32         if (IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) {
33             dumper->Add("declare ");
34         }
35 
36         dumper->Add("namespace ");
37         ident_->Dump(dumper);
38         dumper->Add(" {");
39         dumper->IncrIndent();
40     }
41 
42     if (!Statements().empty()) {
43         dumper->Endl();
44         for (auto elem : Statements()) {
45             elem->Dump(dumper);
46             if (elem == Statements().back()) {
47                 dumper->DecrIndent();
48             }
49             dumper->Endl();
50         }
51     }
52     if (IsNamespace()) {
53         dumper->Add("}");
54     }
55 }
56 
Construct(ArenaAllocator * allocator)57 ETSModule *ETSModule::Construct(ArenaAllocator *allocator)
58 {
59     ArenaVector<Statement *> statementList(allocator->Adapter());
60     return allocator->New<ETSModule>(allocator, std::move(statementList), nullptr, ModuleFlag::NONE, nullptr);
61 }
62 
CopyTo(AstNode * other) const63 void ETSModule::CopyTo(AstNode *other) const
64 {
65     auto otherImpl = other->AsETSModule();
66 
67     otherImpl->ident_ = ident_;
68     otherImpl->flag_ = flag_;
69     otherImpl->program_ = program_;
70 
71     JsDocAllowed<AnnotationAllowed<BlockStatement>>::CopyTo(other);
72 }
73 
74 }  // namespace ark::es2panda::ir
75