@abaplint/transpiler 2.13.66 → 2.13.68
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.
- package/build/src/expressions/sql_cond.d.ts +3 -0
- package/build/src/expressions/sql_cond.js +72 -2
- package/build/src/structures/catch_system_exceptions.d.ts +7 -0
- package/build/src/structures/catch_system_exceptions.js +11 -0
- package/build/src/structures/index.d.ts +1 -0
- package/build/src/structures/index.js +1 -0
- package/package.json +1 -1
|
@@ -7,6 +7,9 @@ export declare class SQLCondTranspiler implements IExpressionTranspiler {
|
|
|
7
7
|
transpile(node: Nodes.ExpressionNode, traversal: Traversal, table?: abaplint.Objects.Table | undefined): Chunk;
|
|
8
8
|
private sqlIn;
|
|
9
9
|
private basicCondition;
|
|
10
|
+
private subselectCondition;
|
|
11
|
+
private findSubselect;
|
|
12
|
+
private sqlSubselect;
|
|
10
13
|
private sqlSource;
|
|
11
14
|
private basicConditionNew;
|
|
12
15
|
private sourceWithComponents;
|
|
@@ -42,6 +42,8 @@ const field_chain_1 = require("./field_chain");
|
|
|
42
42
|
const sql_field_name_1 = require("./sql_field_name");
|
|
43
43
|
const transpile_types_1 = require("../transpile_types");
|
|
44
44
|
const source_1 = require("./source");
|
|
45
|
+
const sql_field_list_1 = require("./sql_field_list");
|
|
46
|
+
const sql_from_1 = require("./sql_from");
|
|
45
47
|
class SQLCondTranspiler {
|
|
46
48
|
transpile(node, traversal, table) {
|
|
47
49
|
let ret = "";
|
|
@@ -71,6 +73,9 @@ class SQLCondTranspiler {
|
|
|
71
73
|
else if (c.findDirectExpression(abaplint.Expressions.SQLIn)) {
|
|
72
74
|
ret += this.sqlIn(c, traversal, traversal.getFilename(), table);
|
|
73
75
|
}
|
|
76
|
+
else if (this.findSubselect(c)) {
|
|
77
|
+
ret += this.subselectCondition(c, traversal, table);
|
|
78
|
+
}
|
|
74
79
|
else {
|
|
75
80
|
ret += this.basicCondition(c, traversal, traversal.getFilename(), table);
|
|
76
81
|
}
|
|
@@ -89,14 +94,22 @@ class SQLCondTranspiler {
|
|
|
89
94
|
const fieldName = c.findDirectExpression(abaplint.Expressions.SQLFieldName)
|
|
90
95
|
|| c.findDirectExpression(abaplint.Expressions.SQLAliasField);
|
|
91
96
|
const sqlin = c.findDirectExpression(abaplint.Expressions.SQLIn);
|
|
92
|
-
const
|
|
93
|
-
if (fieldName === undefined || sqlin === undefined
|
|
97
|
+
const subselect = sqlin === undefined ? undefined : this.findSubselect(sqlin);
|
|
98
|
+
if (fieldName === undefined || sqlin === undefined) {
|
|
94
99
|
throw new Error("SQL Condition, transpiler todo, " + c.concatTokens());
|
|
95
100
|
}
|
|
96
101
|
let pre = "";
|
|
97
102
|
if (c.concatTokens().toUpperCase().includes(" NOT IN ")) {
|
|
98
103
|
pre = "NOT ";
|
|
99
104
|
}
|
|
105
|
+
if (subselect) {
|
|
106
|
+
const field = new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldName, traversal).getCode();
|
|
107
|
+
return `${field} ${pre}IN ${this.sqlSubselect(subselect, traversal, table)}`;
|
|
108
|
+
}
|
|
109
|
+
const source = c.findFirstExpression(abaplint.Expressions.SimpleSource3);
|
|
110
|
+
if (source === undefined) {
|
|
111
|
+
throw new Error("SQL Condition, transpiler todo, " + c.concatTokens());
|
|
112
|
+
}
|
|
100
113
|
if (sqlin.getChildren().length === 2) {
|
|
101
114
|
const s = new source_1.SourceTranspiler().transpile(source, traversal).getCode();
|
|
102
115
|
return `${pre}" + abap.expandIN("${fieldName.concatTokens()}", ${s}) + "`;
|
|
@@ -114,6 +127,10 @@ class SQLCondTranspiler {
|
|
|
114
127
|
}
|
|
115
128
|
basicCondition(c, traversal, filename, table) {
|
|
116
129
|
let ret = "";
|
|
130
|
+
const subselect = this.findSubselect(c);
|
|
131
|
+
if (subselect) {
|
|
132
|
+
return this.subselectCondition(c, traversal, table);
|
|
133
|
+
}
|
|
117
134
|
if (c.getChildren().length !== 3) {
|
|
118
135
|
return this.basicConditionNew(c, traversal, filename, table);
|
|
119
136
|
}
|
|
@@ -142,6 +159,59 @@ class SQLCondTranspiler {
|
|
|
142
159
|
ret += this.sqlSource(source, traversal, filename, table);
|
|
143
160
|
return ret;
|
|
144
161
|
}
|
|
162
|
+
subselectCondition(c, traversal, table) {
|
|
163
|
+
const subselect = this.findSubselect(c);
|
|
164
|
+
if (subselect === undefined) {
|
|
165
|
+
throw new Error("SQL Condition, subselect not found, " + c.concatTokens());
|
|
166
|
+
}
|
|
167
|
+
const fieldNameExpression = c.findDirectExpression(abaplint.Expressions.SQLFieldName)
|
|
168
|
+
|| c.findDirectExpression(abaplint.Expressions.SQLAliasField);
|
|
169
|
+
const operator = c.findDirectExpression(abaplint.Expressions.SQLCompareOperator);
|
|
170
|
+
if (fieldNameExpression && operator) {
|
|
171
|
+
const fieldName = new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldNameExpression, traversal).getCode();
|
|
172
|
+
const quantifier = c.getChildren().find(child => child instanceof abaplint.Nodes.TokenNode
|
|
173
|
+
&& ["ALL", "ANY", "SOME"].includes(child.getFirstToken().getStr().toUpperCase()));
|
|
174
|
+
const suffix = quantifier ? " " + quantifier.concatTokens() : "";
|
|
175
|
+
return `${fieldName} ${this.sqlOperator(operator.concatTokens())}${suffix} ${this.sqlSubselect(subselect, traversal, table)}`;
|
|
176
|
+
}
|
|
177
|
+
if (c.findDirectTokenByText("EXISTS")) {
|
|
178
|
+
const not = c.findDirectTokenByText("NOT") ? "NOT " : "";
|
|
179
|
+
return `${not}EXISTS ${this.sqlSubselect(subselect, traversal, table)}`;
|
|
180
|
+
}
|
|
181
|
+
throw new Error("SQL Condition, unsupported subselect, " + c.concatTokens());
|
|
182
|
+
}
|
|
183
|
+
findSubselect(node) {
|
|
184
|
+
const grouped = node.findDirectExpression(abaplint.Expressions.SQLSetOpGroup);
|
|
185
|
+
if (grouped) {
|
|
186
|
+
return grouped;
|
|
187
|
+
}
|
|
188
|
+
// Older parser releases represent the scalar form as an inline sequence
|
|
189
|
+
// instead of wrapping it in SQLSetOpGroup.
|
|
190
|
+
if (node.getTokens().some(token => token.getStr().toUpperCase() === "SELECT")) {
|
|
191
|
+
return node;
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
sqlSubselect(node, traversal, table) {
|
|
196
|
+
const fieldList = node.findFirstExpression(abaplint.Expressions.SQLFieldList);
|
|
197
|
+
const from = node.findFirstExpression(abaplint.Expressions.SQLFrom);
|
|
198
|
+
if (fieldList === undefined || from === undefined) {
|
|
199
|
+
throw new Error("SQL Condition, malformed subselect, " + node.concatTokens());
|
|
200
|
+
}
|
|
201
|
+
const tokens = node.getTokens();
|
|
202
|
+
const selectIndex = tokens.findIndex(token => token.getStr().toUpperCase() === "SELECT");
|
|
203
|
+
const distinct = selectIndex >= 0 && tokens[selectIndex + 1]?.getStr().toUpperCase() === "DISTINCT";
|
|
204
|
+
let ret = `(SELECT${distinct ? " DISTINCT" : ""} `;
|
|
205
|
+
ret += new sql_field_list_1.SQLFieldListTranspiler().transpile(fieldList, traversal).getCode();
|
|
206
|
+
ret += " " + new sql_from_1.SQLFromTranspiler().transpile(from, traversal).getCode().trim();
|
|
207
|
+
const where = node.findFirstExpression(abaplint.Expressions.SQLCond);
|
|
208
|
+
if (where) {
|
|
209
|
+
const subTable = from.findFirstExpression(abaplint.Expressions.DatabaseTable);
|
|
210
|
+
const conditionTable = subTable ? traversal.findTable(subTable.concatTokens()) : table;
|
|
211
|
+
ret += " WHERE " + new SQLCondTranspiler().transpile(where, traversal, conditionTable).getCode();
|
|
212
|
+
}
|
|
213
|
+
return ret + ")";
|
|
214
|
+
}
|
|
145
215
|
sqlSource(source, traversal, filename, table) {
|
|
146
216
|
let ret = "";
|
|
147
217
|
const simple = source.findDirectExpression(abaplint.Expressions.SimpleSource3);
|
|
@@ -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 CatchSystemExceptionsTranspiler implements IStructureTranspiler {
|
|
6
|
+
transpile(node: abaplint.Nodes.StructureNode, traversal: Traversal): Chunk;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CatchSystemExceptionsTranspiler = void 0;
|
|
4
|
+
const chunk_1 = require("../chunk");
|
|
5
|
+
class CatchSystemExceptionsTranspiler {
|
|
6
|
+
transpile(node, traversal) {
|
|
7
|
+
return new chunk_1.Chunk().append(`throw new Error("CATCH SYSTEM-EXCEPTIONS, not supported, transpiler");`, node, traversal);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CatchSystemExceptionsTranspiler = CatchSystemExceptionsTranspiler;
|
|
11
|
+
//# sourceMappingURL=catch_system_exceptions.js.map
|
|
@@ -18,6 +18,7 @@ __exportStar(require("./at_first"), exports);
|
|
|
18
18
|
__exportStar(require("./at_last"), exports);
|
|
19
19
|
__exportStar(require("./case_type"), exports);
|
|
20
20
|
__exportStar(require("./case"), exports);
|
|
21
|
+
__exportStar(require("./catch_system_exceptions"), exports);
|
|
21
22
|
__exportStar(require("./class_definition"), exports);
|
|
22
23
|
__exportStar(require("./class_implementation"), exports);
|
|
23
24
|
__exportStar(require("./constants"), exports);
|