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 16import { 17 global, 18 passNode, 19 passNodeArray, 20 unpackNonNullableNode, 21 unpackNode, 22 unpackNodeArray, 23 assertValidPeer, 24 AstNode, 25 Es2pandaAstNodeType, 26 KNativePointer, 27 nodeByType, 28 ArktsObject, 29 unpackString 30} from "../../reexport-for-generated" 31 32import { FunctionSignature } from "./FunctionSignature" 33import { Identifier } from "./Identifier" 34import { Expression } from "./Expression" 35import { ReturnStatement } from "./ReturnStatement" 36import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" 37import { TypeNode } from "./TypeNode" 38import { Es2pandaScriptFunctionFlags } from "./../Es2pandaEnums" 39import { Es2pandaModifierFlags } from "./../Es2pandaEnums" 40import { AnnotationUsage } from "./AnnotationUsage" 41export class ScriptFunction extends AstNode { 42 constructor(pointer: KNativePointer) { 43 assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_SCRIPT_FUNCTION) 44 super(pointer) 45 46 } 47 static createScriptFunction(databody: AstNode | undefined, datasignature: FunctionSignature | undefined, datafuncFlags: number, dataflags: number): ScriptFunction { 48 return new ScriptFunction(global.generatedEs2panda._CreateScriptFunction(global.context, passNode(databody), passNode(datasignature), datafuncFlags, dataflags)) 49 } 50 static updateScriptFunction(original: ScriptFunction | undefined, databody: AstNode | undefined, datasignature: FunctionSignature | undefined, datafuncFlags: number, dataflags: number): ScriptFunction { 51 return new ScriptFunction(global.generatedEs2panda._UpdateScriptFunction(global.context, passNode(original), passNode(databody), passNode(datasignature), datafuncFlags, dataflags)) 52 } 53 get id(): Identifier | undefined { 54 return unpackNode(global.generatedEs2panda._ScriptFunctionIdConst(global.context, this.peer)) 55 } 56 get params(): readonly Expression[] { 57 return unpackNodeArray(global.generatedEs2panda._ScriptFunctionParamsConst(global.context, this.peer)) 58 } 59 get returnStatements(): readonly ReturnStatement[] { 60 return unpackNodeArray(global.generatedEs2panda._ScriptFunctionReturnStatementsConst(global.context, this.peer)) 61 } 62 get typeParams(): TSTypeParameterDeclaration | undefined { 63 return unpackNode(global.generatedEs2panda._ScriptFunctionTypeParamsConst(global.context, this.peer)) 64 } 65 get body(): AstNode | undefined { 66 return unpackNode(global.generatedEs2panda._ScriptFunctionBodyConst(global.context, this.peer)) 67 } 68 /** @deprecated */ 69 addReturnStatement(returnStatement: ReturnStatement): this { 70 global.generatedEs2panda._ScriptFunctionAddReturnStatement(global.context, this.peer, passNode(returnStatement)) 71 return this 72 } 73 /** @deprecated */ 74 setBody(body: AstNode): this { 75 global.generatedEs2panda._ScriptFunctionSetBody(global.context, this.peer, passNode(body)) 76 return this 77 } 78 get returnTypeAnnotation(): TypeNode | undefined { 79 return unpackNode(global.generatedEs2panda._ScriptFunctionReturnTypeAnnotationConst(global.context, this.peer)) 80 } 81 /** @deprecated */ 82 setReturnTypeAnnotation(node: TypeNode): this { 83 global.generatedEs2panda._ScriptFunctionSetReturnTypeAnnotation(global.context, this.peer, passNode(node)) 84 return this 85 } 86 get isEntryPoint(): boolean { 87 return global.generatedEs2panda._ScriptFunctionIsEntryPointConst(global.context, this.peer) 88 } 89 get isGenerator(): boolean { 90 return global.generatedEs2panda._ScriptFunctionIsGeneratorConst(global.context, this.peer) 91 } 92 get isAsyncFunc(): boolean { 93 return global.generatedEs2panda._ScriptFunctionIsAsyncFuncConst(global.context, this.peer) 94 } 95 get isAsyncImplFunc(): boolean { 96 return global.generatedEs2panda._ScriptFunctionIsAsyncImplFuncConst(global.context, this.peer) 97 } 98 get isArrow(): boolean { 99 return global.generatedEs2panda._ScriptFunctionIsArrowConst(global.context, this.peer) 100 } 101 get isOverload(): boolean { 102 return global.generatedEs2panda._ScriptFunctionIsOverloadConst(global.context, this.peer) 103 } 104 get isExternalOverload(): boolean { 105 return global.generatedEs2panda._ScriptFunctionIsExternalOverloadConst(global.context, this.peer) 106 } 107 get isConstructor(): boolean { 108 return global.generatedEs2panda._ScriptFunctionIsConstructorConst(global.context, this.peer) 109 } 110 get isGetter(): boolean { 111 return global.generatedEs2panda._ScriptFunctionIsGetterConst(global.context, this.peer) 112 } 113 get isSetter(): boolean { 114 return global.generatedEs2panda._ScriptFunctionIsSetterConst(global.context, this.peer) 115 } 116 get isExtensionAccessor(): boolean { 117 return global.generatedEs2panda._ScriptFunctionIsExtensionAccessorConst(global.context, this.peer) 118 } 119 get isMethod(): boolean { 120 return global.generatedEs2panda._ScriptFunctionIsMethodConst(global.context, this.peer) 121 } 122 get isProxy(): boolean { 123 return global.generatedEs2panda._ScriptFunctionIsProxyConst(global.context, this.peer) 124 } 125 get isStaticBlock(): boolean { 126 return global.generatedEs2panda._ScriptFunctionIsStaticBlockConst(global.context, this.peer) 127 } 128 get isEnum(): boolean { 129 return global.generatedEs2panda._ScriptFunctionIsEnumConst(global.context, this.peer) 130 } 131 get isHidden(): boolean { 132 return global.generatedEs2panda._ScriptFunctionIsHiddenConst(global.context, this.peer) 133 } 134 get isExternal(): boolean { 135 return global.generatedEs2panda._ScriptFunctionIsExternalConst(global.context, this.peer) 136 } 137 get isImplicitSuperCallNeeded(): boolean { 138 return global.generatedEs2panda._ScriptFunctionIsImplicitSuperCallNeededConst(global.context, this.peer) 139 } 140 get hasBody(): boolean { 141 return global.generatedEs2panda._ScriptFunctionHasBodyConst(global.context, this.peer) 142 } 143 get hasRestParameter(): boolean { 144 return global.generatedEs2panda._ScriptFunctionHasRestParameterConst(global.context, this.peer) 145 } 146 get hasReturnStatement(): boolean { 147 return global.generatedEs2panda._ScriptFunctionHasReturnStatementConst(global.context, this.peer) 148 } 149 get hasThrowStatement(): boolean { 150 return global.generatedEs2panda._ScriptFunctionHasThrowStatementConst(global.context, this.peer) 151 } 152 get isThrowing(): boolean { 153 return global.generatedEs2panda._ScriptFunctionIsThrowingConst(global.context, this.peer) 154 } 155 get isRethrowing(): boolean { 156 return global.generatedEs2panda._ScriptFunctionIsRethrowingConst(global.context, this.peer) 157 } 158 get isDynamic(): boolean { 159 return global.generatedEs2panda._ScriptFunctionIsDynamicConst(global.context, this.peer) 160 } 161 get isExtensionMethod(): boolean { 162 return global.generatedEs2panda._ScriptFunctionIsExtensionMethodConst(global.context, this.peer) 163 } 164 get flags(): Es2pandaScriptFunctionFlags { 165 return global.generatedEs2panda._ScriptFunctionFlagsConst(global.context, this.peer) 166 } 167 get hasReceiver(): boolean { 168 return global.generatedEs2panda._ScriptFunctionHasReceiverConst(global.context, this.peer) 169 } 170 /** @deprecated */ 171 setIdent(id: Identifier): this { 172 global.generatedEs2panda._ScriptFunctionSetIdent(global.context, this.peer, passNode(id)) 173 return this 174 } 175 /** @deprecated */ 176 addFlag(flags: Es2pandaScriptFunctionFlags): this { 177 global.generatedEs2panda._ScriptFunctionAddFlag(global.context, this.peer, flags) 178 return this 179 } 180 /** @deprecated */ 181 addModifier(flags: Es2pandaModifierFlags): this { 182 global.generatedEs2panda._ScriptFunctionAddModifier(global.context, this.peer, flags) 183 return this 184 } 185 get annotations(): readonly AnnotationUsage[] { 186 return unpackNodeArray(global.generatedEs2panda._ScriptFunctionAnnotationsConst(global.context, this.peer)) 187 } 188 /** @deprecated */ 189 setAnnotations(annotations: readonly AnnotationUsage[]): this { 190 global.generatedEs2panda._ScriptFunctionSetAnnotations(global.context, this.peer, passNodeArray(annotations), annotations.length) 191 return this 192 } 193} 194export function isScriptFunction(node: AstNode): node is ScriptFunction { 195 return node instanceof ScriptFunction 196} 197if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_SCRIPT_FUNCTION)) { 198 nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_SCRIPT_FUNCTION, ScriptFunction) 199} 200