@abaplint/transpiler 1.6.69 → 1.7.3
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.
|
@@ -11,19 +11,48 @@ class EndMethodTranspiler {
|
|
|
11
11
|
throw new Error("EndMethodTranspiler, scope not found");
|
|
12
12
|
}
|
|
13
13
|
let returning = "";
|
|
14
|
+
returning += this.setSubrc(scope, traversal);
|
|
14
15
|
const vars = scope.getData().vars;
|
|
15
16
|
for (const n in vars) {
|
|
16
17
|
const identifier = vars[n];
|
|
17
18
|
if (identifier.getMeta().includes("returning" /* MethodReturning */)) {
|
|
18
|
-
returning
|
|
19
|
+
returning += "return " + n.toLowerCase() + ";\n";
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
const data = scope.getIdentifier();
|
|
22
23
|
if (data.stype === abaplint.ScopeType.Method && data.sname.toLowerCase() === "constructor") {
|
|
23
|
-
returning
|
|
24
|
+
returning += "return this;\n";
|
|
24
25
|
}
|
|
25
26
|
return new chunk_1.Chunk().append(returning + "}", node, traversal);
|
|
26
27
|
}
|
|
28
|
+
setSubrc(scope, traversal) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
let methodName = undefined;
|
|
31
|
+
if ((scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype) === abaplint.ScopeType.Method) {
|
|
32
|
+
methodName = scope === null || scope === void 0 ? void 0 : scope.getIdentifier().sname;
|
|
33
|
+
}
|
|
34
|
+
let className = undefined;
|
|
35
|
+
if (((_a = scope === null || scope === void 0 ? void 0 : scope.getParent()) === null || _a === void 0 ? void 0 : _a.getIdentifier().stype) === abaplint.ScopeType.ClassImplementation) {
|
|
36
|
+
className = (_b = scope === null || scope === void 0 ? void 0 : scope.getParent()) === null || _b === void 0 ? void 0 : _b.getIdentifier().sname;
|
|
37
|
+
}
|
|
38
|
+
if (methodName === undefined || className === undefined) {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
let methodDef = undefined;
|
|
42
|
+
if (methodName.includes("~")) {
|
|
43
|
+
const split = methodName.split("~");
|
|
44
|
+
const classDef = traversal.findInterfaceDefinition(split[0], scope);
|
|
45
|
+
methodDef = classDef === null || classDef === void 0 ? void 0 : classDef.getMethodDefinitions().getByName(split[1]);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const classDef = traversal.findClassDefinition(className, scope);
|
|
49
|
+
methodDef = classDef === null || classDef === void 0 ? void 0 : classDef.getMethodDefinitions().getByName(methodName);
|
|
50
|
+
}
|
|
51
|
+
if (methodDef && methodDef.getExceptions().length > 0) {
|
|
52
|
+
return "abap.builtin.sy.get().subrc.set(0);\n";
|
|
53
|
+
}
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
27
56
|
}
|
|
28
57
|
exports.EndMethodTranspiler = EndMethodTranspiler;
|
|
29
58
|
//# sourceMappingURL=end_method.js.map
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class Traversal {
|
|
|
17
17
|
findStatementInFile(pos: abaplint.Position): abaplint.Nodes.StatementNode | undefined;
|
|
18
18
|
private scopeCache;
|
|
19
19
|
findCurrentScopeByToken(token: abaplint.Token): abaplint.ISpaghettiScopeNode | undefined;
|
|
20
|
-
getInterfaceDefinition(token: abaplint.Token):
|
|
20
|
+
getInterfaceDefinition(token: abaplint.Token): abaplint.IInterfaceDefinition | undefined;
|
|
21
21
|
getClassDefinition(token: abaplint.Token): abaplint.IClassDefinition | undefined;
|
|
22
22
|
private isClassAttribute;
|
|
23
23
|
prefixAndName(t: abaplint.Token, filename?: string): string;
|
|
@@ -31,8 +31,11 @@ export declare class Traversal {
|
|
|
31
31
|
isInterfaceAttribute(token: abaplint.Token): string | undefined;
|
|
32
32
|
private findReadOrWriteReference;
|
|
33
33
|
buildConstructorContents(scope: abaplint.ISpaghettiScopeNode | undefined, def: abaplint.IClassDefinition, inputName: string): string;
|
|
34
|
+
findInterfaceDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IInterfaceDefinition | undefined;
|
|
35
|
+
findClassDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IClassDefinition | undefined;
|
|
36
|
+
private dataFromInterfaces;
|
|
34
37
|
determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
35
|
-
registerClassOrInterface(def: abaplint.IClassDefinition | undefined): string;
|
|
38
|
+
registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
|
|
36
39
|
lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined): string;
|
|
37
40
|
private buildPrefix;
|
|
38
41
|
protected traverseStructure(node: abaplint.Nodes.StructureNode): Chunk;
|
package/build/src/traversal.js
CHANGED
|
@@ -75,7 +75,6 @@ class Traversal {
|
|
|
75
75
|
}
|
|
76
76
|
return node;
|
|
77
77
|
}
|
|
78
|
-
// todo, add explicit return type,
|
|
79
78
|
getInterfaceDefinition(token) {
|
|
80
79
|
let scope = this.findCurrentScopeByToken(token);
|
|
81
80
|
while (scope !== undefined) {
|
|
@@ -103,8 +102,12 @@ class Traversal {
|
|
|
103
102
|
throw new Error("isClassAttribute, unable to lookup position");
|
|
104
103
|
}
|
|
105
104
|
const name = token.getStr();
|
|
105
|
+
if (name.toLowerCase() === "me") {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
106
108
|
const found = scope.findScopeForVariable(name);
|
|
107
|
-
if (found && found.stype === abaplint.ScopeType.
|
|
109
|
+
if (found && (found.stype === abaplint.ScopeType.MethodInstance
|
|
110
|
+
|| found.stype === abaplint.ScopeType.ClassImplementation)) {
|
|
108
111
|
return true;
|
|
109
112
|
}
|
|
110
113
|
return false;
|
|
@@ -126,9 +129,9 @@ class Traversal {
|
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
name =
|
|
132
|
+
const className = this.isStaticClassAttribute(t);
|
|
133
|
+
if (className) {
|
|
134
|
+
name = className + "." + name;
|
|
132
135
|
}
|
|
133
136
|
else if (name === "super") {
|
|
134
137
|
return name;
|
|
@@ -142,7 +145,6 @@ class Traversal {
|
|
|
142
145
|
return name;
|
|
143
146
|
}
|
|
144
147
|
isStaticClassAttribute(token) {
|
|
145
|
-
var _a;
|
|
146
148
|
const scope = this.findCurrentScopeByToken(token);
|
|
147
149
|
if (scope === undefined) {
|
|
148
150
|
throw new Error(`isStaticClassAttribute, unable to lookup position, ${token.getStr()},${token.getRow()},${token.getCol()},` +
|
|
@@ -154,7 +156,8 @@ class Traversal {
|
|
|
154
156
|
if (found && id
|
|
155
157
|
&& id.getMeta().includes("static" /* Static */)
|
|
156
158
|
&& found.stype === abaplint.ScopeType.ClassImplementation) {
|
|
157
|
-
|
|
159
|
+
// console.dir(found.sname);
|
|
160
|
+
return found.sname.toLowerCase();
|
|
158
161
|
}
|
|
159
162
|
return undefined;
|
|
160
163
|
}
|
|
@@ -243,35 +246,30 @@ class Traversal {
|
|
|
243
246
|
return undefined;
|
|
244
247
|
}
|
|
245
248
|
buildConstructorContents(scope, def, inputName) {
|
|
246
|
-
|
|
249
|
+
/*
|
|
250
|
+
const vars = scope?.getData().vars;
|
|
247
251
|
if (vars === undefined || Object.keys(vars).length === 0) {
|
|
248
|
-
|
|
252
|
+
return "";
|
|
249
253
|
}
|
|
254
|
+
*/
|
|
250
255
|
let ret = "";
|
|
251
256
|
if (def.getSuperClass() !== undefined) {
|
|
252
257
|
// todo, more here, there might be parameters to pass
|
|
253
258
|
// for now just pass the same input
|
|
254
259
|
ret += `await super.constructor_(${inputName});\n`;
|
|
255
260
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
const name = n.toLowerCase().replace("~", "$");
|
|
262
|
-
if (name === "super") {
|
|
263
|
-
continue; // todo, https://github.com/abaplint/transpiler/issues/133
|
|
264
|
-
}
|
|
265
|
-
// todo, better handling of variables from interfaces, it should only initialize those that are directly implemented
|
|
266
|
-
if (def.getAttributes().findByName(name) === undefined
|
|
267
|
-
&& name.includes("$") === false
|
|
268
|
-
&& name !== "me") {
|
|
261
|
+
ret += "this.me = new abap.types.ABAPObject();\n";
|
|
262
|
+
ret += "this.me.set(this);\n";
|
|
263
|
+
for (const a of def.getAttributes().getAll()) {
|
|
264
|
+
if (a.getMeta().includes("static" /* Static */) === true) {
|
|
269
265
|
continue;
|
|
270
266
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
267
|
+
const name = a.getName().toLowerCase();
|
|
268
|
+
ret += "this." + name + " = " + new types_1.TranspileTypes().toType(a.getType()) + ";\n";
|
|
269
|
+
}
|
|
270
|
+
// attributes from directly implemented interfaces(not interfaces implemented in super classes)
|
|
271
|
+
for (const i of def.getImplementing()) {
|
|
272
|
+
ret += this.dataFromInterfaces(i.name, scope);
|
|
275
273
|
}
|
|
276
274
|
// handle aliases after initialization of carrier variables
|
|
277
275
|
for (const a of def.getAliases().getAll()) {
|
|
@@ -283,6 +281,37 @@ class Traversal {
|
|
|
283
281
|
}
|
|
284
282
|
return ret;
|
|
285
283
|
}
|
|
284
|
+
findInterfaceDefinition(name, scope) {
|
|
285
|
+
let intf = scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(name);
|
|
286
|
+
if (intf === undefined) {
|
|
287
|
+
const iglobal = this.reg.getObject("INTF", name);
|
|
288
|
+
intf = iglobal === null || iglobal === void 0 ? void 0 : iglobal.getDefinition();
|
|
289
|
+
}
|
|
290
|
+
return intf;
|
|
291
|
+
}
|
|
292
|
+
findClassDefinition(name, scope) {
|
|
293
|
+
let clas = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name);
|
|
294
|
+
if (clas === undefined) {
|
|
295
|
+
const iglobal = this.reg.getObject("CLAS", name);
|
|
296
|
+
clas = iglobal === null || iglobal === void 0 ? void 0 : iglobal.getDefinition();
|
|
297
|
+
}
|
|
298
|
+
return clas;
|
|
299
|
+
}
|
|
300
|
+
dataFromInterfaces(name, scope) {
|
|
301
|
+
let ret = "";
|
|
302
|
+
const intf = this.findInterfaceDefinition(name, scope);
|
|
303
|
+
for (const a of (intf === null || intf === void 0 ? void 0 : intf.getAttributes().getAll()) || []) {
|
|
304
|
+
if (a.getMeta().includes("static" /* Static */) === true) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const n = name.toLowerCase() + "$" + a.getName().toLowerCase();
|
|
308
|
+
ret += "this." + n + " = " + new types_1.TranspileTypes().toType(a.getType()) + ";\n";
|
|
309
|
+
}
|
|
310
|
+
for (const i of (intf === null || intf === void 0 ? void 0 : intf.getImplementing()) || []) {
|
|
311
|
+
ret += this.dataFromInterfaces(i.name, scope);
|
|
312
|
+
}
|
|
313
|
+
return ret;
|
|
314
|
+
}
|
|
286
315
|
determineType(node, scope) {
|
|
287
316
|
var _a;
|
|
288
317
|
if (scope === undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"compile": "tsc",
|
|
13
|
+
"publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
13
14
|
"publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
|
|
14
15
|
"test": "npm run compile && mocha"
|
|
15
16
|
},
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"author": "abaplint",
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@abaplint/core": "
|
|
30
|
+
"@abaplint/core": "^2.83.17",
|
|
30
31
|
"source-map": "^0.7.3"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|