@abaplint/transpiler 1.7.1 → 1.7.5

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.
@@ -36,6 +36,8 @@ class CompareOperatorTranspiler {
36
36
  return new chunk_1.Chunk().append("ns", node, traversal);
37
37
  case "CN":
38
38
  return new chunk_1.Chunk().append("cn", node, traversal);
39
+ case "NA":
40
+ return new chunk_1.Chunk().append("na", node, traversal);
39
41
  default:
40
42
  return new chunk_1.Chunk().append("compareoperatortodo" + op, node, traversal);
41
43
  }
@@ -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;
@@ -258,30 +258,6 @@ class Traversal {
258
258
  // for now just pass the same input
259
259
  ret += `await super.constructor_(${inputName});\n`;
260
260
  }
261
- /*
262
- for (const n in vars) {
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
261
  ret += "this.me = new abap.types.ABAPObject();\n";
286
262
  ret += "this.me.set(this);\n";
287
263
  for (const a of def.getAttributes().getAll()) {
@@ -293,18 +269,7 @@ class Traversal {
293
269
  }
294
270
  // attributes from directly implemented interfaces(not interfaces implemented in super classes)
295
271
  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();
300
- }
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";
307
- }
272
+ ret += this.dataFromInterfaces(i.name, scope);
308
273
  }
309
274
  // handle aliases after initialization of carrier variables
310
275
  for (const a of def.getAliases().getAll()) {
@@ -316,6 +281,37 @@ class Traversal {
316
281
  }
317
282
  return ret;
318
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
+ }
319
315
  determineType(node, scope) {
320
316
  var _a;
321
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.1",
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.5",
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.21",
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
+ }