@abaplint/transpiler 2.0.51 → 2.0.52

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.
@@ -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, _e;
31
+ var _a, _b, _c, _d, _e, _f;
32
32
  reg.parse();
33
33
  new keywords_1.Keywords().handle(reg);
34
34
  this.validate(reg);
@@ -38,6 +38,7 @@ class Transpiler {
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
40
  initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_e = this.options) === null || _e === void 0 ? void 0 : _e.extraSetup),
41
+ initializationScript2: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_f = this.options) === null || _f === void 0 ? void 0 : _f.extraSetup, true),
41
42
  databaseSetup: dbSetup,
42
43
  reg: reg,
43
44
  };
@@ -17,6 +17,7 @@ export interface IOutput {
17
17
  unitTestScript: string;
18
18
  unitTestScriptOpen: string;
19
19
  initializationScript: string;
20
+ initializationScript2: string;
20
21
  databaseSetup: DatabaseSetupResult;
21
22
  }
22
23
  export interface IRequire {
@@ -6,7 +6,7 @@ export declare type TestMethodList = {
6
6
  method: string;
7
7
  }[];
8
8
  export declare class UnitTest {
9
- initializationScript(reg: abaplint.IRegistry, dbSetup: DatabaseSetupResult, extraSetup?: string): string;
9
+ initializationScript(reg: abaplint.IRegistry, dbSetup: DatabaseSetupResult, extraSetup?: string, useImport?: boolean): string;
10
10
  private escapeNamespace;
11
11
  unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
12
12
  unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
@@ -5,11 +5,11 @@ exports.UnitTest = void 0;
5
5
  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
- initializationScript(reg, dbSetup, extraSetup) {
8
+ initializationScript(reg, dbSetup, extraSetup, useImport) {
9
9
  let ret = `/* eslint-disable import/newline-after-import */
10
10
  import runtime from "@abaplint/runtime";
11
11
  globalThis.abap = new runtime.ABAP();
12
- ${this.buildImports(reg)}
12
+ ${this.buildImports(reg, useImport)}
13
13
 
14
14
  export async function initializeABAP() {\n`;
15
15
  ret += ` const sqlite = \`${dbSetup.schemas.sqlite}\`;\n`;
@@ -165,37 +165,38 @@ run().then(() => {
165
165
  });`;
166
166
  return ret;
167
167
  }
168
- buildImports(reg) {
169
- // note: ES modules are hoised, so use the dynamic import()
168
+ buildImports(reg, useImport) {
169
+ // note: ES modules are hoised, so use the dynamic import(), hmm, but why?
170
170
  // todo, some sorting might be required? eg. a class constructor using constant from interface?
171
171
  // temporary sorting: by filename
172
172
  const list = [];
173
- for (const obj of reg.getObjects()) {
174
- if (obj instanceof abaplint.Objects.Table) {
175
- list.push(`await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.tabl.mjs");`);
173
+ const imp = (filename) => {
174
+ if (useImport === true) {
175
+ return `import "./${filename}.mjs";`;
176
176
  }
177
- else if (obj instanceof abaplint.Objects.DataElement) {
178
- list.push(`await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.dtel.mjs");`);
177
+ else {
178
+ return `await import("./${filename}.mjs");`;
179
179
  }
180
- else if (obj instanceof abaplint.Objects.TableType) {
181
- list.push(`await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.ttyp.mjs");`);
180
+ };
181
+ for (const obj of reg.getObjects()) {
182
+ if (obj instanceof abaplint.Objects.Table
183
+ || obj instanceof abaplint.Objects.DataElement
184
+ || obj instanceof abaplint.Objects.TableType) {
185
+ list.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
182
186
  }
183
187
  }
184
188
  for (const obj of reg.getObjects()) {
185
189
  if (obj instanceof abaplint.Objects.FunctionGroup) {
186
190
  for (const m of obj.getModules()) {
187
- list.push(`await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.fugr.${m.getName().toLowerCase()}.mjs");`);
191
+ list.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.fugr.${m.getName().toLowerCase()}`));
188
192
  }
189
193
  }
190
- else if (obj instanceof abaplint.Objects.Class) {
191
- list.push(`await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.clas.mjs");`);
192
- }
193
- else if (obj instanceof abaplint.Objects.Interface) {
194
- list.push(`await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.intf.mjs");`);
194
+ else if (obj instanceof abaplint.Objects.Class
195
+ || obj instanceof abaplint.Objects.Interface) {
196
+ list.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
195
197
  }
196
198
  }
197
- list.sort();
198
- return list.join("\n");
199
+ return list.sort().join("\n");
199
200
  }
200
201
  }
201
202
  exports.UnitTest = UnitTest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.0.51",
3
+ "version": "2.0.52",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "author": "abaplint",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@abaplint/core": "^2.91.5",
31
+ "@abaplint/core": "^2.91.6",
32
32
  "source-map": "^0.7.4"
33
33
  },
34
34
  "devDependencies": {