1 /** 2 * Copyright (c) 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 "services/utilities.h" 17 #include "ir/expressions/assignmentExpression.h" 18 #include "ir/base/classProperty.h" 19 #include "varbinder/variable.h" 20 #include "varbinder/declaration.h" 21 #include "api.h" 22 23 namespace ark::es2panda::lsp { 24 IsValidImplementation(ir::AstNode * astNode)25bool IsValidImplementation(ir::AstNode *astNode) 26 { 27 if (astNode == nullptr) { 28 return false; 29 } 30 31 return !IsThis(astNode) && !IsInitializer(astNode) && !IsReturnNode(astNode) && !IsAsTypeNode(astNode); 32 } 33 IsInitializer(ir::AstNode * astNode)34bool IsInitializer(ir::AstNode *astNode) 35 { 36 return astNode != nullptr && astNode->Parent() != nullptr && 37 ((astNode->IsClassProperty() && astNode->AsClassProperty()->Value() != nullptr) || 38 (astNode->IsAssignmentExpression() && 39 astNode->AsAssignmentExpression()->Target()->Declaration()->IsLetOrConstDecl()) || 40 astNode->IsVariableDeclaration()); 41 } 42 IsThis(ir::AstNode * astNode)43bool IsThis(ir::AstNode *astNode) 44 { 45 return astNode->IsThisExpression() || astNode->IsTSThisType(); 46 } 47 IsReturnNode(ir::AstNode * astNode)48bool IsReturnNode(ir::AstNode *astNode) 49 { 50 return astNode != nullptr && astNode->Parent() != nullptr && astNode->Parent()->IsReturnStatement(); 51 } 52 IsAsTypeNode(ir::AstNode * astNode)53bool IsAsTypeNode(ir::AstNode *astNode) 54 { 55 return astNode != nullptr && astNode->IsAssignmentExpression() && 56 astNode->AsAssignmentExpression()->Right()->IsTSAsExpression(); 57 } 58 59 } // namespace ark::es2panda::lsp 60