@abaplint/transpiler 2.12.23 → 2.12.25
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.
|
@@ -9,7 +9,10 @@ class ConstantTranspiler {
|
|
|
9
9
|
this.addGet = addGet;
|
|
10
10
|
}
|
|
11
11
|
handleInteger(int, traversal) {
|
|
12
|
-
|
|
12
|
+
let concat = int.concatTokens().trim().replace(/^0+/, "");
|
|
13
|
+
if (concat === "") {
|
|
14
|
+
concat = "0";
|
|
15
|
+
}
|
|
13
16
|
const parsed = Number.parseInt(concat, 10);
|
|
14
17
|
let code = "";
|
|
15
18
|
if (concat.length > 18) {
|
|
@@ -6,6 +6,7 @@ const abaplint = require("@abaplint/core");
|
|
|
6
6
|
const chunk_1 = require("../chunk");
|
|
7
7
|
const type_name_or_infer_1 = require("./type_name_or_infer");
|
|
8
8
|
const transpile_types_1 = require("../transpile_types");
|
|
9
|
+
const types_1 = require("../types");
|
|
9
10
|
class NewObjectTranspiler {
|
|
10
11
|
transpile(node, traversal) {
|
|
11
12
|
const ret = new chunk_1.Chunk();
|
|
@@ -18,8 +19,26 @@ class NewObjectTranspiler {
|
|
|
18
19
|
if (parameters) {
|
|
19
20
|
para = traversal.traverse(parameters).getCode();
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
if (type
|
|
22
|
+
let type = new type_name_or_infer_1.TypeNameOrInfer().findTypeOrUndefined(typeNameOrInfer, traversal);
|
|
23
|
+
if (type === undefined) {
|
|
24
|
+
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
25
|
+
try {
|
|
26
|
+
type = traversal.lookupType(typeNameOrInfer, scope);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// ignore
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (type === undefined) {
|
|
33
|
+
if (traversal.options?.unknownTypes === types_1.UnknownTypesEnum.runtimeError) {
|
|
34
|
+
ret.appendString(`(function() { throw new Error("Void type: ${typeNameOrInfer.concatTokens().toUpperCase()}") })()`);
|
|
35
|
+
return ret;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error("NewObjectTranspiler, type not found: " + node.concatTokens() + ", " + traversal.getCurrentObject().getName() + " line " + node.getFirstToken().getStart().getRow());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (type instanceof abaplint.BasicTypes.ObjectReferenceType) {
|
|
23
42
|
if (node.getChildren()[3].get() instanceof abaplint.Expressions.Source) {
|
|
24
43
|
// single default parameter
|
|
25
44
|
const scope = traversal.findCurrentScopeByToken(typeNameOrInfer.getFirstToken());
|
|
@@ -32,7 +51,13 @@ class NewObjectTranspiler {
|
|
|
32
51
|
ret.appendString(transpile_types_1.TranspileTypes.toType(type) + ".set(await (new " + clas + "()).constructor_(" + para + "))");
|
|
33
52
|
}
|
|
34
53
|
else {
|
|
35
|
-
|
|
54
|
+
const source = node.findFirstExpression(abaplint.Expressions.Source);
|
|
55
|
+
if (source === undefined) {
|
|
56
|
+
throw new Error("NewObjectTranspiler: DataReference source not found");
|
|
57
|
+
}
|
|
58
|
+
const typeCode = transpile_types_1.TranspileTypes.toType(type);
|
|
59
|
+
const sourceCode = traversal.traverse(source).getCode();
|
|
60
|
+
ret.appendString("((() => {const r = new abap.types.DataReference(" + typeCode + "); r.assign(" + sourceCode + "); return r; })())");
|
|
36
61
|
}
|
|
37
62
|
return ret;
|
|
38
63
|
}
|
|
@@ -4,5 +4,6 @@ import { Traversal } from "../traversal";
|
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class TypeNameOrInfer implements IExpressionTranspiler {
|
|
6
6
|
findType(node: Nodes.ExpressionNode, traversal: Traversal): AbstractType;
|
|
7
|
+
findTypeOrUndefined(node: Nodes.ExpressionNode, traversal: Traversal): AbstractType | undefined;
|
|
7
8
|
transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
|
|
8
9
|
}
|
|
@@ -12,6 +12,11 @@ class TypeNameOrInfer {
|
|
|
12
12
|
}
|
|
13
13
|
return type;
|
|
14
14
|
}
|
|
15
|
+
findTypeOrUndefined(node, traversal) {
|
|
16
|
+
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
17
|
+
const type = traversal.lookupInferred(node, scope);
|
|
18
|
+
return type;
|
|
19
|
+
}
|
|
15
20
|
transpile(node, traversal) {
|
|
16
21
|
const type = this.findType(node, traversal);
|
|
17
22
|
const ret = new chunk_1.Chunk();
|
package/build/src/traversal.js
CHANGED
|
@@ -496,7 +496,13 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
|
|
|
496
496
|
}
|
|
497
497
|
// handle aliases after initialization of carrier variables
|
|
498
498
|
for (const a of def.getAliases() || []) {
|
|
499
|
-
|
|
499
|
+
const thisName = `this.${a.getName().toLowerCase()}`;
|
|
500
|
+
const aliasName = "this." + Traversal.escapeNamespace(a.getComponent().replace("~", "$").toLowerCase());
|
|
501
|
+
ret += `if (${thisName} === undefined)\n`;
|
|
502
|
+
ret += thisName + " = " + aliasName + ";\n";
|
|
503
|
+
// or the method(if its a method) might be implemented as its aliased name
|
|
504
|
+
ret += `else if (${aliasName} === undefined)\n`;
|
|
505
|
+
ret += aliasName + " = " + thisName + ";\n";
|
|
500
506
|
}
|
|
501
507
|
// constants can be accessed both statically and via reference
|
|
502
508
|
for (const c of def.getAttributes()?.getConstants() || []) {
|
|
@@ -595,7 +601,8 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
|
|
|
595
601
|
if (scope === undefined) {
|
|
596
602
|
return undefined;
|
|
597
603
|
}
|
|
598
|
-
else if (!(node.get() instanceof abaplint.Expressions.TypeName)
|
|
604
|
+
else if (!(node.get() instanceof abaplint.Expressions.TypeName)
|
|
605
|
+
&& !(node.get() instanceof abaplint.Expressions.TypeNameOrInfer)) {
|
|
599
606
|
throw new Error("lookupType, node is not a TypeName, " + node.get());
|
|
600
607
|
}
|
|
601
608
|
const name = node.concatTokens().toLowerCase();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.25",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "abaplint",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@abaplint/core": "^2.115.
|
|
32
|
+
"@abaplint/core": "^2.115.16",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|