@abaplint/transpiler 2.12.35 → 2.13.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.
@@ -19,7 +19,7 @@ class HandleDataElement {
19
19
  }
20
20
  const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
21
21
  "objectType": "DTEL",
22
- "type": ${transpile_types_1.TranspileTypes.toType(type)},
22
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type)},
23
23
  "domain": ${JSON.stringify(obj.getDomainName())},
24
24
  "fixedValues": ${JSON.stringify(fixedValues)},
25
25
  "description": ${JSON.stringify(obj.getDescription())},
@@ -13,7 +13,7 @@ class HandleTable {
13
13
  const type = obj.parseType(reg);
14
14
  const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
15
  "objectType": "TABL",
16
- "type": ${transpile_types_1.TranspileTypes.toType(type)},
16
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type)},
17
17
  "keyFields": ${JSON.stringify(obj.listKeys(reg))},
18
18
  "description": ${JSON.stringify(obj.getDescription())},
19
19
  };`);
@@ -12,7 +12,7 @@ class HandleTableType {
12
12
  const type = obj.parseType(reg);
13
13
  const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
14
14
  "objectType": "TTYP",
15
- "type": ${transpile_types_1.TranspileTypes.toType(type)},
15
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type)},
16
16
  "description": ${JSON.stringify(obj.getDescription())},
17
17
  };`);
18
18
  const output = {
@@ -13,7 +13,7 @@ class HandleView {
13
13
  const type = obj.parseType(reg);
14
14
  const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
15
  "objectType": "VIEW",
16
- "type": ${transpile_types_1.TranspileTypes.toType(type)},
16
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type)},
17
17
  };`);
18
18
  // todo, "keyFields": ${JSON.stringify(obj.listKeys())},
19
19
  const output = {
@@ -26,7 +26,7 @@ class SelectTranspiler {
26
26
  // note: this implementation SELECTs everything into memory, which might be bad, and sometimes not correct
27
27
  const targetName = unique_identifier_1.UniqueIdentifier.get();
28
28
  const loopName = unique_identifier_1.UniqueIdentifier.get();
29
- ret.appendString(`let ${targetName} = new abap.types.Table(abap.DDIC["${from}"].type);\n`);
29
+ ret.appendString(`let ${targetName} = new abap.types.Table(abap.DDIC["${from}"].type());\n`);
30
30
  ret.appendChunk(new select_1.SelectTranspiler().transpile(selectStatement, traversal, targetName));
31
31
  // todo: optimize, it should do real streaming?
32
32
  const packageSize = node.findFirstExpression(abaplint.Expressions.SelectLoop)?.findExpressionAfterToken("SIZE");
@@ -2,5 +2,7 @@ import * as abaplint from "@abaplint/core";
2
2
  export declare class TranspileTypes {
3
3
  static declare(t: abaplint.TypedIdentifier): string;
4
4
  static declareStaticSkipVoid(pre: string, t: abaplint.TypedIdentifier): string;
5
+ /** this returns a function, so it doesnt throw when loading the code, only when running */
6
+ static toTypeFunction(type: abaplint.AbstractType): string;
5
7
  static toType(type: abaplint.AbstractType): string;
6
8
  }
@@ -18,6 +18,17 @@ class TranspileTypes {
18
18
  }
19
19
  return pre + t.getName().toLowerCase() + " = " + code + ";\n";
20
20
  }
21
+ /** this returns a function, so it doesnt throw when loading the code, only when running */
22
+ static toTypeFunction(type) {
23
+ if (type instanceof abaplint.BasicTypes.UnknownType) {
24
+ return `() => { throw new Error("Unknown type: ${type.getError()}") }`;
25
+ }
26
+ else if (type instanceof abaplint.BasicTypes.VoidType) {
27
+ return `() => { throw new Error("Void type: ${type.getVoided()}") }`;
28
+ }
29
+ // return singleton,
30
+ return "(() => { let _t; return () => (_t ??= " + this.toType(type) + "); })()";
31
+ }
21
32
  static toType(type) {
22
33
  let resolved = "";
23
34
  let extra = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.12.35",
3
+ "version": "2.13.0",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",