@abaplint/transpiler 2.1.85 → 2.1.87
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/statements/check.d.ts +0 -1
- package/build/src/statements/check.js +1 -23
- package/build/src/statements/exit.js +7 -1
- package/build/src/traversal.d.ts +1 -0
- package/build/src/traversal.js +23 -2
- package/build/src/unit_test.d.ts +1 -0
- package/build/src/unit_test.js +17 -2
- package/build/src/validation.js +6 -4
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ class CheckTranspiler {
|
|
|
11
11
|
ret.append("if (!(", node, traversal);
|
|
12
12
|
ret.appendChunk(cond);
|
|
13
13
|
ret.appendString(")) {\n");
|
|
14
|
-
if (
|
|
14
|
+
if (traversal.isInsideLoop(node)) {
|
|
15
15
|
ret.appendString("continue;");
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
@@ -20,28 +20,6 @@ class CheckTranspiler {
|
|
|
20
20
|
ret.append("\n}", node.getLastToken(), traversal);
|
|
21
21
|
return ret;
|
|
22
22
|
}
|
|
23
|
-
isInsideLoop(node, traversal) {
|
|
24
|
-
const stack = [];
|
|
25
|
-
for (const statement of traversal.getFile().getStatements()) {
|
|
26
|
-
const get = statement.get();
|
|
27
|
-
if (get instanceof abaplint.Statements.Loop
|
|
28
|
-
|| get instanceof abaplint.Statements.While
|
|
29
|
-
|| get instanceof abaplint.Statements.SelectLoop
|
|
30
|
-
|| get instanceof abaplint.Statements.Do) {
|
|
31
|
-
stack.push(statement);
|
|
32
|
-
}
|
|
33
|
-
else if (get instanceof abaplint.Statements.EndLoop
|
|
34
|
-
|| get instanceof abaplint.Statements.EndWhile
|
|
35
|
-
|| get instanceof abaplint.Statements.EndSelect
|
|
36
|
-
|| get instanceof abaplint.Statements.EndDo) {
|
|
37
|
-
stack.pop();
|
|
38
|
-
}
|
|
39
|
-
if (statement === node) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return stack.length > 0;
|
|
44
|
-
}
|
|
45
23
|
}
|
|
46
24
|
exports.CheckTranspiler = CheckTranspiler;
|
|
47
25
|
//# sourceMappingURL=check.js.map
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExitTranspiler = void 0;
|
|
4
4
|
const chunk_1 = require("../chunk");
|
|
5
|
+
const return_1 = require("./return");
|
|
5
6
|
class ExitTranspiler {
|
|
6
7
|
transpile(node, traversal) {
|
|
7
|
-
|
|
8
|
+
if (traversal.isInsideLoop(node)) {
|
|
9
|
+
return new chunk_1.Chunk().append("break;", node, traversal);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return new return_1.ReturnTranspiler().transpile(node, traversal);
|
|
13
|
+
}
|
|
8
14
|
}
|
|
9
15
|
}
|
|
10
16
|
exports.ExitTranspiler = ExitTranspiler;
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare class Traversal {
|
|
|
37
37
|
findClassDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IClassDefinition | undefined;
|
|
38
38
|
private dataFromInterfaces;
|
|
39
39
|
determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
40
|
+
isInsideLoop(node: abaplint.Nodes.StatementNode): boolean;
|
|
40
41
|
registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
|
|
41
42
|
lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
|
|
42
43
|
private buildPrefix;
|
package/build/src/traversal.js
CHANGED
|
@@ -271,7 +271,7 @@ class Traversal {
|
|
|
271
271
|
}
|
|
272
272
|
// handle aliases after initialization of carrier variables
|
|
273
273
|
for (const a of def.getAliases().getAll()) {
|
|
274
|
-
ret += "this." + a.getName().toLowerCase() + " = this." + a.getComponent().replace("~", "$").toLowerCase() + ";\n";
|
|
274
|
+
ret += "this." + a.getName().toLowerCase() + " = this." + Traversal.escapeClassName(a.getComponent().replace("~", "$").toLowerCase()) + ";\n";
|
|
275
275
|
}
|
|
276
276
|
// constants can be accessed both statically and via reference
|
|
277
277
|
for (const c of def.getAttributes().getConstants()) {
|
|
@@ -350,7 +350,28 @@ class Traversal {
|
|
|
350
350
|
}
|
|
351
351
|
return context;
|
|
352
352
|
}
|
|
353
|
-
|
|
353
|
+
isInsideLoop(node) {
|
|
354
|
+
const stack = [];
|
|
355
|
+
for (const statement of this.getFile().getStatements()) {
|
|
356
|
+
const get = statement.get();
|
|
357
|
+
if (get instanceof abaplint.Statements.Loop
|
|
358
|
+
|| get instanceof abaplint.Statements.While
|
|
359
|
+
|| get instanceof abaplint.Statements.SelectLoop
|
|
360
|
+
|| get instanceof abaplint.Statements.Do) {
|
|
361
|
+
stack.push(statement);
|
|
362
|
+
}
|
|
363
|
+
else if (get instanceof abaplint.Statements.EndLoop
|
|
364
|
+
|| get instanceof abaplint.Statements.EndWhile
|
|
365
|
+
|| get instanceof abaplint.Statements.EndSelect
|
|
366
|
+
|| get instanceof abaplint.Statements.EndDo) {
|
|
367
|
+
stack.pop();
|
|
368
|
+
}
|
|
369
|
+
if (statement === node) {
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return stack.length > 0;
|
|
374
|
+
}
|
|
354
375
|
registerClassOrInterface(def) {
|
|
355
376
|
if (def === undefined) {
|
|
356
377
|
return "";
|
package/build/src/unit_test.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare class UnitTest {
|
|
|
11
11
|
unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
|
|
12
12
|
unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
|
|
13
13
|
private buildImports;
|
|
14
|
+
private hasClassConstructor;
|
|
14
15
|
}
|
package/build/src/unit_test.js
CHANGED
|
@@ -181,7 +181,6 @@ run().then(() => {
|
|
|
181
181
|
buildImports(reg, useImport) {
|
|
182
182
|
// note: ES modules are hoised, so use the dynamic import(), due to setting of globalThis.abap
|
|
183
183
|
// some sorting required: eg. a class constructor using constant from interface
|
|
184
|
-
var _a;
|
|
185
184
|
const list = [];
|
|
186
185
|
const late = [];
|
|
187
186
|
const imp = (filename) => {
|
|
@@ -207,7 +206,7 @@ run().then(() => {
|
|
|
207
206
|
}
|
|
208
207
|
else if (obj instanceof abaplint.Objects.Class) {
|
|
209
208
|
if (obj.getName().toUpperCase() !== "CL_ABAP_CHAR_UTILITIES"
|
|
210
|
-
&& (
|
|
209
|
+
&& this.hasClassConstructor(reg, obj)) {
|
|
211
210
|
// this will not solve all problems with class constors 100%, but probably good enough
|
|
212
211
|
late.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
|
|
213
212
|
}
|
|
@@ -221,6 +220,22 @@ run().then(() => {
|
|
|
221
220
|
}
|
|
222
221
|
return [...list.sort(), ...late].join("\n");
|
|
223
222
|
}
|
|
223
|
+
// class constructors might make early use of eg. constants from interfaces
|
|
224
|
+
// sub classes will import() super classes and trigger a class constructor of the super
|
|
225
|
+
hasClassConstructor(reg, clas) {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
if (((_a = clas.getDefinition()) === null || _a === void 0 ? void 0 : _a.getMethodDefinitions().getByName("CLASS_CONSTRUCTOR")) !== undefined) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
const sup = (_b = clas.getDefinition()) === null || _b === void 0 ? void 0 : _b.getSuperClass();
|
|
231
|
+
if (sup !== undefined) {
|
|
232
|
+
const superClass = reg.getObject("CLAS", sup);
|
|
233
|
+
if (superClass) {
|
|
234
|
+
return this.hasClassConstructor(reg, superClass);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
224
239
|
}
|
|
225
240
|
exports.UnitTest = UnitTest;
|
|
226
241
|
//# sourceMappingURL=unit_test.js.map
|
package/build/src/validation.js
CHANGED
|
@@ -30,10 +30,12 @@ exports.config = {
|
|
|
30
30
|
"allowed_object_types": {
|
|
31
31
|
"allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "XSLT", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
|
|
32
32
|
},
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
/*
|
|
34
|
+
"exit_or_check": {
|
|
35
|
+
"allowCheck": true,
|
|
36
|
+
"allowExit": false,
|
|
37
|
+
},
|
|
38
|
+
*/
|
|
37
39
|
"unknown_types": true,
|
|
38
40
|
"ambiguous_statement": true,
|
|
39
41
|
"implement_methods": true,
|