@abaplint/transpiler 2.1.92 → 2.2.1

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,6 +3,7 @@ export declare class SQLiteDatabaseSchema {
3
3
  private readonly reg;
4
4
  constructor(reg: abaplint.IRegistry);
5
5
  run(): string[];
6
- private transparentTable;
6
+ private buildVIEW;
7
+ private buildTABL;
7
8
  private toType;
8
9
  }
@@ -12,13 +12,41 @@ class SQLiteDatabaseSchema {
12
12
  for (const obj of this.reg.getObjects()) {
13
13
  if (obj instanceof abaplint.Objects.Table
14
14
  && obj.getTableCategory() === abaplint.Objects.TableCategory.Transparent) {
15
- statements.push(this.transparentTable(obj).trim());
15
+ statements.push(this.buildTABL(obj).trim());
16
+ }
17
+ }
18
+ // CREATE VIEWs after TABLEs
19
+ // todo: what if the view is based on another view?
20
+ for (const obj of this.reg.getObjects()) {
21
+ if (obj instanceof abaplint.Objects.View) {
22
+ statements.push(this.buildVIEW(obj).trim());
16
23
  }
17
24
  }
18
25
  return statements;
19
26
  }
20
27
  //////////////////
21
- transparentTable(tabl) {
28
+ // https://www.sqlite.org/lang_createview.html
29
+ buildVIEW(view) {
30
+ const fields = view.getFields();
31
+ const columns = fields === null || fields === void 0 ? void 0 : fields.map((f) => f.TABNAME.toLowerCase() + "." + f.FIELDNAME.toLowerCase() + " AS " + f.VIEWFIELD.toLowerCase()).join(", ");
32
+ let from = "";
33
+ let previous = "";
34
+ for (const j of view.getJoin() || []) {
35
+ if (previous === "") {
36
+ from += j.LTAB.toLowerCase() + " INNER JOIN " + j.RTAB.toLowerCase() + " ON " + j.LTAB.toLowerCase() + "." + j.LFIELD.toLowerCase() + " = " + j.RTAB.toLowerCase() + "." + j.RFIELD.toLowerCase();
37
+ }
38
+ else if (previous === j.LTAB + "," + j.RTAB) {
39
+ from += " AND " + j.LTAB.toLowerCase() + "." + j.LFIELD.toLowerCase() + " = " + j.RTAB.toLowerCase() + "." + j.RFIELD.toLowerCase();
40
+ }
41
+ else {
42
+ from += " INNER JOIN " + j.RTAB.toLowerCase() + " ON " + j.LTAB.toLowerCase() + "." + j.LFIELD.toLowerCase() + " = " + j.RTAB.toLowerCase() + "." + j.RFIELD.toLowerCase();
43
+ }
44
+ previous = j.LTAB + "," + j.RTAB;
45
+ }
46
+ from = from.trim();
47
+ return `CREATE VIEW ${view.getName().toLowerCase()} AS SELECT ${columns} FROM ${from};\n`;
48
+ }
49
+ buildTABL(tabl) {
22
50
  const type = tabl.parseType(this.reg);
23
51
  if (!(type instanceof abaplint.BasicTypes.StructureType)) {
24
52
  return "";
@@ -32,7 +60,7 @@ class SQLiteDatabaseSchema {
32
60
  const key = ", PRIMARY KEY(" + tabl.listKeys().map(e => "'" + e.toLowerCase() + "'").join(",") + ")";
33
61
  return `CREATE TABLE ${tabl.getName().toLowerCase()} (${fields.join(", ")}${key});\n`;
34
62
  }
35
- toType(type, fieldname, table) {
63
+ toType(type, fieldname, errorInfo) {
36
64
  if (type instanceof abaplint.BasicTypes.CharacterType) {
37
65
  return `NCHAR(${type.getLength()})`;
38
66
  }
@@ -67,10 +95,10 @@ class SQLiteDatabaseSchema {
67
95
  return `DECIMAL(${type.getLength()},${type.getDecimals()})`;
68
96
  }
69
97
  else if (type instanceof abaplint.BasicTypes.VoidType) {
70
- throw `Type of ${table}-${fieldname} is VoidType(${type.getVoided()}), make sure the type is known, enable strict syntax checking`;
98
+ throw `Type of ${errorInfo}-${fieldname} is VoidType(${type.getVoided()}), make sure the type is known, enable strict syntax checking`;
71
99
  }
72
100
  else {
73
- throw "database_setup: " + table + "-" + fieldname + ", todo toType handle: " + type.constructor.name;
101
+ throw "database_setup: " + errorInfo + "-" + fieldname + ", todo toType handle: " + type.constructor.name;
74
102
  }
75
103
  }
76
104
  }
@@ -1,6 +1,6 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile, ITranspilerOptions } from "./types";
3
- import { Chunk } from "./chunk";
2
+ import { IOutputFile, ITranspilerOptions } from "../types";
3
+ import { Chunk } from "../chunk";
4
4
  export declare class HandleABAP {
5
5
  private readonly options;
6
6
  constructor(options?: ITranspilerOptions);
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleABAP = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
- const traversal_1 = require("./traversal");
6
- const requires_1 = require("./requires");
7
- const rearranger_1 = require("./rearranger");
8
- const chunk_1 = require("./chunk");
5
+ const traversal_1 = require("../traversal");
6
+ const requires_1 = require("../requires");
7
+ const rearranger_1 = require("../rearranger");
8
+ const chunk_1 = require("../chunk");
9
9
  class HandleABAP {
10
10
  constructor(options) {
11
11
  this.options = options;
@@ -1,5 +1,5 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile } from "./types";
2
+ import { IOutputFile } from "../types";
3
3
  export declare class HandleDataElement {
4
4
  runObject(obj: abaplint.Objects.DataElement, reg: abaplint.IRegistry): IOutputFile[];
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleDataElement = void 0;
4
- const chunk_1 = require("./chunk");
5
- const transpile_types_1 = require("./transpile_types");
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
6
  class HandleDataElement {
7
7
  runObject(obj, reg) {
8
8
  var _a;
@@ -1,5 +1,5 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile } from "./types";
2
+ import { IOutputFile } from "../types";
3
3
  export declare class HandleTable {
4
4
  runObject(obj: abaplint.Objects.Table, reg: abaplint.IRegistry): IOutputFile[];
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleTable = void 0;
4
- const chunk_1 = require("./chunk");
5
- const transpile_types_1 = require("./transpile_types");
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
6
  // tables or structures
7
7
  class HandleTable {
8
8
  runObject(obj, reg) {
@@ -1,5 +1,5 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile } from "./types";
2
+ import { IOutputFile } from "../types";
3
3
  export declare class HandleTableType {
4
4
  runObject(obj: abaplint.Objects.TableType, reg: abaplint.IRegistry): IOutputFile[];
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleTableType = void 0;
4
- const chunk_1 = require("./chunk");
5
- const transpile_types_1 = require("./transpile_types");
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
6
  class HandleTableType {
7
7
  runObject(obj, reg) {
8
8
  var _a;
@@ -0,0 +1,5 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IOutputFile } from "../types";
3
+ export declare class HandleView {
4
+ runObject(obj: abaplint.Objects.View, reg: abaplint.IRegistry): IOutputFile[];
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandleView = void 0;
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
+ // view, much like the tables
7
+ class HandleView {
8
+ runObject(obj, reg) {
9
+ var _a;
10
+ const filename = (_a = obj.getXMLFile()) === null || _a === void 0 ? void 0 : _a.getFilename().replace(".xml", ".mjs").toLowerCase();
11
+ if (filename === undefined) {
12
+ return [];
13
+ }
14
+ const type = obj.parseType(reg);
15
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
16
+ "objectType": "VIEW",
17
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
18
+ };`);
19
+ // todo, "keyFields": ${JSON.stringify(obj.listKeys())},
20
+ const output = {
21
+ object: {
22
+ name: obj.getName(),
23
+ type: obj.getType(),
24
+ },
25
+ filename: filename,
26
+ chunk: chunk,
27
+ requires: [],
28
+ exports: [],
29
+ };
30
+ return [output];
31
+ }
32
+ }
33
+ exports.HandleView = HandleView;
34
+ //# sourceMappingURL=handle_view.js.map
@@ -6,11 +6,12 @@ const validation_1 = require("./validation");
6
6
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return validation_1.config; } });
7
7
  const unit_test_1 = require("./unit_test");
8
8
  const keywords_1 = require("./keywords");
9
- const handle_table_1 = require("./handle_table");
10
- const handle_abap_1 = require("./handle_abap");
11
- const handle_data_element_1 = require("./handle_data_element");
12
- const handle_table_type_1 = require("./handle_table_type");
13
9
  const db_1 = require("./db");
10
+ const handle_table_1 = require("./handlers/handle_table");
11
+ const handle_abap_1 = require("./handlers/handle_abap");
12
+ const handle_data_element_1 = require("./handlers/handle_data_element");
13
+ const handle_table_type_1 = require("./handlers/handle_table_type");
14
+ const handle_view_1 = require("./handlers/handle_view");
14
15
  class Transpiler {
15
16
  constructor(options) {
16
17
  this.options = options;
@@ -59,6 +60,9 @@ class Transpiler {
59
60
  else if (obj instanceof abaplint.Objects.Table) {
60
61
  output.objects.push(...new handle_table_1.HandleTable().runObject(obj, reg));
61
62
  }
63
+ else if (obj instanceof abaplint.Objects.View) {
64
+ output.objects.push(...new handle_view_1.HandleView().runObject(obj, reg));
65
+ }
62
66
  else if (obj instanceof abaplint.Objects.DataElement) {
63
67
  output.objects.push(...new handle_data_element_1.HandleDataElement().runObject(obj, reg));
64
68
  }
@@ -11,9 +11,9 @@ class Keywords {
11
11
  continue;
12
12
  }
13
13
  for (const f of o.getABAPFiles()) {
14
- let tokens = [];
14
+ const tokens = [];
15
15
  for (const s of f.getStatements()) {
16
- tokens = tokens.concat(this.traverse(s, f));
16
+ tokens.push(...this.traverse(s, f));
17
17
  }
18
18
  if (tokens.length === 0) {
19
19
  continue;
@@ -51,6 +51,7 @@ class Keywords {
51
51
  ];
52
52
  // "with"
53
53
  // "delete"
54
+ keywords.push(...keywords.map(k => "!" + k));
54
55
  let ret = [];
55
56
  for (const c of node.getChildren()) {
56
57
  if (c instanceof abaplint.Nodes.TokenNodeRegex) {
@@ -28,7 +28,7 @@ exports.config = {
28
28
  },
29
29
  "parser_error": true,
30
30
  "allowed_object_types": {
31
- "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "XSLT", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
31
+ "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "VIEW", "XSLT", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
32
32
  },
33
33
  /*
34
34
  "exit_or_check": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.1.92",
3
+ "version": "2.2.1",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "author": "abaplint",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@abaplint/core": "^2.93.33",
31
+ "@abaplint/core": "^2.93.35",
32
32
  "source-map": "^0.7.4"
33
33
  },
34
34
  "devDependencies": {