@abaplint/transpiler 2.11.74 → 2.11.76
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.
- package/build/src/expressions/reduce_body.d.ts +6 -0
- package/build/src/expressions/reduce_body.js +71 -0
- package/build/src/expressions/source.d.ts +1 -1
- package/build/src/expressions/source.js +18 -3
- package/build/src/expressions/sql_cond.js +1 -1
- package/build/src/expressions/sql_field.js +8 -0
- package/build/src/expressions/sql_field_list.js +4 -0
- package/build/src/expressions/value_body.js +8 -2
- package/package.json +2 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReduceBodyTranspiler = void 0;
|
|
4
|
+
const core_1 = require("@abaplint/core");
|
|
5
|
+
const chunk_1 = require("../chunk");
|
|
6
|
+
const transpile_types_1 = require("../transpile_types");
|
|
7
|
+
const target_1 = require("./target");
|
|
8
|
+
class ReduceBodyTranspiler {
|
|
9
|
+
transpile(typ, body, traversal) {
|
|
10
|
+
if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
|
|
11
|
+
throw new Error("ReduceBodyTranspiler, Expected TypeNameOrInfer");
|
|
12
|
+
}
|
|
13
|
+
else if (body.findDirectExpression(core_1.Expressions.Let) !== undefined) {
|
|
14
|
+
return new chunk_1.Chunk(`(() => { throw new Error("ReduceBodyTranspiler LET, not supported, transpiler"); })()`);
|
|
15
|
+
}
|
|
16
|
+
const forExpressions = body.findDirectExpressions(core_1.Expressions.For);
|
|
17
|
+
const forExpression = forExpressions[0];
|
|
18
|
+
if (forExpressions.length === 0) {
|
|
19
|
+
throw new Error("ReduceBodyTranspiler, expected FOR");
|
|
20
|
+
}
|
|
21
|
+
else if (forExpressions.length > 1) {
|
|
22
|
+
throw new Error("ReduceBodyTranspiler, multiple FOR not supported, " + body.concatTokens());
|
|
23
|
+
}
|
|
24
|
+
else if (["THEN", "UNTIL", "WHILE", "FROM", "TO", "GROUPS"].some(token => forExpressions[0].findDirectTokenByText(token))) {
|
|
25
|
+
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
26
|
+
}
|
|
27
|
+
const loopExpression = forExpression.findDirectExpression(core_1.Expressions.InlineLoopDefinition);
|
|
28
|
+
const loopSource = traversal.traverse(loopExpression?.findDirectExpression(core_1.Expressions.Source)).getCode();
|
|
29
|
+
const loopVariable = traversal.traverse(loopExpression?.findDirectExpression(core_1.Expressions.TargetField)).getCode();
|
|
30
|
+
// const type = new TypeNameOrInfer().findType(typ, traversal);
|
|
31
|
+
// const target = TranspileTypes.toType(type);
|
|
32
|
+
const ret = new chunk_1.Chunk();
|
|
33
|
+
ret.appendString("(await (async () => {\n");
|
|
34
|
+
let loopWhere = "";
|
|
35
|
+
const whereNode = forExpression?.findDirectExpression(core_1.Expressions.ComponentCond);
|
|
36
|
+
if (whereNode) {
|
|
37
|
+
const where = traversal.traverse(whereNode).getCode();
|
|
38
|
+
loopWhere = `, {"where": async ` + where + `}`;
|
|
39
|
+
}
|
|
40
|
+
/*
|
|
41
|
+
const returnId = UniqueIdentifier.get();
|
|
42
|
+
ret.appendString(`const ${returnId} = ${target};\n`);
|
|
43
|
+
*/
|
|
44
|
+
let returnField = "";
|
|
45
|
+
for (const init of body.findDirectExpressions(core_1.Expressions.InlineFieldDefinition)) {
|
|
46
|
+
const fieldName = init.findDirectExpression(core_1.Expressions.Field).concatTokens().toLowerCase();
|
|
47
|
+
returnField = fieldName;
|
|
48
|
+
const scope = traversal.findCurrentScopeByToken(init.getFirstToken());
|
|
49
|
+
const variable = scope?.findVariable(fieldName);
|
|
50
|
+
if (variable === undefined) {
|
|
51
|
+
throw new Error(`ReduceBodyTranspiler: variable ${fieldName} not found`);
|
|
52
|
+
}
|
|
53
|
+
ret.appendString(transpile_types_1.TranspileTypes.declare(variable) + `\n`);
|
|
54
|
+
}
|
|
55
|
+
ret.appendString(`for await (const ${loopVariable} of abap.statements.loop(${loopSource}${loopWhere})) {\n`);
|
|
56
|
+
for (const nextChild of body.findDirectExpression(core_1.Expressions.ReduceNext)?.getChildren() || []) {
|
|
57
|
+
if (nextChild.get() instanceof core_1.Expressions.SimpleTarget && nextChild instanceof core_1.Nodes.ExpressionNode) {
|
|
58
|
+
ret.appendString(new target_1.TargetTranspiler().transpile(nextChild, traversal).getCode() + ".set(");
|
|
59
|
+
}
|
|
60
|
+
else if (nextChild.get() instanceof core_1.Expressions.Source && nextChild instanceof core_1.Nodes.ExpressionNode) {
|
|
61
|
+
ret.appendString(traversal.traverse(nextChild).getCode() + ");\n");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
ret.appendString(`}\n`);
|
|
65
|
+
ret.appendString(`return ${returnField};\n`);
|
|
66
|
+
ret.appendString("})())");
|
|
67
|
+
return ret;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ReduceBodyTranspiler = ReduceBodyTranspiler;
|
|
71
|
+
//# sourceMappingURL=reduce_body.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractType, Nodes } from "@abaplint/core";
|
|
2
|
+
import { Chunk } from "../chunk";
|
|
2
3
|
import { IExpressionTranspiler } from "./_expression_transpiler";
|
|
3
4
|
import { Traversal } from "../traversal";
|
|
4
|
-
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class SourceTranspiler implements IExpressionTranspiler {
|
|
6
6
|
private readonly addGet;
|
|
7
7
|
constructor(addGet?: boolean);
|
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SourceTranspiler = void 0;
|
|
4
4
|
const core_1 = require("@abaplint/core");
|
|
5
5
|
const _1 = require(".");
|
|
6
|
-
const constant_1 = require("./constant");
|
|
7
6
|
const chunk_1 = require("../chunk");
|
|
8
|
-
const
|
|
9
|
-
const value_body_1 = require("./value_body");
|
|
7
|
+
const constant_1 = require("./constant");
|
|
10
8
|
const corresponding_body_1 = require("./corresponding_body");
|
|
11
9
|
const filter_body_1 = require("./filter_body");
|
|
10
|
+
const reduce_body_1 = require("./reduce_body");
|
|
11
|
+
const transpile_types_1 = require("../transpile_types");
|
|
12
|
+
const value_body_1 = require("./value_body");
|
|
12
13
|
class SourceTranspiler {
|
|
13
14
|
addGet;
|
|
14
15
|
constructor(addGet = false) {
|
|
@@ -97,6 +98,9 @@ class SourceTranspiler {
|
|
|
97
98
|
else if (c.get() instanceof core_1.Expressions.CondBody) {
|
|
98
99
|
continue;
|
|
99
100
|
}
|
|
101
|
+
else if (c.get() instanceof core_1.Expressions.ReduceBody) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
100
104
|
else if (c.get() instanceof core_1.Expressions.SwitchBody) {
|
|
101
105
|
continue;
|
|
102
106
|
}
|
|
@@ -180,6 +184,17 @@ class SourceTranspiler {
|
|
|
180
184
|
}
|
|
181
185
|
ret.appendChunk(new filter_body_1.FilterBodyTranspiler().transpile(typ, filterBody, traversal));
|
|
182
186
|
}
|
|
187
|
+
else if (c instanceof core_1.Nodes.TokenNode && c.getFirstToken().getStr().toUpperCase() === "REDUCE") {
|
|
188
|
+
const typ = node.findDirectExpression(core_1.Expressions.TypeNameOrInfer);
|
|
189
|
+
if (typ === undefined) {
|
|
190
|
+
throw new Error("TypeNameOrInfer not found in ReduceBody");
|
|
191
|
+
}
|
|
192
|
+
const reduceBody = node.findDirectExpression(core_1.Expressions.ReduceBody);
|
|
193
|
+
if (reduceBody === undefined) {
|
|
194
|
+
throw new Error("ReduceBody not found");
|
|
195
|
+
}
|
|
196
|
+
ret.appendChunk(new reduce_body_1.ReduceBodyTranspiler().transpile(typ, reduceBody, traversal));
|
|
197
|
+
}
|
|
183
198
|
else if (c instanceof core_1.Nodes.TokenNode && c.getFirstToken().getStr().toUpperCase() === "REF") {
|
|
184
199
|
const infer = node.findDirectExpression(core_1.Expressions.TypeNameOrInfer);
|
|
185
200
|
if (infer?.concatTokens() !== "#") {
|
|
@@ -69,7 +69,7 @@ class SQLCondTranspiler {
|
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
71
|
const cond = [];
|
|
72
|
-
for (const s of sqlin.findDirectExpressions(abaplint.Expressions.SQLSource)) {
|
|
72
|
+
for (const s of sqlin.findDirectExpressions(abaplint.Expressions.SQLSource).concat(sqlin.findDirectExpressions(abaplint.Expressions.SQLSourceNoSpace))) {
|
|
73
73
|
const field = new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldName, traversal).getCode();
|
|
74
74
|
const sourc = this.sqlSource(s, traversal, filename, table);
|
|
75
75
|
cond.push(field + " = " + sourc);
|
|
@@ -4,17 +4,25 @@ exports.SQLFieldTranspiler = void 0;
|
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
6
|
const sql_field_name_1 = require("./sql_field_name");
|
|
7
|
+
const field_chain_1 = require("./field_chain");
|
|
7
8
|
class SQLFieldTranspiler {
|
|
8
9
|
transpile(node, traversal) {
|
|
9
10
|
const chunk = new chunk_1.Chunk();
|
|
10
11
|
for (const c of node.getChildren()) {
|
|
11
12
|
if (c instanceof abaplint.Nodes.TokenNode) {
|
|
13
|
+
const concat = c.concatTokens();
|
|
14
|
+
if (concat === "@") {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
12
17
|
// keywords
|
|
13
18
|
chunk.appendString(c.concatTokens() + " ");
|
|
14
19
|
}
|
|
15
20
|
else if (c.get() instanceof abaplint.Expressions.SQLFieldName) {
|
|
16
21
|
chunk.appendChunk(new sql_field_name_1.SQLFieldNameTranspiler().transpile(c, traversal));
|
|
17
22
|
}
|
|
23
|
+
else if (c.get() instanceof abaplint.Expressions.SimpleFieldChain2) {
|
|
24
|
+
chunk.appendString(`'" + ` + new field_chain_1.FieldChainTranspiler().transpile(c, traversal).getCode() + `.get() + "' `);
|
|
25
|
+
}
|
|
18
26
|
else {
|
|
19
27
|
chunk.appendString(c.concatTokens() + " ");
|
|
20
28
|
}
|
|
@@ -17,6 +17,10 @@ class SQLFieldListTranspiler {
|
|
|
17
17
|
const code = new sql_field_name_1.SQLFieldNameTranspiler().transpile(f, traversal).getCode();
|
|
18
18
|
fields.push(code);
|
|
19
19
|
}
|
|
20
|
+
else if (f instanceof abaplint.Nodes.ExpressionNode && f.get() instanceof abaplint.Expressions.SQLFieldList) {
|
|
21
|
+
// todo, I have no idea why its nested like this when there is just one field
|
|
22
|
+
return new SQLFieldListTranspiler().transpile(f, traversal);
|
|
23
|
+
}
|
|
20
24
|
else {
|
|
21
25
|
const concat = f.concatTokens();
|
|
22
26
|
if (concat !== ",") {
|
|
@@ -50,13 +50,19 @@ class ValueBodyTranspiler {
|
|
|
50
50
|
ret.appendString(".set(" + source.getCode() + ".clone())");
|
|
51
51
|
}
|
|
52
52
|
else if (child.get() instanceof core_1.Expressions.For && child instanceof core_1.Nodes.ExpressionNode) {
|
|
53
|
-
if (["THEN", "UNTIL", "WHILE", "FROM", "TO", "
|
|
53
|
+
if (["THEN", "UNTIL", "WHILE", "FROM", "TO", "GROUPS"].some(token => child.findDirectTokenByText(token))) {
|
|
54
54
|
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
55
55
|
}
|
|
56
56
|
const loop = child.findDirectExpression(core_1.Expressions.InlineLoopDefinition);
|
|
57
57
|
if (loop === undefined) {
|
|
58
58
|
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
59
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
|
+
}
|
|
60
66
|
const base = loop.findDirectExpression(core_1.Expressions.ValueBase);
|
|
61
67
|
if (base) {
|
|
62
68
|
throw new Error("ValueBody FOR todo, base, " + body.concatTokens());
|
|
@@ -85,7 +91,7 @@ class ValueBodyTranspiler {
|
|
|
85
91
|
ret = new chunk_1.Chunk().appendString(`await (async () => {
|
|
86
92
|
${targetDeclare}
|
|
87
93
|
const VAL = ${val};
|
|
88
|
-
for await (const unique1 of abap.statements.loop(${source})) {
|
|
94
|
+
for await (const unique1 of abap.statements.loop(${source}${loopWhere})) {
|
|
89
95
|
${targetAction}
|
|
90
96
|
VAL`);
|
|
91
97
|
post = ";\n}\nreturn VAL;\n})()";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.76",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "abaplint",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@abaplint/core": "^2.113.
|
|
32
|
+
"@abaplint/core": "^2.113.198",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|