@abaplint/transpiler 2.5.19 → 2.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,5 +3,13 @@ import { IStatementTranspiler } from "./_statement_transpiler";
|
|
|
3
3
|
import { Traversal } from "../traversal";
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class LoopTranspiler implements IStatementTranspiler {
|
|
6
|
+
private unique;
|
|
7
|
+
private readonly injectFrom;
|
|
8
|
+
private readonly skipInto;
|
|
9
|
+
constructor(options?: {
|
|
10
|
+
injectFrom?: string;
|
|
11
|
+
skipInto?: boolean;
|
|
12
|
+
});
|
|
13
|
+
getTarget(): string;
|
|
6
14
|
transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
|
|
7
15
|
}
|
|
@@ -6,36 +6,46 @@ const unique_identifier_1 = require("../unique_identifier");
|
|
|
6
6
|
const expressions_1 = require("../expressions");
|
|
7
7
|
const chunk_1 = require("../chunk");
|
|
8
8
|
class LoopTranspiler {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.unique = "";
|
|
11
|
+
this.injectFrom = undefined;
|
|
12
|
+
this.skipInto = undefined;
|
|
13
|
+
this.injectFrom = options === null || options === void 0 ? void 0 : options.injectFrom;
|
|
14
|
+
this.skipInto = options === null || options === void 0 ? void 0 : options.skipInto;
|
|
15
|
+
}
|
|
16
|
+
getTarget() {
|
|
17
|
+
return this.unique;
|
|
18
|
+
}
|
|
9
19
|
transpile(node, traversal) {
|
|
10
20
|
var _a, _b, _c;
|
|
11
21
|
if (!(node.get() instanceof abaplint.Statements.Loop)) {
|
|
12
22
|
throw new Error("LoopTranspiler, unexpected node");
|
|
13
23
|
}
|
|
14
24
|
const source = traversal.traverse(node.findDirectExpression(abaplint.Expressions.SimpleSource2)).getCode();
|
|
15
|
-
|
|
25
|
+
this.unique = unique_identifier_1.UniqueIdentifier.get();
|
|
16
26
|
let target = "";
|
|
17
27
|
const into = (_a = node.findDirectExpression(abaplint.Expressions.LoopTarget)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(abaplint.Expressions.Target);
|
|
18
|
-
if (into) {
|
|
28
|
+
if (into && this.skipInto !== true) {
|
|
19
29
|
const concat = node.concatTokens().toUpperCase();
|
|
20
30
|
const t = traversal.traverse(into).getCode();
|
|
21
31
|
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
22
32
|
const typ = traversal.determineType(node, scope);
|
|
23
33
|
if (concat.includes(" REFERENCE INTO ")) {
|
|
24
34
|
// target is assumed to be a data reference
|
|
25
|
-
target = t + ".assign(" +
|
|
35
|
+
target = t + ".assign(" + this.unique + ");";
|
|
26
36
|
}
|
|
27
37
|
else if (typ instanceof abaplint.BasicTypes.DataReference) {
|
|
28
38
|
// row type and target is assumed to be data references
|
|
29
|
-
target = t + ".assign(" +
|
|
39
|
+
target = t + ".assign(" + this.unique + ".getPointer());";
|
|
30
40
|
}
|
|
31
41
|
else {
|
|
32
|
-
target = t + ".set(" +
|
|
42
|
+
target = t + ".set(" + this.unique + ");";
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
|
-
else {
|
|
45
|
+
else if (this.skipInto !== true) {
|
|
36
46
|
const assigning = (_b = node.findFirstExpression(abaplint.Expressions.FSTarget)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldSymbol);
|
|
37
47
|
if (assigning) {
|
|
38
|
-
target = traversal.traverse(assigning).getCode() + ".assign(" +
|
|
48
|
+
target = traversal.traverse(assigning).getCode() + ".assign(" + this.unique + ");";
|
|
39
49
|
}
|
|
40
50
|
}
|
|
41
51
|
const extra = [];
|
|
@@ -44,6 +54,9 @@ class LoopTranspiler {
|
|
|
44
54
|
const from = new expressions_1.SourceTranspiler().transpile(fromNode, traversal).getCode();
|
|
45
55
|
extra.push("from: " + from);
|
|
46
56
|
}
|
|
57
|
+
else if (this.injectFrom) {
|
|
58
|
+
extra.push("from: " + this.injectFrom);
|
|
59
|
+
}
|
|
47
60
|
const toNode = node.findExpressionAfterToken("TO");
|
|
48
61
|
if (toNode) {
|
|
49
62
|
const to = new expressions_1.SourceTranspiler().transpile(toNode, traversal).getCode();
|
|
@@ -96,7 +109,7 @@ class LoopTranspiler {
|
|
|
96
109
|
if (extra.length > 0) {
|
|
97
110
|
concat = ",{" + extra.join(",") + "}";
|
|
98
111
|
}
|
|
99
|
-
return new chunk_1.Chunk(`for await (const ${
|
|
112
|
+
return new chunk_1.Chunk(`for await (const ${this.unique} of abap.statements.loop(${source}${concat})) {\n${target}`);
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
exports.LoopTranspiler = LoopTranspiler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as abaplint from "@abaplint/core";
|
|
2
|
+
import { IStructureTranspiler } from "./_structure_transpiler";
|
|
3
|
+
import { Traversal } from "../traversal";
|
|
4
|
+
import { Chunk } from "../chunk";
|
|
5
|
+
export declare class AtTranspiler implements IStructureTranspiler {
|
|
6
|
+
transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal, previous?: string, loopTarget?: string, tabix?: string, loopStatement?: abaplint.Nodes.StatementNode): Chunk;
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AtTranspiler = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
const chunk_1 = require("../chunk");
|
|
6
|
+
const statements_1 = require("../statements");
|
|
7
|
+
const unique_identifier_1 = require("../unique_identifier");
|
|
8
|
+
class AtTranspiler {
|
|
9
|
+
transpile(node, traversal, previous, loopTarget, tabix, loopStatement) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const ret = new chunk_1.Chunk();
|
|
12
|
+
const atStatement = node.findDirectStatement(abaplint.Statements.At);
|
|
13
|
+
const concat = atStatement === null || atStatement === void 0 ? void 0 : atStatement.concatTokens().toUpperCase();
|
|
14
|
+
const name = (_b = (_a = atStatement === null || atStatement === void 0 ? void 0 : atStatement.findDirectExpression(abaplint.Expressions.FieldSub)) === null || _a === void 0 ? void 0 : _a.concatTokens()) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
15
|
+
let suffix = `.get().${name}`;
|
|
16
|
+
if (name === "table_line") {
|
|
17
|
+
suffix = "";
|
|
18
|
+
}
|
|
19
|
+
if (concat === null || concat === void 0 ? void 0 : concat.startsWith("AT NEW ")) {
|
|
20
|
+
// eslint-disable-next-line max-len
|
|
21
|
+
ret.appendString(`if (${previous} === undefined || abap.compare.eq(${previous}${suffix}, ${loopTarget}${suffix}) === false) {\n`);
|
|
22
|
+
const body = node.findDirectStructure(abaplint.Structures.Body);
|
|
23
|
+
if (body) {
|
|
24
|
+
ret.appendChunk(traversal.traverse(body));
|
|
25
|
+
}
|
|
26
|
+
ret.appendString("}\n");
|
|
27
|
+
}
|
|
28
|
+
else if (concat === null || concat === void 0 ? void 0 : concat.startsWith("AT END OF ")) {
|
|
29
|
+
const next = unique_identifier_1.UniqueIdentifier.get();
|
|
30
|
+
ret.appendString(`let ${next} = undefined;\n`);
|
|
31
|
+
const loop = new statements_1.LoopTranspiler({ injectFrom: tabix, skipInto: true });
|
|
32
|
+
ret.appendChunk(loop.transpile(loopStatement, traversal));
|
|
33
|
+
ret.appendString(`${next} = ${loop.getTarget()};\n`);
|
|
34
|
+
ret.appendString(`break;\n`);
|
|
35
|
+
ret.appendString(`}\n`);
|
|
36
|
+
// eslint-disable-next-line max-len
|
|
37
|
+
ret.appendString(`if (${next} === undefined || abap.compare.eq(${next}${suffix}, ${loopTarget}${suffix}) === false) {\n`);
|
|
38
|
+
const body = node.findDirectStructure(abaplint.Structures.Body);
|
|
39
|
+
if (body) {
|
|
40
|
+
ret.appendChunk(traversal.traverse(body));
|
|
41
|
+
}
|
|
42
|
+
ret.appendString("}\n");
|
|
43
|
+
}
|
|
44
|
+
return ret;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.AtTranspiler = AtTranspiler;
|
|
48
|
+
//# sourceMappingURL=at.js.map
|
|
@@ -6,12 +6,26 @@ const chunk_1 = require("../chunk");
|
|
|
6
6
|
const at_first_1 = require("./at_first");
|
|
7
7
|
const at_last_1 = require("./at_last");
|
|
8
8
|
const unique_identifier_1 = require("../unique_identifier");
|
|
9
|
+
const statements_1 = require("../statements");
|
|
10
|
+
const at_1 = require("./at");
|
|
9
11
|
class LoopTranspiler {
|
|
10
12
|
transpile(node, traversal) {
|
|
13
|
+
var _a;
|
|
11
14
|
const ret = new chunk_1.Chunk();
|
|
12
15
|
let pre = "";
|
|
13
16
|
let atFirst = undefined;
|
|
14
17
|
let atLast = undefined;
|
|
18
|
+
let loopStatement = undefined;
|
|
19
|
+
let previous = "";
|
|
20
|
+
let tabix = "";
|
|
21
|
+
let loopTarget = "";
|
|
22
|
+
let hasAt = false;
|
|
23
|
+
for (const n of ((_a = node.findDirectStructure(abaplint.Structures.Body)) === null || _a === void 0 ? void 0 : _a.findDirectStructures(abaplint.Structures.Normal)) || []) {
|
|
24
|
+
if (n.findDirectStructure(abaplint.Structures.At) !== undefined) {
|
|
25
|
+
hasAt = true;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
15
29
|
for (const c of node.getChildren()) {
|
|
16
30
|
if (c instanceof abaplint.Nodes.StructureNode && c.get() instanceof abaplint.Structures.Body) {
|
|
17
31
|
for (const b of c.getChildren()) {
|
|
@@ -28,12 +42,37 @@ class LoopTranspiler {
|
|
|
28
42
|
else if (n instanceof abaplint.Nodes.StructureNode && n.get() instanceof abaplint.Structures.AtLast) {
|
|
29
43
|
atLast = new at_last_1.AtLastTranspiler().transpile(n, traversal);
|
|
30
44
|
}
|
|
45
|
+
else if (n instanceof abaplint.Nodes.StructureNode && n.get() instanceof abaplint.Structures.At) {
|
|
46
|
+
ret.appendChunk(new at_1.AtTranspiler().transpile(n, traversal, previous, loopTarget, tabix, loopStatement));
|
|
47
|
+
}
|
|
31
48
|
else {
|
|
32
49
|
ret.appendChunk(traversal.traverse(n));
|
|
33
50
|
}
|
|
34
51
|
}
|
|
35
52
|
}
|
|
36
53
|
}
|
|
54
|
+
else if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.Loop) {
|
|
55
|
+
if (hasAt === true) {
|
|
56
|
+
previous = unique_identifier_1.UniqueIdentifier.get();
|
|
57
|
+
tabix = unique_identifier_1.UniqueIdentifier.get();
|
|
58
|
+
ret.appendString(`let ${previous} = undefined;\n`);
|
|
59
|
+
ret.appendString(`let ${tabix} = undefined;\n`);
|
|
60
|
+
}
|
|
61
|
+
const loop = new statements_1.LoopTranspiler();
|
|
62
|
+
ret.appendChunk(loop.transpile(c, traversal));
|
|
63
|
+
ret.appendString("\n");
|
|
64
|
+
if (hasAt === true) {
|
|
65
|
+
ret.appendString(tabix + " = new abap.types.Integer().set(abap.builtin.sy.get().tabix.get() + 1);\n");
|
|
66
|
+
}
|
|
67
|
+
loopTarget = loop.getTarget();
|
|
68
|
+
loopStatement = c;
|
|
69
|
+
}
|
|
70
|
+
else if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.EndLoop) {
|
|
71
|
+
if (hasAt === true) {
|
|
72
|
+
ret.appendString(`${previous} = ${loopTarget};\n`);
|
|
73
|
+
}
|
|
74
|
+
ret.appendChunk(traversal.traverse(c));
|
|
75
|
+
}
|
|
37
76
|
else {
|
|
38
77
|
ret.appendChunk(traversal.traverse(c));
|
|
39
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.21",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"author": "abaplint",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@abaplint/core": "^2.95.
|
|
31
|
+
"@abaplint/core": "^2.95.32",
|
|
32
32
|
"source-map": "^0.7.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|