Skip to content

Commit

Permalink
fix RETURN
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Sep 5, 2024
1 parent ed445de commit 1865e70
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/transpiler/src/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/transpiler/src/statements/end_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/transpiler/src/statements/return.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/transpiler/src/transpile_types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as abaplint from "@abaplint/core";
import {Traversal} from "./traversal";

const featureHexUInt8 = false;

Expand All @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions test/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1865e70

Please sign in to comment.