@abaplint/transpiler 2.10.83 → 2.11.1

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 (32) hide show
  1. package/build/src/chunk.js +2 -1
  2. package/build/src/db/index.js +1 -0
  3. package/build/src/db/schema_generation/pg_database_schema.js +1 -0
  4. package/build/src/db/schema_generation/snowflake_database_schema.js +1 -0
  5. package/build/src/db/schema_generation/sqlite_database_schema.js +1 -0
  6. package/build/src/expressions/component_chain_simple.js +1 -1
  7. package/build/src/expressions/constant.js +1 -0
  8. package/build/src/expressions/database_table.js +1 -0
  9. package/build/src/expressions/field_chain.js +2 -0
  10. package/build/src/expressions/method_call_body.js +1 -0
  11. package/build/src/expressions/method_call_param.js +1 -0
  12. package/build/src/expressions/method_source.js +1 -0
  13. package/build/src/expressions/simple_source3.js +1 -0
  14. package/build/src/expressions/source.js +1 -0
  15. package/build/src/handlers/handle_abap.js +1 -0
  16. package/build/src/handlers/handle_fugr.js +1 -0
  17. package/build/src/index.js +1 -0
  18. package/build/src/requires.js +1 -0
  19. package/build/src/statements/do.js +1 -0
  20. package/build/src/statements/end_do.js +1 -0
  21. package/build/src/statements/end_while.js +1 -0
  22. package/build/src/statements/loop.js +3 -3
  23. package/build/src/statements/raise_event.js +10 -2
  24. package/build/src/statements/set_handler.d.ts +1 -0
  25. package/build/src/statements/set_handler.js +47 -5
  26. package/build/src/statements/when.js +1 -0
  27. package/build/src/statements/while.js +1 -0
  28. package/build/src/traversal.d.ts +1 -0
  29. package/build/src/traversal.js +28 -1
  30. package/build/src/unique_identifier.js +2 -2
  31. package/build/src/validation.js +1 -0
  32. package/package.json +2 -2
@@ -14,8 +14,9 @@ abaplint:
14
14
  */
15
15
  // Keeps track of source maps as generated code is added
16
16
  class Chunk {
17
+ raw;
18
+ mappings = [];
17
19
  constructor(str) {
18
- this.mappings = [];
19
20
  this.raw = "";
20
21
  this.mappings = [];
21
22
  if (str) {
@@ -11,6 +11,7 @@ const snowflake_database_schema_1 = require("./schema_generation/snowflake_datab
11
11
  // Postgres is case sensitive, so all column names should be lower case
12
12
  // Sqlite escapes field names with single qoute, postgres with double
13
13
  class DatabaseSetup {
14
+ reg;
14
15
  constructor(reg) {
15
16
  this.reg = reg;
16
17
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PGDatabaseSchema = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class PGDatabaseSchema {
6
+ reg;
6
7
  constructor(reg) {
7
8
  this.reg = reg;
8
9
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SnowflakeDatabaseSchema = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class SnowflakeDatabaseSchema {
6
+ reg;
6
7
  constructor(reg) {
7
8
  this.reg = reg;
8
9
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SQLiteDatabaseSchema = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class SQLiteDatabaseSchema {
6
+ reg;
6
7
  constructor(reg) {
7
8
  this.reg = reg;
8
9
  }
@@ -7,8 +7,8 @@ const traversal_1 = require("../traversal");
7
7
  const field_length_1 = require("./field_length");
8
8
  const field_offset_1 = require("./field_offset");
9
9
  class ComponentChainSimpleTranspiler {
10
+ prefix = "";
10
11
  constructor(prefix = "") {
11
- this.prefix = "";
12
12
  this.prefix = prefix;
13
13
  }
14
14
  transpile(node, traversal) {
@@ -4,6 +4,7 @@ exports.ConstantTranspiler = void 0;
4
4
  const core_1 = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class ConstantTranspiler {
7
+ addGet;
7
8
  constructor(addGet = false) {
8
9
  this.addGet = addGet;
9
10
  }
@@ -4,6 +4,7 @@ exports.DatabaseTableTranspiler = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class DatabaseTableTranspiler {
7
+ prefix;
7
8
  constructor(prefix = true) {
8
9
  this.prefix = prefix;
9
10
  }
@@ -9,6 +9,8 @@ const field_symbol_1 = require("./field_symbol");
9
9
  const chunk_1 = require("../chunk");
10
10
  const feature_flags_1 = require("../feature_flags");
11
11
  class FieldChainTranspiler {
12
+ addGet;
13
+ addGetOffset;
12
14
  constructor(addGet = false) {
13
15
  this.addGet = addGet;
14
16
  }
@@ -6,6 +6,7 @@ const core_1 = require("@abaplint/core");
6
6
  const chunk_1 = require("../chunk");
7
7
  const method_call_param_1 = require("./method_call_param");
8
8
  class MethodCallBodyTranspiler {
9
+ m;
9
10
  constructor(m) {
10
11
  this.m = m;
11
12
  }
@@ -4,6 +4,7 @@ exports.MethodCallParamTranspiler = void 0;
4
4
  const core_1 = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class MethodCallParamTranspiler {
7
+ m;
7
8
  constructor(m) {
8
9
  this.m = m;
9
10
  }
@@ -7,6 +7,7 @@ const traversal_1 = require("../traversal");
7
7
  const chunk_1 = require("../chunk");
8
8
  const _1 = require(".");
9
9
  class MethodSourceTranspiler {
10
+ prepend;
10
11
  constructor(prepend) {
11
12
  this.prepend = (prepend || "") + "await ";
12
13
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SimpleSource3Transpiler = void 0;
4
4
  const source_1 = require("./source");
5
5
  class SimpleSource3Transpiler {
6
+ addGet;
6
7
  constructor(addGet = false) {
7
8
  this.addGet = addGet;
8
9
  }
@@ -6,6 +6,7 @@ const _1 = require(".");
6
6
  const constant_1 = require("./constant");
7
7
  const chunk_1 = require("../chunk");
8
8
  class SourceTranspiler {
9
+ addGet;
9
10
  constructor(addGet = false) {
10
11
  this.addGet = addGet;
11
12
  }
@@ -7,6 +7,7 @@ const requires_1 = require("../requires");
7
7
  const rearranger_1 = require("../rearranger");
8
8
  const chunk_1 = require("../chunk");
9
9
  class HandleABAP {
10
+ options;
10
11
  constructor(options) {
11
12
  this.options = options;
12
13
  }
@@ -6,6 +6,7 @@ const traversal_1 = require("../traversal");
6
6
  const rearranger_1 = require("../rearranger");
7
7
  const chunk_1 = require("../chunk");
8
8
  class HandleFUGR {
9
+ options;
9
10
  constructor(options) {
10
11
  this.options = options;
11
12
  }
@@ -22,6 +22,7 @@ const handle_oa2p_1 = require("./handlers/handle_oa2p");
22
22
  const handle_fugr_1 = require("./handlers/handle_fugr");
23
23
  const initialization_1 = require("./initialization");
24
24
  class Transpiler {
25
+ options;
25
26
  constructor(options) {
26
27
  this.options = options;
27
28
  if (this.options === undefined) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Requires = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class Requires {
6
+ reg;
6
7
  constructor(reg) {
7
8
  this.reg = reg;
8
9
  }
@@ -6,6 +6,7 @@ const expressions_1 = require("../expressions");
6
6
  const unique_identifier_1 = require("../unique_identifier");
7
7
  const chunk_1 = require("../chunk");
8
8
  class DoTranspiler {
9
+ syIndexBackup;
9
10
  constructor(syIndexBackup) {
10
11
  this.syIndexBackup = syIndexBackup;
11
12
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EndDoTranspiler = void 0;
4
4
  const chunk_1 = require("../chunk");
5
5
  class EndDoTranspiler {
6
+ syIndexBackup;
6
7
  constructor(syIndexBackup) {
7
8
  this.syIndexBackup = syIndexBackup;
8
9
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EndWhileTranspiler = void 0;
4
4
  const chunk_1 = require("../chunk");
5
5
  class EndWhileTranspiler {
6
+ syIndexBackup;
6
7
  constructor(syIndexBackup) {
7
8
  this.syIndexBackup = syIndexBackup;
8
9
  }
@@ -6,10 +6,10 @@ const unique_identifier_1 = require("../unique_identifier");
6
6
  const expressions_1 = require("../expressions");
7
7
  const chunk_1 = require("../chunk");
8
8
  class LoopTranspiler {
9
+ unique = "";
10
+ injectFrom = undefined;
11
+ skipInto = undefined;
9
12
  constructor(options) {
10
- this.unique = "";
11
- this.injectFrom = undefined;
12
- this.skipInto = undefined;
13
13
  this.injectFrom = options?.injectFrom;
14
14
  this.skipInto = options?.skipInto;
15
15
  }
@@ -1,11 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RaiseEventTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const traversal_1 = require("../traversal");
4
6
  const chunk_1 = require("../chunk");
7
+ const expressions_1 = require("../expressions");
5
8
  class RaiseEventTranspiler {
6
9
  transpile(node, traversal) {
7
- // todo
8
- return new chunk_1.Chunk().append(`abap.statements.raiseEvent();`, node, traversal);
10
+ const eventName = traversal_1.Traversal.escapeNamespace(node.findFirstExpression(abaplint.Expressions.EventName)?.concatTokens())?.toLowerCase().replace("~", "$");
11
+ const parameters = node.findFirstExpression(abaplint.Expressions.ParameterListS);
12
+ let extra = "";
13
+ if (parameters) {
14
+ extra = "," + new expressions_1.ParameterListSTranspiler().transpile(parameters, traversal).getCode();
15
+ }
16
+ return new chunk_1.Chunk().append(`await abap.statements.raiseEvent(this.${eventName}, this.me${extra});`, node, traversal);
9
17
  }
10
18
  }
11
19
  exports.RaiseEventTranspiler = RaiseEventTranspiler;
@@ -4,4 +4,5 @@ import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class SetHandlerTranspiler implements IStatementTranspiler {
6
6
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
+ private findEventClass;
7
8
  }
@@ -7,20 +7,62 @@ const expressions_1 = require("../expressions");
7
7
  class SetHandlerTranspiler {
8
8
  transpile(node, traversal) {
9
9
  const methods = [];
10
+ let className = undefined;
11
+ let eventName = undefined;
10
12
  for (const m of node.findDirectExpressions(abaplint.Expressions.MethodSource)) {
11
- methods.push(new expressions_1.MethodSourceTranspiler().transpile(m, traversal).getCode());
13
+ methods.push(new expressions_1.MethodSourceTranspiler().transpile(m, traversal).getCode().replace("await ", ""));
14
+ if (className === undefined) {
15
+ const nameToken = m.getFirstToken();
16
+ const scope = traversal.findCurrentScopeByToken(nameToken);
17
+ const method = traversal.findMethodReference(nameToken, scope);
18
+ if (method?.def.isEventHandler() !== true) {
19
+ throw new Error(`SetHandlerTranspiler: Method "${nameToken.getStr()}" is not an event handler`);
20
+ }
21
+ const def = traversal.findClassDefinition(method.def.getClassName(), scope);
22
+ if (def === undefined) {
23
+ throw new Error(`SetHandlerTranspiler: Class "${method.def.getClassName()}" not found`);
24
+ }
25
+ eventName = method.def.getEventName();
26
+ className = this.findEventClass(def, eventName, traversal, scope);
27
+ }
12
28
  }
13
29
  let f = undefined;
14
30
  const forExpression = node.findExpressionAfterToken("FOR");
15
- if (forExpression) {
31
+ if (forExpression instanceof abaplint.Expressions.Source) {
16
32
  f = new expressions_1.SourceTranspiler().transpile(forExpression, traversal).getCode();
17
33
  }
18
- let activation = undefined;
34
+ else {
35
+ f = `"ALL"`;
36
+ }
37
+ let activation = "";
19
38
  const activationExpression = node.findExpressionAfterToken("ACTIVATION");
20
39
  if (activationExpression) {
21
- activation = new expressions_1.SourceTranspiler().transpile(activationExpression, traversal).getCode();
40
+ activation = ", " + new expressions_1.SourceTranspiler().transpile(activationExpression, traversal).getCode();
41
+ }
42
+ return new chunk_1.Chunk().append(`abap.statements.setHandler({EVENT_NAME: "${eventName}", EVENT_CLASS: "${className}"}, [${methods.join(",")}], ${f}${activation});`, node, traversal);
43
+ }
44
+ findEventClass(def, eventName, traversal, scope) {
45
+ let current = def;
46
+ while (current !== undefined) {
47
+ for (const event of current.getEvents()) {
48
+ if (event.getName().toUpperCase() === eventName?.toUpperCase()) {
49
+ return traversal.buildInternalName(current.getName(), current);
50
+ }
51
+ }
52
+ for (const implementing of current.getImplementing()) {
53
+ const idef = traversal.findInterfaceDefinition(implementing.name, scope);
54
+ if (idef === undefined) {
55
+ continue;
56
+ }
57
+ for (const event of idef.getEvents()) {
58
+ if (event.getName().toUpperCase() === eventName?.toUpperCase()) {
59
+ return traversal.buildInternalName(idef.getName(), idef);
60
+ }
61
+ }
62
+ }
63
+ current = traversal.findClassDefinition(current.getSuperClass(), scope);
22
64
  }
23
- return new chunk_1.Chunk().append(`abap.statements.setHandler([${methods.join(",")}], ${f}, ${activation});`, node, traversal);
65
+ throw new Error(`Transpiler: Event "${eventName}" not found in class "${def.getName()}"`);
24
66
  }
25
67
  }
26
68
  exports.SetHandlerTranspiler = SetHandlerTranspiler;
@@ -5,6 +5,7 @@ const abaplint = require("@abaplint/core");
5
5
  const expressions_1 = require("../expressions");
6
6
  const chunk_1 = require("../chunk");
7
7
  class WhenTranspiler {
8
+ u;
8
9
  constructor(u) {
9
10
  this.u = u;
10
11
  }
@@ -6,6 +6,7 @@ const expressions_1 = require("../expressions");
6
6
  const chunk_1 = require("../chunk");
7
7
  const unique_identifier_1 = require("../unique_identifier");
8
8
  class WhileTranspiler {
9
+ syIndexBackup;
9
10
  constructor(syIndexBackup) {
10
11
  this.syIndexBackup = syIndexBackup;
11
12
  }
@@ -42,6 +42,7 @@ export declare class Traversal {
42
42
  private buildThisAttributes;
43
43
  private buildFriendsAccess;
44
44
  buildConstructorContents(scope: abaplint.ISpaghettiScopeNode | undefined, def: abaplint.IClassDefinition): string;
45
+ private eventsFromInterfaces;
45
46
  findInterfaceDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IInterfaceDefinition | undefined;
46
47
  findTable(name: string): abaplint.Objects.Table | undefined;
47
48
  findClassDefinition(name: string | undefined, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IClassDefinition | undefined;
@@ -11,8 +11,12 @@ const expressions_1 = require("./expressions");
11
11
  const keywords_1 = require("./keywords");
12
12
  const feature_flags_1 = require("./feature_flags");
13
13
  class Traversal {
14
+ spaghetti;
15
+ file;
16
+ obj;
17
+ reg;
18
+ options;
14
19
  constructor(spaghetti, file, obj, reg, options) {
15
- this.scopeCache = undefined;
16
20
  this.spaghetti = spaghetti;
17
21
  this.file = file;
18
22
  this.obj = obj;
@@ -68,6 +72,7 @@ class Traversal {
68
72
  }
69
73
  return undefined;
70
74
  }
75
+ scopeCache = undefined;
71
76
  findCurrentScopeByToken(token) {
72
77
  const filename = this.file.getFilename();
73
78
  if (this.scopeCache
@@ -472,6 +477,7 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
472
477
  for (const i of def.getImplementing()) {
473
478
  ret += this.dataFromInterfaces(i.name, scope, cName);
474
479
  ret += this.aliasesFromInterfaces(i.name, scope, cName);
480
+ ret += this.eventsFromInterfaces(i.name, scope);
475
481
  }
476
482
  // handle aliases after initialization of carrier variables
477
483
  for (const a of def.getAliases() || []) {
@@ -481,6 +487,27 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
481
487
  for (const c of def.getAttributes()?.getConstants() || []) {
482
488
  ret += "this." + Traversal.escapeNamespace(c.getName().toLowerCase()) + " = " + cName + "." + Traversal.escapeNamespace(c.getName().toLowerCase()) + ";\n";
483
489
  }
490
+ for (const e of def.getEvents() || []) {
491
+ const name = this.buildInternalName(def.getName(), def);
492
+ ret += "this." + Traversal.escapeNamespace(e.getName().toLowerCase()) + " = {\"EVENT_NAME\": \"" + e.getName().toUpperCase() + "\", \"EVENT_CLASS\": \"" + name + "\"};\n";
493
+ }
494
+ return ret;
495
+ }
496
+ eventsFromInterfaces(name, scope) {
497
+ let ret = "";
498
+ const intf = this.findInterfaceDefinition(name, scope);
499
+ if (intf === undefined) {
500
+ return ret;
501
+ }
502
+ for (const e of intf.getEvents() || []) {
503
+ const fname = Traversal.escapeNamespace(e.getName().toLowerCase());
504
+ const iname = Traversal.escapeNamespace(intf?.getName().toLowerCase());
505
+ const name = this.buildInternalName(intf.getName(), intf);
506
+ ret += "this." + iname + "$" + fname + " = {\"EVENT_NAME\": \"" + e.getName().toUpperCase() + "\", \"EVENT_CLASS\": \"" + name + "\"};\n";
507
+ }
508
+ for (const i of intf.getImplementing() || []) {
509
+ ret += this.eventsFromInterfaces(i.name, scope);
510
+ }
484
511
  return ret;
485
512
  }
486
513
  findInterfaceDefinition(name, scope) {
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UniqueIdentifier = void 0;
4
4
  class UniqueIdentifier {
5
+ static counter = 0;
6
+ static indexBackup = 0;
5
7
  static reset() {
6
8
  this.counter = 0;
7
9
  }
@@ -23,6 +25,4 @@ class UniqueIdentifier {
23
25
  }
24
26
  }
25
27
  exports.UniqueIdentifier = UniqueIdentifier;
26
- UniqueIdentifier.counter = 0;
27
- UniqueIdentifier.indexBackup = 0;
28
28
  //# sourceMappingURL=unique_identifier.js.map
@@ -105,6 +105,7 @@ exports.config = {
105
105
  // todo, make sure nothing is overloaded, eg "lines()", there is a rule for this in abaplint now
106
106
  // hmm this ^ is okay? since lines will be prefixed with "abap.builtin"?
107
107
  class Validation {
108
+ options;
108
109
  constructor(options) {
109
110
  this.options = options;
110
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.10.83",
3
+ "version": "2.11.1",
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.150",
32
+ "@abaplint/core": "^2.113.151",
33
33
  "source-map": "^0.7.6"
34
34
  },
35
35
  "devDependencies": {