@abaplint/transpiler 1.8.40 → 2.0.2

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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # @abaplint/transpiler
2
-
1
+ # @abaplint/transpiler
2
+
3
3
  Transpiler
@@ -0,0 +1,8 @@
1
+ export declare type DatabaseSetupResult = {
2
+ schemas: {
3
+ sqlite: string;
4
+ pg: string;
5
+ hdb: string;
6
+ };
7
+ insert: string;
8
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=database_setup_result.js.map
@@ -0,0 +1,10 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { DatabaseSetupResult } from "./database_setup_result";
3
+ export declare class DatabaseSetup {
4
+ private readonly reg;
5
+ constructor(reg: abaplint.IRegistry);
6
+ run(): DatabaseSetupResult;
7
+ private buildInsert;
8
+ private t000Insert;
9
+ private messageClass;
10
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseSetup = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const sqlite_database_schema_1 = require("./sqlite_database_schema");
6
+ class DatabaseSetup {
7
+ constructor(reg) {
8
+ this.reg = reg;
9
+ }
10
+ run() {
11
+ return {
12
+ schemas: {
13
+ sqlite: new sqlite_database_schema_1.SQLiteDatabaseSchema(this.reg).run(),
14
+ hdb: "todo",
15
+ pg: "todo",
16
+ },
17
+ insert: this.buildInsert(),
18
+ };
19
+ }
20
+ ////////////////////
21
+ buildInsert() {
22
+ let insert = "";
23
+ // INSERT data
24
+ for (const obj of this.reg.getObjects()) {
25
+ if (obj instanceof abaplint.Objects.MessageClass) {
26
+ insert += this.messageClass(obj);
27
+ }
28
+ }
29
+ insert += this.t000Insert();
30
+ return insert;
31
+ }
32
+ t000Insert() {
33
+ const obj = this.reg.getObject("TABL", "T000");
34
+ if (obj === undefined) {
35
+ return "";
36
+ }
37
+ const type = obj.parseType(this.reg);
38
+ if (type instanceof abaplint.BasicTypes.StructureType && type.getComponents().length === 3) {
39
+ // todo, this should take the client number from the settings
40
+ return `INSERT INTO t000 VALUES ('123', '', '');\n`;
41
+ }
42
+ else {
43
+ return "";
44
+ }
45
+ }
46
+ messageClass(msag) {
47
+ // ignore if T100 is unknown
48
+ if (this.reg.getObject("TABL", "T100") === undefined) {
49
+ return "";
50
+ }
51
+ let ret = "";
52
+ for (const m of msag.getMessages()) {
53
+ ret += `INSERT INTO t100 VALUES ('E', '${msag.getName()}', '${m.getNumber()}', '${m.getMessage()}');\n`;
54
+ }
55
+ return ret;
56
+ }
57
+ }
58
+ exports.DatabaseSetup = DatabaseSetup;
59
+ //# sourceMappingURL=index.js.map
@@ -1,10 +1,8 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- export declare class DatabaseSetup {
2
+ export declare class SQLiteDatabaseSchema {
3
3
  private readonly reg;
4
4
  constructor(reg: abaplint.IRegistry);
5
5
  run(): string;
6
- private t000Insert;
7
- private messageClass;
8
6
  private transparentTable;
9
7
  private toType;
10
8
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DatabaseSetup = void 0;
3
+ exports.SQLiteDatabaseSchema = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
- class DatabaseSetup {
5
+ class SQLiteDatabaseSchema {
6
6
  constructor(reg) {
7
7
  this.reg = reg;
8
8
  }
@@ -14,41 +14,9 @@ class DatabaseSetup {
14
14
  ret += this.transparentTable(obj);
15
15
  }
16
16
  }
17
- // INSERT data
18
- for (const obj of this.reg.getObjects()) {
19
- if (obj instanceof abaplint.Objects.MessageClass) {
20
- ret += this.messageClass(obj);
21
- }
22
- }
23
- ret += this.t000Insert();
24
17
  return ret.trim();
25
18
  }
26
19
  //////////////////
27
- t000Insert() {
28
- const obj = this.reg.getObject("TABL", "T000");
29
- if (obj === undefined) {
30
- return "";
31
- }
32
- const type = obj.parseType(this.reg);
33
- if (type instanceof abaplint.BasicTypes.StructureType && type.getComponents().length === 3) {
34
- // todo, this should take the client number from the settings
35
- return `INSERT INTO t000 VALUES ('123', '', '');\n`;
36
- }
37
- else {
38
- return "";
39
- }
40
- }
41
- messageClass(msag) {
42
- // ignore if T100 is unknown
43
- if (this.reg.getObject("TABL", "T100") === undefined) {
44
- return "";
45
- }
46
- let ret = "";
47
- for (const m of msag.getMessages()) {
48
- ret += `INSERT INTO t100 VALUES ('E', '${msag.getName()}', '${m.getNumber()}', '${m.getMessage()}');\n`;
49
- }
50
- return ret;
51
- }
52
20
  transparentTable(tabl) {
53
21
  const type = tabl.parseType(this.reg);
54
22
  if (!(type instanceof abaplint.BasicTypes.StructureType)) {
@@ -85,5 +53,5 @@ class DatabaseSetup {
85
53
  }
86
54
  }
87
55
  }
88
- exports.DatabaseSetup = DatabaseSetup;
89
- //# sourceMappingURL=database_setup.js.map
56
+ exports.SQLiteDatabaseSchema = SQLiteDatabaseSchema;
57
+ //# sourceMappingURL=sqlite_database_schema.js.map
@@ -18,11 +18,11 @@ class HandleDataElement {
18
18
  fixedValues = doma.getFixedValues();
19
19
  }
20
20
  }
21
- const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
22
- "objectType": "DTEL",
23
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
24
- "domain": ${JSON.stringify(obj.getDomainName())},
25
- "fixedValues": ${JSON.stringify(fixedValues)},
21
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
22
+ "objectType": "DTEL",
23
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
24
+ "domain": ${JSON.stringify(obj.getDomainName())},
25
+ "fixedValues": ${JSON.stringify(fixedValues)},
26
26
  };`);
27
27
  const output = {
28
28
  object: {
@@ -12,10 +12,10 @@ 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
- "objectType": "TABL",
17
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
18
- "keyFields": ${JSON.stringify(obj.listKeys())},
15
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
16
+ "objectType": "TABL",
17
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
18
+ "keyFields": ${JSON.stringify(obj.listKeys())},
19
19
  };`);
20
20
  const output = {
21
21
  object: {
@@ -11,9 +11,9 @@ 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
- "objectType": "TTYP",
16
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
14
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
15
+ "objectType": "TTYP",
16
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
17
17
  };`);
18
18
  const output = {
19
19
  object: {
@@ -6,11 +6,11 @@ const validation_1 = require("./validation");
6
6
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return validation_1.config; } });
7
7
  const unit_test_1 = require("./unit_test");
8
8
  const keywords_1 = require("./keywords");
9
- const database_setup_1 = require("./database_setup");
10
9
  const handle_table_1 = require("./handle_table");
11
10
  const handle_abap_1 = require("./handle_abap");
12
11
  const handle_data_element_1 = require("./handle_data_element");
13
12
  const handle_table_type_1 = require("./handle_table_type");
13
+ const db_1 = require("./db");
14
14
  class Transpiler {
15
15
  constructor(options) {
16
16
  this.options = options;
@@ -32,7 +32,7 @@ class Transpiler {
32
32
  reg.parse();
33
33
  new keywords_1.Keywords().handle(reg);
34
34
  this.validate(reg);
35
- const dbSetup = new database_setup_1.DatabaseSetup(reg).run();
35
+ const dbSetup = new db_1.DatabaseSetup(reg).run();
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),
@@ -12,7 +12,7 @@ class DeleteDatabaseTranspiler {
12
12
  const ttab = traversal.traverse(tab);
13
13
  options.push(`"table": ` + ttab.getCode());
14
14
  }
15
- return new chunk_1.Chunk(`abap.statements.deleteDatabase(${table.getCode()}, {${options.join(", ")}});`);
15
+ return new chunk_1.Chunk(`await abap.statements.deleteDatabase(${table.getCode()}, {${options.join(", ")}});`);
16
16
  }
17
17
  }
18
18
  exports.DeleteDatabaseTranspiler = DeleteDatabaseTranspiler;
@@ -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
  }
@@ -8,6 +8,7 @@ export * from "./call_function";
8
8
  export * from "./call_transformation";
9
9
  export * from "./call";
10
10
  export * from "./case";
11
+ export * from "./scan";
11
12
  export * from "./check";
12
13
  export * from "./class_deferred";
13
14
  export * from "./class_implementation";
@@ -24,6 +24,7 @@ __exportStar(require("./call_function"), exports);
24
24
  __exportStar(require("./call_transformation"), exports);
25
25
  __exportStar(require("./call"), exports);
26
26
  __exportStar(require("./case"), exports);
27
+ __exportStar(require("./scan"), exports);
27
28
  __exportStar(require("./check"), exports);
28
29
  __exportStar(require("./class_deferred"), exports);
29
30
  __exportStar(require("./class_implementation"), exports);
@@ -12,7 +12,7 @@ class InsertDatabaseTranspiler {
12
12
  const tvalues = traversal.traverse(values);
13
13
  options.push(`"values": ` + tvalues.getCode());
14
14
  }
15
- return new chunk_1.Chunk(`abap.statements.insertDatabase(${table.getCode()}, {${options.join(", ")}});`);
15
+ return new chunk_1.Chunk(`await abap.statements.insertDatabase(${table.getCode()}, {${options.join(", ")}});`);
16
16
  }
17
17
  }
18
18
  exports.InsertDatabaseTranspiler = InsertDatabaseTranspiler;
@@ -55,7 +55,7 @@ class MessageTranspiler {
55
55
  options.push("with: [" + w.join(",") + "]");
56
56
  }
57
57
  return new chunk_1.Chunk()
58
- .append("abap.statements.message({", node, traversal)
58
+ .append("await abap.statements.message({", node, traversal)
59
59
  .appendString(options.join(", "))
60
60
  .append("});", node.getLastToken(), traversal);
61
61
  }
@@ -12,7 +12,7 @@ class ModifyDatabaseTranspiler {
12
12
  const ttab = traversal.traverse(tab);
13
13
  options.push(`"table": ` + ttab.getCode());
14
14
  }
15
- return new chunk_1.Chunk(`abap.statements.modifyDatabase(${table.getCode()}, {${options.join(", ")}});`);
15
+ return new chunk_1.Chunk(`await abap.statements.modifyDatabase(${table.getCode()}, {${options.join(", ")}});`);
16
16
  }
17
17
  }
18
18
  exports.ModifyDatabaseTranspiler = ModifyDatabaseTranspiler;
@@ -0,0 +1,7 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IStatementTranspiler } from "./_statement_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class ScanTranspiler implements IStatementTranspiler {
6
+ transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScanTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const chunk_1 = require("../chunk");
6
+ class ScanTranspiler {
7
+ transpile(node, traversal) {
8
+ const lookup = traversal.lookupClassOrInterface("KERNEL_SCAN_ABAP_SOURCE", node.getFirstToken());
9
+ const options = [];
10
+ let name = "";
11
+ for (const c of node.getChildren()) {
12
+ if (c instanceof abaplint.Nodes.ExpressionNode) {
13
+ options.push(name + ": " + traversal.traverse(c).getCode());
14
+ name = "";
15
+ }
16
+ else {
17
+ if (name !== "" && name.endsWith("_") === false) {
18
+ name += "_";
19
+ }
20
+ name += c.concatTokens().toLowerCase().replace("-", "");
21
+ }
22
+ }
23
+ const call = `await ${lookup}.call({${options.join(", ")}});`;
24
+ return new chunk_1.Chunk().append(`if (${lookup} === undefined) throw new Error("ScanAbapSource, kernel class missing");\n${call}`, node, traversal);
25
+ }
26
+ }
27
+ exports.ScanTranspiler = ScanTranspiler;
28
+ //# sourceMappingURL=scan.js.map
@@ -22,7 +22,7 @@ class SelectTranspiler {
22
22
  if (node.concatTokens().toUpperCase().startsWith("SELECT SINGLE ")) {
23
23
  select += "LIMIT 1";
24
24
  }
25
- return new chunk_1.Chunk().append(`abap.statements.select(${target}, "${select.trim()}");`, node, traversal);
25
+ return new chunk_1.Chunk().append(`await abap.statements.select(${target}, "${select.trim()}");`, node, traversal);
26
26
  }
27
27
  }
28
28
  exports.SelectTranspiler = SelectTranspiler;
@@ -1,6 +1,7 @@
1
1
  import { Chunk } from "./chunk";
2
2
  import * as abaplint from "@abaplint/core";
3
3
  import { TestMethodList } from "./unit_test";
4
+ import { DatabaseSetupResult } from "./db/database_setup_result";
4
5
  export interface IFile {
5
6
  filename: string;
6
7
  relative?: string;
@@ -16,7 +17,7 @@ export interface IOutput {
16
17
  unitTestScript: string;
17
18
  unitTestScriptOpen: string;
18
19
  initializationScript: string;
19
- databaseSetup: string;
20
+ databaseSetup: DatabaseSetupResult;
20
21
  }
21
22
  export interface IRequire {
22
23
  name: string | undefined;
@@ -1,11 +1,12 @@
1
1
  import * as abaplint from "@abaplint/core";
2
+ import { DatabaseSetupResult } from "./db/database_setup_result";
2
3
  export declare type TestMethodList = {
3
4
  object: string;
4
5
  class: string;
5
6
  method: string;
6
7
  }[];
7
8
  export declare class UnitTest {
8
- initializationScript(reg: abaplint.IRegistry, dbSetup: string, extraSetup?: string): string;
9
+ initializationScript(reg: abaplint.IRegistry, dbSetup: DatabaseSetupResult, extraSetup?: string): string;
9
10
  unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
10
11
  unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
11
12
  private buildImports;
@@ -4,42 +4,43 @@ exports.UnitTest = void 0;
4
4
  /* eslint-disable max-len */
5
5
  const abaplint = require("@abaplint/core");
6
6
  class UnitTest {
7
- // todo, move this somewhere else, its much more than just unit test relevant
7
+ // todo, move this method somewhere else, its much more than just unit test relevant
8
8
  initializationScript(reg, dbSetup, extraSetup) {
9
- let ret = `/* eslint-disable import/newline-after-import */
10
- import runtime from "@abaplint/runtime";
11
- global.abap = new runtime.ABAP();
12
- ${this.buildImports(reg)}
9
+ let ret = `/* eslint-disable import/newline-after-import */
10
+ import runtime from "@abaplint/runtime";
11
+ global.abap = new runtime.ABAP();
12
+ ${this.buildImports(reg)}
13
+
13
14
  export async function initializeABAP() {\n`;
14
- if (dbSetup === "") {
15
- ret += `// no database artifacts, skip DB initialization\n`;
16
- }
17
- else {
18
- ret += ` await global.abap.initDB(\`${dbSetup}\`);\n`;
19
- }
15
+ ret += ` const sqlite = \`${dbSetup.schemas.sqlite}\`;\n`;
16
+ ret += ` const hdb = \`${dbSetup.schemas.hdb}\`;\n`;
17
+ ret += ` const pg = \`${dbSetup.schemas.pg}\`;\n`;
18
+ ret += ` const schemas = {sqlite, hdb, pg};\n`;
19
+ ret += ` const insert = \`${dbSetup.insert}\`;\n`;
20
20
  if (extraSetup === undefined) {
21
- ret += `// no extra setup\n`;
21
+ ret += `// no setup logic specified in config\n`;
22
22
  }
23
23
  else {
24
- ret += ` await import("../test/extra.mjs");\n`;
24
+ ret += ` const {setup} = await import("${extraSetup}");\n` +
25
+ ` await setup(global.abap, schemas, insert);\n`;
25
26
  }
26
27
  ret += `}`;
27
28
  return ret;
28
29
  }
29
30
  unitTestScriptOpen(reg, _skip, _only) {
30
- let ret = `/* eslint-disable curly */
31
- import fs from "fs";
32
- import path from "path";
33
- import {fileURLToPath} from "url";
34
- import {initializeABAP} from "./init.mjs";
35
-
36
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
37
-
38
- async function run() {
39
- await initializeABAP();
40
- 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":[]});
41
- 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})});
42
- 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()});
31
+ let ret = `/* eslint-disable curly */
32
+ import fs from "fs";
33
+ import path from "path";
34
+ import {fileURLToPath} from "url";
35
+ import {initializeABAP} from "./init.mjs";
36
+
37
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
38
+
39
+ async function run() {
40
+ await initializeABAP();
41
+ 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":[]});
42
+ 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})});
43
+ 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()});
43
44
  `;
44
45
  for (const obj of reg.getObjects()) {
45
46
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -59,44 +60,44 @@ async function run() {
59
60
  if (m.isForTesting === false) {
60
61
  continue;
61
62
  }
62
- ret += ` ls_input.get().class_name.set("${obj.getName()}");
63
- ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
64
- ls_input.get().method_name.set("${m.name.toUpperCase()}");
63
+ ret += ` ls_input.get().class_name.set("${obj.getName()}");
64
+ ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
65
+ ls_input.get().method_name.set("${m.name.toUpperCase()}");
65
66
  abap.statements.append({source: ls_input, target: lt_input});`;
66
67
  }
67
68
  }
68
69
  }
69
70
  }
70
- ret += `
71
-
72
- ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
73
- fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
74
- }
75
-
76
- run().then(() => {
77
- process.exit(0);
78
- }).catch((err) => {
79
- console.log(err);
80
- process.exit(1);
71
+ ret += `
72
+
73
+ ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
74
+ fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
75
+ }
76
+
77
+ run().then(() => {
78
+ process.exit(0);
79
+ }).catch((err) => {
80
+ console.log(err);
81
+ process.exit(1);
81
82
  });`;
82
83
  return ret;
83
84
  }
84
85
  unitTestScript(reg, skip, _only) {
85
- let ret = `/* eslint-disable curly */
86
- import fs from "fs";
87
- import path from "path";
88
- import {fileURLToPath} from "url";
89
- import {initializeABAP} from "./init.mjs";
90
- import runtime from "@abaplint/runtime";
91
-
92
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
93
-
94
- async function run() {
95
- await initializeABAP();
96
- const unit = new runtime.UnitTestResult();
97
- let clas;
98
- let locl;
99
- let meth;
86
+ let ret = `/* eslint-disable curly */
87
+ import fs from "fs";
88
+ import path from "path";
89
+ import {fileURLToPath} from "url";
90
+ import {initializeABAP} from "./init.mjs";
91
+ import runtime from "@abaplint/runtime";
92
+
93
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
94
+
95
+ async function run() {
96
+ await initializeABAP();
97
+ const unit = new runtime.UnitTestResult();
98
+ let clas;
99
+ let locl;
100
+ let meth;
100
101
  try {\n`;
101
102
  for (const obj of reg.getObjects()) {
102
103
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -110,9 +111,9 @@ async function run() {
110
111
  // todo, fix, there might be global test methods
111
112
  continue;
112
113
  }
113
- ret += ` {
114
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
115
- locl = clas.addTestClass("${def.name}");
114
+ ret += ` {
115
+ const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
116
+ locl = clas.addTestClass("${def.name}");
116
117
  if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
117
118
  for (const m of def.methods) {
118
119
  if (m.isForTesting === false) {
@@ -139,24 +140,24 @@ async function run() {
139
140
  }
140
141
  }
141
142
  }
142
- ret += `// -------------------END-------------------
143
- console.log(abap.console.get());
144
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
145
- } catch (e) {
146
- if (meth) {
147
- meth.fail();
148
- }
149
- console.log(abap.console.get());
150
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
151
- throw e;
152
- }
153
- }
154
-
155
- run().then(() => {
156
- process.exit(0);
157
- }).catch((err) => {
158
- console.log(err);
159
- process.exit(1);
143
+ ret += `// -------------------END-------------------
144
+ console.log(abap.console.get());
145
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
146
+ } catch (e) {
147
+ if (meth) {
148
+ meth.fail();
149
+ }
150
+ console.log(abap.console.get());
151
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
152
+ throw e;
153
+ }
154
+ }
155
+
156
+ run().then(() => {
157
+ process.exit(0);
158
+ }).catch((err) => {
159
+ console.log(err);
160
+ process.exit(1);
160
161
  });`;
161
162
  return ret;
162
163
  }
@@ -190,7 +191,7 @@ run().then(() => {
190
191
  }
191
192
  }
192
193
  list.sort();
193
- return list.join("\n") + "\n";
194
+ return list.join("\n");
194
195
  }
195
196
  }
196
197
  exports.UnitTest = UnitTest;
package/package.json CHANGED
@@ -1,41 +1,42 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.8.40",
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.86.6",
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.6",
37
- "mocha": "^9.2.2",
38
- "source-map-support": "^0.5.21",
39
- "typescript": "^4.6.3"
40
- }
41
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "2.0.2",
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:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
14
+ "publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
15
+ "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
16
+ "test": "npm run compile && mocha"
17
+ },
18
+ "mocha": {
19
+ "recursive": true,
20
+ "reporter": "progress",
21
+ "spec": "build/test/**/*.js",
22
+ "require": "source-map-support/register"
23
+ },
24
+ "keywords": [
25
+ "ABAP",
26
+ "abaplint"
27
+ ],
28
+ "author": "abaplint",
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@abaplint/core": "^2.88.2",
32
+ "source-map": "^0.7.3"
33
+ },
34
+ "devDependencies": {
35
+ "@types/chai": "^4.3.0",
36
+ "@types/mocha": "^9.1.0",
37
+ "chai": "^4.3.6",
38
+ "mocha": "^9.2.2",
39
+ "source-map-support": "^0.5.21",
40
+ "typescript": "^4.6.3"
41
+ }
42
+ }