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 "declaration.h"
17
18#include <binder/scope.h>
19#include <ir/base/classDefinition.h>
20#include <ir/base/scriptFunction.h>
21#include <ir/ts/tsModuleDeclaration.h>
22#include <parser/program/program.h>
23
24namespace panda::es2panda::binder {
25
26bool Decl::IsSendableClassDecl() const
27{
28    return node_ && node_->IsClassDefinition() && node_->AsClassDefinition()->IsSendable();
29}
30
31bool Decl::IsSendableFunctionDecl() const
32{
33    return node_ && node_->IsScriptFunction() && node_->AsScriptFunction()->IsSendable();
34}
35
36bool Decl::NeedSetInSendableEnv(Scope *scope) const
37{
38    if (!scope->IsModuleScope()) {
39        return false;
40    }
41
42    // sendable env will not be effective before api 12
43    if (scope->AsModuleScope()->Program()->TargetApiVersion() < 12) {
44        return false;
45    }
46    return IsSendableClassDecl() || IsSendableFunctionDecl();
47}
48
49bool NamespaceDecl::IsInstantiated() const
50{
51    auto tsModules = Decls();
52    for (auto *it : tsModules) {
53        if (it->IsInstantiated()) {
54            return true;
55        }
56    }
57    return false;
58}
59
60}  // namespace panda::es2panda::binder
61