@abaplint/transpiler 2.13.21 → 2.13.23

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 sources = assignSource?.findDirectExpressionsMulti([abaplint.Expressions.Source, abaplint.Expressions.SimpleSource3]).map(e => new expressions_1.SourceTranspiler(false).transpile(e, traversal).getCode()) || [];
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 = assignSource?.findDirectExpressionsMulti([abaplint.Expressions.Source, abaplint.Expressions.SimpleSource3])[0];
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];
@@ -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.21",
3
+ "version": "2.13.23",
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.12",
32
+ "@abaplint/core": "^2.119.16",
33
33
  "source-map": "^0.7.6"
34
34
  },
35
35
  "devDependencies": {