@abaplint/transpiler 2.0.24 → 2.0.27

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
@@ -12,7 +12,10 @@ class SourceTranspiler {
12
12
  transpile(node, traversal) {
13
13
  let ret = new chunk_1.Chunk();
14
14
  const post = new chunk_1.Chunk();
15
- for (const c of node.getChildren()) {
15
+ const children = node.getChildren();
16
+ for (let i = 0; i < children.length; i++) {
17
+ const c = children[i];
18
+ const last = i === children.length - 1;
16
19
  if (c instanceof core_1.Nodes.ExpressionNode) {
17
20
  if (c.get() instanceof core_1.Expressions.FieldChain) {
18
21
  ret.appendChunk(new _1.FieldChainTranspiler(this.addGet).transpile(c, traversal));
@@ -35,14 +38,12 @@ class SourceTranspiler {
35
38
  }
36
39
  else if (c.get() instanceof core_1.Expressions.MethodCallChain) {
37
40
  ret.appendChunk(traversal.traverse(c));
38
- if (this.addGet) {
39
- const code = ret.getCode();
40
- if (code.includes("await")) {
41
- ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(").get()");
42
- }
43
- else {
44
- ret.append(".get()", c, traversal);
45
- }
41
+ const code = ret.getCode();
42
+ if (code.includes("await")) {
43
+ ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(")");
44
+ }
45
+ if (this.addGet && last === true) {
46
+ ret.append(".get()", c, traversal);
46
47
  }
47
48
  }
48
49
  else if (c.get() instanceof core_1.Expressions.Source) {
@@ -57,6 +58,9 @@ class SourceTranspiler {
57
58
  else if (c.get() instanceof core_1.Expressions.ComponentChain) {
58
59
  ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(").get().");
59
60
  ret.appendChunk(new _1.ComponentChainTranspiler().transpile(c, traversal));
61
+ if (this.addGet && last === true) {
62
+ ret.append(".get()", c, traversal);
63
+ }
60
64
  }
61
65
  else if (c.get() instanceof core_1.Expressions.Dereference) {
62
66
  ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(").getPointer()");
@@ -82,6 +86,7 @@ class SourceTranspiler {
82
86
  }
83
87
  }
84
88
  ret.appendChunk(post);
89
+ // console.dir(ret.getCode());
85
90
  return ret;
86
91
  }
87
92
  }
@@ -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: {
@@ -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
  }
@@ -15,7 +15,7 @@ class EndMethodTranspiler {
15
15
  const vars = scope.getData().vars;
16
16
  for (const n in vars) {
17
17
  const identifier = vars[n];
18
- if (identifier.getMeta().includes("returning" /* MethodReturning */)) {
18
+ if (identifier.getMeta().includes("returning" /* abaplint.IdentifierMeta.MethodReturning */)) {
19
19
  returning += "return " + n.toLowerCase() + ";\n";
20
20
  }
21
21
  }
@@ -31,14 +31,14 @@ class MethodImplementationTranspiler {
31
31
  for (const n in vars) {
32
32
  const identifier = vars[n];
33
33
  const varName = n.toLowerCase();
34
- if (identifier.getMeta().includes("importing" /* MethodImporting */)
35
- || identifier.getMeta().includes("changing" /* MethodChanging */)
36
- || identifier.getMeta().includes("exporting" /* MethodExporting */)) {
34
+ if (identifier.getMeta().includes("importing" /* abaplint.IdentifierMeta.MethodImporting */)
35
+ || identifier.getMeta().includes("changing" /* abaplint.IdentifierMeta.MethodChanging */)
36
+ || identifier.getMeta().includes("exporting" /* abaplint.IdentifierMeta.MethodExporting */)) {
37
37
  if (unique === "") {
38
38
  unique = "INPUT";
39
39
  }
40
40
  after = after + new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
41
- if (identifier.getMeta().includes("importing" /* MethodImporting */) && identifier.getType().isGeneric() === false) {
41
+ if (identifier.getMeta().includes("importing" /* abaplint.IdentifierMeta.MethodImporting */) && identifier.getType().isGeneric() === false) {
42
42
  after += "if (" + unique + " && " + unique + "." + varName + ") {" + varName + ".set(" + unique + "." + varName + ");}\n";
43
43
  }
44
44
  else {
@@ -71,7 +71,7 @@ class MethodImplementationTranspiler {
71
71
  after += "if (" + unique + " === undefined || " + unique + "." + varName + " === undefined) {" + varName + " = " + val + ";}\n";
72
72
  }
73
73
  }
74
- else if (identifier.getMeta().includes("returning" /* MethodReturning */)) {
74
+ else if (identifier.getMeta().includes("returning" /* abaplint.IdentifierMeta.MethodReturning */)) {
75
75
  after = after + new transpile_types_1.TranspileTypes().declare(identifier) + "\n";
76
76
  }
77
77
  }
@@ -9,7 +9,7 @@ class ReturnTranspiler {
9
9
  const vars = scope === null || scope === void 0 ? void 0 : scope.getData().vars;
10
10
  for (const n in vars) {
11
11
  const identifier = vars[n];
12
- if (identifier.getMeta().includes("returning" /* MethodReturning */)) {
12
+ if (identifier.getMeta().includes("returning" /* abaplint.IdentifierMeta.MethodReturning */)) {
13
13
  extra = " " + n.toLowerCase();
14
14
  }
15
15
  }
@@ -36,8 +36,8 @@ class InterfaceTranspiler {
36
36
  let ret = "\n";
37
37
  for (const n in vars) {
38
38
  const identifier = vars[n];
39
- if (identifier.getMeta().includes("static" /* Static */) === false
40
- || identifier.getMeta().includes("read_only" /* ReadOnly */) === false) {
39
+ if (identifier.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) === false
40
+ || identifier.getMeta().includes("read_only" /* abaplint.IdentifierMeta.ReadOnly */) === false) {
41
41
  continue;
42
42
  }
43
43
  const interfaceName = node.getFirstToken().getStr().toLowerCase();
@@ -154,7 +154,7 @@ class Traversal {
154
154
  const found = scope.findScopeForVariable(name);
155
155
  const id = scope.findVariable(name);
156
156
  if (found && id
157
- && id.getMeta().includes("static" /* Static */)
157
+ && id.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */)
158
158
  && found.stype === abaplint.ScopeType.ClassImplementation) {
159
159
  // console.dir(found.sname);
160
160
  return found.sname.toLowerCase();
@@ -261,7 +261,7 @@ class Traversal {
261
261
  ret += "this.me = new abap.types.ABAPObject();\n";
262
262
  ret += "this.me.set(this);\n";
263
263
  for (const a of def.getAttributes().getAll()) {
264
- if (a.getMeta().includes("static" /* Static */) === true) {
264
+ if (a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) === true) {
265
265
  continue;
266
266
  }
267
267
  const name = a.getName().toLowerCase();
@@ -305,7 +305,7 @@ class Traversal {
305
305
  let ret = "";
306
306
  const intf = this.findInterfaceDefinition(name, scope);
307
307
  for (const a of (intf === null || intf === void 0 ? void 0 : intf.getAttributes().getAll()) || []) {
308
- if (a.getMeta().includes("static" /* Static */) === true) {
308
+ if (a.getMeta().includes("static" /* abaplint.IdentifierMeta.Static */) === true) {
309
309
  continue;
310
310
  }
311
311
  const n = name.toLowerCase() + "$" + a.getName().toLowerCase();
@@ -6,11 +6,11 @@ const abaplint = require("@abaplint/core");
6
6
  class UnitTest {
7
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)}
13
-
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
+
14
14
  export async function initializeABAP() {\n`;
15
15
  ret += ` const sqlite = \`${dbSetup.schemas.sqlite}\`;\n`;
16
16
  ret += ` const hdb = \`${dbSetup.schemas.hdb}\`;\n`;
@@ -28,19 +28,19 @@ export async function initializeABAP() {\n`;
28
28
  return ret;
29
29
  }
30
30
  unitTestScriptOpen(reg, _skip, _only) {
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()});
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()});
44
44
  `;
45
45
  for (const obj of reg.getObjects()) {
46
46
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -60,44 +60,44 @@ async function run() {
60
60
  if (m.isForTesting === false) {
61
61
  continue;
62
62
  }
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()}");
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()}");
66
66
  abap.statements.append({source: ls_input, target: lt_input});`;
67
67
  }
68
68
  }
69
69
  }
70
70
  }
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);
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);
82
82
  });`;
83
83
  return ret;
84
84
  }
85
85
  unitTestScript(reg, skip, _only) {
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;
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;
101
101
  try {\n`;
102
102
  for (const obj of reg.getObjects()) {
103
103
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -111,9 +111,9 @@ async function run() {
111
111
  // todo, fix, there might be global test methods
112
112
  continue;
113
113
  }
114
- ret += ` {
115
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
116
- 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}");
117
117
  if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
118
118
  for (const m of def.methods) {
119
119
  if (m.isForTesting === false) {
@@ -140,24 +140,24 @@ async function run() {
140
140
  }
141
141
  }
142
142
  }
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);
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);
161
161
  });`;
162
162
  return ret;
163
163
  }
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "2.0.24",
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.90.4",
32
- "source-map": "^0.7.3"
33
- },
34
- "devDependencies": {
35
- "@types/chai": "^4.3.1",
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.6.4"
41
- }
42
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "2.0.27",
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.90.9",
32
+ "source-map": "^0.7.3"
33
+ },
34
+ "devDependencies": {
35
+ "@types/chai": "^4.3.1",
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.7.2"
41
+ }
42
+ }