@abaplint/transpiler 2.8.29 → 2.9.0
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/function_parameters.js +3 -8
- package/build/src/expressions/parameter_name.js +2 -1
- package/build/src/handlers/handle_fugr.d.ts +7 -0
- package/build/src/handlers/handle_fugr.js +41 -0
- package/build/src/index.js +4 -0
- package/build/src/requires.js +14 -0
- package/build/src/statements/include.d.ts +1 -1
- package/build/src/statements/include.js +22 -1
- package/build/src/traversal.d.ts +1 -0
- package/build/src/traversal.js +15 -0
- package/build/src/unit_test.js +1 -3
- package/package.json +1 -1
|
@@ -21,16 +21,11 @@ class FunctionParametersTranspiler {
|
|
|
21
21
|
if (ch) {
|
|
22
22
|
params.changing = traversal.traverse(ch).getCode();
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const ret = [];
|
|
25
25
|
for (const p of Object.keys(params)) {
|
|
26
|
-
|
|
27
|
-
ret += p + ": " + params[p];
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
ret += ", " + p + ": " + params[p];
|
|
31
|
-
}
|
|
26
|
+
ret.push(p + ": " + params[p]);
|
|
32
27
|
}
|
|
33
|
-
return new chunk_1.Chunk(`{${ret}}`);
|
|
28
|
+
return new chunk_1.Chunk(`{${ret.join(", ")}}`);
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
31
|
exports.FunctionParametersTranspiler = FunctionParametersTranspiler;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParameterNameTranspiler = void 0;
|
|
4
|
+
const traversal_1 = require("../traversal");
|
|
4
5
|
const chunk_1 = require("../chunk");
|
|
5
6
|
class ParameterNameTranspiler {
|
|
6
7
|
transpile(node, traversal) {
|
|
7
8
|
const nameToken = node.getFirstToken();
|
|
8
|
-
const name = nameToken.getStr().toLowerCase();
|
|
9
|
+
const name = traversal_1.Traversal.escapeNamespace(nameToken.getStr().toLowerCase());
|
|
9
10
|
return new chunk_1.Chunk().append(name, nameToken, traversal);
|
|
10
11
|
}
|
|
11
12
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as abaplint from "@abaplint/core";
|
|
2
|
+
import { IOutputFile, ITranspilerOptions } from "../types";
|
|
3
|
+
export declare class HandleFUGR {
|
|
4
|
+
private readonly options;
|
|
5
|
+
constructor(options?: ITranspilerOptions);
|
|
6
|
+
runObject(obj: abaplint.ABAPObject, reg: abaplint.IRegistry): IOutputFile[];
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandleFUGR = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
const traversal_1 = require("../traversal");
|
|
6
|
+
const rearranger_1 = require("../rearranger");
|
|
7
|
+
const chunk_1 = require("../chunk");
|
|
8
|
+
class HandleFUGR {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
// function groups are compiled into a single file, with one closure for the function groups top variables
|
|
13
|
+
runObject(obj, reg) {
|
|
14
|
+
const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti;
|
|
15
|
+
const chunk = new chunk_1.Chunk().appendString("{\n");
|
|
16
|
+
for (const file of obj.getSequencedFiles()) {
|
|
17
|
+
if (this.options?.addFilenames === true) {
|
|
18
|
+
chunk.appendString("// " + file.getFilename() + "\n");
|
|
19
|
+
}
|
|
20
|
+
const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
|
|
21
|
+
const contents = new traversal_1.Traversal(spaghetti, file, obj, reg, this.options).traverse(rearranged);
|
|
22
|
+
chunk.appendChunk(contents);
|
|
23
|
+
chunk.stripLastNewline();
|
|
24
|
+
chunk.runIndentationLogic(this.options?.ignoreSourceMap);
|
|
25
|
+
}
|
|
26
|
+
chunk.appendString("\n}");
|
|
27
|
+
const output = {
|
|
28
|
+
object: {
|
|
29
|
+
name: obj.getName(),
|
|
30
|
+
type: obj.getType(),
|
|
31
|
+
},
|
|
32
|
+
filename: obj.getName().toLowerCase().replace(/\//g, "#") + ".fugr.mjs",
|
|
33
|
+
chunk: chunk,
|
|
34
|
+
requires: [],
|
|
35
|
+
exports: [],
|
|
36
|
+
};
|
|
37
|
+
return [output];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.HandleFUGR = HandleFUGR;
|
|
41
|
+
//# sourceMappingURL=handle_fugr.js.map
|
package/build/src/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const handle_w3mi_1 = require("./handlers/handle_w3mi");
|
|
|
20
20
|
const handle_smim_1 = require("./handlers/handle_smim");
|
|
21
21
|
const handle_msag_1 = require("./handlers/handle_msag");
|
|
22
22
|
const handle_oa2p_1 = require("./handlers/handle_oa2p");
|
|
23
|
+
const handle_fugr_1 = require("./handlers/handle_fugr");
|
|
23
24
|
class Transpiler {
|
|
24
25
|
constructor(options) {
|
|
25
26
|
this.options = options;
|
|
@@ -56,6 +57,9 @@ class Transpiler {
|
|
|
56
57
|
if (obj instanceof abaplint.Objects.TypePool) {
|
|
57
58
|
output.objects.push(...new handle_type_pool_1.HandleTypePool().runObject(obj, reg));
|
|
58
59
|
}
|
|
60
|
+
else if (obj instanceof abaplint.Objects.FunctionGroup) {
|
|
61
|
+
output.objects.push(...new handle_fugr_1.HandleFUGR(this.options).runObject(obj, reg));
|
|
62
|
+
}
|
|
59
63
|
else if (obj instanceof abaplint.ABAPObject) {
|
|
60
64
|
output.objects.push(...new handle_abap_1.HandleABAP(this.options).runObject(obj, reg));
|
|
61
65
|
}
|
package/build/src/requires.js
CHANGED
|
@@ -55,6 +55,20 @@ class Requires {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
/*
|
|
59
|
+
else if (obj.getType() === "FUGR") {
|
|
60
|
+
const fugr = obj as abaplint.Objects.FunctionGroup;
|
|
61
|
+
const functionModules = fugr.getModules();
|
|
62
|
+
const isFunctionModule = functionModules.find((f) => filename.includes("." + f.getName().toLowerCase() + ".")) !== undefined;
|
|
63
|
+
if (isFunctionModule) {
|
|
64
|
+
const name = Traversal.escapeNamespace(fugr.getName())?.toLowerCase();
|
|
65
|
+
add({
|
|
66
|
+
filename: name + ".fugr.sapl" + name + ".abap",
|
|
67
|
+
name: undefined,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
*/
|
|
58
72
|
// always add CX_ROOT, it is used for CATCH, no catches in global interfaces
|
|
59
73
|
// todo, it might be possible to remove this, as CATCH uses instanceof with dynamic registered classes
|
|
60
74
|
if (obj.getType() !== "INTF") {
|
|
@@ -3,5 +3,5 @@ import { IStatementTranspiler } from "./_statement_transpiler";
|
|
|
3
3
|
import { Traversal } from "../traversal";
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class IncludeTranspiler implements IStatementTranspiler {
|
|
6
|
-
transpile(
|
|
6
|
+
transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
|
|
7
7
|
}
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IncludeTranspiler = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
const traversal_1 = require("../traversal");
|
|
4
6
|
const chunk_1 = require("../chunk");
|
|
7
|
+
const rearranger_1 = require("../rearranger");
|
|
5
8
|
class IncludeTranspiler {
|
|
6
|
-
transpile(
|
|
9
|
+
transpile(node, traversal) {
|
|
10
|
+
const includeName = node.findDirectExpression(abaplint.Expressions.IncludeName)?.concatTokens();
|
|
11
|
+
if (includeName === undefined) {
|
|
12
|
+
throw new Error("INCLUDE, IncludeName not found");
|
|
13
|
+
}
|
|
14
|
+
const obj = traversal.getCurrentObject();
|
|
15
|
+
if (obj instanceof abaplint.Objects.FunctionGroup) {
|
|
16
|
+
if (includeName.toUpperCase().endsWith("XX") === false) {
|
|
17
|
+
const include = obj.getInclude(includeName);
|
|
18
|
+
if (include === undefined) {
|
|
19
|
+
throw new Error(`Include ${includeName} not found`);
|
|
20
|
+
}
|
|
21
|
+
const sub = new traversal_1.Traversal(traversal.getSpaghetti(), include, traversal.getCurrentObject(), traversal.reg, traversal.options);
|
|
22
|
+
const rearranged = new rearranger_1.Rearranger().run(obj.getType(), include.getStructure());
|
|
23
|
+
const chunk = sub.traverse(rearranged);
|
|
24
|
+
// console.dir(chunk.getCode());
|
|
25
|
+
return chunk;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
7
28
|
// todo, this will not work
|
|
8
29
|
return new chunk_1.Chunk("");
|
|
9
30
|
}
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class Traversal {
|
|
|
19
19
|
findStatementInFile(pos: abaplint.Position): abaplint.Nodes.StatementNode | undefined;
|
|
20
20
|
private scopeCache;
|
|
21
21
|
findCurrentScopeByToken(token: abaplint.Token): abaplint.ISpaghettiScopeNode | undefined;
|
|
22
|
+
private fuctionGroupWorkaround;
|
|
22
23
|
getInterfaceDefinition(token: abaplint.Token): abaplint.IInterfaceDefinition | undefined;
|
|
23
24
|
getClassDefinition(token: abaplint.Token): abaplint.IClassDefinition | undefined;
|
|
24
25
|
private isClassAttribute;
|
package/build/src/traversal.js
CHANGED
|
@@ -78,8 +78,23 @@ class Traversal {
|
|
|
78
78
|
else {
|
|
79
79
|
this.scopeCache = undefined;
|
|
80
80
|
}
|
|
81
|
+
if (node === undefined
|
|
82
|
+
&& this.obj instanceof abaplint.Objects.FunctionGroup
|
|
83
|
+
&& this.obj.getInclude(filename.split(".")[2])) {
|
|
84
|
+
// workaround for INCLUDEs in function groups
|
|
85
|
+
return this.fuctionGroupWorkaround(token);
|
|
86
|
+
}
|
|
81
87
|
return node;
|
|
82
88
|
}
|
|
89
|
+
fuctionGroupWorkaround(token) {
|
|
90
|
+
// check the function group level, it might be an INCLUDE defining the DATA
|
|
91
|
+
const functionGroupLevel = this.spaghetti.getFirstChild()?.getFirstChild();
|
|
92
|
+
const variable = functionGroupLevel?.getData().vars[token.getStr().toUpperCase()];
|
|
93
|
+
if (variable?.getStart().equals(token.getStart())) {
|
|
94
|
+
return functionGroupLevel;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
83
98
|
getInterfaceDefinition(token) {
|
|
84
99
|
let scope = this.findCurrentScopeByToken(token);
|
|
85
100
|
while (scope !== undefined) {
|
package/build/src/unit_test.js
CHANGED
|
@@ -336,9 +336,7 @@ run().then(() => {
|
|
|
336
336
|
}
|
|
337
337
|
for (const obj of reg.getObjects()) {
|
|
338
338
|
if (obj instanceof abaplint.Objects.FunctionGroup) {
|
|
339
|
-
|
|
340
|
-
list.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.fugr.${this.escapeNamespace(m.getName().toLowerCase())}`));
|
|
341
|
-
}
|
|
339
|
+
list.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.fugr`));
|
|
342
340
|
}
|
|
343
341
|
else if (obj instanceof abaplint.Objects.Class) {
|
|
344
342
|
if (obj.getName().toUpperCase() !== "CL_ABAP_CHAR_UTILITIES"
|