@abaplint/transpiler 2.11.44 → 2.11.46
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/cond_body.d.ts +6 -0
- package/build/src/expressions/cond_body.js +71 -0
- package/build/src/expressions/index.d.ts +1 -0
- package/build/src/expressions/index.js +1 -0
- package/build/src/expressions/source.js +14 -0
- package/build/src/statements/raise.js +4 -1
- package/package.json +2 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CondBodyTranspiler = void 0;
|
|
4
|
+
const core_1 = require("@abaplint/core");
|
|
5
|
+
const chunk_1 = require("../chunk");
|
|
6
|
+
const type_name_or_infer_1 = require("./type_name_or_infer");
|
|
7
|
+
const transpile_types_1 = require("../transpile_types");
|
|
8
|
+
const cond_1 = require("./cond");
|
|
9
|
+
const source_1 = require("./source");
|
|
10
|
+
class CondBodyTranspiler {
|
|
11
|
+
transpile(typ, body, traversal) {
|
|
12
|
+
if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
|
|
13
|
+
throw new Error("CondBodyTranspiler, Expected TypeNameOrInfer");
|
|
14
|
+
}
|
|
15
|
+
else if (body.findDirectExpression(core_1.Expressions.Let)) {
|
|
16
|
+
throw new Error("CondBodyTranspiler, Let not supported, todo");
|
|
17
|
+
}
|
|
18
|
+
const whenThen = [];
|
|
19
|
+
const expressions = [];
|
|
20
|
+
for (const c of body.getChildren()) {
|
|
21
|
+
if (c instanceof core_1.Nodes.TokenNode) {
|
|
22
|
+
if (c.concatTokens() === "ELSE") {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
expressions.push(c);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (let i = 0; i < expressions.length; i = i + 2) {
|
|
31
|
+
whenThen.push({ when: expressions[i], then: expressions[i + 1] });
|
|
32
|
+
}
|
|
33
|
+
const type = new type_name_or_infer_1.TypeNameOrInfer().findType(typ, traversal);
|
|
34
|
+
const target = transpile_types_1.TranspileTypes.toType(type);
|
|
35
|
+
const ret = new chunk_1.Chunk();
|
|
36
|
+
ret.appendString("(" + target + ".set(");
|
|
37
|
+
ret.appendString("await (async () => {\n");
|
|
38
|
+
for (const { when, then } of whenThen) {
|
|
39
|
+
let condition = "";
|
|
40
|
+
if (when.get() instanceof core_1.Expressions.Cond) {
|
|
41
|
+
condition = new cond_1.CondTranspiler().transpile(when, traversal).getCode();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error("CondBodyTranspiler, Expected Cond, todo, " + when.get().constructor.name);
|
|
45
|
+
}
|
|
46
|
+
let value = "";
|
|
47
|
+
if (then.get() instanceof core_1.Expressions.Source) {
|
|
48
|
+
value = new source_1.SourceTranspiler().transpile(then, traversal).getCode();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error("CondBodyTranspiler, Expected Source, todo, " + then.get().constructor.name);
|
|
52
|
+
}
|
|
53
|
+
ret.appendString(`if (${condition}) { return ${value}; }\n`);
|
|
54
|
+
}
|
|
55
|
+
const els = body.findExpressionAfterToken("ELSE");
|
|
56
|
+
if (els) {
|
|
57
|
+
if (!(els.get() instanceof core_1.Expressions.Source)) {
|
|
58
|
+
throw new Error("CondBodyTranspiler, Expected Source, todo, " + els.get().constructor.name);
|
|
59
|
+
}
|
|
60
|
+
const value = new source_1.SourceTranspiler().transpile(els, traversal).getCode();
|
|
61
|
+
ret.appendString(`return ${value};\n`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
ret.appendString(`return ${target};\n`);
|
|
65
|
+
}
|
|
66
|
+
ret.appendString("})()))");
|
|
67
|
+
return ret;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.CondBodyTranspiler = CondBodyTranspiler;
|
|
71
|
+
//# sourceMappingURL=cond_body.js.map
|
|
@@ -26,6 +26,7 @@ export * from "./let";
|
|
|
26
26
|
export * from "./message_number";
|
|
27
27
|
export * from "./method_call_body";
|
|
28
28
|
export * from "./method_call_chain";
|
|
29
|
+
export * from "./cond_body";
|
|
29
30
|
export * from "./method_call_param";
|
|
30
31
|
export * from "./new_object";
|
|
31
32
|
export * from "./method_call";
|
|
@@ -42,6 +42,7 @@ __exportStar(require("./let"), exports);
|
|
|
42
42
|
__exportStar(require("./message_number"), exports);
|
|
43
43
|
__exportStar(require("./method_call_body"), exports);
|
|
44
44
|
__exportStar(require("./method_call_chain"), exports);
|
|
45
|
+
__exportStar(require("./cond_body"), exports);
|
|
45
46
|
__exportStar(require("./method_call_param"), exports);
|
|
46
47
|
__exportStar(require("./new_object"), exports);
|
|
47
48
|
__exportStar(require("./method_call"), exports);
|
|
@@ -92,6 +92,9 @@ class SourceTranspiler {
|
|
|
92
92
|
else if (c.get() instanceof core_1.Expressions.CorrespondingBody) {
|
|
93
93
|
continue;
|
|
94
94
|
}
|
|
95
|
+
else if (c.get() instanceof core_1.Expressions.CondBody) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
95
98
|
else {
|
|
96
99
|
ret.appendString("SourceUnknown$" + c.get().constructor.name);
|
|
97
100
|
}
|
|
@@ -136,6 +139,17 @@ class SourceTranspiler {
|
|
|
136
139
|
}
|
|
137
140
|
ret.appendChunk(new corresponding_body_1.CorrespondingBodyTranspiler().transpile(typ, correspondingBody, traversal));
|
|
138
141
|
}
|
|
142
|
+
else if (c instanceof core_1.Nodes.TokenNode && c.getFirstToken().getStr().toUpperCase() === "COND") {
|
|
143
|
+
const typ = node.findDirectExpression(core_1.Expressions.TypeNameOrInfer);
|
|
144
|
+
if (typ === undefined) {
|
|
145
|
+
throw new Error("TypeNameOrInfer not found in CondBody");
|
|
146
|
+
}
|
|
147
|
+
const condBody = node.findDirectExpression(core_1.Expressions.CondBody);
|
|
148
|
+
if (condBody === undefined) {
|
|
149
|
+
throw new Error("CondBody not found");
|
|
150
|
+
}
|
|
151
|
+
ret.appendChunk(new _1.CondBodyTranspiler().transpile(typ, condBody, traversal));
|
|
152
|
+
}
|
|
139
153
|
else if (c instanceof core_1.Nodes.TokenNode && c.getFirstToken().getStr().toUpperCase() === "REF") {
|
|
140
154
|
const infer = node.findDirectExpression(core_1.Expressions.TypeNameOrInfer);
|
|
141
155
|
if (infer?.concatTokens() !== "#") {
|
|
@@ -10,7 +10,10 @@ class RaiseTranspiler {
|
|
|
10
10
|
const classNameToken = node.findFirstExpression(abaplint.Expressions.ClassName)?.getFirstToken();
|
|
11
11
|
const className = classNameToken?.getStr();
|
|
12
12
|
if (className === undefined) {
|
|
13
|
-
|
|
13
|
+
let s = node.findFirstExpression(abaplint.Expressions.SimpleSource2);
|
|
14
|
+
if (s === undefined) {
|
|
15
|
+
s = node.findFirstExpression(abaplint.Expressions.Source);
|
|
16
|
+
}
|
|
14
17
|
if (s === undefined) {
|
|
15
18
|
const name = node.findFirstExpression(abaplint.Expressions.ExceptionName)?.concatTokens().toLowerCase();
|
|
16
19
|
return new chunk_1.Chunk().append(`throw new abap.ClassicError({classic: "${name}"});`, node, traversal);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.46",
|
|
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.184",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|