1/* 2 * Copyright (c) 2022-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 { Expression } from '../../generated'; 17import { 18 assertValidPeer, 19 AstNode, 20 Es2pandaAstNodeType, 21 Es2pandaMemberExpressionKind, 22 KNativePointer, 23 passNode, 24 unpackNonNullableNode, 25 global, 26} from '../../reexport-for-generated'; 27 28export class MemberExpression extends Expression { 29 constructor(peer: KNativePointer) { 30 assertValidPeer(peer, Es2pandaAstNodeType.AST_NODE_TYPE_MEMBER_EXPRESSION); 31 super(peer); 32 } 33 34 static create( 35 object: AstNode, 36 property: AstNode, 37 kind: Es2pandaMemberExpressionKind, 38 computed: boolean, 39 optional: boolean 40 ): MemberExpression { 41 return new MemberExpression( 42 global.generatedEs2panda._CreateMemberExpression( 43 global.context, 44 passNode(object), 45 passNode(property), 46 kind, 47 computed, 48 optional 49 ) 50 ); 51 } 52 53 static update( 54 node: MemberExpression, 55 object: AstNode, 56 property: AstNode, 57 kind: Es2pandaMemberExpressionKind, 58 computed: boolean, 59 optional: boolean 60 ): MemberExpression { 61 return new MemberExpression( 62 global.generatedEs2panda._UpdateMemberExpression( 63 global.context, 64 node.peer, 65 passNode(object), 66 passNode(property), 67 kind, 68 computed, 69 optional 70 ) 71 ); 72 } 73 74 protected override dumpMessage(): string { 75 return ` <kind: ${this.kind}>`; 76 } 77 78 get object(): AstNode { 79 return unpackNonNullableNode(global.generatedEs2panda._MemberExpressionObject(global.context, this.peer)); 80 } 81 82 get property(): AstNode { 83 return unpackNonNullableNode(global.generatedEs2panda._MemberExpressionProperty(global.context, this.peer)); 84 } 85 86 get kind(): Es2pandaMemberExpressionKind { 87 return global.generatedEs2panda._MemberExpressionKindConst(global.context, this.peer); 88 } 89 90 get computed(): boolean { 91 return global.generatedEs2panda._MemberExpressionIsComputedConst(global.context, this.peer); 92 } 93 94 get optional(): boolean { 95 return false; // todo: no corresponding method in es2panda 96 } 97 98 /** @deprecated */ 99 setObject(object_arg?: Expression): this { 100 global.generatedEs2panda._MemberExpressionSetObject(global.context, this.peer, passNode(object_arg)); 101 return this; 102 } 103 /** @deprecated */ 104 setProperty(prop?: Expression): this { 105 global.generatedEs2panda._MemberExpressionSetProperty(global.context, this.peer, passNode(prop)); 106 return this; 107 } 108} 109