diff --git a/arkoala-arkts/libarkts/plugins/src/print-visitor.ts b/arkoala-arkts/libarkts/plugins/src/print-visitor.ts index 50be42fc2f9894ca188389e1bf9f0dd436c1cb15..d49bbfd7d3d28e5460d39ec0450aef5efe04358f 100644 --- a/arkoala-arkts/libarkts/plugins/src/print-visitor.ts +++ b/arkoala-arkts/libarkts/plugins/src/print-visitor.ts @@ -1,22 +1,19 @@ -import * as ts from "@koalaui/libarkts" +import * as arkts from "@koalaui/libarkts" import { AbstractVisitor } from "./AbstractVisitor"; export class PrintVisitor extends AbstractVisitor { private result = "" - private print(s: string) { - this.result += " ".repeat(4 * this.indentation) + s + '\n' + private printNode(node: arkts.AstNode) { + return `${" ".repeat(4 * this.indentation) + node.constructor.name} ${this.nameIfIdentifier(node)}` } - visitor(node: ts.AstNode): ts.AstNode { - console.log(`${" ".repeat(4 * this.indentation) + node.constructor.name}`) - this.print(`${node.constructor.name}`) - return this.visitEachChild(node) + private nameIfIdentifier(node: arkts.AstNode): string { + return arkts.isIdentifier(node) ? `'${node.name}'` : "" } - astToString(node: ts.AstNode): string { - this.result = "" - this.visitor(node) - return this.result.trim() + visitor(node: arkts.AstNode): arkts.AstNode { + console.log(this.printNode(node)) + return this.visitEachChild(node) } }