@abaplint/transpiler 1.7.16 → 1.7.17
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/handle_abap.d.ts +14 -0
- package/build/src/handle_abap.js +173 -0
- package/build/src/handle_table.d.ts +5 -0
- package/build/src/handle_table.js +32 -0
- package/build/src/index.d.ts +2 -56
- package/build/src/index.js +7 -163
- package/build/src/requires.d.ts +1 -1
- package/build/src/statements/data.js +2 -2
- package/build/src/statements/do.js +4 -4
- package/build/src/statements/method_implementation.js +3 -3
- package/build/src/structures/class_implementation.js +2 -2
- package/build/src/structures/interface.js +2 -2
- package/build/src/transpile_types.d.ts +5 -0
- package/build/src/transpile_types.js +115 -0
- package/build/src/traversal.js +3 -3
- package/build/src/types.d.ts +47 -3
- package/build/src/types.js +0 -112
- package/build/src/unit_test.js +42 -37
- package/build/src/validation.d.ts +1 -1
- package/package.json +41 -41
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as abaplint from "@abaplint/core";
|
|
2
|
+
import { IOutputFile, ITranspilerOptions } from "./types";
|
|
3
|
+
import { Chunk } from "./chunk";
|
|
4
|
+
export declare class HandleABAP {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options?: ITranspilerOptions);
|
|
7
|
+
runObject(obj: abaplint.ABAPObject, reg: abaplint.IRegistry): IOutputFile[];
|
|
8
|
+
/** merges the locals def and imp into one mjs file */
|
|
9
|
+
private rearrangeClassLocals;
|
|
10
|
+
protected addImportsAndExports(output: IOutputFile): Chunk;
|
|
11
|
+
protected findExports(node: abaplint.Nodes.StructureNode | undefined): string[];
|
|
12
|
+
protected handleConstants(obj: abaplint.ABAPObject, file: abaplint.ABAPFile, reg: abaplint.IRegistry): string;
|
|
13
|
+
protected findConstants(obj: abaplint.ABAPObject, file: abaplint.ABAPFile, reg: abaplint.IRegistry): Set<string>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandleABAP = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
const traversal_1 = require("./traversal");
|
|
6
|
+
const requires_1 = require("./requires");
|
|
7
|
+
const rearranger_1 = require("./rearranger");
|
|
8
|
+
const chunk_1 = require("./chunk");
|
|
9
|
+
class HandleABAP {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
runObject(obj, reg) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti;
|
|
16
|
+
let ret = [];
|
|
17
|
+
for (const file of obj.getSequencedFiles()) {
|
|
18
|
+
const chunk = new chunk_1.Chunk();
|
|
19
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.addFilenames) === true) {
|
|
20
|
+
chunk.appendString("// " + file.getFilename() + "\n");
|
|
21
|
+
}
|
|
22
|
+
chunk.appendString(this.handleConstants(obj, file, reg));
|
|
23
|
+
const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
|
|
24
|
+
const contents = new traversal_1.Traversal(spaghetti, file, obj, reg, ((_b = this.options) === null || _b === void 0 ? void 0 : _b.unknownTypes) === "runtimeError").traverse(rearranged);
|
|
25
|
+
chunk.appendChunk(contents);
|
|
26
|
+
chunk.stripLastNewline();
|
|
27
|
+
chunk.runIndentationLogic();
|
|
28
|
+
const exports = this.findExports(file.getStructure());
|
|
29
|
+
const filename = file.getFilename().replace(".abap", ".mjs").toLowerCase();
|
|
30
|
+
const output = {
|
|
31
|
+
object: {
|
|
32
|
+
name: obj.getName(),
|
|
33
|
+
type: obj.getType(),
|
|
34
|
+
},
|
|
35
|
+
filename: filename,
|
|
36
|
+
chunk: chunk,
|
|
37
|
+
requires: new requires_1.Requires(reg).find(obj, spaghetti.getTop(), file.getFilename()),
|
|
38
|
+
exports: exports,
|
|
39
|
+
};
|
|
40
|
+
ret.push(output);
|
|
41
|
+
}
|
|
42
|
+
ret = this.rearrangeClassLocals(obj, ret);
|
|
43
|
+
if (((_c = this.options) === null || _c === void 0 ? void 0 : _c.addCommonJS) === true) {
|
|
44
|
+
ret.map(output => output.chunk = this.addImportsAndExports(output));
|
|
45
|
+
}
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
/** merges the locals def and imp into one mjs file */
|
|
49
|
+
rearrangeClassLocals(obj, output) {
|
|
50
|
+
const ret = [];
|
|
51
|
+
if (obj.getType() !== "CLAS") {
|
|
52
|
+
return output;
|
|
53
|
+
}
|
|
54
|
+
let imp = undefined;
|
|
55
|
+
let def = undefined;
|
|
56
|
+
for (const o of output) {
|
|
57
|
+
if (o.filename.endsWith(".clas.locals_imp.mjs")) {
|
|
58
|
+
imp = o;
|
|
59
|
+
}
|
|
60
|
+
else if (o.filename.endsWith(".clas.locals_def.mjs")) {
|
|
61
|
+
def = o;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
ret.push(o);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (def) {
|
|
68
|
+
def.filename = def.filename.replace(".locals_def.mjs", ".locals.mjs");
|
|
69
|
+
}
|
|
70
|
+
if (imp) {
|
|
71
|
+
imp.filename = imp.filename.replace(".locals_imp.mjs", ".locals.mjs");
|
|
72
|
+
}
|
|
73
|
+
if (imp && def) {
|
|
74
|
+
// remove duplicates
|
|
75
|
+
const requires = [...def.requires];
|
|
76
|
+
for (const r of imp.requires) {
|
|
77
|
+
if (requires.find(a => a.filename === r.filename && a.name === r.name) === undefined) {
|
|
78
|
+
requires.push(r);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const chunk = new chunk_1.Chunk().appendChunk(def.chunk).appendChunk(imp.chunk);
|
|
82
|
+
ret.push({
|
|
83
|
+
object: imp.object,
|
|
84
|
+
filename: imp.filename,
|
|
85
|
+
chunk: chunk,
|
|
86
|
+
requires: requires,
|
|
87
|
+
exports: def.exports.concat(imp.exports),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if (imp) {
|
|
91
|
+
ret.push(imp);
|
|
92
|
+
}
|
|
93
|
+
else if (def) {
|
|
94
|
+
ret.push(def);
|
|
95
|
+
}
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
addImportsAndExports(output) {
|
|
99
|
+
var _a;
|
|
100
|
+
const contents = new chunk_1.Chunk();
|
|
101
|
+
for (const r of output.requires) {
|
|
102
|
+
const name = (_a = r.name) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
103
|
+
const filename = r.filename.replace(".abap", ".mjs");
|
|
104
|
+
if (filename === output.filename) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (name) {
|
|
108
|
+
contents.appendString("const {" + name + "} = await import(\"./" + filename + "\");\n");
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
contents.appendString("await import(\"./" + filename + "\");\n");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
contents.appendChunk(output.chunk);
|
|
115
|
+
if (output.exports.length > 0) {
|
|
116
|
+
contents.appendString("\nexport {" + output.exports.join(", ") + "};");
|
|
117
|
+
}
|
|
118
|
+
return contents;
|
|
119
|
+
}
|
|
120
|
+
findExports(node) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
if (node === undefined) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const res = [];
|
|
126
|
+
for (const c of node.findAllStatements(abaplint.Statements.ClassDefinition)) {
|
|
127
|
+
const e = (_a = c.findFirstExpression(abaplint.Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr();
|
|
128
|
+
if (e) {
|
|
129
|
+
res.push(e.toLowerCase());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const c of node.findAllStatements(abaplint.Statements.Interface)) {
|
|
133
|
+
const e = (_b = c.findFirstExpression(abaplint.Expressions.InterfaceName)) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr();
|
|
134
|
+
if (e) {
|
|
135
|
+
res.push(e.toLowerCase());
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return res;
|
|
139
|
+
}
|
|
140
|
+
handleConstants(obj, file, reg) {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
let result = "";
|
|
143
|
+
const constants = this.findConstants(obj, file, reg);
|
|
144
|
+
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) {
|
|
145
|
+
for (const concat of Array.from(constants).sort()) {
|
|
146
|
+
const post = concat.startsWith("-") ? "minus_" : "";
|
|
147
|
+
result += `const constant_${post}${concat.replace("-", "")} = new abap.types.Integer().set(${concat});\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
findConstants(obj, file, reg) {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
let constants = new Set();
|
|
155
|
+
for (const i of ((_a = file.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllExpressions(abaplint.Expressions.Integer)) || []) {
|
|
156
|
+
constants.add(i.concatTokens().replace(" ", ""));
|
|
157
|
+
}
|
|
158
|
+
// extra constants from interfaces, used for default values
|
|
159
|
+
if (obj.getType() === "CLAS") {
|
|
160
|
+
const clas = obj;
|
|
161
|
+
for (const i of ((_b = clas.getClassDefinition()) === null || _b === void 0 ? void 0 : _b.interfaces) || []) {
|
|
162
|
+
const intf = reg.getObject("INTF", i.name);
|
|
163
|
+
const main = intf === null || intf === void 0 ? void 0 : intf.getMainABAPFile();
|
|
164
|
+
if (intf && main) {
|
|
165
|
+
constants = new Set([...constants, ...this.findConstants(intf, main, reg).values()]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return constants;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.HandleABAP = HandleABAP;
|
|
173
|
+
//# sourceMappingURL=handle_abap.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandleTable = void 0;
|
|
4
|
+
const chunk_1 = require("./chunk");
|
|
5
|
+
const transpile_types_1 = require("./transpile_types");
|
|
6
|
+
// tables or structures
|
|
7
|
+
class HandleTable {
|
|
8
|
+
runObject(obj, reg) {
|
|
9
|
+
var _a;
|
|
10
|
+
const filename = (_a = obj.getXMLFile()) === null || _a === void 0 ? void 0 : _a.getFilename().replace(".xml", ".mjs").toLowerCase();
|
|
11
|
+
if (filename === undefined) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const type = obj.parseType(reg);
|
|
15
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
16
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
17
|
+
};`);
|
|
18
|
+
const output = {
|
|
19
|
+
object: {
|
|
20
|
+
name: obj.getName(),
|
|
21
|
+
type: obj.getType(),
|
|
22
|
+
},
|
|
23
|
+
filename: filename,
|
|
24
|
+
chunk: chunk,
|
|
25
|
+
requires: [],
|
|
26
|
+
exports: [],
|
|
27
|
+
};
|
|
28
|
+
return [output];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.HandleTable = HandleTable;
|
|
32
|
+
//# sourceMappingURL=handle_table.js.map
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,65 +1,11 @@
|
|
|
1
1
|
import * as abaplint from "@abaplint/core";
|
|
2
2
|
import { config } from "./validation";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { config };
|
|
6
|
-
export interface IFile {
|
|
7
|
-
filename: string;
|
|
8
|
-
relative?: string;
|
|
9
|
-
contents: string;
|
|
10
|
-
}
|
|
11
|
-
export interface IObjectIdentifier {
|
|
12
|
-
name: string;
|
|
13
|
-
type: string;
|
|
14
|
-
}
|
|
15
|
-
export interface IOutput {
|
|
16
|
-
objects: IOutputFile[];
|
|
17
|
-
reg: abaplint.IRegistry;
|
|
18
|
-
unitTestScript: string;
|
|
19
|
-
initializationScript: string;
|
|
20
|
-
databaseSetup: string;
|
|
21
|
-
}
|
|
22
|
-
export interface IRequire {
|
|
23
|
-
name: string | undefined;
|
|
24
|
-
filename: string;
|
|
25
|
-
}
|
|
26
|
-
export interface IProgress {
|
|
27
|
-
set(total: number, text: string): void;
|
|
28
|
-
tick(text: string): Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
/** one javascript output file for each object */
|
|
31
|
-
export interface IOutputFile {
|
|
32
|
-
object: IObjectIdentifier;
|
|
33
|
-
filename: string;
|
|
34
|
-
chunk: Chunk;
|
|
35
|
-
requires: readonly IRequire[];
|
|
36
|
-
exports: readonly string[];
|
|
37
|
-
}
|
|
38
|
-
export interface ITranspilerOptions {
|
|
39
|
-
/** ignore syntax check, used for internal testing */
|
|
40
|
-
ignoreSyntaxCheck?: boolean;
|
|
41
|
-
/** adds common js modules */
|
|
42
|
-
addCommonJS?: boolean;
|
|
43
|
-
/** adds filenames as comments in the output js */
|
|
44
|
-
addFilenames?: boolean;
|
|
45
|
-
/** skip outputing constants, used for internal testing */
|
|
46
|
-
skipConstants?: boolean;
|
|
47
|
-
/** sets behavior for unknown types, either fail at compile- or run-time */
|
|
48
|
-
unknownTypes?: "compileError" | "runtimeError";
|
|
49
|
-
skip?: TestMethodList;
|
|
50
|
-
only?: TestMethodList;
|
|
51
|
-
}
|
|
3
|
+
import { IFile, IOutput, IProgress, ITranspilerOptions, IOutputFile } from "./types";
|
|
4
|
+
export { config, ITranspilerOptions, IFile, IProgress, IOutputFile };
|
|
52
5
|
export declare class Transpiler {
|
|
53
6
|
private readonly options;
|
|
54
7
|
constructor(options?: ITranspilerOptions);
|
|
55
8
|
runRaw(files: IFile[]): Promise<IOutput>;
|
|
56
9
|
run(reg: abaplint.IRegistry, progress?: IProgress): Promise<IOutput>;
|
|
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<string>;
|
|
59
|
-
protected runObject(obj: abaplint.ABAPObject, reg: abaplint.IRegistry): IOutputFile[];
|
|
60
|
-
/** merges the locals def and imp into one mjs file */
|
|
61
|
-
private rearrangeClassLocals;
|
|
62
|
-
protected addImportsAndExports(output: IOutputFile): Chunk;
|
|
63
|
-
protected findExports(node: abaplint.Nodes.StructureNode | undefined): string[];
|
|
64
10
|
protected validate(reg: abaplint.IRegistry): void;
|
|
65
11
|
}
|
package/build/src/index.js
CHANGED
|
@@ -4,13 +4,11 @@ exports.Transpiler = exports.config = void 0;
|
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
5
|
const validation_1 = require("./validation");
|
|
6
6
|
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return validation_1.config; } });
|
|
7
|
-
const traversal_1 = require("./traversal");
|
|
8
|
-
const requires_1 = require("./requires");
|
|
9
7
|
const unit_test_1 = require("./unit_test");
|
|
10
8
|
const keywords_1 = require("./keywords");
|
|
11
9
|
const database_setup_1 = require("./database_setup");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
10
|
+
const handle_table_1 = require("./handle_table");
|
|
11
|
+
const handle_abap_1 = require("./handle_abap");
|
|
14
12
|
class Transpiler {
|
|
15
13
|
constructor(options) {
|
|
16
14
|
this.options = options;
|
|
@@ -44,6 +42,7 @@ class Transpiler {
|
|
|
44
42
|
for (const obj of reg.getObjects()) {
|
|
45
43
|
await (progress === null || progress === void 0 ? void 0 : progress.tick("Building, Syntax Logic, " + obj.getName()));
|
|
46
44
|
if (obj instanceof abaplint.ABAPObject) {
|
|
45
|
+
// todo, this is already done inside reg.parse()?
|
|
47
46
|
new abaplint.SyntaxLogic(reg, obj).run();
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -51,170 +50,15 @@ class Transpiler {
|
|
|
51
50
|
for (const obj of reg.getObjects()) {
|
|
52
51
|
await (progress === null || progress === void 0 ? void 0 : progress.tick("Building, " + obj.getName()));
|
|
53
52
|
if (obj instanceof abaplint.ABAPObject && !(obj instanceof abaplint.Objects.TypePool)) {
|
|
54
|
-
output.objects
|
|
53
|
+
output.objects.push(...new handle_abap_1.HandleABAP(this.options).runObject(obj, reg));
|
|
54
|
+
}
|
|
55
|
+
else if (obj instanceof abaplint.Objects.Table) {
|
|
56
|
+
output.objects.push(...new handle_table_1.HandleTable().runObject(obj, reg));
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
return output;
|
|
58
60
|
}
|
|
59
61
|
// ///////////////////////////////
|
|
60
|
-
handleConstants(obj, file, reg) {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
let result = "";
|
|
63
|
-
const constants = this.findConstants(obj, file, reg);
|
|
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 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
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
findConstants(obj, file, reg) {
|
|
73
|
-
var _a, _b;
|
|
74
|
-
let constants = new Set();
|
|
75
|
-
for (const i of ((_a = file.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllExpressions(abaplint.Expressions.Integer)) || []) {
|
|
76
|
-
constants.add(i.concatTokens().replace(" ", ""));
|
|
77
|
-
}
|
|
78
|
-
// extra constants from interfaces, used for default values
|
|
79
|
-
if (obj.getType() === "CLAS") {
|
|
80
|
-
const clas = obj;
|
|
81
|
-
for (const i of ((_b = clas.getClassDefinition()) === null || _b === void 0 ? void 0 : _b.interfaces) || []) {
|
|
82
|
-
const intf = reg.getObject("INTF", i.name);
|
|
83
|
-
const main = intf === null || intf === void 0 ? void 0 : intf.getMainABAPFile();
|
|
84
|
-
if (intf && main) {
|
|
85
|
-
constants = new Set([...constants, ...this.findConstants(intf, main, reg).values()]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return constants;
|
|
90
|
-
}
|
|
91
|
-
runObject(obj, reg) {
|
|
92
|
-
var _a, _b, _c;
|
|
93
|
-
const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti;
|
|
94
|
-
let ret = [];
|
|
95
|
-
for (const file of obj.getSequencedFiles()) {
|
|
96
|
-
const chunk = new chunk_1.Chunk();
|
|
97
|
-
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.addFilenames) === true) {
|
|
98
|
-
chunk.appendString("// " + file.getFilename() + "\n");
|
|
99
|
-
}
|
|
100
|
-
chunk.appendString(this.handleConstants(obj, file, reg));
|
|
101
|
-
const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
|
|
102
|
-
const contents = new traversal_1.Traversal(spaghetti, file, obj, reg, ((_b = this.options) === null || _b === void 0 ? void 0 : _b.unknownTypes) === "runtimeError").traverse(rearranged);
|
|
103
|
-
chunk.appendChunk(contents);
|
|
104
|
-
chunk.stripLastNewline();
|
|
105
|
-
chunk.runIndentationLogic();
|
|
106
|
-
const exports = this.findExports(file.getStructure());
|
|
107
|
-
const filename = file.getFilename().replace(".abap", ".mjs").toLowerCase();
|
|
108
|
-
const output = {
|
|
109
|
-
object: {
|
|
110
|
-
name: obj.getName(),
|
|
111
|
-
type: obj.getType(),
|
|
112
|
-
},
|
|
113
|
-
filename: filename,
|
|
114
|
-
chunk: chunk,
|
|
115
|
-
requires: new requires_1.Requires(reg).find(obj, spaghetti.getTop(), file.getFilename()),
|
|
116
|
-
exports: exports,
|
|
117
|
-
};
|
|
118
|
-
ret.push(output);
|
|
119
|
-
}
|
|
120
|
-
ret = this.rearrangeClassLocals(obj, ret);
|
|
121
|
-
if (((_c = this.options) === null || _c === void 0 ? void 0 : _c.addCommonJS) === true) {
|
|
122
|
-
ret.map(output => output.chunk = this.addImportsAndExports(output));
|
|
123
|
-
}
|
|
124
|
-
return ret;
|
|
125
|
-
}
|
|
126
|
-
/** merges the locals def and imp into one mjs file */
|
|
127
|
-
rearrangeClassLocals(obj, output) {
|
|
128
|
-
const ret = [];
|
|
129
|
-
if (obj.getType() !== "CLAS") {
|
|
130
|
-
return output;
|
|
131
|
-
}
|
|
132
|
-
let imp = undefined;
|
|
133
|
-
let def = undefined;
|
|
134
|
-
for (const o of output) {
|
|
135
|
-
if (o.filename.endsWith(".clas.locals_imp.mjs")) {
|
|
136
|
-
imp = o;
|
|
137
|
-
}
|
|
138
|
-
else if (o.filename.endsWith(".clas.locals_def.mjs")) {
|
|
139
|
-
def = o;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
ret.push(o);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (def) {
|
|
146
|
-
def.filename = def.filename.replace(".locals_def.mjs", ".locals.mjs");
|
|
147
|
-
}
|
|
148
|
-
if (imp) {
|
|
149
|
-
imp.filename = imp.filename.replace(".locals_imp.mjs", ".locals.mjs");
|
|
150
|
-
}
|
|
151
|
-
if (imp && def) {
|
|
152
|
-
// remove duplicates
|
|
153
|
-
const requires = [...def.requires];
|
|
154
|
-
for (const r of imp.requires) {
|
|
155
|
-
if (requires.find(a => a.filename === r.filename && a.name === r.name) === undefined) {
|
|
156
|
-
requires.push(r);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const chunk = new chunk_1.Chunk().appendChunk(def.chunk).appendChunk(imp.chunk);
|
|
160
|
-
ret.push({
|
|
161
|
-
object: imp.object,
|
|
162
|
-
filename: imp.filename,
|
|
163
|
-
chunk: chunk,
|
|
164
|
-
requires: requires,
|
|
165
|
-
exports: def.exports.concat(imp.exports),
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
else if (imp) {
|
|
169
|
-
ret.push(imp);
|
|
170
|
-
}
|
|
171
|
-
else if (def) {
|
|
172
|
-
ret.push(def);
|
|
173
|
-
}
|
|
174
|
-
return ret;
|
|
175
|
-
}
|
|
176
|
-
addImportsAndExports(output) {
|
|
177
|
-
var _a;
|
|
178
|
-
const contents = new chunk_1.Chunk();
|
|
179
|
-
for (const r of output.requires) {
|
|
180
|
-
const name = (_a = r.name) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
181
|
-
const filename = r.filename.replace(".abap", ".mjs");
|
|
182
|
-
if (filename === output.filename) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (name) {
|
|
186
|
-
contents.appendString("const {" + name + "} = await import(\"./" + filename + "\");\n");
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
contents.appendString("await import(\"./" + filename + "\");\n");
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
contents.appendChunk(output.chunk);
|
|
193
|
-
if (output.exports.length > 0) {
|
|
194
|
-
contents.appendString("\nexport {" + output.exports.join(", ") + "};");
|
|
195
|
-
}
|
|
196
|
-
return contents;
|
|
197
|
-
}
|
|
198
|
-
findExports(node) {
|
|
199
|
-
var _a, _b;
|
|
200
|
-
if (node === undefined) {
|
|
201
|
-
return [];
|
|
202
|
-
}
|
|
203
|
-
const res = [];
|
|
204
|
-
for (const c of node.findAllStatements(abaplint.Statements.ClassDefinition)) {
|
|
205
|
-
const e = (_a = c.findFirstExpression(abaplint.Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr();
|
|
206
|
-
if (e) {
|
|
207
|
-
res.push(e.toLowerCase());
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
for (const c of node.findAllStatements(abaplint.Statements.Interface)) {
|
|
211
|
-
const e = (_b = c.findFirstExpression(abaplint.Expressions.InterfaceName)) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr();
|
|
212
|
-
if (e) {
|
|
213
|
-
res.push(e.toLowerCase());
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return res;
|
|
217
|
-
}
|
|
218
62
|
validate(reg) {
|
|
219
63
|
const issues = new validation_1.Validation(this.options).run(reg);
|
|
220
64
|
if (issues.length > 0) {
|
package/build/src/requires.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
|
-
const
|
|
5
|
+
const transpile_types_1 = require("../transpile_types");
|
|
6
6
|
const constant_1 = require("../expressions/constant");
|
|
7
7
|
const expressions_1 = require("../expressions");
|
|
8
8
|
const chunk_1 = require("../chunk");
|
|
@@ -40,7 +40,7 @@ class DataTranspiler {
|
|
|
40
40
|
const ret = new chunk_1.Chunk()
|
|
41
41
|
.appendString("let ")
|
|
42
42
|
.append(found.getName().toLowerCase(), token, traversal)
|
|
43
|
-
.appendString(" = " + new
|
|
43
|
+
.appendString(" = " + new transpile_types_1.TranspileTypes().toType(found.getType()))
|
|
44
44
|
.append(";", node.getLastToken(), traversal)
|
|
45
45
|
.append(value, node.getLastToken(), traversal);
|
|
46
46
|
return ret;
|
|
@@ -12,14 +12,14 @@ class DoTranspiler {
|
|
|
12
12
|
const source = new expressions_1.SourceTranspiler(true).transpile(found, traversal).getCode();
|
|
13
13
|
const idSource = unique_identifier_1.UniqueIdentifier.get();
|
|
14
14
|
const id = unique_identifier_1.UniqueIdentifier.get();
|
|
15
|
-
return new chunk_1.Chunk(`const ${idSource} = ${source};
|
|
16
|
-
for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
|
|
15
|
+
return new chunk_1.Chunk(`const ${idSource} = ${source};
|
|
16
|
+
for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
|
|
17
17
|
abap.builtin.sy.get().index.set(${id} + 1);`);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
20
|
const unique = unique_identifier_1.UniqueIdentifier.get();
|
|
21
|
-
return new chunk_1.Chunk(`let ${unique} = 1;
|
|
22
|
-
while (true) {
|
|
21
|
+
return new chunk_1.Chunk(`let ${unique} = 1;
|
|
22
|
+
while (true) {
|
|
23
23
|
abap.builtin.sy.get().index.set(${unique}++);`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MethodImplementationTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
|
-
const
|
|
5
|
+
const transpile_types_1 = require("../transpile_types");
|
|
6
6
|
const expressions_1 = require("../expressions");
|
|
7
7
|
const chunk_1 = require("../chunk");
|
|
8
8
|
class MethodImplementationTranspiler {
|
|
@@ -37,7 +37,7 @@ class MethodImplementationTranspiler {
|
|
|
37
37
|
if (unique === "") {
|
|
38
38
|
unique = "INPUT";
|
|
39
39
|
}
|
|
40
|
-
after = after + new
|
|
40
|
+
after = after + new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
|
|
41
41
|
if (identifier.getMeta().includes("importing" /* MethodImporting */) && identifier.getType().isGeneric() === false) {
|
|
42
42
|
after += "if (" + unique + " && " + unique + "." + varName + ") {" + varName + ".set(" + unique + "." + varName + ");}\n";
|
|
43
43
|
}
|
|
@@ -72,7 +72,7 @@ class MethodImplementationTranspiler {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
else if (identifier.getMeta().includes("returning" /* MethodReturning */)) {
|
|
75
|
-
after = after + new
|
|
75
|
+
after = after + new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
if (after.length > 0) { // argh
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClassImplementationTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
|
-
const
|
|
5
|
+
const transpile_types_1 = require("../transpile_types");
|
|
6
6
|
const expressions_1 = require("../expressions");
|
|
7
7
|
const chunk_1 = require("../chunk");
|
|
8
8
|
class ClassImplementationTranspiler {
|
|
@@ -70,7 +70,7 @@ class ClassImplementationTranspiler {
|
|
|
70
70
|
const staticAttributes = this.findStaticAttributes(cdef, scope);
|
|
71
71
|
for (const attr of staticAttributes) {
|
|
72
72
|
const name = clasName + "." + attr.prefix + attr.identifier.getName().toLowerCase();
|
|
73
|
-
ret += name + " = " + new
|
|
73
|
+
ret += name + " = " + new transpile_types_1.TranspileTypes().toType(attr.identifier.getType()) + ";\n";
|
|
74
74
|
const val = attr.identifier.getValue();
|
|
75
75
|
if (typeof val === "string") {
|
|
76
76
|
const e = new expressions_1.ConstantTranspiler().escape(val);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InterfaceTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
|
-
const
|
|
5
|
+
const transpile_types_1 = require("../transpile_types");
|
|
6
6
|
const expressions_1 = require("../expressions");
|
|
7
7
|
const chunk_1 = require("../chunk");
|
|
8
8
|
class InterfaceTranspiler {
|
|
@@ -42,7 +42,7 @@ class InterfaceTranspiler {
|
|
|
42
42
|
}
|
|
43
43
|
const interfaceName = node.getFirstToken().getStr().toLowerCase();
|
|
44
44
|
const name = interfaceName + "." + interfaceName + "$" + n.toLowerCase();
|
|
45
|
-
ret += name + " = " + new
|
|
45
|
+
ret += name + " = " + new transpile_types_1.TranspileTypes().toType(identifier.getType()) + ";\n";
|
|
46
46
|
const constantStatement = traversal.findStatementInFile(identifier.getStart());
|
|
47
47
|
const valExpression = constantStatement === null || constantStatement === void 0 ? void 0 : constantStatement.findFirstExpression(abaplint.Expressions.Value);
|
|
48
48
|
if ((valExpression === null || valExpression === void 0 ? void 0 : valExpression.getChildren()[1].get()) instanceof abaplint.Expressions.SimpleFieldChain) {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranspileTypes = void 0;
|
|
4
|
+
const abaplint = require("@abaplint/core");
|
|
5
|
+
class TranspileTypes {
|
|
6
|
+
declare(t) {
|
|
7
|
+
const type = t.getType();
|
|
8
|
+
return "let " + t.getName().toLowerCase() + " = " + this.toType(type) + ";";
|
|
9
|
+
}
|
|
10
|
+
toType(type) {
|
|
11
|
+
let resolved = "";
|
|
12
|
+
let extra = "";
|
|
13
|
+
if (type instanceof abaplint.BasicTypes.ObjectReferenceType
|
|
14
|
+
|| type instanceof abaplint.BasicTypes.GenericObjectReferenceType) {
|
|
15
|
+
resolved = "ABAPObject";
|
|
16
|
+
}
|
|
17
|
+
else if (type instanceof abaplint.BasicTypes.TableType) {
|
|
18
|
+
resolved = "Table";
|
|
19
|
+
extra = this.toType(type.getRowType());
|
|
20
|
+
extra += ", " + JSON.stringify(type.getOptions());
|
|
21
|
+
}
|
|
22
|
+
else if (type instanceof abaplint.BasicTypes.IntegerType) {
|
|
23
|
+
resolved = "Integer";
|
|
24
|
+
}
|
|
25
|
+
else if (type instanceof abaplint.BasicTypes.StringType) {
|
|
26
|
+
resolved = "String";
|
|
27
|
+
}
|
|
28
|
+
else if (type instanceof abaplint.BasicTypes.DateType) {
|
|
29
|
+
resolved = "Date";
|
|
30
|
+
}
|
|
31
|
+
else if (type instanceof abaplint.BasicTypes.TimeType) {
|
|
32
|
+
resolved = "Time";
|
|
33
|
+
}
|
|
34
|
+
else if (type instanceof abaplint.BasicTypes.DataReference) {
|
|
35
|
+
resolved = "DataReference";
|
|
36
|
+
extra = this.toType(type.getType());
|
|
37
|
+
}
|
|
38
|
+
else if (type instanceof abaplint.BasicTypes.StructureType) {
|
|
39
|
+
resolved = "Structure";
|
|
40
|
+
const list = [];
|
|
41
|
+
for (const c of type.getComponents()) {
|
|
42
|
+
list.push(c.name.toLowerCase() + ": " + this.toType(c.type));
|
|
43
|
+
}
|
|
44
|
+
extra = "{" + list.join(", ") + "}";
|
|
45
|
+
}
|
|
46
|
+
else if (type instanceof abaplint.BasicTypes.CLikeType
|
|
47
|
+
|| type instanceof abaplint.BasicTypes.CSequenceType) {
|
|
48
|
+
// if not supplied its a Character(1)
|
|
49
|
+
resolved = "Character";
|
|
50
|
+
}
|
|
51
|
+
else if (type instanceof abaplint.BasicTypes.AnyType) {
|
|
52
|
+
// if not supplied its a Character(4)
|
|
53
|
+
resolved = "Character";
|
|
54
|
+
extra = "{length: 4}";
|
|
55
|
+
}
|
|
56
|
+
else if (type instanceof abaplint.BasicTypes.SimpleType) {
|
|
57
|
+
// if not supplied its a Character(1)
|
|
58
|
+
resolved = "Character";
|
|
59
|
+
}
|
|
60
|
+
else if (type instanceof abaplint.BasicTypes.CharacterType) {
|
|
61
|
+
resolved = "Character";
|
|
62
|
+
if (type.getLength() !== 1) {
|
|
63
|
+
extra = "{length: " + type.getLength() + ", qualifiedName: \"" + type.getQualifiedName() + "\"}";
|
|
64
|
+
}
|
|
65
|
+
else if (type.getQualifiedName() !== undefined) {
|
|
66
|
+
extra = "{qualifiedName: \"" + type.getQualifiedName() + "\"}";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (type instanceof abaplint.BasicTypes.NumericType) {
|
|
70
|
+
resolved = "Numc";
|
|
71
|
+
if (type.getLength() !== 1) {
|
|
72
|
+
extra = "{length: " + type.getLength() + "}";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (type instanceof abaplint.BasicTypes.PackedType) {
|
|
76
|
+
resolved = "Packed";
|
|
77
|
+
extra = "{length: " + type.getLength() + ", decimals: " + type.getDecimals() + "}";
|
|
78
|
+
}
|
|
79
|
+
else if (type instanceof abaplint.BasicTypes.NumericGenericType) {
|
|
80
|
+
resolved = "Packed";
|
|
81
|
+
extra = "{length: 8, decimals: 0}";
|
|
82
|
+
}
|
|
83
|
+
else if (type instanceof abaplint.BasicTypes.XStringType) {
|
|
84
|
+
resolved = "XString";
|
|
85
|
+
}
|
|
86
|
+
else if (type instanceof abaplint.BasicTypes.XSequenceType) {
|
|
87
|
+
// if not supplied itsa a Hex(1)
|
|
88
|
+
resolved = "Hex";
|
|
89
|
+
}
|
|
90
|
+
else if (type instanceof abaplint.BasicTypes.HexType) {
|
|
91
|
+
resolved = "Hex";
|
|
92
|
+
if (type.getLength() !== 1) {
|
|
93
|
+
extra = "{length: " + type.getLength() + "}";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (type instanceof abaplint.BasicTypes.FloatType) {
|
|
97
|
+
resolved = "Float";
|
|
98
|
+
}
|
|
99
|
+
else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
|
|
100
|
+
resolved = "DecFloat34";
|
|
101
|
+
}
|
|
102
|
+
else if (type instanceof abaplint.BasicTypes.UnknownType) {
|
|
103
|
+
return `(() => { throw "Unknown type: ${type.getError()}" })()`;
|
|
104
|
+
}
|
|
105
|
+
else if (type instanceof abaplint.BasicTypes.VoidType) {
|
|
106
|
+
return `(() => { throw "Void type: ${type.getVoided()}" })()`;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
resolved = "typeTodo" + type.constructor.name;
|
|
110
|
+
}
|
|
111
|
+
return "new abap.types." + resolved + "(" + extra + ")";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.TranspileTypes = TranspileTypes;
|
|
115
|
+
//# sourceMappingURL=transpile_types.js.map
|
package/build/src/traversal.js
CHANGED
|
@@ -5,7 +5,7 @@ const abaplint = require("@abaplint/core");
|
|
|
5
5
|
const StatementTranspilers = require("./statements");
|
|
6
6
|
const ExpressionTranspilers = require("./expressions");
|
|
7
7
|
const StructureTranspilers = require("./structures");
|
|
8
|
-
const
|
|
8
|
+
const transpile_types_1 = require("./transpile_types");
|
|
9
9
|
const chunk_1 = require("./chunk");
|
|
10
10
|
class Traversal {
|
|
11
11
|
constructor(spaghetti, file, obj, reg, runtimeTypeError = false) {
|
|
@@ -265,7 +265,7 @@ class Traversal {
|
|
|
265
265
|
continue;
|
|
266
266
|
}
|
|
267
267
|
const name = a.getName().toLowerCase();
|
|
268
|
-
ret += "this." + name + " = " + new
|
|
268
|
+
ret += "this." + name + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
|
|
269
269
|
}
|
|
270
270
|
// attributes from directly implemented interfaces(not interfaces implemented in super classes)
|
|
271
271
|
for (const i of def.getImplementing()) {
|
|
@@ -305,7 +305,7 @@ class Traversal {
|
|
|
305
305
|
continue;
|
|
306
306
|
}
|
|
307
307
|
const n = name.toLowerCase() + "$" + a.getName().toLowerCase();
|
|
308
|
-
ret += "this." + n + " = " + new
|
|
308
|
+
ret += "this." + n + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
|
|
309
309
|
}
|
|
310
310
|
for (const i of (intf === null || intf === void 0 ? void 0 : intf.getImplementing()) || []) {
|
|
311
311
|
ret += this.dataFromInterfaces(i.name, scope);
|
package/build/src/types.d.ts
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
|
+
import { Chunk } from "./chunk";
|
|
1
2
|
import * as abaplint from "@abaplint/core";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { TestMethodList } from "./unit_test";
|
|
4
|
+
export interface IFile {
|
|
5
|
+
filename: string;
|
|
6
|
+
relative?: string;
|
|
7
|
+
contents: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IObjectIdentifier {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}
|
|
13
|
+
export interface IOutput {
|
|
14
|
+
objects: IOutputFile[];
|
|
15
|
+
reg: abaplint.IRegistry;
|
|
16
|
+
unitTestScript: string;
|
|
17
|
+
initializationScript: string;
|
|
18
|
+
databaseSetup: string;
|
|
19
|
+
}
|
|
20
|
+
export interface IRequire {
|
|
21
|
+
name: string | undefined;
|
|
22
|
+
filename: string;
|
|
23
|
+
}
|
|
24
|
+
export interface IProgress {
|
|
25
|
+
set(total: number, text: string): void;
|
|
26
|
+
tick(text: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** one javascript output file for each object */
|
|
29
|
+
export interface IOutputFile {
|
|
30
|
+
object: IObjectIdentifier;
|
|
31
|
+
filename: string;
|
|
32
|
+
chunk: Chunk;
|
|
33
|
+
requires: readonly IRequire[];
|
|
34
|
+
exports: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
export interface ITranspilerOptions {
|
|
37
|
+
/** ignore syntax check, used for internal testing */
|
|
38
|
+
ignoreSyntaxCheck?: boolean;
|
|
39
|
+
/** adds common js modules */
|
|
40
|
+
addCommonJS?: boolean;
|
|
41
|
+
/** adds filenames as comments in the output js */
|
|
42
|
+
addFilenames?: boolean;
|
|
43
|
+
/** skip outputing constants, used for internal testing */
|
|
44
|
+
skipConstants?: boolean;
|
|
45
|
+
/** sets behavior for unknown types, either fail at compile- or run-time */
|
|
46
|
+
unknownTypes?: "compileError" | "runtimeError";
|
|
47
|
+
skip?: TestMethodList;
|
|
48
|
+
only?: TestMethodList;
|
|
5
49
|
}
|
package/build/src/types.js
CHANGED
|
@@ -1,115 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TranspileTypes = void 0;
|
|
4
|
-
const abaplint = require("@abaplint/core");
|
|
5
|
-
class TranspileTypes {
|
|
6
|
-
declare(t) {
|
|
7
|
-
const type = t.getType();
|
|
8
|
-
return "let " + t.getName().toLowerCase() + " = " + this.toType(type) + ";";
|
|
9
|
-
}
|
|
10
|
-
toType(type) {
|
|
11
|
-
let resolved = "";
|
|
12
|
-
let extra = "";
|
|
13
|
-
if (type instanceof abaplint.BasicTypes.ObjectReferenceType
|
|
14
|
-
|| type instanceof abaplint.BasicTypes.GenericObjectReferenceType) {
|
|
15
|
-
resolved = "ABAPObject";
|
|
16
|
-
}
|
|
17
|
-
else if (type instanceof abaplint.BasicTypes.TableType) {
|
|
18
|
-
resolved = "Table";
|
|
19
|
-
extra = this.toType(type.getRowType());
|
|
20
|
-
extra += ", " + JSON.stringify(type.getOptions());
|
|
21
|
-
}
|
|
22
|
-
else if (type instanceof abaplint.BasicTypes.IntegerType) {
|
|
23
|
-
resolved = "Integer";
|
|
24
|
-
}
|
|
25
|
-
else if (type instanceof abaplint.BasicTypes.StringType) {
|
|
26
|
-
resolved = "String";
|
|
27
|
-
}
|
|
28
|
-
else if (type instanceof abaplint.BasicTypes.DateType) {
|
|
29
|
-
resolved = "Date";
|
|
30
|
-
}
|
|
31
|
-
else if (type instanceof abaplint.BasicTypes.TimeType) {
|
|
32
|
-
resolved = "Time";
|
|
33
|
-
}
|
|
34
|
-
else if (type instanceof abaplint.BasicTypes.DataReference) {
|
|
35
|
-
resolved = "DataReference";
|
|
36
|
-
extra = this.toType(type.getType());
|
|
37
|
-
}
|
|
38
|
-
else if (type instanceof abaplint.BasicTypes.StructureType) {
|
|
39
|
-
resolved = "Structure";
|
|
40
|
-
const list = [];
|
|
41
|
-
for (const c of type.getComponents()) {
|
|
42
|
-
list.push(c.name.toLowerCase() + ": " + this.toType(c.type));
|
|
43
|
-
}
|
|
44
|
-
extra = "{" + list.join(", ") + "}";
|
|
45
|
-
}
|
|
46
|
-
else if (type instanceof abaplint.BasicTypes.CLikeType
|
|
47
|
-
|| type instanceof abaplint.BasicTypes.CSequenceType) {
|
|
48
|
-
// if not supplied its a Character(1)
|
|
49
|
-
resolved = "Character";
|
|
50
|
-
}
|
|
51
|
-
else if (type instanceof abaplint.BasicTypes.AnyType) {
|
|
52
|
-
// if not supplied its a Character(4)
|
|
53
|
-
resolved = "Character";
|
|
54
|
-
extra = "{length: 4}";
|
|
55
|
-
}
|
|
56
|
-
else if (type instanceof abaplint.BasicTypes.SimpleType) {
|
|
57
|
-
// if not supplied its a Character(1)
|
|
58
|
-
resolved = "Character";
|
|
59
|
-
}
|
|
60
|
-
else if (type instanceof abaplint.BasicTypes.CharacterType) {
|
|
61
|
-
resolved = "Character";
|
|
62
|
-
if (type.getLength() !== 1) {
|
|
63
|
-
extra = "{length: " + type.getLength() + ", qualifiedName: \"" + type.getQualifiedName() + "\"}";
|
|
64
|
-
}
|
|
65
|
-
else if (type.getQualifiedName() !== undefined) {
|
|
66
|
-
extra = "{qualifiedName: \"" + type.getQualifiedName() + "\"}";
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (type instanceof abaplint.BasicTypes.NumericType) {
|
|
70
|
-
resolved = "Numc";
|
|
71
|
-
if (type.getLength() !== 1) {
|
|
72
|
-
extra = "{length: " + type.getLength() + "}";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else if (type instanceof abaplint.BasicTypes.PackedType) {
|
|
76
|
-
resolved = "Packed";
|
|
77
|
-
extra = "{length: " + type.getLength() + ", decimals: " + type.getDecimals() + "}";
|
|
78
|
-
}
|
|
79
|
-
else if (type instanceof abaplint.BasicTypes.NumericGenericType) {
|
|
80
|
-
resolved = "Packed";
|
|
81
|
-
extra = "{length: 8, decimals: 0}";
|
|
82
|
-
}
|
|
83
|
-
else if (type instanceof abaplint.BasicTypes.XStringType) {
|
|
84
|
-
resolved = "XString";
|
|
85
|
-
}
|
|
86
|
-
else if (type instanceof abaplint.BasicTypes.XSequenceType) {
|
|
87
|
-
// if not supplied itsa a Hex(1)
|
|
88
|
-
resolved = "Hex";
|
|
89
|
-
}
|
|
90
|
-
else if (type instanceof abaplint.BasicTypes.HexType) {
|
|
91
|
-
resolved = "Hex";
|
|
92
|
-
if (type.getLength() !== 1) {
|
|
93
|
-
extra = "{length: " + type.getLength() + "}";
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else if (type instanceof abaplint.BasicTypes.FloatType) {
|
|
97
|
-
resolved = "Float";
|
|
98
|
-
}
|
|
99
|
-
else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
|
|
100
|
-
resolved = "DecFloat34";
|
|
101
|
-
}
|
|
102
|
-
else if (type instanceof abaplint.BasicTypes.UnknownType) {
|
|
103
|
-
return `(() => { throw "Unknown type: ${type.getError()}" })()`;
|
|
104
|
-
}
|
|
105
|
-
else if (type instanceof abaplint.BasicTypes.VoidType) {
|
|
106
|
-
return `(() => { throw "Void type: ${type.getVoided()}" })()`;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
resolved = "typeTodo" + type.constructor.name;
|
|
110
|
-
}
|
|
111
|
-
return "new abap.types." + resolved + "(" + extra + ")";
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.TranspileTypes = TranspileTypes;
|
|
115
3
|
//# sourceMappingURL=types.js.map
|
package/build/src/unit_test.js
CHANGED
|
@@ -5,9 +5,9 @@ const abaplint = require("@abaplint/core");
|
|
|
5
5
|
class UnitTest {
|
|
6
6
|
// todo, move this somewhere else, its much more than just unit test relevant
|
|
7
7
|
initializationScript(reg, dbSetup) {
|
|
8
|
-
let ret = `import runtime from "@abaplint/runtime";
|
|
9
|
-
global.abap = new runtime.ABAP();
|
|
10
|
-
${this.buildImports(reg)}
|
|
8
|
+
let ret = `import runtime from "@abaplint/runtime";
|
|
9
|
+
global.abap = new runtime.ABAP();
|
|
10
|
+
${this.buildImports(reg)}
|
|
11
11
|
export async function initializeABAP(settings) {\n`;
|
|
12
12
|
if (dbSetup === "") {
|
|
13
13
|
ret += `// no database artifacts, skip DB initialization\n`;
|
|
@@ -19,20 +19,20 @@ export async function initializeABAP(settings) {\n`;
|
|
|
19
19
|
return ret;
|
|
20
20
|
}
|
|
21
21
|
unitTestScript(reg, skip, _only) {
|
|
22
|
-
let ret = `import fs from "fs";
|
|
23
|
-
import path from "path";
|
|
24
|
-
import {dirname} from 'path';
|
|
25
|
-
import {fileURLToPath} from 'url';
|
|
26
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
27
|
-
import {initializeABAP} from "./init.mjs";
|
|
28
|
-
import runtime from "@abaplint/runtime";
|
|
29
|
-
|
|
30
|
-
async function run() {
|
|
31
|
-
await initializeABAP();
|
|
32
|
-
const unit = new runtime.UnitTestResult();
|
|
33
|
-
let clas;
|
|
34
|
-
let locl;
|
|
35
|
-
let meth;
|
|
22
|
+
let ret = `import fs from "fs";
|
|
23
|
+
import path from "path";
|
|
24
|
+
import {dirname} from 'path';
|
|
25
|
+
import {fileURLToPath} from 'url';
|
|
26
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
import {initializeABAP} from "./init.mjs";
|
|
28
|
+
import runtime from "@abaplint/runtime";
|
|
29
|
+
|
|
30
|
+
async function run() {
|
|
31
|
+
await initializeABAP();
|
|
32
|
+
const unit = new runtime.UnitTestResult();
|
|
33
|
+
let clas;
|
|
34
|
+
let locl;
|
|
35
|
+
let meth;
|
|
36
36
|
try {\n`;
|
|
37
37
|
for (const obj of reg.getObjects()) {
|
|
38
38
|
if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
|
|
@@ -47,8 +47,8 @@ try {\n`;
|
|
|
47
47
|
|| def.methods.length === 0) {
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
|
-
ret += `{
|
|
51
|
-
const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
|
|
50
|
+
ret += `{
|
|
51
|
+
const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
|
|
52
52
|
locl = clas.addTestClass("${def.name}");\n`;
|
|
53
53
|
ret += `if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
|
|
54
54
|
for (const m of def.methods) {
|
|
@@ -76,24 +76,24 @@ locl = clas.addTestClass("${def.name}");\n`;
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
ret += `// -------------------END-------------------
|
|
80
|
-
console.log(abap.console.get());
|
|
81
|
-
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
82
|
-
} catch (e) {
|
|
83
|
-
if (meth) {
|
|
84
|
-
meth.fail();
|
|
85
|
-
}
|
|
86
|
-
console.log(abap.console.get());
|
|
87
|
-
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
run().then(() => {
|
|
93
|
-
process.exit(0);
|
|
94
|
-
}).catch((err) => {
|
|
95
|
-
console.log(err);
|
|
96
|
-
process.exit(1);
|
|
79
|
+
ret += `// -------------------END-------------------
|
|
80
|
+
console.log(abap.console.get());
|
|
81
|
+
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
82
|
+
} catch (e) {
|
|
83
|
+
if (meth) {
|
|
84
|
+
meth.fail();
|
|
85
|
+
}
|
|
86
|
+
console.log(abap.console.get());
|
|
87
|
+
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
run().then(() => {
|
|
93
|
+
process.exit(0);
|
|
94
|
+
}).catch((err) => {
|
|
95
|
+
console.log(err);
|
|
96
|
+
process.exit(1);
|
|
97
97
|
});`;
|
|
98
98
|
return ret;
|
|
99
99
|
}
|
|
@@ -102,6 +102,11 @@ run().then(() => {
|
|
|
102
102
|
// todo, some sorting might be required? eg. a class constructor using constant from interface?
|
|
103
103
|
// temporary sorting: by filename
|
|
104
104
|
const list = [];
|
|
105
|
+
for (const obj of reg.getObjects()) {
|
|
106
|
+
if (obj instanceof abaplint.Objects.Table) {
|
|
107
|
+
list.push(`await import("./${obj.getName().toLowerCase()}.tabl.mjs");`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
105
110
|
for (const obj of reg.getObjects()) {
|
|
106
111
|
if (obj instanceof abaplint.Objects.FunctionGroup) {
|
|
107
112
|
for (const m of obj.getModules()) {
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "Transpiler",
|
|
5
|
-
"main": "build/src/index.js",
|
|
6
|
-
"typings": "build/src/index.d.ts",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/abaplint/transpiler.git"
|
|
10
|
-
},
|
|
11
|
-
"scripts": {
|
|
12
|
-
"compile": "tsc",
|
|
13
|
-
"publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
14
|
-
"publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
15
|
-
"test": "npm run compile && mocha"
|
|
16
|
-
},
|
|
17
|
-
"mocha": {
|
|
18
|
-
"recursive": true,
|
|
19
|
-
"reporter": "progress",
|
|
20
|
-
"spec": "build/test/**/*.js",
|
|
21
|
-
"require": "source-map-support/register"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"ABAP",
|
|
25
|
-
"abaplint"
|
|
26
|
-
],
|
|
27
|
-
"author": "abaplint",
|
|
28
|
-
"license": "MIT",
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"@abaplint/core": "^2.83.23",
|
|
31
|
-
"source-map": "^0.7.3"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@types/chai": "^4.3.0",
|
|
35
|
-
"@types/mocha": "^9.0.0",
|
|
36
|
-
"chai": "^4.3.4",
|
|
37
|
-
"mocha": "^9.1.4",
|
|
38
|
-
"source-map-support": "^0.5.21",
|
|
39
|
-
"typescript": "^4.5.4"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@abaplint/transpiler",
|
|
3
|
+
"version": "1.7.17",
|
|
4
|
+
"description": "Transpiler",
|
|
5
|
+
"main": "build/src/index.js",
|
|
6
|
+
"typings": "build/src/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/abaplint/transpiler.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"compile": "tsc",
|
|
13
|
+
"publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
14
|
+
"publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
15
|
+
"test": "npm run compile && mocha"
|
|
16
|
+
},
|
|
17
|
+
"mocha": {
|
|
18
|
+
"recursive": true,
|
|
19
|
+
"reporter": "progress",
|
|
20
|
+
"spec": "build/test/**/*.js",
|
|
21
|
+
"require": "source-map-support/register"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"ABAP",
|
|
25
|
+
"abaplint"
|
|
26
|
+
],
|
|
27
|
+
"author": "abaplint",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@abaplint/core": "^2.83.23",
|
|
31
|
+
"source-map": "^0.7.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/chai": "^4.3.0",
|
|
35
|
+
"@types/mocha": "^9.0.0",
|
|
36
|
+
"chai": "^4.3.4",
|
|
37
|
+
"mocha": "^9.1.4",
|
|
38
|
+
"source-map-support": "^0.5.21",
|
|
39
|
+
"typescript": "^4.5.4"
|
|
40
|
+
}
|
|
41
|
+
}
|