@abaplint/transpiler 1.7.10 → 1.7.15
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.
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CreateObjectTranspiler = void 0;
|
|
4
4
|
const abaplint = require("@abaplint/core");
|
|
5
5
|
const chunk_1 = require("../chunk");
|
|
6
|
+
const expressions_1 = require("../expressions");
|
|
6
7
|
class CreateObjectTranspiler {
|
|
7
8
|
transpile(node, traversal) {
|
|
8
|
-
var _a;
|
|
9
|
+
var _a, _b;
|
|
9
10
|
const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode();
|
|
10
11
|
let para = "";
|
|
11
12
|
const parameters = node.findFirstExpression(abaplint.Expressions.ParameterListS);
|
|
@@ -13,16 +14,24 @@ class CreateObjectTranspiler {
|
|
|
13
14
|
para = traversal.traverse(parameters).getCode();
|
|
14
15
|
}
|
|
15
16
|
let name = "";
|
|
16
|
-
|
|
17
|
+
let directGlobal = false;
|
|
18
|
+
let dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
|
|
17
19
|
if (dynamic) {
|
|
18
20
|
name = dynamic.getFirstToken().getStr();
|
|
19
21
|
name = name.substring(1, name.length - 1);
|
|
20
22
|
}
|
|
21
23
|
else {
|
|
24
|
+
dynamic = (_b = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldChain);
|
|
25
|
+
if (dynamic) {
|
|
26
|
+
name = new expressions_1.FieldChainTranspiler(true).transpile(dynamic, traversal).getCode();
|
|
27
|
+
directGlobal = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (name === "") {
|
|
22
31
|
name = this.findClassName(node, traversal);
|
|
23
32
|
}
|
|
24
33
|
let ret = "";
|
|
25
|
-
const clas = traversal.lookupClassOrInterface(name, node.getFirstToken());
|
|
34
|
+
const clas = traversal.lookupClassOrInterface(name, node.getFirstToken(), directGlobal);
|
|
26
35
|
const cx = traversal.lookupClassOrInterface("CX_SY_CREATE_OBJECT_ERROR", node.getFirstToken());
|
|
27
36
|
if (dynamic) {
|
|
28
37
|
ret += `if (${clas} === undefined) { throw new ${cx}; }\n`;
|
|
@@ -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/traversal.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare class Traversal {
|
|
|
36
36
|
private dataFromInterfaces;
|
|
37
37
|
determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
38
38
|
registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
|
|
39
|
-
lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined): string;
|
|
39
|
+
lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
|
|
40
40
|
private buildPrefix;
|
|
41
41
|
protected traverseStructure(node: abaplint.Nodes.StructureNode): Chunk;
|
|
42
42
|
protected traverseStatement(node: abaplint.Nodes.StatementNode): Chunk;
|
package/build/src/traversal.js
CHANGED
|
@@ -347,11 +347,14 @@ class Traversal {
|
|
|
347
347
|
return `abap.Classes['${name.toUpperCase()}'] = ${name.toLowerCase()};`;
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
|
-
lookupClassOrInterface(name, token) {
|
|
350
|
+
lookupClassOrInterface(name, token, directGlobal = false) {
|
|
351
351
|
var _a, _b;
|
|
352
352
|
if (name === undefined || token === undefined) {
|
|
353
353
|
return "abap.Classes['undefined']";
|
|
354
354
|
}
|
|
355
|
+
if (directGlobal === true) {
|
|
356
|
+
return "abap.Classes[" + name + "]";
|
|
357
|
+
}
|
|
355
358
|
const scope = this.findCurrentScopeByToken(token);
|
|
356
359
|
// todo, add explicit type,
|
|
357
360
|
let def = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name);
|
package/build/src/types.js
CHANGED
|
@@ -96,6 +96,9 @@ class TranspileTypes {
|
|
|
96
96
|
else if (type instanceof abaplint.BasicTypes.FloatType) {
|
|
97
97
|
resolved = "Float";
|
|
98
98
|
}
|
|
99
|
+
else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
|
|
100
|
+
resolved = "DecFloat34";
|
|
101
|
+
}
|
|
99
102
|
else if (type instanceof abaplint.BasicTypes.UnknownType) {
|
|
100
103
|
return `(() => { throw "Unknown type: ${type.getError()}" })()`;
|
|
101
104
|
}
|
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
|
}
|
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.3",
|
|
38
|
-
"source-map-support": "^0.5.21",
|
|
39
|
-
"typescript": "^4.5.4"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@abaplint/transpiler",
|
|
3
|
+
"version": "1.7.15",
|
|
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.3",
|
|
38
|
+
"source-map-support": "^0.5.21",
|
|
39
|
+
"typescript": "^4.5.4"
|
|
40
|
+
}
|
|
41
|
+
}
|