@abaplint/transpiler 2.11.38 → 2.11.40
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.
|
@@ -43,9 +43,14 @@ class FieldChainTranspiler {
|
|
|
43
43
|
let name = c.getFirstToken().getStr().toLowerCase();
|
|
44
44
|
if (context instanceof abaplint.BasicTypes.ObjectReferenceType) {
|
|
45
45
|
const cdef = traversal.findClassDefinition(context.getIdentifierName(), scope);
|
|
46
|
-
const
|
|
46
|
+
const tokenName = c.getFirstToken().getStr();
|
|
47
|
+
const attr = cdef?.getAttributes().findByName(tokenName);
|
|
48
|
+
// Do not mark constants as private JS fields. Constants are exposed on instances via constructor copying.
|
|
49
|
+
const constants = cdef?.getAttributes().getConstants() || [];
|
|
50
|
+
const isConstant = constants.some(cons => cons.getName().toUpperCase() === tokenName.toUpperCase());
|
|
47
51
|
if (feature_flags_1.FEATURE_FLAGS.PRIVATE_ATTRIBUTES === true
|
|
48
|
-
&& attr?.getVisibility() === abaplint.Visibility.Private
|
|
52
|
+
&& attr?.getVisibility() === abaplint.Visibility.Private
|
|
53
|
+
&& isConstant === false) {
|
|
49
54
|
const id = scope?.getParent()?.getParent()?.getIdentifier();
|
|
50
55
|
if (id?.stype === abaplint.ScopeType.ClassImplementation
|
|
51
56
|
&& cdef?.getName().toUpperCase() === id.sname.toUpperCase()) {
|
|
@@ -6,6 +6,8 @@ const chunk_1 = require("../chunk");
|
|
|
6
6
|
const type_name_or_infer_1 = require("./type_name_or_infer");
|
|
7
7
|
const value_body_line_1 = require("./value_body_line");
|
|
8
8
|
const field_assignment_1 = require("./field_assignment");
|
|
9
|
+
const statements_1 = require("../statements");
|
|
10
|
+
const source_field_symbol_1 = require("./source_field_symbol");
|
|
9
11
|
class ValueBodyTranspiler {
|
|
10
12
|
transpile(typ, body, traversal) {
|
|
11
13
|
if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
|
|
@@ -13,8 +15,9 @@ class ValueBodyTranspiler {
|
|
|
13
15
|
}
|
|
14
16
|
let ret = new chunk_1.Chunk().appendString(new type_name_or_infer_1.TypeNameOrInfer().transpile(typ, traversal).getCode());
|
|
15
17
|
const context = new type_name_or_infer_1.TypeNameOrInfer().findType(typ, traversal);
|
|
16
|
-
|
|
18
|
+
let post = "";
|
|
17
19
|
let extraFields = "";
|
|
20
|
+
const hasLines = body.findDirectExpression(core_1.Expressions.ValueBodyLine) !== undefined;
|
|
18
21
|
for (const child of body.getChildren()) {
|
|
19
22
|
if (child.get() instanceof core_1.Expressions.FieldAssignment && child instanceof core_1.Nodes.ExpressionNode) {
|
|
20
23
|
const transpiled = new field_assignment_1.FieldAssignmentTranspiler().transpile(child, traversal).getCode();
|
|
@@ -40,11 +43,47 @@ class ValueBodyTranspiler {
|
|
|
40
43
|
const source = traversal.traverse(child);
|
|
41
44
|
ret.appendString(".set(" + source.getCode() + ".clone())");
|
|
42
45
|
}
|
|
46
|
+
else if (child.get() instanceof core_1.Expressions.For && child instanceof core_1.Nodes.ExpressionNode) {
|
|
47
|
+
if (child.getChildren().length !== 2) {
|
|
48
|
+
throw new Error("ValueBody FOR todo, num");
|
|
49
|
+
}
|
|
50
|
+
const loop = child.findDirectExpression(core_1.Expressions.InlineLoopDefinition);
|
|
51
|
+
if (loop === undefined) {
|
|
52
|
+
throw new Error("ValueBody FOR todo");
|
|
53
|
+
}
|
|
54
|
+
else if (loop.getChildren().length !== 3) {
|
|
55
|
+
throw new Error("ValueBody FOR todo, num loop");
|
|
56
|
+
}
|
|
57
|
+
let targetDeclare = "";
|
|
58
|
+
let targetAction = "";
|
|
59
|
+
const fs = loop.findDirectExpression(core_1.Expressions.TargetFieldSymbol);
|
|
60
|
+
if (fs) {
|
|
61
|
+
targetDeclare = new statements_1.FieldSymbolTranspiler().transpile(fs, traversal).getCode();
|
|
62
|
+
const targetName = new source_field_symbol_1.SourceFieldSymbolTranspiler().transpile(fs, traversal).getCode();
|
|
63
|
+
targetAction = `${targetName}.assign(unique1);`;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const field = traversal.traverse(loop.findDirectExpression(core_1.Expressions.TargetField));
|
|
67
|
+
if (field === undefined) {
|
|
68
|
+
throw new Error("ValueBody FOR empty field todo");
|
|
69
|
+
}
|
|
70
|
+
targetAction = `const ${field.getCode()} = unique1.clone();`;
|
|
71
|
+
}
|
|
72
|
+
const source = traversal.traverse(loop.findDirectExpression(core_1.Expressions.Source)).getCode();
|
|
73
|
+
const val = new type_name_or_infer_1.TypeNameOrInfer().transpile(typ, traversal).getCode();
|
|
74
|
+
ret = new chunk_1.Chunk().appendString(`await (async () => {
|
|
75
|
+
${targetDeclare}
|
|
76
|
+
const VAL = ${val};
|
|
77
|
+
for await (const unique1 of abap.statements.loop(${source})) {
|
|
78
|
+
${targetAction}
|
|
79
|
+
VAL`);
|
|
80
|
+
post = ";\n}\nreturn VAL;\n})()";
|
|
81
|
+
}
|
|
43
82
|
else {
|
|
44
83
|
throw new Error("ValueBodyTranspiler, unknown " + child.get().constructor.name + " \"" + child.concatTokens()) + "\"";
|
|
45
84
|
}
|
|
46
85
|
}
|
|
47
|
-
return ret;
|
|
86
|
+
return ret.appendString(post);
|
|
48
87
|
}
|
|
49
88
|
}
|
|
50
89
|
exports.ValueBodyTranspiler = ValueBodyTranspiler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.40",
|
|
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.113.
|
|
32
|
+
"@abaplint/core": "^2.113.181",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|