From 839ca31e76cab9f81a249220f3a58c00a2deb8b9 Mon Sep 17 00:00:00 2001 From: carlosmiei <43336371+carlosmiei@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:57:45 +0000 Subject: [PATCH] fix(go): handle panicOnError after callinternal --- src/goTranspiler.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/goTranspiler.ts b/src/goTranspiler.ts index 3d1c344..4a819e0 100644 --- a/src/goTranspiler.ts +++ b/src/goTranspiler.ts @@ -459,7 +459,14 @@ ${this.getIden(identation)}PanicOnError(${parsedName})`; if (isNew) { return this.getIden(identation) + this.printNode(declaration.name) + " := " + parsedValue; } - return this.getIden(identation) + "var " + this.printNode(declaration.name) + " interface{} = " + parsedValue; + const varName = this.printNode(declaration.name); + const stm = this.getIden(identation) + "var " + varName + " interface{} = " + parsedValue; + if (parsedValue.startsWith("<-this.callInternal(")) { + return ` +${stm} +${this.getIden(identation)}PanicOnError(${varName})`; + } + return stm; } return this.getIden(identation) + this.printNode(declaration.name) + " := " + parsedValue.trim(); @@ -610,9 +617,9 @@ ${this.getIden(identation)}PanicOnError(${parsedName})`; let argsParsed = ""; if (args.length > 0) { argsParsed = args.map((a) => this.printNode(a, 0)).join(", "); - return `this.callInternal("${methodName}", ${argsParsed})`; + return `<-this.callInternal("${methodName}", ${argsParsed})`; } - return `this.callInternal("${methodName}")`; + return `<-this.callInternal("${methodName}")`; } } @@ -1390,7 +1397,7 @@ ${this.getIden(identation)}return ${rightPart}`; return `AddElementToObject(${leftSide}, ${propName}, ${rightSide})`; } - if (right?.kind === ts.SyntaxKind.AwaitExpression) { + if (right?.kind === ts.SyntaxKind.AwaitExpression || rightSide.startsWith('<-this.callInternal')) { const leftParsed = this.printNode(left, 0); return ` ${leftParsed} = ${rightSide}