@abaplint/transpiler 1.7.41 → 1.7.42
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,7 +3,7 @@ import { IExpressionTranspiler } from "./_expression_transpiler";
|
|
|
3
3
|
import { Traversal } from "../traversal";
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class MethodSourceTranspiler implements IExpressionTranspiler {
|
|
6
|
-
private
|
|
6
|
+
private prepend;
|
|
7
7
|
constructor(prepend?: string);
|
|
8
8
|
transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
|
|
9
9
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MethodSourceTranspiler = void 0;
|
|
4
|
+
/* eslint-disable max-len */
|
|
4
5
|
const core_1 = require("@abaplint/core");
|
|
5
6
|
const chunk_1 = require("../chunk");
|
|
6
7
|
const _1 = require(".");
|
|
@@ -11,36 +12,26 @@ class MethodSourceTranspiler {
|
|
|
11
12
|
transpile(node, traversal) {
|
|
12
13
|
const ret = new chunk_1.Chunk();
|
|
13
14
|
const children = node.getChildren();
|
|
15
|
+
let call = "";
|
|
14
16
|
for (let i = 0; i < children.length; i++) {
|
|
15
17
|
const child = children[i];
|
|
16
18
|
const nextChild = children[i + 1];
|
|
17
19
|
if (child.get() instanceof core_1.Expressions.ClassName) {
|
|
18
|
-
|
|
20
|
+
call += traversal.lookupClassOrInterface(child.concatTokens(), child.getFirstToken());
|
|
19
21
|
}
|
|
20
22
|
else if (child.get() instanceof core_1.Expressions.Dynamic && (nextChild === null || nextChild === void 0 ? void 0 : nextChild.concatTokens()) === "=>") {
|
|
21
23
|
const second = child.getChildren()[1];
|
|
24
|
+
const lookupException = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_CLASS'", child.getFirstToken(), true);
|
|
22
25
|
if (second.get() instanceof core_1.Expressions.FieldChain && second instanceof core_1.Nodes.ExpressionNode) {
|
|
23
26
|
const t = new _1.FieldChainTranspiler(true).transpile(second, traversal).getCode();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ret.appendString(`if (${lookup} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
|
|
28
|
-
ret.appendString(`if (${lookup} === undefined) { throw new ${lookupException}(); }\n`);
|
|
29
|
-
if (i === 0) {
|
|
30
|
-
ret.appendString(this.prepend);
|
|
31
|
-
}
|
|
32
|
-
ret.appendString(lookup);
|
|
27
|
+
call = traversal.lookupClassOrInterface(t, child.getFirstToken(), true);
|
|
28
|
+
ret.appendString(`if (${call} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
|
|
29
|
+
ret.appendString(`if (${call} === undefined) { throw new ${lookupException}(); }\n`);
|
|
33
30
|
}
|
|
34
31
|
else if (second.get() instanceof core_1.Expressions.Constant) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
ret.appendString(`if (${lookup} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
|
|
39
|
-
ret.appendString(`if (${lookup} === undefined) { throw new ${lookupException}(); }\n`);
|
|
40
|
-
if (i === 0) {
|
|
41
|
-
ret.appendString(this.prepend);
|
|
42
|
-
}
|
|
43
|
-
ret.appendString(lookup);
|
|
32
|
+
call = traversal.lookupClassOrInterface(second.getFirstToken().getStr(), child.getFirstToken(), true);
|
|
33
|
+
ret.appendString(`if (${call} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_CLASS not found"; }\n`);
|
|
34
|
+
ret.appendString(`if (${call} === undefined) { throw new ${lookupException}(); }\n`);
|
|
44
35
|
}
|
|
45
36
|
else {
|
|
46
37
|
ret.appendString("MethodSourceTranspiler-Unexpected");
|
|
@@ -48,49 +39,51 @@ class MethodSourceTranspiler {
|
|
|
48
39
|
}
|
|
49
40
|
else if (child.get() instanceof core_1.Expressions.Dynamic) {
|
|
50
41
|
const second = child.getChildren()[1];
|
|
42
|
+
const lookupException = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_METHOD'", child.getFirstToken(), true);
|
|
51
43
|
if (second.get() instanceof core_1.Expressions.FieldChain) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
call += "[";
|
|
45
|
+
call += traversal.traverse(second).getCode();
|
|
46
|
+
call += ".get().toLowerCase()]";
|
|
55
47
|
}
|
|
56
48
|
else if (second.get() instanceof core_1.Expressions.Constant) {
|
|
57
|
-
if (
|
|
58
|
-
|
|
49
|
+
if (call.endsWith(".") === false) {
|
|
50
|
+
call += ".";
|
|
59
51
|
}
|
|
60
|
-
|
|
52
|
+
call += second.getFirstToken().getStr().replace(/\'/g, "").toLowerCase().replace("~", "$");
|
|
61
53
|
}
|
|
62
54
|
else {
|
|
63
55
|
ret.appendString("MethodSourceTranspiler-Unexpected");
|
|
64
56
|
}
|
|
57
|
+
ret.appendString(`if (${call} === undefined && ${lookupException} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_METHOD not found"; }\n`);
|
|
58
|
+
ret.appendString(`if (${call} === undefined) { throw new ${lookupException}(); }\n`);
|
|
65
59
|
}
|
|
66
60
|
else if (child.get() instanceof core_1.Expressions.MethodName) {
|
|
67
61
|
if (i === 0) {
|
|
68
|
-
|
|
62
|
+
this.prepend += "this.";
|
|
69
63
|
}
|
|
70
64
|
const methodName = child.concatTokens().toLowerCase().replace("~", "$");
|
|
71
|
-
|
|
65
|
+
call += methodName;
|
|
72
66
|
}
|
|
73
67
|
else if (child.concatTokens() === "=>") {
|
|
74
|
-
|
|
68
|
+
call += ".";
|
|
75
69
|
}
|
|
76
70
|
else if (child.concatTokens() === "->") {
|
|
77
71
|
if (ret.getCode() !== "super") {
|
|
78
|
-
|
|
72
|
+
call += ".get()";
|
|
79
73
|
}
|
|
80
74
|
if (!(nextChild.get() instanceof core_1.Expressions.Dynamic)) {
|
|
81
|
-
|
|
75
|
+
call += ".";
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
else if (child.get() instanceof core_1.Expressions.FieldChain) {
|
|
85
|
-
|
|
86
|
-
ret.appendString(this.prepend);
|
|
87
|
-
}
|
|
88
|
-
ret.appendChunk(traversal.traverse(child));
|
|
79
|
+
call += traversal.traverse(child).getCode();
|
|
89
80
|
}
|
|
90
81
|
else {
|
|
91
82
|
ret.appendString("MethodSourceTranspiler-" + child.get().constructor.name + "-todo");
|
|
92
83
|
}
|
|
93
84
|
}
|
|
85
|
+
ret.appendString(this.prepend);
|
|
86
|
+
ret.appendString(call);
|
|
94
87
|
return ret;
|
|
95
88
|
}
|
|
96
89
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.42",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "abaplint",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abaplint/core": "^2.85.
|
|
30
|
+
"@abaplint/core": "^2.85.10",
|
|
31
31
|
"source-map": "^0.7.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|