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 * as arkts from '@koalaui/libarkts'; 17 18import { AbstractVisitor } from '../common/abstract-visitor'; 19 20import { debugLog } from '../common/debug'; 21 22export class EmitTransformer extends AbstractVisitor { 23 constructor(private options?: interop.EmitTransformerOptions) { 24 super(); 25 } 26 27 processComponent(node: arkts.ClassDeclaration): arkts.ClassDeclaration { 28 const className = node.definition?.ident?.name; 29 if (!className) { 30 throw 'Non Empty className expected for Component'; 31 } 32 33 const newDefinition = arkts.factory.updateClassDefinition( 34 node.definition, 35 node.definition?.ident, 36 undefined, 37 undefined, 38 node.definition?.implements, 39 undefined, 40 undefined, 41 node.definition?.body, 42 node.definition?.modifiers, 43 arkts.classDefinitionFlags(node.definition) | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE 44 ); 45 46 let newDec: arkts.ClassDeclaration = arkts.factory.updateClassDeclaration(node, newDefinition); 47 48 debugLog(`DeclTransformer:checked:struct_ast:${newDefinition.dumpJson()}`); 49 newDec.modifiers = node.modifiers; 50 return newDec; 51 } 52 53 visitor(beforeChildren: arkts.AstNode): arkts.AstNode { 54 const node = this.visitEachChild(beforeChildren); 55 if (arkts.isClassDeclaration(node) && arkts.classDefinitionIsFromStructConst(node.definition!)) { 56 return this.processComponent(node); 57 } 58 return node; 59 } 60} 61