@abaplint/transpiler-cli 2.14.19 → 2.14.20

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.
package/README.md CHANGED
@@ -77,7 +77,8 @@ Imports and registered MIME filenames reference the new paths.
77
77
 
78
78
  Shared initialization scripts and test runners remain at the output root.
79
79
  Run programs with `node output/project/zapp.prog.mjs`; run project unit tests
80
- with `node output/index.mjs`. When migrating from flat output, rebuild a clean
80
+ with `node output/index.mjs`. Importing a program module, eg. for its unit tests,
81
+ does not run the program; call its exported `$main()` to run it. When migrating from flat output, rebuild a clean
81
82
  generated output directory and update scripts that reference individual
82
83
  modules or assets.
83
84
 
package/build/bundle.js CHANGED
@@ -1091,6 +1091,8 @@ exports.collectObjectFiles = collectObjectFiles;
1091
1091
  const path = __importStar(__webpack_require__(/*! path */ "path"));
1092
1092
  const url_1 = __webpack_require__(/*! url */ "url");
1093
1093
  const transpiler_1 = __webpack_require__(/*! @abaplint/transpiler */ "./node_modules/@abaplint/transpiler/build/src/index.js");
1094
+ /** the exported function of a program module running the program, see HandleABAP in the transpiler */
1095
+ const PROGRAM_MAIN = "$main";
1094
1096
  function collectObjectFiles(outputFiles, config, files) {
1095
1097
  const root = path.resolve(config.output_folder);
1096
1098
  const filesToWrite = [];
@@ -1105,6 +1107,11 @@ function collectObjectFiles(outputFiles, config, files) {
1105
1107
  if (type === "PROG") {
1106
1108
  contents = 'if (!globalThis.abap) await import("' + (0, transpiler_1.importPath)(output.filename, "_init.mjs") + '");\n' + contents;
1107
1109
  generatedLineOffset = 1;
1110
+ if (output.exports.includes(PROGRAM_MAIN)) {
1111
+ // run the program when executed directly, "node zapp.prog.mjs", not when imported eg. for unit testing
1112
+ contents += "\nif (process.argv[1] !== undefined"
1113
+ + ` && import.meta.url === (await import("url")).pathToFileURL(process.argv[1]).href) await ${PROGRAM_MAIN}();`;
1114
+ }
1108
1115
  }
1109
1116
  if (config.write_source_map === true && (type === "PROG" || type === "FUGR" || type === "CLAS")) {
1110
1117
  const name = output.filename + ".map";
@@ -57014,6 +57021,8 @@ class MethodParameters {
57014
57021
  || concat.includes(" FOR FEATURES ")
57015
57022
  || concat.includes(" FOR INSTANCE FEATURES ")
57016
57023
  || concat.includes(" FOR GLOBAL AUTHORIZATION ")
57024
+ || concat.includes(" FOR INSTANCE AUTHORIZATION ")
57025
+ || concat.includes(" FOR AUTHORIZATION ")
57017
57026
  || concat.includes(" FOR PRECHECK ")
57018
57027
  || concat.includes(" FOR NUMBERING ")
57019
57028
  || concat.includes(" FOR READ ")
@@ -74232,7 +74241,7 @@ class Registry {
74232
74241
  }
74233
74242
  static abaplintVersion() {
74234
74243
  // magic, see build script "version.js"
74235
- return "2.120.94";
74244
+ return "2.120.95";
74236
74245
  }
74237
74246
  getDDICReferences() {
74238
74247
  return this.ddicReferences;
@@ -121749,7 +121758,7 @@ class SQLCondTranspiler {
121749
121758
  if (found) {
121750
121759
  let name = traversal.prefixAndName(alias.getFirstToken(), filename).replace("~", "$");
121751
121760
  name = traversal_1.Traversal.escapeNamespace(name);
121752
- ret += "'\" + " + name + ".get() + \"'";
121761
+ ret += "'\" + abap.sqlEscape(" + name + ".get()) + \"'";
121753
121762
  }
121754
121763
  else {
121755
121764
  let concat = source.concatTokens();
@@ -121764,10 +121773,10 @@ class SQLCondTranspiler {
121764
121773
  const conversionField = traversal.isSQLConversion(source.getFirstToken());
121765
121774
  if (conversionField) {
121766
121775
  const field = (table?.parseType(traversal.reg)).getComponentByName(conversionField);
121767
- ret += "'\" + " + traversal.toType(field) + ".set(" + concat + ").get() + \"'";
121776
+ ret += "'\" + abap.sqlEscape(" + traversal.toType(field) + ".set(" + concat + ").get()) + \"'";
121768
121777
  }
121769
121778
  else if (concat.startsWith("`")) {
121770
- ret += "'" + concat.substring(1, concat.length - 1) + "'";
121779
+ ret += "'" + concat.substring(1, concat.length - 1).replace(/'/g, "''") + "'";
121771
121780
  }
121772
121781
  else {
121773
121782
  ret += concat;
@@ -121777,9 +121786,10 @@ class SQLCondTranspiler {
121777
121786
  }
121778
121787
  sqlHost(code, numericHost) {
121779
121788
  if (numericHost) {
121780
- return `" + ((value) => typeof value === "number" || typeof value === "bigint" ? value : "'" + value + "'")(${code}) + "`;
121789
+ return `" + ((value) => typeof value === "number" || typeof value === "bigint" ? value `
121790
+ + `: "'" + abap.sqlEscape(value) + "'")(${code}) + "`;
121781
121791
  }
121782
- return "'\" + " + code + " + \"'";
121792
+ return "'\" + abap.sqlEscape(" + code + ") + \"'";
121783
121793
  }
121784
121794
  basicConditionNew(node, traversal, filename, table) {
121785
121795
  const sourceWithComponents = this.sourceWithComponents(node, traversal);
@@ -121800,7 +121810,7 @@ class SQLCondTranspiler {
121800
121810
  && child instanceof abaplint.Nodes.ExpressionNode
121801
121811
  && child.get() instanceof abaplint.Expressions.SimpleSource3) {
121802
121812
  const code = new simple_source3_1.SimpleSource3Transpiler(true).transpile(child, traversal).getCode();
121803
- ret += `'" + ${code} + "'`;
121813
+ ret += `'" + abap.sqlEscape(${code}) + "'`;
121804
121814
  hostExpression = false;
121805
121815
  }
121806
121816
  else if ((child.get() instanceof abaplint.Expressions.SQLFieldName
@@ -121809,7 +121819,7 @@ class SQLCondTranspiler {
121809
121819
  if (hostExpression) {
121810
121820
  let name = traversal.prefixAndName(child.getFirstToken(), filename).replace("~", "$");
121811
121821
  name = traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(name));
121812
- ret += `'" + ${name}.get() + "'`;
121822
+ ret += `'" + abap.sqlEscape(${name}.get()) + "'`;
121813
121823
  hostExpression = false;
121814
121824
  }
121815
121825
  else {
@@ -121872,7 +121882,7 @@ class SQLCondTranspiler {
121872
121882
  }
121873
121883
  code += ".get()";
121874
121884
  const field = new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldName, traversal).getCode();
121875
- return `${field} ${this.sqlOperator(operator.concatTokens())} '" + ${code} + "'`;
121885
+ return `${field} ${this.sqlOperator(operator.concatTokens())} '" + abap.sqlEscape(${code}) + "'`;
121876
121886
  }
121877
121887
  sqlOperator(op) {
121878
121888
  if (op.toUpperCase() === "EQ") {
@@ -121952,7 +121962,7 @@ class SQLFieldTranspiler {
121952
121962
  chunk.appendChunk(new sql_field_name_1.SQLFieldNameTranspiler().transpile(c, traversal));
121953
121963
  }
121954
121964
  else if (c.get() instanceof abaplint.Expressions.SimpleFieldChain2) {
121955
- chunk.appendString(`'" + ` + new field_chain_1.FieldChainTranspiler().transpile(c, traversal).getCode() + `.get() + "' `);
121965
+ chunk.appendString(`'" + abap.sqlEscape(` + new field_chain_1.FieldChainTranspiler().transpile(c, traversal).getCode() + `.get()) + "' `);
121956
121966
  }
121957
121967
  else {
121958
121968
  chunk.appendString(c.concatTokens() + " ");
@@ -122028,7 +122038,7 @@ class SQLFieldAndValueTranspiler {
122028
122038
  const source = traversal.traverse(n);
122029
122039
  // todo: value conversion? abap vs db, traversal.isSQLConversion
122030
122040
  // todo: integers?
122031
- chunk.appendString("'\" + " + source.getCode() + ".get() + \"'");
122041
+ chunk.appendString("'\" + abap.sqlEscape(" + source.getCode() + ".get()) + \"'");
122032
122042
  }
122033
122043
  else if (n instanceof abaplint.Nodes.TokenNode) {
122034
122044
  // operators/keywords, eg. the "+" in "field = field + value"
@@ -123789,9 +123799,18 @@ const rearranger_1 = __webpack_require__(/*! ../rearranger */ "./node_modules/@a
123789
123799
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
123790
123800
  const output_layout_1 = __webpack_require__(/*! ../output_layout */ "./node_modules/@abaplint/transpiler/build/src/output_layout.js");
123791
123801
  const type_factory_registry_1 = __webpack_require__(/*! ../type_factory_registry */ "./node_modules/@abaplint/transpiler/build/src/type_factory_registry.js");
123802
+ const program_includes_1 = __webpack_require__(/*! ../program_includes */ "./node_modules/@abaplint/transpiler/build/src/program_includes.js");
123792
123803
  class HandleABAP {
123793
123804
  layout;
123805
+ /** the function running the program, not a name a FORM or variable can be transpiled to */
123806
+ static PROGRAM_MAIN = "$main";
123794
123807
  options;
123808
+ /** executable programs as modules, their event blocks and other executable code are wrapped in a function */
123809
+ static wrapsMain(obj, options) {
123810
+ return options?.addCommonJS === true
123811
+ && obj instanceof abaplint.Objects.Program
123812
+ && obj.isInclude() === false;
123813
+ }
123795
123814
  constructor(options, layout = new output_layout_1.OutputLayout()) {
123796
123815
  this.layout = layout;
123797
123816
  this.options = options;
@@ -123831,13 +123850,33 @@ class HandleABAP {
123831
123850
  throw new Error("HandleABAP, file has no structure, probably a syntax error: " + file.getFilename());
123832
123851
  }
123833
123852
  const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
123834
- const contents = new traversal_1.Traversal(spaghetti, file, obj, reg, this.options, typeFactory).traverse(rearranged);
123853
+ const traversal = new traversal_1.Traversal(spaghetti, file, obj, reg, this.options, typeFactory);
123854
+ const wrapMain = HandleABAP.wrapsMain(obj, this.options);
123855
+ if (wrapMain) {
123856
+ traversal.programMain = new chunk_1.Chunk();
123857
+ }
123858
+ const contents = traversal.traverse(rearranged);
123835
123859
  chunk.appendChunk(contents);
123860
+ if (wrapMain) {
123861
+ // the program runs when main is called, importing the module eg. for unit testing does not run it
123862
+ chunk.appendString(`async function ${HandleABAP.PROGRAM_MAIN}() {\n`);
123863
+ chunk.appendChunk(traversal.programMain);
123864
+ chunk.appendString("}\n");
123865
+ }
123836
123866
  chunk.stripLastNewline();
123837
123867
  if (this.options?.sharedTypeFactories !== true) {
123838
123868
  chunk.runIndentationLogic(this.options?.ignoreSourceMap);
123839
123869
  }
123840
123870
  const exports = this.findExports(file.getStructure());
123871
+ if (obj instanceof abaplint.Objects.Program) {
123872
+ // INCLUDEs are expanded into the program, so export their contents too
123873
+ for (const include of (0, program_includes_1.findProgramIncludes)(file, reg)) {
123874
+ exports.push(...this.findExports(include.getStructure()).filter(e => exports.includes(e) === false));
123875
+ }
123876
+ }
123877
+ if (wrapMain) {
123878
+ exports.push(HandleABAP.PROGRAM_MAIN);
123879
+ }
123841
123880
  const output = {
123842
123881
  object: {
123843
123882
  name: obj.getName(),
@@ -125235,6 +125274,84 @@ function importPath(from, to) {
125235
125274
 
125236
125275
  /***/ },
125237
125276
 
125277
+ /***/ "./node_modules/@abaplint/transpiler/build/src/program_includes.js"
125278
+ /*!*************************************************************************!*\
125279
+ !*** ./node_modules/@abaplint/transpiler/build/src/program_includes.js ***!
125280
+ \*************************************************************************/
125281
+ (__unused_webpack_module, exports, __webpack_require__) {
125282
+
125283
+ "use strict";
125284
+
125285
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
125286
+ if (k2 === undefined) k2 = k;
125287
+ var desc = Object.getOwnPropertyDescriptor(m, k);
125288
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
125289
+ desc = { enumerable: true, get: function() { return m[k]; } };
125290
+ }
125291
+ Object.defineProperty(o, k2, desc);
125292
+ }) : (function(o, m, k, k2) {
125293
+ if (k2 === undefined) k2 = k;
125294
+ o[k2] = m[k];
125295
+ }));
125296
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
125297
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
125298
+ }) : function(o, v) {
125299
+ o["default"] = v;
125300
+ });
125301
+ var __importStar = (this && this.__importStar) || (function () {
125302
+ var ownKeys = function(o) {
125303
+ ownKeys = Object.getOwnPropertyNames || function (o) {
125304
+ var ar = [];
125305
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
125306
+ return ar;
125307
+ };
125308
+ return ownKeys(o);
125309
+ };
125310
+ return function (mod) {
125311
+ if (mod && mod.__esModule) return mod;
125312
+ var result = {};
125313
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
125314
+ __setModuleDefault(result, mod);
125315
+ return result;
125316
+ };
125317
+ })();
125318
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
125319
+ exports.filesWithProgramIncludes = filesWithProgramIncludes;
125320
+ exports.findProgramIncludes = findProgramIncludes;
125321
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
125322
+ /** the files of the object, for programs also the files of the include programs expanded into it */
125323
+ function filesWithProgramIncludes(obj, reg) {
125324
+ const files = obj.getSequencedFiles();
125325
+ if (!(obj instanceof abaplint.Objects.Program) || obj.isInclude() === true) {
125326
+ return files;
125327
+ }
125328
+ const ret = [...files];
125329
+ const visited = new Set();
125330
+ for (const file of files) {
125331
+ ret.push(...findProgramIncludes(file, reg, visited));
125332
+ }
125333
+ return ret;
125334
+ }
125335
+ /** include programs referenced by INCLUDE statements in the file, recursively, each returned once */
125336
+ function findProgramIncludes(file, reg, visited = new Set()) {
125337
+ const ret = [];
125338
+ for (const statement of file.getStructure()?.findAllStatements(abaplint.Statements.Include) || []) {
125339
+ const name = statement.findDirectExpression(abaplint.Expressions.IncludeName)?.concatTokens().toUpperCase();
125340
+ if (name === undefined || visited.has(name)) {
125341
+ continue;
125342
+ }
125343
+ visited.add(name);
125344
+ const include = reg.getObject("PROG", name)?.getMainABAPFile();
125345
+ if (include !== undefined) {
125346
+ ret.push(include, ...findProgramIncludes(include, reg, visited));
125347
+ }
125348
+ }
125349
+ return ret;
125350
+ }
125351
+ //# sourceMappingURL=program_includes.js.map
125352
+
125353
+ /***/ },
125354
+
125238
125355
  /***/ "./node_modules/@abaplint/transpiler/build/src/rearranger.js"
125239
125356
  /*!*******************************************************************!*\
125240
125357
  !*** ./node_modules/@abaplint/transpiler/build/src/rearranger.js ***!
@@ -125503,6 +125620,7 @@ var __importStar = (this && this.__importStar) || (function () {
125503
125620
  Object.defineProperty(exports, "__esModule", ({ value: true }));
125504
125621
  exports.Requires = void 0;
125505
125622
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
125623
+ const program_includes_1 = __webpack_require__(/*! ./program_includes */ "./node_modules/@abaplint/transpiler/build/src/program_includes.js");
125506
125624
  class Requires {
125507
125625
  reg;
125508
125626
  constructor(reg) {
@@ -125585,7 +125703,7 @@ class Requires {
125585
125703
  }
125586
125704
  }
125587
125705
  // include global super classes for local class definitions
125588
- for (const f of obj.getSequencedFiles()) {
125706
+ for (const f of (0, program_includes_1.filesWithProgramIncludes)(obj, this.reg)) {
125589
125707
  for (const c of f.getInfo().listClassDefinitions()) {
125590
125708
  if (c.superClassName === undefined) {
125591
125709
  continue;
@@ -125703,6 +125821,150 @@ exports.DatasetOperands = DatasetOperands;
125703
125821
 
125704
125822
  /***/ },
125705
125823
 
125824
+ /***/ "./node_modules/@abaplint/transpiler/build/src/statements/_eml.js"
125825
+ /*!************************************************************************!*\
125826
+ !*** ./node_modules/@abaplint/transpiler/build/src/statements/_eml.js ***!
125827
+ \************************************************************************/
125828
+ (__unused_webpack_module, exports, __webpack_require__) {
125829
+
125830
+ "use strict";
125831
+
125832
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
125833
+ if (k2 === undefined) k2 = k;
125834
+ var desc = Object.getOwnPropertyDescriptor(m, k);
125835
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
125836
+ desc = { enumerable: true, get: function() { return m[k]; } };
125837
+ }
125838
+ Object.defineProperty(o, k2, desc);
125839
+ }) : (function(o, m, k, k2) {
125840
+ if (k2 === undefined) k2 = k;
125841
+ o[k2] = m[k];
125842
+ }));
125843
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
125844
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
125845
+ }) : function(o, v) {
125846
+ o["default"] = v;
125847
+ });
125848
+ var __importStar = (this && this.__importStar) || (function () {
125849
+ var ownKeys = function(o) {
125850
+ ownKeys = Object.getOwnPropertyNames || function (o) {
125851
+ var ar = [];
125852
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
125853
+ return ar;
125854
+ };
125855
+ return ownKeys(o);
125856
+ };
125857
+ return function (mod) {
125858
+ if (mod && mod.__esModule) return mod;
125859
+ var result = {};
125860
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
125861
+ __setModuleDefault(result, mod);
125862
+ return result;
125863
+ };
125864
+ })();
125865
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
125866
+ exports.EMLWalker = exports.KERNEL_RAP_EML = void 0;
125867
+ exports.abapString = abapString;
125868
+ exports.abapFlag = abapFlag;
125869
+ exports.unsupportedAddition = unsupportedAddition;
125870
+ exports.emitCalls = emitCalls;
125871
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
125872
+ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
125873
+ /** The kernel class the EML statements are lowered to. One call per
125874
+ * operation of a statement; the names travel as strings, the FROM / WITH
125875
+ * table and the MAPPED, FAILED, REPORTED and RESULT targets as they are,
125876
+ * and only the targets the statement names are passed, the kernel binds
125877
+ * the rest. */
125878
+ exports.KERNEL_RAP_EML = "KERNEL_RAP_EML";
125879
+ function abapString(value) {
125880
+ return `new abap.types.String().set(${JSON.stringify(value)})`;
125881
+ }
125882
+ function abapFlag() {
125883
+ return `abap.CharacterFactory.get(1, 'X')`;
125884
+ }
125885
+ /** the EML forms this lowering does not handle, named in the statement */
125886
+ function unsupportedAddition(node, additions) {
125887
+ const tokens = node.getChildren().filter(c => c instanceof abaplint.Nodes.TokenNode).map(c => c.getFirstToken().getStr().toUpperCase());
125888
+ const text = " " + tokens.join(" ") + " ";
125889
+ for (const addition of additions) {
125890
+ if (text.includes(" " + addition + " ")) {
125891
+ return addition;
125892
+ }
125893
+ }
125894
+ if (node.findAllExpressions(abaplint.Expressions.EMLEntityPath).length > 0
125895
+ || node.findAllExpressions(abaplint.Expressions.EntityAssociation).length > 0) {
125896
+ return "BY";
125897
+ }
125898
+ return undefined;
125899
+ }
125900
+ function emitCalls(name, lookup, calls, node, traversal) {
125901
+ const ret = `if (${lookup} === undefined) throw new Error("${name}, kernel class missing");\n` + calls.join("\n");
125902
+ return new chunk_1.Chunk().append(ret, node, traversal);
125903
+ }
125904
+ /** a walker over the flat token and expression sequence of an EML statement */
125905
+ class EMLWalker {
125906
+ children;
125907
+ index = 0;
125908
+ constructor(node) {
125909
+ this.children = node.getChildren();
125910
+ }
125911
+ done() {
125912
+ return this.index >= this.children.length;
125913
+ }
125914
+ /** the next child as an upper case keyword, or undefined for an expression */
125915
+ peekKeyword() {
125916
+ const child = this.children[this.index];
125917
+ if (child instanceof abaplint.Nodes.TokenNode) {
125918
+ return child.getFirstToken().getStr().toUpperCase();
125919
+ }
125920
+ return undefined;
125921
+ }
125922
+ takeKeyword() {
125923
+ const keyword = this.peekKeyword();
125924
+ if (keyword !== undefined) {
125925
+ this.index++;
125926
+ }
125927
+ return keyword;
125928
+ }
125929
+ /** consume the keywords in order, or nothing when they are not next */
125930
+ accept(...keywords) {
125931
+ for (let i = 0; i < keywords.length; i++) {
125932
+ const child = this.children[this.index + i];
125933
+ if (!(child instanceof abaplint.Nodes.TokenNode) || child.getFirstToken().getStr().toUpperCase() !== keywords[i]) {
125934
+ return false;
125935
+ }
125936
+ }
125937
+ this.index += keywords.length;
125938
+ return true;
125939
+ }
125940
+ takeExpression() {
125941
+ const child = this.children[this.index];
125942
+ if (!(child instanceof abaplint.Nodes.ExpressionNode)) {
125943
+ throw new Error("EML: expected an expression, got " + (child?.concatTokens() ?? "the end of the statement"));
125944
+ }
125945
+ this.index++;
125946
+ return child;
125947
+ }
125948
+ /** an entity, action or behavior definition name, upper case */
125949
+ takeName() {
125950
+ return this.takeExpression().concatTokens().toUpperCase();
125951
+ }
125952
+ /** the SimpleNames of FIELDS ( a b ) up to the closing parenthesis, upper case */
125953
+ takeFieldList() {
125954
+ const names = [];
125955
+ this.accept("(");
125956
+ while (!this.done() && this.peekKeyword() !== ")") {
125957
+ names.push(this.takeName());
125958
+ }
125959
+ this.accept(")");
125960
+ return names;
125961
+ }
125962
+ }
125963
+ exports.EMLWalker = EMLWalker;
125964
+ //# sourceMappingURL=_eml.js.map
125965
+
125966
+ /***/ },
125967
+
125706
125968
  /***/ "./node_modules/@abaplint/transpiler/build/src/statements/_selection.js"
125707
125969
  /*!******************************************************************************!*\
125708
125970
  !*** ./node_modules/@abaplint/transpiler/build/src/statements/_selection.js ***!
@@ -127561,6 +127823,54 @@ exports.CommitTranspiler = CommitTranspiler;
127561
127823
 
127562
127824
  /***/ },
127563
127825
 
127826
+ /***/ "./node_modules/@abaplint/transpiler/build/src/statements/commit_entities.js"
127827
+ /*!***********************************************************************************!*\
127828
+ !*** ./node_modules/@abaplint/transpiler/build/src/statements/commit_entities.js ***!
127829
+ \***********************************************************************************/
127830
+ (__unused_webpack_module, exports, __webpack_require__) {
127831
+
127832
+ "use strict";
127833
+
127834
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
127835
+ exports.CommitEntitiesTranspiler = void 0;
127836
+ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
127837
+ const _eml_1 = __webpack_require__(/*! ./_eml */ "./node_modules/@abaplint/transpiler/build/src/statements/_eml.js");
127838
+ /** COMMIT ENTITIES [RESPONSE OF bdef FAILED f REPORTED r] [RESPONSES FAILED f REPORTED r]
127839
+ *
127840
+ * lowered to KERNEL_RAP_EML.commit with the behavior definition of
127841
+ * RESPONSE OF and the targets named; the kernel sets sy-subrc. Not
127842
+ * lowered: IN SIMULATION MODE. */
127843
+ class CommitEntitiesTranspiler {
127844
+ transpile(node, traversal) {
127845
+ const unsupported = (0, _eml_1.unsupportedAddition)(node, ["SIMULATION"]);
127846
+ if (unsupported !== undefined) {
127847
+ return new chunk_1.Chunk(`throw new Error("CommitEntities ${unsupported}, not supported, transpiler");`);
127848
+ }
127849
+ const lookup = traversal.lookupClassOrInterface(_eml_1.KERNEL_RAP_EML, node.getFirstToken());
127850
+ const walker = new _eml_1.EMLWalker(node);
127851
+ const options = [];
127852
+ while (!walker.done()) {
127853
+ const keyword = walker.takeKeyword();
127854
+ switch (keyword) {
127855
+ case "OF":
127856
+ options.push(`bdef: ${(0, _eml_1.abapString)(walker.takeName())}`);
127857
+ break;
127858
+ case "FAILED":
127859
+ case "REPORTED":
127860
+ options.push(`${keyword.toLowerCase()}: ${traversal.traverse(walker.takeExpression()).getCode()}`);
127861
+ break;
127862
+ default:
127863
+ break;
127864
+ }
127865
+ }
127866
+ return (0, _eml_1.emitCalls)("CommitEntities", lookup, [`await ${lookup}.commit({${options.join(", ")}});`], node, traversal);
127867
+ }
127868
+ }
127869
+ exports.CommitEntitiesTranspiler = CommitEntitiesTranspiler;
127870
+ //# sourceMappingURL=commit_entities.js.map
127871
+
127872
+ /***/ },
127873
+
127564
127874
  /***/ "./node_modules/@abaplint/transpiler/build/src/statements/compute.js"
127565
127875
  /*!***************************************************************************!*\
127566
127876
  !*** ./node_modules/@abaplint/transpiler/build/src/statements/compute.js ***!
@@ -130583,6 +130893,21 @@ class IncludeTranspiler {
130583
130893
  return chunk;
130584
130894
  }
130585
130895
  }
130896
+ if (obj instanceof abaplint.Objects.Program) {
130897
+ const prog = traversal.reg.getObject("PROG", includeName);
130898
+ const file = prog?.getMainABAPFile();
130899
+ if (file !== undefined) {
130900
+ // traversed with the spaghetti of the main program, the include can use its types and data
130901
+ const sub = new traversal_1.Traversal(traversal.getSpaghetti(), file, obj, traversal.reg, traversal.options, traversal.typeFactories);
130902
+ sub.programMain = traversal.programMain;
130903
+ const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
130904
+ const chunk = new chunk_1.Chunk();
130905
+ if (traversal.options?.addFilenames === true) {
130906
+ chunk.appendString("// " + file.getFilename() + "\n");
130907
+ }
130908
+ return chunk.appendChunk(sub.traverse(rearranged));
130909
+ }
130910
+ }
130586
130911
  // todo, this will not work
130587
130912
  return new chunk_1.Chunk("// transpiler TODO: INCLUDE " + includeName + "\n");
130588
130913
  }
@@ -130645,6 +130970,7 @@ __exportStar(__webpack_require__(/*! ./close_cursor */ "./node_modules/@abaplint
130645
130970
  __exportStar(__webpack_require__(/*! ./close_dataset */ "./node_modules/@abaplint/transpiler/build/src/statements/close_dataset.js"), exports);
130646
130971
  __exportStar(__webpack_require__(/*! ./collect */ "./node_modules/@abaplint/transpiler/build/src/statements/collect.js"), exports);
130647
130972
  __exportStar(__webpack_require__(/*! ./commit */ "./node_modules/@abaplint/transpiler/build/src/statements/commit.js"), exports);
130973
+ __exportStar(__webpack_require__(/*! ./commit_entities */ "./node_modules/@abaplint/transpiler/build/src/statements/commit_entities.js"), exports);
130648
130974
  __exportStar(__webpack_require__(/*! ./compute */ "./node_modules/@abaplint/transpiler/build/src/statements/compute.js"), exports);
130649
130975
  __exportStar(__webpack_require__(/*! ./concatenate */ "./node_modules/@abaplint/transpiler/build/src/statements/concatenate.js"), exports);
130650
130976
  __exportStar(__webpack_require__(/*! ./end_of_selection */ "./node_modules/@abaplint/transpiler/build/src/statements/end_of_selection.js"), exports);
@@ -130747,6 +131073,7 @@ __exportStar(__webpack_require__(/*! ./reserve */ "./node_modules/@abaplint/tran
130747
131073
  __exportStar(__webpack_require__(/*! ./retry */ "./node_modules/@abaplint/transpiler/build/src/statements/retry.js"), exports);
130748
131074
  __exportStar(__webpack_require__(/*! ./return */ "./node_modules/@abaplint/transpiler/build/src/statements/return.js"), exports);
130749
131075
  __exportStar(__webpack_require__(/*! ./rollback */ "./node_modules/@abaplint/transpiler/build/src/statements/rollback.js"), exports);
131076
+ __exportStar(__webpack_require__(/*! ./rollback_entities */ "./node_modules/@abaplint/transpiler/build/src/statements/rollback_entities.js"), exports);
130750
131077
  __exportStar(__webpack_require__(/*! ./scan */ "./node_modules/@abaplint/transpiler/build/src/statements/scan.js"), exports);
130751
131078
  __exportStar(__webpack_require__(/*! ./search */ "./node_modules/@abaplint/transpiler/build/src/statements/search.js"), exports);
130752
131079
  __exportStar(__webpack_require__(/*! ./select_option */ "./node_modules/@abaplint/transpiler/build/src/statements/select_option.js"), exports);
@@ -131878,9 +132205,125 @@ exports.ModifyDatabaseTranspiler = ModifyDatabaseTranspiler;
131878
132205
  Object.defineProperty(exports, "__esModule", ({ value: true }));
131879
132206
  exports.ModifyEntitiesTranspiler = void 0;
131880
132207
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
132208
+ const _eml_1 = __webpack_require__(/*! ./_eml */ "./node_modules/@abaplint/transpiler/build/src/statements/_eml.js");
132209
+ /** MODIFY ENTITIES OF bdef ENTITY e CREATE|UPDATE|DELETE|EXECUTE ... MAPPED m FAILED f REPORTED r
132210
+ *
132211
+ * lowered to KERNEL_RAP_EML.begin with the MAPPED / FAILED / REPORTED
132212
+ * targets the statement names (the statement boundary: the kernel clears
132213
+ * them and binds scratch for the rest), then one modify / execute call per
132214
+ * operation in the order of the statement. Not lowered: the dynamic form (OPERATIONS), create by association (BY),
132215
+ * RELATING TO, AUGMENTING, and the deep forms. */
131881
132216
  class ModifyEntitiesTranspiler {
131882
- transpile(_node, _traversal) {
131883
- return new chunk_1.Chunk(`throw new Error("ModifyEntities, not supported, transpiler");`);
132217
+ transpile(node, traversal) {
132218
+ const unsupported = (0, _eml_1.unsupportedAddition)(node, ["OPERATIONS", "RELATING", "AUGMENTING"]);
132219
+ if (unsupported !== undefined) {
132220
+ return new chunk_1.Chunk(`throw new Error("ModifyEntities ${unsupported}, not supported, transpiler");`);
132221
+ }
132222
+ const lookup = traversal.lookupClassOrInterface(_eml_1.KERNEL_RAP_EML, node.getFirstToken());
132223
+ const walker = new _eml_1.EMLWalker(node);
132224
+ const operations = [];
132225
+ const targets = {};
132226
+ let bdef = "";
132227
+ let entity = "";
132228
+ let current = undefined;
132229
+ walker.accept("MODIFY");
132230
+ if (walker.accept("ENTITIES", "OF")) {
132231
+ bdef = walker.takeName();
132232
+ }
132233
+ else if (walker.accept("ENTITY")) {
132234
+ // the short form names the root entity by its behavior definition
132235
+ walker.accept("IN", "LOCAL", "MODE");
132236
+ bdef = walker.takeName();
132237
+ entity = bdef;
132238
+ }
132239
+ while (!walker.done()) {
132240
+ const keyword = walker.takeKeyword();
132241
+ switch (keyword) {
132242
+ case "ENTITY":
132243
+ entity = walker.takeName();
132244
+ break;
132245
+ case "CREATE":
132246
+ case "UPDATE":
132247
+ case "DELETE":
132248
+ current = { kind: keyword, entity };
132249
+ operations.push(current);
132250
+ break;
132251
+ case "EXECUTE":
132252
+ current = { kind: "EXECUTE", entity, action: walker.takeName() };
132253
+ operations.push(current);
132254
+ break;
132255
+ case "FROM":
132256
+ if (current) {
132257
+ current.rows = traversal.traverse(walker.takeExpression()).getCode();
132258
+ }
132259
+ break;
132260
+ case "FIELDS":
132261
+ if (current) {
132262
+ current.fields = walker.takeFieldList();
132263
+ }
132264
+ break;
132265
+ case "SET":
132266
+ // SET FIELDS WITH
132267
+ walker.accept("FIELDS");
132268
+ if (current) {
132269
+ current.setFields = true;
132270
+ }
132271
+ break;
132272
+ case "WITH":
132273
+ if (current) {
132274
+ current.rows = traversal.traverse(walker.takeExpression()).getCode();
132275
+ }
132276
+ break;
132277
+ case "AUTO":
132278
+ walker.accept("FILL", "CID");
132279
+ if (current) {
132280
+ current.autoFillCid = true;
132281
+ }
132282
+ break;
132283
+ case "MAPPED":
132284
+ case "FAILED":
132285
+ case "REPORTED":
132286
+ case "RESULT":
132287
+ targets[keyword.toLowerCase()] = traversal.traverse(walker.takeExpression()).getCode();
132288
+ break;
132289
+ default:
132290
+ // IN LOCAL MODE, PRIVILEGED, FORWARDING, the final period
132291
+ break;
132292
+ }
132293
+ }
132294
+ const calls = [];
132295
+ const statement = [`bdef: ${(0, _eml_1.abapString)(bdef)}`];
132296
+ for (const name of ["mapped", "failed", "reported"]) {
132297
+ if (targets[name] !== undefined) {
132298
+ statement.push(`${name}: ${targets[name]}`);
132299
+ }
132300
+ }
132301
+ calls.push(`await ${lookup}.begin({${statement.join(", ")}});`);
132302
+ for (const op of operations) {
132303
+ const options = [`bdef: ${(0, _eml_1.abapString)(bdef)}`, `entity: ${(0, _eml_1.abapString)(op.entity)}`];
132304
+ if (op.kind === "EXECUTE") {
132305
+ options.push(`action: ${(0, _eml_1.abapString)(op.action ?? "")}`);
132306
+ }
132307
+ else {
132308
+ options.push(`operation: ${(0, _eml_1.abapString)(op.kind)}`);
132309
+ }
132310
+ options.push(`rows: ${op.rows ?? "undefined"}`);
132311
+ if (op.fields !== undefined) {
132312
+ options.push(`fields: ${(0, _eml_1.abapString)(op.fields.join(","))}`);
132313
+ }
132314
+ if (op.setFields === true) {
132315
+ options.push(`set_fields: ${(0, _eml_1.abapFlag)()}`);
132316
+ }
132317
+ if (op.autoFillCid === true) {
132318
+ options.push(`auto_fill_cid: ${(0, _eml_1.abapFlag)()}`);
132319
+ }
132320
+ if (op.kind === "EXECUTE" && targets["result"] !== undefined) {
132321
+ options.push(`result: ${targets["result"]}`);
132322
+ }
132323
+ const method = op.kind === "EXECUTE" ? "execute" : "modify";
132324
+ calls.push(`await ${lookup}.${method}({${options.join(", ")}});`);
132325
+ }
132326
+ return (0, _eml_1.emitCalls)("ModifyEntities", lookup, calls, node, traversal);
131884
132327
  }
131885
132328
  }
131886
132329
  exports.ModifyEntitiesTranspiler = ModifyEntitiesTranspiler;
@@ -133111,9 +133554,89 @@ exports.ReadDatasetTranspiler = ReadDatasetTranspiler;
133111
133554
  Object.defineProperty(exports, "__esModule", ({ value: true }));
133112
133555
  exports.ReadEntitiesTranspiler = void 0;
133113
133556
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
133557
+ const _eml_1 = __webpack_require__(/*! ./_eml */ "./node_modules/@abaplint/transpiler/build/src/statements/_eml.js");
133558
+ /** READ ENTITIES OF bdef ENTITY e FROM|ALL FIELDS WITH|FIELDS ( ) WITH keys RESULT r FAILED f REPORTED r
133559
+ *
133560
+ * lowered to KERNEL_RAP_EML.begin with the FAILED / REPORTED targets the
133561
+ * statement names (the statement boundary), then one read call per read in
133562
+ * the order of the statement. Not lowered: read by association (BY), LINK, and EXECUTE
133563
+ * (functions). */
133114
133564
  class ReadEntitiesTranspiler {
133115
- transpile(_node, _traversal) {
133116
- return new chunk_1.Chunk(`throw new Error("ReadEntities, not supported, transpiler");`);
133565
+ transpile(node, traversal) {
133566
+ const unsupported = (0, _eml_1.unsupportedAddition)(node, ["LINK", "EXECUTE"]);
133567
+ if (unsupported !== undefined) {
133568
+ return new chunk_1.Chunk(`throw new Error("ReadEntities ${unsupported}, not supported, transpiler");`);
133569
+ }
133570
+ const lookup = traversal.lookupClassOrInterface(_eml_1.KERNEL_RAP_EML, node.getFirstToken());
133571
+ const walker = new _eml_1.EMLWalker(node);
133572
+ const reads = [];
133573
+ const targets = {};
133574
+ let bdef = "";
133575
+ let entity = "";
133576
+ let current = undefined;
133577
+ walker.accept("READ");
133578
+ if (walker.accept("ENTITIES", "OF")) {
133579
+ bdef = walker.takeName();
133580
+ }
133581
+ else if (walker.accept("ENTITY")) {
133582
+ walker.accept("IN", "LOCAL", "MODE");
133583
+ bdef = walker.takeName();
133584
+ entity = bdef;
133585
+ }
133586
+ while (!walker.done()) {
133587
+ const keyword = walker.takeKeyword();
133588
+ switch (keyword) {
133589
+ case "ENTITY":
133590
+ entity = walker.takeName();
133591
+ break;
133592
+ case "FROM":
133593
+ current = { entity, keys: traversal.traverse(walker.takeExpression()).getCode() };
133594
+ reads.push(current);
133595
+ break;
133596
+ case "ALL":
133597
+ walker.accept("FIELDS", "WITH");
133598
+ current = { entity, fields: "*", keys: traversal.traverse(walker.takeExpression()).getCode() };
133599
+ reads.push(current);
133600
+ break;
133601
+ case "FIELDS":
133602
+ current = { entity, fields: walker.takeFieldList().join(",") };
133603
+ walker.accept("WITH");
133604
+ current.keys = traversal.traverse(walker.takeExpression()).getCode();
133605
+ reads.push(current);
133606
+ break;
133607
+ case "RESULT":
133608
+ if (current) {
133609
+ current.result = traversal.traverse(walker.takeExpression()).getCode();
133610
+ }
133611
+ break;
133612
+ case "FAILED":
133613
+ case "REPORTED":
133614
+ targets[keyword.toLowerCase()] = traversal.traverse(walker.takeExpression()).getCode();
133615
+ break;
133616
+ default:
133617
+ // IN LOCAL MODE, the final period
133618
+ break;
133619
+ }
133620
+ }
133621
+ const calls = [];
133622
+ const statement = [`bdef: ${(0, _eml_1.abapString)(bdef)}`];
133623
+ for (const name of ["failed", "reported"]) {
133624
+ if (targets[name] !== undefined) {
133625
+ statement.push(`${name}: ${targets[name]}`);
133626
+ }
133627
+ }
133628
+ calls.push(`await ${lookup}.begin({${statement.join(", ")}});`);
133629
+ for (const read of reads) {
133630
+ const options = [`bdef: ${(0, _eml_1.abapString)(bdef)}`, `entity: ${(0, _eml_1.abapString)(read.entity)}`, `keys: ${read.keys ?? "undefined"}`];
133631
+ if (read.fields !== undefined) {
133632
+ options.push(`fields: ${(0, _eml_1.abapString)(read.fields)}`);
133633
+ }
133634
+ if (read.result !== undefined) {
133635
+ options.push(`result: ${read.result}`);
133636
+ }
133637
+ calls.push(`await ${lookup}.read({${options.join(", ")}});`);
133638
+ }
133639
+ return (0, _eml_1.emitCalls)("ReadEntities", lookup, calls, node, traversal);
133117
133640
  }
133118
133641
  }
133119
133642
  exports.ReadEntitiesTranspiler = ReadEntitiesTranspiler;
@@ -133767,6 +134290,29 @@ exports.RollbackTranspiler = RollbackTranspiler;
133767
134290
 
133768
134291
  /***/ },
133769
134292
 
134293
+ /***/ "./node_modules/@abaplint/transpiler/build/src/statements/rollback_entities.js"
134294
+ /*!*************************************************************************************!*\
134295
+ !*** ./node_modules/@abaplint/transpiler/build/src/statements/rollback_entities.js ***!
134296
+ \*************************************************************************************/
134297
+ (__unused_webpack_module, exports, __webpack_require__) {
134298
+
134299
+ "use strict";
134300
+
134301
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
134302
+ exports.RollbackEntitiesTranspiler = void 0;
134303
+ const _eml_1 = __webpack_require__(/*! ./_eml */ "./node_modules/@abaplint/transpiler/build/src/statements/_eml.js");
134304
+ /** ROLLBACK ENTITIES, lowered to KERNEL_RAP_EML.rollback */
134305
+ class RollbackEntitiesTranspiler {
134306
+ transpile(node, traversal) {
134307
+ const lookup = traversal.lookupClassOrInterface(_eml_1.KERNEL_RAP_EML, node.getFirstToken());
134308
+ return (0, _eml_1.emitCalls)("RollbackEntities", lookup, [`await ${lookup}.rollback();`], node, traversal);
134309
+ }
134310
+ }
134311
+ exports.RollbackEntitiesTranspiler = RollbackEntitiesTranspiler;
134312
+ //# sourceMappingURL=rollback_entities.js.map
134313
+
134314
+ /***/ },
134315
+
133770
134316
  /***/ "./node_modules/@abaplint/transpiler/build/src/statements/scan.js"
133771
134317
  /*!************************************************************************!*\
133772
134318
  !*** ./node_modules/@abaplint/transpiler/build/src/statements/scan.js ***!
@@ -134063,7 +134609,8 @@ class SelectTranspiler {
134063
134609
  // ABAP semantics: with an empty driving table the whole WHERE condition is ignored
134064
134610
  const selectEmpty = select.replace(whereClause, "");
134065
134611
  const bindRow = (text) => text
134066
- .replace(new RegExp(" " + escapeRegExp(faeTranspiled), "g"), " " + unique)
134612
+ // the row reference follows a blank, or the parenthesis of abap.sqlEscape(
134613
+ .replace(new RegExp("([ (])" + escapeRegExp(faeTranspiled), "g"), "$1" + unique)
134067
134614
  .replace(unique + ".get().table_line.get()", unique + ".get()"); // there can be only one?
134068
134615
  select = bindRow(select);
134069
134616
  const where = bindRow(whereClause);
@@ -135804,7 +136351,7 @@ class UpdateDatabaseTranspiler {
135804
136351
  const where = [];
135805
136352
  const set = [];
135806
136353
  for (const fieldName of allFields) {
135807
- const cond = `\\"${fieldName}\\" = '\" + ${sqlSource}.${fieldName}.get() + \"'`;
136354
+ const cond = `\\"${fieldName}\\" = '\" + abap.sqlEscape(${sqlSource}.${fieldName}.get()) + \"'`;
135808
136355
  if (keys.includes(fieldName) === true) {
135809
136356
  where.push(cond);
135810
136357
  }
@@ -136606,12 +137153,13 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
136606
137153
  exports.ClassDefinitionTranspiler = void 0;
136607
137154
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
136608
137155
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
137156
+ const program_includes_1 = __webpack_require__(/*! ../program_includes */ "./node_modules/@abaplint/transpiler/build/src/program_includes.js");
136609
137157
  class ClassDefinitionTranspiler {
136610
137158
  transpile(node, traversal) {
136611
137159
  const className = node.findFirstExpression(abaplint.Expressions.ClassName)?.concatTokens().toUpperCase();
136612
137160
  let found = false;
136613
137161
  if (className !== undefined) {
136614
- for (const a of traversal.getCurrentObject().getABAPFiles()) {
137162
+ for (const a of (0, program_includes_1.filesWithProgramIncludes)(traversal.getCurrentObject(), traversal.reg)) {
136615
137163
  if (a.getInfo().getClassImplementationByName(className) !== undefined) {
136616
137164
  found = true;
136617
137165
  }
@@ -138744,6 +139292,9 @@ class Traversal {
138744
139292
  reg;
138745
139293
  options;
138746
139294
  typeFactories;
139295
+ /** set when the executable program level code is collected into the program's main function,
139296
+ * shared with the traversals of its INCLUDEs, see traverseProgramLevel */
139297
+ programMain = undefined;
138747
139298
  constructor(spaghetti, file, obj, reg, options, typeFactories) {
138748
139299
  this.spaghetti = spaghetti;
138749
139300
  this.file = file;
@@ -138819,6 +139370,15 @@ class Traversal {
138819
139370
  getCurrentObject() {
138820
139371
  return this.obj;
138821
139372
  }
139373
+ /** true if the file is part of the current object, include programs are inlined into the object using them */
139374
+ isCurrentObjectFile(filename) {
139375
+ if (this.getCurrentObject().getABAPFileByName(filename) !== undefined) {
139376
+ return true;
139377
+ }
139378
+ const file = this.reg.getFileByName(filename);
139379
+ const found = file ? this.reg.findObjectForFile(file) : undefined;
139380
+ return found instanceof abaplint.Objects.Program && found.isInclude();
139381
+ }
138822
139382
  traverse(node) {
138823
139383
  if (node instanceof abaplint.Nodes.StructureNode) {
138824
139384
  return this.traverseStructure(node);
@@ -138888,6 +139448,13 @@ class Traversal {
138888
139448
  // workaround for INCLUDEs in function groups
138889
139449
  return this.fuctionGroupWorkaround(token);
138890
139450
  }
139451
+ if (node === undefined
139452
+ && this.obj instanceof abaplint.Objects.Program
139453
+ && this.obj.getABAPFileByName(filename) === undefined
139454
+ && this.isCurrentObjectFile(filename)) {
139455
+ // INCLUDE in program, the program level scope only covers the main file
139456
+ return this.spaghetti.getFirstChild()?.getFirstChild();
139457
+ }
138891
139458
  return node;
138892
139459
  }
138893
139460
  fuctionGroupWorkaround(token) {
@@ -138964,7 +139531,7 @@ class Traversal {
138964
139531
  }
138965
139532
  prefixAndName(t, filename) {
138966
139533
  let name = t.getStr().toLowerCase().replace(/^!/, "");
138967
- if (filename && this.getCurrentObject().getABAPFileByName(filename) === undefined) {
139534
+ if (filename && this.isCurrentObjectFile(filename) === false) {
138968
139535
  // the prefix is from a different object
138969
139536
  const file = this.reg.getFileByName(filename);
138970
139537
  if (file) {
@@ -139301,7 +139868,7 @@ class Traversal {
139301
139868
  return scope?.getIdentifier().sname;
139302
139869
  }
139303
139870
  }
139304
- else if (this.getCurrentObject().getABAPFileByName(ref.getFilename()) !== undefined) {
139871
+ else if (this.isCurrentObjectFile(ref.getFilename())) {
139305
139872
  const scope = this.spaghetti.lookupPosition(ref.getStart(), ref.getFilename());
139306
139873
  if (scope?.getIdentifier().stype === abaplint.ScopeType.Interface) {
139307
139874
  return scope?.getIdentifier().sname;
@@ -139845,10 +140412,76 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
139845
140412
  }
139846
140413
  }
139847
140414
  }
140415
+ static PROGRAM_LEVEL_DECLARATIONS = [
140416
+ abaplint.Statements.Data, abaplint.Statements.DataBegin, abaplint.Statements.DataEnd,
140417
+ abaplint.Statements.Constant, abaplint.Statements.ConstantBegin,
140418
+ abaplint.Statements.Type, abaplint.Statements.TypeBegin, abaplint.Statements.TypeEnum,
140419
+ abaplint.Statements.FieldSymbol, abaplint.Statements.Static, abaplint.Statements.StaticBegin,
140420
+ abaplint.Statements.Tables, abaplint.Statements.TypePools, abaplint.Statements.Ranges, abaplint.Statements.Nodes,
140421
+ abaplint.Statements.Parameter, abaplint.Statements.SelectOption, abaplint.Statements.SelectionScreen,
140422
+ abaplint.Statements.ClassDeferred, abaplint.Statements.InterfaceDeferred,
140423
+ abaplint.Statements.ClassDefinitionLoad, abaplint.Statements.InterfaceLoad,
140424
+ abaplint.Statements.Define, abaplint.Statements.Include, abaplint.Statements.Report, abaplint.Statements.Program,
140425
+ ];
140426
+ static isProgramLevelDeclaration(node) {
140427
+ const get = node.get();
140428
+ if (node instanceof abaplint.Nodes.StatementNode) {
140429
+ return Traversal.PROGRAM_LEVEL_DECLARATIONS.some(d => get instanceof d);
140430
+ }
140431
+ else if (node instanceof abaplint.Nodes.StructureNode) {
140432
+ return get instanceof abaplint.Structures.Data
140433
+ || get instanceof abaplint.Structures.Constants
140434
+ || get instanceof abaplint.Structures.Types
140435
+ || get instanceof abaplint.Structures.TypeEnum
140436
+ || get instanceof abaplint.Structures.Statics
140437
+ || get instanceof abaplint.Structures.Define;
140438
+ }
140439
+ return false;
140440
+ }
140441
+ /** Splits the top level of a program, or of an INCLUDE expanded into it: declarations, classes and FORMs
140442
+ * stay on module level and are returned, the executable statements and event blocks are appended to
140443
+ * programMain. Declarations nested in executable blocks are global in ABAP, they stay on module level */
140444
+ traverseProgramLevel(node, main) {
140445
+ const ret = new chunk_1.Chunk();
140446
+ for (const c of node.getChildren()) {
140447
+ if (c instanceof abaplint.Nodes.StatementNode) {
140448
+ // event statements like INITIALIZATION are executable, REPORT, PARAMETERS etc. are declarations
140449
+ (Traversal.isProgramLevelDeclaration(c) ? ret : main).appendChunk(this.traverse(c));
140450
+ continue;
140451
+ }
140452
+ else if (!(c.get() instanceof abaplint.Structures.Normal)) {
140453
+ // classes, interfaces, FORMs
140454
+ ret.appendChunk(this.traverse(c));
140455
+ continue;
140456
+ }
140457
+ for (const n of c.getChildren()) {
140458
+ if (Traversal.isProgramLevelDeclaration(n)) {
140459
+ ret.appendChunk(this.traverse(n));
140460
+ }
140461
+ else if (n instanceof abaplint.Nodes.StructureNode) {
140462
+ ret.appendChunk(this.declareNestedEarly(n));
140463
+ this.blockDepth++;
140464
+ try {
140465
+ main.appendChunk(this.traverseStructure(n));
140466
+ }
140467
+ finally {
140468
+ this.blockDepth--;
140469
+ }
140470
+ }
140471
+ else {
140472
+ main.appendChunk(this.traverse(n));
140473
+ }
140474
+ }
140475
+ }
140476
+ return ret;
140477
+ }
139848
140478
  traverseStructure(node) {
139849
140479
  if (this.declaredEarly.has(node) && this.emittingEarly === false) {
139850
140480
  return new chunk_1.Chunk();
139851
140481
  }
140482
+ else if (this.programMain !== undefined && node.get() instanceof abaplint.Structures.Any) {
140483
+ return this.traverseProgramLevel(node, this.programMain);
140484
+ }
139852
140485
  else if (this.blockDepth === 0 && node.get() instanceof abaplint.Structures.Normal) {
139853
140486
  return this.traverseProcedureLevel(node);
139854
140487
  }
@@ -140169,6 +140802,7 @@ exports.UnitTest = void 0;
140169
140802
  /* eslint-disable max-len */
140170
140803
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
140171
140804
  const output_layout_1 = __webpack_require__(/*! ./output_layout */ "./node_modules/@abaplint/transpiler/build/src/output_layout.js");
140805
+ const program_includes_1 = __webpack_require__(/*! ./program_includes */ "./node_modules/@abaplint/transpiler/build/src/program_includes.js");
140172
140806
  class UnitTest {
140173
140807
  layout;
140174
140808
  constructor(layout = new output_layout_1.OutputLayout()) {
@@ -140190,14 +140824,29 @@ async function run() {
140190
140824
  let ls_result = new abap.types.Structure({list: new abap.types.Table(new abap.types.Structure({class_name: new abap.types.Character(30), testclass_name: new abap.types.Character(30), method_name: new abap.types.Character(30), expected: new abap.types.String(), actual: new abap.types.String(), status: new abap.types.String(), runtime: new abap.types.Integer(), message: new abap.types.String(), js_location: new abap.types.String(), console: new abap.types.String()}), {"withHeader":false,"type":"STANDARD","isUnique":false,"keyFields":[]}), json: new abap.types.String()});
140191
140825
  `;
140192
140826
  for (const obj of reg.getObjects()) {
140193
- if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
140827
+ if (reg.isDependency(obj)) {
140194
140828
  continue;
140195
140829
  }
140196
- const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
140197
- if (hasTestFile === true) {
140198
- ret += ` await import("${(0, output_layout_1.importPath)("index.mjs", this.layout.objectModule(obj, ".testclasses"))}");\n`;
140830
+ let files = [];
140831
+ if (obj instanceof abaplint.Objects.Class) {
140832
+ const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
140833
+ if (hasTestFile === true) {
140834
+ ret += ` await import("${(0, output_layout_1.importPath)("index.mjs", this.layout.objectModule(obj, ".testclasses"))}");\n`;
140835
+ }
140836
+ files = obj.getABAPFiles();
140199
140837
  }
140200
- for (const file of obj.getABAPFiles()) {
140838
+ else if (obj instanceof abaplint.Objects.Program && obj.isInclude() === false) {
140839
+ // KERNEL_UNIT_RUNNER finds local classes of programs as "PROG-<program>-<class>",
140840
+ // importing the program module registers them, its main function is not run
140841
+ files = (0, program_includes_1.filesWithProgramIncludes)(obj, reg);
140842
+ if (files.some(f => f.getInfo().listClassDefinitions().some(d => d.isForTesting === true && d.isGlobal === false))) {
140843
+ ret += ` await import("${(0, output_layout_1.importPath)("index.mjs", this.layout.objectModule(obj))}");\n`;
140844
+ }
140845
+ }
140846
+ else {
140847
+ continue;
140848
+ }
140849
+ for (const file of files) {
140201
140850
  for (const def of file.getInfo().listClassDefinitions()) {
140202
140851
  if (def.isForTesting === false || def.isGlobal === true || def.methods.length === 0) {
140203
140852
  // todo, fix, there might be global test methods
@@ -140232,14 +140881,28 @@ run().then(() => {
140232
140881
  getSortedTests(reg) {
140233
140882
  const tests = [];
140234
140883
  for (const obj of reg.getObjects()) {
140235
- if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
140884
+ if (reg.isDependency(obj)) {
140236
140885
  continue;
140237
140886
  }
140238
- const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
140239
- if (hasTestFile === false) {
140887
+ let files = [];
140888
+ let filename = "";
140889
+ if (obj instanceof abaplint.Objects.Class) {
140890
+ const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
140891
+ if (hasTestFile === false) {
140892
+ continue;
140893
+ }
140894
+ files = obj.getABAPFiles();
140895
+ filename = (0, output_layout_1.importPath)("index.mjs", this.layout.objectModule(obj, ".testclasses"));
140896
+ }
140897
+ else if (obj instanceof abaplint.Objects.Program && obj.isInclude() === false) {
140898
+ // local test classes are in the program or its includes, the includes are expanded into the program module
140899
+ files = (0, program_includes_1.filesWithProgramIncludes)(obj, reg);
140900
+ filename = (0, output_layout_1.importPath)("index.mjs", this.layout.objectModule(obj));
140901
+ }
140902
+ else {
140240
140903
  continue;
140241
140904
  }
140242
- for (const file of obj.getABAPFiles()) {
140905
+ for (const file of files) {
140243
140906
  for (const def of file.getInfo().listClassDefinitions()) {
140244
140907
  if (def.isForTesting === false
140245
140908
  || def.isGlobal === true
@@ -140262,7 +140925,7 @@ run().then(() => {
140262
140925
  }
140263
140926
  tests.push({
140264
140927
  obj,
140265
- filename: `${(0, output_layout_1.importPath)("index.mjs", this.layout.objectModule(obj, ".testclasses"))}`,
140928
+ filename: filename,
140266
140929
  localClass: def.name.toLowerCase(),
140267
140930
  riskLevel: def.riskLevel,
140268
140931
  duration: def.duration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.14.19",
3
+ "version": "2.14.20",
4
4
  "description": "Transpiler - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -27,8 +27,8 @@
27
27
  "author": "abaplint",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@abaplint/core": "^2.120.94",
31
- "@abaplint/transpiler": "^2.14.19",
30
+ "@abaplint/core": "^2.120.95",
31
+ "@abaplint/transpiler": "^2.14.20",
32
32
  "@types/glob": "^9.0.0",
33
33
  "@types/node": "^26.6.6",
34
34
  "@types/progress": "^2.0.7",