Skip to content

Commit

Permalink
2.10.3: bugfix DELETE short form (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp authored Jul 8, 2024
1 parent 956eb81 commit 77a6ff2
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 23 deletions.
18 changes: 9 additions & 9 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abaplint/transpiler-cli",
"version": "2.10.2",
"version": "2.10.3",
"description": "Transpiler - Command Line Interface",
"funding": "https://github.com/sponsors/larshp",
"bin": {
Expand All @@ -26,7 +26,7 @@
"author": "abaplint",
"license": "MIT",
"devDependencies": {
"@abaplint/transpiler": "^2.10.2",
"@abaplint/transpiler": "^2.10.3",
"@types/glob": "^8.1.0",
"glob": "=7.2.0",
"@types/progress": "^2.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abaplint/runtime",
"version": "2.10.2",
"version": "2.10.3",
"description": "Transpiler - Runtime",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down
11 changes: 5 additions & 6 deletions packages/runtime/src/statements/delete_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ export async function deleteInternal(target: Table | HashedTable | FieldSymbol,
return;
}

// @ts-ignore
const originalTabix = abap.builtin.sy.get().tabix.get();
// short form, "DELETE tab"
if (options === undefined) {
target.deleteIndex((target as Table).getCurrentLoopIndex());
return;
}

for await (const i of loop(target)) {
// @ts-ignore
Expand All @@ -109,10 +112,6 @@ export async function deleteInternal(target: Table | HashedTable | FieldSymbol,
target.deleteIndex(index);
} else if (options?.from && options.from.get() <= index + 1) {
target.deleteIndex(index);
} else if (options === undefined && originalTabix === index + 1) {
// short form, "DELETE tab"
target.deleteIndex(index);
break;
}
}
}
8 changes: 8 additions & 0 deletions packages/runtime/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ export class Table implements ITable {
return l;
}

public getCurrentLoopIndex() {
if (this.loops.size !== 1) {
throw new Error("More than one LOOP");
}

return Array.from(this.loops)[0].index;
}

public unregisterLoop(loop: LoopController) {
this.loops.delete(loop);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/transpiler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/transpiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abaplint/transpiler",
"version": "2.10.2",
"version": "2.10.3",
"description": "Transpiler",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down
32 changes: 32 additions & 0 deletions test/statements/delete_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,38 @@ LOOP AT tab TRANSPORTING NO FIELDS WHERE field <= 5.
EXIT.
ENDLOOP.
LOOP AT tab INTO row.
WRITE / row-field.
ENDLOOP.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
expect(abap.console.get()).to.equal("6\n3\n10");
});

it("DELETE, messing with sy-tabix", async () => {
const code = `
TYPES: BEGIN OF ty,
field TYPE i,
END OF ty.
DATA tab TYPE STANDARD TABLE OF ty WITH DEFAULT KEY.
DATA row LIKE LINE OF tab.
row-field = 6.
INSERT row INTO TABLE tab.
row-field = 3.
INSERT row INTO TABLE tab.
row-field = 3.
INSERT row INTO TABLE tab.
row-field = 10.
INSERT row INTO TABLE tab.
LOOP AT tab TRANSPORTING NO FIELDS WHERE field <= 5.
sy-tabix = 1.
DELETE tab.
EXIT.
ENDLOOP.
LOOP AT tab INTO row.
WRITE / row-field.
ENDLOOP.`;
Expand Down

0 comments on commit 77a6ff2

Please sign in to comment.