@abaplint/transpiler 2.13.91 → 2.13.92

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.
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.AttributeNameTranspiler = void 0;
37
37
  const abaplint = __importStar(require("@abaplint/core"));
38
+ const traversal_1 = require("../traversal");
38
39
  const chunk_1 = require("../chunk");
39
40
  class AttributeNameTranspiler {
40
41
  transpile(node, traversal) {
@@ -45,6 +46,16 @@ class AttributeNameTranspiler {
45
46
  && ref.getVisibility() === abaplint.Visibility.Private) {
46
47
  concat = "#" + concat;
47
48
  }
49
+ // an attribute declared in an interface lives on the object as "<intf>$<name>",
50
+ // also when it is reached via an interface reference without the "intf~" alias,
51
+ // eg. "obj->method( )->value" where method returns "REF TO lif_intf"
52
+ const interfaceName = traversal.isInterfaceAttribute(node.getFirstToken());
53
+ if (interfaceName && concat.startsWith(interfaceName) === false) {
54
+ concat = traversal_1.Traversal.escapeNamespace(interfaceName) + "$" + traversal_1.Traversal.escapeNamespace(concat).replace("~", "$");
55
+ }
56
+ else {
57
+ concat = traversal_1.Traversal.escapeNamespace(concat).replace("~", "$");
58
+ }
48
59
  return new chunk_1.Chunk().append(concat, node, traversal);
49
60
  }
50
61
  }
@@ -98,10 +98,22 @@ class ReadTableTranspiler {
98
98
  const s = traversal.traverse(source).getCode();
99
99
  let field = "";
100
100
  let key = left.concatTokens().toLowerCase();
101
+ // the component name is a JS object key, computed at runtime for a dynamic variable
102
+ let keyExpression = "";
101
103
  if (left.get() instanceof abaplint.Expressions.Dynamic
102
104
  && left instanceof abaplint.Nodes.ExpressionNode) {
103
- key = key.substring(2, key.length - 2);
104
- field = "i." + key;
105
+ const chain = left.findDirectExpression(abaplint.Expressions.FieldChain);
106
+ if (chain) {
107
+ // WITH TABLE KEY (variable) = value
108
+ const name = new expressions_1.FieldChainTranspiler(true).transpile(chain, traversal).getCode();
109
+ keyExpression = name + ".trimEnd().toLowerCase()";
110
+ field = "i[" + keyExpression + "]";
111
+ }
112
+ else {
113
+ // WITH TABLE KEY ('LITERAL') = value
114
+ key = key.substring(2, key.length - 2);
115
+ field = "i." + key;
116
+ }
105
117
  }
106
118
  else if (left.get() instanceof abaplint.Expressions.ComponentChainSimple
107
119
  && left instanceof abaplint.Nodes.ExpressionNode) {
@@ -113,17 +125,18 @@ class ReadTableTranspiler {
113
125
  if (field === "i.table_line") {
114
126
  usesTableLine = true;
115
127
  }
128
+ const simpleKey = keyExpression !== "" ? "[" + keyExpression + "]" : JSON.stringify(key);
116
129
  if (s.includes("await")) {
117
130
  const id = unique_identifier_1.UniqueIdentifier.get();
118
131
  prefix += "const " + id + " = " + s + ";\n";
119
132
  withKey.push("abap.compare.eq(" + field + ", " + id + ")");
120
133
  withKeyValue.push(`{key: (i) => {return ${field}}, value: ${id}}`);
121
- withKeySimple.push(`${JSON.stringify(key)}: ${id}`);
134
+ withKeySimple.push(`${simpleKey}: ${id}`);
122
135
  }
123
136
  else {
124
137
  withKey.push("abap.compare.eq(" + field + ", " + s + ")");
125
138
  withKeyValue.push(`{key: (i) => {return ${field}}, value: ${s}}`);
126
- withKeySimple.push(`${JSON.stringify(key)}: ${s}`);
139
+ withKeySimple.push(`${simpleKey}: ${s}`);
127
140
  }
128
141
  }
129
142
  extra.push("withKey: (i) => {return " + withKey.join(" && ") + ";}");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.13.91",
3
+ "version": "2.13.92",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "author": "abaplint",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@abaplint/core": "^2.120.58",
32
+ "@abaplint/core": "^2.120.59",
33
33
  "source-map": "^0.8.0"
34
34
  },
35
35
  "devDependencies": {