@abaplint/transpiler 1.7.12 → 1.7.16
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/constant.js +3 -2
- package/build/src/index.d.ts +1 -1
- package/build/src/index.js +4 -5
- package/build/src/statements/create_object.js +12 -3
- package/build/src/statements/select.js +9 -0
- package/build/src/traversal.d.ts +1 -1
- package/build/src/traversal.js +4 -1
- package/build/src/types.js +3 -0
- package/package.json +2 -2
|
@@ -10,8 +10,9 @@ class ConstantTranspiler {
|
|
|
10
10
|
transpile(node, traversal) {
|
|
11
11
|
const int = node.findFirstExpression(core_1.Expressions.Integer);
|
|
12
12
|
if (int) {
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const concat = int.concatTokens().trim();
|
|
14
|
+
const post = concat.startsWith("-") ? "minus_" : "";
|
|
15
|
+
let ret = "constant_" + post + int.getLastToken().getStr();
|
|
15
16
|
if (this.addGet === true) {
|
|
16
17
|
ret += ".get()";
|
|
17
18
|
}
|
package/build/src/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare class Transpiler {
|
|
|
55
55
|
runRaw(files: IFile[]): Promise<IOutput>;
|
|
56
56
|
run(reg: abaplint.IRegistry, progress?: IProgress): Promise<IOutput>;
|
|
57
57
|
protected handleConstants(obj: abaplint.ABAPObject, file: abaplint.ABAPFile, reg: abaplint.IRegistry): string;
|
|
58
|
-
protected findConstants(obj: abaplint.ABAPObject, file: abaplint.ABAPFile, reg: abaplint.IRegistry): Set<
|
|
58
|
+
protected findConstants(obj: abaplint.ABAPObject, file: abaplint.ABAPFile, reg: abaplint.IRegistry): Set<string>;
|
|
59
59
|
protected runObject(obj: abaplint.ABAPObject, reg: abaplint.IRegistry): IOutputFile[];
|
|
60
60
|
/** merges the locals def and imp into one mjs file */
|
|
61
61
|
private rearrangeClassLocals;
|
package/build/src/index.js
CHANGED
|
@@ -62,9 +62,9 @@ class Transpiler {
|
|
|
62
62
|
let result = "";
|
|
63
63
|
const constants = this.findConstants(obj, file, reg);
|
|
64
64
|
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.skipConstants) === false || ((_b = this.options) === null || _b === void 0 ? void 0 : _b.skipConstants) === undefined) {
|
|
65
|
-
for (const
|
|
66
|
-
const post =
|
|
67
|
-
result += `const constant_${post}${
|
|
65
|
+
for (const concat of Array.from(constants).sort()) {
|
|
66
|
+
const post = concat.startsWith("-") ? "minus_" : "";
|
|
67
|
+
result += `const constant_${post}${concat.replace("-", "")} = new abap.types.Integer().set(${concat});\n`;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return result;
|
|
@@ -73,8 +73,7 @@ class Transpiler {
|
|
|
73
73
|
var _a, _b;
|
|
74
74
|
let constants = new Set();
|
|
75
75
|
for (const i of ((_a = file.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllExpressions(abaplint.Expressions.Integer)) || []) {
|
|
76
|
-
|
|
77
|
-
constants.add(j);
|
|
76
|
+
constants.add(i.concatTokens().replace(" ", ""));
|
|
78
77
|
}
|
|
79
78
|
// extra constants from interfaces, used for default values
|
|
80
79
|
if (obj.getType() === "CLAS") {
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CreateObjectTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
|
+
const expressions_1 = require("../expressions");
|
|
6
7
|
class CreateObjectTranspiler {
|
|
7
8
|
transpile(node, traversal) {
|
|
8
|
-
var _a;
|
|
9
|
+
var _a, _b;
|
|
9
10
|
const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode();
|
|
10
11
|
let para = "";
|
|
11
12
|
const parameters = node.findFirstExpression(abaplint.Expressions.ParameterListS);
|
|
@@ -13,16 +14,24 @@ class CreateObjectTranspiler {
|
|
|
13
14
|
para = traversal.traverse(parameters).getCode();
|
|
14
15
|
}
|
|
15
16
|
let name = "";
|
|
16
|
-
|
|
17
|
+
let directGlobal = false;
|
|
18
|
+
let dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
|
|
17
19
|
if (dynamic) {
|
|
18
20
|
name = dynamic.getFirstToken().getStr();
|
|
19
21
|
name = name.substring(1, name.length - 1);
|
|
20
22
|
}
|
|
21
23
|
else {
|
|
24
|
+
dynamic = (_b = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldChain);
|
|
25
|
+
if (dynamic) {
|
|
26
|
+
name = new expressions_1.FieldChainTranspiler(true).transpile(dynamic, traversal).getCode();
|
|
27
|
+
directGlobal = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (name === "") {
|
|
22
31
|
name = this.findClassName(node, traversal);
|
|
23
32
|
}
|
|
24
33
|
let ret = "";
|
|
25
|
-
const clas = traversal.lookupClassOrInterface(name, node.getFirstToken());
|
|
34
|
+
const clas = traversal.lookupClassOrInterface(name, node.getFirstToken(), directGlobal);
|
|
26
35
|
const cx = traversal.lookupClassOrInterface("CX_SY_CREATE_OBJECT_ERROR", node.getFirstToken());
|
|
27
36
|
if (dynamic) {
|
|
28
37
|
ret += `if (${clas} === undefined) { throw new ${cx}; }\n`;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SelectTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
|
+
const expressions_1 = require("../expressions");
|
|
6
7
|
class SelectTranspiler {
|
|
7
8
|
transpile(node, traversal) {
|
|
8
9
|
var _a, _b;
|
|
@@ -10,6 +11,14 @@ class SelectTranspiler {
|
|
|
10
11
|
let select = "SELECT ";
|
|
11
12
|
select += ((_a = node.findFirstExpression(abaplint.Expressions.SQLFieldList)) === null || _a === void 0 ? void 0 : _a.concatTokens()) + " ";
|
|
12
13
|
select += ((_b = node.findFirstExpression(abaplint.Expressions.SQLFrom)) === null || _b === void 0 ? void 0 : _b.concatTokens()) + " ";
|
|
14
|
+
for (const d of node.findAllExpressionsRecursive(abaplint.Expressions.Dynamic)) {
|
|
15
|
+
const chain = d.findFirstExpression(abaplint.Expressions.FieldChain);
|
|
16
|
+
if (chain) {
|
|
17
|
+
const code = new expressions_1.FieldChainTranspiler(true).transpile(chain, traversal).getCode();
|
|
18
|
+
const search = d.concatTokens();
|
|
19
|
+
select = select.replace(search, `" + ${code} + "`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
13
22
|
if (node.concatTokens().toUpperCase().startsWith("SELECT SINGLE ")) {
|
|
14
23
|
select += "LIMIT 1";
|
|
15
24
|
}
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare class Traversal {
|
|
|
36
36
|
private dataFromInterfaces;
|
|
37
37
|
determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
38
38
|
registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
|
|
39
|
-
lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined): string;
|
|
39
|
+
lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
|
|
40
40
|
private buildPrefix;
|
|
41
41
|
protected traverseStructure(node: abaplint.Nodes.StructureNode): Chunk;
|
|
42
42
|
protected traverseStatement(node: abaplint.Nodes.StatementNode): Chunk;
|
package/build/src/traversal.js
CHANGED
|
@@ -347,11 +347,14 @@ class Traversal {
|
|
|
347
347
|
return `abap.Classes['${name.toUpperCase()}'] = ${name.toLowerCase()};`;
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
|
-
lookupClassOrInterface(name, token) {
|
|
350
|
+
lookupClassOrInterface(name, token, directGlobal = false) {
|
|
351
351
|
var _a, _b;
|
|
352
352
|
if (name === undefined || token === undefined) {
|
|
353
353
|
return "abap.Classes['undefined']";
|
|
354
354
|
}
|
|
355
|
+
if (directGlobal === true) {
|
|
356
|
+
return "abap.Classes[" + name + "]";
|
|
357
|
+
}
|
|
355
358
|
const scope = this.findCurrentScopeByToken(token);
|
|
356
359
|
// todo, add explicit type,
|
|
357
360
|
let def = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name);
|
package/build/src/types.js
CHANGED
|
@@ -96,6 +96,9 @@ class TranspileTypes {
|
|
|
96
96
|
else if (type instanceof abaplint.BasicTypes.FloatType) {
|
|
97
97
|
resolved = "Float";
|
|
98
98
|
}
|
|
99
|
+
else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
|
|
100
|
+
resolved = "DecFloat34";
|
|
101
|
+
}
|
|
99
102
|
else if (type instanceof abaplint.BasicTypes.UnknownType) {
|
|
100
103
|
return `(() => { throw "Unknown type: ${type.getError()}" })()`;
|
|
101
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.16",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@types/chai": "^4.3.0",
|
|
35
35
|
"@types/mocha": "^9.0.0",
|
|
36
36
|
"chai": "^4.3.4",
|
|
37
|
-
"mocha": "^9.1.
|
|
37
|
+
"mocha": "^9.1.4",
|
|
38
38
|
"source-map-support": "^0.5.21",
|
|
39
39
|
"typescript": "^4.5.4"
|
|
40
40
|
}
|