@abaplint/transpiler 1.8.9 → 1.8.12

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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -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: {
@@ -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, _c, _d;
31
+ var _a, _b, _c, _d, _e;
32
32
  reg.parse();
33
33
  new keywords_1.Keywords().handle(reg);
34
34
  this.validate(reg);
@@ -37,7 +37,7 @@ class Transpiler {
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
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),
40
- initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup),
40
+ initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_e = this.options) === null || _e === void 0 ? void 0 : _e.extraSetup),
41
41
  databaseSetup: dbSetup,
42
42
  reg: reg,
43
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
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -47,4 +47,6 @@ export interface ITranspilerOptions {
47
47
  unknownTypes?: "compileError" | "runtimeError";
48
48
  skip?: TestMethodList;
49
49
  only?: TestMethodList;
50
+ /** extra setup script to be executed during initialization */
51
+ extraSetup?: string;
50
52
  }
@@ -5,7 +5,7 @@ export declare type TestMethodList = {
5
5
  method: string;
6
6
  }[];
7
7
  export declare class UnitTest {
8
- initializationScript(reg: abaplint.IRegistry, dbSetup: string): string;
8
+ initializationScript(reg: abaplint.IRegistry, dbSetup: string, extraSetup?: string): string;
9
9
  unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
10
10
  unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
11
11
  private buildImports;
@@ -5,34 +5,41 @@ exports.UnitTest = void 0;
5
5
  const abaplint = require("@abaplint/core");
6
6
  class UnitTest {
7
7
  // todo, move this somewhere else, its much more than just unit test relevant
8
- initializationScript(reg, dbSetup) {
9
- let ret = `import runtime from "@abaplint/runtime";
10
- global.abap = new runtime.ABAP();
11
- ${this.buildImports(reg)}
12
- export async function initializeABAP(settings) {\n`;
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)}
13
+ export async function initializeABAP() {\n`;
13
14
  if (dbSetup === "") {
14
15
  ret += `// no database artifacts, skip DB initialization\n`;
15
16
  }
16
17
  else {
17
18
  ret += ` await global.abap.initDB(\`${dbSetup}\`);\n`;
18
19
  }
20
+ if (extraSetup === undefined) {
21
+ ret += `// no extra setup\n`;
22
+ }
23
+ else {
24
+ ret += ` await import("../test/extra.mjs");\n`;
25
+ }
19
26
  ret += `}`;
20
27
  return ret;
21
28
  }
22
29
  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()});
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()});
36
43
  `;
37
44
  for (const obj of reg.getObjects()) {
38
45
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -52,44 +59,44 @@ async function run() {
52
59
  if (m.isForTesting === false) {
53
60
  continue;
54
61
  }
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()}");
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()}");
58
65
  abap.statements.append({source: ls_input, target: lt_input});`;
59
66
  }
60
67
  }
61
68
  }
62
69
  }
63
- ret += `
64
-
65
- ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
66
- fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
67
- }
68
-
69
- run().then(() => {
70
- process.exit(0);
71
- }).catch((err) => {
72
- console.log(err);
73
- process.exit(1);
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);
74
81
  });`;
75
82
  return ret;
76
83
  }
77
84
  unitTestScript(reg, skip, _only) {
78
- let ret = `/* eslint-disable curly */
79
- import fs from "fs";
80
- import path from "path";
81
- import {fileURLToPath} from "url";
82
- import {initializeABAP} from "./init.mjs";
83
- import runtime from "@abaplint/runtime";
84
-
85
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
86
-
87
- async function run() {
88
- await initializeABAP();
89
- const unit = new runtime.UnitTestResult();
90
- let clas;
91
- let locl;
92
- let meth;
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;
93
100
  try {\n`;
94
101
  for (const obj of reg.getObjects()) {
95
102
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -103,9 +110,9 @@ async function run() {
103
110
  // todo, fix, there might be global test methods
104
111
  continue;
105
112
  }
106
- ret += ` {
107
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
108
- locl = clas.addTestClass("${def.name}");
113
+ ret += ` {
114
+ const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
115
+ locl = clas.addTestClass("${def.name}");
109
116
  if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
110
117
  for (const m of def.methods) {
111
118
  if (m.isForTesting === false) {
@@ -132,24 +139,24 @@ async function run() {
132
139
  }
133
140
  }
134
141
  }
135
- ret += `// -------------------END-------------------
136
- console.log(abap.console.get());
137
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
138
- } catch (e) {
139
- if (meth) {
140
- meth.fail();
141
- }
142
- console.log(abap.console.get());
143
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
144
- throw e;
145
- }
146
- }
147
-
148
- run().then(() => {
149
- process.exit(0);
150
- }).catch((err) => {
151
- console.log(err);
152
- process.exit(1);
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);
153
160
  });`;
154
161
  return ret;
155
162
  }
@@ -28,7 +28,7 @@ exports.config = {
28
28
  },
29
29
  "parser_error": true,
30
30
  "allowed_object_types": {
31
- "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "XSLT", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
31
+ "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "XSLT", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
32
32
  },
33
33
  "exit_or_check": {
34
34
  "allowCheck": true,
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.8.9",
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.85.19",
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.0",
38
- "source-map-support": "^0.5.21",
39
- "typescript": "^4.5.5"
40
- }
41
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "1.8.12",
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.85.36",
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.1",
38
+ "source-map-support": "^0.5.21",
39
+ "typescript": "^4.6.2"
40
+ }
41
+ }