@abaplint/transpiler 2.11.11 → 2.11.13

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 (34) hide show
  1. package/build/src/expressions/index.d.ts +4 -3
  2. package/build/src/expressions/index.js +4 -3
  3. package/build/src/expressions/source.js +2 -2
  4. package/build/src/expressions/sql_cond.js +1 -1
  5. package/build/src/expressions/target_field.d.ts +7 -0
  6. package/build/src/expressions/target_field.js +11 -0
  7. package/build/src/expressions/type_name_or_infer.js +1 -1
  8. package/build/src/handlers/handle_data_element.js +1 -1
  9. package/build/src/handlers/handle_table.js +1 -1
  10. package/build/src/handlers/handle_table_type.js +1 -1
  11. package/build/src/handlers/handle_type_pool.js +2 -2
  12. package/build/src/handlers/handle_view.js +1 -1
  13. package/build/src/inline.d.ts +5 -0
  14. package/build/src/inline.js +26 -0
  15. package/build/src/statements/create_data.js +1 -1
  16. package/build/src/statements/data.js +1 -1
  17. package/build/src/statements/field_symbol.js +1 -1
  18. package/build/src/statements/loop.d.ts +1 -0
  19. package/build/src/statements/loop.js +9 -1
  20. package/build/src/statements/method_implementation.js +7 -7
  21. package/build/src/statements/ranges.js +1 -1
  22. package/build/src/statements/tables.js +1 -1
  23. package/build/src/structures/class_implementation.js +2 -2
  24. package/build/src/structures/form.js +5 -0
  25. package/build/src/structures/function_module.js +1 -1
  26. package/build/src/structures/index.d.ts +1 -0
  27. package/build/src/structures/index.js +1 -0
  28. package/build/src/structures/interface.js +2 -2
  29. package/build/src/structures/method.d.ts +7 -0
  30. package/build/src/structures/method.js +21 -0
  31. package/build/src/transpile_types.d.ts +3 -3
  32. package/build/src/transpile_types.js +3 -4
  33. package/build/src/traversal.js +5 -5
  34. package/package.json +2 -2
@@ -19,8 +19,6 @@ export * from "./field_length";
19
19
  export * from "./field_offset";
20
20
  export * from "./field_symbol";
21
21
  export * from "./function_exporting";
22
- export * from "./source_field_symbol_chain";
23
- export * from "./type_name_or_infer";
24
22
  export * from "./function_parameters";
25
23
  export * from "./message_number";
26
24
  export * from "./method_call_body";
@@ -39,6 +37,7 @@ export * from "./simple_source1";
39
37
  export * from "./simple_source2";
40
38
  export * from "./simple_source3";
41
39
  export * from "./simple_source4";
40
+ export * from "./source_field_symbol_chain";
42
41
  export * from "./source_field_symbol";
43
42
  export * from "./source_field";
44
43
  export * from "./source";
@@ -50,8 +49,8 @@ export * from "./sql_field_name";
50
49
  export * from "./sql_field";
51
50
  export * from "./sql_from_source";
52
51
  export * from "./sql_from";
53
- export * from "./sql_into_structure";
54
52
  export * from "./sql_into_list";
53
+ export * from "./sql_into_structure";
55
54
  export * from "./sql_join";
56
55
  export * from "./sql_order_by";
57
56
  export * from "./sql_source_simple";
@@ -59,4 +58,6 @@ export * from "./sql_source";
59
58
  export * from "./sql_target";
60
59
  export * from "./string_template_source";
61
60
  export * from "./string_template";
61
+ export * from "./target_field";
62
62
  export * from "./target";
63
+ export * from "./type_name_or_infer";
@@ -35,8 +35,6 @@ __exportStar(require("./field_length"), exports);
35
35
  __exportStar(require("./field_offset"), exports);
36
36
  __exportStar(require("./field_symbol"), exports);
37
37
  __exportStar(require("./function_exporting"), exports);
38
- __exportStar(require("./source_field_symbol_chain"), exports);
39
- __exportStar(require("./type_name_or_infer"), exports);
40
38
  __exportStar(require("./function_parameters"), exports);
41
39
  __exportStar(require("./message_number"), exports);
42
40
  __exportStar(require("./method_call_body"), exports);
@@ -55,6 +53,7 @@ __exportStar(require("./simple_source1"), exports);
55
53
  __exportStar(require("./simple_source2"), exports);
56
54
  __exportStar(require("./simple_source3"), exports);
57
55
  __exportStar(require("./simple_source4"), exports);
56
+ __exportStar(require("./source_field_symbol_chain"), exports);
58
57
  __exportStar(require("./source_field_symbol"), exports);
59
58
  __exportStar(require("./source_field"), exports);
60
59
  __exportStar(require("./source"), exports);
@@ -66,8 +65,8 @@ __exportStar(require("./sql_field_name"), exports);
66
65
  __exportStar(require("./sql_field"), exports);
67
66
  __exportStar(require("./sql_from_source"), exports);
68
67
  __exportStar(require("./sql_from"), exports);
69
- __exportStar(require("./sql_into_structure"), exports);
70
68
  __exportStar(require("./sql_into_list"), exports);
69
+ __exportStar(require("./sql_into_structure"), exports);
71
70
  __exportStar(require("./sql_join"), exports);
72
71
  __exportStar(require("./sql_order_by"), exports);
73
72
  __exportStar(require("./sql_source_simple"), exports);
@@ -75,5 +74,7 @@ __exportStar(require("./sql_source"), exports);
75
74
  __exportStar(require("./sql_target"), exports);
76
75
  __exportStar(require("./string_template_source"), exports);
77
76
  __exportStar(require("./string_template"), exports);
77
+ __exportStar(require("./target_field"), exports);
78
78
  __exportStar(require("./target"), exports);
79
+ __exportStar(require("./type_name_or_infer"), exports);
79
80
  //# sourceMappingURL=index.js.map
@@ -107,9 +107,9 @@ class SourceTranspiler {
107
107
  const scope = traversal.findCurrentScopeByToken(infer.getFirstToken());
108
108
  const inferType = traversal.lookupInferred(infer, scope);
109
109
  if (inferType === undefined) {
110
- throw new Error("transpiler: REF # todo, lookupInferred");
110
+ throw new Error("transpiler: REF # todo, lookupInferred, " + node.concatTokens());
111
111
  }
112
- const typ = new transpile_types_1.TranspileTypes().toType(inferType);
112
+ const typ = transpile_types_1.TranspileTypes.toType(inferType);
113
113
  if (typ.startsWith("new abap.types.DataReference(") === false) {
114
114
  throw new Error("transpiler: REF # unexpected type");
115
115
  }
@@ -138,7 +138,7 @@ class SQLCondTranspiler {
138
138
  const conversionField = traversal.isSQLConversion(source.getFirstToken());
139
139
  if (conversionField) {
140
140
  const field = (table?.parseType(traversal.reg)).getComponentByName(conversionField);
141
- ret += "'\" + " + new transpile_types_1.TranspileTypes().toType(field) + ".set(" + concat + ").get() + \"'";
141
+ ret += "'\" + " + transpile_types_1.TranspileTypes.toType(field) + ".set(" + concat + ").get() + \"'";
142
142
  }
143
143
  else if (concat.startsWith("`")) {
144
144
  ret += "'" + concat.substring(1, concat.length - 1) + "'";
@@ -0,0 +1,7 @@
1
+ import { Nodes } from "@abaplint/core";
2
+ import { Chunk } from "../chunk";
3
+ import { Traversal } from "../traversal";
4
+ import { IExpressionTranspiler } from "./_expression_transpiler";
5
+ export declare class TargetFieldTranspiler implements IExpressionTranspiler {
6
+ transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TargetFieldTranspiler = void 0;
4
+ const field_chain_1 = require("./field_chain");
5
+ class TargetFieldTranspiler {
6
+ transpile(node, traversal) {
7
+ return new field_chain_1.FieldChainTranspiler().transpile(node, traversal);
8
+ }
9
+ }
10
+ exports.TargetFieldTranspiler = TargetFieldTranspiler;
11
+ //# sourceMappingURL=target_field.js.map
@@ -17,7 +17,7 @@ class TypeNameOrInfer {
17
17
  throw new Error("TypeNameOrInfer, type not found: " + node.concatTokens());
18
18
  }
19
19
  const ret = new chunk_1.Chunk();
20
- ret.appendString(new transpile_types_1.TranspileTypes().toType(type));
20
+ ret.appendString(transpile_types_1.TranspileTypes.toType(type));
21
21
  return ret;
22
22
  }
23
23
  }
@@ -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": ${new transpile_types_1.TranspileTypes().toType(type)},
22
+ "type": ${transpile_types_1.TranspileTypes.toType(type)},
23
23
  "domain": ${JSON.stringify(obj.getDomainName())},
24
24
  "fixedValues": ${JSON.stringify(fixedValues)},
25
25
  };`);
@@ -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": ${new transpile_types_1.TranspileTypes().toType(type)},
16
+ "type": ${transpile_types_1.TranspileTypes.toType(type)},
17
17
  "keyFields": ${JSON.stringify(obj.listKeys(reg))},
18
18
  };`);
19
19
  const output = {
@@ -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": ${new transpile_types_1.TranspileTypes().toType(type)},
15
+ "type": ${transpile_types_1.TranspileTypes.toType(type)},
16
16
  };`);
17
17
  const output = {
18
18
  object: {
@@ -22,7 +22,7 @@ class HandleTypePool {
22
22
  for (const v in spaghettiNode?.getData().vars) {
23
23
  const abs = spaghettiNode.getData().vars[v];
24
24
  const name = `pool['${v.toLowerCase()}']`;
25
- chunk.appendString(`${name} = ${new transpile_types_1.TranspileTypes().toType(abs.getType())};\n`);
25
+ chunk.appendString(`${name} = ${transpile_types_1.TranspileTypes.toType(abs.getType())};\n`);
26
26
  chunk.appendString(traversal_1.Traversal.setValues(abs, name));
27
27
  // yea, this is a mess
28
28
  for (const cons of abapFile.getStructure()?.findAllStructures(abaplint.Structures.Constants) || []) {
@@ -34,7 +34,7 @@ class HandleTypePool {
34
34
  }
35
35
  for (const t in spaghettiNode?.getData().types) {
36
36
  const abs = spaghettiNode.getData().types[t];
37
- chunk.appendString(`pool['${t.toLowerCase()}'] = ${new transpile_types_1.TranspileTypes().toType(abs.getType())};\n`);
37
+ chunk.appendString(`pool['${t.toLowerCase()}'] = ${transpile_types_1.TranspileTypes.toType(abs.getType())};\n`);
38
38
  }
39
39
  chunk.appendString(`abap.TypePools['${obj.getName()}'] = pool;`);
40
40
  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": ${new transpile_types_1.TranspileTypes().toType(type)},
16
+ "type": ${transpile_types_1.TranspileTypes.toType(type)},
17
17
  };`);
18
18
  // todo, "keyFields": ${JSON.stringify(obj.listKeys())},
19
19
  const output = {
@@ -0,0 +1,5 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { Traversal } from "./traversal";
3
+ export declare class InlineDeclarations {
4
+ static buildDeclarations(node: abaplint.Nodes.StructureNode, traversal: Traversal): string;
5
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InlineDeclarations = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const transpile_types_1 = require("./transpile_types");
6
+ class InlineDeclarations {
7
+ static buildDeclarations(node, traversal) {
8
+ const expressions = node.findAllExpressionsRecursive(abaplint.Expressions.InlineData);
9
+ let result = "";
10
+ for (const expression of expressions) {
11
+ const name = expression.findFirstExpression(abaplint.Expressions.TargetField)?.concatTokens();
12
+ if (name === undefined) {
13
+ throw new Error("InlineDeclarations: no target field found");
14
+ }
15
+ const scope = traversal.findCurrentScopeByToken(expression.getFirstToken());
16
+ const variable = scope?.findVariable(name);
17
+ if (variable === undefined) {
18
+ throw new Error("InlineDeclarations: no variable found");
19
+ }
20
+ result += transpile_types_1.TranspileTypes.declare(variable) + "\n";
21
+ }
22
+ return result;
23
+ }
24
+ }
25
+ exports.InlineDeclarations = InlineDeclarations;
26
+ //# sourceMappingURL=inline.js.map
@@ -25,7 +25,7 @@ class CreateDataTranspiler {
25
25
  if (typeNameNode) {
26
26
  const id = traversal.findCurrentScopeByToken(typeNameNode.getFirstToken())?.findType(typeNameNode.concatTokens());
27
27
  if (id) {
28
- options.push(`"type": ` + new transpile_types_1.TranspileTypes().toType(id.getType()));
28
+ options.push(`"type": ` + transpile_types_1.TranspileTypes.toType(id.getType()));
29
29
  }
30
30
  else {
31
31
  options.push(`"typeName": "${typeNameNode.concatTokens().toUpperCase()}"`);
@@ -31,7 +31,7 @@ class DataTranspiler {
31
31
  const ret = new chunk_1.Chunk()
32
32
  .appendString("let ")
33
33
  .appendString(traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(found.getName().toLowerCase())))
34
- .appendString(" = " + new transpile_types_1.TranspileTypes().toType(found.getType()))
34
+ .appendString(" = " + transpile_types_1.TranspileTypes.toType(found.getType()))
35
35
  .appendString(";")
36
36
  .appendString(value);
37
37
  return ret;
@@ -24,7 +24,7 @@ class FieldSymbolTranspiler {
24
24
  return new chunk_1.Chunk()
25
25
  .appendString("let ")
26
26
  .appendString(new field_symbol_1.FieldSymbolTranspiler().transpile(name, traversal).getCode())
27
- .appendString(" = new abap.types.FieldSymbol(" + new transpile_types_1.TranspileTypes().toType(found.getType()) + ");");
27
+ .appendString(" = new abap.types.FieldSymbol(" + transpile_types_1.TranspileTypes.toType(found.getType()) + ");");
28
28
  }
29
29
  throw new Error("FieldSymbolTranspiler, name not found");
30
30
  }
@@ -11,5 +11,6 @@ export declare class LoopTranspiler implements IStatementTranspiler {
11
11
  skipInto?: boolean;
12
12
  });
13
13
  getTarget(): string;
14
+ private determineInto;
14
15
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
15
16
  }
@@ -16,6 +16,14 @@ class LoopTranspiler {
16
16
  getTarget() {
17
17
  return this.unique;
18
18
  }
19
+ determineInto(node) {
20
+ const loopTarget = node.findDirectExpression(abaplint.Expressions.LoopTarget);
21
+ let into = loopTarget?.findDirectExpression(abaplint.Expressions.Target);
22
+ if (into?.getFirstChild()?.get() instanceof abaplint.Expressions.InlineData) {
23
+ into = into.findFirstExpression(abaplint.Expressions.TargetField);
24
+ }
25
+ return into;
26
+ }
19
27
  transpile(node, traversal) {
20
28
  if (!(node.get() instanceof abaplint.Statements.Loop)) {
21
29
  throw new Error("LoopTranspiler, unexpected node");
@@ -24,7 +32,7 @@ class LoopTranspiler {
24
32
  const source = traversal.traverse(loopSource).getCode();
25
33
  this.unique = unique_identifier_1.UniqueIdentifier.get();
26
34
  let target = "";
27
- const into = node.findDirectExpression(abaplint.Expressions.LoopTarget)?.findDirectExpression(abaplint.Expressions.Target);
35
+ const into = this.determineInto(node);
28
36
  if (into && this.skipInto !== true) {
29
37
  const concat = node.concatTokens().toUpperCase();
30
38
  const t = traversal.traverse(into).getCode();
@@ -46,7 +46,7 @@ class MethodImplementationTranspiler {
46
46
  const passByValue = identifier.getMeta().includes("pass_by_value" /* abaplint.IdentifierMeta.PassByValue */);
47
47
  const type = identifier.getType();
48
48
  if (identifier.getMeta().includes("exporting" /* abaplint.IdentifierMeta.MethodExporting */)) {
49
- after += `let ${varPrefixed} = ${unique}?.${varName} || ${new transpile_types_1.TranspileTypes().toType(identifier.getType())};\n`;
49
+ after += `let ${varPrefixed} = ${unique}?.${varName} || ${transpile_types_1.TranspileTypes.toType(identifier.getType())};\n`;
50
50
  }
51
51
  else if (identifier.getMeta().includes("importing" /* abaplint.IdentifierMeta.MethodImporting */)
52
52
  && parameterDefault === undefined
@@ -57,31 +57,31 @@ class MethodImplementationTranspiler {
57
57
  if (identifier.getType().getQualifiedName() !== undefined && identifier.getType().getQualifiedName() !== "") {
58
58
  after += `if (${varPrefixed}?.getQualifiedName === undefined || ${varPrefixed}.getQualifiedName() !== "${identifier.getType().getQualifiedName()?.toUpperCase()}") { ${varPrefixed} = undefined; }\n`;
59
59
  }
60
- after += `if (${varPrefixed} === undefined) { ${varPrefixed} = ${new transpile_types_1.TranspileTypes().toType(identifier.getType())}.set(${unique}.${varName}); }\n`;
60
+ after += `if (${varPrefixed} === undefined) { ${varPrefixed} = ${transpile_types_1.TranspileTypes.toType(identifier.getType())}.set(${unique}.${varName}); }\n`;
61
61
  }
62
62
  else if (identifier.getMeta().includes("importing" /* abaplint.IdentifierMeta.MethodImporting */)
63
63
  && type.isGeneric() === true) {
64
64
  if (isOptional === true) {
65
- after += `let ${varPrefixed} = ${unique}?.${varName} || ${new transpile_types_1.TranspileTypes().toType(identifier.getType())};\n`;
65
+ after += `let ${varPrefixed} = ${unique}?.${varName} || ${transpile_types_1.TranspileTypes.toType(identifier.getType())};\n`;
66
66
  }
67
67
  else {
68
68
  after += `let ${varPrefixed} = ${unique}?.${varName};\n`;
69
69
  }
70
70
  if (type instanceof abaplint.BasicTypes.NumericGenericType) {
71
71
  after += `if (${varPrefixed}.constructor.name === "Character") {
72
- ${varPrefixed} = ${new transpile_types_1.TranspileTypes().toType(identifier.getType())};
72
+ ${varPrefixed} = ${transpile_types_1.TranspileTypes.toType(identifier.getType())};
73
73
  ${varPrefixed}.set(${unique}?.${varName});
74
74
  }\n`;
75
75
  }
76
76
  }
77
77
  else if (identifier.getMeta().includes("importing" /* abaplint.IdentifierMeta.MethodImporting */)
78
78
  && type.isGeneric() === false) {
79
- after += new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
79
+ after += transpile_types_1.TranspileTypes.declare(identifier) + "\n";
80
80
  // note: it might be nessesary to do a type conversion, eg char is passed to xstring parameter
81
81
  after += "if (" + unique + " && " + unique + "." + varName + ") {" + varPrefixed + ".set(" + unique + "." + varName + ");}\n";
82
82
  }
83
83
  else {
84
- after += new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
84
+ after += transpile_types_1.TranspileTypes.declare(identifier) + "\n";
85
85
  after += "if (" + unique + " && " + unique + "." + varName + ") {" + varPrefixed + " = " + unique + "." + varName + ";}\n";
86
86
  }
87
87
  if (parameterDefault) {
@@ -95,7 +95,7 @@ class MethodImplementationTranspiler {
95
95
  }
96
96
  }
97
97
  else if (identifier.getMeta().includes("returning" /* abaplint.IdentifierMeta.MethodReturning */)) {
98
- after = after + new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
98
+ after = after + transpile_types_1.TranspileTypes.declare(identifier) + "\n";
99
99
  }
100
100
  }
101
101
  if (after.length > 0) { // argh
@@ -22,7 +22,7 @@ class RangesTranspiler {
22
22
  const ret = new chunk_1.Chunk()
23
23
  .appendString("let ")
24
24
  .appendString(traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(found.getName().toLowerCase())))
25
- .appendString(" = " + new transpile_types_1.TranspileTypes().toType(found.getType()))
25
+ .appendString(" = " + transpile_types_1.TranspileTypes.toType(found.getType()))
26
26
  .appendString(";");
27
27
  return ret;
28
28
  }
@@ -21,7 +21,7 @@ class TablesTranspiler {
21
21
  const ret = new chunk_1.Chunk()
22
22
  .appendString("let ")
23
23
  .append(found.getName().toLowerCase(), token, traversal)
24
- .appendString(" = " + new transpile_types_1.TranspileTypes().toType(found.getType()))
24
+ .appendString(" = " + transpile_types_1.TranspileTypes.toType(found.getType()))
25
25
  .append(";", node.getLastToken(), traversal);
26
26
  return ret;
27
27
  }
@@ -70,7 +70,7 @@ class ClassImplementationTranspiler {
70
70
  const prefix = traversal_1.Traversal.escapeNamespace(cdef.getName().toLowerCase()) + ".";
71
71
  let ret = "";
72
72
  for (const ty of cdef.getTypeDefinitions().getAll()) {
73
- ret += new transpile_types_1.TranspileTypes().declareStaticSkipVoid(prefix, ty.type);
73
+ ret += transpile_types_1.TranspileTypes.declareStaticSkipVoid(prefix, ty.type);
74
74
  }
75
75
  return ret;
76
76
  }
@@ -108,7 +108,7 @@ class ClassImplementationTranspiler {
108
108
  const staticAttributes = this.findStaticAttributes(cdef, scope, traversal);
109
109
  for (const attr of staticAttributes) {
110
110
  const name = traversal_1.Traversal.escapeNamespace(clasName) + "." + traversal_1.Traversal.escapeNamespace(attr.prefix) + traversal_1.Traversal.escapeNamespace(attr.identifier.getName().toLowerCase());
111
- ret += name + " = " + new transpile_types_1.TranspileTypes().toType(attr.identifier.getType()) + ";\n";
111
+ ret += name + " = " + transpile_types_1.TranspileTypes.toType(attr.identifier.getType()) + ";\n";
112
112
  ret += traversal.setValues(attr.identifier, name);
113
113
  }
114
114
  for (const alias of cdef.getAliases()) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FormTranspiler = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
+ const inline_1 = require("../inline");
6
7
  class FormTranspiler {
7
8
  transpile(node, traversal) {
8
9
  const formName = node.findFirstStatement(abaplint.Statements.Form)
@@ -10,6 +11,10 @@ class FormTranspiler {
10
11
  const ret = new chunk_1.Chunk();
11
12
  for (const c of node.getChildren()) {
12
13
  ret.appendChunk(traversal.traverse(c));
14
+ if (c.get() instanceof abaplint.Statements.Form) {
15
+ const declare = inline_1.InlineDeclarations.buildDeclarations(node, traversal);
16
+ ret.appendString(declare);
17
+ }
13
18
  }
14
19
  if (formName && traversal.getCurrentObject().getType() === "PROG") {
15
20
  ret.appendString(`abap.Forms['PROG-${traversal.getCurrentObject().getName().toUpperCase()}-${formName}'] = ${formName?.toLowerCase()};`);
@@ -61,7 +61,7 @@ class FunctionModuleTranspiler {
61
61
  if (type !== undefined && p.optional === true) {
62
62
  // todo, set DEFAULT value
63
63
  ret += `if (${name} === undefined) {
64
- ${name} = ${new transpile_types_1.TranspileTypes().toType(type)};
64
+ ${name} = ${transpile_types_1.TranspileTypes.toType(type)};
65
65
  }\n`;
66
66
  }
67
67
  }
@@ -13,6 +13,7 @@ export * from "./interface";
13
13
  export * from "./loop";
14
14
  export * from "./module";
15
15
  export * from "./select";
16
+ export * from "./method";
16
17
  export * from "./try";
17
18
  export * from "./types";
18
19
  export * from "./when";
@@ -29,6 +29,7 @@ __exportStar(require("./interface"), exports);
29
29
  __exportStar(require("./loop"), exports);
30
30
  __exportStar(require("./module"), exports);
31
31
  __exportStar(require("./select"), exports);
32
+ __exportStar(require("./method"), exports);
32
33
  __exportStar(require("./try"), exports);
33
34
  __exportStar(require("./types"), exports);
34
35
  __exportStar(require("./when"), exports);
@@ -37,7 +37,7 @@ class InterfaceTranspiler {
37
37
  const prefix = traversal_1.Traversal.escapeNamespace(idef.getName().toLowerCase()) + ".";
38
38
  let ret = "";
39
39
  for (const ty of idef.getTypeDefinitions().getAll()) {
40
- ret += new transpile_types_1.TranspileTypes().declareStaticSkipVoid(prefix, ty.type);
40
+ ret += transpile_types_1.TranspileTypes.declareStaticSkipVoid(prefix, ty.type);
41
41
  }
42
42
  return ret;
43
43
  }
@@ -63,7 +63,7 @@ class InterfaceTranspiler {
63
63
  }
64
64
  const interfaceName = traversal_1.Traversal.escapeNamespace(node.getFirstToken().getStr().toLowerCase());
65
65
  const name = interfaceName + "." + interfaceName + "$" + n.toLowerCase();
66
- ret += name + " = " + new transpile_types_1.TranspileTypes().toType(identifier.getType()) + ";\n";
66
+ ret += name + " = " + transpile_types_1.TranspileTypes.toType(identifier.getType()) + ";\n";
67
67
  const alias = idef?.getAliases().find(a => a.getName().toUpperCase() === n.toUpperCase());
68
68
  if (alias) {
69
69
  // todo: this is an evil workaround, should be fixed in abaplint instead
@@ -0,0 +1,7 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IStructureTranspiler } from "./_structure_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class MethodTranspiler implements IStructureTranspiler {
6
+ transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MethodTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const chunk_1 = require("../chunk");
6
+ const inline_1 = require("../inline");
7
+ class MethodTranspiler {
8
+ transpile(node, traversal) {
9
+ const ret = new chunk_1.Chunk();
10
+ for (const c of node.getChildren()) {
11
+ ret.appendChunk(traversal.traverse(c));
12
+ if (c.get() instanceof abaplint.Statements.MethodImplementation) {
13
+ const declare = inline_1.InlineDeclarations.buildDeclarations(node, traversal);
14
+ ret.appendString(declare);
15
+ }
16
+ }
17
+ return ret;
18
+ }
19
+ }
20
+ exports.MethodTranspiler = MethodTranspiler;
21
+ //# sourceMappingURL=method.js.map
@@ -1,6 +1,6 @@
1
1
  import * as abaplint from "@abaplint/core";
2
2
  export declare class TranspileTypes {
3
- declare(t: abaplint.TypedIdentifier): string;
4
- declareStaticSkipVoid(pre: string, t: abaplint.TypedIdentifier): string;
5
- toType(type: abaplint.AbstractType): string;
3
+ static declare(t: abaplint.TypedIdentifier): string;
4
+ static declareStaticSkipVoid(pre: string, t: abaplint.TypedIdentifier): string;
5
+ static toType(type: abaplint.AbstractType): string;
6
6
  }
@@ -4,13 +4,12 @@ exports.TranspileTypes = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  const traversal_1 = require("./traversal");
6
6
  const featureHexUInt8 = false;
7
- // todo: change this class to static for performance?
8
7
  class TranspileTypes {
9
- declare(t) {
8
+ static declare(t) {
10
9
  const type = t.getType();
11
10
  return "let " + traversal_1.Traversal.prefixVariable(t.getName().toLowerCase()) + " = " + this.toType(type) + ";";
12
11
  }
13
- declareStaticSkipVoid(pre, t) {
12
+ static declareStaticSkipVoid(pre, t) {
14
13
  const type = t.getType();
15
14
  const code = this.toType(type);
16
15
  // todo, this should look at the configuration, for runtime vs compile time errors
@@ -19,7 +18,7 @@ class TranspileTypes {
19
18
  }
20
19
  return pre + t.getName().toLowerCase() + " = " + code + ";\n";
21
20
  }
22
- toType(type) {
21
+ static toType(type) {
23
22
  let resolved = "";
24
23
  let extra = "";
25
24
  if (type instanceof abaplint.BasicTypes.ObjectReferenceType
@@ -231,7 +231,7 @@ class Traversal {
231
231
  for (const m of methodDefinitions.getAll()) {
232
232
  const parameters = [];
233
233
  for (const p of m.getParameters().getAll()) {
234
- const type = new transpile_types_1.TranspileTypes().toType(p.getType());
234
+ const type = transpile_types_1.TranspileTypes.toType(p.getType());
235
235
  const optional = m.getParameters().getOptional().includes(p.getName()) ? "X" : " ";
236
236
  parameters.push(`"${p.getName().toUpperCase()}": {"type": () => {return ${type};}, "is_optional": "${optional}"}`);
237
237
  }
@@ -256,13 +256,13 @@ class Traversal {
256
256
  return attr;
257
257
  }
258
258
  for (const a of def.getAttributes()?.getAll() || []) {
259
- const type = new transpile_types_1.TranspileTypes().toType(a.getType());
259
+ const type = transpile_types_1.TranspileTypes.toType(a.getType());
260
260
  const runtime = this.mapVisibility(a.getVisibility());
261
261
  const isClass = a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) ? "X" : " ";
262
262
  attr.add(`"${prefix + a.getName().toUpperCase()}": {"type": () => {return ${type};}, "visibility": "${runtime}", "is_constant": " ", "is_class": "${isClass}"}`);
263
263
  }
264
264
  for (const a of def.getAttributes()?.getConstants() || []) {
265
- const type = new transpile_types_1.TranspileTypes().toType(a.getType());
265
+ const type = transpile_types_1.TranspileTypes.toType(a.getType());
266
266
  let runtime = "";
267
267
  switch (a.getVisibility()) {
268
268
  case abaplint.Visibility.Private:
@@ -445,7 +445,7 @@ class Traversal {
445
445
  escaped = "#" + escaped;
446
446
  }
447
447
  const name = "this." + escaped;
448
- ret += name + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
448
+ ret += name + " = " + transpile_types_1.TranspileTypes.toType(a.getType()) + ";\n";
449
449
  ret += this.setValues(a, name);
450
450
  if (escaped?.startsWith("#")) {
451
451
  ret += `this.FRIENDS_ACCESS_INSTANCE["${escaped.replace("#", "")}"] = ${name};\n`;
@@ -582,7 +582,7 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
582
582
  ret += "if (this." + n + " === undefined) this." + n + " = " + cname + "." + n + ";\n";
583
583
  }
584
584
  else {
585
- ret += "if (this." + n + " === undefined) this." + n + " = " + new transpile_types_1.TranspileTypes().toType(a.getType()) + ";\n";
585
+ ret += "if (this." + n + " === undefined) this." + n + " = " + transpile_types_1.TranspileTypes.toType(a.getType()) + ";\n";
586
586
  }
587
587
  }
588
588
  for (const i of intf?.getImplementing() || []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.11.11",
3
+ "version": "2.11.13",
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.158",
32
+ "@abaplint/core": "^2.113.160",
33
33
  "source-map": "^0.7.6"
34
34
  },
35
35
  "devDependencies": {