@abaplint/transpiler 2.10.50 → 2.10.51
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/assign.js +12 -11
- package/build/src/statements/call_function.js +2 -2
- package/build/src/statements/perform.js +55 -35
- package/build/src/structures/form.d.ts +7 -0
- package/build/src/structures/form.js +21 -0
- package/build/src/structures/index.d.ts +1 -0
- package/build/src/structures/index.js +1 -0
- package/build/src/transpile_types.js +1 -1
- package/package.json +1 -1
|
@@ -60,34 +60,35 @@ class AssignTranspiler {
|
|
|
60
60
|
if (firstFirst?.get() instanceof abaplint.Expressions.Constant) {
|
|
61
61
|
const s = firstFirst.getFirstToken().getStr().toLowerCase().match(/\w+/)?.toString();
|
|
62
62
|
options.push(`dynamicSource: (() => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
try { return ${s}; } catch {}
|
|
64
|
+
try { return this.${s}; } catch {}
|
|
65
|
+
})()`);
|
|
66
66
|
}
|
|
67
67
|
else if (firstFirst?.get() instanceof abaplint.Expressions.FieldChain && firstFirst instanceof abaplint.Nodes.ExpressionNode) {
|
|
68
68
|
const code = new expressions_1.FieldChainTranspiler(true).transpile(firstFirst, traversal).getCode();
|
|
69
69
|
options.push(`dynamicSource: (() => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
|
|
71
|
+
try { return eval(name); } catch {}
|
|
72
|
+
try { return eval("this." + name); } catch {}
|
|
73
|
+
})()`);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else if (first?.get() instanceof abaplint.Expressions.Source && first instanceof abaplint.Nodes.ExpressionNode) {
|
|
77
77
|
// const name = first.concatTokens().toLowerCase();
|
|
78
78
|
const name = new expressions_1.SourceTranspiler().transpile(first, traversal).getCode();
|
|
79
79
|
options.push(`dynamicSource: (() => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
try { return ${name}; } catch {}
|
|
81
|
+
try { return this.${name}; } catch {}
|
|
82
|
+
})()`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
if (concat.endsWith(" CASTING.") || concat.includes(" CASTING TYPE ")) {
|
|
86
86
|
options.push("casting: true");
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
const ret = new chunk_1.Chunk().append("abap.statements.assign({", node, traversal)
|
|
89
89
|
.appendString(options.join(", "))
|
|
90
90
|
.append("});", node.getLastToken(), traversal);
|
|
91
|
+
return ret;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
exports.AssignTranspiler = AssignTranspiler;
|
|
@@ -45,8 +45,8 @@ class CallFunctionTranspiler {
|
|
|
45
45
|
else {
|
|
46
46
|
const illegalFunc = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_FUNC'", node.getFirstToken(), true);
|
|
47
47
|
const call = `abap.FunctionModules[${fmname}]`;
|
|
48
|
-
|
|
49
|
-
ret.appendString(`if (${call} === undefined) { throw new ${illegalFunc}(); }\n`);
|
|
48
|
+
// eslint-disable-next-line max-len
|
|
49
|
+
ret.appendString(`if (${call} === undefined) { if (${illegalFunc} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_FUNC not found"; } else { throw new ${illegalFunc}();} }\n`);
|
|
50
50
|
ret.appendString(`await ${call}(${param});`);
|
|
51
51
|
}
|
|
52
52
|
if (exceptions) {
|
|
@@ -11,47 +11,67 @@ class PerformTranspiler {
|
|
|
11
11
|
return new chunk_1.Chunk(`throw new Error("PerformTranspiler FormName not found");`);
|
|
12
12
|
}
|
|
13
13
|
else if (node.concatTokens().toUpperCase().includes(" IN PROGRAM ")) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
&& r.position.getStart().equals(formName.getFirstToken().getStart())
|
|
21
|
-
&& r.resolved instanceof abaplint.Types.FormDefinition) {
|
|
22
|
-
def = r.resolved;
|
|
14
|
+
// todo: throw exception if not found?
|
|
15
|
+
const expression = node.findExpressionAfterToken("PROGRAM");
|
|
16
|
+
let ref = "";
|
|
17
|
+
if (expression?.get() instanceof abaplint.Expressions.Dynamic) {
|
|
18
|
+
const name = expression.getChildren()[1].concatTokens() + ".get().trimEnd()";
|
|
19
|
+
ref = `abap.Forms['PROG-' + ${name} + '-${formName.concatTokens().toUpperCase()}']`;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let index = 0;
|
|
28
|
-
for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
|
|
29
|
-
const name = def?.getTablesParameters()[index].getName().toLowerCase();
|
|
30
|
-
if (name === undefined) {
|
|
31
|
-
continue;
|
|
21
|
+
else {
|
|
22
|
+
const progName = expression?.concatTokens().toUpperCase();
|
|
23
|
+
ref = `abap.Forms['PROG-${progName}-${formName.concatTokens().toUpperCase()}']`;
|
|
32
24
|
}
|
|
33
|
-
params
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const name = def?.getUsingParameters()[index].getName().toLowerCase();
|
|
39
|
-
if (name === undefined) {
|
|
40
|
-
continue;
|
|
25
|
+
const params = [];
|
|
26
|
+
// hacky hack
|
|
27
|
+
for (const t of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Target) || []) {
|
|
28
|
+
const name = t.getFirstToken().getStr();
|
|
29
|
+
params.push(`"${name}": ` + traversal.traverse(t).getCode());
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
index++;
|
|
31
|
+
return new chunk_1.Chunk("await " + ref + `({${params.join(",")}});`);
|
|
44
32
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
else {
|
|
34
|
+
// todo: most of this needs rewriting?
|
|
35
|
+
let def = undefined;
|
|
36
|
+
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
37
|
+
for (const r of scope?.getData().references || []) {
|
|
38
|
+
if (r.referenceType === abaplint.ReferenceType.FormReference
|
|
39
|
+
&& r.position.getStart().equals(formName.getFirstToken().getStart())
|
|
40
|
+
&& r.resolved instanceof abaplint.Types.FormDefinition) {
|
|
41
|
+
def = r.resolved;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// todo: pass by VALUE()
|
|
45
|
+
const params = [];
|
|
46
|
+
let index = 0;
|
|
47
|
+
for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
|
|
48
|
+
const name = def?.getTablesParameters()[index].getName().toLowerCase();
|
|
49
|
+
if (name === undefined) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
params.push(`"${name}": ` + traversal.traverse(t).getCode());
|
|
53
|
+
index++;
|
|
54
|
+
}
|
|
55
|
+
index = 0;
|
|
56
|
+
for (const u of node.findDirectExpression(abaplint.Expressions.PerformUsing)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
|
|
57
|
+
const name = def?.getUsingParameters()[index].getName().toLowerCase();
|
|
58
|
+
if (name === undefined) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
params.push(`"${name}": ` + traversal.traverse(u).getCode());
|
|
62
|
+
index++;
|
|
63
|
+
}
|
|
64
|
+
index = 0;
|
|
65
|
+
for (const c of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
|
|
66
|
+
const name = def?.getChangingParameters()[index].getName().toLowerCase();
|
|
67
|
+
if (name === undefined) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
params.push(`"${name}": ` + traversal.traverse(c).getCode());
|
|
71
|
+
index++;
|
|
50
72
|
}
|
|
51
|
-
|
|
52
|
-
index++;
|
|
73
|
+
return new chunk_1.Chunk("await " + formName.concatTokens() + `({${params.join(",")}});`);
|
|
53
74
|
}
|
|
54
|
-
return new chunk_1.Chunk("await " + formName.concatTokens() + `({${params.join(",")}});`);
|
|
55
75
|
}
|
|
56
76
|
}
|
|
57
77
|
exports.PerformTranspiler = PerformTranspiler;
|
|
@@ -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 FormTranspiler implements IStructureTranspiler {
|
|
6
|
+
transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal): Chunk;
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormTranspiler = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
const chunk_1 = require("../chunk");
|
|
6
|
+
class FormTranspiler {
|
|
7
|
+
transpile(node, traversal) {
|
|
8
|
+
const formName = node.findFirstStatement(abaplint.Statements.Form)
|
|
9
|
+
?.findDirectExpression(abaplint.Expressions.FormName)?.concatTokens()?.toUpperCase();
|
|
10
|
+
const ret = new chunk_1.Chunk();
|
|
11
|
+
for (const c of node.getChildren()) {
|
|
12
|
+
ret.appendChunk(traversal.traverse(c));
|
|
13
|
+
}
|
|
14
|
+
if (formName && traversal.getCurrentObject().getType() === "PROG") {
|
|
15
|
+
ret.appendString(`abap.Forms['PROG-${traversal.getCurrentObject().getName().toUpperCase()}-${formName}'] = ${formName?.toLowerCase()};`);
|
|
16
|
+
}
|
|
17
|
+
return ret;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FormTranspiler = FormTranspiler;
|
|
21
|
+
//# sourceMappingURL=form.js.map
|
|
@@ -91,7 +91,7 @@ class TranspileTypes {
|
|
|
91
91
|
asInclude[c.name.toLowerCase()] = true;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
extra = "{" + list.join("
|
|
94
|
+
extra = "{\n" + list.join(",\n") + "}";
|
|
95
95
|
if (type.getQualifiedName() !== undefined) {
|
|
96
96
|
extra += ", \"" + type.getQualifiedName() + "\"";
|
|
97
97
|
}
|