From 828972c466c76901ced025a3c6a072b61fa736da Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Sun, 16 Feb 2025 04:30:38 +0300 Subject: [PATCH 1/2] interface improvements Signed-off-by: Alexander Gorshenev --- .../plugins/src/component-transformer.ts | 1 + .../src/arkts-api/factory/nodeFactory.ts | 13 ++++++--- arkoala-arkts/libarkts/src/arkts-api/types.ts | 29 ------------------- .../libarkts/src/arkts-api/visitor.ts | 25 ++++++++++++++-- .../generated/peers/TSInterfaceDeclaration.ts | 15 +++++----- 5 files changed, 40 insertions(+), 43 deletions(-) diff --git a/arkoala-arkts/libarkts/plugins/src/component-transformer.ts b/arkoala-arkts/libarkts/plugins/src/component-transformer.ts index 10b2a6d0ea..8f4ebde898 100644 --- a/arkoala-arkts/libarkts/plugins/src/component-transformer.ts +++ b/arkoala-arkts/libarkts/plugins/src/component-transformer.ts @@ -52,6 +52,7 @@ export class ComponentTransformer extends AbstractVisitor { const interfaceDeclarations = this.context.componentNames.map( name => arkts.factory.createInterfaceDeclaration( [], + 0, arkts.factory.createIdentifier(`__Options_${name}`), nullptr, // TODO: wtf arkts.factory.createBlock([]), diff --git a/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts b/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts index 4f3f39b21e..163cb9f85f 100644 --- a/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts +++ b/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts @@ -43,7 +43,6 @@ import { StringLiteral, StructDeclaration, SuperExpression, - TSInterfaceDeclaration, TSTypeParameter, TSTypeParameterDeclaration, TSTypeParameterInstantiation, @@ -53,7 +52,7 @@ import { } from "../types" import { MemberExpression } from "../to-be-generated/MemberExpression" import { AstNode } from "../peers/AstNode" -import { AnnotationUsage } from "../../generated" +import { AnnotationUsage, TSInterfaceBody } from "../../generated" function compose( create: (...args: ARGS) => T, @@ -278,10 +277,16 @@ export const factory = { return compose(TSTypeParameterInstantiation.create) }, get createInterfaceDeclaration() { - return TSInterfaceDeclaration.create + return TSInterfaceDeclaration.createTSInterfaceDeclaration }, get updateInterfaceDeclaration() { - return compose(TSInterfaceDeclaration.create) + return compose(TSInterfaceDeclaration.createTSInterfaceDeclaration) + }, + get createInterfaceBody() { + return TSInterfaceBody.createTSInterfaceBody + }, + get updateInterfaceBody() { + return compose(TSInterfaceBody.createTSInterfaceBody) }, get createUndefinedLiteral() { return UndefinedLiteral.create diff --git a/arkoala-arkts/libarkts/src/arkts-api/types.ts b/arkoala-arkts/libarkts/src/arkts-api/types.ts index e546bff6ec..d1136c3feb 100644 --- a/arkoala-arkts/libarkts/src/arkts-api/types.ts +++ b/arkoala-arkts/libarkts/src/arkts-api/types.ts @@ -1237,35 +1237,6 @@ export class TSTypeParameterInstantiation extends AstNode { } } -export class TSInterfaceDeclaration extends AstNode { - constructor(peer: KPtr) { - assertValidPeer(peer, Es2pandaAstNodeType.AST_NODE_TYPE_TS_INTERFACE_DECLARATION) - super(peer) - } - - static create( - extendsParams: readonly AstNode[], - id: AstNode, - typeParams: AstNode, - body: AstNode, - isStatic: KBoolean, - isExternal: KBoolean, - ): TSInterfaceDeclaration { - return new TSInterfaceDeclaration( - global.generatedEs2panda._CreateTSInterfaceDeclaration( - global.context, - passNodeArray(extendsParams), - extendsParams.length, - passNode(id), - passNode(typeParams), - passNode(body), - isStatic, - isExternal, - ) - ) - } -} - export class UndefinedLiteral extends AstNode { constructor(peer: KPtr) { assertValidPeer(peer, Es2pandaAstNodeType.AST_NODE_TYPE_UNDEFINED_LITERAL) diff --git a/arkoala-arkts/libarkts/src/arkts-api/visitor.ts b/arkoala-arkts/libarkts/src/arkts-api/visitor.ts index 622448e385..60eace96d4 100644 --- a/arkoala-arkts/libarkts/src/arkts-api/visitor.ts +++ b/arkoala-arkts/libarkts/src/arkts-api/visitor.ts @@ -26,7 +26,9 @@ import { FunctionSignature, MethodDefinition, ScriptFunction, - StructDeclaration + StructDeclaration, + TSInterfaceDeclaration, + TSInterfaceBody, } from "./types" import { Es2pandaClassDefinitionModifiers, @@ -224,7 +226,26 @@ export function visitEachChild( node.optional ) } - + if (node instanceof TSInterfaceDeclaration) { + return factory.updateInterfaceDeclaration( + node, + nodesVisitor(node.extends, visitor), + node.extends.length, + nodeVisitor(node.id, visitor), + nodeVisitor(node.typeParams, visitor), + nodeVisitor(node.body, visitor), + node.isStaticConst, + // TODO: how do I get it? + true + ) + } + if (node instanceof TSInterfaceBody) { + return factory.updateInterfaceBody( + node, + nodesVisitor(node.body, visitor), + node.body.length + ) + } // TODO return node } diff --git a/arkoala-arkts/libarkts/src/generated/peers/TSInterfaceDeclaration.ts b/arkoala-arkts/libarkts/src/generated/peers/TSInterfaceDeclaration.ts index d015665ef0..270f232903 100644 --- a/arkoala-arkts/libarkts/src/generated/peers/TSInterfaceDeclaration.ts +++ b/arkoala-arkts/libarkts/src/generated/peers/TSInterfaceDeclaration.ts @@ -14,17 +14,15 @@ */ import { + assertValidPeer, + AstNode, global, + KNativePointer, + nodeByType, passNode, passNodeArray, - unpackNonNullableNode, unpackNode, - unpackNodeArray, - assertValidPeer, - AstNode, - Es2pandaAstNodeType, - KNativePointer, - nodeByType + unpackNodeArray } from "../../reexport-for-generated" import { TypedStatement } from "./TypedStatement" @@ -35,6 +33,7 @@ import { TSTypeParameterDeclaration } from "./TSTypeParameterDeclaration" import { Decorator } from "./Decorator" import { ClassDeclaration } from "./ClassDeclaration" import { AnnotationUsage } from "./AnnotationUsage" + export class TSInterfaceDeclaration extends TypedStatement { constructor(pointer: KNativePointer) { assertValidPeer(pointer, 130) @@ -101,4 +100,4 @@ export function isTSInterfaceDeclaration(node: AstNode): node is TSInterfaceDecl } if (!nodeByType.has(130)) { nodeByType.set(130, TSInterfaceDeclaration) -} \ No newline at end of file +} -- Gitee From c7dfeeb6463c47f132e1871e30a8250eafc808f6 Mon Sep 17 00:00:00 2001 From: naumovdmitrii Date: Wed, 19 Feb 2025 17:15:53 +0300 Subject: [PATCH 2/2] rebase Signed-off-by: naumovdmitrii --- .../libarkts/src/arkts-api/factory/nodeFactory.ts | 2 +- arkoala-arkts/libarkts/src/arkts-api/factory/nodeTests.ts | 5 ----- arkoala-arkts/libarkts/src/arkts-api/visitor.ts | 8 ++------ 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts b/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts index 163cb9f85f..eb99b8552f 100644 --- a/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts +++ b/arkoala-arkts/libarkts/src/arkts-api/factory/nodeFactory.ts @@ -52,7 +52,7 @@ import { } from "../types" import { MemberExpression } from "../to-be-generated/MemberExpression" import { AstNode } from "../peers/AstNode" -import { AnnotationUsage, TSInterfaceBody } from "../../generated" +import { AnnotationUsage, TSInterfaceBody, TSInterfaceDeclaration } from "../../generated" function compose( create: (...args: ARGS) => T, diff --git a/arkoala-arkts/libarkts/src/arkts-api/factory/nodeTests.ts b/arkoala-arkts/libarkts/src/arkts-api/factory/nodeTests.ts index dd87fe0c4e..bcb493faa2 100644 --- a/arkoala-arkts/libarkts/src/arkts-api/factory/nodeTests.ts +++ b/arkoala-arkts/libarkts/src/arkts-api/factory/nodeTests.ts @@ -16,7 +16,6 @@ import { ScriptFunction, StringLiteral, StructDeclaration, - TSInterfaceDeclaration, VariableDeclaration, ClassProperty } from "../types" @@ -27,10 +26,6 @@ export function isAnnotationDeclaration(node: AstNode): node is AnnotationDeclar return global.es2panda._IsAnnotationDeclaration(node.peer); } -export function isTSInterfaceDeclaration(node: AstNode): node is TSInterfaceDeclaration { - return global.es2panda._IsTSInterfaceDeclaration(node.peer); -} - export function isIdentifier(node: AstNode): node is Identifier { return node instanceof Identifier } diff --git a/arkoala-arkts/libarkts/src/arkts-api/visitor.ts b/arkoala-arkts/libarkts/src/arkts-api/visitor.ts index 60eace96d4..e52994391d 100644 --- a/arkoala-arkts/libarkts/src/arkts-api/visitor.ts +++ b/arkoala-arkts/libarkts/src/arkts-api/visitor.ts @@ -27,16 +27,12 @@ import { MethodDefinition, ScriptFunction, StructDeclaration, - TSInterfaceDeclaration, - TSInterfaceBody, } from "./types" -import { - Es2pandaClassDefinitionModifiers, - Es2pandaModifierFlags -} from "../generated/Es2pandaEnums" +import { Es2pandaClassDefinitionModifiers, Es2pandaModifierFlags } from "../generated/Es2pandaEnums" import { nullptr } from "@koalaui/interop" import { AstNode } from "./peers/AstNode" import { MemberExpression } from "./to-be-generated/MemberExpression" +import { TSInterfaceBody, TSInterfaceDeclaration } from "../generated" type Visitor = (node: AstNode) => AstNode -- Gitee