@abaplint/transpiler 2.3.72 → 2.3.74

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.
@@ -19,8 +19,6 @@ export * from "./field_length";
19
19
  export * from "./field_offset";
20
20
  export * from "./field_symbol";
21
21
  export * from "./function_exporting";
22
- export * from "./sql_from";
23
- export * from "./sql_join";
24
22
  export * from "./function_parameters";
25
23
  export * from "./message_number";
26
24
  export * from "./method_call_body";
@@ -41,8 +39,11 @@ export * from "./simple_source4";
41
39
  export * from "./source_field_symbol";
42
40
  export * from "./source";
43
41
  export * from "./sql_cond";
42
+ export * from "./sql_from";
43
+ export * from "./sql_join";
44
44
  export * from "./sql_source_simple";
45
45
  export * from "./sql_source";
46
+ export * from "./sql_target";
46
47
  export * from "./string_template_source";
47
48
  export * from "./string_template";
48
49
  export * from "./target";
@@ -35,8 +35,6 @@ __exportStar(require("./field_length"), exports);
35
35
  __exportStar(require("./field_offset"), exports);
36
36
  __exportStar(require("./field_symbol"), exports);
37
37
  __exportStar(require("./function_exporting"), exports);
38
- __exportStar(require("./sql_from"), exports);
39
- __exportStar(require("./sql_join"), exports);
40
38
  __exportStar(require("./function_parameters"), exports);
41
39
  __exportStar(require("./message_number"), exports);
42
40
  __exportStar(require("./method_call_body"), exports);
@@ -57,8 +55,11 @@ __exportStar(require("./simple_source4"), exports);
57
55
  __exportStar(require("./source_field_symbol"), exports);
58
56
  __exportStar(require("./source"), exports);
59
57
  __exportStar(require("./sql_cond"), exports);
58
+ __exportStar(require("./sql_from"), exports);
59
+ __exportStar(require("./sql_join"), exports);
60
60
  __exportStar(require("./sql_source_simple"), exports);
61
61
  __exportStar(require("./sql_source"), exports);
62
+ __exportStar(require("./sql_target"), exports);
62
63
  __exportStar(require("./string_template_source"), exports);
63
64
  __exportStar(require("./string_template"), exports);
64
65
  __exportStar(require("./target"), exports);
@@ -0,0 +1,7 @@
1
+ import { Nodes } from "@abaplint/core";
2
+ import { IExpressionTranspiler } from "./_expression_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class SQLTargetTranspiler implements IExpressionTranspiler {
6
+ transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SQLTargetTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ class SQLTargetTranspiler {
6
+ transpile(node, traversal) {
7
+ const s = node.findDirectExpression(abaplint.Expressions.Target);
8
+ return traversal.traverse(s);
9
+ }
10
+ }
11
+ exports.SQLTargetTranspiler = SQLTargetTranspiler;
12
+ //# sourceMappingURL=sql_target.js.map
@@ -30,17 +30,17 @@ class Transpiler {
30
30
  return new Transpiler().run(reg);
31
31
  }
32
32
  async run(reg, progress) {
33
- var _a, _b, _c, _d, _e, _f;
33
+ var _a, _b, _c, _d, _e, _f, _g;
34
34
  reg.parse();
35
- new keywords_1.Keywords().handle(reg);
35
+ new keywords_1.Keywords((_a = this.options) === null || _a === void 0 ? void 0 : _a.keywords).handle(reg);
36
36
  this.validate(reg);
37
37
  const dbSetup = new db_1.DatabaseSetup(reg).run();
38
38
  const output = {
39
39
  objects: [],
40
- unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_a = this.options) === null || _a === void 0 ? void 0 : _a.skip, (_b = this.options) === null || _b === void 0 ? void 0 : _b.only),
41
- unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, (_c = this.options) === null || _c === void 0 ? void 0 : _c.skip, (_d = this.options) === null || _d === void 0 ? void 0 : _d.only),
42
- initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_e = this.options) === null || _e === void 0 ? void 0 : _e.extraSetup),
43
- initializationScript2: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_f = this.options) === null || _f === void 0 ? void 0 : _f.extraSetup, true),
40
+ unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_b = this.options) === null || _b === void 0 ? void 0 : _b.skip, (_c = this.options) === null || _c === void 0 ? void 0 : _c.only),
41
+ unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, (_d = this.options) === null || _d === void 0 ? void 0 : _d.skip, (_e = this.options) === null || _e === void 0 ? void 0 : _e.only),
42
+ initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_f = this.options) === null || _f === void 0 ? void 0 : _f.extraSetup),
43
+ initializationScript2: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_g = this.options) === null || _g === void 0 ? void 0 : _g.extraSetup, true),
44
44
  databaseSetup: dbSetup,
45
45
  reg: reg,
46
46
  };
@@ -1,6 +1,8 @@
1
1
  import * as abaplint from "@abaplint/core";
2
2
  /** Replaces javascript keywords in ABAP source code, in-memory only */
3
3
  export declare class Keywords {
4
+ private readonly keywords;
5
+ constructor(keywords?: string[]);
4
6
  handle(reg: abaplint.IRegistry): void;
5
7
  private traverse;
6
8
  }
@@ -2,8 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Keywords = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
+ // https://www.w3schools.com/js/js_reserved.asp
6
+ const defaultKeywords = [
7
+ "abstract", "arguments", "await",
8
+ "break", "byte", "catch",
9
+ "char", "class", "const", "continue",
10
+ "debugger", "default", "do",
11
+ "double", "else", "enum", "eval",
12
+ "export", "extends", "false", "final",
13
+ "finally", "for", "function",
14
+ "goto", "if", "implements", "import",
15
+ "in", "instanceof", "interface",
16
+ "let", "long", "native", "new",
17
+ "null", "package", "private",
18
+ "public", "return", "short", "static",
19
+ "switch", "synchronized", "this",
20
+ "throw", "throws", "transient", "true",
21
+ "try", "typeof", "var", "void",
22
+ "volatile", "while", "yield"
23
+ ];
24
+ // "with"
25
+ // "delete"
5
26
  /** Replaces javascript keywords in ABAP source code, in-memory only */
6
27
  class Keywords {
28
+ constructor(keywords) {
29
+ this.keywords = [];
30
+ if (keywords !== undefined) {
31
+ this.keywords = keywords;
32
+ }
33
+ else {
34
+ this.keywords = defaultKeywords;
35
+ }
36
+ }
7
37
  handle(reg) {
8
38
  reg.parse();
9
39
  for (const o of reg.getObjects()) {
@@ -30,27 +60,6 @@ class Keywords {
30
60
  reg.parse();
31
61
  }
32
62
  traverse(node, file) {
33
- // https://www.w3schools.com/js/js_reserved.asp
34
- const keywords = [
35
- "abstract", "arguments", "await",
36
- "break", "byte", "catch",
37
- "char", "class", "const", "continue",
38
- "debugger", "default", "do",
39
- "double", "else", "enum", "eval",
40
- "export", "extends", "false", "final",
41
- "finally", "for", "function",
42
- "goto", "if", "implements", "import",
43
- "in", "instanceof", "interface",
44
- "let", "long", "native", "new",
45
- "null", "package", "private",
46
- "public", "return", "short", "static",
47
- "switch", "synchronized", "this",
48
- "throw", "throws", "transient", "true",
49
- "try", "typeof", "var", "void",
50
- "volatile", "while", "yield"
51
- ];
52
- // "with"
53
- // "delete"
54
63
  const ret = [];
55
64
  for (const c of node.getChildren()) {
56
65
  if (c instanceof abaplint.Nodes.TokenNodeRegex) {
@@ -59,7 +68,7 @@ class Keywords {
59
68
  if (start instanceof abaplint.VirtualPosition) {
60
69
  continue;
61
70
  }
62
- for (const k of keywords) {
71
+ for (const k of this.keywords) {
63
72
  const lower = token.getStr().toLowerCase();
64
73
  if (k === lower
65
74
  || "!" + k === lower
@@ -66,6 +66,9 @@ class MethodImplementationTranspiler {
66
66
  else if (parameterDefault.getFirstToken().getStr().toLowerCase() === "space") {
67
67
  val = "abap.builtin.space";
68
68
  }
69
+ else if (parameterDefault.concatTokens().toLowerCase() === "sy-langu") {
70
+ val = "abap.builtin.sy.get().langu";
71
+ }
69
72
  else if (parameterDefault.concatTokens().toLowerCase() === "sy-uname") {
70
73
  val = "abap.builtin.sy.get().uname";
71
74
  }
@@ -8,7 +8,7 @@ const unique_identifier_1 = require("../unique_identifier");
8
8
  const sql_from_1 = require("../expressions/sql_from");
9
9
  class SelectTranspiler {
10
10
  transpile(node, traversal, targetOverride) {
11
- var _a, _b, _c;
11
+ var _a;
12
12
  let target = "undefined";
13
13
  if (targetOverride) {
14
14
  target = targetOverride;
@@ -76,14 +76,15 @@ class SelectTranspiler {
76
76
  }
77
77
  if (node.findFirstExpression(abaplint.Expressions.SQLForAllEntries)) {
78
78
  const unique = unique_identifier_1.UniqueIdentifier.get();
79
- const faeName = (_c = (_b = (_a = node.findFirstExpression(abaplint.Expressions.SQLForAllEntries)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(abaplint.Expressions.SQLSource)) === null || _b === void 0 ? void 0 : _b.concatTokens()) === null || _c === void 0 ? void 0 : _c.toLowerCase();
80
- select = select.replace(new RegExp(" " + faeName, "g"), " " + unique);
79
+ const fn = (_a = node.findFirstExpression(abaplint.Expressions.SQLForAllEntries)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(abaplint.Expressions.SQLSource);
80
+ const faeTranspiled = new expressions_1.SQLSourceTranspiler().transpile(fn, traversal).getCode();
81
+ select = select.replace(new RegExp(" " + faeTranspiled, "g"), " " + unique);
81
82
  select = select.replace(unique + ".get().table_line.get()", unique + ".get()"); // there can be only one?
82
- const code = `if (${faeName}.array().length === 0) {
83
+ const code = `if (${faeTranspiled}.array().length === 0) {
83
84
  throw "FAE, todo, empty table";
84
85
  } else {
85
86
  abap.statements.clear(${target});
86
- for await (const ${unique} of abap.statements.loop(${faeName})) {
87
+ for await (const ${unique} of abap.statements.loop(${faeTranspiled})) {
87
88
  await abap.statements.select(${target}, {select: "${select.trim()}"${extra}}, {appending: true});
88
89
  }
89
90
  abap.builtin.sy.get().dbcnt.set(${target}.array().length);
@@ -5,23 +5,24 @@ const abaplint = require("@abaplint/core");
5
5
  const select_1 = require("../statements/select");
6
6
  const chunk_1 = require("../chunk");
7
7
  const unique_identifier_1 = require("../unique_identifier");
8
+ const expressions_1 = require("../expressions");
8
9
  class SelectTranspiler {
9
10
  transpile(node, traversal) {
10
- var _a, _b;
11
+ var _a;
11
12
  const ret = new chunk_1.Chunk();
12
13
  const selectStatement = node.findFirstStatement(abaplint.Statements.SelectLoop);
13
14
  if (selectStatement === undefined) {
14
15
  throw "Structure, select loop not found";
15
16
  }
16
17
  const from = (_a = selectStatement.findFirstExpression(abaplint.Expressions.SQLFromSource)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
17
- const intoName = (_b = selectStatement.findFirstExpression(abaplint.Expressions.SQLTarget)) === null || _b === void 0 ? void 0 : _b.concatTokens();
18
+ const intoName = new expressions_1.SQLTargetTranspiler().transpile(selectStatement.findFirstExpression(abaplint.Expressions.SQLTarget), traversal).getCode();
18
19
  // note: this implementation SELECTs everything into memory, which might be bad, and sometimes not correct
19
20
  const targetName = unique_identifier_1.UniqueIdentifier.get();
20
21
  const loopName = unique_identifier_1.UniqueIdentifier.get();
21
22
  ret.appendString(`let ${targetName} = new abap.types.Table(abap.DDIC["${from}"].type);\n`);
22
23
  ret.appendChunk(new select_1.SelectTranspiler().transpile(selectStatement, traversal, targetName));
23
24
  ret.appendString(`\nfor (const ${loopName} of ${targetName}.array()) {\n`);
24
- ret.appendString(`${intoName === null || intoName === void 0 ? void 0 : intoName.replace("-", ".get().")}.set(${loopName});\n`);
25
+ ret.appendString(`${intoName}.set(${loopName});\n`);
25
26
  const body = node.findDirectStructure(abaplint.Structures.Body);
26
27
  if (body) {
27
28
  ret.appendChunk(traversal.traverse(body));
@@ -51,4 +51,6 @@ export interface ITranspilerOptions {
51
51
  only?: TestMethodList;
52
52
  /** extra setup script to be executed during initialization */
53
53
  extraSetup?: string;
54
+ /** list of keywords to rename, if not supplied default will be used */
55
+ keywords?: string[];
54
56
  }
@@ -27,7 +27,33 @@ exports.config = {
27
27
  },
28
28
  "parser_error": true,
29
29
  "allowed_object_types": {
30
- "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "VIEW", "XSLT", "ENQU", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
30
+ "allowed": [
31
+ "AUTH",
32
+ "CLAS",
33
+ "DEVC",
34
+ "DOMA",
35
+ "DTEL",
36
+ "ENQU",
37
+ "FUGR",
38
+ "INTF",
39
+ "MSAG",
40
+ "NROB",
41
+ "PARA",
42
+ "PROG",
43
+ "SHLP",
44
+ "SHMA",
45
+ "SICF",
46
+ "SMIM",
47
+ "SRFC",
48
+ "SUSO",
49
+ "TABL",
50
+ "TOBJ",
51
+ "TRAN",
52
+ "TTYP",
53
+ "TYPE",
54
+ "VIEW",
55
+ "XSLT",
56
+ ],
31
57
  },
32
58
  "unknown_types": true,
33
59
  "ambiguous_statement": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.3.72",
3
+ "version": "2.3.74",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",