@abaplint/transpiler 2.1.33 → 2.1.36

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.
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssignTranspiler = void 0;
4
+ /* eslint-disable max-len */
4
5
  const abaplint = require("@abaplint/core");
5
6
  const expressions_1 = require("../expressions");
6
7
  const chunk_1 = require("../chunk");
7
8
  class AssignTranspiler {
8
9
  transpile(node, traversal) {
9
- var _a, _b;
10
- const sources = node.findDirectExpressions(abaplint.Expressions.Source).map(e => new expressions_1.SourceTranspiler(false).transpile(e, traversal).getCode());
10
+ var _a, _b, _c;
11
+ const assignSource = node.findDirectExpression(abaplint.Expressions.AssignSource);
12
+ const sources = (assignSource === null || assignSource === void 0 ? void 0 : assignSource.findDirectExpressions(abaplint.Expressions.Source).map(e => new expressions_1.SourceTranspiler(false).transpile(e, traversal).getCode())) || [];
11
13
  const fs = new expressions_1.FieldSymbolTranspiler().transpile(node.findDirectExpression(abaplint.Expressions.FSTarget), traversal).getCode();
12
14
  const options = [];
13
15
  const concat = node.concatTokens().toUpperCase();
@@ -19,17 +21,42 @@ class AssignTranspiler {
19
21
  options.push("source: " + sources.pop());
20
22
  }
21
23
  else {
22
- let dynamic = (_a = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(abaplint.Expressions.ConstantString);
24
+ let dynamicName = "";
25
+ for (const c of (assignSource === null || assignSource === void 0 ? void 0 : assignSource.getChildren()) || []) {
26
+ if (c instanceof abaplint.Nodes.ExpressionNode
27
+ && c.get() instanceof abaplint.Expressions.Dynamic
28
+ && c.findFirstExpression(abaplint.Expressions.ConstantString)) {
29
+ if (dynamicName !== "") {
30
+ dynamicName += " + ";
31
+ }
32
+ dynamicName += (_a = c.findFirstExpression(abaplint.Expressions.ConstantString)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr();
33
+ }
34
+ else if (c instanceof abaplint.Nodes.ExpressionNode
35
+ && c.get() instanceof abaplint.Expressions.Dynamic
36
+ && c.findDirectExpression(abaplint.Expressions.FieldChain)) {
37
+ if (dynamicName !== "") {
38
+ dynamicName += " + ";
39
+ }
40
+ dynamicName += new expressions_1.FieldChainTranspiler(true).transpile(c.findDirectExpression(abaplint.Expressions.FieldChain), traversal).getCode();
41
+ }
42
+ else if (c.concatTokens() === "(" || c.concatTokens() === ")") {
43
+ continue;
44
+ }
45
+ else if (c.concatTokens() === "=>" || c.concatTokens() === "->") {
46
+ dynamicName += " + '" + c.concatTokens() + "'";
47
+ }
48
+ }
49
+ options.push(`dynamicName: ` + dynamicName);
50
+ // dynamicSource is the first part only
51
+ let dynamic = (_b = assignSource === null || assignSource === void 0 ? void 0 : assignSource.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.ConstantString);
23
52
  if (dynamic) {
24
- options.push(`dynamicText: ` + dynamic.getFirstToken().getStr());
25
53
  const s = dynamic.getFirstToken().getStr().toLowerCase().match(/\w+/);
26
54
  options.push(`dynamicSource: (() => {try { return ${s}; } catch {}})()`);
27
55
  }
28
56
  else {
29
- dynamic = (_b = node.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(abaplint.Expressions.FieldChain);
57
+ dynamic = (_c = assignSource === null || assignSource === void 0 ? void 0 : assignSource.findDirectExpression(abaplint.Expressions.Dynamic)) === null || _c === void 0 ? void 0 : _c.findFirstExpression(abaplint.Expressions.FieldChain);
30
58
  if (dynamic) {
31
59
  const code = new expressions_1.FieldChainTranspiler(true).transpile(dynamic, traversal).getCode();
32
- options.push(`dynamicText: ` + code);
33
60
  options.push(`dynamicSource: (() => {try { return eval(${code}.toLowerCase().match(/\\w+/)[0]); } catch {}})()`);
34
61
  }
35
62
  }
@@ -17,7 +17,9 @@ class ClassImplementationTranspiler {
17
17
  else if (def === null || def === void 0 ? void 0 : def.getSuperClass()) {
18
18
  ret += " extends " + ((_a = def === null || def === void 0 ? void 0 : def.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
19
19
  }
20
- return new chunk_1.Chunk().append(ret + " {", node, traversal);
20
+ return new chunk_1.Chunk().append(ret + ` {
21
+ static INTERNAL_TYPE = 'CLAS';
22
+ static IMPLEMENTED_INTERFACES = [${def === null || def === void 0 ? void 0 : def.getImplementing().map(e => `"` + e.name.toUpperCase() + `"`).join(",")}];`, node, traversal);
21
23
  }
22
24
  }
23
25
  exports.ClassImplementationTranspiler = ClassImplementationTranspiler;
@@ -22,6 +22,7 @@ class ClassDefinitionTranspiler {
22
22
  // its an abstract class with only abstract methods
23
23
  return new chunk_1.Chunk(`
24
24
  class ${className === null || className === void 0 ? void 0 : className.toLowerCase()} {
25
+ static INTERNAL_TYPE = 'CLAS';
25
26
  async constructor_() {
26
27
  this.me = new abap.types.ABAPObject();
27
28
  this.me.set(this);
@@ -12,14 +12,16 @@ class InterfaceTranspiler {
12
12
  let ret = "";
13
13
  let name;
14
14
  for (const c of node.getChildren()) {
15
+ const def = traversal.getInterfaceDefinition(node.getFirstToken());
15
16
  if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.Interface) {
16
17
  name = (_a = c.findDirectExpression(abaplint.Expressions.InterfaceName)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr().toLowerCase();
17
18
  name = traversal_1.Traversal.escapeClassName(name);
18
19
  ret += `class ${name} {\n`;
20
+ ret += `static INTERNAL_TYPE = 'INTF';\n`;
21
+ ret += `static IMPLEMENTED_INTERFACES = [${def === null || def === void 0 ? void 0 : def.getImplementing().map(e => `"` + e.name.toUpperCase() + `"`).join(",")}];\n`;
19
22
  }
20
23
  else if (c instanceof abaplint.Nodes.StatementNode && c.get() instanceof abaplint.Statements.EndInterface) {
21
24
  ret += "}\n";
22
- const def = traversal.getInterfaceDefinition(node.getFirstToken());
23
25
  ret += traversal.registerClassOrInterface(def);
24
26
  }
25
27
  }
@@ -8,7 +8,7 @@ class TranspileTypes {
8
8
  return "let " + t.getName().toLowerCase() + " = " + this.toType(type) + ";";
9
9
  }
10
10
  toType(type) {
11
- var _a, _b, _c, _d, _e, _f, _g;
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
12
12
  let resolved = "";
13
13
  let extra = "";
14
14
  if (type instanceof abaplint.BasicTypes.ObjectReferenceType
@@ -96,9 +96,15 @@ class TranspileTypes {
96
96
  }
97
97
  else if (type instanceof abaplint.BasicTypes.NumericType) {
98
98
  resolved = "Numc";
99
- if (type.getLength() !== 1) {
99
+ if (type.getQualifiedName() && type.getLength() !== 1) {
100
+ extra = "{length: " + type.getLength() + ", qualifiedName: \"" + type.getQualifiedName() + "\"}";
101
+ }
102
+ else if (type.getLength() !== 1) {
100
103
  extra = "{length: " + type.getLength() + "}";
101
104
  }
105
+ else if (type.getQualifiedName()) {
106
+ extra = "{qualifiedName: \"" + type.getQualifiedName() + "\"}";
107
+ }
102
108
  }
103
109
  else if (type instanceof abaplint.BasicTypes.PackedType) {
104
110
  resolved = "Packed";
@@ -131,9 +137,15 @@ class TranspileTypes {
131
137
  }
132
138
  else if (type instanceof abaplint.BasicTypes.FloatType) {
133
139
  resolved = "Float";
140
+ if (type.getQualifiedName() !== undefined) {
141
+ extra = "{qualifiedName: \"" + ((_h = type.getQualifiedName()) === null || _h === void 0 ? void 0 : _h.toUpperCase()) + "\"}";
142
+ }
134
143
  }
135
144
  else if (type instanceof abaplint.BasicTypes.FloatingPointType) {
136
145
  resolved = "Float";
146
+ if (type.getQualifiedName() !== undefined) {
147
+ extra = "{qualifiedName: \"" + ((_j = type.getQualifiedName()) === null || _j === void 0 ? void 0 : _j.toUpperCase()) + "\"}";
148
+ }
137
149
  }
138
150
  else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
139
151
  resolved = "DecFloat34";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.1.33",
3
+ "version": "2.1.36",
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.28",
31
+ "@abaplint/core": "^2.91.30",
32
32
  "source-map": "^0.7.4"
33
33
  },
34
34
  "devDependencies": {