@abaplint/transpiler-cli 2.14.27 → 2.14.29

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 (3) hide show
  1. package/build/bundle.js +701 -108
  2. package/package.json +3 -3
  3. package/schema.json +104 -97
package/build/bundle.js CHANGED
@@ -28985,6 +28985,167 @@ exports.Procedural = Procedural;
28985
28985
 
28986
28986
  /***/ },
28987
28987
 
28988
+ /***/ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_raise_message.js"
28989
+ /*!*******************************************************************************!*\
28990
+ !*** ./node_modules/@abaplint/core/build/src/abap/5_syntax/_raise_message.js ***!
28991
+ \*******************************************************************************/
28992
+ (__unused_webpack_module, exports, __webpack_require__) {
28993
+
28994
+ "use strict";
28995
+
28996
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
28997
+ if (k2 === undefined) k2 = k;
28998
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28999
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29000
+ desc = { enumerable: true, get: function() { return m[k]; } };
29001
+ }
29002
+ Object.defineProperty(o, k2, desc);
29003
+ }) : (function(o, m, k, k2) {
29004
+ if (k2 === undefined) k2 = k;
29005
+ o[k2] = m[k];
29006
+ }));
29007
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29008
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29009
+ }) : function(o, v) {
29010
+ o["default"] = v;
29011
+ });
29012
+ var __importStar = (this && this.__importStar) || (function () {
29013
+ var ownKeys = function(o) {
29014
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29015
+ var ar = [];
29016
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29017
+ return ar;
29018
+ };
29019
+ return ownKeys(o);
29020
+ };
29021
+ return function (mod) {
29022
+ if (mod && mod.__esModule) return mod;
29023
+ var result = {};
29024
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
29025
+ __setModuleDefault(result, mod);
29026
+ return result;
29027
+ };
29028
+ })();
29029
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
29030
+ exports.RaiseMessage = void 0;
29031
+ const Expressions = __importStar(__webpack_require__(/*! ../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
29032
+ const nodes_1 = __webpack_require__(/*! ../nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
29033
+ const _syntax_input_1 = __webpack_require__(/*! ./_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
29034
+ const T100_INTERFACES = new Set(["IF_T100_MESSAGE", "IF_T100_DYN_MSG"]);
29035
+ // the root exception classes, they implement IF_MESSAGE and IF_SERIALIZABLE_OBJECT, but not the T100 interfaces
29036
+ const ROOT_EXCEPTIONS = new Set(["CX_ROOT", "CX_STATIC_CHECK", "CX_DYNAMIC_CHECK", "CX_NO_CHECK"]);
29037
+ /** RAISE EXCEPTION TYPE cx MESSAGE ... and THROW cx( MESSAGE ... ) require the exception class to implement
29038
+ * IF_T100_MESSAGE or IF_T100_DYN_MSG, and with RAISE EXCEPTION the constructor parameter TEXTID cannot be
29039
+ * passed in addition to MESSAGE, see the ABAP keyword documentation for RAISE EXCEPTION, MESSAGE.
29040
+ * The interface check only reports when the full class hierarchy is known, void classes and void interfaces
29041
+ * in the hierarchy are skipped, except for the root exception classes. */
29042
+ class RaiseMessage {
29043
+ static checkRaise(node, input) {
29044
+ var _a, _b, _c;
29045
+ var _d;
29046
+ const classTok = (_a = node.findDirectExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
29047
+ if (classTok === undefined || RaiseMessage.hasMessage(node) === false) {
29048
+ return;
29049
+ }
29050
+ for (const p of (_d = (_b = node.findDirectExpression(Expressions.ParameterListS)) === null || _b === void 0 ? void 0 : _b.findDirectExpressions(Expressions.ParameterS)) !== null && _d !== void 0 ? _d : []) {
29051
+ const name = (_c = p.findDirectExpression(Expressions.ParameterName)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
29052
+ if ((name === null || name === void 0 ? void 0 : name.getStr().toUpperCase()) === "TEXTID") {
29053
+ const message = "RAISE EXCEPTION with MESSAGE, TEXTID cannot be passed";
29054
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, name, message));
29055
+ return;
29056
+ }
29057
+ }
29058
+ RaiseMessage.checkClass(classTok.getStr(), input, classTok);
29059
+ }
29060
+ static checkThrow(node, input) {
29061
+ var _a;
29062
+ const classTok = (_a = node.findDirectExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
29063
+ if (classTok === undefined || node.findDirectExpression(Expressions.MessageSource) === undefined) {
29064
+ return;
29065
+ }
29066
+ RaiseMessage.checkClass(classTok.getStr(), input, classTok);
29067
+ }
29068
+ /** MESSAGE msg or MESSAGE ID, but not USING MESSAGE */
29069
+ static hasMessage(node) {
29070
+ const children = node.getChildren();
29071
+ for (let i = 0; i < children.length; i++) {
29072
+ const c = children[i];
29073
+ if (c instanceof nodes_1.TokenNode && c.getFirstToken().getStr().toUpperCase() === "MESSAGE") {
29074
+ const previous = children[i - 1];
29075
+ if (previous === undefined || previous.getFirstToken().getStr().toUpperCase() !== "USING") {
29076
+ return true;
29077
+ }
29078
+ }
29079
+ }
29080
+ return false;
29081
+ }
29082
+ static checkClass(className, input, classTok) {
29083
+ const def = input.scope.findClassDefinition(className);
29084
+ if (def === undefined) {
29085
+ return;
29086
+ }
29087
+ if (RaiseMessage.isT100(def, input.scope, new Set()) === false) {
29088
+ const message = "Exception class " + def.getName().toUpperCase() +
29089
+ " must implement IF_T100_MESSAGE or IF_T100_DYN_MSG to be raised with MESSAGE";
29090
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, classTok, message));
29091
+ }
29092
+ }
29093
+ /** true or false when known, undefined when the hierarchy contains void parts */
29094
+ static isT100(def, scope, visited) {
29095
+ var _a;
29096
+ const upper = def.getName().toUpperCase();
29097
+ if (visited.has(upper)) {
29098
+ return undefined;
29099
+ }
29100
+ visited.add(upper);
29101
+ let unknown = false;
29102
+ const interfaces = def.getImplementing().map(i => i.name.toUpperCase());
29103
+ const seen = new Set();
29104
+ while (interfaces.length > 0) {
29105
+ const name = interfaces.pop();
29106
+ if (seen.has(name)) {
29107
+ continue;
29108
+ }
29109
+ seen.add(name);
29110
+ if (T100_INTERFACES.has(name)) {
29111
+ return true;
29112
+ }
29113
+ const idef = scope.findInterfaceDefinition(name);
29114
+ if (idef === undefined) {
29115
+ unknown = true;
29116
+ }
29117
+ else {
29118
+ interfaces.push(...idef.getImplementing().map(i => i.name.toUpperCase()));
29119
+ }
29120
+ }
29121
+ const superName = (_a = def.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
29122
+ if (superName !== undefined) {
29123
+ const superDef = scope.findClassDefinition(superName);
29124
+ if (superDef !== undefined) {
29125
+ const res = RaiseMessage.isT100(superDef, scope, visited);
29126
+ if (res === true) {
29127
+ return true;
29128
+ }
29129
+ else if (res === undefined) {
29130
+ unknown = true;
29131
+ }
29132
+ }
29133
+ else if (ROOT_EXCEPTIONS.has(superName) === false) {
29134
+ unknown = true;
29135
+ }
29136
+ }
29137
+ else if (ROOT_EXCEPTIONS.has(upper) === false) {
29138
+ // not an exception class, reported elsewhere or not at all
29139
+ unknown = true;
29140
+ }
29141
+ return unknown ? undefined : false;
29142
+ }
29143
+ }
29144
+ exports.RaiseMessage = RaiseMessage;
29145
+ //# sourceMappingURL=_raise_message.js.map
29146
+
29147
+ /***/ },
29148
+
28988
29149
  /***/ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js"
28989
29150
  /*!***************************************************************************!*\
28990
29151
  !*** ./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js ***!
@@ -29163,16 +29324,19 @@ class SortedKeyWrite {
29163
29324
  if (this.procedure === undefined) {
29164
29325
  return;
29165
29326
  }
29166
- // any assignment of a field symbol or reference ends its binding
29167
- for (const fs of node.findAllExpressions(Expressions.FSTarget)) {
29168
- this.unbind(fs.findFirstExpression(Expressions.TargetFieldSymbol), input.scope);
29169
- }
29170
- if (node.get() instanceof Statements.Unassign) {
29171
- this.unbind(node.findDirectExpression(Expressions.TargetFieldSymbol), input.scope);
29172
- }
29173
- for (const target of node.findAllExpressions(Expressions.Target)) {
29174
- if (target.getChildren().length === 1) {
29175
- this.unbind(target.findDirectExpression(Expressions.TargetField), input.scope);
29327
+ // any assignment of a field symbol or reference ends its binding,
29328
+ // skipped when nothing is bound, this runs for every statement
29329
+ if (this.bindings.size > 0) {
29330
+ for (const fs of node.findAllExpressions(Expressions.FSTarget)) {
29331
+ this.unbind(fs.findFirstExpression(Expressions.TargetFieldSymbol), input.scope);
29332
+ }
29333
+ if (node.get() instanceof Statements.Unassign) {
29334
+ this.unbind(node.findDirectExpression(Expressions.TargetFieldSymbol), input.scope);
29335
+ }
29336
+ for (const target of node.findAllExpressions(Expressions.Target)) {
29337
+ if (target.getChildren().length === 1) {
29338
+ this.unbind(target.findDirectExpression(Expressions.TargetField), input.scope);
29339
+ }
29176
29340
  }
29177
29341
  }
29178
29342
  const s = node.get();
@@ -31764,7 +31928,19 @@ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modu
31764
31928
  // a syntax error. Other types, a dynamic offset or length and "*" (undefined) are left alone, as is
31765
31929
  // length 0. The offset is applied first, so the length is compared to what remains after the offset.
31766
31930
  // A substring of a date, time or numeric text field has type n; its bounds are not checked.
31931
+ // An offset or length on a numeric field (i, int8, p, f, decfloat) is a syntax error, whatever its value,
31932
+ // except a length without offset covering the full packed field, eg. "lv_p(5)" for "lv_p(5) TYPE p".
31767
31933
  function substringType(context, offset, length, node, input) {
31934
+ const numericName = numericTypeName(context);
31935
+ if (context instanceof basic_1.PackedType && offset === undefined && length === context.getLength()) {
31936
+ // the offset is checked in a separate call before the length, so this is a length without offset
31937
+ return context;
31938
+ }
31939
+ else if (numericName !== undefined) {
31940
+ const message = `Offset or length specification not possible on a field of numeric type "${numericName}"`;
31941
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
31942
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
31943
+ }
31768
31944
  if (context instanceof basic_1.DateType || context instanceof basic_1.TimeType || context instanceof basic_1.NumericType) {
31769
31945
  return numericSubstringType(context, offset, length);
31770
31946
  }
@@ -31790,6 +31966,30 @@ function substringType(context, offset, length, node, input) {
31790
31966
  }
31791
31967
  return context;
31792
31968
  }
31969
+ function numericTypeName(context) {
31970
+ if (context instanceof basic_1.IntegerType) {
31971
+ return "I";
31972
+ }
31973
+ else if (context instanceof basic_1.Integer8Type) {
31974
+ return "INT8";
31975
+ }
31976
+ else if (context instanceof basic_1.PackedType) {
31977
+ return "P";
31978
+ }
31979
+ else if (context instanceof basic_1.FloatType || context instanceof basic_1.FloatingPointType) {
31980
+ return "F";
31981
+ }
31982
+ else if (context instanceof basic_1.DecFloat16Type) {
31983
+ return "DECFLOAT16";
31984
+ }
31985
+ else if (context instanceof basic_1.DecFloat34Type) {
31986
+ return "DECFLOAT34";
31987
+ }
31988
+ else if (context instanceof basic_1.DecFloatType) {
31989
+ return "DECFLOAT";
31990
+ }
31991
+ return undefined;
31992
+ }
31793
31993
  function numericSubstringType(context, offset, length) {
31794
31994
  const hasOffset = offset !== undefined && offset > 0;
31795
31995
  const hasLength = length !== undefined && length > 0;
@@ -32929,6 +33129,7 @@ const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expr
32929
33129
  const source_1 = __webpack_require__(/*! ./source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
32930
33130
  const let_1 = __webpack_require__(/*! ./let */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/let.js");
32931
33131
  const cond_1 = __webpack_require__(/*! ./cond */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/cond.js");
33132
+ const _raise_message_1 = __webpack_require__(/*! ../_raise_message */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_raise_message.js");
32932
33133
  class CondBody {
32933
33134
  static runSyntax(node, input, targetType) {
32934
33135
  if (node === undefined) {
@@ -32939,6 +33140,9 @@ class CondBody {
32939
33140
  if (l) {
32940
33141
  scoped = let_1.Let.runSyntax(l, input);
32941
33142
  }
33143
+ for (const t of node.findDirectExpressions(Expressions.Throw)) {
33144
+ _raise_message_1.RaiseMessage.checkThrow(t, input);
33145
+ }
32942
33146
  for (const s of node.findDirectExpressions(Expressions.Cond)) {
32943
33147
  cond_1.Cond.runSyntax(s, input);
32944
33148
  }
@@ -36603,6 +36807,7 @@ var __importStar = (this && this.__importStar) || (function () {
36603
36807
  Object.defineProperty(exports, "__esModule", ({ value: true }));
36604
36808
  exports.Select = void 0;
36605
36809
  const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
36810
+ const nodes_1 = __webpack_require__(/*! ../../nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
36606
36811
  const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
36607
36812
  const inline_data_1 = __webpack_require__(/*! ./inline_data */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/inline_data.js");
36608
36813
  const target_1 = __webpack_require__(/*! ./target */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/target.js");
@@ -36618,6 +36823,8 @@ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modu
36618
36823
  const version_1 = __webpack_require__(/*! ../../../version */ "./node_modules/@abaplint/core/build/src/version.js");
36619
36824
  const _check_database_fields_1 = __webpack_require__(/*! ./_check_database_fields */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/_check_database_fields.js");
36620
36825
  const isSimple = /^\w+$/;
36826
+ // SQL functions where the result has the same type as the first argument
36827
+ const sameTypeAsFirstArgument = new Set(["UPPER", "LOWER", "LTRIM", "RTRIM"]);
36621
36828
  class Select {
36622
36829
  static runSyntax(node, input, skipImplicitInto = false, selectLoop = false) {
36623
36830
  var _a;
@@ -36823,7 +37030,7 @@ class Select {
36823
37030
  if (intoStructure) {
36824
37031
  const inlineList = intoStructure.findAllExpressions(Expressions.InlineData);
36825
37032
  if (inlineList.length === 1) {
36826
- inline_data_1.InlineData.runSyntax(inlineList[0], input, this.buildStructureType(fields, dbSources, input.scope));
37033
+ inline_data_1.InlineData.runSyntax(inlineList[0], input, this.buildStructureType(fields, dbSources, input.scope, from));
36827
37034
  }
36828
37035
  else {
36829
37036
  for (const inline of inlineList) {
@@ -36853,7 +37060,12 @@ class Select {
36853
37060
  return;
36854
37061
  }
36855
37062
  let type = basic_1.VoidType.get("SELECT_todo2");
36856
- if (isSimple.test(field.code)) {
37063
+ const fn = this.findFunctionColumn(field, false);
37064
+ if (fn) {
37065
+ const sourceInfos = this.buildDatabaseSourceInfos(from, dbSources);
37066
+ type = this.inferFunctionType(fn, code => this.findFieldType(code, sourceInfos, input.scope)) || type;
37067
+ }
37068
+ else if (isSimple.test(field.code)) {
36857
37069
  for (const dbSource of dbSources) {
36858
37070
  if (dbSource === undefined) {
36859
37071
  continue;
@@ -36885,7 +37097,7 @@ class Select {
36885
37097
  return basic_1.IntegerType.get();
36886
37098
  }
36887
37099
  }
36888
- static buildStructureType(fields, dbSources, scope) {
37100
+ static buildStructureType(fields, dbSources, scope, from) {
36889
37101
  var _a, _b, _c, _d, _e, _f;
36890
37102
  if (fields.length === 1 && dbSources.length === 1) {
36891
37103
  // COUNT( * ) yields an integer regardless of the (possibly dynamic) table
@@ -36921,10 +37133,16 @@ class Select {
36921
37133
  return basic_1.IntegerType.get();
36922
37134
  }
36923
37135
  }
36924
- else {
36925
- // todo: aggregated/calculated values
36926
- return basic_1.VoidType.get("SELECT_todo11");
37136
+ const fn = this.findFunctionColumn(fields[0], false);
37137
+ if (fn) {
37138
+ const sourceInfos = this.buildDatabaseSourceInfos(from, dbSources);
37139
+ const type = this.inferFunctionType(fn, code => this.findFieldType(code, sourceInfos, scope));
37140
+ if (type) {
37141
+ return type;
37142
+ }
36927
37143
  }
37144
+ // todo: aggregated/calculated values
37145
+ return basic_1.VoidType.get("SELECT_todo11");
36928
37146
  }
36929
37147
  else {
36930
37148
  return basic_1.VoidType.get("SELECT_todo10");
@@ -36945,15 +37163,10 @@ class Select {
36945
37163
  if (!(dbType instanceof basic_1.StructureType)) {
36946
37164
  return basic_1.VoidType.get("SELECT_todo14");
36947
37165
  }
36948
- const allFieldsSimple = fields.every(f => isSimple.test(f.code));
36949
- if (allFieldsSimple === true) {
36950
- const components = [];
36951
- for (const field of fields) {
36952
- const type = dbType.getComponentByName(field.code);
36953
- if (type === undefined) {
36954
- return basic_1.VoidType.get("SELECT_todo9");
36955
- }
36956
- components.push({ name: field.as || field.code, type });
37166
+ if (this.allFieldsSupported(fields) === true) {
37167
+ const components = this.buildSingleSourceComponents(fields, dbType, from, dbSources, scope);
37168
+ if (components === undefined) {
37169
+ return basic_1.VoidType.get("SELECT_todo9");
36957
37170
  }
36958
37171
  return new basic_1.StructureType(components);
36959
37172
  }
@@ -36979,9 +37192,15 @@ class Select {
36979
37192
  }
36980
37193
  return new basic_1.TableType(new basic_1.StructureType(components), tableOptions, undefined);
36981
37194
  }
37195
+ const lookup = code => this.findFieldType(code, sourceInfos, scope);
36982
37196
  const components = [];
36983
37197
  for (const field of fields) {
36984
- const type = this.findFieldType(field.code, sourceInfos, scope);
37198
+ const fn = this.findFunctionColumn(field);
37199
+ if (fn) {
37200
+ components.push({ name: field.as, type: this.inferFunctionType(fn, lookup) || basic_1.VoidType.get("SELECT_function") });
37201
+ continue;
37202
+ }
37203
+ const type = lookup(field.code);
36985
37204
  if (type === undefined) {
36986
37205
  return basic_1.VoidType.get("SELECT_todo3");
36987
37206
  }
@@ -37004,20 +37223,101 @@ class Select {
37004
37223
  if (fields.length === 1 && fields[0].code === "*") {
37005
37224
  return new basic_1.TableType(dbType, tableOptions, undefined);
37006
37225
  }
37007
- const allFieldsSimple = fields.every(f => isSimple.test(f.code));
37008
- if (allFieldsSimple === true) {
37009
- const components = [];
37010
- for (const field of fields) {
37011
- const type = dbType.getComponentByName(field.code);
37012
- if (type === undefined) {
37013
- return basic_1.VoidType.get("SELECT_todo6");
37014
- }
37015
- components.push({ name: field.as || field.code, type });
37226
+ if (this.allFieldsSupported(fields) === true) {
37227
+ const components = this.buildSingleSourceComponents(fields, dbType, from, dbSources, scope);
37228
+ if (components === undefined) {
37229
+ return basic_1.VoidType.get("SELECT_todo6");
37016
37230
  }
37017
37231
  return new basic_1.TableType(new basic_1.StructureType(components), tableOptions, undefined);
37018
37232
  }
37019
37233
  return basic_1.VoidType.get("SELECT_todo7");
37020
37234
  }
37235
+ /** plain field names, or SQL function columns with an alias */
37236
+ static allFieldsSupported(fields) {
37237
+ return fields.every(f => isSimple.test(f.code) || this.findFunctionColumn(f) !== undefined);
37238
+ }
37239
+ /** returns undefined if a plain field is not found in the database table */
37240
+ static buildSingleSourceComponents(fields, dbType, from, dbSources, scope) {
37241
+ const sourceInfos = this.buildDatabaseSourceInfos(from, dbSources);
37242
+ const lookup = code => this.findFieldType(code, sourceInfos, scope);
37243
+ const components = [];
37244
+ for (const field of fields) {
37245
+ const fn = this.findFunctionColumn(field);
37246
+ if (fn) {
37247
+ components.push({ name: field.as, type: this.inferFunctionType(fn, lookup) || basic_1.VoidType.get("SELECT_function") });
37248
+ continue;
37249
+ }
37250
+ const type = dbType.getComponentByName(field.code);
37251
+ if (type === undefined) {
37252
+ return undefined;
37253
+ }
37254
+ components.push({ name: field.as || field.code, type });
37255
+ }
37256
+ return components;
37257
+ }
37258
+ /** returns the SQLFunction node if the field list entry is a single SQL function call */
37259
+ static findFunctionColumn(field, requireAlias = true) {
37260
+ if (requireAlias === true && field.as === "") {
37261
+ return undefined;
37262
+ }
37263
+ else if (!(field.expression.get() instanceof Expressions.SQLField)) {
37264
+ return undefined;
37265
+ }
37266
+ const children = field.expression.getChildren().filter(c => !(c.get() instanceof Expressions.SQLAsName) && c.concatTokens().toUpperCase() !== "AS");
37267
+ if (children.length === 1
37268
+ && children[0] instanceof nodes_1.ExpressionNode
37269
+ && children[0].get() instanceof Expressions.SQLFunction) {
37270
+ return children[0];
37271
+ }
37272
+ return undefined;
37273
+ }
37274
+ /** infers the result type of a SQL function, returns undefined if not possible */
37275
+ static inferFunctionType(fn, lookup) {
37276
+ const name = fn.getFirstToken().getStr().toUpperCase();
37277
+ const inputs = fn.findDirectExpressions(Expressions.SQLFunctionInput);
37278
+ if (inputs.length === 0) {
37279
+ return undefined;
37280
+ }
37281
+ if (name === "SUBSTRING" && inputs.length === 3) {
37282
+ const len = inputs[2].concatTokens();
37283
+ if (/^\d+$/.test(len) === false || parseInt(len, 10) <= 0) {
37284
+ return undefined;
37285
+ }
37286
+ const argType = this.inferFunctionInputType(inputs[0], lookup);
37287
+ if (argType instanceof basic_1.StringType) {
37288
+ return argType;
37289
+ }
37290
+ else if (argType instanceof basic_1.CharacterType
37291
+ || argType instanceof basic_1.NumericType
37292
+ || argType instanceof basic_1.DateType
37293
+ || argType instanceof basic_1.TimeType) {
37294
+ return new basic_1.CharacterType(parseInt(len, 10));
37295
+ }
37296
+ return undefined;
37297
+ }
37298
+ else if (sameTypeAsFirstArgument.has(name)) {
37299
+ const argType = this.inferFunctionInputType(inputs[0], lookup);
37300
+ if (argType instanceof basic_1.CharacterType || argType instanceof basic_1.StringType) {
37301
+ return argType;
37302
+ }
37303
+ return undefined;
37304
+ }
37305
+ return undefined;
37306
+ }
37307
+ static inferFunctionInputType(input, lookup) {
37308
+ const children = input.getChildren();
37309
+ if (children.length !== 1 || !(children[0] instanceof nodes_1.ExpressionNode)) {
37310
+ return undefined;
37311
+ }
37312
+ const child = children[0];
37313
+ if (child.get() instanceof Expressions.SQLFieldName || child.get() instanceof Expressions.SQLAliasField) {
37314
+ return lookup(child.concatTokens().toUpperCase());
37315
+ }
37316
+ else if (child.get() instanceof Expressions.SQLFunction) {
37317
+ return this.inferFunctionType(child, lookup);
37318
+ }
37319
+ return undefined;
37320
+ }
37021
37321
  static buildDatabaseSourceInfos(from, dbSources) {
37022
37322
  const fromSources = from.findAllExpressions(Expressions.SQLFromSource);
37023
37323
  return dbSources.map((source, index) => {
@@ -37052,16 +37352,20 @@ class Select {
37052
37352
  return undefined;
37053
37353
  }
37054
37354
  static findFields(node, input) {
37055
- var _a, _b;
37056
- const expr = node.findFirstExpression(Expressions.SQLFieldList);
37355
+ var _a, _b, _c;
37356
+ let expr = node.findFirstExpression(Expressions.SQLFieldList);
37357
+ // a single field can be wrapped in a nested SQLFieldList
37358
+ while (expr && expr.getChildren().length === 1 && ((_a = expr.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.SQLFieldList) {
37359
+ expr = expr.getFirstChild();
37360
+ }
37057
37361
  const ret = [];
37058
- if (((_a = expr === null || expr === void 0 ? void 0 : expr.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Dynamic) {
37362
+ if (((_b = expr === null || expr === void 0 ? void 0 : expr.getFirstChild()) === null || _b === void 0 ? void 0 : _b.get()) instanceof Expressions.Dynamic) {
37059
37363
  dynamic_1.Dynamic.runSyntax(expr.getFirstChild(), input);
37060
37364
  }
37061
37365
  // eslint-disable-next-line max-len
37062
37366
  for (const field of (expr === null || expr === void 0 ? void 0 : expr.findDirectExpressionsMulti([Expressions.SQLField, Expressions.SQLFieldName, Expressions.SQLAggregation])) || []) {
37063
37367
  let code = field.concatTokens().toUpperCase();
37064
- const as = ((_b = field.findDirectExpression(Expressions.SQLAsName)) === null || _b === void 0 ? void 0 : _b.concatTokens()) || "";
37368
+ const as = ((_c = field.findDirectExpression(Expressions.SQLAsName)) === null || _c === void 0 ? void 0 : _c.concatTokens()) || "";
37065
37369
  if (as !== "") {
37066
37370
  code = code.replace(" AS " + as.toUpperCase(), "");
37067
37371
  }
@@ -37479,8 +37783,9 @@ class Source {
37479
37783
  /** The calculation type of an arithmetic expression is the most general of the
37480
37784
  * operand types. An operand of type c, n, d, t or string is converted into it and
37481
37785
  * never becomes the result: "lv_f * '0.25'" is a float, not a character field of
37482
- * length four. Returns undefined when neither operand is numeric, leaving the
37483
- * decision to the caller. */
37786
+ * length four. Date and time operands count as numbers of days and seconds, type i:
37787
+ * "lv_end - lv_start" is a number of days, not a date. Returns undefined when neither
37788
+ * operand is numeric, leaving the decision to the caller. */
37484
37789
  static calculationType(left, right) {
37485
37790
  if (left === undefined || right === undefined) {
37486
37791
  return undefined;
@@ -37492,12 +37797,27 @@ class Source {
37492
37797
  else if (right instanceof basic_1.VoidType || right instanceof unknown_type_1.UnknownType) {
37493
37798
  return right;
37494
37799
  }
37800
+ const dateOrTime = left instanceof basic_1.DateType || left instanceof basic_1.TimeType
37801
+ || right instanceof basic_1.DateType || right instanceof basic_1.TimeType;
37802
+ if (left instanceof basic_1.DateType || left instanceof basic_1.TimeType) {
37803
+ left = basic_1.IntegerType.get();
37804
+ }
37805
+ if (right instanceof basic_1.DateType || right instanceof basic_1.TimeType) {
37806
+ right = basic_1.IntegerType.get();
37807
+ }
37495
37808
  const leftRank = this.numericRank(left);
37496
37809
  const rightRank = this.numericRank(right);
37497
37810
  if (leftRank === undefined && rightRank === undefined) {
37498
37811
  return undefined;
37499
37812
  }
37500
- else if (rightRank === undefined) {
37813
+ // a character-like operand next to a date or time counts as p: "lv_date + '5'" is p
37814
+ if (leftRank === undefined && this.isCharacterLike(left) && dateOrTime) {
37815
+ return rightRank >= 3 ? right : new basic_1.PackedType(8, 0);
37816
+ }
37817
+ else if (rightRank === undefined && this.isCharacterLike(right) && dateOrTime) {
37818
+ return leftRank >= 3 ? left : new basic_1.PackedType(8, 0);
37819
+ }
37820
+ if (rightRank === undefined) {
37501
37821
  return left;
37502
37822
  }
37503
37823
  else if (leftRank === undefined) {
@@ -37505,6 +37825,9 @@ class Source {
37505
37825
  }
37506
37826
  return leftRank >= rightRank ? left : right;
37507
37827
  }
37828
+ static isCharacterLike(type) {
37829
+ return type instanceof basic_1.CharacterType || type instanceof basic_1.NumericType || type instanceof basic_1.StringType;
37830
+ }
37508
37831
  static numericRank(type) {
37509
37832
  if (type instanceof basic_1.DecFloat34Type) {
37510
37833
  return 6;
@@ -38412,6 +38735,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
38412
38735
  exports.SwitchBody = void 0;
38413
38736
  const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
38414
38737
  const source_1 = __webpack_require__(/*! ./source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
38738
+ const _raise_message_1 = __webpack_require__(/*! ../_raise_message */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_raise_message.js");
38415
38739
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
38416
38740
  const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
38417
38741
  class SwitchBody {
@@ -38419,6 +38743,9 @@ class SwitchBody {
38419
38743
  if (node === undefined) {
38420
38744
  return;
38421
38745
  }
38746
+ for (const t of node.findDirectExpressions(Expressions.Throw)) {
38747
+ _raise_message_1.RaiseMessage.checkThrow(t, input);
38748
+ }
38422
38749
  const thenSource = node.findExpressionAfterToken("THEN");
38423
38750
  if (!((thenSource === null || thenSource === void 0 ? void 0 : thenSource.get()) instanceof Expressions.Source)) {
38424
38751
  const message = "SwitchBody, unexpected";
@@ -45360,6 +45687,7 @@ var __importStar = (this && this.__importStar) || (function () {
45360
45687
  Object.defineProperty(exports, "__esModule", ({ value: true }));
45361
45688
  exports.Loop = void 0;
45362
45689
  const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
45690
+ const nodes_1 = __webpack_require__(/*! ../../nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
45363
45691
  const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
45364
45692
  const target_1 = __webpack_require__(/*! ../expressions/target */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/target.js");
45365
45693
  const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
@@ -45471,6 +45799,17 @@ class Loop {
45471
45799
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
45472
45800
  return;
45473
45801
  }
45802
+ if (key.type === basic_1.TableAccessType.sorted && key.keyFields.length > 0) {
45803
+ // the first component of a sorted secondary key must be compared with = or IS INITIAL
45804
+ // in a part of the condition joined by AND, otherwise the WHERE cannot be optimized
45805
+ const first = key.keyFields[0].toUpperCase();
45806
+ if (this.hasKeyCompare(cond, first) === false) {
45807
+ const message = "Loop, WHERE cannot be optimized for secondary key " + name +
45808
+ ", key component " + first + " needs a comparison with = or IS INITIAL joined by AND";
45809
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
45810
+ return;
45811
+ }
45812
+ }
45474
45813
  if (!(0, version_1.releaseAtLeast)(input.scope.getRelease(), version_1.Release.v740sp02)) {
45475
45814
  const compares = cond.findAllExpressionsRecursive(Expressions.ComponentCompare).map(c => c.concatTokens().toUpperCase());
45476
45815
  for (const keyField of key.keyFields) {
@@ -45511,6 +45850,31 @@ class Loop {
45511
45850
  loop_group_by_1.LoopGroupBy.runSyntax(group, input);
45512
45851
  }
45513
45852
  }
45853
+ // true if a conjunct reachable through AND only, ie. not under OR or NOT, compares the component with = or IS INITIAL
45854
+ hasKeyCompare(cond, component) {
45855
+ if (cond.findDirectTokenByText("OR") !== undefined) {
45856
+ return false;
45857
+ }
45858
+ for (const child of cond.getChildren()) {
45859
+ if (child.get() instanceof Expressions.ComponentCompare && child instanceof nodes_1.ExpressionNode) {
45860
+ const concat = child.concatTokens().toUpperCase().replace(/\s+/g, " ");
45861
+ if (concat.startsWith(component + " = ")
45862
+ || concat.startsWith(component + " EQ ")
45863
+ || concat === component + " IS INITIAL") {
45864
+ return true;
45865
+ }
45866
+ }
45867
+ else if (child.get() instanceof Expressions.ComponentCondSub
45868
+ && child instanceof nodes_1.ExpressionNode
45869
+ && child.findDirectTokenByText("NOT") === undefined) {
45870
+ const sub = child.findDirectExpression(Expressions.ComponentCond);
45871
+ if (sub !== undefined && this.hasKeyCompare(sub, component)) {
45872
+ return true;
45873
+ }
45874
+ }
45875
+ }
45876
+ return false;
45877
+ }
45514
45878
  }
45515
45879
  exports.Loop = Loop;
45516
45880
  //# sourceMappingURL=loop.js.map
@@ -46878,6 +47242,7 @@ const raise_with_1 = __webpack_require__(/*! ../expressions/raise_with */ "./nod
46878
47242
  const _object_oriented_1 = __webpack_require__(/*! ../_object_oriented */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_object_oriented.js");
46879
47243
  const method_parameters_1 = __webpack_require__(/*! ../expressions/method_parameters */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/method_parameters.js");
46880
47244
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
47245
+ const _raise_message_1 = __webpack_require__(/*! ../_raise_message */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_raise_message.js");
46881
47246
  class Raise {
46882
47247
  runSyntax(node, input) {
46883
47248
  // todo
@@ -46937,6 +47302,7 @@ class Raise {
46937
47302
  if (param) {
46938
47303
  new method_parameters_1.MethodParameters().checkExporting(param, input, method, true);
46939
47304
  }
47305
+ _raise_message_1.RaiseMessage.checkRaise(node, input);
46940
47306
  for (const s of node.findDirectExpressions(Expressions.RaiseWith)) {
46941
47307
  raise_with_1.RaiseWith.runSyntax(s, input);
46942
47308
  }
@@ -50924,6 +51290,107 @@ exports.Statics = Statics;
50924
51290
 
50925
51291
  /***/ },
50926
51292
 
51293
+ /***/ "./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/try.js"
51294
+ /*!*******************************************************************************!*\
51295
+ !*** ./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/try.js ***!
51296
+ \*******************************************************************************/
51297
+ (__unused_webpack_module, exports, __webpack_require__) {
51298
+
51299
+ "use strict";
51300
+
51301
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
51302
+ if (k2 === undefined) k2 = k;
51303
+ var desc = Object.getOwnPropertyDescriptor(m, k);
51304
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
51305
+ desc = { enumerable: true, get: function() { return m[k]; } };
51306
+ }
51307
+ Object.defineProperty(o, k2, desc);
51308
+ }) : (function(o, m, k, k2) {
51309
+ if (k2 === undefined) k2 = k;
51310
+ o[k2] = m[k];
51311
+ }));
51312
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
51313
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
51314
+ }) : function(o, v) {
51315
+ o["default"] = v;
51316
+ });
51317
+ var __importStar = (this && this.__importStar) || (function () {
51318
+ var ownKeys = function(o) {
51319
+ ownKeys = Object.getOwnPropertyNames || function (o) {
51320
+ var ar = [];
51321
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
51322
+ return ar;
51323
+ };
51324
+ return ownKeys(o);
51325
+ };
51326
+ return function (mod) {
51327
+ if (mod && mod.__esModule) return mod;
51328
+ var result = {};
51329
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
51330
+ __setModuleDefault(result, mod);
51331
+ return result;
51332
+ };
51333
+ })();
51334
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
51335
+ exports.Try = void 0;
51336
+ const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
51337
+ const Statements = __importStar(__webpack_require__(/*! ../../2_statements/statements */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/index.js"));
51338
+ const Structures = __importStar(__webpack_require__(/*! ../../3_structures/structures */ "./node_modules/@abaplint/core/build/src/abap/3_structures/structures/index.js"));
51339
+ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
51340
+ // "special exceptions must be caught before general exceptions", a CATCH of a class that inherits
51341
+ // from a class named in an earlier CATCH of the same TRY can never be reached, this is a syntax error
51342
+ // only reported when the lineage of the later class is known up to the earlier class, void classes are skipped
51343
+ class Try {
51344
+ static runSyntax(node, input) {
51345
+ const caught = new Set();
51346
+ for (const catchStructure of node.findDirectStructures(Structures.Catch)) {
51347
+ const statement = catchStructure.findDirectStatement(Statements.Catch);
51348
+ if (statement === undefined) {
51349
+ continue;
51350
+ }
51351
+ const names = [];
51352
+ for (const c of statement.findDirectExpressions(Expressions.ClassName)) {
51353
+ const token = c.getFirstToken();
51354
+ const className = token.getStr().toUpperCase();
51355
+ names.push(className);
51356
+ if (caught.size === 0) {
51357
+ continue;
51358
+ }
51359
+ const superclass = this.findCaughtSuperclass(className, caught, input);
51360
+ if (superclass !== undefined) {
51361
+ const message = `CATCH of ${className} after the CATCH of its superclass ${superclass}`;
51362
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, message));
51363
+ return;
51364
+ }
51365
+ }
51366
+ for (const name of names) {
51367
+ caught.add(name);
51368
+ }
51369
+ }
51370
+ }
51371
+ static findCaughtSuperclass(className, caught, input) {
51372
+ var _a;
51373
+ const visited = new Set([className]);
51374
+ let current = input.scope.findClassDefinition(className);
51375
+ while (current !== undefined) {
51376
+ const superclass = (_a = current.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
51377
+ if (superclass === undefined || visited.has(superclass)) {
51378
+ return undefined;
51379
+ }
51380
+ else if (caught.has(superclass)) {
51381
+ return superclass;
51382
+ }
51383
+ visited.add(superclass);
51384
+ current = input.scope.findClassDefinition(superclass);
51385
+ }
51386
+ return undefined;
51387
+ }
51388
+ }
51389
+ exports.Try = Try;
51390
+ //# sourceMappingURL=try.js.map
51391
+
51392
+ /***/ },
51393
+
50927
51394
  /***/ "./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/type_enum.js"
50928
51395
  /*!*************************************************************************************!*\
50929
51396
  !*** ./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/type_enum.js ***!
@@ -51331,6 +51798,7 @@ const types_1 = __webpack_require__(/*! ./structures/types */ "./node_modules/@a
51331
51798
  const statics_1 = __webpack_require__(/*! ./structures/statics */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/statics.js");
51332
51799
  const constants_1 = __webpack_require__(/*! ./structures/constants */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/constants.js");
51333
51800
  const cleanup_1 = __webpack_require__(/*! ./structures/cleanup */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/cleanup.js");
51801
+ const try_1 = __webpack_require__(/*! ./structures/try */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/structures/try.js");
51334
51802
  const class_definition_1 = __webpack_require__(/*! ../types/class_definition */ "./node_modules/@abaplint/core/build/src/abap/types/class_definition.js");
51335
51803
  const interface_definition_1 = __webpack_require__(/*! ../types/interface_definition */ "./node_modules/@abaplint/core/build/src/abap/types/interface_definition.js");
51336
51804
  const delete_memory_1 = __webpack_require__(/*! ./statements/delete_memory */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/statements/delete_memory.js");
@@ -51816,6 +52284,9 @@ class SyntaxLogic {
51816
52284
  else if (stru instanceof Structures.Cleanup) {
51817
52285
  cleanup_1.Cleanup.runSyntax(node, input);
51818
52286
  }
52287
+ else if (stru instanceof Structures.Try) {
52288
+ try_1.Try.runSyntax(node, input);
52289
+ }
51819
52290
  return false;
51820
52291
  }
51821
52292
  updateScopeStatement(node) {
@@ -74276,7 +74747,7 @@ class Registry {
74276
74747
  }
74277
74748
  static abaplintVersion() {
74278
74749
  // magic, see build script "version.js"
74279
- return "2.120.99";
74750
+ return "2.120.103";
74280
74751
  }
74281
74752
  getDDICReferences() {
74282
74753
  return this.ddicReferences;
@@ -91904,13 +92375,18 @@ class FullyTypeConstants extends _abap_rule_1.ABAPRule {
91904
92375
  if ((stat.get() instanceof Statements.Constant
91905
92376
  || (this.conf.checkData === true && stat.get() instanceof Statements.Data))
91906
92377
  && !this.isTyped(stat)) {
92378
+ if (stat.get() instanceof Statements.Data && stat.findDirectExpression(expressions_1.DataDefinition) === undefined) {
92379
+ // unnamed field, eg. "DATA (10)." inside DATA BEGIN OF, cannot be typed
92380
+ continue;
92381
+ }
91907
92382
  const type = stat.get() instanceof Statements.Constant ? "constant definition" : "data definition";
91908
92383
  let token = (_a = stat.findFirstExpression(expressions_1.NamespaceSimpleName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
91909
92384
  if (token === undefined) {
91910
92385
  token = (_b = stat.findFirstExpression(expressions_1.DefinitionName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
91911
92386
  }
91912
92387
  if (token === undefined) {
91913
- throw new Error("fully type constants, unexpected node");
92388
+ const start = stat.getFirstToken().getStart();
92389
+ throw new Error(`fully type constants: unexpected node, ${file.getFilename()}, row ${start.getRow()}, col ${start.getCol()}, statement "${stat.concatTokens()}"`);
91914
92390
  }
91915
92391
  issues.push(issue_1.Issue.atToken(file, token, this.getDescription(type), this.getMetadata().key, this.conf.severity));
91916
92392
  }
@@ -117936,6 +118412,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
117936
118412
  exports.CallTransformationOptionsTranspiler = void 0;
117937
118413
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
117938
118414
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
118415
+ const constant_1 = __webpack_require__(/*! ./constant */ "./node_modules/@abaplint/transpiler/build/src/expressions/constant.js");
117939
118416
  class CallTransformationOptionsTranspiler {
117940
118417
  transpile(node, traversal) {
117941
118418
  const res = new chunk_1.Chunk().appendString("{");
@@ -117944,7 +118421,7 @@ class CallTransformationOptionsTranspiler {
117944
118421
  if (res.getCode() !== "{") {
117945
118422
  res.appendString(",");
117946
118423
  }
117947
- res.appendString(c.concatTokens());
118424
+ res.appendString(constant_1.ConstantTranspiler.normalizeInteger(c.concatTokens()));
117948
118425
  }
117949
118426
  else if (c.get() instanceof abaplint.Expressions.Source) {
117950
118427
  res.appendChunk(traversal.traverse(c));
@@ -118010,6 +118487,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
118010
118487
  exports.CallTransformationParametersTranspiler = void 0;
118011
118488
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
118012
118489
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
118490
+ const constant_1 = __webpack_require__(/*! ./constant */ "./node_modules/@abaplint/transpiler/build/src/expressions/constant.js");
118013
118491
  class CallTransformationParametersTranspiler {
118014
118492
  transpile(node, traversal) {
118015
118493
  if (node.getFirstChild()?.get() instanceof abaplint.Expressions.Dynamic) {
@@ -118022,7 +118500,7 @@ class CallTransformationParametersTranspiler {
118022
118500
  if (res.getCode() !== "{") {
118023
118501
  res.appendString(",");
118024
118502
  }
118025
- res.appendString(c.concatTokens());
118503
+ res.appendString(constant_1.ConstantTranspiler.normalizeInteger(c.concatTokens()));
118026
118504
  }
118027
118505
  else if (c.get() instanceof abaplint.Expressions.SimpleSource3) {
118028
118506
  res.appendChunk(traversal.traverse(c));
@@ -118784,11 +119262,20 @@ class ConstantTranspiler {
118784
119262
  constructor(addGet = false) {
118785
119263
  this.addGet = addGet;
118786
119264
  }
118787
- handleInteger(int, traversal) {
118788
- let concat = int.concatTokens().trim().replace(/^0+/, "");
118789
- if (concat === "") {
118790
- concat = "0";
119265
+ /** Normalizes an ABAP integer literal to a JavaScript decimal integer literal, which is also
119266
+ * valid in strict mode, where leading zeros give an octal literal and a SyntaxError.
119267
+ * "007" -> "7", "000" -> "0", "-007" -> "-7", "- 010" -> "-10", "+5" -> "5", "-000" -> "0".
119268
+ * Input that is not an integer literal is returned unchanged */
119269
+ static normalizeInteger(str) {
119270
+ const match = str.replace(/\s/g, "").match(/^([+-]?)(\d+)$/);
119271
+ if (match === null) {
119272
+ return str;
118791
119273
  }
119274
+ const digits = match[2].replace(/^0+(?=\d)/, "");
119275
+ return match[1] === "-" && digits !== "0" ? "-" + digits : digits;
119276
+ }
119277
+ handleInteger(int, traversal) {
119278
+ const concat = ConstantTranspiler.normalizeInteger(int.concatTokens());
118792
119279
  const parsed = Number.parseInt(concat, 10);
118793
119280
  let code = "";
118794
119281
  if (concat.length > 18) {
@@ -119338,6 +119825,7 @@ exports.FieldLengthTranspiler = void 0;
119338
119825
  const core_1 = __webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js");
119339
119826
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
119340
119827
  const field_chain_1 = __webpack_require__(/*! ./field_chain */ "./node_modules/@abaplint/transpiler/build/src/expressions/field_chain.js");
119828
+ const constant_1 = __webpack_require__(/*! ./constant */ "./node_modules/@abaplint/transpiler/build/src/expressions/constant.js");
119341
119829
  class FieldLengthTranspiler {
119342
119830
  transpile(node, traversal) {
119343
119831
  let ret = "";
@@ -119349,11 +119837,7 @@ class FieldLengthTranspiler {
119349
119837
  }
119350
119838
  else if (c instanceof core_1.Nodes.TokenNode) {
119351
119839
  if (c.get() instanceof core_1.Tokens.Identifier) {
119352
- let value = c.getFirstToken().getStr();
119353
- if (/^0+\d+$/.test(value)) {
119354
- value = value.replace(/^0+/, "") || "0";
119355
- }
119356
- ret += value;
119840
+ ret += constant_1.ConstantTranspiler.normalizeInteger(c.getFirstToken().getStr());
119357
119841
  }
119358
119842
  }
119359
119843
  }
@@ -119378,6 +119862,7 @@ exports.FieldOffsetTranspiler = void 0;
119378
119862
  const core_1 = __webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js");
119379
119863
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
119380
119864
  const field_chain_1 = __webpack_require__(/*! ./field_chain */ "./node_modules/@abaplint/transpiler/build/src/expressions/field_chain.js");
119865
+ const constant_1 = __webpack_require__(/*! ./constant */ "./node_modules/@abaplint/transpiler/build/src/expressions/constant.js");
119381
119866
  class FieldOffsetTranspiler {
119382
119867
  transpile(node, traversal) {
119383
119868
  let ret = "";
@@ -119389,11 +119874,7 @@ class FieldOffsetTranspiler {
119389
119874
  }
119390
119875
  else if (c instanceof core_1.Nodes.TokenNode) {
119391
119876
  if (c.get() instanceof core_1.Tokens.Identifier) {
119392
- let value = c.getFirstToken().getStr().toLowerCase();
119393
- if (/^0+\d+$/.test(value)) {
119394
- value = value.replace(/^0+/, "") || "0";
119395
- }
119396
- ret += value;
119877
+ ret += constant_1.ConstantTranspiler.normalizeInteger(c.getFirstToken().getStr().toLowerCase());
119397
119878
  }
119398
119879
  }
119399
119880
  }
@@ -121715,6 +122196,7 @@ const simple_source3_1 = __webpack_require__(/*! ./simple_source3 */ "./node_mod
121715
122196
  const field_chain_1 = __webpack_require__(/*! ./field_chain */ "./node_modules/@abaplint/transpiler/build/src/expressions/field_chain.js");
121716
122197
  const sql_field_name_1 = __webpack_require__(/*! ./sql_field_name */ "./node_modules/@abaplint/transpiler/build/src/expressions/sql_field_name.js");
121717
122198
  const source_1 = __webpack_require__(/*! ./source */ "./node_modules/@abaplint/transpiler/build/src/expressions/source.js");
122199
+ const constant_1 = __webpack_require__(/*! ./constant */ "./node_modules/@abaplint/transpiler/build/src/expressions/constant.js");
121718
122200
  const sql_field_list_1 = __webpack_require__(/*! ./sql_field_list */ "./node_modules/@abaplint/transpiler/build/src/expressions/sql_field_list.js");
121719
122201
  const sql_from_1 = __webpack_require__(/*! ./sql_from */ "./node_modules/@abaplint/transpiler/build/src/expressions/sql_from.js");
121720
122202
  const sql_function_1 = __webpack_require__(/*! ./sql_function */ "./node_modules/@abaplint/transpiler/build/src/expressions/sql_function.js");
@@ -121767,18 +122249,22 @@ class SQLCondTranspiler {
121767
122249
  sqlIn(c, traversal, filename, table) {
121768
122250
  const fieldName = c.findDirectExpression(abaplint.Expressions.SQLFieldName)
121769
122251
  || c.findDirectExpression(abaplint.Expressions.SQLAliasField);
122252
+ const sqlFunction = c.getFirstChild()?.get() instanceof abaplint.Expressions.SQLFunction
122253
+ ? c.getFirstChild() : undefined;
121770
122254
  const sqlin = c.findDirectExpression(abaplint.Expressions.SQLIn);
121771
122255
  const subselect = sqlin === undefined ? undefined : this.findSubselect(sqlin);
121772
- if (fieldName === undefined || sqlin === undefined) {
122256
+ if ((fieldName === undefined && sqlFunction === undefined) || sqlin === undefined) {
121773
122257
  throw new Error("SQL Condition, transpiler todo, " + c.concatTokens());
121774
122258
  }
122259
+ const fieldCode = () => sqlFunction
122260
+ ? new sql_function_1.SQLFunctionTranspiler().transpile(sqlFunction, traversal).getCode()
122261
+ : new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldName, traversal).getCode();
121775
122262
  let pre = "";
121776
122263
  if (c.concatTokens().toUpperCase().includes(" NOT IN ")) {
121777
122264
  pre = "NOT ";
121778
122265
  }
121779
122266
  if (subselect) {
121780
- const field = new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldName, traversal).getCode();
121781
- return `${field} ${pre}IN ${this.sqlSubselect(subselect, traversal, table)}`;
122267
+ return `${fieldCode()} ${pre}IN ${this.sqlSubselect(subselect, traversal, table)}`;
121782
122268
  }
121783
122269
  const source = c.findFirstExpression(abaplint.Expressions.SimpleSource3);
121784
122270
  if (source === undefined) {
@@ -121786,12 +122272,15 @@ class SQLCondTranspiler {
121786
122272
  }
121787
122273
  if (sqlin.getChildren().length === 2) {
121788
122274
  const s = new source_1.SourceTranspiler().transpile(source, traversal).getCode();
122275
+ if (sqlFunction) {
122276
+ return `${pre}" + abap.expandIN("${fieldCode()}", ${s}, true) + "`;
122277
+ }
121789
122278
  return `${pre}" + abap.expandIN("${fieldName.concatTokens()}", ${s}) + "`;
121790
122279
  }
121791
122280
  else {
121792
122281
  const cond = [];
121793
122282
  for (const s of sqlin.findDirectExpressions(abaplint.Expressions.SQLSource).concat(sqlin.findDirectExpressions(abaplint.Expressions.SQLSourceNoSpace))) {
121794
- const field = new sql_field_name_1.SQLFieldNameTranspiler().transpile(fieldName, traversal).getCode();
122283
+ const field = fieldCode();
121795
122284
  const sourc = this.sqlSource(s, traversal, filename, table);
121796
122285
  cond.push(field + " = " + sourc);
121797
122286
  }
@@ -121932,7 +122421,9 @@ class SQLCondTranspiler {
121932
122421
  const conversionField = traversal.isSQLConversion(source.getFirstToken());
121933
122422
  if (conversionField) {
121934
122423
  const field = (table?.parseType(traversal.reg)).getComponentByName(conversionField);
121935
- ret += "'\" + abap.sqlEscape(" + traversal.toType(field) + ".set(" + concat + ").get()) + \"'";
122424
+ // the literal is emitted as JavaScript, an integer like 007 must not become an octal literal
122425
+ const value = constant_1.ConstantTranspiler.normalizeInteger(concat);
122426
+ ret += "'\" + abap.sqlEscape(" + traversal.toType(field) + ".set(" + value + ").get()) + \"'";
121936
122427
  }
121937
122428
  else if (concat.startsWith("`")) {
121938
122429
  ret += "'" + concat.substring(1, concat.length - 1).replace(/'/g, "''") + "'";
@@ -125390,8 +125881,12 @@ exports.InlineDeclarations = void 0;
125390
125881
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
125391
125882
  const statements_1 = __webpack_require__(/*! ./statements */ "./node_modules/@abaplint/transpiler/build/src/statements/index.js");
125392
125883
  class InlineDeclarations {
125393
- static buildDeclarations(node, traversal) {
125394
- const inlineDataExpressions = node.findAllExpressionsRecursive(abaplint.Expressions.InlineData);
125884
+ static buildDeclarations(node, traversal, programLevelOnly = false) {
125885
+ const include = (expression) => {
125886
+ return programLevelOnly === false
125887
+ || InlineDeclarations.isProgramLevelScope(traversal.findCurrentScopeByToken(expression.getFirstToken()));
125888
+ };
125889
+ const inlineDataExpressions = node.findAllExpressionsRecursive(abaplint.Expressions.InlineData).filter(include);
125395
125890
  let result = "";
125396
125891
  for (const expression of inlineDataExpressions) {
125397
125892
  const name = expression.findFirstExpression(abaplint.Expressions.TargetField)?.concatTokens();
@@ -125406,7 +125901,7 @@ class InlineDeclarations {
125406
125901
  result += traversal.declare(variable) + "\n";
125407
125902
  }
125408
125903
  // todo: declare DATA and FSes according to when they appear in the code
125409
- const inlineFieldSymbols = node.findAllExpressionsRecursive(abaplint.Expressions.InlineFS);
125904
+ const inlineFieldSymbols = node.findAllExpressionsRecursive(abaplint.Expressions.InlineFS).filter(include);
125410
125905
  for (const expression of inlineFieldSymbols) {
125411
125906
  const target = expression.findFirstExpression(abaplint.Expressions.TargetFieldSymbol);
125412
125907
  if (target === undefined) {
@@ -125416,6 +125911,12 @@ class InlineDeclarations {
125416
125911
  }
125417
125912
  return result;
125418
125913
  }
125914
+ /** inline declarations outside FORMs, methods and function modules belong to the program, or to an
125915
+ * event block like START-OF-SELECTION, which is also program global */
125916
+ static isProgramLevelScope(scope) {
125917
+ const stype = scope?.getIdentifier().stype;
125918
+ return stype === abaplint.ScopeType.Program || stype === abaplint.ScopeType.SelectionEvent;
125919
+ }
125419
125920
  }
125420
125921
  exports.InlineDeclarations = InlineDeclarations;
125421
125922
  //# sourceMappingURL=inline.js.map
@@ -127134,14 +127635,11 @@ switch (e.classic.toUpperCase()) {\n`;
127134
127635
  for (const e of node.findAllExpressions(abaplint.Expressions.ParameterException)) {
127135
127636
  const name = e.getFirstToken().getStr().toUpperCase();
127136
127637
  // todo, also handle SimpleChain,
127137
- let value = e.findFirstExpression(abaplint.Expressions.Integer)?.getFirstToken().getStr().toUpperCase();
127138
- if (value === undefined) {
127638
+ const integer = e.findFirstExpression(abaplint.Expressions.Integer);
127639
+ if (integer === undefined) {
127139
127640
  continue;
127140
127641
  }
127141
- while (value.substring(0, 1) === "0" && value.length > 1) {
127142
- // remove leading zeros
127143
- value = value.substring(1);
127144
- }
127642
+ const value = expressions_1.ConstantTranspiler.normalizeInteger(integer.concatTokens());
127145
127643
  if (name === "OTHERS") {
127146
127644
  post += `default: abap.builtin.sy.get().subrc.set(${value}); break;\n`;
127147
127645
  }
@@ -127828,8 +128326,14 @@ exports.ClearTranspiler = void 0;
127828
128326
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
127829
128327
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
127830
128328
  class ClearTranspiler {
128329
+ body;
128330
+ /** body: FREE, which clears the body of a table with a header line; CLEAR clears its header line */
128331
+ constructor(body = false) {
128332
+ this.body = body;
128333
+ }
127831
128334
  transpile(node, traversal) {
127832
- const target = traversal.traverse(node.findDirectExpression(abaplint.Expressions.Target));
128335
+ const targetNode = node.findDirectExpression(abaplint.Expressions.Target);
128336
+ const target = traversal.traverse(targetNode);
127833
128337
  // Reference implementation for the source-map convention:
127834
128338
  // - keep the target's own expression-level mappings by appending its Chunk
127835
128339
  // (do NOT flatten with target.getCode(), that discards the mappings)
@@ -127837,9 +128341,24 @@ class ClearTranspiler {
127837
128341
  // getEnd() which points one column past the statement
127838
128342
  const ret = new chunk_1.Chunk();
127839
128343
  ret.appendChunk(target);
127840
- ret.append(".clear();", node.getLastToken(), traversal);
128344
+ if (this.body === false && targetNode && ClearTranspiler.isHeaderLineTable(targetNode, traversal)) {
128345
+ // CLEAR itab of a table with a header line clears the header line, CLEAR itab[] the rows
128346
+ ret.append(".getHeader().clear();", node.getLastToken(), traversal);
128347
+ }
128348
+ else {
128349
+ ret.append(".clear();", node.getLastToken(), traversal);
128350
+ }
127841
128351
  return ret;
127842
128352
  }
128353
+ /** the target is the plain name of a table with a header line (not itab[]) */
128354
+ static isHeaderLineTable(target, traversal) {
128355
+ if (target.getChildren().length !== 1 || !(target.getFirstChild()?.get() instanceof abaplint.Expressions.TargetField)) {
128356
+ return false;
128357
+ }
128358
+ const name = target.getFirstToken();
128359
+ const type = traversal.findCurrentScopeByToken(name)?.findVariable(name.getStr().replace(/^!/, ""))?.getType();
128360
+ return type instanceof abaplint.BasicTypes.TableType && type.isWithHeader();
128361
+ }
127843
128362
  }
127844
128363
  exports.ClearTranspiler = ClearTranspiler;
127845
128364
  //# sourceMappingURL=clear.js.map
@@ -128916,12 +129435,13 @@ class DataTranspiler {
128916
129435
  let value = "";
128917
129436
  const val = node.findFirstExpression(abaplint.Expressions.Value);
128918
129437
  if (val) {
128919
- let int = val.findFirstExpression(abaplint.Expressions.Integer);
128920
- if (int === undefined) {
128921
- int = val.findFirstExpression(abaplint.Expressions.ConstantString);
128922
- }
129438
+ const int = val.findFirstExpression(abaplint.Expressions.Integer);
129439
+ const str = val.findFirstExpression(abaplint.Expressions.ConstantString);
128923
129440
  if (int) {
128924
- const escaped = constant_1.ConstantTranspiler.escape(constant_1.ConstantTranspiler.trimTextFieldLiteral(int.concatTokens()));
129441
+ value = "\n" + name + ".set(" + constant_1.ConstantTranspiler.normalizeInteger(int.concatTokens()) + ");";
129442
+ }
129443
+ else if (str) {
129444
+ const escaped = constant_1.ConstantTranspiler.escape(constant_1.ConstantTranspiler.trimTextFieldLiteral(str.concatTokens()));
128925
129445
  value = "\n" + name + ".set(" + escaped + ");";
128926
129446
  }
128927
129447
  else if (val.getChildren()[1].get() instanceof abaplint.Expressions.SimpleFieldChain) {
@@ -130451,7 +130971,8 @@ exports.FreeTranspiler = void 0;
130451
130971
  const clear_1 = __webpack_require__(/*! ./clear */ "./node_modules/@abaplint/transpiler/build/src/statements/clear.js");
130452
130972
  class FreeTranspiler {
130453
130973
  transpile(node, traversal) {
130454
- return new clear_1.ClearTranspiler().transpile(node, traversal);
130974
+ // FREE of a table with a header line frees the table body, not the header line
130975
+ return new clear_1.ClearTranspiler(true).transpile(node, traversal);
130455
130976
  }
130456
130977
  }
130457
130978
  exports.FreeTranspiler = FreeTranspiler;
@@ -131326,6 +131847,7 @@ __exportStar(__webpack_require__(/*! ./move_corresponding */ "./node_modules/@ab
131326
131847
  __exportStar(__webpack_require__(/*! ./move */ "./node_modules/@abaplint/transpiler/build/src/statements/move.js"), exports);
131327
131848
  __exportStar(__webpack_require__(/*! ./multiply */ "./node_modules/@abaplint/transpiler/build/src/statements/multiply.js"), exports);
131328
131849
  __exportStar(__webpack_require__(/*! ./native_sql */ "./node_modules/@abaplint/transpiler/build/src/statements/native_sql.js"), exports);
131850
+ __exportStar(__webpack_require__(/*! ./new_line */ "./node_modules/@abaplint/transpiler/build/src/statements/new_line.js"), exports);
131329
131851
  __exportStar(__webpack_require__(/*! ./new_page */ "./node_modules/@abaplint/transpiler/build/src/statements/new_page.js"), exports);
131330
131852
  __exportStar(__webpack_require__(/*! ./open_cursor */ "./node_modules/@abaplint/transpiler/build/src/statements/open_cursor.js"), exports);
131331
131853
  __exportStar(__webpack_require__(/*! ./open_dataset */ "./node_modules/@abaplint/transpiler/build/src/statements/open_dataset.js"), exports);
@@ -133064,6 +133586,28 @@ exports.NativeSQLTranspiler = NativeSQLTranspiler;
133064
133586
 
133065
133587
  /***/ },
133066
133588
 
133589
+ /***/ "./node_modules/@abaplint/transpiler/build/src/statements/new_line.js"
133590
+ /*!****************************************************************************!*\
133591
+ !*** ./node_modules/@abaplint/transpiler/build/src/statements/new_line.js ***!
133592
+ \****************************************************************************/
133593
+ (__unused_webpack_module, exports, __webpack_require__) {
133594
+
133595
+ "use strict";
133596
+
133597
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
133598
+ exports.NewLineTranspiler = void 0;
133599
+ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
133600
+ class NewLineTranspiler {
133601
+ transpile(node, traversal) {
133602
+ // NEW-LINE [NO-SCROLLING | SCROLLING]: the next output starts a new line, scrolling has no effect on the text
133603
+ return new chunk_1.Chunk().append("abap.statements.newLine();", node, traversal);
133604
+ }
133605
+ }
133606
+ exports.NewLineTranspiler = NewLineTranspiler;
133607
+ //# sourceMappingURL=new_line.js.map
133608
+
133609
+ /***/ },
133610
+
133067
133611
  /***/ "./node_modules/@abaplint/transpiler/build/src/statements/new_page.js"
133068
133612
  /*!****************************************************************************!*\
133069
133613
  !*** ./node_modules/@abaplint/transpiler/build/src/statements/new_page.js ***!
@@ -134094,6 +134638,34 @@ class ReadTableTranspiler {
134094
134638
  extra.push("into: " + name);
134095
134639
  }
134096
134640
  }
134641
+ // COMPARING comp1 comp2 ... | ALL FIELDS, TRANSPORTING comp1 comp2 ...
134642
+ const children = node.getChildren();
134643
+ const comparingAt = children.findIndex(c => c instanceof abaplint.Nodes.TokenNode && c.concatTokens().toUpperCase() === "COMPARING");
134644
+ let transported = undefined;
134645
+ if (comparingAt >= 0) {
134646
+ const names = [];
134647
+ for (let i = comparingAt + 1; i < children.length; i++) {
134648
+ const c = children[i];
134649
+ if (!(c instanceof abaplint.Nodes.ExpressionNode) || !(c.get() instanceof abaplint.Expressions.FieldSub)) {
134650
+ break;
134651
+ }
134652
+ names.push(c.concatTokens().toLowerCase());
134653
+ }
134654
+ // the parser can read "COMPARING a TRANSPORTING b" as four compared names
134655
+ const cut = names.indexOf("transporting");
134656
+ if (cut >= 0) {
134657
+ transported = names.slice(cut + 1);
134658
+ names.splice(cut);
134659
+ }
134660
+ extra.push("comparing: " + JSON.stringify(names.join(" ") === "all fields" ? ["*"] : names));
134661
+ }
134662
+ const transportingFields = node.findDirectExpression(abaplint.Expressions.TransportingFields);
134663
+ if (transportingFields) {
134664
+ transported = transportingFields.findAllExpressions(abaplint.Expressions.FieldSub).map(f => f.concatTokens().toLowerCase());
134665
+ }
134666
+ if (transported !== undefined && transported.join(" ") !== "all fields") {
134667
+ extra.push("transporting: " + JSON.stringify(transported));
134668
+ }
134097
134669
  const compare = node.findDirectExpression(abaplint.Expressions.ComponentCompareSimple);
134098
134670
  if (compare) {
134099
134671
  const withKey = [];
@@ -138547,7 +139119,6 @@ const at_last_1 = __webpack_require__(/*! ./at_last */ "./node_modules/@abaplint
138547
139119
  const unique_identifier_1 = __webpack_require__(/*! ../unique_identifier */ "./node_modules/@abaplint/transpiler/build/src/unique_identifier.js");
138548
139120
  const statements_1 = __webpack_require__(/*! ../statements */ "./node_modules/@abaplint/transpiler/build/src/statements/index.js");
138549
139121
  const at_1 = __webpack_require__(/*! ./at */ "./node_modules/@abaplint/transpiler/build/src/structures/at.js");
138550
- const inline_1 = __webpack_require__(/*! ../inline */ "./node_modules/@abaplint/transpiler/build/src/inline.js");
138551
139122
  class LoopTranspiler {
138552
139123
  transpile(node, traversal) {
138553
139124
  const ret = new chunk_1.Chunk();
@@ -138569,11 +139140,6 @@ class LoopTranspiler {
138569
139140
  const hasAtLast = (node.findDirectStructure(abaplint.Structures.Body)
138570
139141
  ?.findDirectStructures(abaplint.Structures.Normal) || [])
138571
139142
  .some(n => n.findDirectStructure(abaplint.Structures.AtLast) !== undefined);
138572
- const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
138573
- if (scope?.getIdentifier().stype === abaplint.ScopeType.Program
138574
- || scope?.getIdentifier().stype === abaplint.ScopeType.SelectionEvent) {
138575
- ret.appendString(inline_1.InlineDeclarations.buildDeclarations(node, traversal));
138576
- }
138577
139143
  if (hasAtLast) {
138578
139144
  atLastFlag = unique_identifier_1.UniqueIdentifier.get();
138579
139145
  ret.appendString(`let ${atLastFlag} = false;\n`);
@@ -138911,54 +139477,71 @@ class TryTranspiler {
138911
139477
  return ret;
138912
139478
  }
138913
139479
  /////////////////////
139480
+ // Built as chunks, not as strings: the bodies keep their source mappings, so a stack frame, a
139481
+ // source map or a debugger can name an ABAP line inside a CATCH or CLEANUP block
138914
139482
  buildHandlerCode(nodes, cleanup, traversal) {
138915
- let ret = "";
138916
- let first = true;
138917
139483
  if (nodes.length === 0 && cleanup === undefined) {
138918
139484
  return undefined;
138919
139485
  }
138920
- ret += `} catch (e) {\n`;
139486
+ const ret = new chunk_1.Chunk();
139487
+ ret.appendString(`} catch (e) {\n`);
139488
+ let first = true;
138921
139489
  for (const n of nodes) {
138922
139490
  const catchStatement = n.findDirectStatement(abaplint.Statements.Catch);
138923
139491
  if (catchStatement === undefined) {
138924
139492
  throw "TryTranspiler, unexpected structure";
138925
139493
  }
138926
139494
  const catchNames = catchStatement.findDirectExpressions(abaplint.Expressions.ClassName).map(e => traversal.lookupClassOrInterface(e.concatTokens(), e.getFirstToken()));
138927
- ret += first ? "" : " else ";
139495
+ if (first === false) {
139496
+ ret.appendString(" else ");
139497
+ }
138928
139498
  first = false;
138929
- ret += "if (" + catchNames?.map(n => "(" + n + " && e instanceof " + n + ")").join(" || ") + ") {\n";
139499
+ ret.append("if (" + catchNames?.map(n => "(" + n + " && e instanceof " + n + ")").join(" || ") + ") {\n", catchStatement, traversal);
138930
139500
  const intoNode = catchStatement.findExpressionAfterToken("INTO");
138931
139501
  if (intoNode) {
138932
- ret += traversal.traverse(intoNode).getCode() + ".set(e);\n";
139502
+ ret.appendChunk(traversal.traverse(intoNode)).appendString(".set(e);\n");
138933
139503
  }
138934
139504
  const body = n.findDirectStructure(abaplint.Structures.Body);
138935
139505
  if (body) {
138936
- ret += traversal.traverse(body).getCode();
139506
+ ret.appendChunk(traversal.traverse(body));
138937
139507
  }
138938
- ret += "}";
139508
+ ret.appendString("}");
138939
139509
  }
138940
139510
  // unhandled in this TRY-CATCH, or a javascript runtime error
138941
- const unhandled = this.buildCleanupCode(cleanup, traversal) + `throw e;\n`;
138942
- ret += nodes.length > 0 ? ` else {\n` + unhandled + `}\n` : unhandled;
138943
- return new chunk_1.Chunk(ret);
139511
+ if (nodes.length > 0) {
139512
+ ret.appendString(` else {\n`);
139513
+ }
139514
+ this.appendCleanupCode(ret, cleanup, traversal);
139515
+ ret.appendString(`throw e;\n`);
139516
+ if (nodes.length > 0) {
139517
+ ret.appendString(`}\n`);
139518
+ }
139519
+ return ret;
138944
139520
  }
138945
139521
  /** CLEANUP runs when a class based exception leaves the TRY block, not for an exception raised
138946
139522
  * in a CATCH block of the same TRY, and not for javascript runtime errors */
138947
- buildCleanupCode(cleanup, traversal) {
139523
+ appendCleanupCode(ret, cleanup, traversal) {
138948
139524
  if (cleanup === undefined) {
138949
- return "";
139525
+ return;
138950
139526
  }
138951
139527
  const cxRoot = traversal.lookupClassOrInterface("CX_ROOT", cleanup.getFirstToken());
138952
- let ret = `if (${cxRoot} && e instanceof ${cxRoot}) {\n`;
138953
- const intoNode = cleanup.findDirectStatement(abaplint.Statements.Cleanup)?.findExpressionAfterToken("INTO");
139528
+ const cleanupStatement = cleanup.findDirectStatement(abaplint.Statements.Cleanup);
139529
+ const head = `if (${cxRoot} && e instanceof ${cxRoot}) {\n`;
139530
+ if (cleanupStatement) {
139531
+ ret.append(head, cleanupStatement, traversal);
139532
+ }
139533
+ else {
139534
+ ret.appendString(head);
139535
+ }
139536
+ const intoNode = cleanupStatement?.findExpressionAfterToken("INTO");
138954
139537
  if (intoNode) {
138955
- ret += traversal.traverse(intoNode).getCode() + ".set(e);\n";
139538
+ ret.appendChunk(traversal.traverse(intoNode)).appendString(".set(e);\n");
138956
139539
  }
138957
139540
  const body = cleanup.findDirectStructure(abaplint.Structures.Body);
138958
139541
  if (body) {
138959
- ret += traversal.traverse(body).getCode();
139542
+ ret.appendChunk(traversal.traverse(body));
138960
139543
  }
138961
- return ret + `}\n`;
139544
+ ret.appendString(`}\n`);
138962
139545
  }
138963
139546
  }
138964
139547
  exports.TryTranspiler = TryTranspiler;
@@ -139605,6 +140188,7 @@ const chunk_1 = __webpack_require__(/*! ./chunk */ "./node_modules/@abaplint/tra
139605
140188
  const expressions_1 = __webpack_require__(/*! ./expressions */ "./node_modules/@abaplint/transpiler/build/src/expressions/index.js");
139606
140189
  const keywords_1 = __webpack_require__(/*! ./keywords */ "./node_modules/@abaplint/transpiler/build/src/keywords.js");
139607
140190
  const transpile_types_1 = __webpack_require__(/*! ./transpile_types */ "./node_modules/@abaplint/transpiler/build/src/transpile_types.js");
140191
+ const inline_1 = __webpack_require__(/*! ./inline */ "./node_modules/@abaplint/transpiler/build/src/inline.js");
139608
140192
  /** the references of one scope, by where they start: built once per scope,
139609
140193
  * so finding the reference at a token no longer walks every reference of
139610
140194
  * the scope for every token, which made a long method quadratic */
@@ -139964,8 +140548,10 @@ class Traversal {
139964
140548
  }
139965
140549
  const methodDefinitions = def.getMethodDefinitions();
139966
140550
  if (methodDefinitions === undefined) {
139967
- // this can occur if the dependencies is not 702?
139968
- throw new Error("buildMethods: unexpected undefined, " + def.getName());
140551
+ // abaplint registers a definition before reading it, and stops reading at the first thing it cannot find
140552
+ const superClass = def.getSuperClass();
140553
+ const reason = superClass ? `its super class ${superClass} is not known` : "a super class, interface or type it names is not known";
140554
+ throw new Error(`${this.getFilename()}: the definition of ${def.getName()} could not be read: ${reason}`);
139969
140555
  }
139970
140556
  for (const m of methodDefinitions.getAll()) {
139971
140557
  methods.push(this.buildMethod(m.getName(), m, m.getVisibility()));
@@ -140716,7 +141302,12 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
140716
141302
  * and are initialized once, also when the block is a loop */
140717
141303
  traverseProcedureLevel(node) {
140718
141304
  const ret = new chunk_1.Chunk();
141305
+ // FORMs, methods and function modules declare their own inline declarations
141306
+ const programLevel = inline_1.InlineDeclarations.isProgramLevelScope(this.findCurrentScopeByToken(node.getFirstToken()));
140719
141307
  for (const c of node.getChildren()) {
141308
+ if (programLevel === true) {
141309
+ ret.appendString(inline_1.InlineDeclarations.buildDeclarations(c, this, true));
141310
+ }
140720
141311
  if (c instanceof abaplint.Nodes.StructureNode && Traversal.isDeclaration(c) === false) {
140721
141312
  ret.appendChunk(this.declareNestedEarly(c));
140722
141313
  this.blockDepth++;
@@ -140826,6 +141417,8 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
140826
141417
  continue;
140827
141418
  }
140828
141419
  for (const n of c.getChildren()) {
141420
+ // inline declarations are program global like DATA, so they stay on module level too
141421
+ ret.appendString(inline_1.InlineDeclarations.buildDeclarations(n, this, true));
140829
141422
  if (Traversal.isProgramLevelDeclaration(n)) {
140830
141423
  ret.appendChunk(this.traverse(n));
140831
141424
  }