@abaplint/transpiler 1.6.62 → 1.6.66
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/component_compare.js +1 -1
- package/build/src/expressions/component_cond.js +9 -7
- package/build/src/expressions/function_exporting.js +13 -11
- package/build/src/index.d.ts +2 -2
- package/build/src/index.js +2 -1
- package/build/src/statements/do.js +4 -4
- package/build/src/statements/get_locale.d.ts +7 -0
- package/build/src/statements/get_locale.js +11 -0
- package/build/src/statements/index.d.ts +1 -0
- package/build/src/statements/index.js +1 -0
- package/build/src/statements/replace.js +8 -1
- package/build/src/structures/case.js +3 -0
- package/build/src/unit_test.d.ts +2 -1
- package/build/src/unit_test.js +43 -39
- package/package.json +40 -41
|
@@ -5,7 +5,7 @@ const core_1 = require("@abaplint/core");
|
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
6
|
class ComponentCompareTranspiler {
|
|
7
7
|
transpile(node, traversal) {
|
|
8
|
-
const concat = node.concatTokens();
|
|
8
|
+
const concat = node.concatTokens().toUpperCase();
|
|
9
9
|
const pre = concat.startsWith("NOT") ? "!" : "";
|
|
10
10
|
const component = traversal.traverse(node.findDirectExpression(core_1.Expressions.ComponentChainSimple)).getCode();
|
|
11
11
|
if (node.findDirectExpression(core_1.Expressions.CompareOperator)) {
|
|
@@ -5,32 +5,34 @@ const abaplint = require("@abaplint/core");
|
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
6
|
class ComponentCondTranspiler {
|
|
7
7
|
transpile(node, traversal) {
|
|
8
|
-
// todo, this is still not correct
|
|
9
8
|
let ret = "";
|
|
10
9
|
for (const c of node.getChildren()) {
|
|
11
10
|
if (c instanceof abaplint.Nodes.ExpressionNode) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
let cond = traversal.traverse(c).getCode();
|
|
12
|
+
cond = cond.replace(/^\(i\) => \{return /, "");
|
|
13
|
+
cond = cond.replace(/;\}$/, "");
|
|
14
|
+
ret += cond;
|
|
14
15
|
}
|
|
15
16
|
else if (c instanceof abaplint.Nodes.TokenNode) {
|
|
16
|
-
switch (c.get().getStr()) {
|
|
17
|
+
switch (c.get().getStr().toUpperCase()) {
|
|
17
18
|
case "AND":
|
|
18
|
-
ret
|
|
19
|
+
ret += " && ";
|
|
19
20
|
break;
|
|
20
21
|
case "OR":
|
|
21
|
-
ret
|
|
22
|
+
ret += " || ";
|
|
22
23
|
break;
|
|
23
24
|
case "(":
|
|
24
25
|
ret += "(";
|
|
25
26
|
break;
|
|
26
27
|
case ")":
|
|
27
|
-
ret
|
|
28
|
+
ret += ")";
|
|
28
29
|
break;
|
|
29
30
|
default:
|
|
30
31
|
// todo, runtime error
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
ret = `(i) => {return ${ret};}`;
|
|
34
36
|
return new chunk_1.Chunk(ret);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -7,17 +7,19 @@ class FunctionExportingTranspiler {
|
|
|
7
7
|
transpile(node, traversal) {
|
|
8
8
|
const parameters = [];
|
|
9
9
|
let chunk = new chunk_1.Chunk();
|
|
10
|
-
for (const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
for (const parameter of node.getChildren()) {
|
|
11
|
+
for (const child of parameter.getChildren()) {
|
|
12
|
+
if (child.getFirstToken().getStr() === "=") {
|
|
13
|
+
chunk.appendString(": ");
|
|
14
|
+
}
|
|
15
|
+
else if (child.get() instanceof abaplint.Expressions.ParameterName) {
|
|
16
|
+
chunk = new chunk_1.Chunk();
|
|
17
|
+
chunk.appendChunk(traversal.traverse(child));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
chunk.appendChunk(traversal.traverse(child));
|
|
21
|
+
parameters.push(chunk);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
return new chunk_1.Chunk().appendString("{").join(parameters).appendString("}");
|
package/build/src/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface IObjectIdentifier {
|
|
|
15
15
|
export interface IOutput {
|
|
16
16
|
objects: IOutputFile[];
|
|
17
17
|
reg: abaplint.IRegistry;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
unitTestScript: string;
|
|
19
|
+
initializationScript: string;
|
|
20
20
|
databaseSetup: string;
|
|
21
21
|
}
|
|
22
22
|
export interface IRequire {
|
package/build/src/index.js
CHANGED
|
@@ -35,7 +35,8 @@ class Transpiler {
|
|
|
35
35
|
const dbSetup = new database_setup_1.DatabaseSetup(reg).run();
|
|
36
36
|
const output = {
|
|
37
37
|
objects: [],
|
|
38
|
-
|
|
38
|
+
unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_a = this.options) === null || _a === void 0 ? void 0 : _a.skip),
|
|
39
|
+
initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup),
|
|
39
40
|
databaseSetup: dbSetup,
|
|
40
41
|
reg: reg,
|
|
41
42
|
};
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as abaplint from "@abaplint/core";
|
|
2
|
+
import { IStatementTranspiler } from "./_statement_transpiler";
|
|
3
|
+
import { Traversal } from "../traversal";
|
|
4
|
+
import { Chunk } from "../chunk";
|
|
5
|
+
export declare class GetLocaleTranspiler implements IStatementTranspiler {
|
|
6
|
+
transpile(_node: abaplint.Nodes.StatementNode, _traversal: Traversal): Chunk;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetLocaleTranspiler = void 0;
|
|
4
|
+
const chunk_1 = require("../chunk");
|
|
5
|
+
class GetLocaleTranspiler {
|
|
6
|
+
transpile(_node, _traversal) {
|
|
7
|
+
return new chunk_1.Chunk(`throw new Error("GetLocale, transpiler todo");`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.GetLocaleTranspiler = GetLocaleTranspiler;
|
|
11
|
+
//# sourceMappingURL=get_locale.js.map
|
|
@@ -12,6 +12,7 @@ export * from "./class_deferred";
|
|
|
12
12
|
export * from "./class_implementation";
|
|
13
13
|
export * from "./class_local_friends";
|
|
14
14
|
export * from "./clear";
|
|
15
|
+
export * from "./get_locale";
|
|
15
16
|
export * from "./raise_event";
|
|
16
17
|
export * from "./collect";
|
|
17
18
|
export * from "./commit";
|
|
@@ -24,6 +24,7 @@ __exportStar(require("./class_deferred"), exports);
|
|
|
24
24
|
__exportStar(require("./class_implementation"), exports);
|
|
25
25
|
__exportStar(require("./class_local_friends"), exports);
|
|
26
26
|
__exportStar(require("./clear"), exports);
|
|
27
|
+
__exportStar(require("./get_locale"), exports);
|
|
27
28
|
__exportStar(require("./raise_event"), exports);
|
|
28
29
|
__exportStar(require("./collect"), exports);
|
|
29
30
|
__exportStar(require("./commit"), exports);
|
|
@@ -11,7 +11,14 @@ class ReplaceTranspiler {
|
|
|
11
11
|
sources.push(new expressions_1.SourceTranspiler().transpile(s, traversal).getCode());
|
|
12
12
|
}
|
|
13
13
|
const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode();
|
|
14
|
-
const
|
|
14
|
+
const concat = node.concatTokens().toUpperCase();
|
|
15
|
+
const all = concat.startsWith("REPLACE ALL");
|
|
16
|
+
if (concat.includes("SECTION LENGTH")) {
|
|
17
|
+
// TODO,
|
|
18
|
+
const last = sources.pop();
|
|
19
|
+
sources.pop();
|
|
20
|
+
sources.push(last);
|
|
21
|
+
}
|
|
15
22
|
return new chunk_1.Chunk()
|
|
16
23
|
.append("abap.statements.replace(", node, traversal)
|
|
17
24
|
.appendString(target + ", " + all + ", " + sources.join(", "))
|
|
@@ -34,6 +34,9 @@ class CaseTranspiler {
|
|
|
34
34
|
ret.appendString(") {\n");
|
|
35
35
|
}
|
|
36
36
|
else if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.WhenOthers) {
|
|
37
|
+
if (first === true) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
37
40
|
ret.appendString("} else {\n");
|
|
38
41
|
}
|
|
39
42
|
else {
|
package/build/src/unit_test.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare type SkipSettings = {
|
|
|
5
5
|
method: string;
|
|
6
6
|
}[];
|
|
7
7
|
export declare class UnitTest {
|
|
8
|
-
|
|
8
|
+
initializationScript(reg: abaplint.IRegistry, dbSetup: string): string;
|
|
9
|
+
unitTestScript(reg: abaplint.IRegistry, skip?: SkipSettings): string;
|
|
9
10
|
private buildImports;
|
|
10
11
|
}
|
package/build/src/unit_test.js
CHANGED
|
@@ -3,25 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UnitTest = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
5
|
class UnitTest {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
initializationScript(reg, dbSetup) {
|
|
7
|
+
return `import runtime from "@abaplint/runtime";
|
|
8
|
+
global.abap = new runtime.ABAP();
|
|
9
|
+
${this.buildImports(reg)}
|
|
10
|
+
export async function initDB() {
|
|
11
|
+
return global.abap.initDB(\`${dbSetup}\`);
|
|
12
|
+
}`;
|
|
13
|
+
}
|
|
14
|
+
unitTestScript(reg, skip) {
|
|
15
|
+
let ret = `import fs from "fs";
|
|
16
|
+
import path from "path";
|
|
17
|
+
import {dirname} from 'path';
|
|
18
|
+
import {fileURLToPath} from 'url';
|
|
19
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
import {initDB} from "./init.mjs";
|
|
21
|
+
import runtime from "@abaplint/runtime";
|
|
22
|
+
|
|
23
|
+
async function run() {
|
|
24
|
+
await initDB();
|
|
25
|
+
const unit = new runtime.UnitTestResult();
|
|
26
|
+
let clas;
|
|
27
|
+
let locl;
|
|
28
|
+
let meth;
|
|
25
29
|
try {\n`;
|
|
26
30
|
for (const obj of reg.getObjects()) {
|
|
27
31
|
if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
|
|
@@ -36,8 +40,8 @@ try {\n`;
|
|
|
36
40
|
|| def.methods.length === 0) {
|
|
37
41
|
continue;
|
|
38
42
|
}
|
|
39
|
-
ret += `{
|
|
40
|
-
const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
|
|
43
|
+
ret += `{
|
|
44
|
+
const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
|
|
41
45
|
locl = clas.addTestClass("${def.name}");\n`;
|
|
42
46
|
ret += `if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
|
|
43
47
|
for (const m of def.methods) {
|
|
@@ -65,24 +69,24 @@ locl = clas.addTestClass("${def.name}");\n`;
|
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
|
-
ret += `// -------------------END-------------------
|
|
69
|
-
console.log(abap.console.get());
|
|
70
|
-
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
71
|
-
} catch (e) {
|
|
72
|
-
if (meth) {
|
|
73
|
-
meth.fail();
|
|
74
|
-
}
|
|
75
|
-
console.log(abap.console.get());
|
|
76
|
-
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
77
|
-
throw e;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
run().then(() => {
|
|
82
|
-
process.exit();
|
|
83
|
-
}).catch((err) => {
|
|
84
|
-
console.log(err);
|
|
85
|
-
process.exit(1);
|
|
72
|
+
ret += `// -------------------END-------------------
|
|
73
|
+
console.log(abap.console.get());
|
|
74
|
+
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
75
|
+
} catch (e) {
|
|
76
|
+
if (meth) {
|
|
77
|
+
meth.fail();
|
|
78
|
+
}
|
|
79
|
+
console.log(abap.console.get());
|
|
80
|
+
fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
run().then(() => {
|
|
86
|
+
process.exit();
|
|
87
|
+
}).catch((err) => {
|
|
88
|
+
console.log(err);
|
|
89
|
+
process.exit(1);
|
|
86
90
|
});`;
|
|
87
91
|
return ret;
|
|
88
92
|
}
|
package/package.json
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "1.6.
|
|
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
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"@types/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@abaplint/transpiler",
|
|
3
|
+
"version": "1.6.66",
|
|
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:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
14
|
+
"test": "npm run compile && mocha"
|
|
15
|
+
},
|
|
16
|
+
"mocha": {
|
|
17
|
+
"recursive": true,
|
|
18
|
+
"reporter": "progress",
|
|
19
|
+
"spec": "build/test/**/*.js",
|
|
20
|
+
"require": "source-map-support/register"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"ABAP",
|
|
24
|
+
"abaplint"
|
|
25
|
+
],
|
|
26
|
+
"author": "abaplint",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@abaplint/core": "=2.80.10",
|
|
30
|
+
"source-map": "^0.7.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/chai": "^4.2.22",
|
|
34
|
+
"@types/mocha": "^9.0.0",
|
|
35
|
+
"chai": "^4.3.4",
|
|
36
|
+
"mocha": "^9.1.3",
|
|
37
|
+
"source-map-support": "^0.5.21",
|
|
38
|
+
"typescript": "^4.5.2"
|
|
39
|
+
}
|
|
40
|
+
}
|