@abaplint/transpiler 2.11.40 → 2.11.41
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.
|
@@ -22,6 +22,7 @@ export * from "./field_symbol";
|
|
|
22
22
|
export * from "./function_exporting";
|
|
23
23
|
export * from "./table_expression";
|
|
24
24
|
export * from "./function_parameters";
|
|
25
|
+
export * from "./let";
|
|
25
26
|
export * from "./message_number";
|
|
26
27
|
export * from "./method_call_body";
|
|
27
28
|
export * from "./method_call_chain";
|
|
@@ -38,6 +38,7 @@ __exportStar(require("./field_symbol"), exports);
|
|
|
38
38
|
__exportStar(require("./function_exporting"), exports);
|
|
39
39
|
__exportStar(require("./table_expression"), exports);
|
|
40
40
|
__exportStar(require("./function_parameters"), exports);
|
|
41
|
+
__exportStar(require("./let"), exports);
|
|
41
42
|
__exportStar(require("./message_number"), exports);
|
|
42
43
|
__exportStar(require("./method_call_body"), exports);
|
|
43
44
|
__exportStar(require("./method_call_chain"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LetTranspiler = void 0;
|
|
4
|
+
const core_1 = require("@abaplint/core");
|
|
5
|
+
const chunk_1 = require("../chunk");
|
|
6
|
+
const transpile_types_1 = require("../transpile_types");
|
|
7
|
+
class LetTranspiler {
|
|
8
|
+
transpile(node, traversal) {
|
|
9
|
+
if (!(node.get() instanceof core_1.Expressions.Let)) {
|
|
10
|
+
throw new Error("LetTranspiler, Expected Let");
|
|
11
|
+
}
|
|
12
|
+
const ret = new chunk_1.Chunk();
|
|
13
|
+
for (const def of node.findAllExpressions(core_1.Expressions.InlineFieldDefinition)) {
|
|
14
|
+
const nameToken = def.findDirectExpression(core_1.Expressions.Field);
|
|
15
|
+
if (nameToken === undefined) {
|
|
16
|
+
throw new Error("LetTranspiler, Expected Field");
|
|
17
|
+
}
|
|
18
|
+
const name = nameToken?.concatTokens();
|
|
19
|
+
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
20
|
+
const variable = scope?.findVariable(name);
|
|
21
|
+
if (variable === undefined) {
|
|
22
|
+
throw new Error("LetTranspiler, Expected Variable");
|
|
23
|
+
}
|
|
24
|
+
ret.appendString(transpile_types_1.TranspileTypes.declare(variable));
|
|
25
|
+
const source = def.findDirectExpression(core_1.Expressions.Source);
|
|
26
|
+
if (source) {
|
|
27
|
+
ret.appendString(name + `.set(${traversal.traverse(source).getCode()});`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return ret;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.LetTranspiler = LetTranspiler;
|
|
34
|
+
//# sourceMappingURL=let.js.map
|
|
@@ -8,6 +8,8 @@ const value_body_line_1 = require("./value_body_line");
|
|
|
8
8
|
const field_assignment_1 = require("./field_assignment");
|
|
9
9
|
const statements_1 = require("../statements");
|
|
10
10
|
const source_field_symbol_1 = require("./source_field_symbol");
|
|
11
|
+
const transpile_types_1 = require("../transpile_types");
|
|
12
|
+
const let_1 = require("./let");
|
|
11
13
|
class ValueBodyTranspiler {
|
|
12
14
|
transpile(typ, body, traversal) {
|
|
13
15
|
if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
|
|
@@ -15,6 +17,10 @@ class ValueBodyTranspiler {
|
|
|
15
17
|
}
|
|
16
18
|
let ret = new chunk_1.Chunk().appendString(new type_name_or_infer_1.TypeNameOrInfer().transpile(typ, traversal).getCode());
|
|
17
19
|
const context = new type_name_or_infer_1.TypeNameOrInfer().findType(typ, traversal);
|
|
20
|
+
if (context instanceof core_1.BasicTypes.VoidType || context instanceof core_1.BasicTypes.UnknownType) {
|
|
21
|
+
// compile option is runtime error, or it failed during the validation step
|
|
22
|
+
return new chunk_1.Chunk(transpile_types_1.TranspileTypes.toType(context));
|
|
23
|
+
}
|
|
18
24
|
let post = "";
|
|
19
25
|
let extraFields = "";
|
|
20
26
|
const hasLines = body.findDirectExpression(core_1.Expressions.ValueBodyLine) !== undefined;
|
|
@@ -34,7 +40,7 @@ class ValueBodyTranspiler {
|
|
|
34
40
|
}
|
|
35
41
|
else if (child.get() instanceof core_1.Expressions.ValueBodyLine && child instanceof core_1.Nodes.ExpressionNode) {
|
|
36
42
|
if (!(context instanceof core_1.BasicTypes.TableType)) {
|
|
37
|
-
throw new Error("ValueBodyTranspiler, Expected BasicTypes");
|
|
43
|
+
throw new Error("ValueBodyTranspiler, Expected BasicTypes, " + body.concatTokens());
|
|
38
44
|
}
|
|
39
45
|
const rowType = context.getRowType();
|
|
40
46
|
ret.appendString(new value_body_line_1.ValueBodyLineTranspiler().transpile(rowType, child, traversal, extraFields).getCode());
|
|
@@ -44,15 +50,16 @@ class ValueBodyTranspiler {
|
|
|
44
50
|
ret.appendString(".set(" + source.getCode() + ".clone())");
|
|
45
51
|
}
|
|
46
52
|
else if (child.get() instanceof core_1.Expressions.For && child instanceof core_1.Nodes.ExpressionNode) {
|
|
47
|
-
if (
|
|
48
|
-
throw new Error("ValueBody FOR todo,
|
|
53
|
+
if (["THEN", "UNTIL", "WHILE", "FROM", "TO", "WHERE", "GROUPS"].some(token => child.findDirectTokenByText(token))) {
|
|
54
|
+
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
49
55
|
}
|
|
50
56
|
const loop = child.findDirectExpression(core_1.Expressions.InlineLoopDefinition);
|
|
51
57
|
if (loop === undefined) {
|
|
52
|
-
throw new Error("ValueBody FOR todo");
|
|
58
|
+
throw new Error("ValueBody FOR todo, " + body.concatTokens());
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
const base = loop.findDirectExpression(core_1.Expressions.ValueBase);
|
|
61
|
+
if (base) {
|
|
62
|
+
throw new Error("ValueBody FOR todo, base, " + body.concatTokens());
|
|
56
63
|
}
|
|
57
64
|
let targetDeclare = "";
|
|
58
65
|
let targetAction = "";
|
|
@@ -65,10 +72,14 @@ class ValueBodyTranspiler {
|
|
|
65
72
|
else {
|
|
66
73
|
const field = traversal.traverse(loop.findDirectExpression(core_1.Expressions.TargetField));
|
|
67
74
|
if (field === undefined) {
|
|
68
|
-
throw new Error("ValueBody FOR empty field todo");
|
|
75
|
+
throw new Error("ValueBody FOR empty field todo, " + body.concatTokens());
|
|
69
76
|
}
|
|
70
77
|
targetAction = `const ${field.getCode()} = unique1.clone();`;
|
|
71
78
|
}
|
|
79
|
+
const llet = child.findDirectExpression(core_1.Expressions.Let);
|
|
80
|
+
if (llet) {
|
|
81
|
+
targetAction += new let_1.LetTranspiler().transpile(llet, traversal).getCode();
|
|
82
|
+
}
|
|
72
83
|
const source = traversal.traverse(loop.findDirectExpression(core_1.Expressions.Source)).getCode();
|
|
73
84
|
const val = new type_name_or_infer_1.TypeNameOrInfer().transpile(typ, traversal).getCode();
|
|
74
85
|
ret = new chunk_1.Chunk().appendString(`await (async () => {
|
package/build/src/validation.js
CHANGED