@abaplint/transpiler-cli 2.14.37 → 2.14.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/bundle.js +1455 -355
  2. package/package.json +3 -3
package/build/bundle.js CHANGED
@@ -4526,7 +4526,7 @@ function dynComp(...inside) {
4526
4526
  return (0, combi_1.ver)(version_1.Release.v757, (0, combi_1.seq)((0, combi_1.tok)(tokens_1.Dash), dynIdent, dynInside, ...inside, dynClose));
4527
4527
  }
4528
4528
  function dynAttr() {
4529
- return (0, combi_1.ver)(version_1.Release.v757, (0, combi_1.seq)((0, combi_1.tok)(tokens_1.InstanceArrow), dynIdent, dynInside, dynClose));
4529
+ return (0, combi_1.ver)(version_1.Release.v756, (0, combi_1.seq)((0, combi_1.tok)(tokens_1.InstanceArrow), dynIdent, dynInside, dynClose));
4530
4530
  }
4531
4531
  //# sourceMappingURL=_dynamic_access.js.map
4532
4532
 
@@ -5588,10 +5588,14 @@ exports.CorrespondingBodyBase = CorrespondingBodyBase;
5588
5588
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5589
5589
  exports.CorrespondingBodyMapping = void 0;
5590
5590
  const combi_1 = __webpack_require__(/*! ../combi */ "./node_modules/@abaplint/core/build/src/abap/2_statements/combi.js");
5591
+ const tokens_1 = __webpack_require__(/*! ../../1_lexer/tokens */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/index.js");
5591
5592
  const _1 = __webpack_require__(/*! . */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js");
5592
5593
  class CorrespondingBodyMapping extends combi_1.Expression {
5593
5594
  getRunnable() {
5594
- const mapping = (0, combi_1.seq)("MAPPING", (0, combi_1.plus)((0, combi_1.seq)(_1.ComponentName, "=", _1.ComponentChain)));
5595
+ const single = (0, combi_1.seq)(_1.ComponentName, "=", _1.ComponentChain);
5596
+ // mapping rule for a sub structure or tabular component, with its own MAPPING and EXCEPT
5597
+ const nested = (0, combi_1.seq)((0, combi_1.tok)(tokens_1.WParenLeftW), single, (0, combi_1.optPrio)(CorrespondingBodyMapping), (0, combi_1.optPrio)((0, combi_1.seq)("EXCEPT", (0, combi_1.alt)((0, combi_1.plus)(_1.Field), "*"))), (0, combi_1.tok)(tokens_1.WParenRightW));
5598
+ const mapping = (0, combi_1.seq)("MAPPING", (0, combi_1.plus)((0, combi_1.alt)(single, nested)));
5595
5599
  return mapping;
5596
5600
  }
5597
5601
  }
@@ -30029,12 +30033,25 @@ exports.SuperConstructorCall = SuperConstructorCall;
30029
30033
  Object.defineProperty(exports, "__esModule", ({ value: true }));
30030
30034
  exports.CheckSyntaxKey = void 0;
30031
30035
  exports.syntaxIssue = syntaxIssue;
30036
+ exports.dataObjectBeforeStaticArrow = dataObjectBeforeStaticArrow;
30032
30037
  const issue_1 = __webpack_require__(/*! ../../issue */ "./node_modules/@abaplint/core/build/src/issue.js");
30033
30038
  const severity_1 = __webpack_require__(/*! ../../severity */ "./node_modules/@abaplint/core/build/src/severity.js");
30034
30039
  exports.CheckSyntaxKey = "check_syntax";
30035
30040
  function syntaxIssue(input, token, message, fix) {
30036
30041
  return issue_1.Issue.atTokenFilename(input.filename, token, message, exports.CheckSyntaxKey, severity_1.Severity.Error, fix);
30037
30042
  }
30043
+ /** the name in front of "=>" is looked up as a class or interface only, data objects are not considered.
30044
+ * Call when no class or interface of the name was found: if a data object of the name is visible,
30045
+ * it is not an unknown global class, so report it. Returns true if an issue was added */
30046
+ function dataObjectBeforeStaticArrow(input, token) {
30047
+ const name = token.getStr();
30048
+ if (input.scope.findVariable(name) === undefined) {
30049
+ return false;
30050
+ }
30051
+ const message = `"${name}" is not a class or interface, => cannot be used with a data object`;
30052
+ input.issues.push(syntaxIssue(input, token, message));
30053
+ return true;
30054
+ }
30038
30055
  //# sourceMappingURL=_syntax_input.js.map
30039
30056
 
30040
30057
  /***/ },
@@ -30547,11 +30564,17 @@ class TypeUtils {
30547
30564
  return false;
30548
30565
  }
30549
30566
  }
30550
- if (node && builtin === false && this.isFunctionalMethodResult(node)
30551
- && this.isFunctionalResultAssignable(source, target) === false) {
30567
+ const functionalResult = node !== undefined && builtin === false && this.isFunctionalMethodResult(node);
30568
+ if (functionalResult && this.isFunctionalResultAssignable(source, target) === false) {
30552
30569
  return false;
30553
30570
  }
30554
- if (calculated) {
30571
+ // a structure, table or reference returned by a functional method follows the same rule as a variable
30572
+ const strictResult = functionalResult && (source instanceof basic_1.StructureType
30573
+ || source instanceof basic_1.TableType
30574
+ || source instanceof basic_1.DataReference
30575
+ || source instanceof basic_1.ObjectReferenceType
30576
+ || source instanceof basic_1.GenericObjectReferenceType);
30577
+ if (calculated && strictResult === false) {
30555
30578
  return this.isAssignable(source, target);
30556
30579
  }
30557
30580
  // an elementary text field is not compatible with a structure, also not with a flat character-like one
@@ -30888,8 +30911,40 @@ class TypeUtils {
30888
30911
  else if (source instanceof basic_1.TableType && target instanceof basic_1.TableType) {
30889
30912
  return this.isAssignableStructureTyping(source.getRowType(), target.getRowType());
30890
30913
  }
30914
+ else if (source instanceof basic_1.CharacterType && target instanceof basic_1.StructureType) {
30915
+ // an elementary actual must be character-like, the formal structure purely character-like
30916
+ const length = this.characterLikeStructureLength(target);
30917
+ return length !== undefined && source.getLength() >= length;
30918
+ }
30891
30919
  return this.isAssignableStrict(source, target, node);
30892
30920
  }
30921
+ // returns the total length if the structure is flat and purely character-like, otherwise undefined
30922
+ characterLikeStructureLength(type) {
30923
+ let length = 0;
30924
+ for (const component of type.getComponents()) {
30925
+ const t = component.type;
30926
+ if (t instanceof basic_1.CharacterType || t instanceof basic_1.NumericType) {
30927
+ length += t.getLength();
30928
+ }
30929
+ else if (t instanceof basic_1.DateType) {
30930
+ length += 8;
30931
+ }
30932
+ else if (t instanceof basic_1.TimeType) {
30933
+ length += 6;
30934
+ }
30935
+ else if (t instanceof basic_1.StructureType) {
30936
+ const sub = this.characterLikeStructureLength(t);
30937
+ if (sub === undefined) {
30938
+ return undefined;
30939
+ }
30940
+ length += sub;
30941
+ }
30942
+ else {
30943
+ return undefined;
30944
+ }
30945
+ }
30946
+ return length;
30947
+ }
30893
30948
  isAssignable(source, target) {
30894
30949
  if (source === undefined || target === undefined) {
30895
30950
  return true;
@@ -34794,7 +34849,7 @@ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modu
34794
34849
  const version_1 = __webpack_require__(/*! ../../../version */ "./node_modules/@abaplint/core/build/src/version.js");
34795
34850
  class FieldChain {
34796
34851
  static runSyntax(node, input, refType, allowGenericDeference = false) {
34797
- var _a, _b, _c;
34852
+ var _a, _b, _c, _d;
34798
34853
  if (((_a = node.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.SourceField
34799
34854
  && node.findDirectExpression(Expressions.ComponentName)) {
34800
34855
  // workaround for names with dashes, eg. "sy-repid"
@@ -34865,7 +34920,11 @@ class FieldChain {
34865
34920
  if (afterTableExpression && table_expression_1.TableExpression.checkArrowAfter(input, current.getFirstToken())) {
34866
34921
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
34867
34922
  }
34868
- if (!(context instanceof basic_1.ObjectReferenceType)
34923
+ if (context instanceof basic_1.GenericObjectReferenceType && ((_d = children[i + 1]) === null || _d === void 0 ? void 0 : _d.get()) instanceof tokens_1.ParenLeft) {
34924
+ // dynamic attribute, oref->(name), the attribute is resolved at runtime
34925
+ context = basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
34926
+ }
34927
+ else if (!(context instanceof basic_1.ObjectReferenceType)
34869
34928
  && !(context instanceof basic_1.DataReference)
34870
34929
  && !(context instanceof basic_1.VoidType)) {
34871
34930
  const message = "Not an object reference, field chain";
@@ -34949,6 +35008,9 @@ class FieldChain {
34949
35008
  input.scope.addReference(classTok, found.id, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
34950
35009
  return new basic_1.ObjectReferenceType(found.id);
34951
35010
  }
35011
+ else if ((0, _syntax_input_1.dataObjectBeforeStaticArrow)(input, classTok)) {
35012
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
35013
+ }
34952
35014
  else if (input.scope.getDDIC().inErrorNamespace(classNam) === false) {
34953
35015
  input.scope.addReference(classTok, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, { ooName: classNam.toUpperCase() });
34954
35016
  return basic_1.VoidType.get(classNam);
@@ -35320,7 +35382,7 @@ const assert_error_1 = __webpack_require__(/*! ../assert_error */ "./node_module
35320
35382
  const tokens_1 = __webpack_require__(/*! ../../1_lexer/tokens */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/index.js");
35321
35383
  class FormParam {
35322
35384
  static runSyntax(node, input) {
35323
- var _a, _b, _c;
35385
+ var _a, _b, _c, _d;
35324
35386
  const formParamName = node.findFirstExpression(expressions_1.FormParamName);
35325
35387
  if (formParamName === undefined) {
35326
35388
  throw new assert_error_1.AssertError("FormParam, could not find FormParamName");
@@ -35335,6 +35397,14 @@ class FormParam {
35335
35397
  let type;
35336
35398
  if (typeName) {
35337
35399
  type = (_b = input.scope.findType(typeName)) === null || _b === void 0 ? void 0 : _b.getType();
35400
+ if (type === undefined) {
35401
+ // STRUCTURE can also refer to a program-local data object
35402
+ type = (_c = input.scope.findVariable(typeName)) === null || _c === void 0 ? void 0 : _c.getType();
35403
+ if (type instanceof basic_1.TableType && type.isWithHeader()) {
35404
+ // a table with header line refers to its header line
35405
+ type = type.getRowType();
35406
+ }
35407
+ }
35338
35408
  if (type === undefined) {
35339
35409
  type = input.scope.getDDIC().lookupTableOrView(typeName).type;
35340
35410
  }
@@ -35349,7 +35419,7 @@ class FormParam {
35349
35419
  return new _typed_identifier_1.TypedIdentifier(nameToken, input.filename, basic_1.AnyType.get(), ["form_parameter" /* IdentifierMeta.FormParameter */]);
35350
35420
  }
35351
35421
  let bfound = new basic_types_1.BasicTypes(input).parseType(node);
35352
- const typeName = (_c = node.findFirstExpression(expressions_1.TypeName)) === null || _c === void 0 ? void 0 : _c.concatTokens().toUpperCase();
35422
+ const typeName = (_d = node.findFirstExpression(expressions_1.TypeName)) === null || _d === void 0 ? void 0 : _d.concatTokens().toUpperCase();
35353
35423
  const hasExplicitLength = node.findFirstExpression(expressions_1.Length) !== undefined
35354
35424
  || node.findFirstExpression(expressions_1.ConstantFieldLength) !== undefined;
35355
35425
  // the length cannot be specified for FORM parameters, so these types are generic
@@ -36598,7 +36668,10 @@ class MethodCallChain {
36598
36668
  const token = first.getFirstToken();
36599
36669
  const className = token.getStr();
36600
36670
  const classDefinition = input.scope.findObjectDefinition(className);
36601
- if (classDefinition === undefined && input.scope.getDDIC().inErrorNamespace(className) === false) {
36671
+ if (classDefinition === undefined && (0, _syntax_input_1.dataObjectBeforeStaticArrow)(input, token)) {
36672
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
36673
+ }
36674
+ else if (classDefinition === undefined && input.scope.getDDIC().inErrorNamespace(className) === false) {
36602
36675
  const extra = { ooName: className, ooType: "Void" };
36603
36676
  input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, extra);
36604
36677
  return basic_1.VoidType.get(className);
@@ -37509,7 +37582,10 @@ class MethodSource {
37509
37582
  const token = first.getFirstToken();
37510
37583
  const className = token.getStr();
37511
37584
  const classDefinition = input.scope.findObjectDefinition(className);
37512
- if (classDefinition === undefined && input.scope.getDDIC().inErrorNamespace(className) === false) {
37585
+ if (classDefinition === undefined && (0, _syntax_input_1.dataObjectBeforeStaticArrow)(input, token)) {
37586
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
37587
+ }
37588
+ else if (classDefinition === undefined && input.scope.getDDIC().inErrorNamespace(className) === false) {
37513
37589
  const extra = { ooName: className, ooType: "Void" };
37514
37590
  input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, extra);
37515
37591
  return basic_1.VoidType.get(className);
@@ -38889,6 +38965,7 @@ class Source {
38889
38965
  {
38890
38966
  const foundType = this.determineType(node, input, targetType);
38891
38967
  if ((foundType === null || foundType === void 0 ? void 0 : foundType.isGeneric()) === true
38968
+ && !(foundType instanceof basic_1.DataType)
38892
38969
  && ((_b = node.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _b === void 0 ? void 0 : _b.concatTokens()) === "#"
38893
38970
  && !(0, version_1.releaseAtLeast)(input.scope.getRelease(), version_1.Release.v756)
38894
38971
  && input.scope.getLanguageVersion() !== version_1.LanguageVersion.Cloud
@@ -40328,6 +40405,7 @@ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modu
40328
40405
  const version_1 = __webpack_require__(/*! ../../../version */ "./node_modules/@abaplint/core/build/src/version.js");
40329
40406
  class Target {
40330
40407
  static runSyntax(node, input) {
40408
+ var _a;
40331
40409
  const concat = node.concatTokens();
40332
40410
  if (concat.includes("-")) {
40333
40411
  // workaround for names with dashes
@@ -40378,7 +40456,11 @@ class Target {
40378
40456
  if (afterTableExpression && table_expression_1.TableExpression.checkArrowAfter(input, current.getFirstToken())) {
40379
40457
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
40380
40458
  }
40381
- if (!(context instanceof basic_1.ObjectReferenceType)
40459
+ if (context instanceof basic_1.GenericObjectReferenceType && ((_a = children[currentIndex]) === null || _a === void 0 ? void 0 : _a.get()) instanceof tokens_1.ParenLeft) {
40460
+ // dynamic attribute, oref->(name), the attribute is resolved at runtime
40461
+ context = basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
40462
+ }
40463
+ else if (!(context instanceof basic_1.ObjectReferenceType)
40382
40464
  && !(context instanceof basic_1.DataReference)
40383
40465
  && !(context instanceof basic_1.VoidType)) {
40384
40466
  const message = "Not an object reference, target";
@@ -40497,6 +40579,9 @@ class Target {
40497
40579
  input.scope.addReference(token, found, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
40498
40580
  return new basic_1.ObjectReferenceType(found);
40499
40581
  }
40582
+ else if ((0, _syntax_input_1.dataObjectBeforeStaticArrow)(input, token)) {
40583
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
40584
+ }
40500
40585
  else if (input.scope.getDDIC().inErrorNamespace(name) === false) {
40501
40586
  input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, { ooName: name, ooType: "CLAS" });
40502
40587
  return basic_1.VoidType.get(name);
@@ -41660,6 +41745,7 @@ var __importStar = (this && this.__importStar) || (function () {
41660
41745
  Object.defineProperty(exports, "__esModule", ({ value: true }));
41661
41746
  exports.Append = void 0;
41662
41747
  const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
41748
+ const nodes_1 = __webpack_require__(/*! ../../nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
41663
41749
  const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
41664
41750
  const target_1 = __webpack_require__(/*! ../expressions/target */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/target.js");
41665
41751
  const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
@@ -41730,9 +41816,17 @@ class Append {
41730
41816
  let sourceType = source_1.Source.runSyntax(source, input, rowType);
41731
41817
  if (node.findDirectTokenByText("LINES")) {
41732
41818
  // hmm, checking only the row types are compatible will not check the table type, e.g. sorted or hashed
41819
+ // a generically typed dref->* is checked at runtime, except FROM idx1 TO idx2, which expect an index table
41820
+ const genericLines = sourceType instanceof basic_1.DataType
41821
+ && source.concatTokens().replace(/\s/g, "").endsWith("->*")
41822
+ && node.findDirectTokenByText("FROM") === undefined
41823
+ && node.getChildren().filter(c => c instanceof nodes_1.TokenNode && c.getFirstToken().getStr().toUpperCase() === "TO").length === 1;
41733
41824
  if (sourceType instanceof basic_1.TableType) {
41734
41825
  sourceType = sourceType.getRowType();
41735
41826
  }
41827
+ else if (genericLines) {
41828
+ sourceType = basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
41829
+ }
41736
41830
  else if (!(sourceType instanceof basic_1.VoidType) && !(sourceType instanceof basic_1.UnknownType)) {
41737
41831
  const message = "LINES OF must be a table type";
41738
41832
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
@@ -44580,8 +44674,12 @@ class DeleteInternal {
44580
44674
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
44581
44675
  return;
44582
44676
  }
44583
- if (targetType instanceof basic_1.TableType && targetType.isWithHeader() === false) {
44677
+ if (targetType instanceof basic_1.TableType
44678
+ && targetType.isWithHeader() === false
44679
+ && targetType.isGeneric() === false
44680
+ && this.isBodyOfTableWithHeader(target, input) === false) {
44584
44681
  // short forms, "DELETE itab." deletes the current line inside a LOOP, otherwise both use the header line
44682
+ // generically typed tables are not checked statically
44585
44683
  const children = node.getChildren().length;
44586
44684
  const short = children === 3 && input.inLoop !== true;
44587
44685
  const shortTable = children === 4 && node.findDirectTokenByText("TABLE") !== undefined;
@@ -44603,6 +44701,16 @@ class DeleteInternal {
44603
44701
  component_cond_1.ComponentCond.runSyntax(t, input, targetType);
44604
44702
  }
44605
44703
  }
44704
+ // "DELETE itab[]." where itab has a header line, eg. a FORM TABLES parameter
44705
+ isBodyOfTableWithHeader(target, input) {
44706
+ var _a;
44707
+ const children = target.getChildren();
44708
+ if (children.length !== 2 || !(children[1].get() instanceof Expressions.TableBody)) {
44709
+ return false;
44710
+ }
44711
+ const type = (_a = input.scope.findVariable(children[0].concatTokens())) === null || _a === void 0 ? void 0 : _a.getType();
44712
+ return type instanceof basic_1.TableType && type.isWithHeader();
44713
+ }
44606
44714
  }
44607
44715
  exports.DeleteInternal = DeleteInternal;
44608
44716
  //# sourceMappingURL=delete_internal.js.map
@@ -44781,14 +44889,16 @@ class Describe {
44781
44889
  for (const s of node.findDirectExpressions(Expressions.FieldChain)) {
44782
44890
  field_chain_1.FieldChain.runSyntax(s, input, _reference_1.ReferenceType.DataReadReference);
44783
44891
  }
44784
- const linesTarget = node.findExpressionAfterToken("LINES");
44785
- if ((linesTarget === null || linesTarget === void 0 ? void 0 : linesTarget.get()) instanceof Expressions.Target) {
44786
- const inline = linesTarget === null || linesTarget === void 0 ? void 0 : linesTarget.findDirectExpression(Expressions.InlineData);
44787
- if (inline) {
44788
- inline_data_1.InlineData.runSyntax(inline, input, basic_1.IntegerType.get());
44789
- }
44790
- else {
44791
- target_1.Target.runSyntax(linesTarget, input);
44892
+ for (const addition of ["LINES", "KIND", "OCCURS"]) {
44893
+ const target = node.findExpressionAfterToken(addition);
44894
+ if ((target === null || target === void 0 ? void 0 : target.get()) instanceof Expressions.Target) {
44895
+ const inline = target.findDirectExpression(Expressions.InlineData);
44896
+ if (inline) {
44897
+ inline_data_1.InlineData.runSyntax(inline, input, addition === "KIND" ? new basic_1.CharacterType(1) : basic_1.IntegerType.get());
44898
+ }
44899
+ else {
44900
+ target_1.Target.runSyntax(target, input);
44901
+ }
44792
44902
  }
44793
44903
  }
44794
44904
  const typeTarget = node.findExpressionAfterToken("TYPE");
@@ -46854,16 +46964,21 @@ const _type_utils_1 = __webpack_require__(/*! ../_type_utils */ "./node_modules/
46854
46964
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
46855
46965
  class InsertInternal {
46856
46966
  runSyntax(node, input) {
46857
- var _a, _b;
46967
+ var _a, _b, _c;
46858
46968
  let targetType;
46859
46969
  const t = node.findDirectExpression(Expressions.Target);
46860
46970
  if (t) {
46861
46971
  targetType = target_1.Target.runSyntax(t, input);
46862
46972
  }
46973
+ // a generically typed dref->* is checked at runtime, except where an index table is expected
46974
+ const genericByKey = targetType instanceof basic_1.DataType
46975
+ && ((_a = t === null || t === void 0 ? void 0 : t.getLastChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Dereference
46976
+ && node.findDirectTokenByText("TABLE") !== undefined;
46863
46977
  if (!(targetType instanceof basic_1.TableType)
46864
46978
  && !(targetType instanceof basic_1.VoidType)
46865
46979
  && !(targetType instanceof basic_1.AnyType)
46866
46980
  && !(targetType instanceof basic_1.UnknownType)
46981
+ && genericByKey === false
46867
46982
  && targetType !== undefined) {
46868
46983
  const message = "INSERT target must be a table";
46869
46984
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
@@ -46918,7 +47033,7 @@ class InsertInternal {
46918
47033
  error = true;
46919
47034
  }
46920
47035
  else if ((sourceType instanceof basic_1.StringType || sourceType instanceof basic_1.CharacterType)
46921
- && ((_a = sourceType.getAbstractTypeData()) === null || _a === void 0 ? void 0 : _a.derivedFromConstant) !== true
47036
+ && ((_b = sourceType.getAbstractTypeData()) === null || _b === void 0 ? void 0 : _b.derivedFromConstant) !== true
46922
47037
  && (source === null || source === void 0 ? void 0 : source.findDirectExpression(Expressions.Constant)) === undefined
46923
47038
  && (targetType instanceof basic_1.IntegerType
46924
47039
  || targetType instanceof basic_1.Integer8Type
@@ -46931,7 +47046,7 @@ class InsertInternal {
46931
47046
  }
46932
47047
  else if (sourceType instanceof basic_1.CharacterType
46933
47048
  && targetType instanceof basic_1.CharacterType
46934
- && ((_b = sourceType.getAbstractTypeData()) === null || _b === void 0 ? void 0 : _b.derivedFromConstant) === true
47049
+ && ((_c = sourceType.getAbstractTypeData()) === null || _c === void 0 ? void 0 : _c.derivedFromConstant) === true
46935
47050
  && sourceType.getLength() !== targetType.getLength()) {
46936
47051
  // character literal of different length than the row type
46937
47052
  error = true;
@@ -52399,6 +52514,7 @@ const field_chain_1 = __webpack_require__(/*! ../expressions/field_chain */ "./n
52399
52514
  const _reference_1 = __webpack_require__(/*! ../_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
52400
52515
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
52401
52516
  const _builtin_call_1 = __webpack_require__(/*! ../_builtin_call */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_builtin_call.js");
52517
+ const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
52402
52518
  class Write {
52403
52519
  runSyntax(node, input) {
52404
52520
  // todo, more
@@ -52418,7 +52534,9 @@ class Write {
52418
52534
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message));
52419
52535
  return;
52420
52536
  }
52537
+ // a utclong is written as a time stamp, although it is not character-like elsewhere
52421
52538
  if (s === second
52539
+ && !(type instanceof basic_1.UTCLongType)
52422
52540
  && new _type_utils_1.TypeUtils(input.scope).isCharLike(type) === false
52423
52541
  && new _type_utils_1.TypeUtils(input.scope).isHexLike(type) === false) {
52424
52542
  const message = "Source not character like";
@@ -69685,6 +69803,10 @@ const domain_1 = __webpack_require__(/*! ./domain */ "./node_modules/@abaplint/c
69685
69803
  const _identifier_1 = __webpack_require__(/*! ../abap/4_file_information/_identifier */ "./node_modules/@abaplint/core/build/src/abap/4_file_information/_identifier.js");
69686
69804
  const identifier_1 = __webpack_require__(/*! ../abap/1_lexer/tokens/identifier */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/identifier.js");
69687
69805
  const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
69806
+ function toNumber(value) {
69807
+ const parsed = parseInt(value !== null && value !== void 0 ? value : "", 10);
69808
+ return isNaN(parsed) ? undefined : parsed;
69809
+ }
69688
69810
  class DataElement extends _abstract_object_1.AbstractObject {
69689
69811
  constructor() {
69690
69812
  super(...arguments);
@@ -69734,10 +69856,33 @@ class DataElement extends _abstract_object_1.AbstractObject {
69734
69856
  if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
69735
69857
  return this.parsedXML.datatype;
69736
69858
  }
69737
- if (reg && ((_b = this.parsedXML) === null || _b === void 0 ? void 0 : _b.refkind) === "D" && this.parsedXML.domname) {
69859
+ return (_b = this.findDomain(reg)) === null || _b === void 0 ? void 0 : _b.getDataType();
69860
+ }
69861
+ /** DDIC length, eg. number of digits for DEC, which parseType() cannot give.
69862
+ * Taken from the same place as getDataType(), ie. the data element or its domain. */
69863
+ getLength(reg) {
69864
+ var _a, _b;
69865
+ this.parse();
69866
+ if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
69867
+ return toNumber(this.parsedXML.leng);
69868
+ }
69869
+ return (_b = this.findDomain(reg)) === null || _b === void 0 ? void 0 : _b.getLength();
69870
+ }
69871
+ /** DDIC decimals, taken from the same place as getDataType(), ie. the data element or its domain. */
69872
+ getDecimals(reg) {
69873
+ var _a, _b;
69874
+ this.parse();
69875
+ if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
69876
+ return toNumber(this.parsedXML.decimals);
69877
+ }
69878
+ return (_b = this.findDomain(reg)) === null || _b === void 0 ? void 0 : _b.getDecimals();
69879
+ }
69880
+ findDomain(reg) {
69881
+ var _a;
69882
+ if (reg && ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.refkind) === "D" && this.parsedXML.domname) {
69738
69883
  const domain = reg.getObject("DOMA", this.parsedXML.domname);
69739
69884
  if (domain instanceof domain_1.Domain) {
69740
- return domain.getDataType();
69885
+ return domain;
69741
69886
  }
69742
69887
  }
69743
69888
  return undefined;
@@ -70073,6 +70218,10 @@ const xml_utils_1 = __webpack_require__(/*! ../xml_utils */ "./node_modules/@aba
70073
70218
  const _identifier_1 = __webpack_require__(/*! ../abap/4_file_information/_identifier */ "./node_modules/@abaplint/core/build/src/abap/4_file_information/_identifier.js");
70074
70219
  const identifier_1 = __webpack_require__(/*! ../abap/1_lexer/tokens/identifier */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/identifier.js");
70075
70220
  const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
70221
+ function toNumber(value) {
70222
+ const parsed = parseInt(value !== null && value !== void 0 ? value : "", 10);
70223
+ return isNaN(parsed) ? undefined : parsed;
70224
+ }
70076
70225
  class Domain extends _abstract_object_1.AbstractObject {
70077
70226
  getType() {
70078
70227
  return "DOMA";
@@ -70092,6 +70241,16 @@ class Domain extends _abstract_object_1.AbstractObject {
70092
70241
  this.parse();
70093
70242
  return (_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype;
70094
70243
  }
70244
+ getLength() {
70245
+ var _a;
70246
+ this.parse();
70247
+ return toNumber((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.length);
70248
+ }
70249
+ getDecimals() {
70250
+ var _a;
70251
+ this.parse();
70252
+ return toNumber((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.decimals);
70253
+ }
70095
70254
  getAllowedNaming() {
70096
70255
  return {
70097
70256
  maxLength: 30,
@@ -76757,7 +76916,7 @@ class Registry {
76757
76916
  }
76758
76917
  static abaplintVersion() {
76759
76918
  // magic, see build script "version.js"
76760
- return "2.120.116";
76919
+ return "2.120.119";
76761
76920
  }
76762
76921
  getDDICReferences() {
76763
76922
  return this.ddicReferences;
@@ -80591,8 +80750,7 @@ If BEGIN OF has an INCLUDE TYPE its ignored
80591
80750
  Also note that clean ABAP does not recommend aligning TYPE clauses:
80592
80751
  https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-align-type-clauses`,
80593
80752
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix],
80594
- badExample: `
80595
- TYPES: BEGIN OF foo,
80753
+ badExample: `TYPES: BEGIN OF foo,
80596
80754
  bar TYPE i,
80597
80755
  foobar TYPE i,
80598
80756
  END OF foo.
@@ -80603,8 +80761,7 @@ INTERFACE lif.
80603
80761
  foo TYPE i
80604
80762
  foobar TYPE i.
80605
80763
  ENDINTERFACE.`,
80606
- goodExample: `
80607
- TYPES: BEGIN OF foo,
80764
+ goodExample: `TYPES: BEGIN OF foo,
80608
80765
  bar TYPE i,
80609
80766
  foobar TYPE i,
80610
80767
  END OF foo.
@@ -93357,12 +93514,10 @@ class EmptyEvent extends _abap_rule_1.ABAPRule {
93357
93514
  shortDescription: `Empty selection screen or list processing event block`,
93358
93515
  extendedInformation: ``,
93359
93516
  tags: [_irule_1.RuleTag.SingleFile],
93360
- badExample: `
93361
- INITIALIZATION.
93517
+ badExample: `INITIALIZATION.
93362
93518
  WRITE 'hello'.
93363
93519
  END-OF-SELECTION.`,
93364
- goodExample: `
93365
- START-OF-SELECTION.
93520
+ goodExample: `START-OF-SELECTION.
93366
93521
  PERFORM sdf.
93367
93522
  COMMIT WORK.`,
93368
93523
  };
@@ -101477,18 +101632,14 @@ class ManyParentheses extends _abap_rule_1.ABAPRule {
101477
101632
  title: "Too many parentheses",
101478
101633
  shortDescription: `Searches for expressions where extra parentheses can safely be removed`,
101479
101634
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
101480
- badExample: `
101481
- IF ( destination IS INITIAL ).
101635
+ badExample: `IF ( destination IS INITIAL ).
101482
101636
  ENDIF.
101483
101637
  IF foo = boo AND ( bar = lar AND moo = loo ).
101484
- ENDIF.
101485
- `,
101486
- goodExample: `
101487
- IF destination IS INITIAL.
101638
+ ENDIF.`,
101639
+ goodExample: `IF destination IS INITIAL.
101488
101640
  ENDIF.
101489
101641
  IF foo = boo AND bar = lar AND moo = loo.
101490
- ENDIF.
101491
- `,
101642
+ ENDIF.`,
101492
101643
  };
101493
101644
  }
101494
101645
  getConfig() {
@@ -101713,12 +101864,10 @@ class MaxOneMethodParameterPerLine extends _abap_rule_1.ABAPRule {
101713
101864
  title: "Max one method parameter definition per line",
101714
101865
  shortDescription: `Keep max one method parameter description per line`,
101715
101866
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix],
101716
- badExample: `
101717
- METHODS apps_scope_token
101867
+ badExample: `METHODS apps_scope_token
101718
101868
  IMPORTING
101719
101869
  body TYPE bodyapps_scope_token client_id TYPE str.`,
101720
- goodExample: `
101721
- METHODS apps_scope_token
101870
+ goodExample: `METHODS apps_scope_token
101722
101871
  IMPORTING
101723
101872
  body TYPE bodyapps_scope_token
101724
101873
  client_id TYPE str.`,
@@ -106047,21 +106196,19 @@ class OmitReceiving extends _abap_rule_1.ABAPRule {
106047
106196
  shortDescription: `Omit RECEIVING`,
106048
106197
  extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#omit-receiving`,
106049
106198
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
106050
- badExample: `
106051
- upload_pack(
106052
- EXPORTING
106053
- io_client = lo_client
106054
- iv_url = iv_url
106055
- iv_deepen_level = iv_deepen_level
106056
- it_hashes = lt_hashes
106057
- RECEIVING
106058
- rt_objects = et_objects ).`,
106059
- goodExample: `
106060
- et_objects = upload_pack(
106061
- io_client = lo_client
106062
- iv_url = iv_url
106063
- iv_deepen_level = iv_deepen_level
106064
- it_hashes = lt_hashes ).`,
106199
+ badExample: `upload_pack(
106200
+ EXPORTING
106201
+ io_client = lo_client
106202
+ iv_url = iv_url
106203
+ iv_deepen_level = iv_deepen_level
106204
+ it_hashes = lt_hashes
106205
+ RECEIVING
106206
+ rt_objects = et_objects ).`,
106207
+ goodExample: `et_objects = upload_pack(
106208
+ io_client = lo_client
106209
+ iv_url = iv_url
106210
+ iv_deepen_level = iv_deepen_level
106211
+ it_hashes = lt_hashes ).`,
106065
106212
  };
106066
106213
  }
106067
106214
  getConfig() {
@@ -106902,7 +107049,7 @@ class PreferAbapBoolValues extends _abap_rule_1.ABAPRule {
106902
107049
  title: "Prefer abap_true and abap_false",
106903
107050
  shortDescription: `Use abap_true and abap_false instead of 'X' and ' ' for abap_bool variables`,
106904
107051
  // eslint-disable-next-line max-len
106905
- extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-abap_true-abap_false-and-abap_undefined-for-abap_bool-variables`,
107052
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#use-abap_true-and-abap_false-for-comparisons`,
106906
107053
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
106907
107054
  badExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = 'X'.`,
106908
107055
  goodExample: `DATA lv_flag TYPE abap_bool.\nlv_flag = abap_true.`,
@@ -115536,12 +115683,21 @@ ENDWHILE.`,
115536
115683
  }
115537
115684
  const reads = this.reads(procedure, move.source);
115538
115685
  if (reads === undefined
115539
- || reads.locals.some(l => l.writes().some(w => w.index > from && w.index < to))
115686
+ || reads.locals.some(l => this.changedIn(procedure, l, from, to))
115540
115687
  || reads.others.some(o => this.writtenIn(procedure, o, from, to))) {
115541
115688
  return false;
115542
115689
  }
115543
115690
  return reads.others.length === 0 || this.mayChangeOtherData(procedure, from, to, reads.receivers) === false;
115544
115691
  }
115692
+ /** written in the loop body, or declared inline in it: the inline declaration is not one of the writes(),
115693
+ * but sets the variable in every iteration, possibly from data the loop changes */
115694
+ changedIn(procedure, local, from, to) {
115695
+ if (local.writes().some(w => w.index > from && w.index < to)) {
115696
+ return true;
115697
+ }
115698
+ const index = local.inline && local.declaration !== undefined ? procedure.index(local.declaration) : -1;
115699
+ return index > from && index < to;
115700
+ }
115545
115701
  writtenIn(procedure, identifier, from, to) {
115546
115702
  for (const reference of procedure.analysis.referencesTo(identifier)) {
115547
115703
  if (reference.referenceType !== _reference_1.ReferenceType.DataWriteReference || !procedure.contains(reference.position)) {
@@ -118573,14 +118729,22 @@ var __importStar = (this && this.__importStar) || (function () {
118573
118729
  Object.defineProperty(exports, "__esModule", ({ value: true }));
118574
118730
  exports.UnsecureFAE = exports.UnsecureFAEConf = void 0;
118575
118731
  const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
118732
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/index.js"));
118733
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "./node_modules/@abaplint/core/build/src/abap/3_structures/structures/index.js"));
118576
118734
  const issue_1 = __webpack_require__(/*! ../issue */ "./node_modules/@abaplint/core/build/src/issue.js");
118577
118735
  const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "./node_modules/@abaplint/core/build/src/rules/_basic_rule_config.js");
118578
118736
  const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/core/build/src/rules/_irule.js");
118579
118737
  const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
118580
118738
  const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/syntax.js");
118739
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
118740
+ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_scope_type.js");
118581
118741
  class UnsecureFAEConf extends _basic_rule_config_1.BasicRuleConfig {
118582
118742
  }
118583
118743
  exports.UnsecureFAEConf = UnsecureFAEConf;
118744
+ const PROCEDURES = [Structures.Method, Structures.Form, Structures.FunctionModule];
118745
+ const LOOPS = [Structures.Loop, Structures.Do, Structures.While, Structures.Select, Structures.LoopAtScreen];
118746
+ const CALLS = [Statements.Call, Statements.CallFunction, Statements.Perform, Statements.Submit,
118747
+ Statements.RaiseEvent, Statements.CallTransaction];
118584
118748
  class UnsecureFAE {
118585
118749
  constructor() {
118586
118750
  this.conf = new UnsecureFAEConf();
@@ -118590,8 +118754,24 @@ class UnsecureFAE {
118590
118754
  key: "unsecure_fae",
118591
118755
  title: "Unsecure FAE",
118592
118756
  shortDescription: `Checks for unsecure FAE`,
118593
- extendedInformation: `Issues from rule check_syntax must be fixed before this rule takes effect`,
118757
+ extendedInformation: `Issues from rule check_syntax must be fixed before this rule takes effect
118758
+
118759
+ The driver table of FOR ALL ENTRIES is considered checked, and no issue is reported, if
118760
+ * the SELECT is in the IF or ELSEIF branch of a condition "itab IS NOT INITIAL", "NOT itab IS INITIAL"
118761
+ or "lines( itab ) > 0", also combined with AND, or
118762
+ * "IF itab IS INITIAL. RETURN. ENDIF." or "CHECK itab IS NOT INITIAL." precedes the SELECT in the same method,
118763
+ form or function module, at the same or an outer block level, not inside a loop,
118764
+
118765
+ and the driver table is not changed between the check and the SELECT, or in a loop around the SELECT inside the
118766
+ checked region. If the driver table is not a local variable or parameter, a method, function or form call in
118767
+ between also invalidates the check.`,
118594
118768
  tags: [_irule_1.RuleTag.Experimental, _irule_1.RuleTag.Performance],
118769
+ badExample: `SELECT * FROM t000 FOR ALL ENTRIES IN @lt_list
118770
+ WHERE mandt = @lt_list-table_line INTO TABLE @DATA(lt_t000).`,
118771
+ goodExample: `IF lt_list IS NOT INITIAL.
118772
+ SELECT * FROM t000 FOR ALL ENTRIES IN @lt_list
118773
+ WHERE mandt = @lt_list-table_line INTO TABLE @DATA(lt_t000).
118774
+ ENDIF.`,
118595
118775
  };
118596
118776
  }
118597
118777
  getConfig() {
@@ -118605,7 +118785,6 @@ class UnsecureFAE {
118605
118785
  this.conf = conf;
118606
118786
  }
118607
118787
  run(obj) {
118608
- var _a;
118609
118788
  const issues = [];
118610
118789
  if (!(obj instanceof _abap_object_1.ABAPObject)) {
118611
118790
  return issues;
@@ -118615,15 +118794,193 @@ class UnsecureFAE {
118615
118794
  return issues;
118616
118795
  }
118617
118796
  for (const f of obj.getABAPFiles()) {
118618
- // todo
118619
- for (const e of ((_a = f.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllExpressions(Expressions.SQLForAllEntries)) || []) {
118620
- const token = e.getFirstToken();
118621
- const message = "Unsecure FAE";
118622
- issues.push(issue_1.Issue.atToken(f, token, message, this.getMetadata().key, this.getConfig().severity));
118797
+ const structure = f.getStructure();
118798
+ if (structure === undefined) {
118799
+ continue;
118800
+ }
118801
+ for (const statement of structure.findAllStatementNodes()) {
118802
+ for (const e of statement.findAllExpressions(Expressions.SQLForAllEntries)) {
118803
+ if (this.isChecked(f, structure, statement, e, syntaxResult.spaghetti)) {
118804
+ continue;
118805
+ }
118806
+ const token = e.getFirstToken();
118807
+ const message = "Unsecure FAE";
118808
+ issues.push(issue_1.Issue.atToken(f, token, message, this.getMetadata().key, this.getConfig().severity));
118809
+ }
118623
118810
  }
118624
118811
  }
118625
118812
  return issues;
118626
118813
  }
118814
+ ////////////////
118815
+ isChecked(file, root, statement, fae, spaghetti) {
118816
+ var _a;
118817
+ const source = fae.findDirectExpression(Expressions.SQLSource);
118818
+ const name = source === null || source === void 0 ? void 0 : source.concatTokens().replace(/^@/, "").replace(/\s/g, "").toUpperCase();
118819
+ if (name === undefined || /^[\w/<>~]+((->|=>)[\w/~]+)?$/.test(name) === false) {
118820
+ return false;
118821
+ }
118822
+ const path = this.findPath(root, statement, []);
118823
+ if (path === undefined) {
118824
+ return false;
118825
+ }
118826
+ const local = this.isLocal(file, name, statement.getStart(), spaghetti);
118827
+ for (let i = path.length - 1; i >= 0; i--) {
118828
+ const node = path[i];
118829
+ const type = node.get();
118830
+ if (PROCEDURES.some(p => type instanceof p)) {
118831
+ break;
118832
+ }
118833
+ const child = (_a = path[i + 1]) !== null && _a !== void 0 ? _a : statement;
118834
+ const inner = path.slice(i + 1);
118835
+ // IF itab IS NOT INITIAL. SELECT ... ENDIF.
118836
+ if ((type instanceof Structures.If || type instanceof Structures.ElseIf) && child.get() instanceof Structures.Body) {
118837
+ const header = node.findDirectStatement(type instanceof Structures.If ? Statements.If : Statements.ElseIf);
118838
+ const cond = header === null || header === void 0 ? void 0 : header.findDirectExpression(Expressions.Cond);
118839
+ if (header && cond && this.notInitial(cond, name)
118840
+ && this.unchanged(file, inner, statement, header.getEnd(), name, local)) {
118841
+ return true;
118842
+ }
118843
+ }
118844
+ // IF itab IS INITIAL. RETURN. ENDIF. or CHECK itab IS NOT INITIAL. before the SELECT
118845
+ const outer = path.slice(0, i + 1);
118846
+ if (type instanceof Structures.Body
118847
+ && outer.some(n => PROCEDURES.some(p => n.get() instanceof p))
118848
+ && outer.some(n => LOOPS.some(l => n.get() instanceof l)) === false) {
118849
+ for (const sibling of node.getChildren()) {
118850
+ if (sibling === child) {
118851
+ break;
118852
+ }
118853
+ const content = sibling instanceof nodes_1.StructureNode && sibling.get() instanceof Structures.Normal
118854
+ ? sibling.getFirstChild() : sibling;
118855
+ if ((content instanceof nodes_1.StructureNode || content instanceof nodes_1.StatementNode)
118856
+ && this.leavesIfInitial(content, name)
118857
+ && this.unchanged(file, inner, statement, sibling.getLastToken().getEnd(), name, local)) {
118858
+ return true;
118859
+ }
118860
+ }
118861
+ }
118862
+ }
118863
+ return false;
118864
+ }
118865
+ findPath(node, target, path) {
118866
+ for (const child of node.getChildren()) {
118867
+ if (child === target) {
118868
+ return [...path, node];
118869
+ }
118870
+ else if (child instanceof nodes_1.StructureNode) {
118871
+ const found = this.findPath(child, target, [...path, node]);
118872
+ if (found) {
118873
+ return found;
118874
+ }
118875
+ }
118876
+ }
118877
+ return undefined;
118878
+ }
118879
+ /** local variable or parameter of the procedure, calls cannot change it */
118880
+ isLocal(file, name, position, spaghetti) {
118881
+ if (name.includes("->") || name.includes("=>") || name.startsWith("<")) {
118882
+ return false;
118883
+ }
118884
+ let scope = spaghetti.lookupPosition(position, file.getFilename());
118885
+ while ((scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype) === _scope_type_1.ScopeType.OpenSQL) {
118886
+ scope = scope.getParent();
118887
+ }
118888
+ const stype = scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype;
118889
+ if (stype !== _scope_type_1.ScopeType.Method && stype !== _scope_type_1.ScopeType.Form && stype !== _scope_type_1.ScopeType.FunctionModule) {
118890
+ return false;
118891
+ }
118892
+ return (scope === null || scope === void 0 ? void 0 : scope.getData().vars[name]) !== undefined;
118893
+ }
118894
+ /** "itab IS NOT INITIAL" or "lines( itab ) > 0", possibly combined with AND */
118895
+ notInitial(cond, name) {
118896
+ const children = cond.getChildren();
118897
+ if (children.some(c => ["OR", "EQUIV"].includes(c.concatTokens().toUpperCase()))) {
118898
+ return false;
118899
+ }
118900
+ for (const child of children) {
118901
+ if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Compare) {
118902
+ const text = this.normalize(child);
118903
+ if ([`${name} IS NOT INITIAL`, `NOT ${name} IS INITIAL`,
118904
+ `LINES( ${name} ) > 0`, `LINES( ${name} ) GT 0`, `LINES( ${name} ) <> 0`, `LINES( ${name} ) NE 0`,
118905
+ `LINES( ${name} ) >= 1`, `LINES( ${name} ) GE 1`].includes(text)) {
118906
+ return true;
118907
+ }
118908
+ }
118909
+ else if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.CondSub
118910
+ && child.getFirstToken().getStr().toUpperCase() !== "NOT") {
118911
+ const sub = child.findDirectExpression(Expressions.Cond);
118912
+ if (sub && this.notInitial(sub, name)) {
118913
+ return true;
118914
+ }
118915
+ }
118916
+ }
118917
+ return false;
118918
+ }
118919
+ /** "itab IS INITIAL" or "lines( itab ) = 0", possibly combined with OR */
118920
+ initial(cond, name) {
118921
+ const children = cond.getChildren();
118922
+ if (children.some(c => ["AND", "EQUIV"].includes(c.concatTokens().toUpperCase()))) {
118923
+ return false;
118924
+ }
118925
+ return children.some(c => c instanceof nodes_1.ExpressionNode && c.get() instanceof Expressions.Compare
118926
+ && [`${name} IS INITIAL`, `NOT ${name} IS NOT INITIAL`,
118927
+ `LINES( ${name} ) = 0`, `LINES( ${name} ) EQ 0`, `LINES( ${name} ) < 1`, `LINES( ${name} ) LT 1`]
118928
+ .includes(this.normalize(c)));
118929
+ }
118930
+ /** "IF itab IS INITIAL. RETURN. ENDIF." or "CHECK itab IS NOT INITIAL." */
118931
+ leavesIfInitial(node, name) {
118932
+ var _a, _b;
118933
+ var _c;
118934
+ if (node instanceof nodes_1.StatementNode) {
118935
+ const cond = node.get() instanceof Statements.Check ? node.findDirectExpression(Expressions.Cond) : undefined;
118936
+ return cond !== undefined && this.notInitial(cond, name);
118937
+ }
118938
+ if (!(node.get() instanceof Structures.If)
118939
+ || node.findDirectStructure(Structures.Else) !== undefined
118940
+ || node.findDirectStructure(Structures.ElseIf) !== undefined) {
118941
+ return false;
118942
+ }
118943
+ const statements = (_c = (_a = node.findDirectStructure(Structures.Body)) === null || _a === void 0 ? void 0 : _a.findAllStatementNodes()) !== null && _c !== void 0 ? _c : [];
118944
+ if (statements.length !== 1 || !(statements[0].get() instanceof Statements.Return)) {
118945
+ return false;
118946
+ }
118947
+ const cond = (_b = node.findDirectStatement(Statements.If)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.Cond);
118948
+ return cond !== undefined && this.initial(cond, name);
118949
+ }
118950
+ normalize(node) {
118951
+ return node.concatTokens().toUpperCase().replace(/\s+/g, " ");
118952
+ }
118953
+ /** the driver table is not changed after the check and before the SELECT, nor in a loop around the SELECT
118954
+ * inside the checked region */
118955
+ unchanged(file, inner, statement, from, name, local) {
118956
+ const loop = inner.find(n => LOOPS.some(l => n.get() instanceof l));
118957
+ const to = loop === undefined ? statement.getStart() : loop.getLastToken().getEnd();
118958
+ for (const s of file.getStatements()) {
118959
+ if (s === statement || !s.getStart().isAfter(from) || !s.getStart().isBefore(to)) {
118960
+ continue;
118961
+ }
118962
+ if (this.writes(s, name) || (local === false && this.calls(s))) {
118963
+ return false;
118964
+ }
118965
+ }
118966
+ return true;
118967
+ }
118968
+ writes(statement, name) {
118969
+ for (const target of [...statement.findAllExpressions(Expressions.Target),
118970
+ ...statement.findAllExpressions(Expressions.FSTarget)]) {
118971
+ const text = target.concatTokens().replace(/\s/g, "").toUpperCase();
118972
+ if (text === name || (text.startsWith(name) && /^[^\w/]/.test(text.substring(name.length)))) {
118973
+ return true;
118974
+ }
118975
+ }
118976
+ return false;
118977
+ }
118978
+ calls(statement) {
118979
+ const type = statement.get();
118980
+ return CALLS.some(c => type instanceof c)
118981
+ || statement.findFirstExpression(Expressions.MethodCall) !== undefined
118982
+ || statement.findFirstExpression(Expressions.MethodSource) !== undefined;
118983
+ }
118627
118984
  }
118628
118985
  exports.UnsecureFAE = UnsecureFAE;
118629
118986
  //# sourceMappingURL=unsecure_fae.js.map
@@ -122740,6 +123097,440 @@ function unescape(str) {
122740
123097
 
122741
123098
  /***/ },
122742
123099
 
123100
+ /***/ "./node_modules/@abaplint/transpiler/build/src/cds_metadata.js"
123101
+ /*!*********************************************************************!*\
123102
+ !*** ./node_modules/@abaplint/transpiler/build/src/cds_metadata.js ***!
123103
+ \*********************************************************************/
123104
+ (__unused_webpack_module, exports, __webpack_require__) {
123105
+
123106
+ "use strict";
123107
+
123108
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
123109
+ if (k2 === undefined) k2 = k;
123110
+ var desc = Object.getOwnPropertyDescriptor(m, k);
123111
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
123112
+ desc = { enumerable: true, get: function() { return m[k]; } };
123113
+ }
123114
+ Object.defineProperty(o, k2, desc);
123115
+ }) : (function(o, m, k, k2) {
123116
+ if (k2 === undefined) k2 = k;
123117
+ o[k2] = m[k];
123118
+ }));
123119
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
123120
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
123121
+ }) : function(o, v) {
123122
+ o["default"] = v;
123123
+ });
123124
+ var __importStar = (this && this.__importStar) || (function () {
123125
+ var ownKeys = function(o) {
123126
+ ownKeys = Object.getOwnPropertyNames || function (o) {
123127
+ var ar = [];
123128
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
123129
+ return ar;
123130
+ };
123131
+ return ownKeys(o);
123132
+ };
123133
+ return function (mod) {
123134
+ if (mod && mod.__esModule) return mod;
123135
+ var result = {};
123136
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
123137
+ __setModuleDefault(result, mod);
123138
+ return result;
123139
+ };
123140
+ })();
123141
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
123142
+ exports.CDSMetadata = void 0;
123143
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
123144
+ const cds = abaplint.ExpressionsCDS;
123145
+ /** The metadata of a CDS entity, as far as it is written in its own source: its annotations, its
123146
+ * elements and its associations. Associations a projection or a view exposes from its source are
123147
+ * taken from that source's metadata. Metadata extensions (DDLX) are not merged. */
123148
+ class CDSMetadata {
123149
+ reg;
123150
+ cache = new Map();
123151
+ constructor(reg) {
123152
+ this.reg = reg;
123153
+ }
123154
+ build(obj) {
123155
+ const key = obj.getName().toUpperCase();
123156
+ if (this.cache.has(key)) {
123157
+ return this.cache.get(key);
123158
+ }
123159
+ this.cache.set(key, undefined); // cycle guard, associations can point back
123160
+ const tree = obj.getTree() ?? (obj.parse(), obj.getTree());
123161
+ const result = tree === undefined ? undefined : this.definition(tree);
123162
+ this.cache.set(key, result);
123163
+ return result;
123164
+ }
123165
+ definition(root) {
123166
+ const result = {
123167
+ definitionType: this.definitionType(root),
123168
+ root: root.findDirectTokenByText("ROOT") !== undefined,
123169
+ annotations: [],
123170
+ fields: [],
123171
+ associations: [],
123172
+ };
123173
+ for (const child of root.getChildren()) {
123174
+ if (child.get() instanceof cds.CDSAnnotation) {
123175
+ result.annotations.push(CDSMetadata.annotation(child));
123176
+ }
123177
+ else {
123178
+ break;
123179
+ }
123180
+ }
123181
+ const def = root.get();
123182
+ if (def instanceof cds.CDSDefineView || def instanceof cds.CDSDefineProjection) {
123183
+ const select = def instanceof cds.CDSDefineView ? root.findFirstExpression(cds.CDSSelect) : root;
123184
+ if (select !== undefined) {
123185
+ for (const a of select.findDirectExpressions(cds.CDSAssociation)) {
123186
+ result.associations.push(this.association(a, "ASSOCIATION"));
123187
+ }
123188
+ for (const c of select.findDirectExpressions(cds.CDSComposition)) {
123189
+ result.associations.push(this.association(c, "COMPOSITION"));
123190
+ }
123191
+ for (const e of select.findDirectExpressions(cds.CDSElement)) {
123192
+ this.element(e, result, this.sources(root));
123193
+ }
123194
+ }
123195
+ }
123196
+ else {
123197
+ this.signature(root, result);
123198
+ }
123199
+ return result;
123200
+ }
123201
+ definitionType(root) {
123202
+ const def = root.get();
123203
+ if (def instanceof cds.CDSDefineView) {
123204
+ return root.findDirectTokenByText("ENTITY") ? "VIEW_ENTITY" : "VIEW";
123205
+ }
123206
+ else if (def instanceof cds.CDSDefineProjection) {
123207
+ return "PROJECTION_VIEW";
123208
+ }
123209
+ else if (def instanceof cds.CDSDefineAbstract) {
123210
+ return "ABSTRACT_ENTITY";
123211
+ }
123212
+ else if (def instanceof cds.CDSDefineCustom) {
123213
+ return "CUSTOM_ENTITY";
123214
+ }
123215
+ else if (def instanceof cds.CDSDefineTableFunction) {
123216
+ return "TABLE_FUNCTION";
123217
+ }
123218
+ else if (def instanceof cds.CDSDefineHierarchy) {
123219
+ return "HIERARCHY";
123220
+ }
123221
+ else if (def instanceof cds.CDSDefineTableEntity) {
123222
+ return "TABLE_ENTITY";
123223
+ }
123224
+ else if (def instanceof cds.CDSDefineExternalEntity) {
123225
+ return "EXTERNAL_ENTITY";
123226
+ }
123227
+ return def.constructor.name;
123228
+ }
123229
+ /** The entities selected or projected from, for the associations they expose */
123230
+ sources(root) {
123231
+ const ret = [];
123232
+ if (root.get() instanceof cds.CDSDefineProjection) {
123233
+ // the first name is the projection's own, the second the projected entity
123234
+ const name = root.findDirectExpressions(cds.CDSName)[1];
123235
+ if (name) {
123236
+ ret.push(name.concatTokens().toUpperCase());
123237
+ }
123238
+ }
123239
+ for (const s of root.findAllExpressions(cds.CDSSource)) {
123240
+ const name = s.findDirectExpression(cds.CDSPrefixedName) ?? s.getFirstChild();
123241
+ if (name) {
123242
+ ret.push(name.concatTokens().replace(/ /g, "").toUpperCase());
123243
+ }
123244
+ }
123245
+ return ret;
123246
+ }
123247
+ sourceAssociation(sources, name) {
123248
+ for (const source of sources) {
123249
+ const obj = this.reg.getObject("DDLS", source);
123250
+ const found = obj ? this.build(obj)?.associations.find(a => a.name.toUpperCase() === name.toUpperCase()) : undefined;
123251
+ if (found) {
123252
+ return found;
123253
+ }
123254
+ }
123255
+ return undefined;
123256
+ }
123257
+ element(e, result, sources) {
123258
+ const annotations = e.findDirectExpressions(cds.CDSAnnotation).map(a => CDSMetadata.annotation(a));
123259
+ const prefixed = e.findDirectExpression(cds.CDSPrefixedName);
123260
+ const path = prefixed?.findAllExpressions(cds.CDSName).map(n => n.concatTokens()) ?? [];
123261
+ const as = e.findDirectExpressions(cds.CDSAs).map(a => this.alias(a)).find(a => a !== undefined);
123262
+ const redirected = this.redirection(e) ?? e.findDirectExpressions(cds.CDSAs).map(a => this.redirection(a)).find(r => r);
123263
+ let name = as;
123264
+ if (name === undefined && path.length > 0) {
123265
+ name = redirected ? path[0] : path[path.length - 1];
123266
+ }
123267
+ if (name === undefined && e.findDirectTokenByText("VIRTUAL")) {
123268
+ name = e.findFirstExpression(cds.CDSName)?.concatTokens();
123269
+ }
123270
+ if (name === undefined) {
123271
+ return;
123272
+ }
123273
+ // an exposed association, declared here or in a source
123274
+ const exposes = path.length > 0 ? path[path.length - 1] : name;
123275
+ const declared = path.length === 1
123276
+ ? result.associations.find(a => a.name.toUpperCase() === exposes.toUpperCase()) : undefined;
123277
+ if (declared) {
123278
+ declared.exposed = true;
123279
+ declared.annotations.push(...annotations);
123280
+ if (redirected) {
123281
+ declared.target = redirected.target;
123282
+ }
123283
+ return;
123284
+ }
123285
+ const inherited = redirected !== undefined || path.length > 0 ? this.sourceAssociation(sources, exposes) : undefined;
123286
+ if (inherited || redirected) {
123287
+ result.associations.push({
123288
+ name: name,
123289
+ target: redirected?.target ?? inherited.target,
123290
+ type: redirected?.type ?? inherited.type,
123291
+ cardinality: inherited?.cardinality,
123292
+ condition: inherited?.condition,
123293
+ defaultFilter: inherited?.defaultFilter,
123294
+ exposed: true,
123295
+ annotations: annotations,
123296
+ });
123297
+ return;
123298
+ }
123299
+ result.fields.push({
123300
+ name: name,
123301
+ key: e.findDirectTokenByText("KEY") !== undefined,
123302
+ virtual: e.findDirectTokenByText("VIRTUAL") !== undefined,
123303
+ annotations: annotations,
123304
+ });
123305
+ }
123306
+ alias(as) {
123307
+ const ret = [];
123308
+ for (const c of as.getChildren().slice(1)) {
123309
+ if (c.concatTokens().startsWith(":")) {
123310
+ break;
123311
+ }
123312
+ ret.push(c.concatTokens());
123313
+ }
123314
+ return ret.length > 0 ? ret.join("") : undefined;
123315
+ }
123316
+ /** ": REDIRECTED TO [PARENT | COMPOSITION CHILD] target", in an element or its alias */
123317
+ redirection(node) {
123318
+ const children = node.getChildren();
123319
+ const to = children.findIndex(c => c instanceof abaplint.Nodes.TokenNode && c.getFirstToken().getStr().toUpperCase() === "TO"
123320
+ && children.some(r => r instanceof abaplint.Nodes.TokenNode && r.getFirstToken().getStr().toUpperCase() === "REDIRECTED"));
123321
+ if (to < 0) {
123322
+ return undefined;
123323
+ }
123324
+ const rest = children.slice(to + 1).map(c => c.concatTokens().toUpperCase());
123325
+ const target = children.slice(to + 1).find(c => c.get() instanceof cds.CDSName)?.concatTokens();
123326
+ if (target === undefined) {
123327
+ return undefined;
123328
+ }
123329
+ let type = "ASSOCIATION";
123330
+ if (rest.includes("PARENT")) {
123331
+ type = "TO_PARENT";
123332
+ }
123333
+ else if (rest.includes("CHILD")) {
123334
+ type = "COMPOSITION";
123335
+ }
123336
+ return { target, type };
123337
+ }
123338
+ /** abstract and custom entities and table functions list their elements inline: name : type ; */
123339
+ signature(root, result) {
123340
+ let inBody = false;
123341
+ let annotations = [];
123342
+ let key = false;
123343
+ let name;
123344
+ let assoc;
123345
+ for (const child of root.getChildren()) {
123346
+ const text = child instanceof abaplint.Nodes.TokenNode ? child.getFirstToken().getStr().toUpperCase() : "";
123347
+ if (inBody === false) {
123348
+ inBody = text === "{";
123349
+ continue;
123350
+ }
123351
+ if (child.get() instanceof cds.CDSAnnotation) {
123352
+ annotations.push(CDSMetadata.annotation(child));
123353
+ }
123354
+ else if (text === "KEY") {
123355
+ key = true;
123356
+ }
123357
+ else if (child.get() instanceof cds.CDSName && name === undefined) {
123358
+ name = child.concatTokens();
123359
+ }
123360
+ else if (child.get() instanceof cds.CDSAssociation || child.get() instanceof cds.CDSComposition) {
123361
+ assoc = child;
123362
+ }
123363
+ else if (text === ";" || text === "}") {
123364
+ if (name !== undefined && assoc !== undefined) {
123365
+ const a = this.association(assoc, assoc.get() instanceof cds.CDSComposition ? "COMPOSITION" : "ASSOCIATION");
123366
+ a.name = name;
123367
+ a.exposed = true;
123368
+ a.annotations = annotations;
123369
+ result.associations.push(a);
123370
+ }
123371
+ else if (name !== undefined) {
123372
+ result.fields.push({ name, key, virtual: false, annotations });
123373
+ }
123374
+ annotations = [];
123375
+ key = false;
123376
+ name = undefined;
123377
+ assoc = undefined;
123378
+ if (text === "}") {
123379
+ return;
123380
+ }
123381
+ }
123382
+ }
123383
+ }
123384
+ association(node, type) {
123385
+ const relation = node.findDirectExpression(cds.CDSRelation);
123386
+ const skip = new Set();
123387
+ relation?.findDirectExpressions(cds.CDSAs).forEach(a => skip.add(a));
123388
+ relation?.findDirectExpressions(cds.CDSParametersSelect).forEach(a => skip.add(a));
123389
+ const target = relation?.getChildren().filter(c => !skip.has(c)).map(c => c.concatTokens().replace(/ /g, "")).join("") || "";
123390
+ const as = relation?.findDirectExpression(cds.CDSAs);
123391
+ const conditions = node.findDirectExpressions(cds.CDSCondition);
123392
+ // the words before the target: ASSOCIATION [0..1] TO, ASSOCIATION OF MANY TO ONE, COMPOSITION OF ONE TO MANY, ...
123393
+ const words = [];
123394
+ for (const c of node.getChildren()) {
123395
+ if (c === relation) {
123396
+ break;
123397
+ }
123398
+ words.push(...c.concatTokens().toUpperCase().split(/\s+|(?=\[|\]|\.\.)|(?<=\[|\]|\.\.)/).filter(w => w !== ""));
123399
+ }
123400
+ if (words.includes("PARENT")) {
123401
+ type = "TO_PARENT";
123402
+ }
123403
+ return {
123404
+ name: (as ? this.alias(as) : undefined) ?? target,
123405
+ target: target,
123406
+ type: type,
123407
+ cardinality: this.cardinality(words, type),
123408
+ condition: conditions[0] ? CDSMetadata.text(conditions[0]) : undefined,
123409
+ defaultFilter: conditions[1] ? CDSMetadata.text(conditions[1]) : undefined,
123410
+ exposed: false,
123411
+ annotations: [],
123412
+ };
123413
+ }
123414
+ cardinality(words, type) {
123415
+ if (type === "TO_PARENT") {
123416
+ return { min: 1, max: 1 };
123417
+ }
123418
+ const open = words.indexOf("[");
123419
+ if (open >= 0) {
123420
+ const inside = words.slice(open + 1, words.indexOf("]")).join("").split("..");
123421
+ const num = (s) => s === "*" ? "*" : parseInt(s, 10);
123422
+ // [n] is [0..n]
123423
+ return inside.length === 1 ? { min: 0, max: num(inside[0]) } : { min: num(inside[0]), max: num(inside[1]) };
123424
+ }
123425
+ // the target side is the last one: TO ONE, OF MANY TO ONE, OF EXACT ONE, ONE TO MANY TO
123426
+ const sides = words.filter(w => w !== "ASSOCIATION" && w !== "COMPOSITION" && w !== "OF")
123427
+ .join(" ").split("TO").map(s => s.trim()).filter(s => s !== "");
123428
+ const side = sides[sides.length - 1];
123429
+ if (side === "EXACT ONE") {
123430
+ return { min: 1, max: 1 };
123431
+ }
123432
+ else if (side === "ONE") {
123433
+ return { min: 0, max: 1 };
123434
+ }
123435
+ else if (side === "MANY") {
123436
+ return { min: 0, max: "*" };
123437
+ }
123438
+ return type === "COMPOSITION" ? { min: 0, max: "*" } : { min: 0, max: 1 };
123439
+ }
123440
+ ///////////////////////////////
123441
+ /** the source text, tokens separated by single spaces except around path dots: $projection.id = _Item.id */
123442
+ static text(node) {
123443
+ let ret = "";
123444
+ let previous = "";
123445
+ for (const token of node.getTokens().map(t => t.getStr())) {
123446
+ ret += (ret === "" || token === "." || previous === "." ? "" : " ") + token;
123447
+ previous = token;
123448
+ }
123449
+ return ret;
123450
+ }
123451
+ static annotation(node) {
123452
+ const children = node.getChildren();
123453
+ const colon = children.findIndex(c => c instanceof abaplint.Nodes.TokenNode && c.getFirstToken().getStr() === ":");
123454
+ const nameParts = (colon < 0 ? children : children.slice(0, colon)).map(c => c.concatTokens());
123455
+ const name = nameParts.join("").replace(/\s/g, "").replace(/^@<?/, "");
123456
+ const valueNode = colon < 0 ? undefined : children[colon + 1];
123457
+ // an annotation without a value is true
123458
+ const value = valueNode instanceof abaplint.Nodes.ExpressionNode ? CDSMetadata.value(valueNode) : true;
123459
+ return { name, value };
123460
+ }
123461
+ static value(node) {
123462
+ const type = node.get();
123463
+ if (type instanceof cds.CDSAnnotationArray) {
123464
+ return node.getChildren()
123465
+ .filter((c) => c instanceof abaplint.Nodes.ExpressionNode)
123466
+ .map(c => CDSMetadata.value(c));
123467
+ }
123468
+ else if (type instanceof cds.CDSAnnotationObject) {
123469
+ const record = {};
123470
+ let path = [];
123471
+ let assigned = false;
123472
+ for (const c of node.getChildren()) {
123473
+ if (c.get() instanceof cds.CDSName) {
123474
+ path.push(c.concatTokens());
123475
+ }
123476
+ else if (c instanceof abaplint.Nodes.ExpressionNode) {
123477
+ CDSMetadata.set(record, path, CDSMetadata.value(c));
123478
+ assigned = true;
123479
+ }
123480
+ else {
123481
+ const text = c.getFirstToken().getStr();
123482
+ if ((text === "," || text === "}") && path.length > 0) {
123483
+ if (assigned === false) {
123484
+ CDSMetadata.set(record, path, true);
123485
+ }
123486
+ path = [];
123487
+ assigned = false;
123488
+ }
123489
+ }
123490
+ }
123491
+ return record;
123492
+ }
123493
+ return CDSMetadata.simple(node);
123494
+ }
123495
+ static simple(node) {
123496
+ const tokens = node.getTokens().map(t => t.getStr());
123497
+ const first = tokens[0] ?? "";
123498
+ if (first.startsWith("'")) {
123499
+ return first.substring(1, first.length - 1).replace(/''/g, "'");
123500
+ }
123501
+ else if (first === "#" && tokens[1] === "(") {
123502
+ return { "#()": tokens.slice(2, tokens.length - 1).join(" ") };
123503
+ }
123504
+ else if (first.startsWith("#")) {
123505
+ return { "#": first.substring(1) };
123506
+ }
123507
+ const lower = tokens.join("").toLowerCase();
123508
+ if (lower === "true" || lower === "false") {
123509
+ return lower === "true";
123510
+ }
123511
+ else if (lower === "null") {
123512
+ return null;
123513
+ }
123514
+ const num = Number(tokens.join(""));
123515
+ return isNaN(num) ? tokens.join("") : num;
123516
+ }
123517
+ static set(record, path, value) {
123518
+ let current = record;
123519
+ for (const part of path.slice(0, path.length - 1)) {
123520
+ const next = current[part];
123521
+ if (typeof next !== "object" || next === null || Array.isArray(next)) {
123522
+ current[part] = {};
123523
+ }
123524
+ current = current[part];
123525
+ }
123526
+ current[path[path.length - 1]] = value;
123527
+ }
123528
+ }
123529
+ exports.CDSMetadata = CDSMetadata;
123530
+ //# sourceMappingURL=cds_metadata.js.map
123531
+
123532
+ /***/ },
123533
+
122743
123534
  /***/ "./node_modules/@abaplint/transpiler/build/src/chunk.js"
122744
123535
  /*!**************************************************************!*\
122745
123536
  !*** ./node_modules/@abaplint/transpiler/build/src/chunk.js ***!
@@ -123165,14 +123956,21 @@ class CDSDatabaseView {
123165
123956
  for (const join of select.findDirectExpressions(cds.CDSJoin)) {
123166
123957
  from.push(this.join(join));
123167
123958
  }
123168
- const elements = select.findDirectExpressions(cds.CDSElement);
123959
+ // associations are not columns, neither are virtual elements
123960
+ const associations = this.associationNames(select);
123961
+ const elements = select.findDirectExpressions(cds.CDSElement).filter(e => {
123962
+ const path = e.findDirectExpression(cds.CDSPrefixedName)?.findAllExpressions(cds.CDSName) || [];
123963
+ const last = path[path.length - 1]?.concatTokens().toUpperCase();
123964
+ return e.findDirectTokenByText("VIRTUAL") === undefined && (last === undefined || !associations.has(last));
123965
+ });
123169
123966
  if (elements.length === 0) {
123170
123967
  return this.unsupported("expected explicit projected fields");
123171
123968
  }
123172
123969
  const columns = elements.map(e => this.element(e)).join(", ");
123173
123970
  let where = "";
123174
123971
  for (const child of select.getChildren()) {
123175
- if (child === source || child.get() instanceof cds.CDSJoin || child.get() instanceof cds.CDSElement) {
123972
+ if (child === source || child.get() instanceof cds.CDSJoin || child.get() instanceof cds.CDSElement
123973
+ || child.get() instanceof cds.CDSAssociation || child.get() instanceof cds.CDSComposition) {
123176
123974
  continue;
123177
123975
  }
123178
123976
  else if (child.get() instanceof cds.CDSWhere) {
@@ -123185,6 +123983,26 @@ class CDSDatabaseView {
123185
123983
  const distinct = select.findDirectTokenByText("DISTINCT") ? "DISTINCT " : "";
123186
123984
  return `CREATE VIEW ${this.quote(this.viewName)} AS SELECT ${distinct}${columns} FROM ${from.join(" ")}${where};`;
123187
123985
  }
123986
+ /** Aliases of the associations declared here or in the CDS sources, they can be exposed as elements */
123987
+ associationNames(select) {
123988
+ const ret = new Set();
123989
+ for (const a of [...select.findDirectExpressions(cds.CDSAssociation), ...select.findDirectExpressions(cds.CDSComposition)]) {
123990
+ const relation = a.findDirectExpression(cds.CDSRelation);
123991
+ const name = relation?.findDirectExpression(cds.CDSAs)?.findDirectExpression(cds.CDSName) || relation?.getFirstChild();
123992
+ if (name) {
123993
+ ret.add(name.concatTokens().toUpperCase());
123994
+ }
123995
+ }
123996
+ for (const s of select.findAllExpressions(cds.CDSSource)) {
123997
+ const name = s.findDirectExpression(cds.CDSPrefixedName)?.concatTokens().replace(/ /g, "");
123998
+ const ddls = name ? this.reg.getObject("DDLS", name) : undefined;
123999
+ ddls?.parse();
124000
+ for (const a of ddls?.getParsedData()?.associations || []) {
124001
+ ret.add((a.as || a.name).toUpperCase());
124002
+ }
124003
+ }
124004
+ return ret;
124005
+ }
123188
124006
  source(node) {
123189
124007
  const nameNode = node.findDirectExpression(cds.CDSPrefixedName);
123190
124008
  if (nameNode === undefined) {
@@ -125531,14 +126349,83 @@ const type_name_or_infer_1 = __webpack_require__(/*! ./type_name_or_infer */ "./
125531
126349
  const component_chain_1 = __webpack_require__(/*! ./component_chain */ "./node_modules/@abaplint/transpiler/build/src/expressions/component_chain.js");
125532
126350
  const unique_identifier_1 = __webpack_require__(/*! ../unique_identifier */ "./node_modules/@abaplint/transpiler/build/src/unique_identifier.js");
125533
126351
  class CorrespondingBodyTranspiler {
125534
- transpile(typ, body, traversal) {
126352
+ /** genericTarget: code of the target the result is assigned to, used when the inferred type is generic,
126353
+ * the result then gets the runtime type of the target, eg. "ct = CORRESPONDING #( ... )" with
126354
+ * "CHANGING ct TYPE STANDARD TABLE" */
126355
+ transpile(typ, body, traversal, genericTarget) {
125535
126356
  if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
125536
126357
  throw new Error("CorrespondingBodyTranspiler, Expected TypeNameOrInfer");
125537
126358
  }
125538
126359
  const type = new type_name_or_infer_1.TypeNameOrInfer().findType(typ, traversal);
126360
+ if (genericTarget !== undefined && type.isGeneric() === true) {
126361
+ return this.transpileGeneric(body, traversal, genericTarget);
126362
+ }
126363
+ const { source, base, mapping } = this.parseBody(body, traversal);
125539
126364
  let target = traversal.toType(type);
125540
- let source;
126365
+ if (base !== undefined) {
126366
+ target = `abap.statements.moveCorresponding(${base.getCode()}, ${target})`;
126367
+ }
125541
126368
  const isTableType = type instanceof core_1.BasicTypes.TableType;
126369
+ const ret = new chunk_1.Chunk();
126370
+ const id = unique_identifier_1.UniqueIdentifier.get();
126371
+ const sourceId = unique_identifier_1.UniqueIdentifier.get();
126372
+ ret.appendString("(await (async () => {\n");
126373
+ ret.appendString(`const ${id} = ${target};\n`);
126374
+ ret.appendString(`const ${sourceId} = ${source.getCode()};\n`);
126375
+ if (isTableType) {
126376
+ const rowTargetType = traversal.toType(type.getRowType());
126377
+ const sourceRowId = unique_identifier_1.UniqueIdentifier.get();
126378
+ const targetRowId = unique_identifier_1.UniqueIdentifier.get();
126379
+ ret.appendString(`for (const ${sourceRowId} of ${sourceId}.array()) {\n`);
126380
+ ret.appendString(`const ${targetRowId} = ${rowTargetType};\n`);
126381
+ ret.appendString(`abap.statements.moveCorresponding(${sourceRowId}, ${targetRowId});\n`);
126382
+ ret.appendString(this.mappingCode(mapping, targetRowId, sourceRowId, traversal));
126383
+ ret.appendString(`abap.statements.insertInternal({table: ${id}, data: ${targetRowId}});\n`);
126384
+ ret.appendString("}\n");
126385
+ }
126386
+ else {
126387
+ ret.appendString(`abap.statements.moveCorresponding(${sourceId}, ${id});\n`);
126388
+ ret.appendString(this.mappingCode(mapping, id, sourceId, traversal));
126389
+ }
126390
+ ret.appendString("return " + id + ";\n");
126391
+ ret.appendString("})())");
126392
+ return ret;
126393
+ }
126394
+ /** the type is only known at runtime, it is taken from the target, a table or a structure */
126395
+ transpileGeneric(body, traversal, genericTarget) {
126396
+ const { source, base, mapping } = this.parseBody(body, traversal);
126397
+ const ret = new chunk_1.Chunk();
126398
+ const id = unique_identifier_1.UniqueIdentifier.get();
126399
+ const sourceId = unique_identifier_1.UniqueIdentifier.get();
126400
+ const sourceRowId = unique_identifier_1.UniqueIdentifier.get();
126401
+ const targetRowId = unique_identifier_1.UniqueIdentifier.get();
126402
+ ret.appendString("(await (async () => {\n");
126403
+ const pointer = `(${genericTarget} instanceof abap.types.FieldSymbol ? ${genericTarget}.getPointer() : ${genericTarget})`;
126404
+ ret.appendString(`const ${id} = ${pointer}.clone();\n`);
126405
+ ret.appendString(`${id}.clear();\n`);
126406
+ if (base !== undefined) {
126407
+ ret.appendString(`${id}.set(${base.getCode()});\n`);
126408
+ }
126409
+ ret.appendString(`const ${sourceId} = ${source.getCode()};\n`);
126410
+ ret.appendString(`if (${id} instanceof abap.types.Table || ${id} instanceof abap.types.HashedTable) {\n`);
126411
+ ret.appendString(`for (const ${sourceRowId} of ${sourceId}.array()) {\n`);
126412
+ ret.appendString(`const ${targetRowId} = ${id}.getRowType().clone();\n`);
126413
+ ret.appendString(`${targetRowId}.clear();\n`);
126414
+ ret.appendString(`abap.statements.moveCorresponding(${sourceRowId}, ${targetRowId});\n`);
126415
+ ret.appendString(this.mappingCode(mapping, targetRowId, sourceRowId, traversal));
126416
+ ret.appendString(`abap.statements.insertInternal({table: ${id}, data: ${targetRowId}});\n`);
126417
+ ret.appendString("}\n");
126418
+ ret.appendString("} else {\n");
126419
+ ret.appendString(`abap.statements.moveCorresponding(${sourceId}, ${id});\n`);
126420
+ ret.appendString(this.mappingCode(mapping, id, sourceId, traversal));
126421
+ ret.appendString("}\n");
126422
+ ret.appendString("return " + id + ";\n");
126423
+ ret.appendString("})())");
126424
+ return ret;
126425
+ }
126426
+ parseBody(body, traversal) {
126427
+ let source;
126428
+ let base;
125542
126429
  const mapping = [];
125543
126430
  for (const child of body.getChildren()) {
125544
126431
  const c = child.get();
@@ -125546,8 +126433,7 @@ class CorrespondingBodyTranspiler {
125546
126433
  source = traversal.traverse(child);
125547
126434
  }
125548
126435
  else if (c instanceof core_1.Expressions.CorrespondingBodyBase && child instanceof core_1.Nodes.ExpressionNode) {
125549
- source = traversal.traverse(child?.findDirectExpression(core_1.Expressions.Source));
125550
- target = `abap.statements.moveCorresponding(${source.getCode()}, ${target})`;
126436
+ base = traversal.traverse(child.findDirectExpression(core_1.Expressions.Source));
125551
126437
  }
125552
126438
  else if (c instanceof core_1.Expressions.CorrespondingBodyMapping && child instanceof core_1.Nodes.ExpressionNode) {
125553
126439
  let mappingRow = { componentName: undefined, componentChain: undefined };
@@ -125566,38 +126452,16 @@ class CorrespondingBodyTranspiler {
125566
126452
  throw new Error("CorrespondingBodyTranspiler, todo, " + c.constructor.name + ", " + body.concatTokens());
125567
126453
  }
125568
126454
  }
125569
- const ret = new chunk_1.Chunk();
125570
- const id = unique_identifier_1.UniqueIdentifier.get();
125571
- const sourceId = unique_identifier_1.UniqueIdentifier.get();
125572
- ret.appendString("(await (async () => {\n");
125573
- ret.appendString(`const ${id} = ${target};\n`);
125574
- ret.appendString(`const ${sourceId} = ${source.getCode()};\n`);
125575
- if (isTableType) {
125576
- const rowTargetType = traversal.toType(type.getRowType());
125577
- const sourceRowId = unique_identifier_1.UniqueIdentifier.get();
125578
- const targetRowId = unique_identifier_1.UniqueIdentifier.get();
125579
- ret.appendString(`for (const ${sourceRowId} of ${sourceId}.array()) {\n`);
125580
- ret.appendString(`const ${targetRowId} = ${rowTargetType};\n`);
125581
- ret.appendString(`abap.statements.moveCorresponding(${sourceRowId}, ${targetRowId});\n`);
125582
- for (const map of mapping) {
125583
- const componentName = map.componentName.concatTokens().toLowerCase();
125584
- const chain = new component_chain_1.ComponentChainTranspiler().transpile(map.componentChain, traversal).getCode();
125585
- ret.appendString(`${targetRowId}.get().${componentName}.set(${sourceRowId}.get().${chain});\n`);
125586
- }
125587
- ret.appendString(`abap.statements.insertInternal({table: ${id}, data: ${targetRowId}});\n`);
125588
- ret.appendString("}\n");
125589
- }
125590
- else {
125591
- ret.appendString(`abap.statements.moveCorresponding(${sourceId}, ${id});\n`);
125592
- for (const map of mapping) {
125593
- const componentName = map.componentName.concatTokens().toLowerCase();
125594
- const chain = new component_chain_1.ComponentChainTranspiler().transpile(map.componentChain, traversal).getCode();
125595
- ret.appendString(`${id}.get().${componentName}.set(${sourceId}.get().${chain});\n`);
125596
- }
126455
+ return { source: source, base, mapping };
126456
+ }
126457
+ mappingCode(mapping, targetId, sourceId, traversal) {
126458
+ let code = "";
126459
+ for (const map of mapping) {
126460
+ const componentName = map.componentName.concatTokens().toLowerCase();
126461
+ const chain = new component_chain_1.ComponentChainTranspiler().transpile(map.componentChain, traversal).getCode();
126462
+ code += `${targetId}.get().${componentName}.set(${sourceId}.get().${chain});\n`;
125597
126463
  }
125598
- ret.appendString("return " + id + ";\n");
125599
- ret.appendString("})())");
125600
- return ret;
126464
+ return code;
125601
126465
  }
125602
126466
  }
125603
126467
  exports.CorrespondingBodyTranspiler = CorrespondingBodyTranspiler;
@@ -130823,210 +131687,312 @@ var __importStar = (this && this.__importStar) || (function () {
130823
131687
  };
130824
131688
  })();
130825
131689
  Object.defineProperty(exports, "__esModule", ({ value: true }));
130826
- exports.HandleABAP = void 0;
131690
+ exports.HandleABAP = void 0;
131691
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
131692
+ const traversal_1 = __webpack_require__(/*! ../traversal */ "./node_modules/@abaplint/transpiler/build/src/traversal.js");
131693
+ const requires_1 = __webpack_require__(/*! ../requires */ "./node_modules/@abaplint/transpiler/build/src/requires.js");
131694
+ const rearranger_1 = __webpack_require__(/*! ../rearranger */ "./node_modules/@abaplint/transpiler/build/src/rearranger.js");
131695
+ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
131696
+ const output_layout_1 = __webpack_require__(/*! ../output_layout */ "./node_modules/@abaplint/transpiler/build/src/output_layout.js");
131697
+ const type_factory_registry_1 = __webpack_require__(/*! ../type_factory_registry */ "./node_modules/@abaplint/transpiler/build/src/type_factory_registry.js");
131698
+ const program_includes_1 = __webpack_require__(/*! ../program_includes */ "./node_modules/@abaplint/transpiler/build/src/program_includes.js");
131699
+ class HandleABAP {
131700
+ layout;
131701
+ /** the function running the program, not a name a FORM or variable can be transpiled to */
131702
+ static PROGRAM_MAIN = "$main";
131703
+ options;
131704
+ /** executable programs as modules, their event blocks and other executable code are wrapped in a function */
131705
+ static wrapsMain(obj, options) {
131706
+ return options?.addCommonJS === true
131707
+ && obj instanceof abaplint.Objects.Program
131708
+ && obj.isInclude() === false;
131709
+ }
131710
+ constructor(options, layout = new output_layout_1.OutputLayout()) {
131711
+ this.layout = layout;
131712
+ this.options = options;
131713
+ }
131714
+ runObject(obj, reg) {
131715
+ let ret = [];
131716
+ const typeFactories = new Map();
131717
+ const sequencedFiles = obj.getSequencedFiles();
131718
+ if (obj instanceof abaplint.Objects.Program && obj.isInclude() === true) {
131719
+ // includes are only compiled along with the programs where its used?
131720
+ return [];
131721
+ }
131722
+ const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti;
131723
+ // Reserve names across every source contributing to each final module
131724
+ // before traversal assigns any helper names (notably merged class locals).
131725
+ for (const file of sequencedFiles) {
131726
+ const filename = file.getFilename().replace(".abap", ".mjs").toLowerCase();
131727
+ const registryKey = filename.replace(/\.clas\.locals_(def|imp)\.mjs$/, ".clas.locals.mjs");
131728
+ let typeFactory = typeFactories.get(registryKey);
131729
+ if (typeFactory === undefined) {
131730
+ typeFactory = new type_factory_registry_1.TypeFactoryRegistry(registryKey);
131731
+ typeFactories.set(registryKey, typeFactory);
131732
+ }
131733
+ typeFactory.reserveSource(file.getRaw());
131734
+ }
131735
+ for (const file of sequencedFiles) {
131736
+ const chunk = new chunk_1.Chunk();
131737
+ const filename = file.getFilename().replace(".abap", ".mjs").toLowerCase();
131738
+ const registryKey = filename.replace(/\.clas\.locals_(def|imp)\.mjs$/, ".clas.locals.mjs");
131739
+ const typeFactory = typeFactories.get(registryKey);
131740
+ if (this.options?.addFilenames === true) {
131741
+ chunk.appendString("// " + file.getFilename() + "\n");
131742
+ }
131743
+ if (file.getStructure() === undefined) {
131744
+ throw new Error("HandleABAP, file has no structure, probably a syntax error: " + file.getFilename());
131745
+ }
131746
+ const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
131747
+ const traversal = new traversal_1.Traversal(spaghetti, file, obj, reg, this.options, typeFactory);
131748
+ const wrapMain = HandleABAP.wrapsMain(obj, this.options);
131749
+ if (wrapMain) {
131750
+ traversal.programMain = new chunk_1.Chunk();
131751
+ }
131752
+ const contents = traversal.traverse(rearranged);
131753
+ chunk.appendChunk(contents);
131754
+ if (wrapMain) {
131755
+ // the program runs when main is called, importing the module eg. for unit testing does not run it
131756
+ chunk.appendString(`async function ${HandleABAP.PROGRAM_MAIN}() {\n`);
131757
+ chunk.appendChunk(traversal.programMain);
131758
+ chunk.appendString("}\n");
131759
+ }
131760
+ chunk.stripLastNewline();
131761
+ const exports = this.findExports(file.getStructure());
131762
+ if (obj instanceof abaplint.Objects.Program) {
131763
+ // INCLUDEs are expanded into the program, so export their contents too
131764
+ for (const include of (0, program_includes_1.findProgramIncludes)(file, reg)) {
131765
+ exports.push(...this.findExports(include.getStructure()).filter(e => exports.includes(e) === false));
131766
+ }
131767
+ }
131768
+ if (wrapMain) {
131769
+ exports.push(HandleABAP.PROGRAM_MAIN);
131770
+ }
131771
+ const output = {
131772
+ object: {
131773
+ name: obj.getName(),
131774
+ type: obj.getType(),
131775
+ },
131776
+ filename: filename,
131777
+ chunk: chunk,
131778
+ requires: new requires_1.Requires(reg).find(obj, spaghetti.getTop(), file.getFilename()),
131779
+ exports: exports,
131780
+ };
131781
+ ret.push(output);
131782
+ }
131783
+ ret = this.rearrangeClassLocals(obj, ret);
131784
+ for (const output of ret) {
131785
+ const registry = typeFactories.get(output.filename);
131786
+ const code = registry?.finalize(output.chunk) ?? "";
131787
+ if (code !== "") {
131788
+ output.chunk = new chunk_1.Chunk(code).appendChunk(output.chunk);
131789
+ }
131790
+ output.chunk.runIndentationLogic(this.options?.ignoreSourceMap);
131791
+ }
131792
+ if (this.options?.addCommonJS === true) {
131793
+ ret.map(output => output.chunk = this.addImportsAndExports(output));
131794
+ }
131795
+ return ret;
131796
+ }
131797
+ /** merges the locals def and imp into one mjs file */
131798
+ rearrangeClassLocals(obj, output) {
131799
+ const ret = [];
131800
+ if (obj.getType() !== "CLAS") {
131801
+ return output;
131802
+ }
131803
+ let imp = undefined;
131804
+ let def = undefined;
131805
+ for (const o of output) {
131806
+ if (o.filename.endsWith(".clas.locals_imp.mjs")) {
131807
+ imp = o;
131808
+ }
131809
+ else if (o.filename.endsWith(".clas.locals_def.mjs")) {
131810
+ def = o;
131811
+ }
131812
+ else {
131813
+ ret.push(o);
131814
+ }
131815
+ }
131816
+ if (def) {
131817
+ def.filename = def.filename.replace(".locals_def.mjs", ".locals.mjs");
131818
+ }
131819
+ if (imp) {
131820
+ imp.filename = imp.filename.replace(".locals_imp.mjs", ".locals.mjs");
131821
+ }
131822
+ if (imp && def) {
131823
+ // remove duplicates
131824
+ const requires = [...def.requires];
131825
+ for (const r of imp.requires) {
131826
+ if (requires.find(a => a.filename === r.filename && a.name === r.name) === undefined) {
131827
+ requires.push(r);
131828
+ }
131829
+ }
131830
+ const chunk = new chunk_1.Chunk().appendChunk(def.chunk).appendChunk(imp.chunk);
131831
+ ret.push({
131832
+ object: imp.object,
131833
+ filename: imp.filename,
131834
+ chunk: chunk,
131835
+ requires: requires,
131836
+ exports: def.exports.concat(imp.exports),
131837
+ });
131838
+ }
131839
+ else if (imp) {
131840
+ ret.push(imp);
131841
+ }
131842
+ else if (def) {
131843
+ ret.push(def);
131844
+ }
131845
+ return ret;
131846
+ }
131847
+ addImportsAndExports(output) {
131848
+ const contents = new chunk_1.Chunk();
131849
+ for (const r of output.requires) {
131850
+ const name = r.name?.toLowerCase();
131851
+ const filename = r.filename.replace(".abap", ".mjs");
131852
+ if (filename === output.filename) {
131853
+ continue;
131854
+ }
131855
+ const specifier = (0, output_layout_1.importPath)(this.layout.file(output.object, output.filename), this.layout.sourceModule(r.filename));
131856
+ if (name) {
131857
+ contents.appendString("const {" + traversal_1.Traversal.escapeNamespace(name) + "} = await import(\"" + specifier + "\");\n");
131858
+ }
131859
+ else {
131860
+ contents.appendString("await import(\"" + specifier + "\");\n");
131861
+ }
131862
+ }
131863
+ contents.appendChunk(output.chunk);
131864
+ if (output.exports.length > 0) {
131865
+ contents.appendString("\nexport {" + output.exports.map(traversal_1.Traversal.escapeNamespace).join(", ") + "};");
131866
+ }
131867
+ return contents;
131868
+ }
131869
+ findExports(node) {
131870
+ const res = [];
131871
+ for (const c of node?.findAllStatements(abaplint.Statements.ClassDefinition) || []) {
131872
+ const e = c.findFirstExpression(abaplint.Expressions.ClassName)?.getFirstToken().getStr();
131873
+ if (e) {
131874
+ res.push(e.toLowerCase());
131875
+ }
131876
+ }
131877
+ for (const c of node?.findAllStatements(abaplint.Statements.Interface) || []) {
131878
+ const e = c.findFirstExpression(abaplint.Expressions.InterfaceName)?.getFirstToken().getStr();
131879
+ if (e) {
131880
+ res.push(e.toLowerCase());
131881
+ }
131882
+ }
131883
+ for (const c of node?.findAllStatements(abaplint.Statements.Form) || []) {
131884
+ const e = c.findFirstExpression(abaplint.Expressions.FormName);
131885
+ if (e) {
131886
+ res.push(traversal_1.Traversal.formName(e));
131887
+ }
131888
+ }
131889
+ return res;
131890
+ }
131891
+ }
131892
+ exports.HandleABAP = HandleABAP;
131893
+ //# sourceMappingURL=handle_abap.js.map
131894
+
131895
+ /***/ },
131896
+
131897
+ /***/ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_definition.js"
131898
+ /*!****************************************************************************************!*\
131899
+ !*** ./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_definition.js ***!
131900
+ \****************************************************************************************/
131901
+ (__unused_webpack_module, exports, __webpack_require__) {
131902
+
131903
+ "use strict";
131904
+
131905
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
131906
+ if (k2 === undefined) k2 = k;
131907
+ var desc = Object.getOwnPropertyDescriptor(m, k);
131908
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
131909
+ desc = { enumerable: true, get: function() { return m[k]; } };
131910
+ }
131911
+ Object.defineProperty(o, k2, desc);
131912
+ }) : (function(o, m, k, k2) {
131913
+ if (k2 === undefined) k2 = k;
131914
+ o[k2] = m[k];
131915
+ }));
131916
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
131917
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
131918
+ }) : function(o, v) {
131919
+ o["default"] = v;
131920
+ });
131921
+ var __importStar = (this && this.__importStar) || (function () {
131922
+ var ownKeys = function(o) {
131923
+ ownKeys = Object.getOwnPropertyNames || function (o) {
131924
+ var ar = [];
131925
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
131926
+ return ar;
131927
+ };
131928
+ return ownKeys(o);
131929
+ };
131930
+ return function (mod) {
131931
+ if (mod && mod.__esModule) return mod;
131932
+ var result = {};
131933
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
131934
+ __setModuleDefault(result, mod);
131935
+ return result;
131936
+ };
131937
+ })();
131938
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
131939
+ exports.HandleDataDefinition = void 0;
130827
131940
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
130828
- const traversal_1 = __webpack_require__(/*! ../traversal */ "./node_modules/@abaplint/transpiler/build/src/traversal.js");
130829
- const requires_1 = __webpack_require__(/*! ../requires */ "./node_modules/@abaplint/transpiler/build/src/requires.js");
130830
- const rearranger_1 = __webpack_require__(/*! ../rearranger */ "./node_modules/@abaplint/transpiler/build/src/rearranger.js");
130831
131941
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
130832
- const output_layout_1 = __webpack_require__(/*! ../output_layout */ "./node_modules/@abaplint/transpiler/build/src/output_layout.js");
131942
+ const transpile_types_1 = __webpack_require__(/*! ../transpile_types */ "./node_modules/@abaplint/transpiler/build/src/transpile_types.js");
130833
131943
  const type_factory_registry_1 = __webpack_require__(/*! ../type_factory_registry */ "./node_modules/@abaplint/transpiler/build/src/type_factory_registry.js");
130834
- const program_includes_1 = __webpack_require__(/*! ../program_includes */ "./node_modules/@abaplint/transpiler/build/src/program_includes.js");
130835
- class HandleABAP {
130836
- layout;
130837
- /** the function running the program, not a name a FORM or variable can be transpiled to */
130838
- static PROGRAM_MAIN = "$main";
130839
- options;
130840
- /** executable programs as modules, their event blocks and other executable code are wrapped in a function */
130841
- static wrapsMain(obj, options) {
130842
- return options?.addCommonJS === true
130843
- && obj instanceof abaplint.Objects.Program
130844
- && obj.isInclude() === false;
130845
- }
130846
- constructor(options, layout = new output_layout_1.OutputLayout()) {
130847
- this.layout = layout;
130848
- this.options = options;
131944
+ // CDS entities: the row type like tables and views, plus the CDS metadata, eg. for XCO
131945
+ class HandleDataDefinition {
131946
+ metadata;
131947
+ constructor(metadata) {
131948
+ this.metadata = metadata;
130849
131949
  }
130850
131950
  runObject(obj, reg) {
130851
- let ret = [];
130852
- const typeFactories = new Map();
130853
- const sequencedFiles = obj.getSequencedFiles();
130854
- if (obj instanceof abaplint.Objects.Program && obj.isInclude() === true) {
130855
- // includes are only compiled along with the programs where its used?
131951
+ if (obj.findSourceFile() === undefined) {
130856
131952
  return [];
130857
131953
  }
130858
- const spaghetti = new abaplint.SyntaxLogic(reg, obj).run().spaghetti;
130859
- // Reserve names across every source contributing to each final module
130860
- // before traversal assigns any helper names (notably merged class locals).
130861
- for (const file of sequencedFiles) {
130862
- const filename = file.getFilename().replace(".abap", ".mjs").toLowerCase();
130863
- const registryKey = filename.replace(/\.clas\.locals_(def|imp)\.mjs$/, ".clas.locals.mjs");
130864
- let typeFactory = typeFactories.get(registryKey);
130865
- if (typeFactory === undefined) {
130866
- typeFactory = new type_factory_registry_1.TypeFactoryRegistry(registryKey);
130867
- typeFactories.set(registryKey, typeFactory);
130868
- }
130869
- typeFactory.reserveSource(file.getRaw());
130870
- }
130871
- for (const file of sequencedFiles) {
130872
- const chunk = new chunk_1.Chunk();
130873
- const filename = file.getFilename().replace(".abap", ".mjs").toLowerCase();
130874
- const registryKey = filename.replace(/\.clas\.locals_(def|imp)\.mjs$/, ".clas.locals.mjs");
130875
- const typeFactory = typeFactories.get(registryKey);
130876
- if (this.options?.addFilenames === true) {
130877
- chunk.appendString("// " + file.getFilename() + "\n");
130878
- }
130879
- if (file.getStructure() === undefined) {
130880
- throw new Error("HandleABAP, file has no structure, probably a syntax error: " + file.getFilename());
130881
- }
130882
- const rearranged = new rearranger_1.Rearranger().run(obj.getType(), file.getStructure());
130883
- const traversal = new traversal_1.Traversal(spaghetti, file, obj, reg, this.options, typeFactory);
130884
- const wrapMain = HandleABAP.wrapsMain(obj, this.options);
130885
- if (wrapMain) {
130886
- traversal.programMain = new chunk_1.Chunk();
130887
- }
130888
- const contents = traversal.traverse(rearranged);
130889
- chunk.appendChunk(contents);
130890
- if (wrapMain) {
130891
- // the program runs when main is called, importing the module eg. for unit testing does not run it
130892
- chunk.appendString(`async function ${HandleABAP.PROGRAM_MAIN}() {\n`);
130893
- chunk.appendChunk(traversal.programMain);
130894
- chunk.appendString("}\n");
130895
- }
130896
- chunk.stripLastNewline();
130897
- const exports = this.findExports(file.getStructure());
130898
- if (obj instanceof abaplint.Objects.Program) {
130899
- // INCLUDEs are expanded into the program, so export their contents too
130900
- for (const include of (0, program_includes_1.findProgramIncludes)(file, reg)) {
130901
- exports.push(...this.findExports(include.getStructure()).filter(e => exports.includes(e) === false));
130902
- }
130903
- }
130904
- if (wrapMain) {
130905
- exports.push(HandleABAP.PROGRAM_MAIN);
130906
- }
130907
- const output = {
130908
- object: {
130909
- name: obj.getName(),
130910
- type: obj.getType(),
130911
- },
130912
- filename: filename,
130913
- chunk: chunk,
130914
- requires: new requires_1.Requires(reg).find(obj, spaghetti.getTop(), file.getFilename()),
130915
- exports: exports,
130916
- };
130917
- ret.push(output);
130918
- }
130919
- ret = this.rearrangeClassLocals(obj, ret);
130920
- for (const output of ret) {
130921
- const registry = typeFactories.get(output.filename);
130922
- const code = registry?.finalize(output.chunk) ?? "";
130923
- if (code !== "") {
130924
- output.chunk = new chunk_1.Chunk(code).appendChunk(output.chunk);
130925
- }
130926
- output.chunk.runIndentationLogic(this.options?.ignoreSourceMap);
130927
- }
130928
- if (this.options?.addCommonJS === true) {
130929
- ret.map(output => output.chunk = this.addImportsAndExports(output));
130930
- }
130931
- return ret;
130932
- }
130933
- /** merges the locals def and imp into one mjs file */
130934
- rearrangeClassLocals(obj, output) {
130935
- const ret = [];
130936
- if (obj.getType() !== "CLAS") {
130937
- return output;
130938
- }
130939
- let imp = undefined;
130940
- let def = undefined;
130941
- for (const o of output) {
130942
- if (o.filename.endsWith(".clas.locals_imp.mjs")) {
130943
- imp = o;
130944
- }
130945
- else if (o.filename.endsWith(".clas.locals_def.mjs")) {
130946
- def = o;
130947
- }
130948
- else {
130949
- ret.push(o);
130950
- }
130951
- }
130952
- if (def) {
130953
- def.filename = def.filename.replace(".locals_def.mjs", ".locals.mjs");
130954
- }
130955
- if (imp) {
130956
- imp.filename = imp.filename.replace(".locals_imp.mjs", ".locals.mjs");
130957
- }
130958
- if (imp && def) {
130959
- // remove duplicates
130960
- const requires = [...def.requires];
130961
- for (const r of imp.requires) {
130962
- if (requires.find(a => a.filename === r.filename && a.name === r.name) === undefined) {
130963
- requires.push(r);
130964
- }
130965
- }
130966
- const chunk = new chunk_1.Chunk().appendChunk(def.chunk).appendChunk(imp.chunk);
130967
- ret.push({
130968
- object: imp.object,
130969
- filename: imp.filename,
130970
- chunk: chunk,
130971
- requires: requires,
130972
- exports: def.exports.concat(imp.exports),
130973
- });
130974
- }
130975
- else if (imp) {
130976
- ret.push(imp);
130977
- }
130978
- else if (def) {
130979
- ret.push(def);
130980
- }
130981
- return ret;
130982
- }
130983
- addImportsAndExports(output) {
130984
- const contents = new chunk_1.Chunk();
130985
- for (const r of output.requires) {
130986
- const name = r.name?.toLowerCase();
130987
- const filename = r.filename.replace(".abap", ".mjs");
130988
- if (filename === output.filename) {
130989
- continue;
130990
- }
130991
- const specifier = (0, output_layout_1.importPath)(this.layout.file(output.object, output.filename), this.layout.sourceModule(r.filename));
130992
- if (name) {
130993
- contents.appendString("const {" + traversal_1.Traversal.escapeNamespace(name) + "} = await import(\"" + specifier + "\");\n");
130994
- }
130995
- else {
130996
- contents.appendString("await import(\"" + specifier + "\");\n");
130997
- }
130998
- }
130999
- contents.appendChunk(output.chunk);
131000
- if (output.exports.length > 0) {
131001
- contents.appendString("\nexport {" + output.exports.map(traversal_1.Traversal.escapeNamespace).join(", ") + "};");
131002
- }
131003
- return contents;
131954
+ const filename = obj.getName().toLowerCase().replace(/\//g, "#") + ".ddls.mjs";
131955
+ const cds = this.metadata.build(obj);
131956
+ const type = this.withoutAssociations(obj.parseType(reg), cds);
131957
+ const typeFactory = new type_factory_registry_1.TypeFactoryRegistry(filename);
131958
+ const body = `abap.DDIC["${obj.getName().toUpperCase()}"] = {
131959
+ "objectType": "DDLS",
131960
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type, typeFactory)},
131961
+ "keyFields": ${JSON.stringify(cds?.fields.filter(f => f.key).map(f => f.name.toUpperCase()) ?? [])},
131962
+ "description": ${JSON.stringify(obj.getDescription())},
131963
+ "sqlViewName": ${JSON.stringify(obj.getSQLViewName())},
131964
+ "cds": ${JSON.stringify(cds)},
131965
+ };`;
131966
+ const chunk = new chunk_1.Chunk(body);
131967
+ const helpers = typeFactory.finalize(chunk);
131968
+ const outputChunk = helpers === "" ? chunk : new chunk_1.Chunk(helpers).appendChunk(chunk);
131969
+ const output = {
131970
+ object: {
131971
+ name: obj.getName(),
131972
+ type: obj.getType(),
131973
+ },
131974
+ filename: filename,
131975
+ chunk: outputChunk,
131976
+ requires: [],
131977
+ exports: [],
131978
+ };
131979
+ return [output];
131004
131980
  }
131005
- findExports(node) {
131006
- const res = [];
131007
- for (const c of node?.findAllStatements(abaplint.Statements.ClassDefinition) || []) {
131008
- const e = c.findFirstExpression(abaplint.Expressions.ClassName)?.getFirstToken().getStr();
131009
- if (e) {
131010
- res.push(e.toLowerCase());
131011
- }
131012
- }
131013
- for (const c of node?.findAllStatements(abaplint.Statements.Interface) || []) {
131014
- const e = c.findFirstExpression(abaplint.Expressions.InterfaceName)?.getFirstToken().getStr();
131015
- if (e) {
131016
- res.push(e.toLowerCase());
131017
- }
131981
+ /** exposed associations are elements of the signature, but not components of the row type */
131982
+ withoutAssociations(type, cds) {
131983
+ if (!(type instanceof abaplint.BasicTypes.StructureType) || cds === undefined) {
131984
+ return type;
131018
131985
  }
131019
- for (const c of node?.findAllStatements(abaplint.Statements.Form) || []) {
131020
- const e = c.findFirstExpression(abaplint.Expressions.FormName);
131021
- if (e) {
131022
- res.push(traversal_1.Traversal.formName(e));
131023
- }
131986
+ const associations = new Set(cds.associations.map(a => a.name.toUpperCase()));
131987
+ const components = type.getComponents().filter(c => !associations.has(c.name.toUpperCase()));
131988
+ if (components.length === type.getComponents().length) {
131989
+ return type;
131024
131990
  }
131025
- return res;
131991
+ return new abaplint.BasicTypes.StructureType(components, type.getQualifiedName(), type.getDDICName(), type.getDescription());
131026
131992
  }
131027
131993
  }
131028
- exports.HandleABAP = HandleABAP;
131029
- //# sourceMappingURL=handle_abap.js.map
131994
+ exports.HandleDataDefinition = HandleDataDefinition;
131995
+ //# sourceMappingURL=handle_data_definition.js.map
131030
131996
 
131031
131997
  /***/ },
131032
131998
 
@@ -131062,6 +132028,9 @@ class HandleDataElement {
131062
132028
  "objectType": "DTEL",
131063
132029
  "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type, typeFactory)},
131064
132030
  "domain": ${JSON.stringify(obj.getDomainName())},
132031
+ "datatype": ${JSON.stringify(obj.getDataType(reg))},
132032
+ "length": ${JSON.stringify(obj.getLength(reg))},
132033
+ "decimals": ${JSON.stringify(obj.getDecimals(reg))},
131065
132034
  "fixedValues": ${JSON.stringify(fixedValues)},
131066
132035
  "description": ${JSON.stringify(obj.getDescription())},
131067
132036
  };`;
@@ -131759,6 +132728,8 @@ const handle_abap_1 = __webpack_require__(/*! ./handlers/handle_abap */ "./node_
131759
132728
  const handle_data_element_1 = __webpack_require__(/*! ./handlers/handle_data_element */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_element.js");
131760
132729
  const handle_table_type_1 = __webpack_require__(/*! ./handlers/handle_table_type */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_table_type.js");
131761
132730
  const handle_view_1 = __webpack_require__(/*! ./handlers/handle_view */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_view.js");
132731
+ const handle_data_definition_1 = __webpack_require__(/*! ./handlers/handle_data_definition */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_data_definition.js");
132732
+ const cds_metadata_1 = __webpack_require__(/*! ./cds_metadata */ "./node_modules/@abaplint/transpiler/build/src/cds_metadata.js");
131762
132733
  const handle_enqu_1 = __webpack_require__(/*! ./handlers/handle_enqu */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_enqu.js");
131763
132734
  const handle_type_pool_1 = __webpack_require__(/*! ./handlers/handle_type_pool */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_type_pool.js");
131764
132735
  const handle_w3mi_1 = __webpack_require__(/*! ./handlers/handle_w3mi */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_w3mi.js");
@@ -131805,6 +132776,7 @@ class Transpiler {
131805
132776
  databaseSetup: dbSetup,
131806
132777
  reg: reg,
131807
132778
  };
132779
+ const cdsMetadata = new cds_metadata_1.CDSMetadata(reg);
131808
132780
  progress?.set(reg.getObjectCount().total, "Building");
131809
132781
  for (const obj of reg.getObjects()) {
131810
132782
  await progress?.tick("Building, " + obj.getName());
@@ -131832,6 +132804,9 @@ class Transpiler {
131832
132804
  else if (obj instanceof abaplint.Objects.View) {
131833
132805
  output.objects.push(...new handle_view_1.HandleView().runObject(obj, reg));
131834
132806
  }
132807
+ else if (obj instanceof abaplint.Objects.DataDefinition) {
132808
+ output.objects.push(...new handle_data_definition_1.HandleDataDefinition(cdsMetadata).runObject(obj, reg));
132809
+ }
131835
132810
  else if (obj instanceof abaplint.Objects.LockObject) {
131836
132811
  output.objects.push(...new handle_enqu_1.HandleEnqu().runObject(obj, reg));
131837
132812
  }
@@ -132059,7 +133034,8 @@ globalThis.abap = new runtime.ABAP();\n`;
132059
133034
  || obj instanceof abaplint.Objects.WebMIME
132060
133035
  || obj instanceof abaplint.Objects.TypePool
132061
133036
  || obj instanceof abaplint.Objects.TableType
132062
- || obj instanceof abaplint.Objects.View) {
133037
+ || obj instanceof abaplint.Objects.View
133038
+ || (obj instanceof abaplint.Objects.DataDefinition && obj.findSourceFile() !== undefined)) {
132063
133039
  list.push(imp(this.layout.objectModule(obj)));
132064
133040
  }
132065
133041
  }
@@ -132261,7 +133237,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
132261
133237
  exports.OutputLayout = exports.DDIC_MODULE = exports.DDIC_TYPES = void 0;
132262
133238
  exports.importPath = importPath;
132263
133239
  /** Object types whose module only sets abap.DDIC[...] */
132264
- exports.DDIC_TYPES = new Set(["DTEL", "TABL", "TTYP", "VIEW"]);
133240
+ exports.DDIC_TYPES = new Set(["DDLS", "DTEL", "TABL", "TTYP", "VIEW"]);
132265
133241
  /** Per folder module holding all its DDIC definitions. Object filenames never start
132266
133242
  * with an underscore, so it cannot collide with an object module. Loading tens of
132267
133243
  * thousands of tiny modules dominates startup, one module per folder avoids that. */
@@ -132846,64 +133822,82 @@ var __importStar = (this && this.__importStar) || (function () {
132846
133822
  };
132847
133823
  })();
132848
133824
  Object.defineProperty(exports, "__esModule", ({ value: true }));
132849
- exports.sharedMedium = sharedMedium;
133825
+ exports.dataClusterMedium = dataClusterMedium;
132850
133826
  exports.mediumOptions = mediumOptions;
132851
133827
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
132852
- function sharedMedium(node, keyword, traversal) {
133828
+ function word(node) {
133829
+ return node instanceof abaplint.Nodes.TokenNode ? node.getFirstToken().getStr().toUpperCase() : "";
133830
+ }
133831
+ function dataClusterMedium(node, keyword, traversal) {
132853
133832
  const children = node.getChildren();
132854
- let at = -1;
132855
- for (let i = 0; i < children.length - 1; i++) {
132856
- const here = children[i];
132857
- const next = children[i + 1];
132858
- if (here instanceof abaplint.Nodes.TokenNode && here.getFirstToken().getStr().toUpperCase() === keyword
132859
- && next instanceof abaplint.Nodes.TokenNode && next.getFirstToken().getStr().toUpperCase() === "SHARED") {
132860
- at = i + 1;
132861
- break;
132862
- }
132863
- }
132864
- if (at < 0) {
133833
+ const at = children.findIndex(c => word(c) === keyword) + 1;
133834
+ if (at === 0) {
132865
133835
  return undefined;
132866
133836
  }
132867
- const kind = children[at + 1]?.getFirstToken().getStr().toUpperCase();
132868
- if (kind !== "MEMORY" && kind !== "BUFFER") {
132869
- return undefined;
133837
+ let ret;
133838
+ let additions;
133839
+ if (word(children[at]) === "MEMORY") {
133840
+ ret = { medium: "MEMORY" };
133841
+ additions = at + 1;
132870
133842
  }
132871
- const tableNode = children[at + 2];
132872
- const areaNode = children[at + 4];
132873
- if (!(tableNode instanceof abaplint.Nodes.ExpressionNode) || areaNode === undefined) {
132874
- return undefined;
133843
+ else if (word(children[at]) === "DATA" && word(children[at + 1]) === "BUFFER"
133844
+ && children[at + 2] instanceof abaplint.Nodes.ExpressionNode) {
133845
+ return { medium: "DATA BUFFER", buffer: traversal.traverse(children[at + 2]).getCode() };
132875
133846
  }
132876
- const ret = {
132877
- medium: kind === "MEMORY" ? "SHARED MEMORY" : "SHARED BUFFER",
132878
- table: tableNode.concatTokens().toUpperCase(),
132879
- area: areaNode.getFirstToken().getStr().toUpperCase(),
132880
- };
132881
- // after the "( ar )": the additions in any order, ID / CLIENT followed by
132882
- // a Source; FROM wa (EXPORT) and TO wa (IMPORT) name the dbtab's work area,
132883
- // whose extra fields have no place in this store and are not read
132884
- for (let i = at + 6; i < children.length - 1; i++) {
133847
+ else {
133848
+ // DATABASE dbtab(ar) ... / SHARED MEMORY|BUFFER dbtab(ar) ...
133849
+ let tableAt;
133850
+ if (word(children[at]) === "DATABASE") {
133851
+ ret = { medium: "DATABASE" };
133852
+ tableAt = at + 1;
133853
+ }
133854
+ else if (word(children[at]) === "SHARED" && (word(children[at + 1]) === "MEMORY" || word(children[at + 1]) === "BUFFER")) {
133855
+ ret = { medium: word(children[at + 1]) === "MEMORY" ? "SHARED MEMORY" : "SHARED BUFFER" };
133856
+ tableAt = at + 2;
133857
+ }
133858
+ else {
133859
+ return undefined;
133860
+ }
133861
+ const tableNode = children[tableAt];
133862
+ const areaNode = children[tableAt + 2];
133863
+ if (!(tableNode instanceof abaplint.Nodes.ExpressionNode) || areaNode === undefined) {
133864
+ return undefined;
133865
+ }
133866
+ ret.table = tableNode.concatTokens().toUpperCase();
133867
+ ret.area = areaNode.getFirstToken().getStr().toUpperCase();
133868
+ additions = tableAt + 4;
133869
+ }
133870
+ // the additions in any order, ID / CLIENT followed by a Source; FROM wa
133871
+ // (EXPORT) and TO wa (IMPORT) name the dbtab's work area, whose extra
133872
+ // fields have no place in this store and are not read
133873
+ for (let i = additions; i < children.length - 1; i++) {
132885
133874
  const here = children[i];
132886
133875
  const next = children[i + 1];
132887
133876
  if (!(here instanceof abaplint.Nodes.TokenNode) || !(next instanceof abaplint.Nodes.ExpressionNode)) {
132888
133877
  continue;
132889
133878
  }
132890
- const word = here.getFirstToken().getStr().toUpperCase();
132891
- if (word === "ID") {
133879
+ if (word(here) === "ID") {
132892
133880
  ret.id = traversal.traverse(next).getCode();
132893
133881
  }
132894
- else if (word === "CLIENT") {
133882
+ else if (word(here) === "CLIENT") {
132895
133883
  ret.client = traversal.traverse(next).getCode();
132896
133884
  }
133885
+ else if (word(here) === "USING") {
133886
+ return undefined;
133887
+ }
132897
133888
  }
132898
- if (ret.id === undefined) {
133889
+ if (ret.medium !== "MEMORY" && ret.id === undefined) {
132899
133890
  return undefined;
132900
133891
  }
132901
133892
  return ret;
132902
133893
  }
132903
133894
  function mediumOptions(medium) {
132904
- return `medium: ${JSON.stringify(medium.medium)}, table: ${JSON.stringify(medium.table)}, `
132905
- + `area: ${JSON.stringify(medium.area)}, id: ${medium.id}`
132906
- + (medium.client === undefined ? "" : `, client: ${medium.client}`);
133895
+ return `medium: ${JSON.stringify(medium.medium)}`
133896
+ + (medium.table === undefined ? "" : `, table: ${JSON.stringify(medium.table)}`)
133897
+ + (medium.area === undefined ? "" : `, area: ${JSON.stringify(medium.area)}`)
133898
+ + (medium.id === undefined ? "" : `, id: ${medium.id}`)
133899
+ + (medium.client === undefined ? "" : `, client: ${medium.client}`)
133900
+ + (medium.buffer === undefined ? "" : `, buffer: ${medium.buffer}`);
132907
133901
  }
132908
133902
  //# sourceMappingURL=_data_cluster.js.map
132909
133903
 
@@ -136156,9 +137150,14 @@ exports.DataTranspiler = DataTranspiler;
136156
137150
  Object.defineProperty(exports, "__esModule", ({ value: true }));
136157
137151
  exports.DeleteClusterTranspiler = void 0;
136158
137152
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
137153
+ const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
136159
137154
  class DeleteClusterTranspiler {
136160
- transpile(_node, _traversal) {
136161
- return new chunk_1.Chunk(`throw new Error("DELETE CLUSTER, not supported, transpiler");`);
137155
+ transpile(node, traversal) {
137156
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "FROM", traversal);
137157
+ if (medium === undefined) {
137158
+ return new chunk_1.Chunk(`throw new Error("DELETE CLUSTER, not supported, transpiler");`);
137159
+ }
137160
+ return new chunk_1.Chunk(`abap.statements.deleteCluster({${(0, _data_cluster_1.mediumOptions)(medium)}});`);
136162
137161
  }
136163
137162
  }
136164
137163
  exports.DeleteClusterTranspiler = DeleteClusterTranspiler;
@@ -136441,9 +137440,14 @@ exports.DeleteInternalTranspiler = DeleteInternalTranspiler;
136441
137440
  Object.defineProperty(exports, "__esModule", ({ value: true }));
136442
137441
  exports.DeleteMemoryTranspiler = void 0;
136443
137442
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
137443
+ const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
136444
137444
  class DeleteMemoryTranspiler {
136445
- transpile(_node, _traversal) {
136446
- return new chunk_1.Chunk(`throw new Error("DeleteMemory, not supported, transpiler");`);
137445
+ transpile(node, traversal) {
137446
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "FROM", traversal);
137447
+ if (medium === undefined) {
137448
+ return new chunk_1.Chunk(`throw new Error("DeleteMemory, not supported, transpiler");`);
137449
+ }
137450
+ return new chunk_1.Chunk(`abap.statements.deleteCluster({${(0, _data_cluster_1.mediumOptions)(medium)}});`);
136447
137451
  }
136448
137452
  }
136449
137453
  exports.DeleteMemoryTranspiler = DeleteMemoryTranspiler;
@@ -137371,7 +138375,7 @@ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/tr
137371
138375
  const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
137372
138376
  class ExportTranspiler {
137373
138377
  transpile(node, traversal) {
137374
- const medium = (0, _data_cluster_1.sharedMedium)(node, "TO", traversal);
138378
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "TO", traversal);
137375
138379
  const parameters = medium === undefined ? undefined : this.parameters(node, traversal);
137376
138380
  if (medium === undefined || parameters === undefined) {
137377
138381
  return new chunk_1.Chunk(`throw new Error("Export, transpiler todo");`);
@@ -137959,12 +138963,47 @@ exports.FreeTranspiler = FreeTranspiler;
137959
138963
 
137960
138964
  "use strict";
137961
138965
 
138966
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
138967
+ if (k2 === undefined) k2 = k;
138968
+ var desc = Object.getOwnPropertyDescriptor(m, k);
138969
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
138970
+ desc = { enumerable: true, get: function() { return m[k]; } };
138971
+ }
138972
+ Object.defineProperty(o, k2, desc);
138973
+ }) : (function(o, m, k, k2) {
138974
+ if (k2 === undefined) k2 = k;
138975
+ o[k2] = m[k];
138976
+ }));
138977
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
138978
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
138979
+ }) : function(o, v) {
138980
+ o["default"] = v;
138981
+ });
138982
+ var __importStar = (this && this.__importStar) || (function () {
138983
+ var ownKeys = function(o) {
138984
+ ownKeys = Object.getOwnPropertyNames || function (o) {
138985
+ var ar = [];
138986
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
138987
+ return ar;
138988
+ };
138989
+ return ownKeys(o);
138990
+ };
138991
+ return function (mod) {
138992
+ if (mod && mod.__esModule) return mod;
138993
+ var result = {};
138994
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
138995
+ __setModuleDefault(result, mod);
138996
+ return result;
138997
+ };
138998
+ })();
137962
138999
  Object.defineProperty(exports, "__esModule", ({ value: true }));
137963
139000
  exports.FreeMemoryTranspiler = void 0;
139001
+ const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
137964
139002
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
137965
139003
  class FreeMemoryTranspiler {
137966
- transpile(_node, _traversal) {
137967
- return new chunk_1.Chunk(`throw new Error("FreeMemory, not supported, transpiler");`);
139004
+ transpile(node, traversal) {
139005
+ const id = node.findDirectExpression(abaplint.Expressions.Source);
139006
+ return new chunk_1.Chunk(`abap.statements.freeMemory({${id === undefined ? "" : "id: " + traversal.traverse(id).getCode()}});`);
137968
139007
  }
137969
139008
  }
137970
139009
  exports.FreeMemoryTranspiler = FreeMemoryTranspiler;
@@ -138812,7 +139851,7 @@ const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/tr
138812
139851
  const _data_cluster_1 = __webpack_require__(/*! ./_data_cluster */ "./node_modules/@abaplint/transpiler/build/src/statements/_data_cluster.js");
138813
139852
  class ImportTranspiler {
138814
139853
  transpile(node, traversal) {
138815
- const medium = (0, _data_cluster_1.sharedMedium)(node, "FROM", traversal);
139854
+ const medium = (0, _data_cluster_1.dataClusterMedium)(node, "FROM", traversal);
138816
139855
  const parameters = medium === undefined ? undefined : this.parameters(node, traversal);
138817
139856
  if (medium === undefined || parameters === undefined) {
138818
139857
  return new chunk_1.Chunk(`throw new Error("Import, transpiler todo");`);
@@ -139526,6 +140565,11 @@ class InsertInternalTranspiler {
139526
140565
  if (index) {
139527
140566
  options.push("index: " + traversal.traverse(index).getCode());
139528
140567
  }
140568
+ else if (!concat.startsWith("INSERT LINES OF ") && !concat.includes(" INTO TABLE ") && concat.includes(" INTO ")
140569
+ && node.findDirectExpression(abaplint.Expressions.Target) !== undefined) {
140570
+ // INSERT wa INTO itab: in a LOOP over itab, in front of the current row
140571
+ options.push("currentRow: true");
140572
+ }
139529
140573
  if (concat.includes(" REFERENCE INTO ")) {
139530
140574
  const targets = node.findDirectExpressions(abaplint.Expressions.Target);
139531
140575
  options.push("referenceInto: " + traversal.traverse(targets[1]).getCode());
@@ -140955,6 +141999,8 @@ exports.MoveTranspiler = void 0;
140955
141999
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
140956
142000
  const chunk_1 = __webpack_require__(/*! ../chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
140957
142001
  const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/transpiler/build/src/expressions/source.js");
142002
+ const type_name_or_infer_1 = __webpack_require__(/*! ../expressions/type_name_or_infer */ "./node_modules/@abaplint/transpiler/build/src/expressions/type_name_or_infer.js");
142003
+ const corresponding_body_1 = __webpack_require__(/*! ../expressions/corresponding_body */ "./node_modules/@abaplint/transpiler/build/src/expressions/corresponding_body.js");
140958
142004
  class MoveTranspiler {
140959
142005
  transpile(node, traversal) {
140960
142006
  const sourceExpression = node.findDirectExpression(abaplint.Expressions.Source);
@@ -140974,10 +142020,15 @@ class MoveTranspiler {
140974
142020
  ret.appendString(target + `.set(abap.alphaIn(${tSource.getCode()}, ${target}, ${target}));`);
140975
142021
  return ret;
140976
142022
  }
140977
- let source = this.isInt8Calculation(node, sourceExpression, targetExpressions.length, traversal)
140978
- ? new source_1.SourceTranspiler(false, true).transpile(sourceExpression, traversal)
140979
- : traversal.traverse(sourceExpression);
140980
142023
  const second = node.getChildren()[1]?.concatTokens();
142024
+ let source = second === "=" && targetExpressions.length === 1
142025
+ ? this.correspondingGeneric(sourceExpression, targets[0], traversal)
142026
+ : undefined;
142027
+ if (source === undefined) {
142028
+ source = this.isInt8Calculation(node, sourceExpression, targetExpressions.length, traversal)
142029
+ ? new source_1.SourceTranspiler(false, true).transpile(sourceExpression, traversal)
142030
+ : traversal.traverse(sourceExpression);
142031
+ }
140981
142032
  switch (second) {
140982
142033
  case "?=":
140983
142034
  ret.appendString("await abap.statements.cast(")
@@ -141039,6 +142090,22 @@ class MoveTranspiler {
141039
142090
  }
141040
142091
  return ret;
141041
142092
  }
142093
+ // "target = CORRESPONDING #( ... )" with a generic target, eg. "CHANGING ct TYPE STANDARD TABLE",
142094
+ // the type of the result is only known at runtime, so the target is passed on
142095
+ correspondingGeneric(source, target, traversal) {
142096
+ const children = source?.getChildren() || [];
142097
+ const typ = source?.findDirectExpression(abaplint.Expressions.TypeNameOrInfer);
142098
+ const body = source?.findDirectExpression(abaplint.Expressions.CorrespondingBody);
142099
+ if (children.length !== 5
142100
+ || children[0].concatTokens().toUpperCase() !== "CORRESPONDING"
142101
+ || typ === undefined
142102
+ || typ.concatTokens() !== "#"
142103
+ || body === undefined
142104
+ || new type_name_or_infer_1.TypeNameOrInfer().findTypeOrUndefined(typ, traversal)?.isGeneric() !== true) {
142105
+ return undefined;
142106
+ }
142107
+ return new corresponding_body_1.CorrespondingBodyTranspiler().transpile(typ, body, traversal, target.getCode());
142108
+ }
141042
142109
  // The calculation type of an arithmetic expression comes from its operands and the target
141043
142110
  // field, the type with the largest range wins. With operands of type i or int8 it is int8
141044
142111
  // when the target or an operand is int8: i * i into int8 is exact up to 2^62, and "/"
@@ -142088,6 +143155,22 @@ class RaiseEventTranspiler {
142088
143155
  if (parameters) {
142089
143156
  extra = "," + new expressions_1.ParameterListSTranspiler().transpile(parameters, traversal).getCode();
142090
143157
  }
143158
+ // a static event: handlers may only react when the class of this statement is theirs, it is passed along
143159
+ const def = traversal.getClassDefinition(node.getFirstToken());
143160
+ const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
143161
+ let search = def;
143162
+ let isStatic = false;
143163
+ while (search !== undefined) {
143164
+ const event = search.getEvents().find(e => e.getName().toLowerCase() === eventName);
143165
+ if (event !== undefined) {
143166
+ isStatic = event.isStatic();
143167
+ break;
143168
+ }
143169
+ search = search.getSuperClass() ? traversal.findClassDefinition(search.getSuperClass(), scope) : undefined;
143170
+ }
143171
+ if (isStatic === true && def !== undefined) {
143172
+ extra = (extra === "" ? ", undefined" : extra) + ", " + traversal_1.Traversal.escapeNamespace(def.getName().toLowerCase());
143173
+ }
142091
143174
  return new chunk_1.Chunk().append(`await abap.statements.raiseEvent(this.${eventName}, this.me${extra});`, node, traversal);
142092
143175
  }
142093
143176
  }
@@ -143880,6 +144963,7 @@ class SetHandlerTranspiler {
143880
144963
  const methods = [];
143881
144964
  let eventClass = undefined;
143882
144965
  let eventName = undefined;
144966
+ let forClass = "";
143883
144967
  for (const m of node.findDirectExpressions(abaplint.Expressions.MethodSource)) {
143884
144968
  // the handler method is registered as a reference, it is dispatched dynamically when the event is raised,
143885
144969
  // so no static binding even if the SET HANDLER is inside a constructor
@@ -143896,6 +144980,7 @@ class SetHandlerTranspiler {
143896
144980
  }
143897
144981
  eventName = method.def.getEventName();
143898
144982
  eventClass = this.findEventClass(method.def, traversal, scope);
144983
+ forClass = this.findForClass(method.def, eventClass, traversal, scope);
143899
144984
  }
143900
144985
  }
143901
144986
  let f = undefined;
@@ -143911,9 +144996,23 @@ class SetHandlerTranspiler {
143911
144996
  if (activationExpression) {
143912
144997
  activation = ", " + new expressions_1.SourceTranspiler().transpile(activationExpression, traversal).getCode();
143913
144998
  }
143914
- return new chunk_1.Chunk().append(`abap.statements.setHandler({EVENT_NAME: "${eventName}", EVENT_CLASS: "${eventClass}"}, [${methods.join(",")}], ${f}${activation});`, node, traversal);
144999
+ return new chunk_1.Chunk().append(`abap.statements.setHandler({EVENT_NAME: "${eventName}", EVENT_CLASS: "${eventClass}"${forClass}}, [${methods.join(",")}], ${f}${activation});`, node, traversal);
143915
145000
  }
143916
145001
  ///////////////////////////////////////////////////////////////////////
145002
+ /** a handler FOR EVENT ... OF a subclass of the class declaring the event only reacts to that subclass */
145003
+ findForClass(mdef, eventClass, traversal, scope) {
145004
+ const own = traversal.findClassDefinition(mdef.getEventClass(), scope);
145005
+ if (own === undefined || traversal.buildInternalName(own.getName(), own) === eventClass) {
145006
+ return "";
145007
+ }
145008
+ let def = own;
145009
+ let event = undefined;
145010
+ while (def !== undefined && event === undefined) {
145011
+ event = def.getEvents().find(e => e.getName().toUpperCase() === mdef.getEventName()?.toUpperCase());
145012
+ def = def.getSuperClass() ? traversal.findClassDefinition(def.getSuperClass(), scope) : undefined;
145013
+ }
145014
+ return `, FOR_CLASS: "${traversal.buildInternalName(own.getName(), own)}", STATIC: ${event?.isStatic() === true}`;
145015
+ }
143917
145016
  findEventClass(mdef, traversal, scope) {
143918
145017
  let def = traversal.findClassDefinition(mdef.getEventClass(), scope);
143919
145018
  if (def === undefined) {
@@ -148633,11 +149732,11 @@ class TranspileTypes {
148633
149732
  extra = "{qualifiedName: \"" + type.getQualifiedName()?.toUpperCase() + "\"}";
148634
149733
  }
148635
149734
  }
148636
- else if (type instanceof abaplint.BasicTypes.DecFloat34Type
148637
- || type instanceof abaplint.BasicTypes.DecFloat16Type) {
148638
- // decfloat16 runs on the runtime's decfloat34, an exact decimal: the
148639
- // 16 digit rounding and range of decfloat16 are not modelled, and RTTI
148640
- // describes such a field as a decfloat34
149735
+ else if (type instanceof abaplint.BasicTypes.DecFloat16Type) {
149736
+ // the range of decfloat16 is not modelled
149737
+ resolved = "DecFloat16";
149738
+ }
149739
+ else if (type instanceof abaplint.BasicTypes.DecFloat34Type) {
148641
149740
  resolved = "DecFloat34";
148642
149741
  }
148643
149742
  else if (type instanceof abaplint.BasicTypes.EnumType) {
@@ -150814,6 +151913,7 @@ const defaultAllowedObjectTypes = [
150814
151913
  "CHKO",
150815
151914
  "CHKV",
150816
151915
  "CLAS",
151916
+ "DCLS",
150817
151917
  "DDLS",
150818
151918
  "DDLX",
150819
151919
  "DEVC",