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
21namespace panda::es2panda::ir {
22
23void ExportDefaultDeclaration::Iterate(const NodeTraverser &cb) const
24{
25    cb(decl_);
26}
27
28void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const
29{
30    dumper->Add(
31        {{"type", IsExportEquals() ? "TSExportAssignment" : "ExportDefaultDeclaration"}, {"declaration", decl_}});
32}
33
34void 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        CHECK_NOT_NULL(var);
46        ASSERT(var->IsModuleVariable());
47        pg->StoreModuleVariable(this, var->AsModuleVariable());
48    }
49}
50
51checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::Checker *checker) const
52{
53    return nullptr;
54}
55
56void ExportDefaultDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
57{
58    decl_ = std::get<ir::AstNode *>(cb(decl_));
59}
60
61}  // namespace panda::es2panda::ir
62