@abaplint/transpiler-cli 2.10.50 → 2.10.52

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.
Files changed (2) hide show
  1. package/build/bundle.js +117 -67
  2. package/package.json +3 -3
package/build/bundle.js CHANGED
@@ -80864,16 +80864,16 @@ class Initialization {
80864
80864
  let ret = "";
80865
80865
  if (useImport === true) {
80866
80866
  ret = `/* eslint-disable import/newline-after-import */
80867
- import "./_top.mjs";\n`;
80867
+ import "./_top.mjs";\n`;
80868
80868
  }
80869
80869
  else {
80870
80870
  ret = `/* eslint-disable import/newline-after-import */
80871
- import runtime from "@abaplint/runtime";
80872
- globalThis.abap = new runtime.ABAP();\n`;
80871
+ import runtime from "@abaplint/runtime";
80872
+ globalThis.abap = new runtime.ABAP();\n`;
80873
80873
  }
80874
80874
  ret += `${this.buildImports(reg, useImport)}
80875
80875
 
80876
- export async function initializeABAP() {\n`;
80876
+ export async function initializeABAP() {\n`;
80877
80877
  ret += ` const sqlite = [];\n`;
80878
80878
  for (const i of dbSetup.schemas.sqlite) {
80879
80879
  ret += ` sqlite.push(\`${i}\`);\n`;
@@ -80931,21 +80931,18 @@ class Initialization {
80931
80931
  }
80932
80932
  }
80933
80933
  for (const obj of reg.getObjects()) {
80934
- if (obj instanceof abaplint.Objects.FunctionGroup) {
80935
- list.push(imp(`${escapeNamespaceFilename(obj.getName().toLowerCase())}.fugr`));
80934
+ const name = imp(`${escapeNamespaceFilename(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`);
80935
+ if (obj instanceof abaplint.Objects.Class
80936
+ && obj.getName().toUpperCase() !== "CL_ABAP_CHAR_UTILITIES"
80937
+ && this.hasClassConstructor(reg, obj)) {
80938
+ // this will not solve all problems with class constructors 100%, but probably good enough
80939
+ late.push(name);
80936
80940
  }
80937
- else if (obj instanceof abaplint.Objects.Class) {
80938
- if (obj.getName().toUpperCase() !== "CL_ABAP_CHAR_UTILITIES"
80939
- && this.hasClassConstructor(reg, obj)) {
80940
- // this will not solve all problems with class constors 100%, but probably good enough
80941
- late.push(imp(`${escapeNamespaceFilename(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
80942
- }
80943
- else {
80944
- list.push(imp(`${escapeNamespaceFilename(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
80945
- }
80946
- }
80947
- else if (obj instanceof abaplint.Objects.Interface) {
80948
- list.push(imp(`${escapeNamespaceFilename(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
80941
+ else if (obj instanceof abaplint.Objects.Interface
80942
+ || obj instanceof abaplint.Objects.FunctionGroup
80943
+ || obj instanceof abaplint.Objects.Program
80944
+ || obj instanceof abaplint.Objects.Class) {
80945
+ list.push(name);
80949
80946
  }
80950
80947
  }
80951
80948
  return [...list.sort(), ...late].join("\n");
@@ -81453,34 +81450,35 @@ class AssignTranspiler {
81453
81450
  if (firstFirst?.get() instanceof abaplint.Expressions.Constant) {
81454
81451
  const s = firstFirst.getFirstToken().getStr().toLowerCase().match(/\w+/)?.toString();
81455
81452
  options.push(`dynamicSource: (() => {
81456
- try { return ${s}; } catch {}
81457
- try { return this.${s}; } catch {}
81458
- })()`);
81453
+ try { return ${s}; } catch {}
81454
+ try { return this.${s}; } catch {}
81455
+ })()`);
81459
81456
  }
81460
81457
  else if (firstFirst?.get() instanceof abaplint.Expressions.FieldChain && firstFirst instanceof abaplint.Nodes.ExpressionNode) {
81461
81458
  const code = new expressions_1.FieldChainTranspiler(true).transpile(firstFirst, traversal).getCode();
81462
81459
  options.push(`dynamicSource: (() => {
81463
- const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
81464
- try { return eval(name); } catch {}
81465
- try { return eval("this." + name); } catch {}
81466
- })()`);
81460
+ const name = ${code}.toLowerCase().replace(/[~\\/]/g, "$").match(/[\\w\\$\\/]+/)[0];
81461
+ try { return eval(name); } catch {}
81462
+ try { return eval("this." + name); } catch {}
81463
+ })()`);
81467
81464
  }
81468
81465
  }
81469
81466
  else if (first?.get() instanceof abaplint.Expressions.Source && first instanceof abaplint.Nodes.ExpressionNode) {
81470
81467
  // const name = first.concatTokens().toLowerCase();
81471
81468
  const name = new expressions_1.SourceTranspiler().transpile(first, traversal).getCode();
81472
81469
  options.push(`dynamicSource: (() => {
81473
- try { return ${name}; } catch {}
81474
- try { return this.${name}; } catch {}
81475
- })()`);
81470
+ try { return ${name}; } catch {}
81471
+ try { return this.${name}; } catch {}
81472
+ })()`);
81476
81473
  }
81477
81474
  }
81478
81475
  if (concat.endsWith(" CASTING.") || concat.includes(" CASTING TYPE ")) {
81479
81476
  options.push("casting: true");
81480
81477
  }
81481
- return new chunk_1.Chunk().append("abap.statements.assign({", node, traversal)
81478
+ const ret = new chunk_1.Chunk().append("abap.statements.assign({", node, traversal)
81482
81479
  .appendString(options.join(", "))
81483
81480
  .append("});", node.getLastToken(), traversal);
81481
+ return ret;
81484
81482
  }
81485
81483
  }
81486
81484
  exports.AssignTranspiler = AssignTranspiler;
@@ -81764,8 +81762,8 @@ class CallFunctionTranspiler {
81764
81762
  else {
81765
81763
  const illegalFunc = traversal.lookupClassOrInterface("'CX_SY_DYN_CALL_ILLEGAL_FUNC'", node.getFirstToken(), true);
81766
81764
  const call = `abap.FunctionModules[${fmname}]`;
81767
- ret.appendString(`if (${call} === undefined && ${illegalFunc} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_FUNC not found"; }\n`);
81768
- ret.appendString(`if (${call} === undefined) { throw new ${illegalFunc}(); }\n`);
81765
+ // eslint-disable-next-line max-len
81766
+ ret.appendString(`if (${call} === undefined) { if (${illegalFunc} === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_FUNC not found"; } else { throw new ${illegalFunc}();} }\n`);
81769
81767
  ret.appendString(`await ${call}(${param});`);
81770
81768
  }
81771
81769
  if (exceptions) {
@@ -85201,47 +85199,67 @@ class PerformTranspiler {
85201
85199
  return new chunk_1.Chunk(`throw new Error("PerformTranspiler FormName not found");`);
85202
85200
  }
85203
85201
  else if (node.concatTokens().toUpperCase().includes(" IN PROGRAM ")) {
85204
- return new chunk_1.Chunk(`throw new Error("PerformTranspiler IN PROGRAM, transpiler todo");`);
85205
- }
85206
- let def = undefined;
85207
- const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
85208
- for (const r of scope?.getData().references || []) {
85209
- if (r.referenceType === abaplint.ReferenceType.FormReference
85210
- && r.position.getStart().equals(formName.getFirstToken().getStart())
85211
- && r.resolved instanceof abaplint.Types.FormDefinition) {
85212
- def = r.resolved;
85202
+ // todo: throw exception if not found?
85203
+ const expression = node.findExpressionAfterToken("PROGRAM");
85204
+ let ref = "";
85205
+ if (expression?.get() instanceof abaplint.Expressions.Dynamic) {
85206
+ const name = expression.getChildren()[1].concatTokens() + ".get().trimEnd()";
85207
+ ref = `abap.Forms['PROG-' + ${name} + '-${formName.concatTokens().toUpperCase()}']`;
85213
85208
  }
85214
- }
85215
- // todo: pass by VALUE()
85216
- const params = [];
85217
- let index = 0;
85218
- for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
85219
- const name = def?.getTablesParameters()[index].getName().toLowerCase();
85220
- if (name === undefined) {
85221
- continue;
85209
+ else {
85210
+ const progName = expression?.concatTokens().toUpperCase();
85211
+ ref = `abap.Forms['PROG-${progName}-${formName.concatTokens().toUpperCase()}']`;
85222
85212
  }
85223
- params.push(`"${name}": ` + traversal.traverse(t).getCode());
85224
- index++;
85225
- }
85226
- index = 0;
85227
- for (const u of node.findDirectExpression(abaplint.Expressions.PerformUsing)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
85228
- const name = def?.getUsingParameters()[index].getName().toLowerCase();
85229
- if (name === undefined) {
85230
- continue;
85213
+ const params = [];
85214
+ // hacky hack
85215
+ for (const t of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Target) || []) {
85216
+ const name = t.getFirstToken().getStr();
85217
+ params.push(`"${name}": ` + traversal.traverse(t).getCode());
85231
85218
  }
85232
- params.push(`"${name}": ` + traversal.traverse(u).getCode());
85233
- index++;
85219
+ return new chunk_1.Chunk("await " + ref + `({${params.join(",")}});`);
85234
85220
  }
85235
- index = 0;
85236
- for (const c of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
85237
- const name = def?.getChangingParameters()[index].getName().toLowerCase();
85238
- if (name === undefined) {
85239
- continue;
85221
+ else {
85222
+ // todo: most of this needs rewriting?
85223
+ let def = undefined;
85224
+ const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
85225
+ for (const r of scope?.getData().references || []) {
85226
+ if (r.referenceType === abaplint.ReferenceType.FormReference
85227
+ && r.position.getStart().equals(formName.getFirstToken().getStart())
85228
+ && r.resolved instanceof abaplint.Types.FormDefinition) {
85229
+ def = r.resolved;
85230
+ }
85231
+ }
85232
+ // todo: pass by VALUE()
85233
+ const params = [];
85234
+ let index = 0;
85235
+ for (const t of node.findDirectExpression(abaplint.Expressions.PerformTables)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
85236
+ const name = def?.getTablesParameters()[index].getName().toLowerCase();
85237
+ if (name === undefined) {
85238
+ continue;
85239
+ }
85240
+ params.push(`"${name}": ` + traversal.traverse(t).getCode());
85241
+ index++;
85240
85242
  }
85241
- params.push(`"${name}": ` + traversal.traverse(c).getCode());
85242
- index++;
85243
+ index = 0;
85244
+ for (const u of node.findDirectExpression(abaplint.Expressions.PerformUsing)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
85245
+ const name = def?.getUsingParameters()[index].getName().toLowerCase();
85246
+ if (name === undefined) {
85247
+ continue;
85248
+ }
85249
+ params.push(`"${name}": ` + traversal.traverse(u).getCode());
85250
+ index++;
85251
+ }
85252
+ index = 0;
85253
+ for (const c of node.findDirectExpression(abaplint.Expressions.PerformChanging)?.findDirectExpressions(abaplint.Expressions.Source) || []) {
85254
+ const name = def?.getChangingParameters()[index].getName().toLowerCase();
85255
+ if (name === undefined) {
85256
+ continue;
85257
+ }
85258
+ params.push(`"${name}": ` + traversal.traverse(c).getCode());
85259
+ index++;
85260
+ }
85261
+ return new chunk_1.Chunk("await " + formName.concatTokens() + `({${params.join(",")}});`);
85243
85262
  }
85244
- return new chunk_1.Chunk("await " + formName.concatTokens() + `({${params.join(",")}});`);
85245
85263
  }
85246
85264
  }
85247
85265
  exports.PerformTranspiler = PerformTranspiler;
@@ -87581,6 +87599,37 @@ exports.DoTranspiler = DoTranspiler;
87581
87599
 
87582
87600
  /***/ }),
87583
87601
 
87602
+ /***/ "./node_modules/@abaplint/transpiler/build/src/structures/form.js":
87603
+ /*!************************************************************************!*\
87604
+ !*** ./node_modules/@abaplint/transpiler/build/src/structures/form.js ***!
87605
+ \************************************************************************/
87606
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
87607
+
87608
+ "use strict";
87609
+
87610
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
87611
+ exports.FormTranspiler = void 0;
87612
+ const abaplint = __webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js");
87613
+ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
87614
+ class FormTranspiler {
87615
+ transpile(node, traversal) {
87616
+ const formName = node.findFirstStatement(abaplint.Statements.Form)
87617
+ ?.findDirectExpression(abaplint.Expressions.FormName)?.concatTokens()?.toUpperCase();
87618
+ const ret = new chunk_1.Chunk();
87619
+ for (const c of node.getChildren()) {
87620
+ ret.appendChunk(traversal.traverse(c));
87621
+ }
87622
+ if (formName && traversal.getCurrentObject().getType() === "PROG") {
87623
+ ret.appendString(`abap.Forms['PROG-${traversal.getCurrentObject().getName().toUpperCase()}-${formName}'] = ${formName?.toLowerCase()};`);
87624
+ }
87625
+ return ret;
87626
+ }
87627
+ }
87628
+ exports.FormTranspiler = FormTranspiler;
87629
+ //# sourceMappingURL=form.js.map
87630
+
87631
+ /***/ }),
87632
+
87584
87633
  /***/ "./node_modules/@abaplint/transpiler/build/src/structures/function_module.js":
87585
87634
  /*!***********************************************************************************!*\
87586
87635
  !*** ./node_modules/@abaplint/transpiler/build/src/structures/function_module.js ***!
@@ -87705,6 +87754,7 @@ __exportStar(__webpack_require__(/*! ./try */ "./node_modules/@abaplint/transpil
87705
87754
  __exportStar(__webpack_require__(/*! ./types */ "./node_modules/@abaplint/transpiler/build/src/structures/types.js"), exports);
87706
87755
  __exportStar(__webpack_require__(/*! ./when */ "./node_modules/@abaplint/transpiler/build/src/structures/when.js"), exports);
87707
87756
  __exportStar(__webpack_require__(/*! ./while */ "./node_modules/@abaplint/transpiler/build/src/structures/while.js"), exports);
87757
+ __exportStar(__webpack_require__(/*! ./form */ "./node_modules/@abaplint/transpiler/build/src/structures/form.js"), exports);
87708
87758
  //# sourceMappingURL=index.js.map
87709
87759
 
87710
87760
  /***/ }),
@@ -88255,7 +88305,7 @@ class TranspileTypes {
88255
88305
  asInclude[c.name.toLowerCase()] = true;
88256
88306
  }
88257
88307
  }
88258
- extra = "{" + list.join(", ") + "}";
88308
+ extra = "{\n" + list.join(",\n") + "}";
88259
88309
  if (type.getQualifiedName() !== undefined) {
88260
88310
  extra += ", \"" + type.getQualifiedName() + "\"";
88261
88311
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.10.50",
3
+ "version": "2.10.52",
4
4
  "description": "Transpiler - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -28,9 +28,9 @@
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
30
  "@abaplint/core": "^2.113.114",
31
- "@abaplint/transpiler": "^2.10.50",
31
+ "@abaplint/transpiler": "^2.10.52",
32
32
  "@types/glob": "^8.1.0",
33
- "@types/node": "^22.15.17",
33
+ "@types/node": "^22.15.18",
34
34
  "@types/progress": "^2.0.7",
35
35
  "glob": "=7.2.0",
36
36
  "progress": "^2.0.3",