@abaplint/transpiler 1.7.30 → 1.7.31

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,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MethodSourceTranspiler = void 0;
4
4
  const core_1 = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
+ const _1 = require(".");
6
7
  class MethodSourceTranspiler {
7
8
  constructor(prepend) {
8
9
  this.prepend = (prepend || "") + "await ";
@@ -18,8 +19,17 @@ class MethodSourceTranspiler {
18
19
  }
19
20
  else if (child.get() instanceof core_1.Expressions.Dynamic && (nextChild === null || nextChild === void 0 ? void 0 : nextChild.concatTokens()) === "=>") {
20
21
  const second = child.getChildren()[1];
21
- if (second.get() instanceof core_1.Expressions.FieldChain) {
22
- ret.appendChunk(traversal.traverse(second));
22
+ if (second.get() instanceof core_1.Expressions.FieldChain && second instanceof core_1.Nodes.ExpressionNode) {
23
+ 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);
23
33
  }
24
34
  else if (second.get() instanceof core_1.Expressions.Constant) {
25
35
  const lookup = traversal.lookupClassOrInterface(second.getFirstToken().getStr(), child.getFirstToken(), true);
@@ -11,8 +11,8 @@ class HandleDataElement {
11
11
  return [];
12
12
  }
13
13
  const type = obj.parseType(reg);
14
- const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
14
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
16
16
  };`);
17
17
  const output = {
18
18
  object: {
@@ -12,9 +12,9 @@ class HandleTable {
12
12
  return [];
13
13
  }
14
14
  const type = obj.parseType(reg);
15
- const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
16
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
17
- "keyFields": ${JSON.stringify(obj.listKeys())},
15
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
16
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
17
+ "keyFields": ${JSON.stringify(obj.listKeys())},
18
18
  };`);
19
19
  const output = {
20
20
  object: {
@@ -11,8 +11,8 @@ class HandleTableType {
11
11
  return [];
12
12
  }
13
13
  const type = obj.parseType(reg);
14
- const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
14
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
16
16
  };`);
17
17
  const output = {
18
18
  object: {
@@ -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
  }
@@ -5,9 +5,9 @@ const abaplint = require("@abaplint/core");
5
5
  class UnitTest {
6
6
  // todo, move this somewhere else, its much more than just unit test relevant
7
7
  initializationScript(reg, dbSetup) {
8
- let ret = `import runtime from "@abaplint/runtime";
9
- global.abap = new runtime.ABAP();
10
- ${this.buildImports(reg)}
8
+ let ret = `import runtime from "@abaplint/runtime";
9
+ global.abap = new runtime.ABAP();
10
+ ${this.buildImports(reg)}
11
11
  export async function initializeABAP(settings) {\n`;
12
12
  if (dbSetup === "") {
13
13
  ret += `// no database artifacts, skip DB initialization\n`;
@@ -19,21 +19,21 @@ export async function initializeABAP(settings) {\n`;
19
19
  return ret;
20
20
  }
21
21
  unitTestScript(reg, skip, _only) {
22
- let ret = `/* eslint-disable curly */
23
- import fs from "fs";
24
- import path from "path";
25
- import {fileURLToPath} from "url";
26
- import {initializeABAP} from "./init.mjs";
27
- import runtime from "@abaplint/runtime";
28
-
29
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
30
-
31
- async function run() {
32
- await initializeABAP();
33
- const unit = new runtime.UnitTestResult();
34
- let clas;
35
- let locl;
36
- let meth;
22
+ let ret = `/* eslint-disable curly */
23
+ import fs from "fs";
24
+ import path from "path";
25
+ import {fileURLToPath} from "url";
26
+ import {initializeABAP} from "./init.mjs";
27
+ import runtime from "@abaplint/runtime";
28
+
29
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
30
+
31
+ async function run() {
32
+ await initializeABAP();
33
+ const unit = new runtime.UnitTestResult();
34
+ let clas;
35
+ let locl;
36
+ let meth;
37
37
  try {\n`;
38
38
  for (const obj of reg.getObjects()) {
39
39
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -48,9 +48,9 @@ async function run() {
48
48
  || def.methods.length === 0) {
49
49
  continue;
50
50
  }
51
- ret += ` {
52
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
53
- locl = clas.addTestClass("${def.name}");
51
+ ret += ` {
52
+ const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
53
+ locl = clas.addTestClass("${def.name}");
54
54
  if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
55
55
  for (const m of def.methods) {
56
56
  if (m.isForTesting === false) {
@@ -77,24 +77,24 @@ async function run() {
77
77
  }
78
78
  }
79
79
  }
80
- ret += `// -------------------END-------------------
81
- console.log(abap.console.get());
82
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
83
- } catch (e) {
84
- if (meth) {
85
- meth.fail();
86
- }
87
- console.log(abap.console.get());
88
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
89
- throw e;
90
- }
91
- }
92
-
93
- run().then(() => {
94
- process.exit(0);
95
- }).catch((err) => {
96
- console.log(err);
97
- process.exit(1);
80
+ ret += `// -------------------END-------------------
81
+ console.log(abap.console.get());
82
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
83
+ } catch (e) {
84
+ if (meth) {
85
+ meth.fail();
86
+ }
87
+ console.log(abap.console.get());
88
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
89
+ throw e;
90
+ }
91
+ }
92
+
93
+ run().then(() => {
94
+ process.exit(0);
95
+ }).catch((err) => {
96
+ console.log(err);
97
+ process.exit(1);
98
98
  });`;
99
99
  return ret;
100
100
  }
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.7.30",
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.84.4",
31
- "source-map": "^0.7.3"
32
- },
33
- "devDependencies": {
34
- "@types/chai": "^4.3.0",
35
- "@types/mocha": "^9.1.0",
36
- "chai": "^4.3.4",
37
- "mocha": "^9.2.0",
38
- "source-map-support": "^0.5.21",
39
- "typescript": "^4.5.5"
40
- }
41
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "1.7.31",
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.84.5",
31
+ "source-map": "^0.7.3"
32
+ },
33
+ "devDependencies": {
34
+ "@types/chai": "^4.3.0",
35
+ "@types/mocha": "^9.1.0",
36
+ "chai": "^4.3.5",
37
+ "mocha": "^9.2.0",
38
+ "source-map-support": "^0.5.21",
39
+ "typescript": "^4.5.5"
40
+ }
41
+ }