@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
@@ -18,7 +18,7 @@ class Traversal {
18
18
  this.options = options;
19
19
  }
20
20
  static escapeNamespace(name) {
21
- return name === null || name === void 0 ? void 0 : name.replace(/\//g, "$");
21
+ return name?.replace(/\//g, "$");
22
22
  }
23
23
  getCurrentObject() {
24
24
  return this.obj;
@@ -83,7 +83,7 @@ class Traversal {
83
83
  let scope = this.findCurrentScopeByToken(token);
84
84
  while (scope !== undefined) {
85
85
  if (scope.getIdentifier().stype === abaplint.ScopeType.Interface) {
86
- return scope.findInterfaceDefinition(scope === null || scope === void 0 ? void 0 : scope.getIdentifier().sname);
86
+ return scope.findInterfaceDefinition(scope?.getIdentifier().sname);
87
87
  }
88
88
  scope = scope.getParent();
89
89
  }
@@ -94,7 +94,7 @@ class Traversal {
94
94
  while (scope !== undefined) {
95
95
  if (scope.getIdentifier().stype === abaplint.ScopeType.ClassImplementation
96
96
  || scope.getIdentifier().stype === abaplint.ScopeType.ClassDefinition) {
97
- return scope.findClassDefinition(scope === null || scope === void 0 ? void 0 : scope.getIdentifier().sname);
97
+ return scope.findClassDefinition(scope?.getIdentifier().sname);
98
98
  }
99
99
  scope = scope.getParent();
100
100
  }
@@ -201,18 +201,17 @@ class Traversal {
201
201
  }
202
202
  }
203
203
  buildAttributes(def, scope, prefix = "") {
204
- var _a, _b;
205
204
  const attr = [];
206
205
  if (def === undefined) {
207
206
  return attr;
208
207
  }
209
- for (const a of ((_a = def.getAttributes()) === null || _a === void 0 ? void 0 : _a.getAll()) || []) {
208
+ for (const a of def.getAttributes()?.getAll() || []) {
210
209
  const type = new transpile_types_1.TranspileTypes().toType(a.getType());
211
210
  const runtime = this.mapVisibility(a.getVisibility());
212
211
  const isClass = a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) ? "X" : " ";
213
212
  attr.push(`"${prefix + a.getName().toUpperCase()}": {"type": () => {return ${type};}, "visibility": "${runtime}", "is_constant": " ", "is_class": "${isClass}"}`);
214
213
  }
215
- for (const a of ((_b = def.getAttributes()) === null || _b === void 0 ? void 0 : _b.getConstants()) || []) {
214
+ for (const a of def.getAttributes()?.getConstants() || []) {
216
215
  const type = new transpile_types_1.TranspileTypes().toType(a.getType());
217
216
  let runtime = "";
218
217
  switch (a.getVisibility()) {
@@ -248,7 +247,7 @@ class Traversal {
248
247
  }
249
248
  isSQLConversion(token) {
250
249
  const scope = this.findCurrentScopeByToken(token);
251
- for (const s of (scope === null || scope === void 0 ? void 0 : scope.getData().sqlConversion) || []) {
250
+ for (const s of scope?.getData().sqlConversion || []) {
252
251
  if (s.token.getStart().equals(token.getStart())) {
253
252
  return s.fieldName;
254
253
  }
@@ -256,7 +255,6 @@ class Traversal {
256
255
  return undefined;
257
256
  }
258
257
  findMethodReference(token, scope) {
259
- var _a, _b;
260
258
  let candidate = undefined;
261
259
  if (scope === undefined) {
262
260
  return undefined;
@@ -266,7 +264,7 @@ class Traversal {
266
264
  && r.position.getStart().equals(token.getStart())
267
265
  && r.resolved instanceof abaplint.Types.MethodDefinition) {
268
266
  let name = r.resolved.getName();
269
- if (((_a = r.extra) === null || _a === void 0 ? void 0 : _a.ooName) && ((_b = r.extra) === null || _b === void 0 ? void 0 : _b.ooType) === "INTF") {
267
+ if (r.extra?.ooName && r.extra?.ooType === "INTF") {
270
268
  name = r.extra.ooName + "$" + name;
271
269
  }
272
270
  candidate = { def: r.resolved, name };
@@ -300,13 +298,13 @@ class Traversal {
300
298
  }
301
299
  isTypePool(token) {
302
300
  const ref = this.findReadOrWriteReference(token);
303
- if (ref === null || ref === void 0 ? void 0 : ref.getFilename().endsWith(".type.abap")) {
301
+ if (ref?.getFilename().endsWith(".type.abap")) {
304
302
  const file = this.reg.getFileByName(ref.getFilename());
305
303
  if (file === undefined) {
306
304
  return undefined;
307
305
  }
308
306
  const obj = this.reg.findObjectForFile(file);
309
- return obj === null || obj === void 0 ? void 0 : obj.getName();
307
+ return obj?.getName();
310
308
  }
311
309
  return undefined;
312
310
  }
@@ -319,8 +317,8 @@ class Traversal {
319
317
  // local
320
318
  if (ref.getFilename() === this.getFilename()) {
321
319
  const scope = this.findCurrentScopeByToken(ref.getToken());
322
- if ((scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype) === abaplint.ScopeType.Interface) {
323
- return scope === null || scope === void 0 ? void 0 : scope.getIdentifier().sname;
320
+ if (scope?.getIdentifier().stype === abaplint.ScopeType.Interface) {
321
+ return scope?.getIdentifier().sname;
324
322
  }
325
323
  }
326
324
  // global
@@ -355,7 +353,6 @@ class Traversal {
355
353
  return undefined;
356
354
  }
357
355
  buildConstructorContents(scope, def) {
358
- var _a, _b, _c;
359
356
  let ret = "";
360
357
  if (def.getSuperClass() !== undefined || def.getName().toUpperCase() === "CX_ROOT") {
361
358
  ret += "super();\n";
@@ -363,7 +360,7 @@ class Traversal {
363
360
  const cName = Traversal.escapeNamespace(def.getName().toLowerCase());
364
361
  ret += "this.me = new abap.types.ABAPObject();\n";
365
362
  ret += "this.me.set(this);\n";
366
- for (const a of ((_a = def.getAttributes()) === null || _a === void 0 ? void 0 : _a.getAll()) || []) {
363
+ for (const a of def.getAttributes()?.getAll() || []) {
367
364
  const escaped = Traversal.escapeNamespace(a.getName().toLowerCase());
368
365
  if (a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) === true) {
369
366
  ret += "this." + escaped + " = " + cName + "." + escaped + ";\n";
@@ -379,20 +376,20 @@ class Traversal {
379
376
  ret += this.aliasesFromInterfaces(i.name, scope, cName);
380
377
  }
381
378
  // handle aliases after initialization of carrier variables
382
- for (const a of ((_b = def.getAliases()) === null || _b === void 0 ? void 0 : _b.getAll()) || []) {
379
+ for (const a of def.getAliases()?.getAll() || []) {
383
380
  ret += "this." + a.getName().toLowerCase() + " = this." + Traversal.escapeNamespace(a.getComponent().replace("~", "$").toLowerCase()) + ";\n";
384
381
  }
385
382
  // constants can be accessed both statically and via reference
386
- for (const c of ((_c = def.getAttributes()) === null || _c === void 0 ? void 0 : _c.getConstants()) || []) {
383
+ for (const c of def.getAttributes()?.getConstants() || []) {
387
384
  ret += "this." + Traversal.escapeNamespace(c.getName().toLowerCase()) + " = " + cName + "." + Traversal.escapeNamespace(c.getName().toLowerCase()) + ";\n";
388
385
  }
389
386
  return ret;
390
387
  }
391
388
  findInterfaceDefinition(name, scope) {
392
- let intf = scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(name);
389
+ let intf = scope?.findInterfaceDefinition(name);
393
390
  if (intf === undefined) {
394
391
  const iglobal = this.reg.getObject("INTF", name);
395
- intf = iglobal === null || iglobal === void 0 ? void 0 : iglobal.getDefinition();
392
+ intf = iglobal?.getDefinition();
396
393
  }
397
394
  return intf;
398
395
  }
@@ -407,24 +404,24 @@ class Traversal {
407
404
  let clas = scope.findClassDefinition(name);
408
405
  if (clas === undefined) {
409
406
  const iglobal = this.reg.getObject("CLAS", name);
410
- clas = iglobal === null || iglobal === void 0 ? void 0 : iglobal.getDefinition();
407
+ clas = iglobal?.getDefinition();
411
408
  }
412
409
  return clas;
413
410
  }
414
411
  dataFromInterfaces(name, scope, cname) {
415
412
  let ret = "";
416
413
  const intf = this.findInterfaceDefinition(name, scope);
417
- for (const a of (intf === null || intf === void 0 ? void 0 : intf.getAttributes().getConstants()) || []) {
414
+ for (const a of intf?.getAttributes().getConstants() || []) {
418
415
  const fname = Traversal.escapeNamespace(a.getName().toLowerCase());
419
- const iname = Traversal.escapeNamespace(intf === null || intf === void 0 ? void 0 : intf.getName().toLowerCase());
420
- if ((intf === null || intf === void 0 ? void 0 : intf.isGlobal()) === true) {
421
- ret += "this." + iname + "$" + fname + " = abap.Classes['" + (intf === null || intf === void 0 ? void 0 : intf.getName().toUpperCase()) + "']." + iname + "$" + fname + ";\n";
416
+ const iname = Traversal.escapeNamespace(intf?.getName().toLowerCase());
417
+ if (intf?.isGlobal() === true) {
418
+ ret += "this." + iname + "$" + fname + " = abap.Classes['" + intf?.getName().toUpperCase() + "']." + iname + "$" + fname + ";\n";
422
419
  }
423
420
  else {
424
421
  ret += "this." + iname + "$" + fname + " = " + iname + "." + iname + "$" + fname + ";\n";
425
422
  }
426
423
  }
427
- for (const a of (intf === null || intf === void 0 ? void 0 : intf.getAttributes().getAll()) || []) {
424
+ for (const a of intf?.getAttributes().getAll() || []) {
428
425
  const n = Traversal.escapeNamespace(name.toLowerCase()) + "$" + a.getName().toLowerCase();
429
426
  // note: interface inheritenace and super inheritance might be strange,
430
427
  if (a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) === true) {
@@ -434,7 +431,7 @@ class Traversal {
434
431
  ret += "if (this." + n + " === undefined) this." + n + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
435
432
  }
436
433
  }
437
- for (const i of (intf === null || intf === void 0 ? void 0 : intf.getImplementing()) || []) {
434
+ for (const i of intf?.getImplementing() || []) {
438
435
  ret += this.dataFromInterfaces(i.name, scope, cname);
439
436
  }
440
437
  return ret;
@@ -442,19 +439,18 @@ class Traversal {
442
439
  aliasesFromInterfaces(name, scope, cname) {
443
440
  let ret = "";
444
441
  const intf = this.findInterfaceDefinition(name, scope);
445
- for (const a of (intf === null || intf === void 0 ? void 0 : intf.getAliases().getAll()) || []) {
446
- const iname = Traversal.escapeNamespace(intf === null || intf === void 0 ? void 0 : intf.getName().toLowerCase());
442
+ for (const a of intf?.getAliases().getAll() || []) {
443
+ const iname = Traversal.escapeNamespace(intf?.getName().toLowerCase());
447
444
  const aname = Traversal.escapeNamespace(a.getName().toLowerCase());
448
445
  const cname = Traversal.escapeNamespace(a.getComponent().toLowerCase().replace("~", "$"));
449
446
  ret += "this." + iname + "$" + aname + " = this." + cname + ";\n";
450
447
  }
451
- for (const i of (intf === null || intf === void 0 ? void 0 : intf.getImplementing()) || []) {
448
+ for (const i of intf?.getImplementing() || []) {
452
449
  ret += this.aliasesFromInterfaces(i.name, scope, cname);
453
450
  }
454
451
  return ret;
455
452
  }
456
453
  determineType(node, scope) {
457
- var _a, _b, _c;
458
454
  if (scope === undefined) {
459
455
  return undefined;
460
456
  }
@@ -465,7 +461,7 @@ class Traversal {
465
461
  let context = undefined;
466
462
  for (const c of found.getChildren()) {
467
463
  if (context === undefined) {
468
- context = (_a = scope.findVariable(c.getFirstToken().getStr())) === null || _a === void 0 ? void 0 : _a.getType();
464
+ context = scope.findVariable(c.getFirstToken().getStr())?.getType();
469
465
  }
470
466
  else if (c.get() instanceof abaplint.Expressions.ComponentName
471
467
  && context instanceof abaplint.BasicTypes.StructureType) {
@@ -479,10 +475,10 @@ class Traversal {
479
475
  if (concat.includes("~")) {
480
476
  const [iname, aname] = concat.split("~");
481
477
  const intf = this.findInterfaceDefinition(iname, scope);
482
- context = (_b = intf === null || intf === void 0 ? void 0 : intf.getAttributes().findByName(aname)) === null || _b === void 0 ? void 0 : _b.getType();
478
+ context = intf?.getAttributes().findByName(aname)?.getType();
483
479
  }
484
480
  else {
485
- context = (_c = id.getAttributes().findByName(concat)) === null || _c === void 0 ? void 0 : _c.getType();
481
+ context = id.getAttributes().findByName(concat)?.getType();
486
482
  }
487
483
  }
488
484
  }
@@ -569,14 +565,13 @@ class Traversal {
569
565
  return ret;
570
566
  }
571
567
  buildInternalName(name, def) {
572
- var _a, _b;
573
568
  if (def) {
574
569
  if (def.isGlobal() === false) {
575
570
  const prefix = this.buildPrefix();
576
- return `${prefix}${(_a = def === null || def === void 0 ? void 0 : def.getName()) === null || _a === void 0 ? void 0 : _a.toUpperCase()}`;
571
+ return `${prefix}${def?.getName()?.toUpperCase()}`;
577
572
  }
578
573
  else {
579
- return (_b = def === null || def === void 0 ? void 0 : def.getName()) === null || _b === void 0 ? void 0 : _b.toUpperCase();
574
+ return def?.getName()?.toUpperCase();
580
575
  }
581
576
  }
582
577
  // assume global
@@ -590,9 +585,9 @@ class Traversal {
590
585
  return "abap.Classes[" + name + ".trimEnd()]";
591
586
  }
592
587
  const scope = this.findCurrentScopeByToken(token);
593
- let def = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name);
588
+ let def = scope?.findClassDefinition(name);
594
589
  if (def === undefined) {
595
- def = scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(name);
590
+ def = scope?.findInterfaceDefinition(name);
596
591
  }
597
592
  const internalName = this.buildInternalName(name, def);
598
593
  return "abap.Classes['" + internalName + "']";
@@ -357,11 +357,10 @@ run().then(() => {
357
357
  // class constructors might make early use of eg. constants from interfaces
358
358
  // sub classes will import() super classes and trigger a class constructor of the super
359
359
  hasClassConstructor(reg, clas) {
360
- var _a, _b;
361
- if (((_a = clas.getDefinition()) === null || _a === void 0 ? void 0 : _a.getMethodDefinitions().getByName("CLASS_CONSTRUCTOR")) !== undefined) {
360
+ if (clas.getDefinition()?.getMethodDefinitions().getByName("CLASS_CONSTRUCTOR") !== undefined) {
362
361
  return true;
363
362
  }
364
- const sup = (_b = clas.getDefinition()) === null || _b === void 0 ? void 0 : _b.getSuperClass();
363
+ const sup = clas.getDefinition()?.getSuperClass();
365
364
  if (sup !== undefined) {
366
365
  const superClass = reg.getObject("CLAS", sup);
367
366
  if (superClass) {
@@ -112,15 +112,14 @@ class Validation {
112
112
  this.options = options;
113
113
  }
114
114
  run(reg) {
115
- var _a, _b, _c;
116
- if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.ignoreSyntaxCheck) === true) {
115
+ if (this.options?.ignoreSyntaxCheck === true) {
117
116
  exports.config.rules["check_syntax"] = false;
118
117
  }
119
118
  else {
120
119
  exports.config.rules["check_syntax"] = true;
121
120
  }
122
121
  exports.config.rules["forbidden_identifier"]["check"] = ["^unique\\d+$"];
123
- if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.keywords) === undefined) {
122
+ if (this.options?.keywords === undefined) {
124
123
  for (const d of keywords_1.defaultKeywords) {
125
124
  const add = "^" + d + "$";
126
125
  exports.config.rules["forbidden_identifier"]["check"].push(add);
@@ -132,7 +131,7 @@ class Validation {
132
131
  exports.config.rules["forbidden_identifier"]["check"].push(add);
133
132
  }
134
133
  }
135
- if (((_c = this.options) === null || _c === void 0 ? void 0 : _c.unknownTypes) === types_1.UnknownTypesEnum.runtimeError) {
134
+ if (this.options?.unknownTypes === types_1.UnknownTypesEnum.runtimeError) {
136
135
  // this is not a constant, just a regex that happens to not match anything
137
136
  exports.config.syntax.errorNamespace = "VOID_EVERYTHING";
138
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.7.165",
3
+ "version": "2.8.0",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",