• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021 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 "tsTypeAliasDeclaration.h"
17 
18 #include <binder/scope.h>
19 #include <typescript/checker.h>
20 #include <ir/astDump.h>
21 #include <ir/expressions/identifier.h>
22 #include <ir/ts/tsTypeParameter.h>
23 #include <ir/ts/tsTypeParameterDeclaration.h>
24 
25 namespace panda::es2panda::ir {
26 
Iterate(const NodeTraverser & cb) const27 void TSTypeAliasDeclaration::Iterate(const NodeTraverser &cb) const
28 {
29     cb(id_);
30 
31     if (typeParams_) {
32         cb(typeParams_);
33     }
34 
35     cb(typeAnnotation_);
36 }
37 
Dump(ir::AstDumper * dumper) const38 void TSTypeAliasDeclaration::Dump(ir::AstDumper *dumper) const
39 {
40     dumper->Add({{"type", "TSTypeAliasDeclaration"},
41                  {"id", id_},
42                  {"typeAnnotation", typeAnnotation_},
43                  {"typeParameters", AstDumper::Optional(typeParams_)},
44                  {"declare", AstDumper::Optional(declare_)}});
45 }
46 
Compile(compiler::PandaGen * pg) const47 void TSTypeAliasDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {}
48 
Check(checker::Checker * checker) const49 checker::Type *TSTypeAliasDeclaration::Check(checker::Checker *checker) const
50 {
51     typeAnnotation_->Check(checker);
52     return nullptr;
53 }
54 
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)55 void TSTypeAliasDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
56 {
57     id_ = std::get<ir::AstNode *>(cb(id_))->AsIdentifier();
58 
59     if (typeParams_) {
60         typeParams_ = std::get<ir::AstNode *>(cb(typeParams_))->AsTSTypeParameterDeclaration();
61     }
62 
63     typeAnnotation_ = std::get<ir::AstNode *>(cb(typeAnnotation_))->AsExpression();
64 }
65 
66 }  // namespace panda::es2panda::ir
67