@abaplint/transpiler-cli 2.14.4 → 2.14.5

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 +54 -28
  2. package/package.json +2 -2
package/build/bundle.js CHANGED
@@ -115523,6 +115523,16 @@ const source_1 = __webpack_require__(/*! ./source */ "./node_modules/@abaplint/t
115523
115523
  class ValueBodyLineTranspiler {
115524
115524
  transpile(rowType, line, traversal, extraFields) {
115525
115525
  const ret = new chunk_1.Chunk();
115526
+ const lines = line.findDirectExpression(core_1.Expressions.ValueBodyLines);
115527
+ if (lines) {
115528
+ const source = traversal.traverse(lines.findDirectExpression(core_1.Expressions.Source)).getCode();
115529
+ const from = lines.findExpressionAfterToken("FROM");
115530
+ const to = lines.findExpressionAfterToken("TO");
115531
+ const fromCode = from ? traversal.traverse(from).getCode() : "undefined";
115532
+ const toCode = to ? ", " + traversal.traverse(to).getCode() : "";
115533
+ const range = from || to ? ", " + fromCode + toCode : "";
115534
+ return ret.appendString(`.appendLines(${source}${range})`);
115535
+ }
115526
115536
  ret.appendString(`.appendThis(${transpile_types_1.TranspileTypes.toType(rowType)}`);
115527
115537
  for (const child of line.getChildren()) {
115528
115538
  if (child instanceof core_1.Nodes.TokenNode) {
@@ -116051,11 +116061,11 @@ class HandleSMIM {
116051
116061
  obj.parse();
116052
116062
  const dataFile = obj.getDataFile();
116053
116063
  const dataFilename = dataFile ? this.layout.file({ name: obj.getName(), type: obj.getType() }, dataFile.getFilename()) : undefined;
116054
- const chunk = new chunk_1.Chunk().appendString(`abap.SMIM["${obj.getName().toUpperCase()}"] = {
116055
- "objectType": "SMIM",
116056
- "filename": ${JSON.stringify(dataFilename)},
116057
- "url": ${JSON.stringify(obj.getURL())},
116058
- "class": ${JSON.stringify(obj.getClass())},
116064
+ const chunk = new chunk_1.Chunk().appendString(`abap.SMIM["${obj.getName().toUpperCase()}"] = {
116065
+ "objectType": "SMIM",
116066
+ "filename": ${JSON.stringify(dataFilename)},
116067
+ "url": ${JSON.stringify(obj.getURL())},
116068
+ "class": ${JSON.stringify(obj.getClass())},
116059
116069
  };`);
116060
116070
  const output = {
116061
116071
  object: {
@@ -116342,9 +116352,9 @@ class HandleW3MI {
116342
116352
  obj.parse();
116343
116353
  const dataFile = obj.getDataFile();
116344
116354
  const dataFilename = dataFile ? this.layout.file({ name: obj.getName(), type: obj.getType() }, dataFile.getFilename()) : undefined;
116345
- const chunk = new chunk_1.Chunk().appendString(`abap.W3MI["${(0, w3mi_name_1.w3miObjectName)(obj)}"] = {
116346
- "objectType": "W3MI",
116347
- "filename": ${JSON.stringify(dataFilename)},
116355
+ const chunk = new chunk_1.Chunk().appendString(`abap.W3MI["${(0, w3mi_name_1.w3miObjectName)(obj)}"] = {
116356
+ "objectType": "W3MI",
116357
+ "filename": ${JSON.stringify(dataFilename)},
116348
116358
  };`);
116349
116359
  const output = {
116350
116360
  object: {
@@ -116624,12 +116634,12 @@ class Initialization {
116624
116634
  script(reg, dbSetup, options, useImport) {
116625
116635
  let ret = "";
116626
116636
  if (useImport === true) {
116627
- ret = `/* eslint-disable import/newline-after-import */
116637
+ ret = `/* eslint-disable import/newline-after-import */
116628
116638
  import "./_top.mjs";\n`;
116629
116639
  }
116630
116640
  else {
116631
- ret = `/* eslint-disable import/newline-after-import */
116632
- import runtime from "@abaplint/runtime";
116641
+ ret = `/* eslint-disable import/newline-after-import */
116642
+ import runtime from "@abaplint/runtime";
116633
116643
  globalThis.abap = new runtime.ABAP();\n`;
116634
116644
  }
116635
116645
  if (options?.setup?.filename === undefined || options?.setup?.filename === "") {
@@ -129568,21 +129578,20 @@ class TryTranspiler {
129568
129578
  transpile(node, traversal) {
129569
129579
  const ret = new chunk_1.Chunk();
129570
129580
  const catches = node.findDirectStructures(abaplint.Structures.Catch);
129571
- const cleanup = node.findDirectStructures(abaplint.Structures.Cleanup);
129572
- let catchCode = this.buildCatchCode(catches, traversal);
129581
+ const cleanup = node.findDirectStructure(abaplint.Structures.Cleanup);
129582
+ // the CATCH blocks and the CLEANUP block become one javascript catch
129583
+ let handlerCode = this.buildHandlerCode(catches, cleanup, traversal);
129573
129584
  for (const c of node.getChildren()) {
129574
- if (c.get() instanceof abaplint.Structures.Catch) {
129575
- if (catchCode) {
129576
- ret.appendChunk(catchCode);
129585
+ if (c.get() instanceof abaplint.Structures.Catch
129586
+ || c.get() instanceof abaplint.Structures.Cleanup) {
129587
+ if (handlerCode) {
129588
+ ret.appendChunk(handlerCode);
129577
129589
  }
129578
- catchCode = undefined;
129579
- }
129580
- else if (c.get() instanceof abaplint.Structures.Cleanup) {
129581
- ret.appendString(`} finally {\n// Transpiler todo: CLEANUP ignored\n`);
129590
+ handlerCode = undefined;
129582
129591
  }
129583
129592
  else if (c.get() instanceof abaplint.Statements.Try
129584
129593
  || c.get() instanceof abaplint.Statements.EndTry) {
129585
- if (catches.length === 0 && cleanup.length === 0) {
129594
+ if (catches.length === 0 && cleanup === undefined) {
129586
129595
  continue;
129587
129596
  }
129588
129597
  ret.appendChunk(traversal.traverse(c));
@@ -129594,11 +129603,11 @@ class TryTranspiler {
129594
129603
  return ret;
129595
129604
  }
129596
129605
  /////////////////////
129597
- buildCatchCode(nodes, traversal) {
129606
+ buildHandlerCode(nodes, cleanup, traversal) {
129598
129607
  let ret = "";
129599
129608
  let first = true;
129600
- if (nodes.length === 0) {
129601
- return new chunk_1.Chunk(ret);
129609
+ if (nodes.length === 0 && cleanup === undefined) {
129610
+ return undefined;
129602
129611
  }
129603
129612
  ret += `} catch (e) {\n`;
129604
129613
  for (const n of nodes) {
@@ -129620,12 +129629,29 @@ class TryTranspiler {
129620
129629
  }
129621
129630
  ret += "}";
129622
129631
  }
129623
- // "else" unhandled in this TRY-CATCH, or a javascript runtime error
129624
- ret += ` else {\n` +
129625
- `throw e;\n` +
129626
- `}\n`;
129632
+ // unhandled in this TRY-CATCH, or a javascript runtime error
129633
+ const unhandled = this.buildCleanupCode(cleanup, traversal) + `throw e;\n`;
129634
+ ret += nodes.length > 0 ? ` else {\n` + unhandled + `}\n` : unhandled;
129627
129635
  return new chunk_1.Chunk(ret);
129628
129636
  }
129637
+ /** CLEANUP runs when a class based exception leaves the TRY block, not for an exception raised
129638
+ * in a CATCH block of the same TRY, and not for javascript runtime errors */
129639
+ buildCleanupCode(cleanup, traversal) {
129640
+ if (cleanup === undefined) {
129641
+ return "";
129642
+ }
129643
+ const cxRoot = traversal.lookupClassOrInterface("CX_ROOT", cleanup.getFirstToken());
129644
+ let ret = `if (${cxRoot} && e instanceof ${cxRoot}) {\n`;
129645
+ const intoNode = cleanup.findDirectStatement(abaplint.Statements.Cleanup)?.findExpressionAfterToken("INTO");
129646
+ if (intoNode) {
129647
+ ret += traversal.traverse(intoNode).getCode() + ".set(e);\n";
129648
+ }
129649
+ const body = cleanup.findDirectStructure(abaplint.Structures.Body);
129650
+ if (body) {
129651
+ ret += traversal.traverse(body).getCode();
129652
+ }
129653
+ return ret + `}\n`;
129654
+ }
129629
129655
  }
129630
129656
  exports.TryTranspiler = TryTranspiler;
129631
129657
  //# sourceMappingURL=try.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.14.4",
3
+ "version": "2.14.5",
4
4
  "description": "Transpiler - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
30
  "@abaplint/core": "^2.120.77",
31
- "@abaplint/transpiler": "^2.14.4",
31
+ "@abaplint/transpiler": "^2.14.5",
32
32
  "@types/glob": "^9.0.0",
33
33
  "@types/node": "^26.6.2",
34
34
  "@types/progress": "^2.0.7",