@abaplint/transpiler 1.7.6 → 1.7.10

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.
@@ -31,6 +31,7 @@ class DatabaseSetup {
31
31
  }
32
32
  const type = obj.parseType(this.reg);
33
33
  if (type instanceof abaplint.BasicTypes.StructureType && type.getComponents().length === 3) {
34
+ // todo, this should take the client number from the settings
34
35
  return `INSERT INTO t000 VALUES ('123', '', '');\n`;
35
36
  }
36
37
  else {
@@ -1,6 +1,6 @@
1
1
  import * as abaplint from "@abaplint/core";
2
2
  import { config } from "./validation";
3
- import { SkipSettings } from "./unit_test";
3
+ import { TestMethodList } from "./unit_test";
4
4
  import { Chunk } from "./chunk";
5
5
  export { config };
6
6
  export interface IFile {
@@ -46,7 +46,8 @@ export interface ITranspilerOptions {
46
46
  skipConstants?: boolean;
47
47
  /** sets behavior for unknown types, either fail at compile- or run-time */
48
48
  unknownTypes?: "compileError" | "runtimeError";
49
- skip?: SkipSettings;
49
+ skip?: TestMethodList;
50
+ only?: TestMethodList;
50
51
  }
51
52
  export declare class Transpiler {
52
53
  private readonly options;
@@ -28,14 +28,14 @@ class Transpiler {
28
28
  return new Transpiler().run(reg);
29
29
  }
30
30
  async run(reg, progress) {
31
- var _a;
31
+ var _a, _b;
32
32
  reg.parse();
33
33
  new keywords_1.Keywords().handle(reg);
34
34
  this.validate(reg);
35
35
  const dbSetup = new database_setup_1.DatabaseSetup(reg).run();
36
36
  const output = {
37
37
  objects: [],
38
- unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_a = this.options) === null || _a === void 0 ? void 0 : _a.skip),
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
  initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup),
40
40
  databaseSetup: dbSetup,
41
41
  reg: reg,
@@ -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 CreateDataTranspiler 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,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CreateDataTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
4
5
  const chunk_1 = require("../chunk");
5
6
  class CreateDataTranspiler {
6
- transpile(_node, _traversal) {
7
- return new chunk_1.Chunk(`throw "CreateDataTranspiler-todo";`);
7
+ transpile(node, traversal) {
8
+ const targetNode = node.findDirectExpression(abaplint.Expressions.Target);
9
+ const target = traversal.traverse(targetNode);
10
+ return new chunk_1.Chunk("abap.statements.createData(" + target.getCode() + ");");
8
11
  }
9
12
  }
10
13
  exports.CreateDataTranspiler = CreateDataTranspiler;
@@ -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,11 +1,11 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- export declare type SkipSettings = {
2
+ export declare type TestMethodList = {
3
3
  object: string;
4
4
  class: string;
5
5
  method: string;
6
6
  }[];
7
7
  export declare class UnitTest {
8
8
  initializationScript(reg: abaplint.IRegistry, dbSetup: string): string;
9
- unitTestScript(reg: abaplint.IRegistry, skip?: SkipSettings): string;
9
+ unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
10
10
  private buildImports;
11
11
  }
@@ -3,29 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnitTest = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  class UnitTest {
6
+ // todo, move this somewhere else, its much more than just unit test relevant
6
7
  initializationScript(reg, dbSetup) {
7
- return `import runtime from "@abaplint/runtime";
8
- global.abap = new runtime.ABAP();
9
- ${this.buildImports(reg)}
10
- export async function initDB() {
11
- return global.abap.initDB(\`${dbSetup}\`);
12
- }`;
8
+ let ret = `import runtime from "@abaplint/runtime";
9
+ global.abap = new runtime.ABAP();
10
+ ${this.buildImports(reg)}
11
+ export async function initializeABAP(settings) {\n`;
12
+ if (dbSetup === "") {
13
+ ret += `// no database artifacts, skip DB initialization\n`;
14
+ }
15
+ else {
16
+ ret += ` await global.abap.initDB(\`${dbSetup}\`);\n`;
17
+ }
18
+ ret += `}`;
19
+ return ret;
13
20
  }
14
- unitTestScript(reg, skip) {
15
- let ret = `import fs from "fs";
16
- import path from "path";
17
- import {dirname} from 'path';
18
- import {fileURLToPath} from 'url';
19
- const __dirname = dirname(fileURLToPath(import.meta.url));
20
- import {initDB} from "./init.mjs";
21
- import runtime from "@abaplint/runtime";
22
-
23
- async function run() {
24
- await initDB();
25
- const unit = new runtime.UnitTestResult();
26
- let clas;
27
- let locl;
28
- let meth;
21
+ unitTestScript(reg, skip, _only) {
22
+ let ret = `import fs from "fs";
23
+ import path from "path";
24
+ import {dirname} from 'path';
25
+ import {fileURLToPath} from 'url';
26
+ const __dirname = dirname(fileURLToPath(import.meta.url));
27
+ import {initializeABAP} from "./init.mjs";
28
+ import runtime from "@abaplint/runtime";
29
+
30
+ async function run() {
31
+ await initializeABAP();
32
+ const unit = new runtime.UnitTestResult();
33
+ let clas;
34
+ let locl;
35
+ let meth;
29
36
  try {\n`;
30
37
  for (const obj of reg.getObjects()) {
31
38
  if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
@@ -40,8 +47,8 @@ try {\n`;
40
47
  || def.methods.length === 0) {
41
48
  continue;
42
49
  }
43
- ret += `{
44
- const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
50
+ ret += `{
51
+ const {${def.name}} = await import("./${obj.getName().toLowerCase()}.${obj.getType().toLowerCase()}.testclasses.mjs");
45
52
  locl = clas.addTestClass("${def.name}");\n`;
46
53
  ret += `if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
47
54
  for (const m of def.methods) {
@@ -69,24 +76,24 @@ locl = clas.addTestClass("${def.name}");\n`;
69
76
  }
70
77
  }
71
78
  }
72
- ret += `// -------------------END-------------------
73
- console.log(abap.console.get());
74
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
75
- } catch (e) {
76
- if (meth) {
77
- meth.fail();
78
- }
79
- console.log(abap.console.get());
80
- fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
81
- throw e;
82
- }
83
- }
84
-
85
- run().then(() => {
86
- process.exit();
87
- }).catch((err) => {
88
- console.log(err);
89
- process.exit(1);
79
+ ret += `// -------------------END-------------------
80
+ console.log(abap.console.get());
81
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
82
+ } catch (e) {
83
+ if (meth) {
84
+ meth.fail();
85
+ }
86
+ console.log(abap.console.get());
87
+ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
88
+ throw e;
89
+ }
90
+ }
91
+
92
+ run().then(() => {
93
+ process.exit(0);
94
+ }).catch((err) => {
95
+ console.log(err);
96
+ process.exit(1);
90
97
  });`;
91
98
  return ret;
92
99
  }
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@abaplint/transpiler",
3
- "version": "1.7.6",
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.83.21",
31
- "source-map": "^0.7.3"
32
- },
33
- "devDependencies": {
34
- "@types/chai": "^4.3.0",
35
- "@types/mocha": "^9.0.0",
36
- "chai": "^4.3.4",
37
- "mocha": "^9.1.3",
38
- "source-map-support": "^0.5.21",
39
- "typescript": "^4.5.4"
40
- }
41
- }
1
+ {
2
+ "name": "@abaplint/transpiler",
3
+ "version": "1.7.10",
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.83.23",
31
+ "source-map": "^0.7.3"
32
+ },
33
+ "devDependencies": {
34
+ "@types/chai": "^4.3.0",
35
+ "@types/mocha": "^9.0.0",
36
+ "chai": "^4.3.4",
37
+ "mocha": "^9.1.3",
38
+ "source-map-support": "^0.5.21",
39
+ "typescript": "^4.5.4"
40
+ }
41
+ }