@abaplint/transpiler 2.1.61 → 2.1.62

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
@@ -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: {
@@ -26,9 +26,9 @@ class CallTranspiler {
26
26
  }
27
27
  post += ";";
28
28
  if (exceptions) {
29
- post += `\nabap.builtin.sy.get().subrc.set(0);
30
- } catch (e) {
31
- if (e.classic) {
29
+ post += `\nabap.builtin.sy.get().subrc.set(0);
30
+ } catch (e) {
31
+ if (e.classic) {
32
32
  switch (e.classic.toUpperCase()) {\n`;
33
33
  for (const e of exceptions.findAllExpressions(abaplint.Expressions.ParameterException)) {
34
34
  const name = e.getFirstToken().getStr().toUpperCase();
@@ -43,10 +43,10 @@ if (e.classic) {
43
43
  post += `case "${name}": abap.builtin.sy.get().subrc.set(${value}); break;\n`;
44
44
  }
45
45
  }
46
- post += ` }
47
- } else {
48
- throw e;
49
- }
46
+ post += ` }
47
+ } else {
48
+ throw e;
49
+ }
50
50
  }`;
51
51
  }
52
52
  return new chunk_1.Chunk()
@@ -17,8 +17,8 @@ class ClassImplementationTranspiler {
17
17
  else if (def === null || def === void 0 ? void 0 : def.getSuperClass()) {
18
18
  ret += " extends " + ((_a = def === null || def === void 0 ? void 0 : def.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
19
19
  }
20
- return new chunk_1.Chunk().append(ret + ` {
21
- static INTERNAL_TYPE = 'CLAS';
20
+ return new chunk_1.Chunk().append(ret + ` {
21
+ static INTERNAL_TYPE = 'CLAS';
22
22
  static IMPLEMENTED_INTERFACES = [${def === null || def === void 0 ? void 0 : def.getImplementing().map(e => `"` + e.name.toUpperCase() + `"`).join(",")}];`, node, traversal);
23
23
  }
24
24
  }
@@ -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
  }
@@ -69,14 +69,14 @@ class SelectTranspiler {
69
69
  const faeName = (_d = (_c = (_b = node.findFirstExpression(abaplint.Expressions.SQLForAllEntries)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(abaplint.Expressions.SQLSource)) === null || _c === void 0 ? void 0 : _c.concatTokens()) === null || _d === void 0 ? void 0 : _d.toLowerCase();
70
70
  select = select.replace(new RegExp(" " + faeName, "g"), " " + unique);
71
71
  select = select.replace(unique + ".get().table_line.get()", unique + ".get()"); // there can be only one?
72
- const code = `if (${faeName}.array().length === 0) {
73
- throw "FAE, todo, empty table";
74
- } else {
75
- abap.statements.clear(${target});
76
- for await (const ${unique} of abap.statements.loop(${faeName})) {
77
- await abap.statements.select(${target}, {select: "${select.trim()}"${extra}}, {appending: true});
78
- }
79
- abap.builtin.sy.get().dbcnt.set(${target}.array().length);
72
+ const code = `if (${faeName}.array().length === 0) {
73
+ throw "FAE, todo, empty table";
74
+ } else {
75
+ abap.statements.clear(${target});
76
+ for await (const ${unique} of abap.statements.loop(${faeName})) {
77
+ await abap.statements.select(${target}, {select: "${select.trim()}"${extra}}, {appending: true});
78
+ }
79
+ abap.builtin.sy.get().dbcnt.set(${target}.array().length);
80
80
  }`;
81
81
  return new chunk_1.Chunk().append(code, node, traversal);
82
82
  }
@@ -20,14 +20,14 @@ class ClassDefinitionTranspiler {
20
20
  }
21
21
  else {
22
22
  // its an abstract class with only abstract methods
23
- return new chunk_1.Chunk(`
24
- class ${className === null || className === void 0 ? void 0 : className.toLowerCase()} {
25
- static INTERNAL_TYPE = 'CLAS';
26
- async constructor_() {
27
- this.me = new abap.types.ABAPObject();
28
- this.me.set(this);
29
- return this;
30
- }
23
+ return new chunk_1.Chunk(`
24
+ class ${className === null || className === void 0 ? void 0 : className.toLowerCase()} {
25
+ static INTERNAL_TYPE = 'CLAS';
26
+ async constructor_() {
27
+ this.me = new abap.types.ABAPObject();
28
+ this.me.set(this);
29
+ return this;
30
+ }
31
31
  }`);
32
32
  }
33
33
  }
@@ -8,16 +8,16 @@ class UnitTest {
8
8
  initializationScript(reg, dbSetup, extraSetup, useImport) {
9
9
  let ret = "";
10
10
  if (useImport === true) {
11
- ret = `/* eslint-disable import/newline-after-import */
11
+ ret = `/* eslint-disable import/newline-after-import */
12
12
  import "./_top.mjs";\n`;
13
13
  }
14
14
  else {
15
- ret = `/* eslint-disable import/newline-after-import */
16
- import runtime from "@abaplint/runtime";
15
+ ret = `/* eslint-disable import/newline-after-import */
16
+ import runtime from "@abaplint/runtime";
17
17
  globalThis.abap = new runtime.ABAP();\n`;
18
18
  }
19
- ret += `${this.buildImports(reg, useImport)}
20
-
19
+ ret += `${this.buildImports(reg, useImport)}
20
+
21
21
  export async function initializeABAP() {\n`;
22
22
  ret += ` const sqlite = [];\n`;
23
23
  for (const i of dbSetup.schemas.sqlite) {
@@ -45,19 +45,19 @@ export async function initializeABAP() {\n`;
45
45
  return filename.replace(/\//g, "%23");
46
46
  }
47
47
  unitTestScriptOpen(reg, _skip, _only) {
48
- let ret = `/* eslint-disable curly */
49
- import fs from "fs";
50
- import path from "path";
51
- import {fileURLToPath} from "url";
52
- import {initializeABAP} from "./init.mjs";
53
-
54
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
55
-
56
- async function run() {
57
- await initializeABAP();
58
- 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":[]});
59
- 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})});
60
- 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()});
48
+ let ret = `/* eslint-disable curly */
49
+ import fs from "fs";
50
+ import path from "path";
51
+ import {fileURLToPath} from "url";
52
+ import {initializeABAP} from "./init.mjs";
53
+
54
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
55
+
56
+ async function run() {
57
+ await initializeABAP();
58
+ 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":[]});
59
+ 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})});
60
+ 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()});
61
61
  `;
62
62
  for (const obj of reg.getObjects()) {
63
63
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -77,44 +77,44 @@ async function run() {
77
77
  if (m.isForTesting === false) {
78
78
  continue;
79
79
  }
80
- ret += ` ls_input.get().class_name.set("${obj.getName()}");
81
- ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
82
- ls_input.get().method_name.set("${m.name.toUpperCase()}");
80
+ ret += ` ls_input.get().class_name.set("${obj.getName()}");
81
+ ls_input.get().testclass_name.set("${def.name.toUpperCase()}");
82
+ ls_input.get().method_name.set("${m.name.toUpperCase()}");
83
83
  abap.statements.append({source: ls_input, target: lt_input});\n`;
84
84
  }
85
85
  }
86
86
  }
87
87
  }
88
- ret += `
89
-
90
- ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
91
- fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
92
- }
93
-
94
- run().then(() => {
95
- process.exit(0);
96
- }).catch((err) => {
97
- console.log(err);
98
- process.exit(1);
88
+ ret += `
89
+
90
+ ls_result.set(await abap.Classes["KERNEL_UNIT_RUNNER"].run({it_input: lt_input}));
91
+ fs.writeFileSync(__dirname + path.sep + "output.json", ls_result.get().json.get());
92
+ }
93
+
94
+ run().then(() => {
95
+ process.exit(0);
96
+ }).catch((err) => {
97
+ console.log(err);
98
+ process.exit(1);
99
99
  });`;
100
100
  return ret;
101
101
  }
102
102
  unitTestScript(reg, skip, _only) {
103
- let ret = `/* eslint-disable curly */
104
- import fs from "fs";
105
- import path from "path";
106
- import {fileURLToPath} from "url";
107
- import {initializeABAP} from "./init.mjs";
108
- import runtime from "@abaplint/runtime";
109
-
110
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
111
-
112
- async function run() {
113
- await initializeABAP();
114
- const unit = new runtime.UnitTestResult();
115
- let clas;
116
- let locl;
117
- let meth;
103
+ let ret = `/* eslint-disable curly */
104
+ import fs from "fs";
105
+ import path from "path";
106
+ import {fileURLToPath} from "url";
107
+ import {initializeABAP} from "./init.mjs";
108
+ import runtime from "@abaplint/runtime";
109
+
110
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
111
+
112
+ async function run() {
113
+ await initializeABAP();
114
+ const unit = new runtime.UnitTestResult();
115
+ let clas;
116
+ let locl;
117
+ let meth;
118
118
  try {\n`;
119
119
  for (const obj of reg.getObjects()) {
120
120
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -128,9 +128,9 @@ async function run() {
128
128
  // todo, fix, there might be global test methods
129
129
  continue;
130
130
  }
131
- ret += ` {
132
- const {${def.name}} = await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}.testclasses.mjs");
133
- locl = clas.addTestClass("${def.name}");
131
+ ret += ` {
132
+ const {${def.name}} = await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}.testclasses.mjs");
133
+ locl = clas.addTestClass("${def.name}");
134
134
  if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
135
135
  for (const m of def.methods) {
136
136
  if (m.isForTesting === false) {
@@ -157,24 +157,24 @@ async function run() {
157
157
  }
158
158
  }
159
159
  }
160
- ret += `// -------------------END-------------------
161
- console.log(abap.console.get());
162
- fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
163
- } catch (e) {
164
- if (meth) {
165
- meth.fail();
166
- }
167
- console.log(abap.console.get());
168
- fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
169
- throw e;
170
- }
171
- }
172
-
173
- run().then(() => {
174
- process.exit(0);
175
- }).catch((err) => {
176
- console.log(err);
177
- process.exit(1);
160
+ ret += `// -------------------END-------------------
161
+ console.log(abap.console.get());
162
+ fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
163
+ } catch (e) {
164
+ if (meth) {
165
+ meth.fail();
166
+ }
167
+ console.log(abap.console.get());
168
+ fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
169
+ throw e;
170
+ }
171
+ }
172
+
173
+ run().then(() => {
174
+ process.exit(0);
175
+ }).catch((err) => {
176
+ console.log(err);
177
+ process.exit(1);
178
178
  });`;
179
179
  return ret;
180
180
  }
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "2.1.61",
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.93.12",
32
- "source-map": "^0.7.4"
33
- },
34
- "devDependencies": {
35
- "@types/chai": "^4.3.3",
36
- "@types/mocha": "^9.1.1",
37
- "chai": "^4.3.6",
38
- "mocha": "^10.0.0",
39
- "source-map-support": "^0.5.21",
40
- "typescript": "^4.8.3"
41
- }
42
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "2.1.62",
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.93.12",
32
+ "source-map": "^0.7.4"
33
+ },
34
+ "devDependencies": {
35
+ "@types/chai": "^4.3.3",
36
+ "@types/mocha": "^9.1.1",
37
+ "chai": "^4.3.6",
38
+ "mocha": "^10.0.0",
39
+ "source-map-support": "^0.5.21",
40
+ "typescript": "^4.8.3"
41
+ }
42
+ }