Skip to content

Commit

Permalink
implement dummy enhancement point
Browse files Browse the repository at this point in the history
  • Loading branch information
joltdx committed Sep 7, 2024
1 parent bfbc3eb commit 5ccb921
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/transpiler/src/statements/enhancement_point.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as abaplint from "@abaplint/core";
import {IStatementTranspiler} from "./_statement_transpiler";
import {Traversal} from "../traversal";
import {Chunk} from "../chunk";

export class EnhancementPointTranspiler implements IStatementTranspiler {

public transpile(_node: abaplint.Nodes.StatementNode, _traversal: Traversal): Chunk {
// for now, do nothing, but leave a comment

// ENHANCEMENT-POINT enh_id SPOTS spot1 spot2 ... [STATIC] [INCLUDE BOUND].
let enhId: string = "";
const spots: string[] = [];
for (const tn of _node.getTokenNodes()) {
if (tn instanceof abaplint.Nodes.TokenNodeRegex) {
if (!enhId) {
enhId = tn.get().getStr();
} else {
spots.push(tn.get().getStr());
}
}
}

// [Transpiler] EnhancementPoint not implemented. Ignoring 'enh_id' spots 'spot1', 'spot2' ...
return new Chunk(`// [Transpiler] EnhancementPoint not implemented. Ignoring '${enhId}' spots '${ spots.join("', '") }'`);
}

}
1 change: 1 addition & 0 deletions packages/transpiler/src/statements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export * from "./end_loop";
export * from "./end_method";
export * from "./end_try";
export * from "./end_while";
export * from "./enhancement_point";
export * from "./enhancement_section";
export * from "./exit";
export * from "./export";
Expand Down
28 changes: 28 additions & 0 deletions test/statements/enhancement_point.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {expect} from "chai";
import {ABAP, MemoryConsole} from "../../packages/runtime/src";
import {AsyncFunction, runFiles} from "../_utils";

let abap: ABAP;

async function run(contents: string) {
return runFiles(abap, [{filename: "zfoobar.prog.abap", contents}]);
}

describe("Running statements - ENHANCEMENT POINT", () => {

beforeEach(async () => {
abap = new ABAP({console: new MemoryConsole()});
});

it("enhancement point", async () => {
const code = `
WRITE 'hello'.
ENHANCEMENT-POINT foo SPOTS bar.
WRITE 'hi'.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
expect(abap.console.get()).to.equal("hellohi");
});

});

0 comments on commit 5ccb921

Please sign in to comment.