@abaplint/transpiler 2.7.165 → 2.8.0

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.
Files changed (72) hide show
  1. package/build/src/db/index.js +2 -3
  2. package/build/src/db/schema_generation/pg_database_schema.js +1 -1
  3. package/build/src/db/schema_generation/snowflake_database_schema.js +1 -1
  4. package/build/src/db/schema_generation/sqlite_database_schema.js +1 -1
  5. package/build/src/expressions/call_transformation_parameters.js +1 -2
  6. package/build/src/expressions/compare.js +2 -3
  7. package/build/src/expressions/component_compare.js +2 -2
  8. package/build/src/expressions/constant.js +6 -1
  9. package/build/src/expressions/method_call.js +3 -4
  10. package/build/src/expressions/method_call_param.js +2 -3
  11. package/build/src/expressions/method_source.js +1 -1
  12. package/build/src/expressions/parameter_s.js +2 -3
  13. package/build/src/expressions/parameter_t.js +2 -3
  14. package/build/src/expressions/sql_cond.js +2 -3
  15. package/build/src/expressions/sql_source.js +1 -1
  16. package/build/src/handlers/handle_abap.js +6 -9
  17. package/build/src/handlers/handle_data_element.js +1 -2
  18. package/build/src/handlers/handle_enqu.js +1 -2
  19. package/build/src/handlers/handle_msag.js +1 -2
  20. package/build/src/handlers/handle_oa2p.js +1 -2
  21. package/build/src/handlers/handle_smim.js +4 -5
  22. package/build/src/handlers/handle_table.js +1 -2
  23. package/build/src/handlers/handle_table_type.js +1 -2
  24. package/build/src/handlers/handle_type_pool.js +3 -4
  25. package/build/src/handlers/handle_view.js +1 -2
  26. package/build/src/handlers/handle_w3mi.js +4 -5
  27. package/build/src/index.js +7 -8
  28. package/build/src/requires.js +6 -7
  29. package/build/src/statements/assign.js +10 -11
  30. package/build/src/statements/call.js +5 -7
  31. package/build/src/statements/call_function.js +2 -3
  32. package/build/src/statements/call_transformation.js +1 -2
  33. package/build/src/statements/class_implementation.js +3 -4
  34. package/build/src/statements/concatenate.js +1 -2
  35. package/build/src/statements/convert.js +8 -8
  36. package/build/src/statements/create_data.js +3 -4
  37. package/build/src/statements/create_object.js +5 -7
  38. package/build/src/statements/data.js +1 -2
  39. package/build/src/statements/end_method.js +6 -7
  40. package/build/src/statements/field_symbol.js +1 -1
  41. package/build/src/statements/find.js +3 -4
  42. package/build/src/statements/form.js +4 -4
  43. package/build/src/statements/loop.js +7 -8
  44. package/build/src/statements/method_implementation.js +9 -11
  45. package/build/src/statements/move.js +1 -2
  46. package/build/src/statements/open_cursor.js +4 -4
  47. package/build/src/statements/perform.js +7 -8
  48. package/build/src/statements/raise.js +4 -5
  49. package/build/src/statements/read_table.js +3 -3
  50. package/build/src/statements/receive.js +1 -2
  51. package/build/src/statements/replace.js +1 -1
  52. package/build/src/statements/return.js +3 -3
  53. package/build/src/statements/select.js +1 -2
  54. package/build/src/statements/tables.js +1 -2
  55. package/build/src/statements/write.js +1 -2
  56. package/build/src/structures/at.js +7 -5
  57. package/build/src/structures/case.js +1 -2
  58. package/build/src/structures/case_type.js +2 -3
  59. package/build/src/structures/class_definition.js +2 -3
  60. package/build/src/structures/class_implementation.js +3 -5
  61. package/build/src/structures/constants.js +2 -3
  62. package/build/src/structures/data.js +2 -3
  63. package/build/src/structures/function_module.js +3 -5
  64. package/build/src/structures/interface.js +5 -6
  65. package/build/src/structures/loop.js +1 -2
  66. package/build/src/structures/select.js +2 -3
  67. package/build/src/structures/try.js +1 -1
  68. package/build/src/transpile_types.js +11 -12
  69. package/build/src/traversal.js +33 -38
  70. package/build/src/unit_test.js +2 -3
  71. package/build/src/validation.js +3 -4
  72. package/package.json +1 -1
@@ -6,12 +6,11 @@ const chunk_1 = require("../chunk");
6
6
  const expressions_1 = require("../expressions");
7
7
  class CallTranspiler {
8
8
  transpile(node, traversal) {
9
- var _a, _b, _c, _d;
10
9
  const chain = node.findDirectExpression(abaplint.Expressions.MethodCallChain);
11
10
  if (chain) {
12
11
  let pre = "";
13
12
  let post = "";
14
- const receiving = (_b = (_a = chain.findFirstExpression(abaplint.Expressions.MethodParameters)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(abaplint.Expressions.ParameterT)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(abaplint.Expressions.Target);
13
+ const receiving = chain.findFirstExpression(abaplint.Expressions.MethodParameters)?.findDirectExpression(abaplint.Expressions.ParameterT)?.findDirectExpression(abaplint.Expressions.Target);
15
14
  if (receiving) {
16
15
  pre = traversal.traverse(receiving).getCode() + ".set(";
17
16
  post = ")";
@@ -37,15 +36,15 @@ class CallTranspiler {
37
36
  const methodSource = node.findDirectExpression(abaplint.Expressions.MethodSource);
38
37
  if (methodSource) {
39
38
  let body = "";
40
- const nameToken = (_c = methodSource.getLastChild()) === null || _c === void 0 ? void 0 : _c.getFirstToken();
39
+ const nameToken = methodSource.getLastChild()?.getFirstToken();
41
40
  const m = nameToken ? traversal.findMethodReference(nameToken, traversal.findCurrentScopeByToken(nameToken)) : undefined;
42
41
  const methodCallBody = node.findDirectExpression(abaplint.Expressions.MethodCallBody);
43
42
  if (methodCallBody) {
44
- body = new expressions_1.MethodCallBodyTranspiler(m === null || m === void 0 ? void 0 : m.def).transpile(methodCallBody, traversal).getCode();
43
+ body = new expressions_1.MethodCallBodyTranspiler(m?.def).transpile(methodCallBody, traversal).getCode();
45
44
  }
46
45
  let pre = "";
47
46
  let post = "";
48
- const receiving = (_d = node.findFirstExpression(abaplint.Expressions.MethodParameters)) === null || _d === void 0 ? void 0 : _d.findExpressionAfterToken("RECEIVING");
47
+ const receiving = node.findFirstExpression(abaplint.Expressions.MethodParameters)?.findExpressionAfterToken("RECEIVING");
49
48
  if (receiving) {
50
49
  const target = traversal.traverse(receiving.findDirectExpression(abaplint.Expressions.Target));
51
50
  pre = target.getCode() + ".set(";
@@ -70,7 +69,6 @@ class CallTranspiler {
70
69
  throw new Error("CallTranspiler, todo");
71
70
  }
72
71
  static buildExceptions(node) {
73
- var _a;
74
72
  let pre = "";
75
73
  let post = "";
76
74
  pre = "try {\n" + pre;
@@ -80,7 +78,7 @@ if (e.classic) {
80
78
  switch (e.classic.toUpperCase()) {\n`;
81
79
  for (const e of node.findAllExpressions(abaplint.Expressions.ParameterException)) {
82
80
  const name = e.getFirstToken().getStr().toUpperCase();
83
- const value = (_a = e.findFirstExpression(abaplint.Expressions.SimpleName)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr().toUpperCase();
81
+ const value = e.findFirstExpression(abaplint.Expressions.SimpleName)?.getFirstToken().getStr().toUpperCase();
84
82
  if (value === undefined) {
85
83
  continue;
86
84
  }
@@ -7,8 +7,7 @@ const expressions_1 = require("../expressions");
7
7
  const call_1 = require("./call");
8
8
  class CallFunctionTranspiler {
9
9
  transpile(node, traversal) {
10
- var _a, _b;
11
- const fmchild = (_a = node.findDirectExpression(abaplint.Expressions.FunctionName)) === null || _a === void 0 ? void 0 : _a.getFirstChild();
10
+ const fmchild = node.findDirectExpression(abaplint.Expressions.FunctionName)?.getFirstChild();
12
11
  if (fmchild === undefined) {
13
12
  throw new Error("CallFunctionTranspilerNameNotFound");
14
13
  }
@@ -32,7 +31,7 @@ class CallFunctionTranspiler {
32
31
  ret.appendString("try {\n");
33
32
  }
34
33
  const calling = node.findExpressionAfterToken("CALLING");
35
- const dest = (_b = node.findDirectExpression(abaplint.Expressions.Destination)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(abaplint.Expressions.Source);
34
+ const dest = node.findDirectExpression(abaplint.Expressions.Destination)?.findDirectExpression(abaplint.Expressions.Source);
36
35
  if (dest) {
37
36
  const s = new expressions_1.SourceTranspiler(true).transpile(dest, traversal);
38
37
  param = param.replace("{", ",").replace(/}$/, "");
@@ -5,10 +5,9 @@ const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class CallTransformationTranspiler {
7
7
  transpile(node, traversal) {
8
- var _a;
9
8
  const lookup = traversal.lookupClassOrInterface("KERNEL_CALL_TRANSFORMATION", node.getFirstToken());
10
9
  const options = [];
11
- const name = (_a = node.findDirectExpression(abaplint.Expressions.NamespaceSimpleName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
10
+ const name = node.findDirectExpression(abaplint.Expressions.NamespaceSimpleName)?.concatTokens();
12
11
  options.push("name: \"" + name + "\"");
13
12
  const sourceXML = node.findDirectExpression(abaplint.Expressions.SimpleSource3);
14
13
  if (sourceXML) {
@@ -7,7 +7,6 @@ const traversal_1 = require("../traversal");
7
7
  const chunk_1 = require("../chunk");
8
8
  class ClassImplementationTranspiler {
9
9
  transpile(node, traversal) {
10
- var _a;
11
10
  const token = node.findFirstExpression(abaplint.Expressions.ClassName).getFirstToken();
12
11
  const def = traversal.getClassDefinition(token);
13
12
  let ret = "class " + traversal_1.Traversal.escapeNamespace(token.getStr().toLowerCase());
@@ -15,8 +14,8 @@ class ClassImplementationTranspiler {
15
14
  // special case for exceptions
16
15
  ret += " extends Error";
17
16
  }
18
- else if (def === null || def === void 0 ? void 0 : def.getSuperClass()) {
19
- ret += " extends " + traversal_1.Traversal.escapeNamespace((_a = def === null || def === void 0 ? void 0 : def.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
17
+ else if (def?.getSuperClass()) {
18
+ ret += " extends " + traversal_1.Traversal.escapeNamespace(def?.getSuperClass()?.toLowerCase());
20
19
  }
21
20
  const scope = traversal.findCurrentScopeByToken(token);
22
21
  return new chunk_1.Chunk().append(ret + ` {
@@ -50,7 +49,7 @@ static METHODS = {${traversal.buildMethods(def, scope).join(",\n")}};`, node, tr
50
49
  while (sup !== undefined) {
51
50
  const sdef = traversal.findClassDefinition(sup, scope);
52
51
  list.push(...this.findImplementedByClass(traversal, sdef, scope));
53
- sup = sdef === null || sdef === void 0 ? void 0 : sdef.getSuperClass();
52
+ sup = sdef?.getSuperClass();
54
53
  }
55
54
  return list;
56
55
  }
@@ -5,7 +5,6 @@ const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class ConcatenateTranspiler {
7
7
  transpile(node, traversal) {
8
- var _a;
9
8
  const concat = node.concatTokens().toUpperCase();
10
9
  const slist = [];
11
10
  for (const s of node.findDirectExpressions(abaplint.Expressions.Source)) {
@@ -13,7 +12,7 @@ class ConcatenateTranspiler {
13
12
  }
14
13
  let extra = "";
15
14
  if (node.findExpressionAfterToken("BY")) {
16
- extra = `, separatedBy: ${(_a = slist.pop()) === null || _a === void 0 ? void 0 : _a.getCode()}`;
15
+ extra = `, separatedBy: ${slist.pop()?.getCode()}`;
17
16
  }
18
17
  if (concat.startsWith("CONCATENATE LINES OF ")) {
19
18
  extra += ", lines: true";
@@ -9,31 +9,31 @@ class ConvertTranspiler {
9
9
  const source = [];
10
10
  const target = [];
11
11
  const date = node.findExpressionAfterToken("DATE");
12
- if ((date === null || date === void 0 ? void 0 : date.get()) instanceof abaplint.Expressions.Source) {
12
+ if (date?.get() instanceof abaplint.Expressions.Source) {
13
13
  source.push("date: " + new expressions_1.SourceTranspiler().transpile(date, traversal).getCode());
14
14
  }
15
- else if ((date === null || date === void 0 ? void 0 : date.get()) instanceof abaplint.Expressions.Target) {
15
+ else if (date?.get() instanceof abaplint.Expressions.Target) {
16
16
  target.push("date: " + new expressions_1.TargetTranspiler().transpile(date, traversal).getCode());
17
17
  }
18
18
  const time = node.findExpressionAfterToken("TIME");
19
- if ((time === null || time === void 0 ? void 0 : time.get()) instanceof abaplint.Expressions.Source) {
19
+ if (time?.get() instanceof abaplint.Expressions.Source) {
20
20
  source.push("time: " + new expressions_1.SourceTranspiler().transpile(time, traversal).getCode());
21
21
  }
22
- else if ((time === null || time === void 0 ? void 0 : time.get()) instanceof abaplint.Expressions.Target) {
22
+ else if (time?.get() instanceof abaplint.Expressions.Target) {
23
23
  target.push("time: " + new expressions_1.TargetTranspiler().transpile(time, traversal).getCode());
24
24
  }
25
25
  const stamp = node.findExpressionAfterToken("STAMP");
26
- if ((stamp === null || stamp === void 0 ? void 0 : stamp.get()) instanceof abaplint.Expressions.Source) {
26
+ if (stamp?.get() instanceof abaplint.Expressions.Source) {
27
27
  source.push("stamp: " + new expressions_1.SourceTranspiler().transpile(stamp, traversal).getCode());
28
28
  }
29
- else if ((stamp === null || stamp === void 0 ? void 0 : stamp.get()) instanceof abaplint.Expressions.Target) {
29
+ else if (stamp?.get() instanceof abaplint.Expressions.Target) {
30
30
  target.push("stamp: " + new expressions_1.TargetTranspiler().transpile(stamp, traversal).getCode());
31
31
  }
32
32
  const zone = node.findExpressionAfterToken("ZONE");
33
- if ((zone === null || zone === void 0 ? void 0 : zone.get()) instanceof abaplint.Expressions.Source) {
33
+ if (zone?.get() instanceof abaplint.Expressions.Source) {
34
34
  source.push("zone: " + new expressions_1.SourceTranspiler().transpile(zone, traversal).getCode());
35
35
  }
36
- else if ((zone === null || zone === void 0 ? void 0 : zone.get()) instanceof abaplint.Expressions.Target) {
36
+ else if (zone?.get() instanceof abaplint.Expressions.Target) {
37
37
  target.push("zone: " + new expressions_1.TargetTranspiler().transpile(zone, traversal).getCode());
38
38
  }
39
39
  return new chunk_1.Chunk(`abap.statements.convert({${source.join(",")}}, {${target.join(",")}});`);
@@ -7,24 +7,23 @@ const expressions_1 = require("../expressions");
7
7
  const transpile_types_1 = require("../transpile_types");
8
8
  class CreateDataTranspiler {
9
9
  transpile(node, traversal) {
10
- var _a, _b, _c;
11
10
  const targetNode = node.findDirectExpression(abaplint.Expressions.Target);
12
11
  const target = traversal.traverse(targetNode);
13
12
  const concat = node.concatTokens().toUpperCase();
14
13
  const options = [];
15
- let dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
14
+ let dynamic = node.findDirectExpression(abaplint.Expressions.Dynamic)?.findFirstExpression(abaplint.Expressions.ConstantString);
16
15
  if (dynamic) {
17
16
  options.push(`"name": ` + dynamic.getFirstToken().getStr());
18
17
  }
19
18
  else {
20
- dynamic = (_b = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldChain);
19
+ dynamic = node.findDirectExpression(abaplint.Expressions.Dynamic)?.findFirstExpression(abaplint.Expressions.FieldChain);
21
20
  if (dynamic) {
22
21
  options.push(`"name": ` + new expressions_1.FieldChainTranspiler(true).transpile(dynamic, traversal).getCode());
23
22
  }
24
23
  }
25
24
  const typeNameNode = node.findDirectExpression(abaplint.Expressions.TypeName);
26
25
  if (typeNameNode) {
27
- const id = (_c = traversal.findCurrentScopeByToken(typeNameNode.getFirstToken())) === null || _c === void 0 ? void 0 : _c.findType(typeNameNode.concatTokens());
26
+ const id = traversal.findCurrentScopeByToken(typeNameNode.getFirstToken())?.findType(typeNameNode.concatTokens());
28
27
  if (id) {
29
28
  options.push(`"type": ` + new transpile_types_1.TranspileTypes().toType(id.getType()));
30
29
  }
@@ -8,7 +8,6 @@ const unique_identifier_1 = require("../unique_identifier");
8
8
  const types_1 = require("../types");
9
9
  class CreateObjectTranspiler {
10
10
  transpile(node, traversal) {
11
- var _a, _b;
12
11
  const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode();
13
12
  let para = "";
14
13
  const parameters = node.findFirstExpression(abaplint.Expressions.ParameterListS);
@@ -17,13 +16,13 @@ class CreateObjectTranspiler {
17
16
  }
18
17
  let name = "";
19
18
  let directGlobal = false;
20
- let dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
19
+ let dynamic = node.findDirectExpression(abaplint.Expressions.Dynamic)?.findFirstExpression(abaplint.Expressions.ConstantString);
21
20
  if (dynamic) {
22
21
  name = dynamic.getFirstToken().getStr();
23
22
  // name = name.substring(1, name.length - 1);
24
23
  }
25
24
  else {
26
- dynamic = (_b = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldChain);
25
+ dynamic = node.findDirectExpression(abaplint.Expressions.Dynamic)?.findFirstExpression(abaplint.Expressions.FieldChain);
27
26
  if (dynamic) {
28
27
  name = new expressions_1.FieldChainTranspiler(true).transpile(dynamic, traversal).getCode();
29
28
  directGlobal = true;
@@ -46,7 +45,6 @@ class CreateObjectTranspiler {
46
45
  return new chunk_1.Chunk(ret);
47
46
  }
48
47
  findClassName(node, traversal) {
49
- var _a;
50
48
  const c = node.findDirectExpression(abaplint.Expressions.ClassName);
51
49
  if (c) {
52
50
  return c.concatTokens();
@@ -61,14 +59,14 @@ class CreateObjectTranspiler {
61
59
  }
62
60
  const type = traversal.determineType(node, scope);
63
61
  if (type === undefined) {
64
- throw new Error(`CreateObjectTranspiler, target variable "${target === null || target === void 0 ? void 0 : target.concatTokens()}" not found in scope`);
62
+ throw new Error(`CreateObjectTranspiler, target variable "${target?.concatTokens()}" not found in scope`);
65
63
  }
66
64
  else if (type instanceof abaplint.BasicTypes.GenericObjectReferenceType) {
67
65
  return "object";
68
66
  }
69
67
  else if (!(type instanceof abaplint.BasicTypes.ObjectReferenceType)) {
70
- if (((_a = traversal.options) === null || _a === void 0 ? void 0 : _a.unknownTypes) !== types_1.UnknownTypesEnum.runtimeError) {
71
- throw new Error(`CreateObjectTranspiler, target variable "${target === null || target === void 0 ? void 0 : target.concatTokens()}" not a object reference`);
68
+ if (traversal.options?.unknownTypes !== types_1.UnknownTypesEnum.runtimeError) {
69
+ throw new Error(`CreateObjectTranspiler, target variable "${target?.concatTokens()}" not a object reference`);
72
70
  }
73
71
  else {
74
72
  return "RUNTIME_ERROR";
@@ -8,8 +8,7 @@ const expressions_1 = require("../expressions");
8
8
  const chunk_1 = require("../chunk");
9
9
  class DataTranspiler {
10
10
  transpile(node, traversal) {
11
- var _a;
12
- const token = (_a = node.findFirstExpression(abaplint.Expressions.DefinitionName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
11
+ const token = node.findFirstExpression(abaplint.Expressions.DefinitionName)?.getFirstToken();
13
12
  if (token === undefined) {
14
13
  throw new Error("DataTranspiler, token not found");
15
14
  }
@@ -26,14 +26,13 @@ class EndMethodTranspiler {
26
26
  return new chunk_1.Chunk().append(returning + "}", node, traversal);
27
27
  }
28
28
  setSubrc(scope, traversal) {
29
- var _a, _b;
30
29
  let methodName = undefined;
31
- if ((scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype) === abaplint.ScopeType.Method) {
32
- methodName = scope === null || scope === void 0 ? void 0 : scope.getIdentifier().sname;
30
+ if (scope?.getIdentifier().stype === abaplint.ScopeType.Method) {
31
+ methodName = scope?.getIdentifier().sname;
33
32
  }
34
33
  let className = undefined;
35
- if (((_a = scope === null || scope === void 0 ? void 0 : scope.getParent()) === null || _a === void 0 ? void 0 : _a.getIdentifier().stype) === abaplint.ScopeType.ClassImplementation) {
36
- className = (_b = scope === null || scope === void 0 ? void 0 : scope.getParent()) === null || _b === void 0 ? void 0 : _b.getIdentifier().sname;
34
+ if (scope?.getParent()?.getIdentifier().stype === abaplint.ScopeType.ClassImplementation) {
35
+ className = scope?.getParent()?.getIdentifier().sname;
37
36
  }
38
37
  if (methodName === undefined || className === undefined) {
39
38
  return "";
@@ -42,11 +41,11 @@ class EndMethodTranspiler {
42
41
  if (methodName.includes("~")) {
43
42
  const split = methodName.split("~");
44
43
  const classDef = traversal.findInterfaceDefinition(split[0], scope);
45
- methodDef = classDef === null || classDef === void 0 ? void 0 : classDef.getMethodDefinitions().getByName(split[1]);
44
+ methodDef = classDef?.getMethodDefinitions().getByName(split[1]);
46
45
  }
47
46
  else {
48
47
  const classDef = traversal.findClassDefinition(className, scope);
49
- methodDef = classDef === null || classDef === void 0 ? void 0 : classDef.getMethodDefinitions().getByName(methodName);
48
+ methodDef = classDef?.getMethodDefinitions().getByName(methodName);
50
49
  }
51
50
  if (methodDef && methodDef.getExceptions().length > 0) {
52
51
  return "abap.builtin.sy.get().subrc.set(0);\n";
@@ -8,7 +8,7 @@ const transpile_types_1 = require("../transpile_types");
8
8
  class FieldSymbolTranspiler {
9
9
  transpile(node, traversal) {
10
10
  const name = node.findDirectExpression(abaplint.Expressions.FieldSymbol);
11
- const token = name === null || name === void 0 ? void 0 : name.getFirstToken();
11
+ const token = name?.getFirstToken();
12
12
  if (token === undefined) {
13
13
  throw new Error("FieldSymbolTranspiler, token not found");
14
14
  }
@@ -5,15 +5,14 @@ const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class FindTranspiler {
7
7
  transpile(node, traversal) {
8
- var _a, _b;
9
8
  const options = [];
10
9
  let index = 1;
11
10
  const sources = node.findDirectExpressions(abaplint.Expressions.Source);
12
11
  const source0 = traversal.traverse(sources[0]).getCode();
13
- if ((_a = node.findFirstExpression(abaplint.Expressions.FindType)) === null || _a === void 0 ? void 0 : _a.findDirectTokenByText("REGEX")) {
12
+ if (node.findFirstExpression(abaplint.Expressions.FindType)?.findDirectTokenByText("REGEX")) {
14
13
  options.push("regex: " + source0);
15
14
  }
16
- else if ((_b = node.findFirstExpression(abaplint.Expressions.FindType)) === null || _b === void 0 ? void 0 : _b.findDirectTokenByText("PCRE")) {
15
+ else if (node.findFirstExpression(abaplint.Expressions.FindType)?.findDirectTokenByText("PCRE")) {
17
16
  options.push("pcre: " + source0);
18
17
  }
19
18
  else {
@@ -40,7 +39,7 @@ class FindTranspiler {
40
39
  let prev = undefined;
41
40
  let off;
42
41
  for (const c of node.getChildren()) {
43
- if ((prev === null || prev === void 0 ? void 0 : prev.getFirstToken().getStr().toUpperCase()) === "OFFSET"
42
+ if (prev?.getFirstToken().getStr().toUpperCase() === "OFFSET"
44
43
  && c.get() instanceof abaplint.Expressions.Target) {
45
44
  options.push("offset: " + traversal.traverse(c).getCode());
46
45
  off = c;
@@ -9,16 +9,16 @@ class FormTranspiler {
9
9
  unique_identifier_1.UniqueIdentifier.resetIndexBackup();
10
10
  const name = node.findFirstExpression(abaplint.Expressions.FormName).getFirstToken().getStr();
11
11
  const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
12
- const def = scope === null || scope === void 0 ? void 0 : scope.findFormDefinition(name);
12
+ const def = scope?.findFormDefinition(name);
13
13
  const ret = new chunk_1.Chunk("async function " + name + "(INPUT) {");
14
14
  const params = [];
15
- for (const p of (def === null || def === void 0 ? void 0 : def.getChangingParameters()) || []) {
15
+ for (const p of def?.getChangingParameters() || []) {
16
16
  params.push(`let ${p.getName()} = INPUT.${p.getName()};`);
17
17
  }
18
- for (const p of (def === null || def === void 0 ? void 0 : def.getTablesParameters()) || []) {
18
+ for (const p of def?.getTablesParameters() || []) {
19
19
  params.push(`let ${p.getName()} = INPUT.${p.getName()};`);
20
20
  }
21
- for (const p of (def === null || def === void 0 ? void 0 : def.getUsingParameters()) || []) {
21
+ for (const p of def?.getUsingParameters() || []) {
22
22
  params.push(`let ${p.getName()} = INPUT.${p.getName()};`);
23
23
  }
24
24
  if (params.length > 0) {
@@ -10,21 +10,20 @@ class LoopTranspiler {
10
10
  this.unique = "";
11
11
  this.injectFrom = undefined;
12
12
  this.skipInto = undefined;
13
- this.injectFrom = options === null || options === void 0 ? void 0 : options.injectFrom;
14
- this.skipInto = options === null || options === void 0 ? void 0 : options.skipInto;
13
+ this.injectFrom = options?.injectFrom;
14
+ this.skipInto = options?.skipInto;
15
15
  }
16
16
  getTarget() {
17
17
  return this.unique;
18
18
  }
19
19
  transpile(node, traversal) {
20
- var _a, _b, _c;
21
20
  if (!(node.get() instanceof abaplint.Statements.Loop)) {
22
21
  throw new Error("LoopTranspiler, unexpected node");
23
22
  }
24
23
  const source = traversal.traverse(node.findDirectExpression(abaplint.Expressions.SimpleSource2)).getCode();
25
24
  this.unique = unique_identifier_1.UniqueIdentifier.get();
26
25
  let target = "";
27
- const into = (_a = node.findDirectExpression(abaplint.Expressions.LoopTarget)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(abaplint.Expressions.Target);
26
+ const into = node.findDirectExpression(abaplint.Expressions.LoopTarget)?.findDirectExpression(abaplint.Expressions.Target);
28
27
  if (into && this.skipInto !== true) {
29
28
  const concat = node.concatTokens().toUpperCase();
30
29
  const t = traversal.traverse(into).getCode();
@@ -43,7 +42,7 @@ class LoopTranspiler {
43
42
  }
44
43
  }
45
44
  else if (this.skipInto !== true) {
46
- const assigning = (_b = node.findFirstExpression(abaplint.Expressions.FSTarget)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldSymbol);
45
+ const assigning = node.findFirstExpression(abaplint.Expressions.FSTarget)?.findFirstExpression(abaplint.Expressions.FieldSymbol);
47
46
  if (assigning) {
48
47
  target = traversal.traverse(assigning).getCode() + ".assign(" + this.unique + ");";
49
48
  }
@@ -86,8 +85,8 @@ class LoopTranspiler {
86
85
  extra.push("where: async " + where);
87
86
  }
88
87
  const topEquals = {};
89
- for (const compare of (whereNode === null || whereNode === void 0 ? void 0 : whereNode.findDirectExpressions(abaplint.Expressions.ComponentCompare)) || []) {
90
- const op = (_c = compare.findDirectExpression(abaplint.Expressions.CompareOperator)) === null || _c === void 0 ? void 0 : _c.concatTokens().toUpperCase();
88
+ for (const compare of whereNode?.findDirectExpressions(abaplint.Expressions.ComponentCompare) || []) {
89
+ const op = compare.findDirectExpression(abaplint.Expressions.CompareOperator)?.concatTokens().toUpperCase();
91
90
  if (op !== "=" && op !== "EQ") {
92
91
  continue;
93
92
  }
@@ -95,7 +94,7 @@ class LoopTranspiler {
95
94
  continue;
96
95
  }
97
96
  const simple = compare.findDirectExpression(abaplint.Expressions.ComponentChainSimple);
98
- if ((simple === null || simple === void 0 ? void 0 : simple.getChildren().length) !== 1) {
97
+ if (simple?.getChildren().length !== 1) {
99
98
  continue;
100
99
  }
101
100
  const tchain = traversal.traverse(simple);
@@ -10,7 +10,6 @@ const chunk_1 = require("../chunk");
10
10
  const unique_identifier_1 = require("../unique_identifier");
11
11
  class MethodImplementationTranspiler {
12
12
  transpile(node, traversal) {
13
- var _a, _b, _c;
14
13
  const token = node.findFirstExpression(abaplint.Expressions.MethodName).getFirstToken();
15
14
  let methodName = token.getStr();
16
15
  const scope = traversal.findCurrentScopeByToken(token);
@@ -41,8 +40,8 @@ class MethodImplementationTranspiler {
41
40
  if (unique === "") {
42
41
  unique = "INPUT";
43
42
  }
44
- const parameterDefault = methodDef === null || methodDef === void 0 ? void 0 : methodDef.getParameterDefault(varName);
45
- const isOptional = methodDef === null || methodDef === void 0 ? void 0 : methodDef.getOptional().includes(varName.toUpperCase());
43
+ const parameterDefault = methodDef?.getParameterDefault(varName);
44
+ const isOptional = methodDef?.getOptional().includes(varName.toUpperCase());
46
45
  const passByValue = identifier.getMeta().includes("pass_by_value" /* abaplint.IdentifierMeta.PassByValue */);
47
46
  const type = identifier.getType();
48
47
  if (identifier.getMeta().includes("exporting" /* abaplint.IdentifierMeta.MethodExporting */)) {
@@ -55,7 +54,7 @@ class MethodImplementationTranspiler {
55
54
  && type.isGeneric() === false) {
56
55
  after += `let ${varName} = ${unique}?.${varName};\n`;
57
56
  if (identifier.getType().getQualifiedName() !== undefined && identifier.getType().getQualifiedName() !== "") {
58
- after += `if (${varName}?.getQualifiedName === undefined || ${varName}.getQualifiedName() !== "${(_a = identifier.getType().getQualifiedName()) === null || _a === void 0 ? void 0 : _a.toUpperCase()}") { ${varName} = undefined; }\n`;
57
+ after += `if (${varName}?.getQualifiedName === undefined || ${varName}.getQualifiedName() !== "${identifier.getType().getQualifiedName()?.toUpperCase()}") { ${varName} = undefined; }\n`;
59
58
  }
60
59
  after += `if (${varName} === undefined) { ${varName} = ${new transpile_types_1.TranspileTypes().toType(identifier.getType())}.set(${unique}.${varName}); }\n`;
61
60
  }
@@ -85,7 +84,7 @@ class MethodImplementationTranspiler {
85
84
  after += "if (" + unique + " && " + unique + "." + varName + ") {" + varName + " = " + unique + "." + varName + ";}\n";
86
85
  }
87
86
  if (parameterDefault) {
88
- const val = this.buildDefault(parameterDefault, traversal, methodDef === null || methodDef === void 0 ? void 0 : methodDef.getFilename());
87
+ const val = this.buildDefault(parameterDefault, traversal, methodDef?.getFilename());
89
88
  if (passByValue === true || identifier.getMeta().includes("changing" /* abaplint.IdentifierMeta.MethodChanging */)) {
90
89
  after += "if (" + unique + " === undefined || " + unique + "." + varName + " === undefined) {" + varName + ".set(" + val + ");}\n";
91
90
  }
@@ -110,15 +109,15 @@ class MethodImplementationTranspiler {
110
109
  // it messes up promises when "this" is returned
111
110
  throw new Error(`Method name "then" not allowed`);
112
111
  }
113
- const superDef = traversal.findClassDefinition(classDef === null || classDef === void 0 ? void 0 : classDef.getSuperClass(), scope);
114
- for (const a of (superDef === null || superDef === void 0 ? void 0 : superDef.getAliases().getAll()) || []) {
112
+ const superDef = traversal.findClassDefinition(classDef?.getSuperClass(), scope);
113
+ for (const a of superDef?.getAliases().getAll() || []) {
115
114
  if (a.getName().toLowerCase() === methodName) {
116
115
  methodName = a.getComponent().replace("~", "$").toLowerCase();
117
116
  }
118
117
  }
119
118
  if (method && method.isStatic()) {
120
119
  // in ABAP static methods can be called with instance arrows, "->"
121
- const className = (_c = (_b = scope.getParent()) === null || _b === void 0 ? void 0 : _b.getIdentifier().sname) === null || _c === void 0 ? void 0 : _c.toLowerCase();
120
+ const className = scope.getParent()?.getIdentifier().sname?.toLowerCase();
122
121
  staticMethod = "async " + traversal_1.Traversal.escapeNamespace(methodName) + "(" + unique + ") {\n" +
123
122
  "return " + traversal_1.Traversal.escapeNamespace(className) + "." + traversal_1.Traversal.escapeNamespace(methodName) + "(" + unique + ");\n" +
124
123
  "}\n" + "static ";
@@ -200,7 +199,6 @@ class MethodImplementationTranspiler {
200
199
  return val;
201
200
  }
202
201
  findMethod(name, cdef, traversal) {
203
- var _a, _b;
204
202
  if (cdef === undefined) {
205
203
  return undefined;
206
204
  }
@@ -210,10 +208,10 @@ class MethodImplementationTranspiler {
210
208
  name = split[1];
211
209
  const scope = traversal.findCurrentScopeByToken(cdef.getToken());
212
210
  const intf = traversal.findInterfaceDefinition(intfName, scope);
213
- return (_a = intf === null || intf === void 0 ? void 0 : intf.getMethodDefinitions()) === null || _a === void 0 ? void 0 : _a.getByName(name);
211
+ return intf?.getMethodDefinitions()?.getByName(name);
214
212
  }
215
213
  else {
216
- return (_b = cdef.getMethodDefinitions()) === null || _b === void 0 ? void 0 : _b.getByName(name);
214
+ return cdef.getMethodDefinitions()?.getByName(name);
217
215
  }
218
216
  }
219
217
  findMethodParameters(scope) {
@@ -5,14 +5,13 @@ const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class MoveTranspiler {
7
7
  transpile(node, traversal) {
8
- var _a;
9
8
  let source = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Source));
10
9
  const targets = [];
11
10
  for (const t of node.findDirectExpressions(abaplint.Expressions.Target)) {
12
11
  targets.push(traversal.traverse(t));
13
12
  }
14
13
  const ret = new chunk_1.Chunk();
15
- const second = (_a = node.getChildren()[1]) === null || _a === void 0 ? void 0 : _a.concatTokens();
14
+ const second = node.getChildren()[1]?.concatTokens();
16
15
  if (second === "?=") {
17
16
  ret.appendString("await abap.statements.cast(")
18
17
  .appendChunk(targets[0])
@@ -9,13 +9,13 @@ class OpenCursorTranspiler {
9
9
  const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.SQLTarget)).getCode();
10
10
  const selectExpression = node.findDirectExpression(abaplint.Expressions.Select);
11
11
  let select = "SELECT ";
12
- select += traversal.traverse(selectExpression === null || selectExpression === void 0 ? void 0 : selectExpression.findDirectExpression(abaplint.Expressions.SQLFieldList)).getCode() + " ";
13
- select += traversal.traverse(selectExpression === null || selectExpression === void 0 ? void 0 : selectExpression.findDirectExpression(abaplint.Expressions.SQLFrom)).getCode();
14
- const cond = selectExpression === null || selectExpression === void 0 ? void 0 : selectExpression.findDirectExpression(abaplint.Expressions.SQLCond);
12
+ select += traversal.traverse(selectExpression?.findDirectExpression(abaplint.Expressions.SQLFieldList)).getCode() + " ";
13
+ select += traversal.traverse(selectExpression?.findDirectExpression(abaplint.Expressions.SQLFrom)).getCode();
14
+ const cond = selectExpression?.findDirectExpression(abaplint.Expressions.SQLCond);
15
15
  if (cond) {
16
16
  select += "WHERE " + traversal.traverse(node).getCode();
17
17
  }
18
- const orderBy = selectExpression === null || selectExpression === void 0 ? void 0 : selectExpression.findDirectExpression(abaplint.Expressions.SQLOrderBy);
18
+ const orderBy = selectExpression?.findDirectExpression(abaplint.Expressions.SQLOrderBy);
19
19
  if (orderBy) {
20
20
  select += "ORDER BY " + traversal.traverse(node).getCode();
21
21
  }
@@ -6,7 +6,6 @@ const abaplint = require("@abaplint/core");
6
6
  const chunk_1 = require("../chunk");
7
7
  class PerformTranspiler {
8
8
  transpile(node, traversal) {
9
- var _a, _b, _c;
10
9
  const formName = node.findDirectExpression(abaplint.Expressions.FormName);
11
10
  if (formName === undefined) {
12
11
  return new chunk_1.Chunk(`throw new Error("PerformTranspiler FormName not found");`);
@@ -16,7 +15,7 @@ class PerformTranspiler {
16
15
  }
17
16
  let def = undefined;
18
17
  const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
19
- for (const r of (scope === null || scope === void 0 ? void 0 : scope.getData().references) || []) {
18
+ for (const r of scope?.getData().references || []) {
20
19
  if (r.referenceType === abaplint.ReferenceType.FormReference
21
20
  && r.position.getStart().equals(formName.getFirstToken().getStart())
22
21
  && r.resolved instanceof abaplint.Types.FormDefinition) {
@@ -26,8 +25,8 @@ class PerformTranspiler {
26
25
  // todo: pass by VALUE()
27
26
  const params = [];
28
27
  let index = 0;
29
- for (const t of ((_a = node.findDirectExpression(abaplint.Expressions.PerformTables)) === null || _a === void 0 ? void 0 : _a.findDirectExpressions(abaplint.Expressions.Source)) || []) {
30
- const name = def === null || def === void 0 ? void 0 : def.getTablesParameters()[index].getName().toLowerCase();
28
+ for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
29
+ const name = def?.getTablesParameters()[index].getName().toLowerCase();
31
30
  if (name === undefined) {
32
31
  continue;
33
32
  }
@@ -35,8 +34,8 @@ class PerformTranspiler {
35
34
  index++;
36
35
  }
37
36
  index = 0;
38
- for (const u of ((_b = node.findDirectExpression(abaplint.Expressions.PerformUsing)) === null || _b === void 0 ? void 0 : _b.findDirectExpressions(abaplint.Expressions.Source)) || []) {
39
- const name = def === null || def === void 0 ? void 0 : def.getUsingParameters()[index].getName().toLowerCase();
37
+ for (const u of node.findDirectExpression(abaplint.Expressions.PerformUsing)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
38
+ const name = def?.getUsingParameters()[index].getName().toLowerCase();
40
39
  if (name === undefined) {
41
40
  continue;
42
41
  }
@@ -44,8 +43,8 @@ class PerformTranspiler {
44
43
  index++;
45
44
  }
46
45
  index = 0;
47
- for (const c of ((_c = node.findDirectExpression(abaplint.Expressions.PerformChanging)) === null || _c === void 0 ? void 0 : _c.findDirectExpressions(abaplint.Expressions.Source)) || []) {
48
- const name = def === null || def === void 0 ? void 0 : def.getChangingParameters()[index].getName().toLowerCase();
46
+ for (const c of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
47
+ const name = def?.getChangingParameters()[index].getName().toLowerCase();
49
48
  if (name === undefined) {
50
49
  continue;
51
50
  }
@@ -7,13 +7,12 @@ const expressions_1 = require("../expressions");
7
7
  const unique_identifier_1 = require("../unique_identifier");
8
8
  class RaiseTranspiler {
9
9
  transpile(node, traversal) {
10
- var _a, _b;
11
- const classNameToken = (_a = node.findFirstExpression(abaplint.Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
12
- const className = classNameToken === null || classNameToken === void 0 ? void 0 : classNameToken.getStr();
10
+ const classNameToken = node.findFirstExpression(abaplint.Expressions.ClassName)?.getFirstToken();
11
+ const className = classNameToken?.getStr();
13
12
  if (className === undefined) {
14
13
  const s = node.findFirstExpression(abaplint.Expressions.SimpleSource2);
15
14
  if (s === undefined) {
16
- const name = (_b = node.findFirstExpression(abaplint.Expressions.ExceptionName)) === null || _b === void 0 ? void 0 : _b.concatTokens().toLowerCase();
15
+ const name = node.findFirstExpression(abaplint.Expressions.ExceptionName)?.concatTokens().toLowerCase();
17
16
  return new chunk_1.Chunk().append(`throw new abap.ClassicError({classic: "${name}"});`, node, traversal);
18
17
  }
19
18
  const sCode = new expressions_1.SourceTranspiler(true).transpile(s, traversal).getCode();
@@ -25,7 +24,7 @@ class RaiseTranspiler {
25
24
  p = traversal.traverse(parameters).getCode();
26
25
  }
27
26
  const extra = `{"INTERNAL_FILENAME": "${traversal.getFilename()}","INTERNAL_LINE": ${node.getStart().getRow()}}`;
28
- const lookup = traversal.lookupClassOrInterface(classNameToken === null || classNameToken === void 0 ? void 0 : classNameToken.getStr(), classNameToken);
27
+ const lookup = traversal.lookupClassOrInterface(classNameToken?.getStr(), classNameToken);
29
28
  const id = unique_identifier_1.UniqueIdentifier.get();
30
29
  return new chunk_1.Chunk().append(`const ${id} = await (new ${lookup}()).constructor_(${p});
31
30
  ${id}.EXTRA_CX = ${extra};
@@ -34,15 +34,15 @@ class ReadTableTranspiler {
34
34
  extra.push("withTableKey: true");
35
35
  }
36
36
  const rt = node.findDirectExpression(abaplint.Expressions.ReadTableTarget);
37
- const target = rt === null || rt === void 0 ? void 0 : rt.findDirectExpression(abaplint.Expressions.Target);
38
- const fs = rt === null || rt === void 0 ? void 0 : rt.findDirectExpression(abaplint.Expressions.FSTarget);
37
+ const target = rt?.findDirectExpression(abaplint.Expressions.Target);
38
+ const fs = rt?.findDirectExpression(abaplint.Expressions.FSTarget);
39
39
  if (rt && fs) {
40
40
  const name = new expressions_1.FieldSymbolTranspiler().transpile(fs, traversal).getCode();
41
41
  extra.push("assigning: " + name);
42
42
  }
43
43
  else if (target) {
44
44
  const name = traversal.traverse(target).getCode();
45
- if (rt === null || rt === void 0 ? void 0 : rt.findDirectTokenByText("REFERENCE")) {
45
+ if (rt?.findDirectTokenByText("REFERENCE")) {
46
46
  extra.push("referenceInto: " + name);
47
47
  }
48
48
  else {