@abaplint/transpiler 1.6.65 → 1.6.69

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
  }
@@ -7,7 +7,7 @@ class ParameterSTranspiler {
7
7
  transpile(node, traversal) {
8
8
  var _a;
9
9
  const nameToken = (_a = node.findDirectExpression(core_1.Expressions.ParameterName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
10
- const name = nameToken === null || nameToken === void 0 ? void 0 : nameToken.getStr();
10
+ const name = nameToken === null || nameToken === void 0 ? void 0 : nameToken.getStr().toLowerCase();
11
11
  const source = traversal.traverse(node.findDirectExpression(core_1.Expressions.Source));
12
12
  return new chunk_1.Chunk().append(name + ": ", nameToken || node, traversal).appendChunk(source);
13
13
  }
@@ -15,8 +15,8 @@ export interface IObjectIdentifier {
15
15
  export interface IOutput {
16
16
  objects: IOutputFile[];
17
17
  reg: abaplint.IRegistry;
18
- /** Output experimental file to run unit tests */
19
- unitTest: string;
18
+ unitTestScript: string;
19
+ initializationScript: string;
20
20
  databaseSetup: string;
21
21
  }
22
22
  export interface IRequire {
@@ -35,7 +35,8 @@ class Transpiler {
35
35
  const dbSetup = new database_setup_1.DatabaseSetup(reg).run();
36
36
  const output = {
37
37
  objects: [],
38
- unitTest: new unit_test_1.UnitTest().run(reg, dbSetup, (_a = this.options) === null || _a === void 0 ? void 0 : _a.skip),
38
+ unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_a = this.options) === null || _a === void 0 ? void 0 : _a.skip),
39
+ initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup),
39
40
  databaseSetup: dbSetup,
40
41
  reg: reg,
41
42
  };
@@ -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,6 +5,7 @@ export declare type SkipSettings = {
5
5
  method: string;
6
6
  }[];
7
7
  export declare class UnitTest {
8
- run(reg: abaplint.IRegistry, dbSetup: string, skip?: SkipSettings): string;
8
+ initializationScript(reg: abaplint.IRegistry, dbSetup: string): string;
9
+ unitTestScript(reg: abaplint.IRegistry, skip?: SkipSettings): string;
9
10
  private buildImports;
10
11
  }
@@ -3,25 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnitTest = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class UnitTest {
6
- run(reg, dbSetup, skip) {
7
- let ret = `import fs from "fs";
8
- import path from "path";
9
- import runtime from "@abaplint/runtime";
10
- import {dirname} from 'path';
11
- import {fileURLToPath} from 'url';
12
- global.abap = new runtime.ABAP();
13
- ${this.buildImports(reg)}
14
- const __dirname = dirname(fileURLToPath(import.meta.url));
15
- async function initDB() {
16
- return global.abap.initDB(\`${dbSetup}\`);
17
- }
18
-
19
- async function run() {
20
- await initDB();
21
- const unit = new runtime.UnitTestResult();
22
- let clas;
23
- let locl;
24
- let meth;
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}\`);
12
+ }`;
13
+ }
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;
25
29
  try {\n`;
26
30
  for (const obj of reg.getObjects()) {
27
31
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -36,8 +40,8 @@ try {\n`;
36
40
  || def.methods.length === 0) {
37
41
  continue;
38
42
  }
39
- ret += `{
40
- 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");
41
45
  locl = clas.addTestClass("${def.name}");\n`;
42
46
  ret += `if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
43
47
  for (const m of def.methods) {
@@ -65,24 +69,24 @@ locl = clas.addTestClass("${def.name}");\n`;
65
69
  }
66
70
  }
67
71
  }
68
- ret += `// -------------------END-------------------
69
- console.log(abap.console.get());
70
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
71
- } catch (e) {
72
- if (meth) {
73
- meth.fail();
74
- }
75
- console.log(abap.console.get());
76
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
77
- throw e;
78
- }
79
- }
80
-
81
- run().then(() => {
82
- process.exit();
83
- }).catch((err) => {
84
- console.log(err);
85
- 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);
86
90
  });`;
87
91
  return ret;
88
92
  }
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.6.65",
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:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
14
- "test": "npm run compile && mocha"
15
- },
16
- "mocha": {
17
- "recursive": true,
18
- "reporter": "progress",
19
- "spec": "build/test/**/*.js",
20
- "require": "source-map-support/register"
21
- },
22
- "keywords": [
23
- "ABAP",
24
- "abaplint"
25
- ],
26
- "author": "abaplint",
27
- "license": "MIT",
28
- "dependencies": {
29
- "@abaplint/core": "^2.80.9",
30
- "source-map": "^0.7.3"
31
- },
32
- "devDependencies": {
33
- "@types/chai": "^4.2.22",
34
- "@types/mocha": "^9.0.0",
35
- "chai": "^4.3.4",
36
- "mocha": "^9.1.3",
37
- "source-map-support": "^0.5.20",
38
- "typescript": "^4.4.4"
39
- }
40
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "1.6.69",
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:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
14
+ "test": "npm run compile && mocha"
15
+ },
16
+ "mocha": {
17
+ "recursive": true,
18
+ "reporter": "progress",
19
+ "spec": "build/test/**/*.js",
20
+ "require": "source-map-support/register"
21
+ },
22
+ "keywords": [
23
+ "ABAP",
24
+ "abaplint"
25
+ ],
26
+ "author": "abaplint",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "@abaplint/core": "=2.80.10",
30
+ "source-map": "^0.7.3"
31
+ },
32
+ "devDependencies": {
33
+ "@types/chai": "^4.3.0",
34
+ "@types/mocha": "^9.0.0",
35
+ "chai": "^4.3.4",
36
+ "mocha": "^9.1.3",
37
+ "source-map-support": "^0.5.21",
38
+ "typescript": "^4.5.4"
39
+ }
40
+ }