@abaplint/transpiler 2.10.35 → 2.10.37
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.
|
@@ -5,19 +5,35 @@ const abaplint = require("@abaplint/core");
|
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
6
|
const transpile_types_1 = require("../transpile_types");
|
|
7
7
|
const traversal_1 = require("../traversal");
|
|
8
|
+
const structures_1 = require("../structures");
|
|
8
9
|
class HandleTypePool {
|
|
9
10
|
runObject(obj, reg) {
|
|
10
|
-
const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti
|
|
11
|
+
const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti;
|
|
12
|
+
const spaghettiNode = spaghetti.getFirstChild()?.getFirstChild();
|
|
13
|
+
if (spaghettiNode === undefined) {
|
|
14
|
+
throw new Error("HandleTypePool: no spaghetti found");
|
|
15
|
+
}
|
|
16
|
+
const abapFile = obj.getABAPFiles()[0];
|
|
17
|
+
if (abapFile === undefined) {
|
|
18
|
+
throw new Error("HandleTypePool: no ABAP file found");
|
|
19
|
+
}
|
|
11
20
|
const chunk = new chunk_1.Chunk();
|
|
12
21
|
chunk.appendString(`const pool = {};\n`);
|
|
13
|
-
for (const v in
|
|
14
|
-
const abs =
|
|
22
|
+
for (const v in spaghettiNode?.getData().vars) {
|
|
23
|
+
const abs = spaghettiNode.getData().vars[v];
|
|
15
24
|
const name = `pool['${v.toLowerCase()}']`;
|
|
16
25
|
chunk.appendString(`${name} = ${new transpile_types_1.TranspileTypes().toType(abs.getType())};\n`);
|
|
17
26
|
chunk.appendString(traversal_1.Traversal.setValues(abs, name));
|
|
27
|
+
// yea, this is a mess
|
|
28
|
+
for (const cons of abapFile.getStructure()?.findAllStructures(abaplint.Structures.Constants) || []) {
|
|
29
|
+
const cName = cons.findFirstExpression(abaplint.Expressions.DefinitionName)?.getFirstToken().getStr().toLowerCase();
|
|
30
|
+
if (cName === v.toLocaleLowerCase()) {
|
|
31
|
+
chunk.appendString(structures_1.ConstantsTranspiler.handleValues(name, cons, new traversal_1.Traversal(spaghetti, abapFile, obj, reg)));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
18
34
|
}
|
|
19
|
-
for (const t in
|
|
20
|
-
const abs =
|
|
35
|
+
for (const t in spaghettiNode?.getData().types) {
|
|
36
|
+
const abs = spaghettiNode.getData().types[t];
|
|
21
37
|
chunk.appendString(`pool['${t.toLowerCase()}'] = ${new transpile_types_1.TranspileTypes().toType(abs.getType())};\n`);
|
|
22
38
|
}
|
|
23
39
|
chunk.appendString(`abap.TypePools['${obj.getName()}'] = pool;`);
|
|
@@ -4,4 +4,5 @@ import { Traversal } from "../traversal";
|
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class ConstantsTranspiler implements IStructureTranspiler {
|
|
6
6
|
transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal): Chunk;
|
|
7
|
+
static handleValues(prefix: string, node: abaplint.Nodes.StructureNode, traversal: Traversal): string;
|
|
7
8
|
}
|
|
@@ -15,6 +15,11 @@ class ConstantsTranspiler {
|
|
|
15
15
|
throw "ConstantsTranspilerName";
|
|
16
16
|
}
|
|
17
17
|
let ret = new statements_1.DataTranspiler().transpile(begin, traversal).getCode() + "\n";
|
|
18
|
+
ret += ConstantsTranspiler.handleValues(name, node, traversal);
|
|
19
|
+
return new chunk_1.Chunk(ret);
|
|
20
|
+
}
|
|
21
|
+
static handleValues(prefix, node, traversal) {
|
|
22
|
+
let ret = "";
|
|
18
23
|
// todo: CONSTANTS BEGIN inside CONSTANTS BEGIN
|
|
19
24
|
for (const c of node.findDirectStatements(abaplint.Statements.Constant)) {
|
|
20
25
|
const field = c.findDirectExpression(abaplint.Expressions.DefinitionName)?.getFirstToken().getStr();
|
|
@@ -23,10 +28,10 @@ class ConstantsTranspiler {
|
|
|
23
28
|
}
|
|
24
29
|
const value = c.findFirstExpression(abaplint.Expressions.Constant);
|
|
25
30
|
if (value) {
|
|
26
|
-
ret += `${
|
|
31
|
+
ret += `${prefix}.get().${field}.set(${traversal.traverse(value).getCode()});\n`;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
|
-
return
|
|
34
|
+
return ret;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
exports.ConstantsTranspiler = ConstantsTranspiler;
|
package/build/src/unit_test.js
CHANGED
|
@@ -39,7 +39,7 @@ export async function initializeABAP() {\n`;
|
|
|
39
39
|
ret += ` insert.push(\`${i}\`);\n`;
|
|
40
40
|
}
|
|
41
41
|
ret += `\n`;
|
|
42
|
-
if (extraSetup === undefined) {
|
|
42
|
+
if (extraSetup === undefined || extraSetup === "") {
|
|
43
43
|
ret += `// no setup logic specified in config\n`;
|
|
44
44
|
}
|
|
45
45
|
else {
|