@abaplint/transpiler 2.3.126 → 2.4.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.
@@ -0,0 +1,5 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IOutputFile } from "../types";
3
+ export declare class HandleTypePool {
4
+ runObject(obj: abaplint.ABAPObject, reg: abaplint.IRegistry): IOutputFile[];
5
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandleTypePool = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const chunk_1 = require("../chunk");
6
+ const transpile_types_1 = require("../transpile_types");
7
+ const traversal_1 = require("../traversal");
8
+ class HandleTypePool {
9
+ runObject(obj, reg) {
10
+ var _a;
11
+ const spaghetti = (_a = new abaplint.SyntaxLogic(reg, obj).run().spaghetti.getFirstChild()) === null || _a === void 0 ? void 0 : _a.getFirstChild();
12
+ const chunk = new chunk_1.Chunk();
13
+ chunk.appendString(`const pool = {};\n`);
14
+ for (const v in spaghetti === null || spaghetti === void 0 ? void 0 : spaghetti.getData().vars) {
15
+ const abs = spaghetti.getData().vars[v];
16
+ const name = `pool['${v.toLowerCase()}']`;
17
+ chunk.appendString(`${name} = ${new transpile_types_1.TranspileTypes().toType(abs.getType())};\n`);
18
+ chunk.appendString(traversal_1.Traversal.setValues(abs, name));
19
+ }
20
+ for (const t in spaghetti === null || spaghetti === void 0 ? void 0 : spaghetti.getData().types) {
21
+ const abs = spaghetti.getData().types[t];
22
+ chunk.appendString(`pool['${t.toLowerCase()}'] = ${new transpile_types_1.TranspileTypes().toType(abs.getType())};\n`);
23
+ }
24
+ chunk.appendString(`abap.TypePools['${obj.getName()}'] = pool;`);
25
+ const output = {
26
+ object: {
27
+ name: obj.getName(),
28
+ type: obj.getType(),
29
+ },
30
+ filename: obj.getName().toLowerCase() + "." + obj.getType().toLowerCase() + ".mjs",
31
+ chunk: chunk,
32
+ requires: [],
33
+ exports: [],
34
+ };
35
+ return [output];
36
+ }
37
+ }
38
+ exports.HandleTypePool = HandleTypePool;
39
+ //# sourceMappingURL=handle_type_pool.js.map
@@ -13,6 +13,7 @@ const handle_data_element_1 = require("./handlers/handle_data_element");
13
13
  const handle_table_type_1 = require("./handlers/handle_table_type");
14
14
  const handle_view_1 = require("./handlers/handle_view");
15
15
  const handle_enqu_1 = require("./handlers/handle_enqu");
16
+ const handle_type_pool_1 = require("./handlers/handle_type_pool");
16
17
  class Transpiler {
17
18
  constructor(options) {
18
19
  this.options = options;
@@ -58,6 +59,9 @@ class Transpiler {
58
59
  if (obj instanceof abaplint.ABAPObject && !(obj instanceof abaplint.Objects.TypePool)) {
59
60
  output.objects.push(...new handle_abap_1.HandleABAP(this.options).runObject(obj, reg));
60
61
  }
62
+ else if (obj instanceof abaplint.Objects.TypePool) {
63
+ output.objects.push(...new handle_type_pool_1.HandleTypePool().runObject(obj, reg));
64
+ }
61
65
  else if (obj instanceof abaplint.Objects.Table) {
62
66
  output.objects.push(...new handle_table_1.HandleTable().runObject(obj, reg));
63
67
  }
@@ -29,6 +29,7 @@ export declare class Traversal {
29
29
  name: string;
30
30
  };
31
31
  private isBuiltinVariable;
32
+ isTypePool(token: abaplint.Token): string | undefined;
32
33
  isInterfaceAttribute(token: abaplint.Token): string | undefined;
33
34
  private findReadOrWriteReference;
34
35
  buildConstructorContents(scope: abaplint.ISpaghettiScopeNode | undefined, def: abaplint.IClassDefinition): string;
@@ -41,6 +42,7 @@ export declare class Traversal {
41
42
  isInsideDoOrWhile(node: abaplint.Nodes.StatementNode): boolean;
42
43
  registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
43
44
  setValues(identifier: abaplint.TypedIdentifier, name: string): string;
45
+ static setValues(identifier: abaplint.TypedIdentifier, name: string): string;
44
46
  lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
45
47
  private buildPrefix;
46
48
  protected traverseStructure(node: abaplint.Nodes.StructureNode): Chunk;
@@ -146,6 +146,10 @@ class Traversal {
146
146
  else if (this.isBuiltinVariable(t)) {
147
147
  name = "abap.builtin." + name;
148
148
  }
149
+ else if (this.isTypePool(t)) {
150
+ const tp = this.isTypePool(t);
151
+ name = `abap.TypePools["${tp}"].` + name.toLowerCase();
152
+ }
149
153
  return name;
150
154
  }
151
155
  isStaticClassAttribute(token) {
@@ -221,6 +225,18 @@ class Traversal {
221
225
  }
222
226
  return false;
223
227
  }
228
+ isTypePool(token) {
229
+ const ref = this.findReadOrWriteReference(token);
230
+ if (ref === null || ref === void 0 ? void 0 : ref.getFilename().endsWith(".type.abap")) {
231
+ const file = this.reg.getFileByName(ref.getFilename());
232
+ if (file === undefined) {
233
+ return undefined;
234
+ }
235
+ const obj = this.reg.findObjectForFile(file);
236
+ return obj === null || obj === void 0 ? void 0 : obj.getName();
237
+ }
238
+ return undefined;
239
+ }
224
240
  // returns the interface name if interfaced
225
241
  isInterfaceAttribute(token) {
226
242
  const ref = this.findReadOrWriteReference(token);
@@ -417,6 +433,9 @@ class Traversal {
417
433
  }
418
434
  }
419
435
  setValues(identifier, name) {
436
+ return Traversal.setValues(identifier, name);
437
+ }
438
+ static setValues(identifier, name) {
420
439
  const val = identifier.getValue();
421
440
  let ret = "";
422
441
  if (typeof val === "string") {
@@ -199,6 +199,7 @@ run().then(() => {
199
199
  if (obj instanceof abaplint.Objects.Table
200
200
  || obj instanceof abaplint.Objects.DataElement
201
201
  || obj instanceof abaplint.Objects.LockObject
202
+ || obj instanceof abaplint.Objects.TypePool
202
203
  || obj instanceof abaplint.Objects.TableType) {
203
204
  list.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
204
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.3.126",
3
+ "version": "2.4.0",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",