diff --git a/packages/transpiler/src/statements/enhancement_point.ts b/packages/transpiler/src/statements/enhancement_point.ts new file mode 100644 index 000000000..37d957d39 --- /dev/null +++ b/packages/transpiler/src/statements/enhancement_point.ts @@ -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("', '") }'`); + } + +} \ No newline at end of file diff --git a/packages/transpiler/src/statements/index.ts b/packages/transpiler/src/statements/index.ts index 7d4b9922f..9bf0e41cc 100644 --- a/packages/transpiler/src/statements/index.ts +++ b/packages/transpiler/src/statements/index.ts @@ -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"; diff --git a/test/statements/enhancement_point.ts b/test/statements/enhancement_point.ts new file mode 100644 index 000000000..437cc79c0 --- /dev/null +++ b/test/statements/enhancement_point.ts @@ -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"); + }); + +}); \ No newline at end of file