1 /**
2 * Copyright (c) 2021-2022 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 "exportDefaultDeclaration.h"
17
18 #include <compiler/core/pandagen.h>
19 #include <ir/astDump.h>
20
21 namespace panda::es2panda::ir {
22
Iterate(const NodeTraverser & cb) const23 void ExportDefaultDeclaration::Iterate(const NodeTraverser &cb) const
24 {
25 cb(decl_);
26 }
27
Dump(ir::AstDumper * dumper) const28 void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const
29 {
30 dumper->Add(
31 {{"type", IsExportEquals() ? "TSExportAssignment" : "ExportDefaultDeclaration"}, {"declaration", decl_}});
32 }
33
Compile(compiler::PandaGen * pg) const34 void ExportDefaultDeclaration::Compile(compiler::PandaGen *pg) const
35 {
36 if (!decl_) {
37 return;
38 }
39 decl_->Compile(pg);
40 if (decl_->IsExpression()) {
41 // export default [AssignmentExpression]
42 // e.g. export default 42 (42 be exported as [default])
43 ASSERT(pg->Scope()->IsModuleScope());
44 auto *var = pg->Scope()->FindLocal(parser::SourceTextModuleRecord::DEFAULT_LOCAL_NAME);
45 ASSERT(var->IsModuleVariable());
46 pg->StoreModuleVariable(this, var->AsModuleVariable());
47 }
48 }
49
Check(checker::Checker * checker) const50 checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::Checker *checker) const
51 {
52 return nullptr;
53 }
54
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)55 void ExportDefaultDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
56 {
57 decl_ = std::get<ir::AstNode *>(cb(decl_));
58 }
59
60 } // namespace panda::es2panda::ir
61