@abaplint/transpiler 2.13.26 → 2.13.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.
|
@@ -21,7 +21,7 @@ class SQLCondTranspiler {
|
|
|
21
21
|
if (c.findDirectExpression(abaplint.Expressions.Dynamic)) {
|
|
22
22
|
const chain = c.findDirectExpression(abaplint.Expressions.Dynamic)?.findFirstExpression(abaplint.Expressions.FieldChain);
|
|
23
23
|
if (chain) {
|
|
24
|
-
const code = new field_chain_1.FieldChainTranspiler(
|
|
24
|
+
const code = new field_chain_1.FieldChainTranspiler(false).transpile(chain, traversal).getCode();
|
|
25
25
|
ret += `" + abap.expandDynamic(${code}, (name) => {try { return eval(name);} catch {}}) + "`;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
@@ -5,5 +5,7 @@ import { Chunk } from "../chunk";
|
|
|
5
5
|
export declare class SelectTranspiler implements IStatementTranspiler {
|
|
6
6
|
transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal, targetOverride?: string): Chunk;
|
|
7
7
|
private findTable;
|
|
8
|
+
private dynamicSelectList;
|
|
9
|
+
private dynamicSQLClause;
|
|
8
10
|
private isWhereExpression;
|
|
9
11
|
}
|
|
@@ -75,12 +75,29 @@ class SelectTranspiler {
|
|
|
75
75
|
if (orderBy) {
|
|
76
76
|
select += new expressions_1.SQLOrderByTranspiler().transpile(orderBy, traversal).getCode();
|
|
77
77
|
}
|
|
78
|
+
const fieldListDynamics = new Set(fieldList.findAllExpressionsRecursive(abaplint.Expressions.Dynamic));
|
|
79
|
+
const groupByDynamics = new Set(groupBy?.findAllExpressionsRecursive(abaplint.Expressions.Dynamic) || []);
|
|
80
|
+
const orderByDynamics = new Set(orderBy?.findAllExpressionsRecursive(abaplint.Expressions.Dynamic) || []);
|
|
78
81
|
for (const d of node.findAllExpressionsRecursive(abaplint.Expressions.Dynamic)) {
|
|
79
82
|
const chain = d.findFirstExpression(abaplint.Expressions.FieldChain);
|
|
80
83
|
if (chain) {
|
|
81
|
-
const code = new expressions_1.FieldChainTranspiler(true).transpile(chain, traversal).getCode();
|
|
82
84
|
const search = d.concatTokens();
|
|
83
|
-
|
|
85
|
+
if (fieldListDynamics.has(d)) {
|
|
86
|
+
const code = new expressions_1.FieldChainTranspiler(false).transpile(chain, traversal).getCode();
|
|
87
|
+
select = select.replace(search, `" + ${this.dynamicSelectList(code)} + "`);
|
|
88
|
+
}
|
|
89
|
+
else if (groupByDynamics.has(d)) {
|
|
90
|
+
const code = new expressions_1.FieldChainTranspiler(false).transpile(chain, traversal).getCode();
|
|
91
|
+
select = select.replace("GROUP BY " + search, `" + ${this.dynamicSQLClause("GROUP BY", code)} + "`);
|
|
92
|
+
}
|
|
93
|
+
else if (orderByDynamics.has(d)) {
|
|
94
|
+
const code = new expressions_1.FieldChainTranspiler(false).transpile(chain, traversal).getCode();
|
|
95
|
+
select = select.replace("ORDER BY " + search, `" + ${this.dynamicSQLClause("ORDER BY", code)} + "`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const code = new expressions_1.FieldChainTranspiler(true).transpile(chain, traversal).getCode();
|
|
99
|
+
select = select.replace(search, `" + ${code} + "`);
|
|
100
|
+
}
|
|
84
101
|
}
|
|
85
102
|
}
|
|
86
103
|
const concat = node.concatTokens().toUpperCase();
|
|
@@ -142,6 +159,16 @@ class SelectTranspiler {
|
|
|
142
159
|
}
|
|
143
160
|
return { table: tabl, keys };
|
|
144
161
|
}
|
|
162
|
+
dynamicSelectList(code) {
|
|
163
|
+
return `(${code} instanceof abap.types.Table || ${code} instanceof abap.types.HashedTable`
|
|
164
|
+
+ ` ? (${code}.array().length === 0 ? "*" : ${code}.array().map(row => row.get()).join(", "))`
|
|
165
|
+
+ ` : ${code}.get())`;
|
|
166
|
+
}
|
|
167
|
+
dynamicSQLClause(keyword, code) {
|
|
168
|
+
return `(${code} instanceof abap.types.Table || ${code} instanceof abap.types.HashedTable`
|
|
169
|
+
+ ` ? (${code}.array().length === 0 ? "" : "${keyword} " + ${code}.array().map(row => row.get()).join(" "))`
|
|
170
|
+
+ ` : "${keyword} " + ${code}.get())`;
|
|
171
|
+
}
|
|
145
172
|
isWhereExpression(node, expression) {
|
|
146
173
|
// check if previous token before sqlCond is "WHERE". It could also be "ON" in case of join condition
|
|
147
174
|
let prevToken;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.28",
|
|
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.119.
|
|
32
|
+
"@abaplint/core": "^2.119.24",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|