@abaplint/transpiler 2.3.27 → 2.3.28

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.
@@ -3,5 +3,7 @@ import { IStatementTranspiler } from "./_statement_transpiler";
3
3
  import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class DoTranspiler implements IStatementTranspiler {
6
+ private readonly syIndexBackup;
7
+ constructor(syIndexBackup: string);
6
8
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
9
  }
@@ -6,19 +6,24 @@ const expressions_1 = require("../expressions");
6
6
  const unique_identifier_1 = require("../unique_identifier");
7
7
  const chunk_1 = require("../chunk");
8
8
  class DoTranspiler {
9
+ constructor(syIndexBackup) {
10
+ this.syIndexBackup = syIndexBackup;
11
+ }
9
12
  transpile(node, traversal) {
10
13
  const found = node.findFirstExpression(abaplint.Expressions.Source);
11
14
  if (found) {
12
15
  const source = new expressions_1.SourceTranspiler(true).transpile(found, traversal).getCode();
13
16
  const idSource = unique_identifier_1.UniqueIdentifier.get();
14
17
  const id = unique_identifier_1.UniqueIdentifier.get();
15
- return new chunk_1.Chunk(`const ${idSource} = ${source};
18
+ return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
19
+ const ${idSource} = ${source};
16
20
  for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
17
21
  abap.builtin.sy.get().index.set(${id} + 1);`);
18
22
  }
19
23
  else {
20
24
  const unique = unique_identifier_1.UniqueIdentifier.get();
21
- return new chunk_1.Chunk(`let ${unique} = 1;
25
+ return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
26
+ let ${unique} = 1;
22
27
  while (true) {
23
28
  abap.builtin.sy.get().index.set(${unique}++);`);
24
29
  }
@@ -3,5 +3,7 @@ import { Chunk } from "../chunk";
3
3
  import { Traversal } from "../traversal";
4
4
  import { IStatementTranspiler } from "./_statement_transpiler";
5
5
  export declare class EndDoTranspiler implements IStatementTranspiler {
6
+ private readonly syIndexBackup;
7
+ constructor(syIndexBackup: string);
6
8
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
9
  }
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EndDoTranspiler = void 0;
4
4
  const chunk_1 = require("../chunk");
5
5
  class EndDoTranspiler {
6
+ constructor(syIndexBackup) {
7
+ this.syIndexBackup = syIndexBackup;
8
+ }
6
9
  transpile(node, traversal) {
7
- return new chunk_1.Chunk().append("}", node, traversal);
10
+ return new chunk_1.Chunk().append(`}
11
+ abap.builtin.sy.get().index.set(${this.syIndexBackup});`, node, traversal);
8
12
  }
9
13
  }
10
14
  exports.EndDoTranspiler = EndDoTranspiler;
@@ -3,5 +3,7 @@ import { Chunk } from "../chunk";
3
3
  import { Traversal } from "../traversal";
4
4
  import { IStatementTranspiler } from "./_statement_transpiler";
5
5
  export declare class EndWhileTranspiler implements IStatementTranspiler {
6
+ private readonly syIndexBackup;
7
+ constructor(syIndexBackup: string);
6
8
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
9
  }
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EndWhileTranspiler = void 0;
4
4
  const chunk_1 = require("../chunk");
5
5
  class EndWhileTranspiler {
6
+ constructor(syIndexBackup) {
7
+ this.syIndexBackup = syIndexBackup;
8
+ }
6
9
  transpile(node, traversal) {
7
- return new chunk_1.Chunk().append("}", node, traversal);
10
+ return new chunk_1.Chunk().append(`}
11
+ abap.builtin.sy.get().index.set(${this.syIndexBackup});`, node, traversal);
8
12
  }
9
13
  }
10
14
  exports.EndWhileTranspiler = EndWhileTranspiler;
@@ -3,5 +3,7 @@ import { IStatementTranspiler } from "./_statement_transpiler";
3
3
  import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class WhileTranspiler implements IStatementTranspiler {
6
+ private readonly syIndexBackup;
7
+ constructor(syIndexBackup: string);
6
8
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
9
  }
@@ -6,11 +6,15 @@ const expressions_1 = require("../expressions");
6
6
  const chunk_1 = require("../chunk");
7
7
  const unique_identifier_1 = require("../unique_identifier");
8
8
  class WhileTranspiler {
9
+ constructor(syIndexBackup) {
10
+ this.syIndexBackup = syIndexBackup;
11
+ }
9
12
  transpile(node, traversal) {
10
13
  const cond = new expressions_1.CondTranspiler().transpile(node.findFirstExpression(abaplint.Expressions.Cond), traversal);
11
14
  const unique = unique_identifier_1.UniqueIdentifier.get();
12
15
  return new chunk_1.Chunk()
13
- .append(`let ${unique} = 1;
16
+ .append(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
17
+ let ${unique} = 1;
14
18
  while (`, node, traversal)
15
19
  .appendChunk(cond)
16
20
  .appendString(`) {
@@ -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 DoTranspiler implements IStructureTranspiler {
6
+ transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DoTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const chunk_1 = require("../chunk");
6
+ const statements_1 = require("../statements");
7
+ const unique_identifier_1 = require("../unique_identifier");
8
+ class DoTranspiler {
9
+ transpile(node, traversal) {
10
+ const ret = new chunk_1.Chunk();
11
+ const syIndexBackup = unique_identifier_1.UniqueIdentifier.get();
12
+ for (const c of node.getChildren()) {
13
+ if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.Do) {
14
+ ret.appendChunk(new statements_1.DoTranspiler(syIndexBackup).transpile(c, traversal));
15
+ ret.appendString("\n");
16
+ }
17
+ else if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.EndDo) {
18
+ ret.appendChunk(new statements_1.EndDoTranspiler(syIndexBackup).transpile(c, traversal));
19
+ }
20
+ else {
21
+ ret.appendChunk(traversal.traverse(c));
22
+ }
23
+ }
24
+ return ret;
25
+ }
26
+ }
27
+ exports.DoTranspiler = DoTranspiler;
28
+ //# sourceMappingURL=do.js.map
@@ -4,6 +4,7 @@ exports.FunctionModuleTranspiler = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  const traversal_1 = require("../traversal");
6
6
  const chunk_1 = require("../chunk");
7
+ const transpile_types_1 = require("../transpile_types");
7
8
  class FunctionModuleTranspiler {
8
9
  transpile(node, traversal) {
9
10
  var _a;
@@ -16,7 +17,7 @@ class FunctionModuleTranspiler {
16
17
  name = "FunctionModuleTranspilerNameNotFound";
17
18
  }
18
19
  r += `async function ${traversal_1.Traversal.escapeClassName(name)}(INPUT) {\n`;
19
- r += this.findSignature(traversal, name);
20
+ r += this.findSignature(traversal, name, c);
20
21
  }
21
22
  else if (c.get() instanceof abaplint.Statements.EndFunction) {
22
23
  r += "}\n";
@@ -29,7 +30,8 @@ class FunctionModuleTranspiler {
29
30
  return new chunk_1.Chunk(r);
30
31
  }
31
32
  //////////////////////
32
- findSignature(traversal, name) {
33
+ findSignature(traversal, name, node) {
34
+ var _a;
33
35
  const group = traversal.getCurrentObject();
34
36
  if (group === undefined) {
35
37
  throw "FunctionModuleTranspilerGroupNotFound";
@@ -38,6 +40,7 @@ class FunctionModuleTranspiler {
38
40
  if (module === undefined) {
39
41
  throw "FunctionModuleTranspilerModuleNotFound";
40
42
  }
43
+ const scope = traversal.findCurrentScopeByToken(node.getLastToken());
41
44
  let ret = "";
42
45
  for (const p of module.getParameters()) {
43
46
  ret += `// ${p.direction} ${p.name} ${p.type}\n`;
@@ -49,7 +52,18 @@ class FunctionModuleTranspiler {
49
52
  direction = "importing";
50
53
  }
51
54
  // note: all directions are optional
52
- ret += `let ${p.name.toLowerCase()} = INPUT.${direction}?.${p.name.toLowerCase()};\n`;
55
+ const name = p.name.toLowerCase();
56
+ ret += `let ${name} = INPUT.${direction}?.${name};\n`;
57
+ if (direction === "exporting" || direction === "importing" || direction === "changing") {
58
+ const type = (_a = scope === null || scope === void 0 ? void 0 : scope.findVariable(name)) === null || _a === void 0 ? void 0 : _a.getType();
59
+ if (type !== undefined) {
60
+ // todo, set DEFAULT value
61
+ // todo, check for OPTIONALness and raise exceptions and stuff
62
+ ret += `if (${name} === undefined) {
63
+ ${name} = ${new transpile_types_1.TranspileTypes().toType(type)};
64
+ }\n`;
65
+ }
66
+ }
53
67
  }
54
68
  return ret;
55
69
  }
@@ -3,10 +3,12 @@ export * from "./class_definition";
3
3
  export * from "./class_implementation";
4
4
  export * from "./constants";
5
5
  export * from "./data";
6
+ export * from "./define";
7
+ export * from "./do";
6
8
  export * from "./function_module";
7
9
  export * from "./interface";
10
+ export * from "./while";
8
11
  export * from "./select";
9
12
  export * from "./try";
10
- export * from "./define";
11
13
  export * from "./types";
12
14
  export * from "./when";
@@ -19,11 +19,13 @@ __exportStar(require("./class_definition"), exports);
19
19
  __exportStar(require("./class_implementation"), exports);
20
20
  __exportStar(require("./constants"), exports);
21
21
  __exportStar(require("./data"), exports);
22
+ __exportStar(require("./define"), exports);
23
+ __exportStar(require("./do"), exports);
22
24
  __exportStar(require("./function_module"), exports);
23
25
  __exportStar(require("./interface"), exports);
26
+ __exportStar(require("./while"), exports);
24
27
  __exportStar(require("./select"), exports);
25
28
  __exportStar(require("./try"), exports);
26
- __exportStar(require("./define"), exports);
27
29
  __exportStar(require("./types"), exports);
28
30
  __exportStar(require("./when"), exports);
29
31
  //# sourceMappingURL=index.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 WhileTranspiler implements IStructureTranspiler {
6
+ transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhileTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const chunk_1 = require("../chunk");
6
+ const statements_1 = require("../statements");
7
+ const unique_identifier_1 = require("../unique_identifier");
8
+ class WhileTranspiler {
9
+ transpile(node, traversal) {
10
+ const ret = new chunk_1.Chunk();
11
+ const syIndexBackup = unique_identifier_1.UniqueIdentifier.get();
12
+ for (const c of node.getChildren()) {
13
+ if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.While) {
14
+ ret.appendChunk(new statements_1.WhileTranspiler(syIndexBackup).transpile(c, traversal));
15
+ ret.appendString("\n");
16
+ }
17
+ else if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.EndWhile) {
18
+ ret.appendChunk(new statements_1.EndWhileTranspiler(syIndexBackup).transpile(c, traversal));
19
+ }
20
+ else {
21
+ ret.appendChunk(traversal.traverse(c));
22
+ }
23
+ }
24
+ return ret;
25
+ }
26
+ }
27
+ exports.WhileTranspiler = WhileTranspiler;
28
+ //# sourceMappingURL=while.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.3.27",
3
+ "version": "2.3.28",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",