@abaplint/transpiler 2.13.72 → 2.13.74
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.
|
@@ -15,7 +15,11 @@ class FieldLengthTranspiler {
|
|
|
15
15
|
}
|
|
16
16
|
else if (c instanceof core_1.Nodes.TokenNode) {
|
|
17
17
|
if (c.get() instanceof core_1.Tokens.Identifier) {
|
|
18
|
-
|
|
18
|
+
let value = c.getFirstToken().getStr();
|
|
19
|
+
if (/^0+\d+$/.test(value)) {
|
|
20
|
+
value = value.replace(/^0+/, "") || "0";
|
|
21
|
+
}
|
|
22
|
+
ret += value;
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -15,7 +15,11 @@ class FieldOffsetTranspiler {
|
|
|
15
15
|
}
|
|
16
16
|
else if (c instanceof core_1.Nodes.TokenNode) {
|
|
17
17
|
if (c.get() instanceof core_1.Tokens.Identifier) {
|
|
18
|
-
|
|
18
|
+
let value = c.getFirstToken().getStr().toLowerCase();
|
|
19
|
+
if (/^0+\d+$/.test(value)) {
|
|
20
|
+
value = value.replace(/^0+/, "") || "0";
|
|
21
|
+
}
|
|
22
|
+
ret += value;
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -6,9 +6,11 @@ export declare class LoopTranspiler implements IStatementTranspiler {
|
|
|
6
6
|
private unique;
|
|
7
7
|
private readonly injectFrom;
|
|
8
8
|
private readonly skipInto;
|
|
9
|
+
private readonly atLast;
|
|
9
10
|
constructor(options?: {
|
|
10
11
|
injectFrom?: string;
|
|
11
12
|
skipInto?: boolean;
|
|
13
|
+
atLast?: string;
|
|
12
14
|
});
|
|
13
15
|
getTarget(): string;
|
|
14
16
|
private determineInto;
|
|
@@ -42,9 +42,11 @@ class LoopTranspiler {
|
|
|
42
42
|
unique = "";
|
|
43
43
|
injectFrom = undefined;
|
|
44
44
|
skipInto = undefined;
|
|
45
|
+
atLast = undefined;
|
|
45
46
|
constructor(options) {
|
|
46
47
|
this.injectFrom = options?.injectFrom;
|
|
47
48
|
this.skipInto = options?.skipInto;
|
|
49
|
+
this.atLast = options?.atLast;
|
|
48
50
|
}
|
|
49
51
|
getTarget() {
|
|
50
52
|
return this.unique;
|
|
@@ -142,6 +144,9 @@ class LoopTranspiler {
|
|
|
142
144
|
}
|
|
143
145
|
extra.push(`dynamicWhere: {condition: ${code}, evaluate: (name) => {try { return eval(name);} catch {}}}`);
|
|
144
146
|
}
|
|
147
|
+
if (this.atLast !== undefined) {
|
|
148
|
+
extra.push(`atLast: (last) => { ${this.atLast} = last; }`);
|
|
149
|
+
}
|
|
145
150
|
const topEquals = {};
|
|
146
151
|
for (const compare of whereNode?.findDirectExpressions(abaplint.Expressions.ComponentCompare) || []) {
|
|
147
152
|
const op = compare.findDirectExpression(abaplint.Expressions.CompareOperator)?.concatTokens().toUpperCase();
|
|
@@ -41,12 +41,14 @@ const at_last_1 = require("./at_last");
|
|
|
41
41
|
const unique_identifier_1 = require("../unique_identifier");
|
|
42
42
|
const statements_1 = require("../statements");
|
|
43
43
|
const at_1 = require("./at");
|
|
44
|
+
const inline_1 = require("../inline");
|
|
44
45
|
class LoopTranspiler {
|
|
45
46
|
transpile(node, traversal) {
|
|
46
47
|
const ret = new chunk_1.Chunk();
|
|
47
48
|
let pre = "";
|
|
48
49
|
let atFirst = undefined;
|
|
49
50
|
let atLast = undefined;
|
|
51
|
+
let atLastFlag = "";
|
|
50
52
|
let loopStatement = undefined;
|
|
51
53
|
let previous = "";
|
|
52
54
|
let tabix = "";
|
|
@@ -58,6 +60,18 @@ class LoopTranspiler {
|
|
|
58
60
|
break;
|
|
59
61
|
}
|
|
60
62
|
}
|
|
63
|
+
const hasAtLast = (node.findDirectStructure(abaplint.Structures.Body)
|
|
64
|
+
?.findDirectStructures(abaplint.Structures.Normal) || [])
|
|
65
|
+
.some(n => n.findDirectStructure(abaplint.Structures.AtLast) !== undefined);
|
|
66
|
+
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
67
|
+
if (scope?.getIdentifier().stype === abaplint.ScopeType.Program
|
|
68
|
+
|| scope?.getIdentifier().stype === abaplint.ScopeType.SelectionEvent) {
|
|
69
|
+
ret.appendString(inline_1.InlineDeclarations.buildDeclarations(node, traversal));
|
|
70
|
+
}
|
|
71
|
+
if (hasAtLast) {
|
|
72
|
+
atLastFlag = unique_identifier_1.UniqueIdentifier.get();
|
|
73
|
+
ret.appendString(`let ${atLastFlag} = false;\n`);
|
|
74
|
+
}
|
|
61
75
|
if (node.findDirectStatement(abaplint.Statements.Loop)?.findDirectTokenByText("GROUP") !== undefined) {
|
|
62
76
|
return new chunk_1.Chunk(`throw new Error("transpiler todo, GROUP BY");`);
|
|
63
77
|
}
|
|
@@ -76,6 +90,9 @@ class LoopTranspiler {
|
|
|
76
90
|
}
|
|
77
91
|
else if (n instanceof abaplint.Nodes.StructureNode && n.get() instanceof abaplint.Structures.AtLast) {
|
|
78
92
|
atLast = new at_last_1.AtLastTranspiler().transpile(n, traversal);
|
|
93
|
+
ret.appendString(`if (${atLastFlag}) {\n`);
|
|
94
|
+
ret.appendChunk(atLast);
|
|
95
|
+
ret.appendString("}\n");
|
|
79
96
|
}
|
|
80
97
|
else if (n instanceof abaplint.Nodes.StructureNode && n.get() instanceof abaplint.Structures.At) {
|
|
81
98
|
ret.appendChunk(new at_1.AtTranspiler().transpile(n, traversal, previous, loopTarget, tabix, loopStatement));
|
|
@@ -93,7 +110,7 @@ class LoopTranspiler {
|
|
|
93
110
|
ret.appendString(`let ${previous} = undefined;\n`);
|
|
94
111
|
ret.appendString(`let ${tabix} = undefined;\n`);
|
|
95
112
|
}
|
|
96
|
-
const loop = new statements_1.LoopTranspiler();
|
|
113
|
+
const loop = new statements_1.LoopTranspiler({ atLast: atLastFlag || undefined });
|
|
97
114
|
// LoopStatementTranspiler maps its own head, so no ensureStartMapping needed here
|
|
98
115
|
ret.appendChunk(loop.transpile(c, traversal));
|
|
99
116
|
ret.appendString("\n");
|
|
@@ -118,11 +135,6 @@ class LoopTranspiler {
|
|
|
118
135
|
atted.appendString(pre);
|
|
119
136
|
}
|
|
120
137
|
atted.appendChunk(ret);
|
|
121
|
-
if (atLast) {
|
|
122
|
-
atted.appendString("if (abap.builtin.sy.get().subrc.get() === 0) {\n");
|
|
123
|
-
atted.appendChunk(atLast);
|
|
124
|
-
atted.appendString("}\n");
|
|
125
|
-
}
|
|
126
138
|
return atted;
|
|
127
139
|
}
|
|
128
140
|
}
|