Skip to content

Commit

Permalink
2.10.4: bugfix DELETE itab (#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp authored Jul 8, 2024
1 parent 77a6ff2 commit 91b1ecb
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 22 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.3",
"version": "2.10.4",
"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.3",
"@abaplint/transpiler": "^2.10.4",
"@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.3",
"version": "2.10.4",
"description": "Transpiler - Runtime",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
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.3",
"version": "2.10.4",
"description": "Transpiler",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down
17 changes: 12 additions & 5 deletions packages/transpiler/src/statements/delete_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ import {Chunk} from "../chunk";
export class DeleteInternalTranspiler implements IStatementTranspiler {

public transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk {
const target = traversal.traverse(node.findFirstExpression(abaplint.Expressions.Target)).getCode();
const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode();
const concat = node.concatTokens().toUpperCase();

const extra: string[] = [];
const where = node.findFirstExpression(abaplint.Expressions.ComponentCond);
if (where) {

const componentCond = node.findDirectExpression(abaplint.Expressions.ComponentCond);
if (componentCond) {
// todo, replacing "await" is a hack
extra.push("where: " + traversal.traverse(where).getCode().replace("await ", ""));
extra.push("where: " + traversal.traverse(componentCond).getCode().replace("await ", ""));
}

const componentCompare = node.findDirectExpression(abaplint.Expressions.ComponentCompare);
if (componentCompare) {
// todo: this can be optimized, WITH TABLE KEY
extra.push("where: " + traversal.traverse(componentCompare).getCode());
}

// todo, this is not completely correct, fields might have the name ADJACENT
// comparisons should be on table key unless other is specified, but we're unaware
if (node.findDirectTokenByText("ADJACENT")) {
extra.push("adjacent: true");
if (node.findDirectTokenByText("COMPARING") && !node.concatTokens().toUpperCase().includes("COMPARING ALL FIELDS")) {
if (node.findDirectTokenByText("COMPARING") && !concat.includes("COMPARING ALL FIELDS")) {
const comparing = node.findAllExpressions(abaplint.Expressions.FieldSub);
if (comparing) {
const compareFields = comparing.map(i => "'" + i.getFirstToken().getStr() + "'").join(",");
Expand Down
28 changes: 28 additions & 0 deletions test/statements/delete_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,32 @@ ENDLOOP.`;
expect(abap.console.get()).to.equal("6\n3\n10");
});

it("DELETE, with table key", async () => {
const code = `
TYPES: BEGIN OF ty,
foobar TYPE i,
END OF ty.
TYPES ty_tt TYPE HASHED TABLE OF ty WITH UNIQUE KEY foobar.
DATA itab TYPE ty_tt.
DATA row LIKE LINE OF itab.
row-foobar = 1.
INSERT row INTO TABLE itab.
row-foobar = 2.
INSERT row INTO TABLE itab.
row-foobar = 3.
INSERT row INTO TABLE itab.
DELETE TABLE itab WITH TABLE KEY foobar = 2.
LOOP AT itab INTO row.
WRITE / row-foobar.
ENDLOOP.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
expect(abap.console.get()).to.equal("1\n3");
});

});

0 comments on commit 91b1ecb

Please sign in to comment.