@abaplint/transpiler 2.3.27 → 2.3.29

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});\n`, 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});\n`, node, traversal);
8
12
  }
9
13
  }
10
14
  exports.EndWhileTranspiler = EndWhileTranspiler;
@@ -3,8 +3,10 @@ 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 unique_identifier_1 = require("../unique_identifier");
6
7
  class FormTranspiler {
7
8
  transpile(node) {
9
+ unique_identifier_1.UniqueIdentifier.resetIndexBackup();
8
10
  const name = node.findFirstExpression(abaplint.Expressions.FormName).getFirstToken().getStr();
9
11
  return new chunk_1.Chunk("async function " + name + "() {");
10
12
  }
@@ -6,6 +6,7 @@ const transpile_types_1 = require("../transpile_types");
6
6
  const traversal_1 = require("../traversal");
7
7
  const expressions_1 = require("../expressions");
8
8
  const chunk_1 = require("../chunk");
9
+ const unique_identifier_1 = require("../unique_identifier");
9
10
  class MethodImplementationTranspiler {
10
11
  transpile(node, traversal) {
11
12
  var _a, _b;
@@ -100,9 +101,11 @@ class MethodImplementationTranspiler {
100
101
  "return " + traversal_1.Traversal.escapeClassName(className) + "." + traversal_1.Traversal.escapeClassName(methodName) + "(" + unique + ");\n" +
101
102
  "}\n" + "static ";
102
103
  }
104
+ unique_identifier_1.UniqueIdentifier.resetIndexBackup();
103
105
  const str = staticMethod + "async " + traversal_1.Traversal.escapeClassName(methodName) + "(" + unique + ") {" + after;
104
106
  return new chunk_1.Chunk().append(str, node, traversal);
105
107
  }
108
+ /////////////////////////////
106
109
  findMethod(name, cdef, traversal) {
107
110
  var _a, _b;
108
111
  if (cdef === undefined) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReturnTranspiler = void 0;
4
4
  const chunk_1 = require("../chunk");
5
+ const unique_identifier_1 = require("../unique_identifier");
5
6
  class ReturnTranspiler {
6
7
  transpile(node, traversal) {
7
8
  let extra = "";
@@ -13,7 +14,11 @@ class ReturnTranspiler {
13
14
  extra = " " + n.toLowerCase();
14
15
  }
15
16
  }
16
- return new chunk_1.Chunk().append("return" + extra + ";", node, traversal);
17
+ let pre = "";
18
+ if (traversal.isInsideDoOrWhile(node)) {
19
+ pre = `abap.builtin.sy.get().index.set(${unique_identifier_1.UniqueIdentifier.getIndexBackup1()});\n`;
20
+ }
21
+ return new chunk_1.Chunk().append(pre + "return" + extra + ";", node, traversal);
17
22
  }
18
23
  }
19
24
  exports.ReturnTranspiler = ReturnTranspiler;
@@ -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.getIndexBackup();
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,8 @@ 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");
8
+ const unique_identifier_1 = require("../unique_identifier");
7
9
  class FunctionModuleTranspiler {
8
10
  transpile(node, traversal) {
9
11
  var _a;
@@ -16,7 +18,7 @@ class FunctionModuleTranspiler {
16
18
  name = "FunctionModuleTranspilerNameNotFound";
17
19
  }
18
20
  r += `async function ${traversal_1.Traversal.escapeClassName(name)}(INPUT) {\n`;
19
- r += this.findSignature(traversal, name);
21
+ r += this.findSignature(traversal, name, c);
20
22
  }
21
23
  else if (c.get() instanceof abaplint.Statements.EndFunction) {
22
24
  r += "}\n";
@@ -26,10 +28,12 @@ class FunctionModuleTranspiler {
26
28
  r += traversal.traverse(c).getCode();
27
29
  }
28
30
  }
31
+ unique_identifier_1.UniqueIdentifier.resetIndexBackup();
29
32
  return new chunk_1.Chunk(r);
30
33
  }
31
34
  //////////////////////
32
- findSignature(traversal, name) {
35
+ findSignature(traversal, name, node) {
36
+ var _a;
33
37
  const group = traversal.getCurrentObject();
34
38
  if (group === undefined) {
35
39
  throw "FunctionModuleTranspilerGroupNotFound";
@@ -38,6 +42,7 @@ class FunctionModuleTranspiler {
38
42
  if (module === undefined) {
39
43
  throw "FunctionModuleTranspilerModuleNotFound";
40
44
  }
45
+ const scope = traversal.findCurrentScopeByToken(node.getLastToken());
41
46
  let ret = "";
42
47
  for (const p of module.getParameters()) {
43
48
  ret += `// ${p.direction} ${p.name} ${p.type}\n`;
@@ -49,7 +54,18 @@ class FunctionModuleTranspiler {
49
54
  direction = "importing";
50
55
  }
51
56
  // note: all directions are optional
52
- ret += `let ${p.name.toLowerCase()} = INPUT.${direction}?.${p.name.toLowerCase()};\n`;
57
+ const name = p.name.toLowerCase();
58
+ ret += `let ${name} = INPUT.${direction}?.${name};\n`;
59
+ if (direction === "exporting" || direction === "importing" || direction === "changing") {
60
+ const type = (_a = scope === null || scope === void 0 ? void 0 : scope.findVariable(name)) === null || _a === void 0 ? void 0 : _a.getType();
61
+ if (type !== undefined) {
62
+ // todo, set DEFAULT value
63
+ // todo, check for OPTIONALness and raise exceptions and stuff
64
+ ret += `if (${name} === undefined) {
65
+ ${name} = ${new transpile_types_1.TranspileTypes().toType(type)};
66
+ }\n`;
67
+ }
68
+ }
53
69
  }
54
70
  return ret;
55
71
  }
@@ -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.getIndexBackup();
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
@@ -38,6 +38,7 @@ export declare class Traversal {
38
38
  private dataFromInterfaces;
39
39
  determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
40
40
  isInsideLoop(node: abaplint.Nodes.StatementNode): boolean;
41
+ isInsideDoOrWhile(node: abaplint.Nodes.StatementNode): boolean;
41
42
  registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
42
43
  lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
43
44
  private buildPrefix;
@@ -373,6 +373,24 @@ class Traversal {
373
373
  }
374
374
  return stack.length > 0;
375
375
  }
376
+ isInsideDoOrWhile(node) {
377
+ const stack = [];
378
+ for (const statement of this.getFile().getStatements()) {
379
+ const get = statement.get();
380
+ if (get instanceof abaplint.Statements.While
381
+ || get instanceof abaplint.Statements.Do) {
382
+ stack.push(statement);
383
+ }
384
+ else if (get instanceof abaplint.Statements.EndWhile
385
+ || get instanceof abaplint.Statements.EndDo) {
386
+ stack.pop();
387
+ }
388
+ if (statement === node) {
389
+ break;
390
+ }
391
+ }
392
+ return stack.length > 0;
393
+ }
376
394
  registerClassOrInterface(def) {
377
395
  if (def === undefined) {
378
396
  return "";
@@ -1,5 +1,9 @@
1
1
  export declare class UniqueIdentifier {
2
- static counter: number;
2
+ private static counter;
3
+ private static indexBackup;
3
4
  static reset(): void;
4
5
  static get(): string;
6
+ static resetIndexBackup(): void;
7
+ static getIndexBackup(): string;
8
+ static getIndexBackup1(): string;
5
9
  }
@@ -11,7 +11,18 @@ class UniqueIdentifier {
11
11
  this.counter++;
12
12
  return "unique" + this.counter;
13
13
  }
14
+ static resetIndexBackup() {
15
+ this.indexBackup = 0;
16
+ }
17
+ static getIndexBackup() {
18
+ this.indexBackup++;
19
+ return "indexBackup" + this.indexBackup;
20
+ }
21
+ static getIndexBackup1() {
22
+ return "indexBackup1";
23
+ }
14
24
  }
15
25
  exports.UniqueIdentifier = UniqueIdentifier;
16
26
  UniqueIdentifier.counter = 0;
27
+ UniqueIdentifier.indexBackup = 0;
17
28
  //# sourceMappingURL=unique_identifier.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.29",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "author": "abaplint",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@abaplint/core": "^2.93.57",
31
+ "@abaplint/core": "^2.93.58",
32
32
  "source-map": "^0.7.4"
33
33
  },
34
34
  "devDependencies": {