1 /**
2 * Copyright (c) 2023-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 "partialExportClassGen.h"
17
18 #include "checker/ETSchecker.h"
19 #include "varbinder/ETSBinder.h"
20
21 namespace ark::es2panda::compiler {
22
GeneratePartialDeclForExported(const public_lib::Context * const ctx,ir::AstNode * const node)23 static void GeneratePartialDeclForExported(const public_lib::Context *const ctx, ir::AstNode *const node)
24 {
25 // NOTE (mmartin): handle interfaces
26 if (node->IsClassDeclaration()) {
27 ctx->checker->AsETSChecker()->CreatePartialType(node->AsClassDeclaration()->Definition()->TsType());
28 }
29 }
30
PerformForModule(public_lib::Context * const ctx,parser::Program * const program)31 bool PartialExportClassGen::PerformForModule(public_lib::Context *const ctx, parser::Program *const program)
32 {
33 program->Ast()->TransformChildrenRecursively(
34 [ctx, &program](ir::AstNode *const ast) {
35 if ((ast->IsClassDeclaration() || ast->IsTSInterfaceDeclaration()) && ast->IsExported()) {
36 auto *const savedProg = ctx->checker->VarBinder()->AsETSBinder()->Program();
37 ctx->checker->VarBinder()->AsETSBinder()->SetProgram(program);
38 GeneratePartialDeclForExported(ctx, ast);
39 ctx->checker->VarBinder()->AsETSBinder()->SetProgram(savedProg);
40 }
41
42 return ast;
43 },
44 Name());
45
46 return true;
47 }
48
49 } // namespace ark::es2panda::compiler
50