@abaplint/transpiler 2.10.21 → 2.10.22
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/LICENSE +21 -21
- package/README.md +2 -2
- package/build/src/expressions/field_symbol.js +1 -0
- package/build/src/handlers/handle_data_element.js +5 -5
- package/build/src/handlers/handle_enqu.js +14 -14
- package/build/src/handlers/handle_smim.js +5 -5
- package/build/src/handlers/handle_table.js +4 -4
- package/build/src/handlers/handle_table_type.js +3 -3
- package/build/src/handlers/handle_view.js +3 -3
- package/build/src/handlers/handle_w3mi.js +3 -3
- package/build/src/statements/assign.js +10 -10
- package/build/src/statements/call.js +7 -7
- package/build/src/statements/class_implementation.js +5 -5
- package/build/src/statements/do.js +6 -6
- package/build/src/statements/end_do.js +1 -1
- package/build/src/statements/end_while.js +1 -1
- package/build/src/statements/method_implementation.js +3 -3
- package/build/src/statements/raise.js +2 -2
- package/build/src/statements/select.js +13 -13
- package/build/src/statements/while.js +3 -3
- package/build/src/structures/class_definition.js +11 -11
- package/build/src/structures/function_module.js +2 -2
- package/build/src/structures/select.js +4 -4
- package/build/src/unit_test.js +66 -66
- package/package.json +43 -43
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Lars Hvam Petersen
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Lars Hvam Petersen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# @abaplint/transpiler
|
|
2
|
-
|
|
1
|
+
# @abaplint/transpiler
|
|
2
|
+
|
|
3
3
|
Transpiler
|
|
@@ -17,11 +17,11 @@ class HandleDataElement {
|
|
|
17
17
|
fixedValues = doma.getFixedValues();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
21
|
-
"objectType": "DTEL",
|
|
22
|
-
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
23
|
-
"domain": ${JSON.stringify(obj.getDomainName())},
|
|
24
|
-
"fixedValues": ${JSON.stringify(fixedValues)},
|
|
20
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
21
|
+
"objectType": "DTEL",
|
|
22
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
23
|
+
"domain": ${JSON.stringify(obj.getDomainName())},
|
|
24
|
+
"fixedValues": ${JSON.stringify(fixedValues)},
|
|
25
25
|
};`);
|
|
26
26
|
const output = {
|
|
27
27
|
object: {
|
|
@@ -9,20 +9,20 @@ class HandleEnqu {
|
|
|
9
9
|
if (filename === undefined) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
|
-
const chunk = new chunk_1.Chunk().appendString(`// enqueue object
|
|
13
|
-
abap.FunctionModules["ENQUEUE_${obj.getName().toUpperCase()}"] = async (INPUT) => {
|
|
14
|
-
const lookup = abap.Classes["KERNEL_LOCK"];
|
|
15
|
-
if (lookup === undefined) {
|
|
16
|
-
throw new Error("Lock, kernel class missing");
|
|
17
|
-
}
|
|
18
|
-
await lookup.enqueue(INPUT);
|
|
19
|
-
};
|
|
20
|
-
abap.FunctionModules["DEQUEUE_${obj.getName().toUpperCase()}"] = async (INPUT) => {
|
|
21
|
-
const lookup = abap.Classes["KERNEL_LOCK"];
|
|
22
|
-
if (lookup === undefined) {
|
|
23
|
-
throw new Error("Lock, kernel class missing");
|
|
24
|
-
}
|
|
25
|
-
await lookup.dequeue(INPUT);
|
|
12
|
+
const chunk = new chunk_1.Chunk().appendString(`// enqueue object
|
|
13
|
+
abap.FunctionModules["ENQUEUE_${obj.getName().toUpperCase()}"] = async (INPUT) => {
|
|
14
|
+
const lookup = abap.Classes["KERNEL_LOCK"];
|
|
15
|
+
if (lookup === undefined) {
|
|
16
|
+
throw new Error("Lock, kernel class missing");
|
|
17
|
+
}
|
|
18
|
+
await lookup.enqueue(INPUT);
|
|
19
|
+
};
|
|
20
|
+
abap.FunctionModules["DEQUEUE_${obj.getName().toUpperCase()}"] = async (INPUT) => {
|
|
21
|
+
const lookup = abap.Classes["KERNEL_LOCK"];
|
|
22
|
+
if (lookup === undefined) {
|
|
23
|
+
throw new Error("Lock, kernel class missing");
|
|
24
|
+
}
|
|
25
|
+
await lookup.dequeue(INPUT);
|
|
26
26
|
};`);
|
|
27
27
|
const output = {
|
|
28
28
|
object: {
|
|
@@ -10,11 +10,11 @@ class HandleSMIM {
|
|
|
10
10
|
}
|
|
11
11
|
obj.parse();
|
|
12
12
|
const dataFile = obj.getDataFile();
|
|
13
|
-
const chunk = new chunk_1.Chunk().appendString(`abap.SMIM["${obj.getName().toUpperCase()}"] = {
|
|
14
|
-
"objectType": "SMIM",
|
|
15
|
-
"filename": ${JSON.stringify(dataFile?.getFilename())},
|
|
16
|
-
"url": ${JSON.stringify(obj.getURL())},
|
|
17
|
-
"class": ${JSON.stringify(obj.getClass())},
|
|
13
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.SMIM["${obj.getName().toUpperCase()}"] = {
|
|
14
|
+
"objectType": "SMIM",
|
|
15
|
+
"filename": ${JSON.stringify(dataFile?.getFilename())},
|
|
16
|
+
"url": ${JSON.stringify(obj.getURL())},
|
|
17
|
+
"class": ${JSON.stringify(obj.getClass())},
|
|
18
18
|
};`);
|
|
19
19
|
const output = {
|
|
20
20
|
object: {
|
|
@@ -11,10 +11,10 @@ class HandleTable {
|
|
|
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
|
-
"objectType": "TABL",
|
|
16
|
-
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
17
|
-
"keyFields": ${JSON.stringify(obj.listKeys(reg))},
|
|
14
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
15
|
+
"objectType": "TABL",
|
|
16
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
17
|
+
"keyFields": ${JSON.stringify(obj.listKeys(reg))},
|
|
18
18
|
};`);
|
|
19
19
|
const output = {
|
|
20
20
|
object: {
|
|
@@ -10,9 +10,9 @@ class HandleTableType {
|
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
12
|
const type = obj.parseType(reg);
|
|
13
|
-
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
14
|
-
"objectType": "TTYP",
|
|
15
|
-
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
13
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
14
|
+
"objectType": "TTYP",
|
|
15
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
16
16
|
};`);
|
|
17
17
|
const output = {
|
|
18
18
|
object: {
|
|
@@ -11,9 +11,9 @@ class HandleView {
|
|
|
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
|
-
"objectType": "VIEW",
|
|
16
|
-
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
14
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
|
|
15
|
+
"objectType": "VIEW",
|
|
16
|
+
"type": ${new transpile_types_1.TranspileTypes().toType(type)},
|
|
17
17
|
};`);
|
|
18
18
|
// todo, "keyFields": ${JSON.stringify(obj.listKeys())},
|
|
19
19
|
const output = {
|
|
@@ -10,9 +10,9 @@ class HandleW3MI {
|
|
|
10
10
|
}
|
|
11
11
|
obj.parse();
|
|
12
12
|
const dataFile = obj.getDataFile();
|
|
13
|
-
const chunk = new chunk_1.Chunk().appendString(`abap.W3MI["${obj.getName().toUpperCase()}"] = {
|
|
14
|
-
"objectType": "W3MI",
|
|
15
|
-
"filename": ${JSON.stringify(dataFile?.getFilename())},
|
|
13
|
+
const chunk = new chunk_1.Chunk().appendString(`abap.W3MI["${obj.getName().toUpperCase()}"] = {
|
|
14
|
+
"objectType": "W3MI",
|
|
15
|
+
"filename": ${JSON.stringify(dataFile?.getFilename())},
|
|
16
16
|
};`);
|
|
17
17
|
const output = {
|
|
18
18
|
object: {
|
|
@@ -59,26 +59,26 @@ class AssignTranspiler {
|
|
|
59
59
|
const firstFirst = first.getChildren()[1];
|
|
60
60
|
if (firstFirst?.get() instanceof abaplint.Expressions.Constant) {
|
|
61
61
|
const s = firstFirst.getFirstToken().getStr().toLowerCase().match(/\w+/)?.toString();
|
|
62
|
-
options.push(`dynamicSource: (() => {
|
|
63
|
-
try { return ${s}; } catch {}
|
|
64
|
-
try { return this.${s}; } catch {}
|
|
62
|
+
options.push(`dynamicSource: (() => {
|
|
63
|
+
try { return ${s}; } catch {}
|
|
64
|
+
try { return this.${s}; } catch {}
|
|
65
65
|
})()`);
|
|
66
66
|
}
|
|
67
67
|
else if (firstFirst?.get() instanceof abaplint.Expressions.FieldChain && firstFirst instanceof abaplint.Nodes.ExpressionNode) {
|
|
68
68
|
const code = new expressions_1.FieldChainTranspiler(true).transpile(firstFirst, traversal).getCode();
|
|
69
|
-
options.push(`dynamicSource: (() => {
|
|
70
|
-
const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
|
|
71
|
-
try { return eval(name); } catch {}
|
|
72
|
-
try { return eval("this." + name); } catch {}
|
|
69
|
+
options.push(`dynamicSource: (() => {
|
|
70
|
+
const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
|
|
71
|
+
try { return eval(name); } catch {}
|
|
72
|
+
try { return eval("this." + name); } catch {}
|
|
73
73
|
})()`);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else if (first?.get() instanceof abaplint.Expressions.Source && first instanceof abaplint.Nodes.ExpressionNode) {
|
|
77
77
|
// const name = first.concatTokens().toLowerCase();
|
|
78
78
|
const name = new expressions_1.SourceTranspiler().transpile(first, traversal).getCode();
|
|
79
|
-
options.push(`dynamicSource: (() => {
|
|
80
|
-
try { return ${name}; } catch {}
|
|
81
|
-
try { return this.${name}; } catch {}
|
|
79
|
+
options.push(`dynamicSource: (() => {
|
|
80
|
+
try { return ${name}; } catch {}
|
|
81
|
+
try { return this.${name}; } catch {}
|
|
82
82
|
})()`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -72,9 +72,9 @@ class CallTranspiler {
|
|
|
72
72
|
let pre = "";
|
|
73
73
|
let post = "";
|
|
74
74
|
pre = "try {\n" + pre;
|
|
75
|
-
post += `\nabap.builtin.sy.get().subrc.set(0);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
if (e.classic) {
|
|
75
|
+
post += `\nabap.builtin.sy.get().subrc.set(0);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (e.classic) {
|
|
78
78
|
switch (e.classic.toUpperCase()) {\n`;
|
|
79
79
|
for (const e of node.findAllExpressions(abaplint.Expressions.ParameterException)) {
|
|
80
80
|
const name = e.getFirstToken().getStr().toUpperCase();
|
|
@@ -90,10 +90,10 @@ if (e.classic) {
|
|
|
90
90
|
post += `case "${name}": abap.builtin.sy.get().subrc.set(${value}); break;\n`;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
post += ` }
|
|
94
|
-
} else {
|
|
95
|
-
throw e;
|
|
96
|
-
}
|
|
93
|
+
post += ` }
|
|
94
|
+
} else {
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
97
|
}`;
|
|
98
98
|
return { pre, post };
|
|
99
99
|
}
|
|
@@ -18,11 +18,11 @@ class ClassImplementationTranspiler {
|
|
|
18
18
|
ret += " extends " + traversal_1.Traversal.escapeNamespace(def?.getSuperClass()?.toLowerCase());
|
|
19
19
|
}
|
|
20
20
|
const scope = traversal.findCurrentScopeByToken(token);
|
|
21
|
-
return new chunk_1.Chunk().append(ret + ` {
|
|
22
|
-
static INTERNAL_TYPE = 'CLAS';
|
|
23
|
-
static INTERNAL_NAME = '${traversal.buildInternalName(token.getStr(), def)}';
|
|
24
|
-
static IMPLEMENTED_INTERFACES = [${this.findImplementedByClass(traversal, def, scope).map(e => `"` + e.toUpperCase() + `"`).join(",")}];
|
|
25
|
-
static ATTRIBUTES = {${traversal.buildAttributes(def, scope).join(",\n")}};
|
|
21
|
+
return new chunk_1.Chunk().append(ret + ` {
|
|
22
|
+
static INTERNAL_TYPE = 'CLAS';
|
|
23
|
+
static INTERNAL_NAME = '${traversal.buildInternalName(token.getStr(), def)}';
|
|
24
|
+
static IMPLEMENTED_INTERFACES = [${this.findImplementedByClass(traversal, def, scope).map(e => `"` + e.toUpperCase() + `"`).join(",")}];
|
|
25
|
+
static ATTRIBUTES = {${traversal.buildAttributes(def, scope).join(",\n")}};
|
|
26
26
|
static METHODS = {${traversal.buildMethods(def, scope).join(",\n")}};`, node, traversal);
|
|
27
27
|
}
|
|
28
28
|
findImplementedInterface(traversal, def, scope) {
|
|
@@ -15,16 +15,16 @@ class DoTranspiler {
|
|
|
15
15
|
const source = new expressions_1.SourceTranspiler(true).transpile(found, traversal).getCode();
|
|
16
16
|
const idSource = unique_identifier_1.UniqueIdentifier.get();
|
|
17
17
|
const id = unique_identifier_1.UniqueIdentifier.get();
|
|
18
|
-
return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
19
|
-
const ${idSource} = ${source};
|
|
20
|
-
for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
|
|
18
|
+
return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
19
|
+
const ${idSource} = ${source};
|
|
20
|
+
for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
|
|
21
21
|
abap.builtin.sy.get().index.set(${id} + 1);`);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
const unique = unique_identifier_1.UniqueIdentifier.get();
|
|
25
|
-
return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
26
|
-
let ${unique} = 1;
|
|
27
|
-
while (true) {
|
|
25
|
+
return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
26
|
+
let ${unique} = 1;
|
|
27
|
+
while (true) {
|
|
28
28
|
abap.builtin.sy.get().index.set(${unique}++);`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -7,7 +7,7 @@ class EndDoTranspiler {
|
|
|
7
7
|
this.syIndexBackup = syIndexBackup;
|
|
8
8
|
}
|
|
9
9
|
transpile(node, traversal) {
|
|
10
|
-
return new chunk_1.Chunk().append(`}
|
|
10
|
+
return new chunk_1.Chunk().append(`}
|
|
11
11
|
abap.builtin.sy.get().index.set(${this.syIndexBackup});\n`, node, traversal);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -7,7 +7,7 @@ class EndWhileTranspiler {
|
|
|
7
7
|
this.syIndexBackup = syIndexBackup;
|
|
8
8
|
}
|
|
9
9
|
transpile(node, traversal) {
|
|
10
|
-
return new chunk_1.Chunk().append(`}
|
|
10
|
+
return new chunk_1.Chunk().append(`}
|
|
11
11
|
abap.builtin.sy.get().index.set(${this.syIndexBackup});\n`, node, traversal);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -68,9 +68,9 @@ class MethodImplementationTranspiler {
|
|
|
68
68
|
after += `let ${varPrefixed} = ${unique}?.${varName};\n`;
|
|
69
69
|
}
|
|
70
70
|
if (type instanceof abaplint.BasicTypes.NumericGenericType) {
|
|
71
|
-
after += `if (${varPrefixed}.constructor.name === "Character") {
|
|
72
|
-
${varPrefixed} = ${new transpile_types_1.TranspileTypes().toType(identifier.getType())};
|
|
73
|
-
${varPrefixed}.set(${unique}?.${varName});
|
|
71
|
+
after += `if (${varPrefixed}.constructor.name === "Character") {
|
|
72
|
+
${varPrefixed} = ${new transpile_types_1.TranspileTypes().toType(identifier.getType())};
|
|
73
|
+
${varPrefixed}.set(${unique}?.${varName});
|
|
74
74
|
}\n`;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -26,8 +26,8 @@ class RaiseTranspiler {
|
|
|
26
26
|
const extra = `{"INTERNAL_FILENAME": "${traversal.getFilename()}","INTERNAL_LINE": ${node.getStart().getRow()}}`;
|
|
27
27
|
const lookup = traversal.lookupClassOrInterface(classNameToken?.getStr(), classNameToken);
|
|
28
28
|
const id = unique_identifier_1.UniqueIdentifier.get();
|
|
29
|
-
return new chunk_1.Chunk().append(`const ${id} = await (new ${lookup}()).constructor_(${p});
|
|
30
|
-
${id}.EXTRA_CX = ${extra};
|
|
29
|
+
return new chunk_1.Chunk().append(`const ${id} = await (new ${lookup}()).constructor_(${p});
|
|
30
|
+
${id}.EXTRA_CX = ${extra};
|
|
31
31
|
throw ${id};`, node, traversal);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -96,19 +96,19 @@ class SelectTranspiler {
|
|
|
96
96
|
if (keys.length > 0) {
|
|
97
97
|
by = JSON.stringify(keys);
|
|
98
98
|
}
|
|
99
|
-
const code = `if (${faeTranspiled}.array().length === 0) {
|
|
100
|
-
throw new Error("FAE, todo, empty table");
|
|
101
|
-
} else {
|
|
102
|
-
const ${unique2} = ${faeTranspiled}.array();
|
|
103
|
-
abap.statements.clear(${target});
|
|
104
|
-
for await (const ${unique} of ${unique2}) {
|
|
105
|
-
await abap.statements.select(${target}, {select: "${select.trim()}"${extra}}, {appending: true});
|
|
106
|
-
}
|
|
107
|
-
if (!(${target} instanceof abap.types.HashedTable) && ${target}.getOptions()?.primaryKey?.type !== "SORTED") {
|
|
108
|
-
abap.statements.sort(${target}, {by: ${by}.map(k => { return {component: k}; })});
|
|
109
|
-
await abap.statements.deleteInternal(${target}, {adjacent: true, by: ${by}});
|
|
110
|
-
}
|
|
111
|
-
abap.builtin.sy.get().dbcnt.set(${target}.getArrayLength());
|
|
99
|
+
const code = `if (${faeTranspiled}.array().length === 0) {
|
|
100
|
+
throw new Error("FAE, todo, empty table");
|
|
101
|
+
} else {
|
|
102
|
+
const ${unique2} = ${faeTranspiled}.array();
|
|
103
|
+
abap.statements.clear(${target});
|
|
104
|
+
for await (const ${unique} of ${unique2}) {
|
|
105
|
+
await abap.statements.select(${target}, {select: "${select.trim()}"${extra}}, {appending: true});
|
|
106
|
+
}
|
|
107
|
+
if (!(${target} instanceof abap.types.HashedTable) && ${target}.getOptions()?.primaryKey?.type !== "SORTED") {
|
|
108
|
+
abap.statements.sort(${target}, {by: ${by}.map(k => { return {component: k}; })});
|
|
109
|
+
await abap.statements.deleteInternal(${target}, {adjacent: true, by: ${by}});
|
|
110
|
+
}
|
|
111
|
+
abap.builtin.sy.get().dbcnt.set(${target}.getArrayLength());
|
|
112
112
|
}`;
|
|
113
113
|
return new chunk_1.Chunk().append(code, node, traversal);
|
|
114
114
|
}
|
|
@@ -13,11 +13,11 @@ class WhileTranspiler {
|
|
|
13
13
|
const cond = new expressions_1.CondTranspiler().transpile(node.findFirstExpression(abaplint.Expressions.Cond), traversal);
|
|
14
14
|
const unique = unique_identifier_1.UniqueIdentifier.get();
|
|
15
15
|
return new chunk_1.Chunk()
|
|
16
|
-
.append(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
17
|
-
let ${unique} = 1;
|
|
16
|
+
.append(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
17
|
+
let ${unique} = 1;
|
|
18
18
|
while (`, node, traversal)
|
|
19
19
|
.appendChunk(cond)
|
|
20
|
-
.appendString(`) {
|
|
20
|
+
.appendString(`) {
|
|
21
21
|
abap.builtin.sy.get().index.set(${unique}++);`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -19,17 +19,17 @@ class ClassDefinitionTranspiler {
|
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
// its an abstract class with only abstract methods
|
|
22
|
-
return new chunk_1.Chunk(`
|
|
23
|
-
class ${className?.toLowerCase()} {
|
|
24
|
-
static INTERNAL_TYPE = 'CLAS';
|
|
25
|
-
static IMPLEMENTED_INTERFACES = [];
|
|
26
|
-
static INTERNAL_NAME = 'ABSTRACT_CLASS_INTERNAL_NAME';
|
|
27
|
-
static ATTRIBUTES = {};
|
|
28
|
-
async constructor_() {
|
|
29
|
-
this.me = new abap.types.ABAPObject();
|
|
30
|
-
this.me.set(this);
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
22
|
+
return new chunk_1.Chunk(`
|
|
23
|
+
class ${className?.toLowerCase()} {
|
|
24
|
+
static INTERNAL_TYPE = 'CLAS';
|
|
25
|
+
static IMPLEMENTED_INTERFACES = [];
|
|
26
|
+
static INTERNAL_NAME = 'ABSTRACT_CLASS_INTERNAL_NAME';
|
|
27
|
+
static ATTRIBUTES = {};
|
|
28
|
+
async constructor_() {
|
|
29
|
+
this.me = new abap.types.ABAPObject();
|
|
30
|
+
this.me.set(this);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
33
|
}`);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -60,8 +60,8 @@ class FunctionModuleTranspiler {
|
|
|
60
60
|
const type = scope?.findVariable(name)?.getType();
|
|
61
61
|
if (type !== undefined && p.optional === true) {
|
|
62
62
|
// todo, set DEFAULT value
|
|
63
|
-
ret += `if (${name} === undefined) {
|
|
64
|
-
${name} = ${new transpile_types_1.TranspileTypes().toType(type)};
|
|
63
|
+
ret += `if (${name} === undefined) {
|
|
64
|
+
${name} = ${new transpile_types_1.TranspileTypes().toType(type)};
|
|
65
65
|
}\n`;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -25,10 +25,10 @@ class SelectTranspiler {
|
|
|
25
25
|
const packageSize = node.findFirstExpression(abaplint.Expressions.SelectLoop)?.findExpressionAfterToken("SIZE");
|
|
26
26
|
if (packageSize) {
|
|
27
27
|
const getSize = new expressions_1.SQLSourceTranspiler().transpile(packageSize, traversal).getCode() + ".get()";
|
|
28
|
-
ret.appendString(`if (${targetName}.array().length > ${getSize}) {
|
|
29
|
-
throw new Error("PACKAGE SIZED loop larger than package size not supported");
|
|
30
|
-
};
|
|
31
|
-
abap.statements.append({source: ${targetName}, target: ${intoName}, lines: true});
|
|
28
|
+
ret.appendString(`if (${targetName}.array().length > ${getSize}) {
|
|
29
|
+
throw new Error("PACKAGE SIZED loop larger than package size not supported");
|
|
30
|
+
};
|
|
31
|
+
abap.statements.append({source: ${targetName}, target: ${intoName}, lines: true});
|
|
32
32
|
{\n`);
|
|
33
33
|
}
|
|
34
34
|
else if (concat.includes(" INTO CORRESPONDING FIELDS OF ")) {
|
package/build/src/unit_test.js
CHANGED
|
@@ -8,16 +8,16 @@ class UnitTest {
|
|
|
8
8
|
initializationScript(reg, dbSetup, extraSetup, useImport) {
|
|
9
9
|
let ret = "";
|
|
10
10
|
if (useImport === true) {
|
|
11
|
-
ret = `/* eslint-disable import/newline-after-import */
|
|
11
|
+
ret = `/* eslint-disable import/newline-after-import */
|
|
12
12
|
import "./_top.mjs";\n`;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
ret = `/* eslint-disable import/newline-after-import */
|
|
16
|
-
import runtime from "@abaplint/runtime";
|
|
15
|
+
ret = `/* eslint-disable import/newline-after-import */
|
|
16
|
+
import runtime from "@abaplint/runtime";
|
|
17
17
|
globalThis.abap = new runtime.ABAP();\n`;
|
|
18
18
|
}
|
|
19
|
-
ret += `${this.buildImports(reg, useImport)}
|
|
20
|
-
|
|
19
|
+
ret += `${this.buildImports(reg, useImport)}
|
|
20
|
+
|
|
21
21
|
export async function initializeABAP() {\n`;
|
|
22
22
|
ret += ` const sqlite = [];\n`;
|
|
23
23
|
for (const i of dbSetup.schemas.sqlite) {
|
|
@@ -54,19 +54,19 @@ export async function initializeABAP() {\n`;
|
|
|
54
54
|
return filename.replace(/\//g, "%23");
|
|
55
55
|
}
|
|
56
56
|
unitTestScriptOpen(reg, _skip) {
|
|
57
|
-
let ret = `/* eslint-disable curly */
|
|
58
|
-
import fs from "fs";
|
|
59
|
-
import path from "path";
|
|
60
|
-
import {fileURLToPath} from "url";
|
|
61
|
-
import {initializeABAP} from "./init.mjs";
|
|
62
|
-
|
|
63
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
64
|
-
|
|
65
|
-
async function run() {
|
|
66
|
-
await initializeABAP();
|
|
67
|
-
let lt_input = new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30)}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]});
|
|
68
|
-
let ls_input = new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30)});
|
|
69
|
-
let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(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(), console: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
|
|
57
|
+
let ret = `/* eslint-disable curly */
|
|
58
|
+
import fs from "fs";
|
|
59
|
+
import path from "path";
|
|
60
|
+
import {fileURLToPath} from "url";
|
|
61
|
+
import {initializeABAP} from "./init.mjs";
|
|
62
|
+
|
|
63
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
64
|
+
|
|
65
|
+
async function run() {
|
|
66
|
+
await initializeABAP();
|
|
67
|
+
let lt_input = new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30)}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]});
|
|
68
|
+
let ls_input = new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30)});
|
|
69
|
+
let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(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(), console: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
|
|
70
70
|
`;
|
|
71
71
|
for (const obj of reg.getObjects()) {
|
|
72
72
|
if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
|
|
@@ -86,25 +86,25 @@ async function run() {
|
|
|
86
86
|
if (m.isForTesting === false) {
|
|
87
87
|
continue;
|
|
88
88
|
}
|
|
89
|
-
ret += ` ls_input.get().class_name.set("${obj.getName()}");
|
|
90
|
-
ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
|
|
91
|
-
ls_input.get().method_name.set("${m.name.toUpperCase()}");
|
|
89
|
+
ret += ` ls_input.get().class_name.set("${obj.getName()}");
|
|
90
|
+
ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
|
|
91
|
+
ls_input.get().method_name.set("${m.name.toUpperCase()}");
|
|
92
92
|
abap.statements.append({source: ls_input, target: lt_input});\n`;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
ret += `
|
|
98
|
-
|
|
99
|
-
ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
|
|
100
|
-
fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
run().then(() => {
|
|
104
|
-
process.exit(0);
|
|
105
|
-
}).catch((err) => {
|
|
106
|
-
console.log(err);
|
|
107
|
-
process.exit(1);
|
|
97
|
+
ret += `
|
|
98
|
+
|
|
99
|
+
ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
|
|
100
|
+
fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
run().then(() => {
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}).catch((err) => {
|
|
106
|
+
console.log(err);
|
|
107
|
+
process.exit(1);
|
|
108
108
|
});`;
|
|
109
109
|
return ret;
|
|
110
110
|
}
|
|
@@ -192,29 +192,29 @@ run().then(() => {
|
|
|
192
192
|
return tests;
|
|
193
193
|
}
|
|
194
194
|
unitTestScript(reg, skip) {
|
|
195
|
-
let ret = `/* eslint-disable curly */
|
|
196
|
-
import fs from "fs";
|
|
197
|
-
import path from "path";
|
|
198
|
-
import {fileURLToPath} from "url";
|
|
199
|
-
import {initializeABAP} from "./init.mjs";
|
|
200
|
-
import runtime from "@abaplint/runtime";
|
|
201
|
-
|
|
202
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
203
|
-
|
|
204
|
-
async function run() {
|
|
205
|
-
await initializeABAP();
|
|
206
|
-
const unit = new runtime.UnitTestResult();
|
|
207
|
-
let clas;
|
|
208
|
-
let locl;
|
|
209
|
-
let meth;
|
|
195
|
+
let ret = `/* eslint-disable curly */
|
|
196
|
+
import fs from "fs";
|
|
197
|
+
import path from "path";
|
|
198
|
+
import {fileURLToPath} from "url";
|
|
199
|
+
import {initializeABAP} from "./init.mjs";
|
|
200
|
+
import runtime from "@abaplint/runtime";
|
|
201
|
+
|
|
202
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
203
|
+
|
|
204
|
+
async function run() {
|
|
205
|
+
await initializeABAP();
|
|
206
|
+
const unit = new runtime.UnitTestResult();
|
|
207
|
+
let clas;
|
|
208
|
+
let locl;
|
|
209
|
+
let meth;
|
|
210
210
|
try {\n`;
|
|
211
211
|
for (const st of this.getSortedTests(reg)) {
|
|
212
212
|
ret += `// --------------------------------------------\n`;
|
|
213
213
|
ret += ` clas = unit.addObject("${st.obj.getName()}");\n`;
|
|
214
214
|
const lc = st.localClass.toLowerCase();
|
|
215
|
-
ret += ` {
|
|
216
|
-
const {${lc}} = await import("./${this.escapeNamespace(st.obj.getName().toLowerCase())}.${st.obj.getType().toLowerCase()}.testclasses.mjs");
|
|
217
|
-
locl = clas.addTestClass("${lc}");
|
|
215
|
+
ret += ` {
|
|
216
|
+
const {${lc}} = await import("./${this.escapeNamespace(st.obj.getName().toLowerCase())}.${st.obj.getType().toLowerCase()}.testclasses.mjs");
|
|
217
|
+
locl = clas.addTestClass("${lc}");
|
|
218
218
|
if (${lc}.class_setup) await ${lc}.class_setup();\n`;
|
|
219
219
|
for (const m of st.methods) {
|
|
220
220
|
const skipThis = (skip || []).some(a => a.object === st.obj.getName() && a.class === lc && a.method === m);
|
|
@@ -289,22 +289,22 @@ async function run() {
|
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
*/
|
|
292
|
-
ret += `// -------------------END-------------------
|
|
293
|
-
fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
|
|
294
|
-
} catch (e) {
|
|
295
|
-
if (meth) {
|
|
296
|
-
meth.fail();
|
|
297
|
-
}
|
|
298
|
-
fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
|
|
299
|
-
throw e;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
run().then(() => {
|
|
304
|
-
process.exit(0);
|
|
305
|
-
}).catch((err) => {
|
|
306
|
-
console.log(err);
|
|
307
|
-
process.exit(1);
|
|
292
|
+
ret += `// -------------------END-------------------
|
|
293
|
+
fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
|
|
294
|
+
} catch (e) {
|
|
295
|
+
if (meth) {
|
|
296
|
+
meth.fail();
|
|
297
|
+
}
|
|
298
|
+
fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
run().then(() => {
|
|
304
|
+
process.exit(0);
|
|
305
|
+
}).catch((err) => {
|
|
306
|
+
console.log(err);
|
|
307
|
+
process.exit(1);
|
|
308
308
|
});`;
|
|
309
309
|
return ret;
|
|
310
310
|
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.10.
|
|
4
|
-
"description": "Transpiler",
|
|
5
|
-
"main": "build/src/index.js",
|
|
6
|
-
"typings": "build/src/index.d.ts",
|
|
7
|
-
"funding": "https://github.com/sponsors/larshp",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/abaplint/transpiler.git"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"compile": "tsc",
|
|
14
|
-
"publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
15
|
-
"publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
16
|
-
"publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
17
|
-
"test": "npm run compile && mocha"
|
|
18
|
-
},
|
|
19
|
-
"mocha": {
|
|
20
|
-
"recursive": true,
|
|
21
|
-
"reporter": "progress",
|
|
22
|
-
"spec": "build/test/**/*.js",
|
|
23
|
-
"require": "source-map-support/register"
|
|
24
|
-
},
|
|
25
|
-
"keywords": [
|
|
26
|
-
"ABAP",
|
|
27
|
-
"abaplint"
|
|
28
|
-
],
|
|
29
|
-
"author": "abaplint",
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@abaplint/core": "^2.113.
|
|
33
|
-
"source-map": "^0.7.4"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/chai": "^4.3.20",
|
|
37
|
-
"@types/mocha": "^10.0.10",
|
|
38
|
-
"chai": "^4.5.0",
|
|
39
|
-
"mocha": "^
|
|
40
|
-
"source-map-support": "^0.5.21",
|
|
41
|
-
"typescript": "^5.
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@abaplint/transpiler",
|
|
3
|
+
"version": "2.10.22",
|
|
4
|
+
"description": "Transpiler",
|
|
5
|
+
"main": "build/src/index.js",
|
|
6
|
+
"typings": "build/src/index.d.ts",
|
|
7
|
+
"funding": "https://github.com/sponsors/larshp",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/abaplint/transpiler.git"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"compile": "tsc",
|
|
14
|
+
"publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
15
|
+
"publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
16
|
+
"publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
17
|
+
"test": "npm run compile && mocha"
|
|
18
|
+
},
|
|
19
|
+
"mocha": {
|
|
20
|
+
"recursive": true,
|
|
21
|
+
"reporter": "progress",
|
|
22
|
+
"spec": "build/test/**/*.js",
|
|
23
|
+
"require": "source-map-support/register"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"ABAP",
|
|
27
|
+
"abaplint"
|
|
28
|
+
],
|
|
29
|
+
"author": "abaplint",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@abaplint/core": "^2.113.79",
|
|
33
|
+
"source-map": "^0.7.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/chai": "^4.3.20",
|
|
37
|
+
"@types/mocha": "^10.0.10",
|
|
38
|
+
"chai": "^4.5.0",
|
|
39
|
+
"mocha": "^11.0.1",
|
|
40
|
+
"source-map-support": "^0.5.21",
|
|
41
|
+
"typescript": "^5.7.2"
|
|
42
|
+
}
|
|
43
|
+
}
|