@abaplint/transpiler 2.13.21 → 2.13.22
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,5 +3,6 @@ import { IStatementTranspiler } from "./_statement_transpiler";
|
|
|
3
3
|
import { Traversal } from "../traversal";
|
|
4
4
|
import { Chunk } from "../chunk";
|
|
5
5
|
export declare class AssignTranspiler implements IStatementTranspiler {
|
|
6
|
+
private tableExpressionSafeSource;
|
|
6
7
|
transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
|
|
7
8
|
}
|
|
@@ -6,9 +6,25 @@ const abaplint = require("@abaplint/core");
|
|
|
6
6
|
const expressions_1 = require("../expressions");
|
|
7
7
|
const chunk_1 = require("../chunk");
|
|
8
8
|
class AssignTranspiler {
|
|
9
|
+
tableExpressionSafeSource(node, code) {
|
|
10
|
+
if (node?.findFirstExpression(abaplint.Expressions.TableExpression) === undefined) {
|
|
11
|
+
return code;
|
|
12
|
+
}
|
|
13
|
+
return `(await (async () => {
|
|
14
|
+
try {
|
|
15
|
+
return ${code};
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (abap.isLineNotFound(error)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
})())`;
|
|
23
|
+
}
|
|
9
24
|
transpile(node, traversal) {
|
|
10
25
|
const assignSource = node.findDirectExpression(abaplint.Expressions.AssignSource);
|
|
11
|
-
const
|
|
26
|
+
const sourceExpressions = assignSource?.findDirectExpressionsMulti([abaplint.Expressions.Source, abaplint.Expressions.SimpleSource3]) || [];
|
|
27
|
+
const sources = sourceExpressions.map(e => this.tableExpressionSafeSource(e, new expressions_1.SourceTranspiler(false).transpile(e, traversal).getCode()));
|
|
12
28
|
let fsTarget = node.findDirectExpression(abaplint.Expressions.FSTarget);
|
|
13
29
|
if (fsTarget?.getFirstChild()?.get() instanceof abaplint.Expressions.InlineFS) {
|
|
14
30
|
fsTarget = fsTarget.findFirstExpression(abaplint.Expressions.TargetFieldSymbol);
|
|
@@ -23,7 +39,7 @@ class AssignTranspiler {
|
|
|
23
39
|
if (sources.length !== 0
|
|
24
40
|
&& assignSource?.findDirectExpression(abaplint.Expressions.Dynamic) === undefined) {
|
|
25
41
|
// Check for struct-(var) pattern: dynamic component access via FieldLength after -
|
|
26
|
-
const sourceExprForCheck =
|
|
42
|
+
const sourceExprForCheck = sourceExpressions[0];
|
|
27
43
|
const fieldChainForCheck = sourceExprForCheck?.findFirstExpression(abaplint.Expressions.FieldChain);
|
|
28
44
|
const fcChildren = fieldChainForCheck?.getChildren() ?? [];
|
|
29
45
|
const lastFC = fcChildren[fcChildren.length - 1];
|
|
@@ -85,26 +101,26 @@ class AssignTranspiler {
|
|
|
85
101
|
const firstFirst = first.getChildren()[1];
|
|
86
102
|
if (firstFirst?.get() instanceof abaplint.Expressions.Constant) {
|
|
87
103
|
const s = firstFirst.getFirstToken().getStr().toLowerCase().match(/\w+/)?.toString();
|
|
88
|
-
options.push(`dynamicSource: (() => {
|
|
89
|
-
try { return ${s}; } catch {}
|
|
90
|
-
try { return this.${s}; } catch {}
|
|
104
|
+
options.push(`dynamicSource: (() => {
|
|
105
|
+
try { return ${s}; } catch {}
|
|
106
|
+
try { return this.${s}; } catch {}
|
|
91
107
|
})()`);
|
|
92
108
|
}
|
|
93
109
|
else if (firstFirst?.get() instanceof abaplint.Expressions.FieldChain && firstFirst instanceof abaplint.Nodes.ExpressionNode) {
|
|
94
110
|
const code = new expressions_1.FieldChainTranspiler(true).transpile(firstFirst, traversal).getCode();
|
|
95
|
-
options.push(`dynamicSource: (() => {
|
|
96
|
-
const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
|
|
97
|
-
try { return eval(name); } catch {}
|
|
98
|
-
try { return eval("this." + name); } catch {}
|
|
111
|
+
options.push(`dynamicSource: (() => {
|
|
112
|
+
const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
|
|
113
|
+
try { return eval(name); } catch {}
|
|
114
|
+
try { return eval("this." + name); } catch {}
|
|
99
115
|
})()`);
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
else if (first?.get() instanceof abaplint.Expressions.Source && first instanceof abaplint.Nodes.ExpressionNode) {
|
|
103
119
|
// const name = first.concatTokens().toLowerCase();
|
|
104
120
|
const name = new expressions_1.SourceTranspiler().transpile(first, traversal).getCode();
|
|
105
|
-
options.push(`dynamicSource: (() => {
|
|
106
|
-
try { return ${name}; } catch {}
|
|
107
|
-
try { return this.${name}; } catch {}
|
|
121
|
+
options.push(`dynamicSource: (() => {
|
|
122
|
+
try { return ${name}; } catch {}
|
|
123
|
+
try { return this.${name}; } catch {}
|
|
108
124
|
})()`);
|
|
109
125
|
}
|
|
110
126
|
}
|
|
@@ -7,6 +7,7 @@ const chunk_1 = require("../chunk");
|
|
|
7
7
|
const unique_identifier_1 = require("../unique_identifier");
|
|
8
8
|
class ReturnTranspiler {
|
|
9
9
|
transpile(node, traversal) {
|
|
10
|
+
const source = node.findDirectExpression(abaplint.Expressions.Source);
|
|
10
11
|
let extra = "";
|
|
11
12
|
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
12
13
|
const vars = scope?.getData().vars;
|
|
@@ -24,6 +25,14 @@ class ReturnTranspiler {
|
|
|
24
25
|
&& scope?.getIdentifier().sname.toLowerCase() === "constructor") {
|
|
25
26
|
extra = " this";
|
|
26
27
|
}
|
|
28
|
+
// RETURN <source> assigns to the RETURNING parameter and exits immediately.
|
|
29
|
+
if (source && extra !== " this") {
|
|
30
|
+
return new chunk_1.Chunk().append(pre
|
|
31
|
+
+ extra.trimStart()
|
|
32
|
+
+ `.set(${traversal.traverse(source).getCode()});\nreturn`
|
|
33
|
+
+ extra
|
|
34
|
+
+ ";", node, traversal);
|
|
35
|
+
}
|
|
27
36
|
return new chunk_1.Chunk().append(pre + "return" + extra + ";", node, traversal);
|
|
28
37
|
}
|
|
29
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.22",
|
|
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.119.
|
|
32
|
+
"@abaplint/core": "^2.119.13",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|