@abaplint/transpiler 1.6.67 → 1.7.1

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.
@@ -22,12 +22,15 @@ class ConstantTranspiler {
22
22
  str = node.findFirstExpression(core_1.Expressions.TextElementString);
23
23
  }
24
24
  if (str) {
25
- const res = str.getFirstToken().getStr();
25
+ let res = str.getFirstToken().getStr();
26
26
  if (res.startsWith("'") && this.addGet === false) {
27
27
  const code = "new abap.types.Character({length: " + (res.length - 2) + "}).set(" + this.escape(res) + ")";
28
28
  return new chunk_1.Chunk().append(code, node, traversal);
29
29
  }
30
30
  else {
31
+ if (res.startsWith("'")) {
32
+ res = "'" + res.substring(1, res.length - 1).trimEnd() + "'";
33
+ }
31
34
  const code = this.escape(res);
32
35
  return new chunk_1.Chunk().append(code, node, traversal);
33
36
  }
@@ -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,64 @@ 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
+ /*
250
+ const vars = scope?.getData().vars;
247
251
  if (vars === undefined || Object.keys(vars).length === 0) {
248
- return "";
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
  }
261
+ /*
256
262
  for (const n in vars) {
257
- const identifier = vars[n];
258
- if (identifier.getMeta().includes("static" /* Static */) === true) {
263
+ const identifier = vars[n];
264
+ if (identifier.getMeta().includes(abaplint.IdentifierMeta.Static) === true) {
265
+ continue;
266
+ }
267
+ const name = n.toLowerCase().replace("~", "$");
268
+ if (name === "super") {
269
+ continue; // todo, https://github.com/abaplint/transpiler/issues/133
270
+ }
271
+
272
+ // todo, better handling of variables from interfaces, it should only initialize those that are directly implemented
273
+ if (def.getAttributes().findByName(name) === undefined
274
+ && name.includes("$") === false
275
+ && name !== "me") {
276
+ continue;
277
+ }
278
+
279
+ ret += "this." + name + " = " + new TranspileTypes().toType(identifier.getType()) + ";\n";
280
+ if (name === "me") {
281
+ ret += "this.me.set(this);\n";
282
+ }
283
+ }
284
+ */
285
+ ret += "this.me = new abap.types.ABAPObject();\n";
286
+ ret += "this.me.set(this);\n";
287
+ for (const a of def.getAttributes().getAll()) {
288
+ if (a.getMeta().includes("static" /* Static */) === true) {
259
289
  continue;
260
290
  }
261
- const name = n.toLowerCase().replace("~", "$");
262
- if (name === "super") {
263
- continue; // todo, https://github.com/abaplint/transpiler/issues/133
291
+ const name = a.getName().toLowerCase();
292
+ ret += "this." + name + " = " + new types_1.TranspileTypes().toType(a.getType()) + ";\n";
293
+ }
294
+ // attributes from directly implemented interfaces(not interfaces implemented in super classes)
295
+ for (const i of def.getImplementing()) {
296
+ let intf = scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(i.name);
297
+ if (intf === undefined) {
298
+ const iglobal = this.reg.getObject("INTF", i.name);
299
+ intf = iglobal === null || iglobal === void 0 ? void 0 : iglobal.getDefinition();
264
300
  }
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";
301
+ for (const a of (intf === null || intf === void 0 ? void 0 : intf.getAttributes().getAll()) || []) {
302
+ if (a.getMeta().includes("static" /* Static */) === true) {
303
+ continue;
304
+ }
305
+ const name = i.name.toLowerCase() + "$" + a.getName().toLowerCase();
306
+ ret += "this." + name + " = " + new types_1.TranspileTypes().toType(a.getType()) + ";\n";
274
307
  }
275
308
  }
276
309
  // 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.67",
3
+ "version": "1.7.1",
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,15 +27,15 @@
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": {
33
- "@types/chai": "^4.2.22",
34
+ "@types/chai": "^4.3.0",
34
35
  "@types/mocha": "^9.0.0",
35
36
  "chai": "^4.3.4",
36
37
  "mocha": "^9.1.3",
37
38
  "source-map-support": "^0.5.21",
38
- "typescript": "^4.5.2"
39
+ "typescript": "^4.5.4"
39
40
  }
40
41
  }