@abaplint/transpiler 1.7.12 → 1.7.13
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
|
-
|
|
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`;
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -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;
|
package/build/src/traversal.js
CHANGED
|
@@ -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);
|