@abaplint/transpiler 2.13.99 → 2.13.100

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.
@@ -7,5 +7,6 @@ export declare class SelectTranspiler implements IStatementTranspiler {
7
7
  private findTable;
8
8
  private dynamicSelectList;
9
9
  private dynamicSQLClause;
10
+ private dynamicHavingClause;
10
11
  private isWhereExpression;
11
12
  }
@@ -105,8 +105,18 @@ class SelectTranspiler {
105
105
  const having = node.findDirectExpression(abaplint.Expressions.Select)
106
106
  ?.findDirectExpression(abaplint.Expressions.SQLHaving);
107
107
  const havingCond = having?.findFirstExpression(abaplint.Expressions.SQLCond);
108
+ let dynamicHaving;
108
109
  if (havingCond) {
109
- select += "HAVING " + new expressions_1.SQLCondTranspiler().transpile(havingCond, traversal, table).getCode() + " ";
110
+ const dynamic = havingCond.findFirstExpression(abaplint.Expressions.Dynamic);
111
+ const chain = dynamic?.findFirstExpression(abaplint.Expressions.FieldChain);
112
+ if (chain && havingCond.concatTokens() === dynamic?.concatTokens()) {
113
+ dynamicHaving = dynamic;
114
+ const code = new expressions_1.FieldChainTranspiler(false).transpile(chain, traversal).getCode();
115
+ select += `" + ${this.dynamicHavingClause(code)} + " `;
116
+ }
117
+ else {
118
+ select += "HAVING " + new expressions_1.SQLCondTranspiler().transpile(havingCond, traversal, table).getCode() + " ";
119
+ }
110
120
  }
111
121
  const upTo = node.findFirstExpression(abaplint.Expressions.SQLUpTo);
112
122
  if (upTo) {
@@ -126,6 +136,9 @@ class SelectTranspiler {
126
136
  const groupByDynamics = new Set(groupBy?.findAllExpressionsRecursive(abaplint.Expressions.Dynamic) || []);
127
137
  const orderByDynamics = new Set(orderBy?.findAllExpressionsRecursive(abaplint.Expressions.Dynamic) || []);
128
138
  for (const d of node.findAllExpressionsRecursive(abaplint.Expressions.Dynamic)) {
139
+ if (d === dynamicHaving) {
140
+ continue;
141
+ }
129
142
  const chain = d.findFirstExpression(abaplint.Expressions.FieldChain);
130
143
  if (chain) {
131
144
  const search = d.concatTokens();
@@ -282,6 +295,13 @@ abap.builtin.sy.get().dbcnt.set(${target}.getArrayLength());
282
295
  + ` ? (${code}.array().length === 0 ? "" : "${keyword} " + ${code}.array().map(row => row.get()).join(", "))`
283
296
  + ` : (("" + ${code}.get()).trim() === "" ? "" : "${keyword} " + ${code}.get()))`;
284
297
  }
298
+ dynamicHavingClause(code) {
299
+ return `((value) => {
300
+ const condition = value instanceof abap.types.Table || value instanceof abap.types.HashedTable
301
+ ? value.array().map(row => row.get()).join(" ") : value.get();
302
+ return condition.trim() === "" ? "" : "HAVING " + abap.expandDynamic(condition, (name) => {try { return eval(name);} catch {}});
303
+ })(${code})`;
304
+ }
285
305
  isWhereExpression(node, expression) {
286
306
  // check if previous token before sqlCond is "WHERE". It could also be "ON" in case of join condition
287
307
  let prevToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.13.99",
3
+ "version": "2.13.100",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "author": "abaplint",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@abaplint/core": "^2.120.68",
32
+ "@abaplint/core": "^2.120.69",
33
33
  "source-map": "^0.8.0"
34
34
  },
35
35
  "devDependencies": {