@abaplint/transpiler 1.7.40 → 1.7.44

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.
@@ -3,7 +3,7 @@ import { IExpressionTranspiler } from "./_expression_transpiler";
3
3
  import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class MethodSourceTranspiler implements IExpressionTranspiler {
6
- private readonly prepend;
6
+ private prepend;
7
7
  constructor(prepend?: string);
8
8
  transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
9
9
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MethodSourceTranspiler = void 0;
4
+ /* eslint-disable max-len */
4
5
  const core_1 = require("@abaplint/core");
5
6
  const chunk_1 = require("../chunk");
6
7
  const _1 = require(".");
@@ -11,36 +12,26 @@ class MethodSourceTranspiler {
11
12
  transpile(node, traversal) {
12
13
  const ret = new chunk_1.Chunk();
13
14
  const children = node.getChildren();
15
+ let call = "";
14
16
  for (let i = 0; i < children.length; i++) {
15
17
  const child = children[i];
16
18
  const nextChild = children[i + 1];
17
19
  if (child.get() instanceof core_1.Expressions.ClassName) {
18
- ret.appendString(traversal.lookupClassOrInterface(child.concatTokens(), child.getFirstToken()));
20
+ call += traversal.lookupClassOrInterface(child.concatTokens(), child.getFirstToken());
19
21
  }
20
22
  else if (child.get() instanceof core_1.Expressions.Dynamic && (nextChild === null || nextChild === void 0 ? void 0 : nextChild.concatTokens()) === "=>") {
21
23
  const second = child.getChildren()[1];
24
+ const lookupException = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_CLASS'", child.getFirstToken(), true);
22
25
  if (second.get() instanceof core_1.Expressions.FieldChain && second instanceof core_1.Nodes.ExpressionNode) {
23
26
  const t = new _1.FieldChainTranspiler(true).transpile(second, traversal).getCode();
24
- const lookup = traversal.lookupClassOrInterface(t, child.getFirstToken(), true);
25
- const lookupException = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_CLASS'", child.getFirstToken(), true);
26
- // eslint-disable-next-line max-len
27
- ret.appendString(`if (${lookup} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
28
- ret.appendString(`if (${lookup} === undefined) { throw new ${lookupException}(); }\n`);
29
- if (i === 0) {
30
- ret.appendString(this.prepend);
31
- }
32
- ret.appendString(lookup);
27
+ call = traversal.lookupClassOrInterface(t, child.getFirstToken(), true);
28
+ ret.appendString(`if (${call} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
29
+ ret.appendString(`if (${call} === undefined) { throw new ${lookupException}(); }\n`);
33
30
  }
34
31
  else if (second.get() instanceof core_1.Expressions.Constant) {
35
- const lookup = traversal.lookupClassOrInterface(second.getFirstToken().getStr(), child.getFirstToken(), true);
36
- const lookupException = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_CLASS'", child.getFirstToken(), true);
37
- // eslint-disable-next-line max-len
38
- ret.appendString(`if (${lookup} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
39
- ret.appendString(`if (${lookup} === undefined) { throw new ${lookupException}(); }\n`);
40
- if (i === 0) {
41
- ret.appendString(this.prepend);
42
- }
43
- ret.appendString(lookup);
32
+ call = traversal.lookupClassOrInterface(second.getFirstToken().getStr(), child.getFirstToken(), true);
33
+ ret.appendString(`if (${call} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
34
+ ret.appendString(`if (${call} === undefined) { throw new ${lookupException}(); }\n`);
44
35
  }
45
36
  else {
46
37
  ret.appendString("MethodSourceTranspiler-Unexpected");
@@ -48,49 +39,51 @@ class MethodSourceTranspiler {
48
39
  }
49
40
  else if (child.get() instanceof core_1.Expressions.Dynamic) {
50
41
  const second = child.getChildren()[1];
42
+ const lookupException = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_METHOD'", child.getFirstToken(), true);
51
43
  if (second.get() instanceof core_1.Expressions.FieldChain) {
52
- ret.appendString("[");
53
- ret.appendChunk(traversal.traverse(second));
54
- ret.appendString("]");
44
+ call += "[";
45
+ call += traversal.traverse(second).getCode();
46
+ call += ".get().toLowerCase()]";
55
47
  }
56
48
  else if (second.get() instanceof core_1.Expressions.Constant) {
57
- if (ret.getCode().endsWith(".") === false) {
58
- ret.appendString(".");
49
+ if (call.endsWith(".") === false) {
50
+ call += ".";
59
51
  }
60
- ret.appendString(second.getFirstToken().getStr().replace(/\'/g, "").toLowerCase().replace("~", "$"));
52
+ call += second.getFirstToken().getStr().replace(/\'/g, "").toLowerCase().replace("~", "$");
61
53
  }
62
54
  else {
63
55
  ret.appendString("MethodSourceTranspiler-Unexpected");
64
56
  }
57
+ ret.appendString(`if (${call} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_METHOD not found"; }\n`);
58
+ ret.appendString(`if (${call} === undefined) { throw new ${lookupException}(); }\n`);
65
59
  }
66
60
  else if (child.get() instanceof core_1.Expressions.MethodName) {
67
61
  if (i === 0) {
68
- ret.appendString(this.prepend + "this.");
62
+ this.prepend += "this.";
69
63
  }
70
64
  const methodName = child.concatTokens().toLowerCase().replace("~", "$");
71
- ret.append(methodName, child.getFirstToken().getStart(), traversal);
65
+ call += methodName;
72
66
  }
73
67
  else if (child.concatTokens() === "=>") {
74
- ret.append(".", child.getFirstToken().getStart(), traversal);
68
+ call += ".";
75
69
  }
76
70
  else if (child.concatTokens() === "->") {
77
71
  if (ret.getCode() !== "super") {
78
- ret.append(".get()", child, traversal);
72
+ call += ".get()";
79
73
  }
80
74
  if (!(nextChild.get() instanceof core_1.Expressions.Dynamic)) {
81
- ret.append(".", child, traversal);
75
+ call += ".";
82
76
  }
83
77
  }
84
78
  else if (child.get() instanceof core_1.Expressions.FieldChain) {
85
- if (i === 0) {
86
- ret.appendString(this.prepend);
87
- }
88
- ret.appendChunk(traversal.traverse(child));
79
+ call += traversal.traverse(child).getCode();
89
80
  }
90
81
  else {
91
82
  ret.appendString("MethodSourceTranspiler-" + child.get().constructor.name + "-todo");
92
83
  }
93
84
  }
85
+ ret.appendString(this.prepend);
86
+ ret.appendString(call);
94
87
  return ret;
95
88
  }
96
89
  }
@@ -28,7 +28,7 @@ class Transpiler {
28
28
  return new Transpiler().run(reg);
29
29
  }
30
30
  async run(reg, progress) {
31
- var _a, _b;
31
+ var _a, _b, _c, _d;
32
32
  reg.parse();
33
33
  new keywords_1.Keywords().handle(reg);
34
34
  this.validate(reg);
@@ -36,6 +36,7 @@ class Transpiler {
36
36
  const output = {
37
37
  objects: [],
38
38
  unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_a = this.options) === null || _a === void 0 ? void 0 : _a.skip, (_b = this.options) === null || _b === void 0 ? void 0 : _b.only),
39
+ unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, (_c = this.options) === null || _c === void 0 ? void 0 : _c.skip, (_d = this.options) === null || _d === void 0 ? void 0 : _d.only),
39
40
  initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup),
40
41
  databaseSetup: dbSetup,
41
42
  reg: reg,
@@ -14,6 +14,7 @@ export interface IOutput {
14
14
  objects: IOutputFile[];
15
15
  reg: abaplint.IRegistry;
16
16
  unitTestScript: string;
17
+ unitTestScriptOpen: string;
17
18
  initializationScript: string;
18
19
  databaseSetup: string;
19
20
  }
@@ -6,6 +6,7 @@ export declare type TestMethodList = {
6
6
  }[];
7
7
  export declare class UnitTest {
8
8
  initializationScript(reg: abaplint.IRegistry, dbSetup: string): string;
9
+ unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
9
10
  unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
10
11
  private buildImports;
11
12
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnitTest = void 0;
4
+ /* eslint-disable max-len */
4
5
  const abaplint = require("@abaplint/core");
5
6
  class UnitTest {
6
7
  // todo, move this somewhere else, its much more than just unit test relevant
@@ -18,6 +19,62 @@ export async function initializeABAP(settings) {\n`;
18
19
  ret += `}`;
19
20
  return ret;
20
21
  }
22
+ unitTestScriptOpen(reg, _skip, _only) {
23
+ let ret = `/* eslint-disable curly */
24
+ import fs from "fs";
25
+ import path from "path";
26
+ import {fileURLToPath} from "url";
27
+ import {initializeABAP} from "./init.mjs";
28
+
29
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
30
+
31
+ async function run() {
32
+ await initializeABAP();
33
+ let lt_input = new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30})}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]});
34
+ let ls_input = new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30})});
35
+ let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character({length: 30}), testclass_name: new abap.types.Character({length: 30}), method_name: new abap.types.Character({length: 30}), expected: new abap.types.String(), actual: new abap.types.String(), status: new abap.types.String(), runtime: new abap.types.Integer(), message: new abap.types.String(), js_location: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
36
+ `;
37
+ for (const obj of reg.getObjects()) {
38
+ if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
39
+ continue;
40
+ }
41
+ const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
42
+ if (hasTestFile === true) {
43
+ ret += ` await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");\n`;
44
+ }
45
+ for (const file of obj.getABAPFiles()) {
46
+ for (const def of file.getInfo().listClassDefinitions()) {
47
+ if (def.isForTesting === false || def.isGlobal === true || def.methods.length === 0) {
48
+ // todo, fix, there might be global test methods
49
+ continue;
50
+ }
51
+ for (const m of def.methods) {
52
+ if (m.isForTesting === false) {
53
+ continue;
54
+ }
55
+ ret += ` ls_input.get().class_name.set("${obj.getName()}");
56
+ ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
57
+ ls_input.get().method_name.set("${m.name.toUpperCase()}");
58
+ abap.statements.append({source: ls_input, target: lt_input});`;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ ret += `
64
+
65
+ ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
66
+ console.dir(ls_result);
67
+ fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
68
+ }
69
+
70
+ run().then(() => {
71
+ process.exit(0);
72
+ }).catch((err) => {
73
+ console.log(err);
74
+ process.exit(1);
75
+ });`;
76
+ return ret;
77
+ }
21
78
  unitTestScript(reg, skip, _only) {
22
79
  let ret = `/* eslint-disable curly */
23
80
  import fs from "fs";
@@ -43,9 +100,8 @@ async function run() {
43
100
  ret += ` clas = unit.addObject("${obj.getName()}");\n`;
44
101
  for (const file of obj.getABAPFiles()) {
45
102
  for (const def of file.getInfo().listClassDefinitions()) {
46
- if (def.isForTesting === false
47
- || def.isGlobal === true // todo, fix, there might be global test methods
48
- || def.methods.length === 0) {
103
+ if (def.isForTesting === false || def.isGlobal === true || def.methods.length === 0) {
104
+ // todo, fix, there might be global test methods
49
105
  continue;
50
106
  }
51
107
  ret += ` {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "1.7.40",
3
+ "version": "1.7.44",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "author": "abaplint",
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@abaplint/core": "^2.85.9",
30
+ "@abaplint/core": "^2.85.10",
31
31
  "source-map": "^0.7.3"
32
32
  },
33
33
  "devDependencies": {