@abaplint/transpiler 1.8.1 → 1.8.5

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.
@@ -36,6 +36,7 @@ export * from "./simple_source3";
36
36
  export * from "./simple_source4";
37
37
  export * from "./source_field_symbol";
38
38
  export * from "./source";
39
+ export * from "./sql_source_simple";
39
40
  export * from "./sql_source";
40
41
  export * from "./string_template_source";
41
42
  export * from "./string_template";
@@ -48,6 +48,7 @@ __exportStar(require("./simple_source3"), exports);
48
48
  __exportStar(require("./simple_source4"), exports);
49
49
  __exportStar(require("./source_field_symbol"), exports);
50
50
  __exportStar(require("./source"), exports);
51
+ __exportStar(require("./sql_source_simple"), exports);
51
52
  __exportStar(require("./sql_source"), exports);
52
53
  __exportStar(require("./string_template_source"), exports);
53
54
  __exportStar(require("./string_template"), exports);
@@ -0,0 +1,7 @@
1
+ import { Nodes } from "@abaplint/core";
2
+ import { IExpressionTranspiler } from "./_expression_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class SQLSourceSimpleTranspiler implements IExpressionTranspiler {
6
+ transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SQLSourceSimpleTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ class SQLSourceSimpleTranspiler {
6
+ transpile(node, traversal) {
7
+ let s = node.findDirectExpression(abaplint.Expressions.Source);
8
+ if (s === undefined) {
9
+ s = node.findDirectExpression(abaplint.Expressions.SimpleSource3);
10
+ }
11
+ return traversal.traverse(s);
12
+ }
13
+ }
14
+ exports.SQLSourceSimpleTranspiler = SQLSourceSimpleTranspiler;
15
+ //# sourceMappingURL=sql_source_simple.js.map
@@ -11,8 +11,18 @@ class HandleDataElement {
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
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
14
+ let fixedValues = undefined;
15
+ if (obj.getDomainName()) {
16
+ const doma = reg.getObject("DOMA", obj.getDomainName());
17
+ if (doma) {
18
+ fixedValues = doma.getFixedValues();
19
+ }
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)},
16
26
  };`);
17
27
  const output = {
18
28
  object: {
@@ -12,9 +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
- "type": ${new transpile_types_1.TranspileTypes().toType(type)},
17
- "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())},
18
19
  };`);
19
20
  const output = {
20
21
  object: {
@@ -11,8 +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
- "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)},
16
17
  };`);
17
18
  const output = {
18
19
  object: {
@@ -3,5 +3,5 @@ import { IStatementTranspiler } from "./_statement_transpiler";
3
3
  import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class DeleteDatabaseTranspiler implements IStatementTranspiler {
6
- transpile(_node: abaplint.Nodes.StatementNode, _traversal: Traversal): Chunk;
6
+ transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
7
  }
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeleteDatabaseTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
4
5
  const chunk_1 = require("../chunk");
5
6
  class DeleteDatabaseTranspiler {
6
- transpile(_node, _traversal) {
7
- return new chunk_1.Chunk(`throw new Error("DeleteDatabase, transpiler todo");`);
7
+ transpile(node, traversal) {
8
+ const table = traversal.traverse(node.findFirstExpression(abaplint.Expressions.DatabaseTable));
9
+ const options = [];
10
+ const tab = node.findExpressionAfterToken("TABLE");
11
+ if (tab) {
12
+ const ttab = traversal.traverse(tab);
13
+ options.push(`"table": ` + ttab.getCode());
14
+ }
15
+ return new chunk_1.Chunk(`abap.statements.deleteDatabase(${table.getCode()}, {${options.join(", ")}});`);
8
16
  }
9
17
  }
10
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
  }
@@ -102,7 +102,7 @@ class MethodImplementationTranspiler {
102
102
  const intfName = split[0];
103
103
  name = split[1];
104
104
  const scope = traversal.findCurrentScopeByToken(cdef.getToken());
105
- const intf = scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(intfName);
105
+ const intf = traversal.findInterfaceDefinition(intfName, scope);
106
106
  return (_a = intf === null || intf === void 0 ? void 0 : intf.getMethodDefinitions()) === null || _a === void 0 ? void 0 : _a.getByName(name);
107
107
  }
108
108
  else {
@@ -6,9 +6,9 @@ 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
8
  initializationScript(reg, dbSetup) {
9
- let ret = `import runtime from "@abaplint/runtime";
10
- global.abap = new runtime.ABAP();
11
- ${this.buildImports(reg)}
9
+ let ret = `import runtime from "@abaplint/runtime";
10
+ global.abap = new runtime.ABAP();
11
+ ${this.buildImports(reg)}
12
12
  export async function initializeABAP(settings) {\n`;
13
13
  if (dbSetup === "") {
14
14
  ret += `// no database artifacts, skip DB initialization\n`;
@@ -20,19 +20,19 @@ export async function initializeABAP(settings) {\n`;
20
20
  return ret;
21
21
  }
22
22
  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()});
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()});
36
36
  `;
37
37
  for (const obj of reg.getObjects()) {
38
38
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -52,44 +52,44 @@ async function run() {
52
52
  if (m.isForTesting === false) {
53
53
  continue;
54
54
  }
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()}");
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()}");
58
58
  abap.statements.append({source: ls_input, target: lt_input});`;
59
59
  }
60
60
  }
61
61
  }
62
62
  }
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);
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);
74
74
  });`;
75
75
  return ret;
76
76
  }
77
77
  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;
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;
93
93
  try {\n`;
94
94
  for (const obj of reg.getObjects()) {
95
95
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -103,9 +103,9 @@ async function run() {
103
103
  // todo, fix, there might be global test methods
104
104
  continue;
105
105
  }
106
- ret += ` {
107
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
108
- locl = clas.addTestClass("${def.name}");
106
+ ret += ` {
107
+ const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
108
+ locl = clas.addTestClass("${def.name}");
109
109
  if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
110
110
  for (const m of def.methods) {
111
111
  if (m.isForTesting === false) {
@@ -132,24 +132,24 @@ async function run() {
132
132
  }
133
133
  }
134
134
  }
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);
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);
153
153
  });`;
154
154
  return ret;
155
155
  }
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.8.1",
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.12",
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.5",
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.17",
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
+ }