@abaplint/transpiler 2.0.7 → 2.0.10

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 { IExpressionTranspiler } from "./_expression_transpiler";
3
3
  import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class SimpleSource3Transpiler implements IExpressionTranspiler {
6
+ private readonly addGet;
7
+ constructor(addGet?: boolean);
6
8
  transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
7
9
  }
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SimpleSource3Transpiler = void 0;
4
4
  const source_1 = require("./source");
5
5
  class SimpleSource3Transpiler {
6
+ constructor(addGet = false) {
7
+ this.addGet = addGet;
8
+ }
6
9
  transpile(node, traversal) {
7
- return new source_1.SourceTranspiler().transpile(node, traversal);
10
+ return new source_1.SourceTranspiler(this.addGet).transpile(node, traversal);
8
11
  }
9
12
  }
10
13
  exports.SimpleSource3Transpiler = SimpleSource3Transpiler;
@@ -4,4 +4,6 @@ import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class SelectTranspiler implements IStatementTranspiler {
6
6
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
+ private findKeys;
8
+ private concatCond;
7
9
  }
@@ -11,6 +11,18 @@ class SelectTranspiler {
11
11
  let select = "SELECT ";
12
12
  select += ((_a = node.findFirstExpression(abaplint.Expressions.SQLFieldList)) === null || _a === void 0 ? void 0 : _a.concatTokens()) + " ";
13
13
  select += ((_b = node.findFirstExpression(abaplint.Expressions.SQLFrom)) === null || _b === void 0 ? void 0 : _b.concatTokens()) + " ";
14
+ const where = node.findFirstExpression(abaplint.Expressions.SQLCond);
15
+ if (where) {
16
+ select += "WHERE " + this.concatCond(where, traversal) + " ";
17
+ }
18
+ const orderBy = node.findFirstExpression(abaplint.Expressions.SQLOrderBy);
19
+ if (orderBy) {
20
+ select += orderBy.concatTokens() + " ";
21
+ }
22
+ const upTo = node.findFirstExpression(abaplint.Expressions.SQLUpTo);
23
+ if (upTo) {
24
+ select += upTo.concatTokens() + " ";
25
+ }
14
26
  for (const d of node.findAllExpressionsRecursive(abaplint.Expressions.Dynamic)) {
15
27
  const chain = d.findFirstExpression(abaplint.Expressions.FieldChain);
16
28
  if (chain) {
@@ -20,9 +32,42 @@ class SelectTranspiler {
20
32
  }
21
33
  }
22
34
  if (node.concatTokens().toUpperCase().startsWith("SELECT SINGLE ")) {
23
- select += "LIMIT 1";
35
+ select += "UP TO 1 ROWS";
36
+ }
37
+ const keys = this.findKeys(node, traversal);
38
+ let primaryKey = "";
39
+ if (keys.length > 0) {
40
+ primaryKey = `, primaryKey: ${JSON.stringify(keys)}`;
41
+ }
42
+ return new chunk_1.Chunk().append(`await abap.statements.select(${target}, {select: "${select.trim()}"${primaryKey}});`, node, traversal);
43
+ }
44
+ findKeys(node, traversal) {
45
+ let keys = [];
46
+ const from = node.findAllExpressions(abaplint.Expressions.SQLFromSource).map(e => e.concatTokens());
47
+ if (from.length === 1) {
48
+ const tabl = traversal.findTable(from[0]);
49
+ if (tabl) {
50
+ keys = tabl.listKeys().map(k => k.toLowerCase());
51
+ }
52
+ }
53
+ return keys;
54
+ }
55
+ concatCond(cond, traversal) {
56
+ let ret = "";
57
+ for (const c of cond.getChildren()) {
58
+ if (c.get() instanceof abaplint.Expressions.SimpleSource3
59
+ && c instanceof abaplint.Nodes.ExpressionNode
60
+ && c.findDirectExpression(abaplint.Expressions.Constant) === undefined) {
61
+ ret += " '\" + " + new expressions_1.SimpleSource3Transpiler(true).transpile(c, traversal).getCode() + " + \"'";
62
+ }
63
+ else if (c instanceof abaplint.Nodes.ExpressionNode) {
64
+ ret += " " + this.concatCond(c, traversal);
65
+ }
66
+ else {
67
+ ret += " " + c.concatTokens();
68
+ }
24
69
  }
25
- return new chunk_1.Chunk().append(`await abap.statements.select(${target}, "${select.trim()}");`, node, traversal);
70
+ return ret.trim();
26
71
  }
27
72
  }
28
73
  exports.SelectTranspiler = SelectTranspiler;
@@ -3,22 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WaitTranspiler = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
+ const expressions_1 = require("../expressions");
6
7
  class WaitTranspiler {
7
8
  transpile(node, traversal) {
9
+ const options = [];
10
+ const seconds = node.findExpressionAfterToken("TO");
11
+ if (seconds) {
12
+ options.push("seconds: " + traversal.traverse(seconds).getCode());
13
+ }
8
14
  const concat = node.concatTokens().toUpperCase();
9
- if (concat.includes(" FOR PUSH CHANNELS ") === false) {
10
- return new chunk_1.Chunk().appendString("WAIT_TODO");
15
+ if (concat.includes(" UNTIL ") === false && seconds) {
16
+ const sec = new expressions_1.SourceTranspiler(true).transpile(seconds, traversal).getCode();
17
+ return new chunk_1.Chunk().appendString(`await new Promise(r => setTimeout(r, ${sec} * 1000));`);
11
18
  }
12
19
  const lookup = traversal.lookupClassOrInterface("KERNEL_PUSH_CHANNELS", node.getFirstToken());
13
- const options = [];
14
20
  const cond = node.findFirstExpression(abaplint.Expressions.Cond);
15
21
  if (cond) {
16
22
  options.push("cond: " + traversal.traverse(cond).getCode());
17
23
  }
18
- const seconds = node.findExpressionAfterToken("TO");
19
- if (seconds) {
20
- options.push("seconds: " + traversal.traverse(seconds).getCode());
21
- }
22
24
  const call = `await ${lookup}.wait({${options.join(",")}});`;
23
25
  return new chunk_1.Chunk().append(`if (${lookup} === undefined) throw new Error("Wait, kernel class missing");\n${call}`, node, traversal);
24
26
  }
@@ -32,6 +32,7 @@ export declare class Traversal {
32
32
  private findReadOrWriteReference;
33
33
  buildConstructorContents(scope: abaplint.ISpaghettiScopeNode | undefined, def: abaplint.IClassDefinition, inputName: string): string;
34
34
  findInterfaceDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IInterfaceDefinition | undefined;
35
+ findTable(name: string): abaplint.Objects.Table | undefined;
35
36
  findClassDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IClassDefinition | undefined;
36
37
  private dataFromInterfaces;
37
38
  determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
@@ -289,6 +289,10 @@ class Traversal {
289
289
  }
290
290
  return intf;
291
291
  }
292
+ findTable(name) {
293
+ const tabl = this.reg.getObject("TABL", name);
294
+ return tabl;
295
+ }
292
296
  findClassDefinition(name, scope) {
293
297
  let clas = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name);
294
298
  if (clas === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.0.7",
3
+ "version": "2.0.10",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,11 +28,11 @@
28
28
  "author": "abaplint",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@abaplint/core": "^2.88.6",
31
+ "@abaplint/core": "^2.89.0",
32
32
  "source-map": "^0.7.3"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/chai": "^4.3.0",
35
+ "@types/chai": "^4.3.1",
36
36
  "@types/mocha": "^9.1.0",
37
37
  "chai": "^4.3.6",
38
38
  "mocha": "^9.2.2",