@abaplint/transpiler 2.13.1 → 2.13.2
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/statements/data.d.ts +1 -0
- package/build/src/statements/data.js +27 -0
- package/build/src/structures/index.d.ts +1 -0
- package/build/src/structures/index.js +1 -0
- package/build/src/structures/type_enum.d.ts +7 -0
- package/build/src/structures/type_enum.js +35 -0
- package/build/src/transpile_types.js +6 -0
- package/package.json +2 -2
|
@@ -4,5 +4,6 @@ import { Traversal } from "../traversal";
|
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class DataTranspiler implements IStatementTranspiler {
|
|
6
6
|
transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
|
|
7
|
+
static findEnumDefault(scope: abaplint.ISpaghettiScopeNode, _enumType: abaplint.AbstractType): string | undefined;
|
|
7
8
|
static buildValue(node: abaplint.Nodes.StatementNode, name: string, traversal: Traversal): string;
|
|
8
9
|
}
|
|
@@ -28,6 +28,13 @@ class DataTranspiler {
|
|
|
28
28
|
else {
|
|
29
29
|
value = DataTranspiler.buildValue(node, traversal_1.Traversal.prefixVariable(found.getName().toLowerCase()), traversal);
|
|
30
30
|
}
|
|
31
|
+
// for enum types, initialize with the first enum value
|
|
32
|
+
if (found.getType() instanceof abaplint.BasicTypes.EnumType && value === "") {
|
|
33
|
+
const enumDefault = DataTranspiler.findEnumDefault(scope, found.getType());
|
|
34
|
+
if (enumDefault) {
|
|
35
|
+
value = "\n" + traversal_1.Traversal.prefixVariable(found.getName().toLowerCase()) + ".set(\"" + enumDefault + "\");";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
31
38
|
const ret = new chunk_1.Chunk()
|
|
32
39
|
.appendString("let ")
|
|
33
40
|
.appendString(traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(found.getName().toLowerCase())))
|
|
@@ -36,6 +43,26 @@ class DataTranspiler {
|
|
|
36
43
|
.appendString(value);
|
|
37
44
|
return ret;
|
|
38
45
|
}
|
|
46
|
+
static findEnumDefault(scope, _enumType) {
|
|
47
|
+
let current = scope;
|
|
48
|
+
while (current) {
|
|
49
|
+
const vars = current.getData().vars;
|
|
50
|
+
for (const key of Object.keys(vars)) {
|
|
51
|
+
const v = vars[key];
|
|
52
|
+
if (v.getMeta().includes("enum" /* abaplint.IdentifierMeta.Enum */)) {
|
|
53
|
+
const structType = v.getType();
|
|
54
|
+
if (structType instanceof abaplint.BasicTypes.StructureType) {
|
|
55
|
+
const components = structType.getComponents();
|
|
56
|
+
if (components.length > 0) {
|
|
57
|
+
return components[0].name.toUpperCase();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
current = current.getParent();
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
39
66
|
static buildValue(node, name, traversal) {
|
|
40
67
|
let value = "";
|
|
41
68
|
const val = node.findFirstExpression(abaplint.Expressions.Value);
|
|
@@ -31,6 +31,7 @@ __exportStar(require("./module"), exports);
|
|
|
31
31
|
__exportStar(require("./select"), exports);
|
|
32
32
|
__exportStar(require("./method"), exports);
|
|
33
33
|
__exportStar(require("./try"), exports);
|
|
34
|
+
__exportStar(require("./type_enum"), exports);
|
|
34
35
|
__exportStar(require("./types"), exports);
|
|
35
36
|
__exportStar(require("./when"), exports);
|
|
36
37
|
__exportStar(require("./while"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as abaplint from "@abaplint/core";
|
|
2
|
+
import { IStructureTranspiler } from "./_structure_transpiler";
|
|
3
|
+
import { Traversal } from "../traversal";
|
|
4
|
+
import { Chunk } from "../chunk";
|
|
5
|
+
export declare class TypeEnumTranspiler implements IStructureTranspiler {
|
|
6
|
+
transpile(node: abaplint.Nodes.StructureNode, _traversal: Traversal): Chunk;
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeEnumTranspiler = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
const traversal_1 = require("../traversal");
|
|
6
|
+
const chunk_1 = require("../chunk");
|
|
7
|
+
class TypeEnumTranspiler {
|
|
8
|
+
transpile(node, _traversal) {
|
|
9
|
+
const begin = node.findDirectStatement(abaplint.Statements.TypeEnumBegin);
|
|
10
|
+
if (begin === undefined) {
|
|
11
|
+
return new chunk_1.Chunk("");
|
|
12
|
+
}
|
|
13
|
+
const nsNames = begin.findAllExpressions(abaplint.Expressions.NamespaceSimpleName);
|
|
14
|
+
if (nsNames.length < 2) {
|
|
15
|
+
return new chunk_1.Chunk("");
|
|
16
|
+
}
|
|
17
|
+
const structureName = nsNames[1].concatTokens().toLowerCase();
|
|
18
|
+
const values = [];
|
|
19
|
+
for (const t of node.findDirectStatements(abaplint.Statements.Type)) {
|
|
20
|
+
const name = t.findFirstExpression(abaplint.Expressions.NamespaceSimpleName);
|
|
21
|
+
if (name) {
|
|
22
|
+
values.push(name.concatTokens().toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const fields = values.map(v => `"${v}": new abap.types.String()`).join(",\n");
|
|
26
|
+
let ret = `let ${traversal_1.Traversal.prefixVariable(structureName)} = new abap.types.Structure({
|
|
27
|
+
${fields}});\n`;
|
|
28
|
+
for (const v of values) {
|
|
29
|
+
ret += `${traversal_1.Traversal.prefixVariable(structureName)}.get().${v}.set("${v.toUpperCase()}");\n`;
|
|
30
|
+
}
|
|
31
|
+
return new chunk_1.Chunk(ret);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.TypeEnumTranspiler = TypeEnumTranspiler;
|
|
35
|
+
//# sourceMappingURL=type_enum.js.map
|
|
@@ -195,6 +195,12 @@ class TranspileTypes {
|
|
|
195
195
|
else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
|
|
196
196
|
resolved = "DecFloat34";
|
|
197
197
|
}
|
|
198
|
+
else if (type instanceof abaplint.BasicTypes.EnumType) {
|
|
199
|
+
resolved = "String";
|
|
200
|
+
if (type.getQualifiedName() !== undefined) {
|
|
201
|
+
extra = "{qualifiedName: \"" + type.getQualifiedName()?.toUpperCase() + "\"}";
|
|
202
|
+
}
|
|
203
|
+
}
|
|
198
204
|
else if (type instanceof abaplint.BasicTypes.UnknownType) {
|
|
199
205
|
return `(() => { throw new Error("Unknown type: ${type.getError()}") })()`;
|
|
200
206
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.2",
|
|
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.118.
|
|
32
|
+
"@abaplint/core": "^2.118.7",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|