From 1865e70181cee2fa402175ad6ed3f2998f671aef Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Thu, 5 Sep 2024 17:53:08 +0200 Subject: [PATCH] fix RETURN --- packages/transpiler/src/keywords.ts | 3 ++- .../transpiler/src/statements/end_method.ts | 2 +- packages/transpiler/src/statements/return.ts | 2 +- packages/transpiler/src/transpile_types.ts | 3 ++- test/keywords.ts | 21 +++++++++++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/transpiler/src/keywords.ts b/packages/transpiler/src/keywords.ts index 75071a3d7..fc2281b1d 100644 --- a/packages/transpiler/src/keywords.ts +++ b/packages/transpiler/src/keywords.ts @@ -4,7 +4,8 @@ import * as abaplint from "@abaplint/core"; export const DEFAULT_KEYWORDS: string[] = [ "abstract", "arguments", "await", "break", "byte", "catch", - "char", "class", "const", "continue", +// "char", + "class", "const", "continue", "debugger", "default", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", diff --git a/packages/transpiler/src/statements/end_method.ts b/packages/transpiler/src/statements/end_method.ts index a344dc5a3..2a58c7ef5 100644 --- a/packages/transpiler/src/statements/end_method.ts +++ b/packages/transpiler/src/statements/end_method.ts @@ -20,7 +20,7 @@ export class EndMethodTranspiler implements IStatementTranspiler { for (const n in vars) { const identifier = vars[n]; if (identifier.getMeta().includes(abaplint.IdentifierMeta.MethodReturning)) { - returning += "return " + n.toLowerCase() + ";\n"; + returning += "return " + Traversal.prefixVariable(n.toLowerCase()) + ";\n"; } } diff --git a/packages/transpiler/src/statements/return.ts b/packages/transpiler/src/statements/return.ts index 96b53df82..ca3a5d12c 100644 --- a/packages/transpiler/src/statements/return.ts +++ b/packages/transpiler/src/statements/return.ts @@ -13,7 +13,7 @@ export class ReturnTranspiler implements IStatementTranspiler { for (const n in vars) { const identifier = vars[n]; if (identifier.getMeta().includes(abaplint.IdentifierMeta.MethodReturning)) { - extra = " " + n.toLowerCase(); + extra = " " + Traversal.prefixVariable(n.toLowerCase()); } } diff --git a/packages/transpiler/src/transpile_types.ts b/packages/transpiler/src/transpile_types.ts index c411b64ab..1c54578e0 100644 --- a/packages/transpiler/src/transpile_types.ts +++ b/packages/transpiler/src/transpile_types.ts @@ -1,4 +1,5 @@ import * as abaplint from "@abaplint/core"; +import {Traversal} from "./traversal"; const featureHexUInt8 = false; @@ -7,7 +8,7 @@ export class TranspileTypes { public declare(t: abaplint.TypedIdentifier): string { const type = t.getType(); - return "let " + t.getName().toLowerCase() + " = " + this.toType(type) + ";"; + return "let " + Traversal.prefixVariable(t.getName().toLowerCase()) + " = " + this.toType(type) + ";"; } public declareStaticSkipVoid(pre: string, t: abaplint.TypedIdentifier): string { diff --git a/test/keywords.ts b/test/keywords.ts index 882c667d4..ef12e78c0 100644 --- a/test/keywords.ts +++ b/test/keywords.ts @@ -52,6 +52,27 @@ START-OF-SELECTION. expect(abap.console.get()).to.equal("2"); }); + it("method parameter, returning", async () => { + const code = ` +CLASS lcl DEFINITION. + PUBLIC SECTION. + CLASS-METHODS foo RETURNING VALUE(class) TYPE i. +ENDCLASS. + +CLASS lcl IMPLEMENTATION. + METHOD foo. + class = 2. + ENDMETHOD. +ENDCLASS. + +START-OF-SELECTION. + lcl=>foo( ).`; + + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + }); + it("form parameter", async () => { const code = ` FORM foo USING class TYPE i.