@abaplint/transpiler 2.12.8 → 2.12.10
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.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValueBodyTranspiler = void 0;
|
|
4
4
|
const core_1 = require("@abaplint/core");
|
|
5
|
+
const traversal_1 = require("../traversal");
|
|
5
6
|
const chunk_1 = require("../chunk");
|
|
6
7
|
const type_name_or_infer_1 = require("./type_name_or_infer");
|
|
7
8
|
const value_body_line_1 = require("./value_body_line");
|
|
@@ -50,51 +51,117 @@ class ValueBodyTranspiler {
|
|
|
50
51
|
ret.appendString(".set(" + source.getCode() + ".clone())");
|
|
51
52
|
}
|
|
52
53
|
else if (child.get() instanceof core_1.Expressions.For && child instanceof core_1.Nodes.ExpressionNode) {
|
|
53
|
-
if (["THEN", "UNTIL", "WHILE", "FROM", "TO", "GROUPS"].some(token => child.findDirectTokenByText(token))) {
|
|
54
|
-
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
55
|
-
}
|
|
56
54
|
const loop = child.findDirectExpression(core_1.Expressions.InlineLoopDefinition);
|
|
57
|
-
if (loop
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let loopWhere = "";
|
|
61
|
-
const whereNode = child?.findDirectExpression(core_1.Expressions.ComponentCond);
|
|
62
|
-
if (whereNode) {
|
|
63
|
-
const where = traversal.traverse(whereNode).getCode();
|
|
64
|
-
loopWhere = `, {"where": async ` + where + `}`;
|
|
65
|
-
}
|
|
66
|
-
const base = loop.findDirectExpression(core_1.Expressions.ValueBase);
|
|
67
|
-
if (base) {
|
|
68
|
-
throw new Error("ValueBody FOR todo, base, " + body.concatTokens());
|
|
69
|
-
}
|
|
70
|
-
let targetDeclare = "";
|
|
71
|
-
let targetAction = "";
|
|
72
|
-
const fs = loop.findDirectExpression(core_1.Expressions.TargetFieldSymbol);
|
|
73
|
-
if (fs) {
|
|
74
|
-
targetDeclare = new statements_1.FieldSymbolTranspiler().transpile(fs, traversal).getCode();
|
|
75
|
-
const targetName = new source_field_symbol_1.SourceFieldSymbolTranspiler().transpile(fs, traversal).getCode();
|
|
76
|
-
targetAction = `${targetName}.assign(unique1);`;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const field = traversal.traverse(loop.findDirectExpression(core_1.Expressions.TargetField));
|
|
80
|
-
if (field === undefined) {
|
|
81
|
-
throw new Error("ValueBody FOR empty field todo, " + body.concatTokens());
|
|
55
|
+
if (loop) {
|
|
56
|
+
if (["THEN", "UNTIL", "WHILE", "FROM", "TO", "GROUPS"].some(token => child.findDirectTokenByText(token))) {
|
|
57
|
+
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
82
58
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
let loopWhere = "";
|
|
60
|
+
const whereNode = child?.findDirectExpression(core_1.Expressions.ComponentCond);
|
|
61
|
+
if (whereNode) {
|
|
62
|
+
const where = traversal.traverse(whereNode).getCode();
|
|
63
|
+
loopWhere = `, {"where": async ` + where + `}`;
|
|
64
|
+
}
|
|
65
|
+
const base = loop.findDirectExpression(core_1.Expressions.ValueBase);
|
|
66
|
+
if (base) {
|
|
67
|
+
throw new Error("ValueBody FOR todo, base, " + body.concatTokens());
|
|
68
|
+
}
|
|
69
|
+
let targetDeclare = "";
|
|
70
|
+
let targetAction = "";
|
|
71
|
+
const fs = loop.findDirectExpression(core_1.Expressions.TargetFieldSymbol);
|
|
72
|
+
if (fs) {
|
|
73
|
+
targetDeclare = new statements_1.FieldSymbolTranspiler().transpile(fs, traversal).getCode();
|
|
74
|
+
const targetName = new source_field_symbol_1.SourceFieldSymbolTranspiler().transpile(fs, traversal).getCode();
|
|
75
|
+
targetAction = `${targetName}.assign(unique1);`;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const field = traversal.traverse(loop.findDirectExpression(core_1.Expressions.TargetField));
|
|
79
|
+
if (field === undefined) {
|
|
80
|
+
throw new Error("ValueBody FOR empty field todo, " + body.concatTokens());
|
|
81
|
+
}
|
|
82
|
+
targetAction = `const ${field.getCode()} = unique1.clone();`;
|
|
83
|
+
}
|
|
84
|
+
const llet = child.findDirectExpression(core_1.Expressions.Let);
|
|
85
|
+
if (llet) {
|
|
86
|
+
targetAction += new let_1.LetTranspiler().transpile(llet, traversal).getCode();
|
|
87
|
+
}
|
|
88
|
+
const source = traversal.traverse(loop.findDirectExpression(core_1.Expressions.Source)).getCode();
|
|
89
|
+
const val = new type_name_or_infer_1.TypeNameOrInfer().transpile(typ, traversal).getCode();
|
|
90
|
+
ret = new chunk_1.Chunk().appendString(`await (async () => {
|
|
92
91
|
${targetDeclare}
|
|
93
92
|
const VAL = ${val};
|
|
94
93
|
for await (const unique1 of abap.statements.loop(${source}${loopWhere})) {
|
|
95
94
|
${targetAction}
|
|
96
95
|
VAL`);
|
|
97
|
-
|
|
96
|
+
post = ";\n}\nreturn VAL;\n})()";
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const counter = child.findDirectExpression(core_1.Expressions.InlineFieldDefinition);
|
|
100
|
+
if (counter === undefined) {
|
|
101
|
+
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
102
|
+
}
|
|
103
|
+
if (["GROUPS", "FROM", "TO"].some(token => child.findDirectTokenByText(token))) {
|
|
104
|
+
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
105
|
+
}
|
|
106
|
+
if (child.findDirectExpression(core_1.Expressions.ComponentCond)) {
|
|
107
|
+
throw new Error("ValueBody FOR todo, component cond, " + body.concatTokens());
|
|
108
|
+
}
|
|
109
|
+
const cond = child.findDirectExpression(core_1.Expressions.Cond);
|
|
110
|
+
if (cond === undefined) {
|
|
111
|
+
throw new Error("ValueBody FOR missing condition, " + body.concatTokens());
|
|
112
|
+
}
|
|
113
|
+
const hasUntil = child.findDirectTokenByText("UNTIL") !== undefined;
|
|
114
|
+
const hasWhile = child.findDirectTokenByText("WHILE") !== undefined;
|
|
115
|
+
if ((hasUntil ? 1 : 0) + (hasWhile ? 1 : 0) !== 1) {
|
|
116
|
+
throw new Error("ValueBody FOR todo, condition, " + body.concatTokens());
|
|
117
|
+
}
|
|
118
|
+
const fieldExpr = counter.findDirectExpression(core_1.Expressions.Field);
|
|
119
|
+
const fieldName = fieldExpr?.concatTokens().toLowerCase();
|
|
120
|
+
if (fieldName === undefined) {
|
|
121
|
+
throw new Error("ValueBody FOR todo, inline field, " + body.concatTokens());
|
|
122
|
+
}
|
|
123
|
+
const scope = traversal.findCurrentScopeByToken(counter.getFirstToken());
|
|
124
|
+
const variable = scope?.findVariable(fieldName);
|
|
125
|
+
if (variable === undefined) {
|
|
126
|
+
throw new Error("ValueBody FOR todo, variable, " + body.concatTokens());
|
|
127
|
+
}
|
|
128
|
+
const declare = transpile_types_1.TranspileTypes.declare(variable);
|
|
129
|
+
const counterName = traversal_1.Traversal.prefixVariable(fieldName);
|
|
130
|
+
const startSource = counter.findDirectExpression(core_1.Expressions.Source);
|
|
131
|
+
if (startSource === undefined) {
|
|
132
|
+
throw new Error("ValueBody FOR missing initial value, " + body.concatTokens());
|
|
133
|
+
}
|
|
134
|
+
const start = traversal.traverse(startSource).getCode();
|
|
135
|
+
const thenExpr = child.findExpressionAfterToken("THEN");
|
|
136
|
+
let incrementExpression = "";
|
|
137
|
+
if (thenExpr && thenExpr instanceof core_1.Nodes.ExpressionNode) {
|
|
138
|
+
incrementExpression = traversal.traverse(thenExpr).getCode();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
incrementExpression = `abap.operators.add(${counterName}, new abap.types.Integer().set(1))`;
|
|
142
|
+
}
|
|
143
|
+
const incrementLine = `${counterName}.set(${incrementExpression});`;
|
|
144
|
+
const llet = child.findDirectExpression(core_1.Expressions.Let);
|
|
145
|
+
let letCode = "";
|
|
146
|
+
if (llet) {
|
|
147
|
+
letCode = new let_1.LetTranspiler().transpile(llet, traversal).getCode();
|
|
148
|
+
}
|
|
149
|
+
const letSection = letCode === "" ? "" : " " + letCode.replace(/\n/g, "\n ") + "\n";
|
|
150
|
+
const condCode = traversal.traverse(cond).getCode();
|
|
151
|
+
const val = new type_name_or_infer_1.TypeNameOrInfer().transpile(typ, traversal).getCode();
|
|
152
|
+
const preCheck = hasWhile ? ` if (!(${condCode})) {\n break;\n }\n` : "";
|
|
153
|
+
let postLoop = ` ${incrementLine}\n`;
|
|
154
|
+
if (hasUntil) {
|
|
155
|
+
postLoop += ` if (${condCode}) {\n break;\n }\n`;
|
|
156
|
+
}
|
|
157
|
+
ret = new chunk_1.Chunk().appendString(`await (async () => {
|
|
158
|
+
${declare}
|
|
159
|
+
${counterName}.set(${start});
|
|
160
|
+
const VAL = ${val};
|
|
161
|
+
while (true) {
|
|
162
|
+
${preCheck}${letSection} VAL`);
|
|
163
|
+
post = ";\n" + postLoop + "}\nreturn VAL;\n})()";
|
|
164
|
+
}
|
|
98
165
|
}
|
|
99
166
|
else if (child instanceof core_1.Nodes.TokenNode && child.getFirstToken().getStr().toUpperCase() === "DEFAULT") {
|
|
100
167
|
// note: this is last in the body, so its okay to prepend and postpend
|
package/build/src/index.js
CHANGED
|
@@ -51,7 +51,7 @@ class Transpiler {
|
|
|
51
51
|
databaseSetup: dbSetup,
|
|
52
52
|
reg: reg,
|
|
53
53
|
};
|
|
54
|
-
progress?.set(reg.getObjectCount(
|
|
54
|
+
progress?.set(reg.getObjectCount().total, "Building");
|
|
55
55
|
for (const obj of reg.getObjects()) {
|
|
56
56
|
await progress?.tick("Building, " + obj.getName());
|
|
57
57
|
if (obj instanceof abaplint.Objects.TypePool) {
|
package/build/src/rearranger.js
CHANGED
|
@@ -101,6 +101,10 @@ class Rearranger {
|
|
|
101
101
|
|| !(secondLast.get() instanceof core_1.Expressions.ArithOperator)) {
|
|
102
102
|
return node;
|
|
103
103
|
}
|
|
104
|
+
const nestedArith = last.findDirectExpressions(core_1.Expressions.ArithOperator);
|
|
105
|
+
if (nestedArith.length === 0) {
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
104
108
|
const withoutLast = node.getChildren().slice(0, children.length - 1);
|
|
105
109
|
const flat = withoutLast.concat(last.getChildren());
|
|
106
110
|
node.setChildren(flat);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.10",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"author": "abaplint",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@abaplint/core": "^2.113.
|
|
32
|
+
"@abaplint/core": "^2.113.240",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/chai": "^4.3.20",
|
|
37
37
|
"@types/mocha": "^10.0.10",
|
|
38
38
|
"chai": "^4.5.0",
|
|
39
|
-
"mocha": "^11.7.
|
|
39
|
+
"mocha": "^11.7.5",
|
|
40
40
|
"source-map-support": "^0.5.21",
|
|
41
41
|
"typescript": "^5.9.3"
|
|
42
42
|
}
|