@abaplint/transpiler 1.7.44 → 1.8.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/constant.js +4 -0
- package/build/src/expressions/source.js +4 -5
- package/build/src/expressions/string_template.js +1 -1
- package/build/src/handle_data_element.js +2 -2
- package/build/src/handle_table.js +3 -3
- package/build/src/handle_table_type.js +2 -2
- package/build/src/statements/do.js +4 -4
- package/build/src/unit_test.js +66 -67
- package/package.json +41 -41
|
@@ -28,6 +28,10 @@ class ConstantTranspiler {
|
|
|
28
28
|
const code = "new abap.types.Character({length: " + (res.length - 2) + "}).set(" + this.escape(res) + ")";
|
|
29
29
|
return new chunk_1.Chunk().append(code, node, traversal);
|
|
30
30
|
}
|
|
31
|
+
else if (res.startsWith("`") && this.addGet === false) {
|
|
32
|
+
const code = "new abap.types.String().set(" + this.escape(res) + ")";
|
|
33
|
+
return new chunk_1.Chunk().append(code, node, traversal);
|
|
34
|
+
}
|
|
31
35
|
else {
|
|
32
36
|
if (res.startsWith("'")) {
|
|
33
37
|
res = "'" + res.substring(1, res.length - 1).trimEnd() + "'";
|
|
@@ -66,11 +66,10 @@ class SourceTranspiler {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else if (c instanceof core_1.Nodes.TokenNode && (c.getFirstToken().getStr() === "&&" || c.getFirstToken().getStr() === "&")) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
ret.append(" + ", c, traversal);
|
|
69
|
+
ret = new chunk_1.Chunk().appendString("abap.operators.concat(").appendChunk(ret).appendString(",");
|
|
70
|
+
post.appendString(")");
|
|
71
|
+
if (this.addGet) {
|
|
72
|
+
post.append(".get()", c, traversal);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
else if (c instanceof core_1.Nodes.TokenNodeRegex && c.getFirstToken().getStr().toUpperCase() === "BOOLC") {
|
|
@@ -33,7 +33,7 @@ class StringTemplateTranspiler {
|
|
|
33
33
|
ret += new _1.StringTemplateSourceTranspiler().transpile(c, traversal).getCode();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return new chunk_1.Chunk(ret);
|
|
36
|
+
return new chunk_1.Chunk("new abap.types.String().set(" + ret + ")");
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.StringTemplateTranspiler = StringTemplateTranspiler;
|
|
@@ -11,8 +11,8 @@ class HandleDataElement {
|
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
13
13
|
const type = obj.parseType(reg);
|
|
14
|
-
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
15
|
-
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
14
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
15
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
16
16
|
};`);
|
|
17
17
|
const output = {
|
|
18
18
|
object: {
|
|
@@ -12,9 +12,9 @@ class HandleTable {
|
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
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
|
-
"keyFields": ${JSON.stringify(obj.listKeys())},
|
|
15
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
16
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
17
|
+
"keyFields": ${JSON.stringify(obj.listKeys())},
|
|
18
18
|
};`);
|
|
19
19
|
const output = {
|
|
20
20
|
object: {
|
|
@@ -11,8 +11,8 @@ class HandleTableType {
|
|
|
11
11
|
return [];
|
|
12
12
|
}
|
|
13
13
|
const type = obj.parseType(reg);
|
|
14
|
-
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
15
|
-
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
14
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
15
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
16
16
|
};`);
|
|
17
17
|
const output = {
|
|
18
18
|
object: {
|
|
@@ -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
|
}
|
package/build/src/unit_test.js
CHANGED
|
@@ -6,9 +6,9 @@ const abaplint = require("@abaplint/core");
|
|
|
6
6
|
class UnitTest {
|
|
7
7
|
// todo, move this somewhere else, its much more than just unit test relevant
|
|
8
8
|
initializationScript(reg, dbSetup) {
|
|
9
|
-
let ret = `import runtime from "@abaplint/runtime";
|
|
10
|
-
global.abap = new runtime.ABAP();
|
|
11
|
-
${this.buildImports(reg)}
|
|
9
|
+
let ret = `import runtime from "@abaplint/runtime";
|
|
10
|
+
global.abap = new runtime.ABAP();
|
|
11
|
+
${this.buildImports(reg)}
|
|
12
12
|
export async function initializeABAP(settings) {\n`;
|
|
13
13
|
if (dbSetup === "") {
|
|
14
14
|
ret += `// no database artifacts, skip DB initialization\n`;
|
|
@@ -20,19 +20,19 @@ export async function initializeABAP(settings) {\n`;
|
|
|
20
20
|
return ret;
|
|
21
21
|
}
|
|
22
22
|
unitTestScriptOpen(reg, _skip, _only) {
|
|
23
|
-
let ret = `/* eslint-disable curly */
|
|
24
|
-
import fs from "fs";
|
|
25
|
-
import path from "path";
|
|
26
|
-
import {fileURLToPath} from "url";
|
|
27
|
-
import {initializeABAP} from "./init.mjs";
|
|
28
|
-
|
|
29
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
-
|
|
31
|
-
async function run() {
|
|
32
|
-
await initializeABAP();
|
|
33
|
-
let lt_input = new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30})}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]});
|
|
34
|
-
let ls_input = new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30})});
|
|
35
|
-
let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30}), expected: new abap.types.String(), actual: new abap.types.String(), status: new abap.types.String(), runtime: new abap.types.Integer(), message: new abap.types.String(), js_location: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
|
|
23
|
+
let ret = `/* eslint-disable curly */
|
|
24
|
+
import fs from "fs";
|
|
25
|
+
import path from "path";
|
|
26
|
+
import {fileURLToPath} from "url";
|
|
27
|
+
import {initializeABAP} from "./init.mjs";
|
|
28
|
+
|
|
29
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
|
|
31
|
+
async function run() {
|
|
32
|
+
await initializeABAP();
|
|
33
|
+
let lt_input = new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30})}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]});
|
|
34
|
+
let ls_input = new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30})});
|
|
35
|
+
let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30}), expected: new abap.types.String(), actual: new abap.types.String(), status: new abap.types.String(), runtime: new abap.types.Integer(), message: new abap.types.String(), js_location: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
|
|
36
36
|
`;
|
|
37
37
|
for (const obj of reg.getObjects()) {
|
|
38
38
|
if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
|
|
@@ -52,45 +52,44 @@ async function run() {
|
|
|
52
52
|
if (m.isForTesting === false) {
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
|
-
ret += ` ls_input.get().class_name.set("${obj.getName()}");
|
|
56
|
-
ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
|
|
57
|
-
ls_input.get().method_name.set("${m.name.toUpperCase()}");
|
|
55
|
+
ret += ` ls_input.get().class_name.set("${obj.getName()}");
|
|
56
|
+
ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
|
|
57
|
+
ls_input.get().method_name.set("${m.name.toUpperCase()}");
|
|
58
58
|
abap.statements.append({source: ls_input, target: lt_input});`;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
ret += `
|
|
64
|
-
|
|
65
|
-
ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
process.exit(1);
|
|
63
|
+
ret += `
|
|
64
|
+
|
|
65
|
+
ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
|
|
66
|
+
fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
run().then(() => {
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}).catch((err) => {
|
|
72
|
+
console.log(err);
|
|
73
|
+
process.exit(1);
|
|
75
74
|
});`;
|
|
76
75
|
return ret;
|
|
77
76
|
}
|
|
78
77
|
unitTestScript(reg, skip, _only) {
|
|
79
|
-
let ret = `/* eslint-disable curly */
|
|
80
|
-
import fs from "fs";
|
|
81
|
-
import path from "path";
|
|
82
|
-
import {fileURLToPath} from "url";
|
|
83
|
-
import {initializeABAP} from "./init.mjs";
|
|
84
|
-
import runtime from "@abaplint/runtime";
|
|
85
|
-
|
|
86
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
87
|
-
|
|
88
|
-
async function run() {
|
|
89
|
-
await initializeABAP();
|
|
90
|
-
const unit = new runtime.UnitTestResult();
|
|
91
|
-
let clas;
|
|
92
|
-
let locl;
|
|
93
|
-
let meth;
|
|
78
|
+
let ret = `/* eslint-disable curly */
|
|
79
|
+
import fs from "fs";
|
|
80
|
+
import path from "path";
|
|
81
|
+
import {fileURLToPath} from "url";
|
|
82
|
+
import {initializeABAP} from "./init.mjs";
|
|
83
|
+
import runtime from "@abaplint/runtime";
|
|
84
|
+
|
|
85
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
86
|
+
|
|
87
|
+
async function run() {
|
|
88
|
+
await initializeABAP();
|
|
89
|
+
const unit = new runtime.UnitTestResult();
|
|
90
|
+
let clas;
|
|
91
|
+
let locl;
|
|
92
|
+
let meth;
|
|
94
93
|
try {\n`;
|
|
95
94
|
for (const obj of reg.getObjects()) {
|
|
96
95
|
if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
|
|
@@ -104,9 +103,9 @@ async function run() {
|
|
|
104
103
|
// todo, fix, there might be global test methods
|
|
105
104
|
continue;
|
|
106
105
|
}
|
|
107
|
-
ret += ` {
|
|
108
|
-
const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
|
|
109
|
-
locl = clas.addTestClass("${def.name}");
|
|
106
|
+
ret += ` {
|
|
107
|
+
const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
|
|
108
|
+
locl = clas.addTestClass("${def.name}");
|
|
110
109
|
if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
|
|
111
110
|
for (const m of def.methods) {
|
|
112
111
|
if (m.isForTesting === false) {
|
|
@@ -133,24 +132,24 @@ async function run() {
|
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
|
-
ret += `// -------------------END-------------------
|
|
137
|
-
console.log(abap.console.get());
|
|
138
|
-
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
139
|
-
} catch (e) {
|
|
140
|
-
if (meth) {
|
|
141
|
-
meth.fail();
|
|
142
|
-
}
|
|
143
|
-
console.log(abap.console.get());
|
|
144
|
-
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
145
|
-
throw e;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
run().then(() => {
|
|
150
|
-
process.exit(0);
|
|
151
|
-
}).catch((err) => {
|
|
152
|
-
console.log(err);
|
|
153
|
-
process.exit(1);
|
|
135
|
+
ret += `// -------------------END-------------------
|
|
136
|
+
console.log(abap.console.get());
|
|
137
|
+
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
138
|
+
} catch (e) {
|
|
139
|
+
if (meth) {
|
|
140
|
+
meth.fail();
|
|
141
|
+
}
|
|
142
|
+
console.log(abap.console.get());
|
|
143
|
+
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
run().then(() => {
|
|
149
|
+
process.exit(0);
|
|
150
|
+
}).catch((err) => {
|
|
151
|
+
console.log(err);
|
|
152
|
+
process.exit(1);
|
|
154
153
|
});`;
|
|
155
154
|
return ret;
|
|
156
155
|
}
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "1.
|
|
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.85.
|
|
31
|
-
"source-map": "^0.7.3"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@types/chai": "^4.3.0",
|
|
35
|
-
"@types/mocha": "^9.1.0",
|
|
36
|
-
"chai": "^4.3.6",
|
|
37
|
-
"mocha": "^9.2.0",
|
|
38
|
-
"source-map-support": "^0.5.21",
|
|
39
|
-
"typescript": "^4.5.5"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@abaplint/transpiler",
|
|
3
|
+
"version": "1.8.0",
|
|
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.85.12",
|
|
31
|
+
"source-map": "^0.7.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/chai": "^4.3.0",
|
|
35
|
+
"@types/mocha": "^9.1.0",
|
|
36
|
+
"chai": "^4.3.6",
|
|
37
|
+
"mocha": "^9.2.0",
|
|
38
|
+
"source-map-support": "^0.5.21",
|
|
39
|
+
"typescript": "^4.5.5"
|
|
40
|
+
}
|
|
41
|
+
}
|