@abaplint/transpiler 2.13.20 → 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.
@@ -8,6 +8,12 @@ class TypeNameOrInfer {
8
8
  const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
9
9
  const type = traversal.lookupInferred(node, scope);
10
10
  if (type === undefined) {
11
+ if (node.concatTokens() === "#") {
12
+ const sqlType = traversal.getSQLInferredType();
13
+ if (sqlType !== undefined) {
14
+ return sqlType;
15
+ }
16
+ }
11
17
  throw new Error("TypeNameOrInfer, type not found: " + node.concatTokens() + ", " + traversal.getCurrentObject().getName() + " line " + node.getFirstToken().getStart().getRow());
12
18
  }
13
19
  return type;
@@ -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];
@@ -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
  }
@@ -0,0 +1,7 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IStatementTranspiler } from "./_statement_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class GenerateSubroutineTranspiler implements IStatementTranspiler {
6
+ transpile(_node: abaplint.Nodes.StatementNode, _traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateSubroutineTranspiler = void 0;
4
+ const chunk_1 = require("../chunk");
5
+ class GenerateSubroutineTranspiler {
6
+ transpile(_node, _traversal) {
7
+ return new chunk_1.Chunk(`throw new Error("GenerateSubroutine, not supported, transpiler");`);
8
+ }
9
+ }
10
+ exports.GenerateSubroutineTranspiler = GenerateSubroutineTranspiler;
11
+ //# sourceMappingURL=generate_subroutine.js.map
@@ -129,6 +129,7 @@ export * from "./set_language";
129
129
  export * from "./set_locale";
130
130
  export * from "./set_parameter";
131
131
  export * from "./set_pf_status";
132
+ export * from "./generate_subroutine";
132
133
  export * from "./set_screen";
133
134
  export * from "./set_titlebar";
134
135
  export * from "./shift";
@@ -145,6 +145,7 @@ __exportStar(require("./set_language"), exports);
145
145
  __exportStar(require("./set_locale"), exports);
146
146
  __exportStar(require("./set_parameter"), exports);
147
147
  __exportStar(require("./set_pf_status"), exports);
148
+ __exportStar(require("./generate_subroutine"), exports);
148
149
  __exportStar(require("./set_screen"), exports);
149
150
  __exportStar(require("./set_titlebar"), exports);
150
151
  __exportStar(require("./shift"), exports);
@@ -20,7 +20,7 @@ class InsertDatabaseTranspiler {
20
20
  }
21
21
  const from = node.findExpressionAfterToken("FROM");
22
22
  if (from && from.get() instanceof abaplint.Expressions.SQLSource) {
23
- const tvalues = traversal.traverse(from);
23
+ const tvalues = traversal.traverseWithTableContext(dbtab.concatTokens(), from);
24
24
  options.push(`"values": ` + tvalues.getCode());
25
25
  }
26
26
  const fromTable = node.findExpressionAfterToken("TABLE");
@@ -19,7 +19,7 @@ class ModifyDatabaseTranspiler {
19
19
  }
20
20
  const from = node.findExpressionAfterToken("FROM");
21
21
  if (from && from.get() instanceof abaplint.Expressions.SQLSource) {
22
- const tvalues = traversal.traverse(from);
22
+ const tvalues = traversal.traverseWithTableContext(dbtab.concatTokens(), from);
23
23
  options.push(`"values": ` + tvalues.getCode());
24
24
  }
25
25
  return new chunk_1.Chunk(`await abap.statements.modifyDatabase(${table.getCode()}, {${options.join(", ")}});`);
@@ -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
  }
@@ -5,6 +5,7 @@ export declare class Traversal {
5
5
  private readonly spaghetti;
6
6
  private readonly file;
7
7
  private readonly obj;
8
+ private sqlInferredType;
8
9
  readonly reg: abaplint.IRegistry;
9
10
  readonly options: ITranspilerOptions | undefined;
10
11
  constructor(spaghetti: abaplint.ISpaghettiScope, file: abaplint.ABAPFile, obj: abaplint.ABAPObject, reg: abaplint.IRegistry, options?: ITranspilerOptions);
@@ -20,6 +21,8 @@ export declare class Traversal {
20
21
  private scopeCache;
21
22
  findCurrentScopeByToken(token: abaplint.Token): abaplint.ISpaghettiScopeNode | undefined;
22
23
  private fuctionGroupWorkaround;
24
+ getSQLInferredType(): abaplint.AbstractType | undefined;
25
+ traverseWithTableContext(tableName: string, expressionNode: abaplint.Nodes.ExpressionNode): Chunk;
23
26
  getInterfaceDefinition(token: abaplint.Token): abaplint.IInterfaceDefinition | undefined;
24
27
  getClassDefinition(token: abaplint.Token): abaplint.IClassDefinition | undefined;
25
28
  private isPrivateAttribute;
@@ -13,6 +13,7 @@ class Traversal {
13
13
  spaghetti;
14
14
  file;
15
15
  obj;
16
+ sqlInferredType;
16
17
  reg;
17
18
  options;
18
19
  constructor(spaghetti, file, obj, reg, options) {
@@ -107,6 +108,16 @@ class Traversal {
107
108
  }
108
109
  return undefined;
109
110
  }
111
+ getSQLInferredType() {
112
+ return this.sqlInferredType;
113
+ }
114
+ traverseWithTableContext(tableName, expressionNode) {
115
+ const tabl = this.reg.getObject("TABL", tableName);
116
+ this.sqlInferredType = tabl?.parseType(this.reg);
117
+ const result = this.traverse(expressionNode);
118
+ this.sqlInferredType = undefined;
119
+ return result;
120
+ }
110
121
  getInterfaceDefinition(token) {
111
122
  let scope = this.findCurrentScopeByToken(token);
112
123
  while (scope !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.13.20",
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.12",
32
+ "@abaplint/core": "^2.119.13",
33
33
  "source-map": "^0.7.6"
34
34
  },
35
35
  "devDependencies": {