@abaplint/transpiler 2.13.1 → 2.13.3

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.
@@ -77,9 +77,11 @@ class PopulateTables {
77
77
  else if (parameter.getMeta().includes("exporting" /* abaplint.IdentifierMeta.MethodExporting */)) {
78
78
  pardecltyp = "1";
79
79
  }
80
- const paroptionl = optionalParameters.includes(parameter.getName()) ? "X" : " ";
80
+ const name = parameter.getName().toUpperCase();
81
+ const paroptionl = (optionalParameters.some(o => o.toUpperCase() === name) || method.getParameters().getParameterDefault(name) !== undefined) ? "X" : " ";
81
82
  const type = parameter.getType().getQualifiedName()?.toUpperCase() || "";
82
- ret.push(`INSERT INTO "seosubcodf" ("clsname", "cmpname", "sconame", "version", "editorder", "pardecltyp", "type", "paroptionl") VALUES ('${obj.getName()}', '${method.getName().toUpperCase()}', '${parameter.getName().toUpperCase()}', '1', ${editorder}, '${pardecltyp}', '${type}', '${paroptionl}');`);
83
+ const parvalue = method.getParameters().getParameterDefault(name)?.concatTokens() || "";
84
+ ret.push(`INSERT INTO "seosubcodf" ("clsname", "cmpname", "sconame", "version", "editorder", "pardecltyp", "type", "paroptionl", "parvalue") VALUES ('${obj.getName()}', '${method.getName().toUpperCase()}', '${name}', '1', ${editorder}, '${pardecltyp}', '${type}', '${paroptionl}', '${this.escape(parvalue)}');`);
83
85
  }
84
86
  }
85
87
  return ret;
@@ -90,9 +92,32 @@ class PopulateTables {
90
92
  if (def === undefined || !this.hasSEOSUBCOTX) {
91
93
  return [];
92
94
  }
95
+ const descriptions = [];
96
+ const xml = obj.getXML();
97
+ if (xml) {
98
+ const parsed = obj.parseRaw2();
99
+ const sub = parsed?.abapGit["asx:abap"]["asx:values"]?.DESCRIPTIONS?.SEOSUBCOTX;
100
+ if (sub) {
101
+ if (Array.isArray(sub)) {
102
+ descriptions.push(...sub);
103
+ }
104
+ else {
105
+ descriptions.push(sub);
106
+ }
107
+ }
108
+ }
93
109
  for (const method of def.getMethodDefinitions().getAll()) {
94
110
  for (const parameter of method.getParameters().getAll()) {
95
- ret.push(`INSERT INTO "seosubcotx" ("clsname", "cmpname", "sconame", "langu", "descript") VALUES ('${obj.getName()}', '${method.getName().toUpperCase()}', '${parameter.getName().toUpperCase()}', 'E', 'todo');`);
111
+ const mName = method.getName().toUpperCase();
112
+ const pName = parameter.getName().toUpperCase();
113
+ let descript = "";
114
+ for (const d of descriptions) {
115
+ if (d.CMPNAME?.toUpperCase() === mName && d.SCONAME?.toUpperCase() === pName) {
116
+ descript = d.DESCRIPT || "";
117
+ break;
118
+ }
119
+ }
120
+ ret.push(`INSERT INTO "seosubcotx" ("clsname", "cmpname", "sconame", "langu", "descript") VALUES ('${obj.getName()}', '${mName}', '${pName}', 'E', '${this.escape(descript)}');`);
96
121
  }
97
122
  }
98
123
  return ret;
@@ -4,5 +4,6 @@ import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class DataTranspiler implements IStatementTranspiler {
6
6
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
+ static findEnumDefault(scope: abaplint.ISpaghettiScopeNode, _enumType: abaplint.AbstractType): string | undefined;
7
8
  static buildValue(node: abaplint.Nodes.StatementNode, name: string, traversal: Traversal): string;
8
9
  }
@@ -28,6 +28,13 @@ class DataTranspiler {
28
28
  else {
29
29
  value = DataTranspiler.buildValue(node, traversal_1.Traversal.prefixVariable(found.getName().toLowerCase()), traversal);
30
30
  }
31
+ // for enum types, initialize with the first enum value
32
+ if (found.getType() instanceof abaplint.BasicTypes.EnumType && value === "") {
33
+ const enumDefault = DataTranspiler.findEnumDefault(scope, found.getType());
34
+ if (enumDefault) {
35
+ value = "\n" + traversal_1.Traversal.prefixVariable(found.getName().toLowerCase()) + ".set(\"" + enumDefault + "\");";
36
+ }
37
+ }
31
38
  const ret = new chunk_1.Chunk()
32
39
  .appendString("let ")
33
40
  .appendString(traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(found.getName().toLowerCase())))
@@ -36,6 +43,26 @@ class DataTranspiler {
36
43
  .appendString(value);
37
44
  return ret;
38
45
  }
46
+ static findEnumDefault(scope, _enumType) {
47
+ let current = scope;
48
+ while (current) {
49
+ const vars = current.getData().vars;
50
+ for (const key of Object.keys(vars)) {
51
+ const v = vars[key];
52
+ if (v.getMeta().includes("enum" /* abaplint.IdentifierMeta.Enum */)) {
53
+ const structType = v.getType();
54
+ if (structType instanceof abaplint.BasicTypes.StructureType) {
55
+ const components = structType.getComponents();
56
+ if (components.length > 0) {
57
+ return components[0].name.toUpperCase();
58
+ }
59
+ }
60
+ }
61
+ }
62
+ current = current.getParent();
63
+ }
64
+ return undefined;
65
+ }
39
66
  static buildValue(node, name, traversal) {
40
67
  let value = "";
41
68
  const val = node.findFirstExpression(abaplint.Expressions.Value);
@@ -15,6 +15,7 @@ export * from "./module";
15
15
  export * from "./select";
16
16
  export * from "./method";
17
17
  export * from "./try";
18
+ export * from "./type_enum";
18
19
  export * from "./types";
19
20
  export * from "./when";
20
21
  export * from "./while";
@@ -31,6 +31,7 @@ __exportStar(require("./module"), exports);
31
31
  __exportStar(require("./select"), exports);
32
32
  __exportStar(require("./method"), exports);
33
33
  __exportStar(require("./try"), exports);
34
+ __exportStar(require("./type_enum"), exports);
34
35
  __exportStar(require("./types"), exports);
35
36
  __exportStar(require("./when"), exports);
36
37
  __exportStar(require("./while"), exports);
@@ -0,0 +1,7 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IStructureTranspiler } from "./_structure_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class TypeEnumTranspiler implements IStructureTranspiler {
6
+ transpile(node: abaplint.Nodes.StructureNode, _traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeEnumTranspiler = void 0;
4
+ const abaplint = require("@abaplint/core");
5
+ const traversal_1 = require("../traversal");
6
+ const chunk_1 = require("../chunk");
7
+ class TypeEnumTranspiler {
8
+ transpile(node, _traversal) {
9
+ const begin = node.findDirectStatement(abaplint.Statements.TypeEnumBegin);
10
+ if (begin === undefined) {
11
+ return new chunk_1.Chunk("");
12
+ }
13
+ const nsNames = begin.findAllExpressions(abaplint.Expressions.NamespaceSimpleName);
14
+ if (nsNames.length < 2) {
15
+ return new chunk_1.Chunk("");
16
+ }
17
+ const structureName = nsNames[1].concatTokens().toLowerCase();
18
+ const values = [];
19
+ for (const t of node.findDirectStatements(abaplint.Statements.Type)) {
20
+ const name = t.findFirstExpression(abaplint.Expressions.NamespaceSimpleName);
21
+ if (name) {
22
+ values.push(name.concatTokens().toLowerCase());
23
+ }
24
+ }
25
+ const fields = values.map(v => `"${v}": new abap.types.String()`).join(",\n");
26
+ let ret = `let ${traversal_1.Traversal.prefixVariable(structureName)} = new abap.types.Structure({
27
+ ${fields}});\n`;
28
+ for (const v of values) {
29
+ ret += `${traversal_1.Traversal.prefixVariable(structureName)}.get().${v}.set("${v.toUpperCase()}");\n`;
30
+ }
31
+ return new chunk_1.Chunk(ret);
32
+ }
33
+ }
34
+ exports.TypeEnumTranspiler = TypeEnumTranspiler;
35
+ //# sourceMappingURL=type_enum.js.map
@@ -176,9 +176,15 @@ class TranspileTypes {
176
176
  }
177
177
  else if (type instanceof abaplint.BasicTypes.HexType) {
178
178
  resolved = featureHexUInt8 ? "HexUInt8" : "Hex";
179
- if (type.getLength() !== 1) {
179
+ if (type.getLength() !== 1 && type.getQualifiedName() !== undefined) {
180
+ extra = "{length: " + type.getLength() + ", qualifiedName: \"" + type.getQualifiedName()?.toUpperCase() + "\"}";
181
+ }
182
+ else if (type.getLength() !== 1) {
180
183
  extra = "{length: " + type.getLength() + "}";
181
184
  }
185
+ else if (type.getQualifiedName() !== undefined) {
186
+ extra = "{qualifiedName: \"" + type.getQualifiedName()?.toUpperCase() + "\"}";
187
+ }
182
188
  }
183
189
  else if (type instanceof abaplint.BasicTypes.FloatType) {
184
190
  resolved = "Float";
@@ -195,6 +201,12 @@ class TranspileTypes {
195
201
  else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
196
202
  resolved = "DecFloat34";
197
203
  }
204
+ else if (type instanceof abaplint.BasicTypes.EnumType) {
205
+ resolved = "String";
206
+ if (type.getQualifiedName() !== undefined) {
207
+ extra = "{qualifiedName: \"" + type.getQualifiedName()?.toUpperCase() + "\"}";
208
+ }
209
+ }
198
210
  else if (type instanceof abaplint.BasicTypes.UnknownType) {
199
211
  return `(() => { throw new Error("Unknown type: ${type.getError()}") })()`;
200
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.13.1",
3
+ "version": "2.13.3",
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.118.2",
32
+ "@abaplint/core": "^2.118.7",
33
33
  "source-map": "^0.7.6"
34
34
  },
35
35
  "devDependencies": {