@abaplint/transpiler 2.10.50 → 2.10.51

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.
@@ -60,34 +60,35 @@ class AssignTranspiler {
60
60
  if (firstFirst?.get() instanceof abaplint.Expressions.Constant) {
61
61
  const s = firstFirst.getFirstToken().getStr().toLowerCase().match(/\w+/)?.toString();
62
62
  options.push(`dynamicSource: (() => {
63
- try { return ${s}; } catch {}
64
- try { return this.${s}; } catch {}
65
- })()`);
63
+ try { return ${s}; } catch {}
64
+ try { return this.${s}; } catch {}
65
+ })()`);
66
66
  }
67
67
  else if (firstFirst?.get() instanceof abaplint.Expressions.FieldChain && firstFirst instanceof abaplint.Nodes.ExpressionNode) {
68
68
  const code = new expressions_1.FieldChainTranspiler(true).transpile(firstFirst, traversal).getCode();
69
69
  options.push(`dynamicSource: (() => {
70
- const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
71
- try { return eval(name); } catch {}
72
- try { return eval("this." + name); } catch {}
73
- })()`);
70
+ const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
71
+ try { return eval(name); } catch {}
72
+ try { return eval("this." + name); } catch {}
73
+ })()`);
74
74
  }
75
75
  }
76
76
  else if (first?.get() instanceof abaplint.Expressions.Source && first instanceof abaplint.Nodes.ExpressionNode) {
77
77
  // const name = first.concatTokens().toLowerCase();
78
78
  const name = new expressions_1.SourceTranspiler().transpile(first, traversal).getCode();
79
79
  options.push(`dynamicSource: (() => {
80
- try { return ${name}; } catch {}
81
- try { return this.${name}; } catch {}
82
- })()`);
80
+ try { return ${name}; } catch {}
81
+ try { return this.${name}; } catch {}
82
+ })()`);
83
83
  }
84
84
  }
85
85
  if (concat.endsWith(" CASTING.") || concat.includes(" CASTING TYPE ")) {
86
86
  options.push("casting: true");
87
87
  }
88
- return new chunk_1.Chunk().append("abap.statements.assign({", node, traversal)
88
+ const ret = new chunk_1.Chunk().append("abap.statements.assign({", node, traversal)
89
89
  .appendString(options.join(", "))
90
90
  .append("});", node.getLastToken(), traversal);
91
+ return ret;
91
92
  }
92
93
  }
93
94
  exports.AssignTranspiler = AssignTranspiler;
@@ -45,8 +45,8 @@ class CallFunctionTranspiler {
45
45
  else {
46
46
  const illegalFunc = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_FUNC'", node.getFirstToken(), true);
47
47
  const call = `abap.FunctionModules[${fmname}]`;
48
- ret.appendString(`if (${call} === undefined && ${illegalFunc} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_FUNC not found"; }\n`);
49
- ret.appendString(`if (${call} === undefined) { throw new ${illegalFunc}(); }\n`);
48
+ // eslint-disable-next-line max-len
49
+ ret.appendString(`if (${call} === undefined) { if (${illegalFunc} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_FUNC not found"; } else { throw new ${illegalFunc}();} }\n`);
50
50
  ret.appendString(`await ${call}(${param});`);
51
51
  }
52
52
  if (exceptions) {
@@ -11,47 +11,67 @@ class PerformTranspiler {
11
11
  return new chunk_1.Chunk(`throw new Error("PerformTranspiler FormName not found");`);
12
12
  }
13
13
  else if (node.concatTokens().toUpperCase().includes(" IN PROGRAM ")) {
14
- return new chunk_1.Chunk(`throw new Error("PerformTranspiler IN PROGRAM, transpiler todo");`);
15
- }
16
- let def = undefined;
17
- const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
18
- for (const r of scope?.getData().references || []) {
19
- if (r.referenceType === abaplint.ReferenceType.FormReference
20
- && r.position.getStart().equals(formName.getFirstToken().getStart())
21
- && r.resolved instanceof abaplint.Types.FormDefinition) {
22
- def = r.resolved;
14
+ // todo: throw exception if not found?
15
+ const expression = node.findExpressionAfterToken("PROGRAM");
16
+ let ref = "";
17
+ if (expression?.get() instanceof abaplint.Expressions.Dynamic) {
18
+ const name = expression.getChildren()[1].concatTokens() + ".get().trimEnd()";
19
+ ref = `abap.Forms['PROG-' + ${name} + '-${formName.concatTokens().toUpperCase()}']`;
23
20
  }
24
- }
25
- // todo: pass by VALUE()
26
- const params = [];
27
- let index = 0;
28
- for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
29
- const name = def?.getTablesParameters()[index].getName().toLowerCase();
30
- if (name === undefined) {
31
- continue;
21
+ else {
22
+ const progName = expression?.concatTokens().toUpperCase();
23
+ ref = `abap.Forms['PROG-${progName}-${formName.concatTokens().toUpperCase()}']`;
32
24
  }
33
- params.push(`"${name}": ` + traversal.traverse(t).getCode());
34
- index++;
35
- }
36
- index = 0;
37
- for (const u of node.findDirectExpression(abaplint.Expressions.PerformUsing)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
38
- const name = def?.getUsingParameters()[index].getName().toLowerCase();
39
- if (name === undefined) {
40
- continue;
25
+ const params = [];
26
+ // hacky hack
27
+ for (const t of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Target) || []) {
28
+ const name = t.getFirstToken().getStr();
29
+ params.push(`"${name}": ` + traversal.traverse(t).getCode());
41
30
  }
42
- params.push(`"${name}": ` + traversal.traverse(u).getCode());
43
- index++;
31
+ return new chunk_1.Chunk("await " + ref + `({${params.join(",")}});`);
44
32
  }
45
- index = 0;
46
- for (const c of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
47
- const name = def?.getChangingParameters()[index].getName().toLowerCase();
48
- if (name === undefined) {
49
- continue;
33
+ else {
34
+ // todo: most of this needs rewriting?
35
+ let def = undefined;
36
+ const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
37
+ for (const r of scope?.getData().references || []) {
38
+ if (r.referenceType === abaplint.ReferenceType.FormReference
39
+ && r.position.getStart().equals(formName.getFirstToken().getStart())
40
+ && r.resolved instanceof abaplint.Types.FormDefinition) {
41
+ def = r.resolved;
42
+ }
43
+ }
44
+ // todo: pass by VALUE()
45
+ const params = [];
46
+ let index = 0;
47
+ for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
48
+ const name = def?.getTablesParameters()[index].getName().toLowerCase();
49
+ if (name === undefined) {
50
+ continue;
51
+ }
52
+ params.push(`"${name}": ` + traversal.traverse(t).getCode());
53
+ index++;
54
+ }
55
+ index = 0;
56
+ for (const u of node.findDirectExpression(abaplint.Expressions.PerformUsing)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
57
+ const name = def?.getUsingParameters()[index].getName().toLowerCase();
58
+ if (name === undefined) {
59
+ continue;
60
+ }
61
+ params.push(`"${name}": ` + traversal.traverse(u).getCode());
62
+ index++;
63
+ }
64
+ index = 0;
65
+ for (const c of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
66
+ const name = def?.getChangingParameters()[index].getName().toLowerCase();
67
+ if (name === undefined) {
68
+ continue;
69
+ }
70
+ params.push(`"${name}": ` + traversal.traverse(c).getCode());
71
+ index++;
50
72
  }
51
- params.push(`"${name}": ` + traversal.traverse(c).getCode());
52
- index++;
73
+ return new chunk_1.Chunk("await " + formName.concatTokens() + `({${params.join(",")}});`);
53
74
  }
54
- return new chunk_1.Chunk("await " + formName.concatTokens() + `({${params.join(",")}});`);
55
75
  }
56
76
  }
57
77
  exports.PerformTranspiler = PerformTranspiler;
@@ -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 FormTranspiler 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.FormTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const chunk_1 = require("../chunk");
6
+ class FormTranspiler {
7
+ transpile(node, traversal) {
8
+ const formName = node.findFirstStatement(abaplint.Statements.Form)
9
+ ?.findDirectExpression(abaplint.Expressions.FormName)?.concatTokens()?.toUpperCase();
10
+ const ret = new chunk_1.Chunk();
11
+ for (const c of node.getChildren()) {
12
+ ret.appendChunk(traversal.traverse(c));
13
+ }
14
+ if (formName && traversal.getCurrentObject().getType() === "PROG") {
15
+ ret.appendString(`abap.Forms['PROG-${traversal.getCurrentObject().getName().toUpperCase()}-${formName}'] = ${formName?.toLowerCase()};`);
16
+ }
17
+ return ret;
18
+ }
19
+ }
20
+ exports.FormTranspiler = FormTranspiler;
21
+ //# sourceMappingURL=form.js.map
@@ -17,3 +17,4 @@ export * from "./try";
17
17
  export * from "./types";
18
18
  export * from "./when";
19
19
  export * from "./while";
20
+ export * from "./form";
@@ -33,4 +33,5 @@ __exportStar(require("./try"), exports);
33
33
  __exportStar(require("./types"), exports);
34
34
  __exportStar(require("./when"), exports);
35
35
  __exportStar(require("./while"), exports);
36
+ __exportStar(require("./form"), exports);
36
37
  //# sourceMappingURL=index.js.map
@@ -91,7 +91,7 @@ class TranspileTypes {
91
91
  asInclude[c.name.toLowerCase()] = true;
92
92
  }
93
93
  }
94
- extra = "{" + list.join(", ") + "}";
94
+ extra = "{\n" + list.join(",\n") + "}";
95
95
  if (type.getQualifiedName() !== undefined) {
96
96
  extra += ", \"" + type.getQualifiedName() + "\"";
97
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.10.50",
3
+ "version": "2.10.51",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",