@abaplint/transpiler 2.10.49 → 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.
@@ -119,22 +119,25 @@ class HandleABAP {
119
119
  return contents;
120
120
  }
121
121
  findExports(node) {
122
- if (node === undefined) {
123
- return [];
124
- }
125
122
  const res = [];
126
- for (const c of node.findAllStatements(abaplint.Statements.ClassDefinition)) {
123
+ for (const c of node?.findAllStatements(abaplint.Statements.ClassDefinition) || []) {
127
124
  const e = c.findFirstExpression(abaplint.Expressions.ClassName)?.getFirstToken().getStr();
128
125
  if (e) {
129
126
  res.push(e.toLowerCase());
130
127
  }
131
128
  }
132
- for (const c of node.findAllStatements(abaplint.Statements.Interface)) {
129
+ for (const c of node?.findAllStatements(abaplint.Statements.Interface) || []) {
133
130
  const e = c.findFirstExpression(abaplint.Expressions.InterfaceName)?.getFirstToken().getStr();
134
131
  if (e) {
135
132
  res.push(e.toLowerCase());
136
133
  }
137
134
  }
135
+ for (const c of node?.findAllStatements(abaplint.Statements.Form) || []) {
136
+ const e = c.findFirstExpression(abaplint.Expressions.FormName)?.getFirstToken().getStr();
137
+ if (e) {
138
+ res.push(e.toLowerCase());
139
+ }
140
+ }
138
141
  return res;
139
142
  }
140
143
  }
@@ -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) {
@@ -25,6 +25,7 @@ export * from "./close_dataset";
25
25
  export * from "./collect";
26
26
  export * from "./commit";
27
27
  export * from "./compute";
28
+ export * from "./program";
28
29
  export * from "./concatenate";
29
30
  export * from "./condense";
30
31
  export * from "./constant";
@@ -41,6 +41,7 @@ __exportStar(require("./close_dataset"), exports);
41
41
  __exportStar(require("./collect"), exports);
42
42
  __exportStar(require("./commit"), exports);
43
43
  __exportStar(require("./compute"), exports);
44
+ __exportStar(require("./program"), exports);
44
45
  __exportStar(require("./concatenate"), exports);
45
46
  __exportStar(require("./condense"), exports);
46
47
  __exportStar(require("./constant"), exports);
@@ -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 { IStatementTranspiler } from "./_statement_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class ProgramTranspiler implements IStatementTranspiler {
6
+ transpile(_node: abaplint.Nodes.StatementNode, _traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProgramTranspiler = void 0;
4
+ const chunk_1 = require("../chunk");
5
+ class ProgramTranspiler {
6
+ transpile(_node, _traversal) {
7
+ // for now, do nothing,
8
+ return new chunk_1.Chunk(``);
9
+ }
10
+ }
11
+ exports.ProgramTranspiler = ProgramTranspiler;
12
+ //# sourceMappingURL=program.js.map
@@ -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
  }
@@ -1,5 +1,4 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { ISpaghettiScopeNode } from "@abaplint/core";
3
2
  import { Chunk } from "./chunk";
4
3
  import { ITranspilerOptions } from "./types";
5
4
  export declare class Traversal {
@@ -31,7 +30,7 @@ export declare class Traversal {
31
30
  buildAttributes(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined, scope: abaplint.ISpaghettiScopeNode | undefined, prefix?: string): Set<string>;
32
31
  isBuiltinMethod(token: abaplint.Token): boolean;
33
32
  isSQLConversion(token: abaplint.Token): string | undefined;
34
- findMethodReference(token: abaplint.Token, scope: ISpaghettiScopeNode | undefined): undefined | {
33
+ findMethodReference(token: abaplint.Token, scope: abaplint.ISpaghettiScopeNode | undefined): undefined | {
35
34
  def: abaplint.Types.MethodDefinition;
36
35
  name: string;
37
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.10.49",
3
+ "version": "2.10.51",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -29,14 +29,14 @@
29
29
  "author": "abaplint",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@abaplint/core": "^2.113.110",
32
+ "@abaplint/core": "^2.113.114",
33
33
  "source-map": "^0.7.4"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/chai": "^4.3.20",
37
37
  "@types/mocha": "^10.0.10",
38
38
  "chai": "^4.5.0",
39
- "mocha": "^11.1.0",
39
+ "mocha": "^11.2.2",
40
40
  "source-map-support": "^0.5.21",
41
41
  "typescript": "^5.8.3"
42
42
  }