@abaplint/transpiler 2.1.44 → 2.1.47

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.
@@ -8,7 +8,7 @@ class CallFunctionTranspiler {
8
8
  var _a, _b;
9
9
  const fmname = (_a = node.findDirectExpression(abaplint.Expressions.FunctionName)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
10
10
  if (fmname === undefined) {
11
- throw "CallFunctionTranspilerNameNotFound";
11
+ throw new Error("CallFunctionTranspilerNameNotFound");
12
12
  }
13
13
  let param = "";
14
14
  const fmp = node.findDirectExpression(abaplint.Expressions.FunctionParameters);
@@ -71,7 +71,7 @@ class MethodImplementationTranspiler {
71
71
  }
72
72
  }
73
73
  else {
74
- throw "MethodImplementationTranspiler, unknown default param type";
74
+ throw new Error("MethodImplementationTranspiler, unknown default param type");
75
75
  }
76
76
  after += "if (" + unique + " === undefined || " + unique + "." + varName + " === undefined) {" + varName + " = " + val + ";}\n";
77
77
  }
@@ -39,15 +39,18 @@ class ReadTableTranspiler {
39
39
  }
40
40
  const compare = node.findDirectExpression(abaplint.Expressions.ComponentCompareSimple);
41
41
  if (compare) {
42
- const components = compare.findDirectExpressions(abaplint.Expressions.ComponentChainSimple);
43
- const sources = compare.findDirectExpressions(abaplint.Expressions.Source);
44
- if (components.length !== sources.length) {
45
- throw new Error("READ TABLE, transpiler unexpected lengths");
46
- }
47
42
  const conds = [];
48
- for (let i = 0; i < components.length; i++) {
49
- const s = traversal.traverse(sources[i]).getCode();
50
- const field = components[i].concatTokens().toLowerCase().replace("-", ".get().");
43
+ const count = compare.getChildren().length / 3;
44
+ for (let i = 0; i < count; i++) {
45
+ const left = compare.getChildren()[i * 3];
46
+ const source = compare.getChildren()[(i * 3) + 2];
47
+ const s = traversal.traverse(source).getCode();
48
+ let field = left.concatTokens().toLowerCase().replace("-", ".get().");
49
+ if (left.get() instanceof abaplint.Expressions.Dynamic
50
+ && left instanceof abaplint.Nodes.ExpressionNode) {
51
+ const concat = left.concatTokens().toLowerCase();
52
+ field = concat.substring(2, concat.length - 2);
53
+ }
51
54
  if (s.includes("await")) {
52
55
  const id = unique_identifier_1.UniqueIdentifier.get();
53
56
  prefix += "const " + id + " = " + s + ";\n";
@@ -6,5 +6,7 @@ export declare class SelectTranspiler implements IStatementTranspiler {
6
6
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal, targetOverride?: string): Chunk;
7
7
  private findKeys;
8
8
  private concatCond;
9
+ private sqlIn;
10
+ private basicCondition;
9
11
  private isWhereExpression;
10
12
  }
@@ -96,12 +96,30 @@ class SelectTranspiler {
96
96
  return keys;
97
97
  }
98
98
  concatCond(cond, traversal) {
99
+ var _a;
99
100
  let ret = "";
100
101
  for (const c of cond.getChildren()) {
101
- if (c.get() instanceof abaplint.Expressions.SimpleSource3
102
- && c instanceof abaplint.Nodes.ExpressionNode
103
- && c.findDirectExpression(abaplint.Expressions.Constant) === undefined) {
104
- ret += " '\" + " + new expressions_1.SimpleSource3Transpiler(true).transpile(c, traversal).getCode() + " + \"'";
102
+ if (c instanceof abaplint.Nodes.ExpressionNode
103
+ && c.get() instanceof abaplint.Expressions.SQLCompare) {
104
+ if (ret !== "") {
105
+ ret += " ";
106
+ }
107
+ if (c.findDirectExpression(abaplint.Expressions.Dynamic)) {
108
+ const chain = (_a = c.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.FieldChain);
109
+ if (chain) {
110
+ const code = new expressions_1.FieldChainTranspiler(true).transpile(chain, traversal).getCode();
111
+ ret += `" + ${code} + "`;
112
+ }
113
+ else {
114
+ throw new Error("SQL Condition, transpiler todo, dyn cond, " + c.concatTokens());
115
+ }
116
+ }
117
+ else if (c.findDirectExpression(abaplint.Expressions.SQLIn)) {
118
+ ret += this.sqlIn(c, traversal);
119
+ }
120
+ else {
121
+ ret += this.basicCondition(c, traversal);
122
+ }
105
123
  }
106
124
  else if (c instanceof abaplint.Nodes.ExpressionNode) {
107
125
  ret += " " + this.concatCond(c, traversal);
@@ -112,6 +130,37 @@ class SelectTranspiler {
112
130
  }
113
131
  return ret.trim();
114
132
  }
133
+ sqlIn(c, _traversal) {
134
+ const fieldName = c.findDirectExpression(abaplint.Expressions.SQLFieldName);
135
+ const slqin = c.findDirectExpression(abaplint.Expressions.SQLIn);
136
+ const source = c.findFirstExpression(abaplint.Expressions.SimpleSource3);
137
+ if (fieldName === undefined || slqin === undefined || source === undefined) {
138
+ throw new Error("SQL Condition, transpiler todo, " + c.concatTokens());
139
+ }
140
+ const ret = `" + abap.expandIN("${fieldName.concatTokens()}", ${source.concatTokens()}) + "`;
141
+ return ret;
142
+ }
143
+ basicCondition(c, traversal) {
144
+ let ret = "";
145
+ if (c.getChildren().length !== 3) {
146
+ throw new Error("SQL Condition, transpiler todo, " + c.concatTokens() + ", " + c.getChildren().length);
147
+ }
148
+ const fieldName = c.findDirectExpression(abaplint.Expressions.SQLFieldName);
149
+ const operator = c.findDirectExpression(abaplint.Expressions.SQLCompareOperator);
150
+ const source = c.findDirectExpression(abaplint.Expressions.SQLSource);
151
+ if (fieldName === undefined || operator === undefined || source === undefined) {
152
+ throw new Error("SQL Condition, transpiler todo, " + c.concatTokens());
153
+ }
154
+ ret += fieldName.concatTokens() + " " + operator.concatTokens() + " ";
155
+ const simple = source.findDirectExpression(abaplint.Expressions.SimpleSource3);
156
+ if (simple && simple.findDirectExpression(abaplint.Expressions.Constant) === undefined) {
157
+ ret += "'\" + " + new expressions_1.SimpleSource3Transpiler(true).transpile(simple, traversal).getCode() + " + \"'";
158
+ }
159
+ else {
160
+ ret += source.concatTokens();
161
+ }
162
+ return ret;
163
+ }
115
164
  isWhereExpression(node, expression) {
116
165
  // check if previous token before sqlCond is "WHERE". It could also be "ON" in case of join condition
117
166
  let prevToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.1.44",
3
+ "version": "2.1.47",
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.6",
31
+ "@abaplint/core": "^2.93.8",
32
32
  "source-map": "^0.7.4"
33
33
  },
34
34
  "devDependencies": {