@abaplint/transpiler 1.7.9 → 1.7.14

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.
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CreateObjectTranspiler = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
5
  const chunk_1 = require("../chunk");
6
+ const expressions_1 = require("../expressions");
6
7
  class CreateObjectTranspiler {
7
8
  transpile(node, traversal) {
8
- var _a;
9
+ var _a, _b;
9
10
  const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target)).getCode();
10
11
  let para = "";
11
12
  const parameters = node.findFirstExpression(abaplint.Expressions.ParameterListS);
@@ -13,16 +14,24 @@ class CreateObjectTranspiler {
13
14
  para = traversal.traverse(parameters).getCode();
14
15
  }
15
16
  let name = "";
16
- const dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
17
+ let directGlobal = false;
18
+ let dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
17
19
  if (dynamic) {
18
20
  name = dynamic.getFirstToken().getStr();
19
21
  name = name.substring(1, name.length - 1);
20
22
  }
21
23
  else {
24
+ dynamic = (_b = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldChain);
25
+ if (dynamic) {
26
+ name = new expressions_1.FieldChainTranspiler(true).transpile(dynamic, traversal).getCode();
27
+ directGlobal = true;
28
+ }
29
+ }
30
+ if (name === "") {
22
31
  name = this.findClassName(node, traversal);
23
32
  }
24
33
  let ret = "";
25
- const clas = traversal.lookupClassOrInterface(name, node.getFirstToken());
34
+ const clas = traversal.lookupClassOrInterface(name, node.getFirstToken(), directGlobal);
26
35
  const cx = traversal.lookupClassOrInterface("CX_SY_CREATE_OBJECT_ERROR", node.getFirstToken());
27
36
  if (dynamic) {
28
37
  ret += `if (${clas} === undefined) { throw new ${cx}; }\n`;
@@ -36,7 +36,7 @@ export declare class Traversal {
36
36
  private dataFromInterfaces;
37
37
  determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
38
38
  registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
39
- lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined): string;
39
+ lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
40
40
  private buildPrefix;
41
41
  protected traverseStructure(node: abaplint.Nodes.StructureNode): Chunk;
42
42
  protected traverseStatement(node: abaplint.Nodes.StatementNode): Chunk;
@@ -347,11 +347,14 @@ class Traversal {
347
347
  return `abap.Classes['${name.toUpperCase()}'] = ${name.toLowerCase()};`;
348
348
  }
349
349
  }
350
- lookupClassOrInterface(name, token) {
350
+ lookupClassOrInterface(name, token, directGlobal = false) {
351
351
  var _a, _b;
352
352
  if (name === undefined || token === undefined) {
353
353
  return "abap.Classes['undefined']";
354
354
  }
355
+ if (directGlobal === true) {
356
+ return "abap.Classes[" + name + "]";
357
+ }
355
358
  const scope = this.findCurrentScopeByToken(token);
356
359
  // todo, add explicit type,
357
360
  let def = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name);
@@ -5,12 +5,18 @@ const abaplint = require("@abaplint/core");
5
5
  class UnitTest {
6
6
  // todo, move this somewhere else, its much more than just unit test relevant
7
7
  initializationScript(reg, dbSetup) {
8
- return `import runtime from "@abaplint/runtime";
8
+ let ret = `import runtime from "@abaplint/runtime";
9
9
  global.abap = new runtime.ABAP();
10
10
  ${this.buildImports(reg)}
11
- export async function initializeABAP(settings) {
12
- await global.abap.initDB(\`${dbSetup}\`);
13
- }`;
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;
14
20
  }
15
21
  unitTestScript(reg, skip, _only) {
16
22
  let ret = `import fs from "fs";
@@ -84,7 +90,7 @@ fs.writeFileSync(__dirname + path.sep + "output.xml", unit.xUnitXML());
84
90
  }
85
91
 
86
92
  run().then(() => {
87
- process.exit();
93
+ process.exit(0);
88
94
  }).catch((err) => {
89
95
  console.log(err);
90
96
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "1.7.9",
3
+ "version": "1.7.14",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",