@abaplint/transpiler 1.7.0 → 1.7.4

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.
@@ -12,14 +12,14 @@ class DoTranspiler {
12
12
  const source = new expressions_1.SourceTranspiler(true).transpile(found, traversal).getCode();
13
13
  const idSource = unique_identifier_1.UniqueIdentifier.get();
14
14
  const id = unique_identifier_1.UniqueIdentifier.get();
15
- return new chunk_1.Chunk(`const ${idSource} = ${source};
16
- for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
15
+ return new chunk_1.Chunk(`const ${idSource} = ${source};
16
+ for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
17
17
  abap.builtin.sy.get().index.set(${id} + 1);`);
18
18
  }
19
19
  else {
20
20
  const unique = unique_identifier_1.UniqueIdentifier.get();
21
- return new chunk_1.Chunk(`let ${unique} = 1;
22
- while (true) {
21
+ return new chunk_1.Chunk(`let ${unique} = 1;
22
+ while (true) {
23
23
  abap.builtin.sy.get().index.set(${unique}++);`);
24
24
  }
25
25
  }
@@ -4,4 +4,5 @@ import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class EndMethodTranspiler implements IStatementTranspiler {
6
6
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
+ private setSubrc;
7
8
  }
@@ -5,28 +5,13 @@ 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;
9
8
  const token = node.getFirstToken();
10
9
  const scope = traversal.findCurrentScopeByToken(token);
11
10
  if (scope === undefined) {
12
11
  throw new Error("EndMethodTranspiler, scope not found");
13
12
  }
14
13
  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
+ returning += this.setSubrc(scope, traversal);
30
15
  const vars = scope.getData().vars;
31
16
  for (const n in vars) {
32
17
  const identifier = vars[n];
@@ -40,6 +25,34 @@ class EndMethodTranspiler {
40
25
  }
41
26
  return new chunk_1.Chunk().append(returning + "}", node, traversal);
42
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
+ }
43
56
  }
44
57
  exports.EndMethodTranspiler = EndMethodTranspiler;
45
58
  //# sourceMappingURL=end_method.js.map
@@ -16,6 +16,11 @@ class ReadTableTranspiler {
16
16
  const s = new expressions_1.SourceTranspiler().transpile(index, traversal).getCode();
17
17
  extra.push("index: " + s);
18
18
  }
19
+ const from = node.findExpressionAfterToken("FROM");
20
+ if (from) {
21
+ const s = new expressions_1.SourceTranspiler().transpile(from, traversal).getCode();
22
+ extra.push("from: " + s);
23
+ }
19
24
  const rt = node.findDirectExpression(abaplint.Expressions.ReadTableTarget);
20
25
  const target = rt === null || rt === void 0 ? void 0 : rt.findDirectExpression(abaplint.Expressions.Target);
21
26
  const fs = rt === null || rt === void 0 ? void 0 : rt.findDirectExpression(abaplint.Expressions.FSTarget);
@@ -47,12 +47,14 @@ class InterfaceTranspiler {
47
47
  const valExpression = constantStatement === null || constantStatement === void 0 ? void 0 : constantStatement.findFirstExpression(abaplint.Expressions.Value);
48
48
  if ((valExpression === null || valExpression === void 0 ? void 0 : valExpression.getChildren()[1].get()) instanceof abaplint.Expressions.SimpleFieldChain) {
49
49
  const s = new expressions_1.FieldChainTranspiler().transpile(valExpression.getChildren()[1], traversal, false).getCode();
50
- ret += name + ".set(" + s + ");\n";
50
+ const e = new expressions_1.ConstantTranspiler().escape(s);
51
+ ret += name + ".set(" + e + ");\n";
51
52
  continue;
52
53
  }
53
54
  const val = identifier.getValue();
54
55
  if (typeof val === "string") {
55
- ret += name + ".set(" + identifier.getValue() + ");\n";
56
+ const e = new expressions_1.ConstantTranspiler().escape(val);
57
+ ret += name + ".set(" + e + ");\n";
56
58
  }
57
59
  else if (typeof val === "object") {
58
60
  const a = val;
@@ -31,6 +31,9 @@ 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
38
  registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
36
39
  lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined): string;
@@ -246,7 +246,6 @@ class Traversal {
246
246
  return undefined;
247
247
  }
248
248
  buildConstructorContents(scope, def, inputName) {
249
- var _a;
250
249
  /*
251
250
  const vars = scope?.getData().vars;
252
251
  if (vars === undefined || Object.keys(vars).length === 0) {
@@ -259,30 +258,6 @@ class Traversal {
259
258
  // for now just pass the same input
260
259
  ret += `await super.constructor_(${inputName});\n`;
261
260
  }
262
- /*
263
- for (const n in vars) {
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
261
  ret += "this.me = new abap.types.ABAPObject();\n";
287
262
  ret += "this.me.set(this);\n";
288
263
  for (const a of def.getAttributes().getAll()) {
@@ -294,13 +269,7 @@ class Traversal {
294
269
  }
295
270
  // attributes from directly implemented interfaces(not interfaces implemented in super classes)
296
271
  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";
303
- }
272
+ ret += this.dataFromInterfaces(i.name, scope);
304
273
  }
305
274
  // handle aliases after initialization of carrier variables
306
275
  for (const a of def.getAliases().getAll()) {
@@ -312,6 +281,37 @@ class Traversal {
312
281
  }
313
282
  return ret;
314
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
+ }
315
315
  determineType(node, scope) {
316
316
  var _a;
317
317
  if (scope === undefined) {
@@ -4,28 +4,28 @@ exports.UnitTest = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class UnitTest {
6
6
  initializationScript(reg, dbSetup) {
7
- return `import runtime from "@abaplint/runtime";
8
- global.abap = new runtime.ABAP();
9
- ${this.buildImports(reg)}
10
- export async function initDB() {
11
- return global.abap.initDB(\`${dbSetup}\`);
7
+ return `import runtime from "@abaplint/runtime";
8
+ global.abap = new runtime.ABAP();
9
+ ${this.buildImports(reg)}
10
+ export async function initDB() {
11
+ return global.abap.initDB(\`${dbSetup}\`);
12
12
  }`;
13
13
  }
14
14
  unitTestScript(reg, skip) {
15
- let ret = `import fs from "fs";
16
- import path from "path";
17
- import {dirname} from 'path';
18
- import {fileURLToPath} from 'url';
19
- const __dirname = dirname(fileURLToPath(import.meta.url));
20
- import {initDB} from "./init.mjs";
21
- import runtime from "@abaplint/runtime";
22
-
23
- async function run() {
24
- await initDB();
25
- const unit = new runtime.UnitTestResult();
26
- let clas;
27
- let locl;
28
- let meth;
15
+ let ret = `import fs from "fs";
16
+ import path from "path";
17
+ import {dirname} from 'path';
18
+ import {fileURLToPath} from 'url';
19
+ const __dirname = dirname(fileURLToPath(import.meta.url));
20
+ import {initDB} from "./init.mjs";
21
+ import runtime from "@abaplint/runtime";
22
+
23
+ async function run() {
24
+ await initDB();
25
+ const unit = new runtime.UnitTestResult();
26
+ let clas;
27
+ let locl;
28
+ let meth;
29
29
  try {\n`;
30
30
  for (const obj of reg.getObjects()) {
31
31
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -40,8 +40,8 @@ try {\n`;
40
40
  || def.methods.length === 0) {
41
41
  continue;
42
42
  }
43
- ret += `{
44
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
43
+ ret += `{
44
+ const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
45
45
  locl = clas.addTestClass("${def.name}");\n`;
46
46
  ret += `if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
47
47
  for (const m of def.methods) {
@@ -69,24 +69,24 @@ locl = clas.addTestClass("${def.name}");\n`;
69
69
  }
70
70
  }
71
71
  }
72
- ret += `// -------------------END-------------------
73
- console.log(abap.console.get());
74
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
75
- } catch (e) {
76
- if (meth) {
77
- meth.fail();
78
- }
79
- console.log(abap.console.get());
80
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
81
- throw e;
82
- }
83
- }
84
-
85
- run().then(() => {
86
- process.exit();
87
- }).catch((err) => {
88
- console.log(err);
89
- process.exit(1);
72
+ ret += `// -------------------END-------------------
73
+ console.log(abap.console.get());
74
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
75
+ } catch (e) {
76
+ if (meth) {
77
+ meth.fail();
78
+ }
79
+ console.log(abap.console.get());
80
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
81
+ throw e;
82
+ }
83
+ }
84
+
85
+ run().then(() => {
86
+ process.exit();
87
+ }).catch((err) => {
88
+ console.log(err);
89
+ process.exit(1);
90
90
  });`;
91
91
  return ret;
92
92
  }
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.7.0",
4
- "description": "Transpiler",
5
- "main": "build/src/index.js",
6
- "typings": "build/src/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/abaplint/transpiler.git"
10
- },
11
- "scripts": {
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",
14
- "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
15
- "test": "npm run compile && mocha"
16
- },
17
- "mocha": {
18
- "recursive": true,
19
- "reporter": "progress",
20
- "spec": "build/test/**/*.js",
21
- "require": "source-map-support/register"
22
- },
23
- "keywords": [
24
- "ABAP",
25
- "abaplint"
26
- ],
27
- "author": "abaplint",
28
- "license": "MIT",
29
- "dependencies": {
30
- "@abaplint/core": "^2.83.16",
31
- "source-map": "^0.7.3"
32
- },
33
- "devDependencies": {
34
- "@types/chai": "^4.3.0",
35
- "@types/mocha": "^9.0.0",
36
- "chai": "^4.3.4",
37
- "mocha": "^9.1.3",
38
- "source-map-support": "^0.5.21",
39
- "typescript": "^4.5.4"
40
- }
41
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "1.7.4",
4
+ "description": "Transpiler",
5
+ "main": "build/src/index.js",
6
+ "typings": "build/src/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/abaplint/transpiler.git"
10
+ },
11
+ "scripts": {
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",
14
+ "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
15
+ "test": "npm run compile && mocha"
16
+ },
17
+ "mocha": {
18
+ "recursive": true,
19
+ "reporter": "progress",
20
+ "spec": "build/test/**/*.js",
21
+ "require": "source-map-support/register"
22
+ },
23
+ "keywords": [
24
+ "ABAP",
25
+ "abaplint"
26
+ ],
27
+ "author": "abaplint",
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "@abaplint/core": "^2.83.18",
31
+ "source-map": "^0.7.3"
32
+ },
33
+ "devDependencies": {
34
+ "@types/chai": "^4.3.0",
35
+ "@types/mocha": "^9.0.0",
36
+ "chai": "^4.3.4",
37
+ "mocha": "^9.1.3",
38
+ "source-map-support": "^0.5.21",
39
+ "typescript": "^4.5.4"
40
+ }
41
+ }