@abaplint/transpiler 1.6.69 → 1.7.0

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.
@@ -5,22 +5,38 @@ const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
6
  class EndMethodTranspiler {
7
7
  transpile(node, traversal) {
8
+ var _a, _b;
8
9
  const token = node.getFirstToken();
9
10
  const scope = traversal.findCurrentScopeByToken(token);
10
11
  if (scope === undefined) {
11
12
  throw new Error("EndMethodTranspiler, scope not found");
12
13
  }
13
14
  let returning = "";
15
+ let methodName = undefined;
16
+ if ((scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype) === abaplint.ScopeType.Method) {
17
+ methodName = scope === null || scope === void 0 ? void 0 : scope.getIdentifier().sname;
18
+ }
19
+ let className = undefined;
20
+ if (((_a = scope === null || scope === void 0 ? void 0 : scope.getParent()) === null || _a === void 0 ? void 0 : _a.getIdentifier().stype) === abaplint.ScopeType.ClassImplementation) {
21
+ className = (_b = scope === null || scope === void 0 ? void 0 : scope.getParent()) === null || _b === void 0 ? void 0 : _b.getIdentifier().sname;
22
+ }
23
+ if (methodName && className) {
24
+ const classDef = scope.findClassDefinition(className);
25
+ const methodDef = classDef === null || classDef === void 0 ? void 0 : classDef.getMethodDefinitions().getByName(methodName);
26
+ if (methodDef && methodDef.getExceptions().length > 0) {
27
+ returning += "abap.builtin.sy.get().subrc.set(0);\n";
28
+ }
29
+ }
14
30
  const vars = scope.getData().vars;
15
31
  for (const n in vars) {
16
32
  const identifier = vars[n];
17
33
  if (identifier.getMeta().includes("returning" /* MethodReturning */)) {
18
- returning = "return " + n.toLowerCase() + ";\n";
34
+ returning += "return " + n.toLowerCase() + ";\n";
19
35
  }
20
36
  }
21
37
  const data = scope.getIdentifier();
22
38
  if (data.stype === abaplint.ScopeType.Method && data.sname.toLowerCase() === "constructor") {
23
- returning = "return this;\n";
39
+ returning += "return this;\n";
24
40
  }
25
41
  return new chunk_1.Chunk().append(returning + "}", node, traversal);
26
42
  }
@@ -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): any | undefined;
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;
@@ -32,7 +32,7 @@ export declare class Traversal {
32
32
  private findReadOrWriteReference;
33
33
  buildConstructorContents(scope: abaplint.ISpaghettiScopeNode | undefined, def: abaplint.IClassDefinition, inputName: string): string;
34
34
  determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
35
- registerClassOrInterface(def: abaplint.IClassDefinition | undefined): string;
35
+ registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
36
36
  lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined): string;
37
37
  private buildPrefix;
38
38
  protected traverseStructure(node: abaplint.Nodes.StructureNode): Chunk;
@@ -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.ClassImplementation) {
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 cla = this.isStaticClassAttribute(t);
130
- if (cla) {
131
- name = cla + "." + 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
- return (_a = scope.getParent()) === null || _a === void 0 ? void 0 : _a.getIdentifier().sname.toLowerCase();
159
+ // console.dir(found.sname);
160
+ return found.sname.toLowerCase();
158
161
  }
159
162
  return undefined;
160
163
  }
@@ -243,34 +246,60 @@ class Traversal {
243
246
  return undefined;
244
247
  }
245
248
  buildConstructorContents(scope, def, inputName) {
246
- const vars = scope === null || scope === void 0 ? void 0 : scope.getData().vars;
249
+ var _a;
250
+ /*
251
+ const vars = scope?.getData().vars;
247
252
  if (vars === undefined || Object.keys(vars).length === 0) {
248
- return "";
253
+ return "";
249
254
  }
255
+ */
250
256
  let ret = "";
251
257
  if (def.getSuperClass() !== undefined) {
252
258
  // todo, more here, there might be parameters to pass
253
259
  // for now just pass the same input
254
260
  ret += `await super.constructor_(${inputName});\n`;
255
261
  }
262
+ /*
256
263
  for (const n in vars) {
257
- const identifier = vars[n];
258
- if (identifier.getMeta().includes("static" /* Static */) === true) {
264
+ const identifier = vars[n];
265
+ if (identifier.getMeta().includes(abaplint.IdentifierMeta.Static) === true) {
266
+ continue;
267
+ }
268
+ const name = n.toLowerCase().replace("~", "$");
269
+ if (name === "super") {
270
+ continue; // todo, https://github.com/abaplint/transpiler/issues/133
271
+ }
272
+
273
+ // todo, better handling of variables from interfaces, it should only initialize those that are directly implemented
274
+ if (def.getAttributes().findByName(name) === undefined
275
+ && name.includes("$") === false
276
+ && name !== "me") {
277
+ continue;
278
+ }
279
+
280
+ ret += "this." + name + " = " + new TranspileTypes().toType(identifier.getType()) + ";\n";
281
+ if (name === "me") {
282
+ ret += "this.me.set(this);\n";
283
+ }
284
+ }
285
+ */
286
+ ret += "this.me = new abap.types.ABAPObject();\n";
287
+ ret += "this.me.set(this);\n";
288
+ for (const a of def.getAttributes().getAll()) {
289
+ if (a.getMeta().includes("static" /* Static */) === true) {
259
290
  continue;
260
291
  }
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") {
269
- continue;
270
- }
271
- ret += "this." + name + " = " + new types_1.TranspileTypes().toType(identifier.getType()) + ";\n";
272
- if (name === "me") {
273
- ret += "this.me.set(this);\n";
292
+ const name = a.getName().toLowerCase();
293
+ ret += "this." + name + " = " + new types_1.TranspileTypes().toType(a.getType()) + ";\n";
294
+ }
295
+ // attributes from directly implemented interfaces(not interfaces implemented in super classes)
296
+ for (const i of def.getImplementing()) {
297
+ for (const a of ((_a = scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(i.name)) === null || _a === void 0 ? void 0 : _a.getAttributes().getAll()) || []) {
298
+ if (a.getMeta().includes("static" /* Static */) === true) {
299
+ continue;
300
+ }
301
+ const name = i.name.toLowerCase() + "$" + a.getName().toLowerCase();
302
+ ret += "this." + name + " = " + new types_1.TranspileTypes().toType(a.getType()) + ";\n";
274
303
  }
275
304
  }
276
305
  // handle aliases after initialization of carrier variables
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "1.6.69",
3
+ "version": "1.7.0",
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": "=2.80.10",
30
+ "@abaplint/core": "^2.83.16",
30
31
  "source-map": "^0.7.3"
31
32
  },
32
33
  "devDependencies": {