@abaplint/transpiler-cli 2.14.38 → 2.14.40

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 +738 -89
  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
 
@@ -30033,12 +30033,25 @@ exports.SuperConstructorCall = SuperConstructorCall;
30033
30033
  Object.defineProperty(exports, "__esModule", ({ value: true }));
30034
30034
  exports.CheckSyntaxKey = void 0;
30035
30035
  exports.syntaxIssue = syntaxIssue;
30036
+ exports.dataObjectBeforeStaticArrow = dataObjectBeforeStaticArrow;
30036
30037
  const issue_1 = __webpack_require__(/*! ../../issue */ "./node_modules/@abaplint/core/build/src/issue.js");
30037
30038
  const severity_1 = __webpack_require__(/*! ../../severity */ "./node_modules/@abaplint/core/build/src/severity.js");
30038
30039
  exports.CheckSyntaxKey = "check_syntax";
30039
30040
  function syntaxIssue(input, token, message, fix) {
30040
30041
  return issue_1.Issue.atTokenFilename(input.filename, token, message, exports.CheckSyntaxKey, severity_1.Severity.Error, fix);
30041
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
+ }
30042
30055
  //# sourceMappingURL=_syntax_input.js.map
30043
30056
 
30044
30057
  /***/ },
@@ -34836,7 +34849,7 @@ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modu
34836
34849
  const version_1 = __webpack_require__(/*! ../../../version */ "./node_modules/@abaplint/core/build/src/version.js");
34837
34850
  class FieldChain {
34838
34851
  static runSyntax(node, input, refType, allowGenericDeference = false) {
34839
- var _a, _b, _c;
34852
+ var _a, _b, _c, _d;
34840
34853
  if (((_a = node.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.SourceField
34841
34854
  && node.findDirectExpression(Expressions.ComponentName)) {
34842
34855
  // workaround for names with dashes, eg. "sy-repid"
@@ -34907,7 +34920,11 @@ class FieldChain {
34907
34920
  if (afterTableExpression && table_expression_1.TableExpression.checkArrowAfter(input, current.getFirstToken())) {
34908
34921
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
34909
34922
  }
34910
- 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)
34911
34928
  && !(context instanceof basic_1.DataReference)
34912
34929
  && !(context instanceof basic_1.VoidType)) {
34913
34930
  const message = "Not an object reference, field chain";
@@ -34991,6 +35008,9 @@ class FieldChain {
34991
35008
  input.scope.addReference(classTok, found.id, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
34992
35009
  return new basic_1.ObjectReferenceType(found.id);
34993
35010
  }
35011
+ else if ((0, _syntax_input_1.dataObjectBeforeStaticArrow)(input, classTok)) {
35012
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
35013
+ }
34994
35014
  else if (input.scope.getDDIC().inErrorNamespace(classNam) === false) {
34995
35015
  input.scope.addReference(classTok, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, { ooName: classNam.toUpperCase() });
34996
35016
  return basic_1.VoidType.get(classNam);
@@ -36648,7 +36668,10 @@ class MethodCallChain {
36648
36668
  const token = first.getFirstToken();
36649
36669
  const className = token.getStr();
36650
36670
  const classDefinition = input.scope.findObjectDefinition(className);
36651
- 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) {
36652
36675
  const extra = { ooName: className, ooType: "Void" };
36653
36676
  input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, extra);
36654
36677
  return basic_1.VoidType.get(className);
@@ -37559,7 +37582,10 @@ class MethodSource {
37559
37582
  const token = first.getFirstToken();
37560
37583
  const className = token.getStr();
37561
37584
  const classDefinition = input.scope.findObjectDefinition(className);
37562
- 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) {
37563
37589
  const extra = { ooName: className, ooType: "Void" };
37564
37590
  input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, extra);
37565
37591
  return basic_1.VoidType.get(className);
@@ -40379,6 +40405,7 @@ const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modu
40379
40405
  const version_1 = __webpack_require__(/*! ../../../version */ "./node_modules/@abaplint/core/build/src/version.js");
40380
40406
  class Target {
40381
40407
  static runSyntax(node, input) {
40408
+ var _a;
40382
40409
  const concat = node.concatTokens();
40383
40410
  if (concat.includes("-")) {
40384
40411
  // workaround for names with dashes
@@ -40429,7 +40456,11 @@ class Target {
40429
40456
  if (afterTableExpression && table_expression_1.TableExpression.checkArrowAfter(input, current.getFirstToken())) {
40430
40457
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
40431
40458
  }
40432
- 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)
40433
40464
  && !(context instanceof basic_1.DataReference)
40434
40465
  && !(context instanceof basic_1.VoidType)) {
40435
40466
  const message = "Not an object reference, target";
@@ -40548,6 +40579,9 @@ class Target {
40548
40579
  input.scope.addReference(token, found, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
40549
40580
  return new basic_1.ObjectReferenceType(found);
40550
40581
  }
40582
+ else if ((0, _syntax_input_1.dataObjectBeforeStaticArrow)(input, token)) {
40583
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
40584
+ }
40551
40585
  else if (input.scope.getDDIC().inErrorNamespace(name) === false) {
40552
40586
  input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, { ooName: name, ooType: "CLAS" });
40553
40587
  return basic_1.VoidType.get(name);
@@ -41711,6 +41745,7 @@ var __importStar = (this && this.__importStar) || (function () {
41711
41745
  Object.defineProperty(exports, "__esModule", ({ value: true }));
41712
41746
  exports.Append = void 0;
41713
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");
41714
41749
  const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
41715
41750
  const target_1 = __webpack_require__(/*! ../expressions/target */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/target.js");
41716
41751
  const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
@@ -41781,9 +41816,17 @@ class Append {
41781
41816
  let sourceType = source_1.Source.runSyntax(source, input, rowType);
41782
41817
  if (node.findDirectTokenByText("LINES")) {
41783
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;
41784
41824
  if (sourceType instanceof basic_1.TableType) {
41785
41825
  sourceType = sourceType.getRowType();
41786
41826
  }
41827
+ else if (genericLines) {
41828
+ sourceType = basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
41829
+ }
41787
41830
  else if (!(sourceType instanceof basic_1.VoidType) && !(sourceType instanceof basic_1.UnknownType)) {
41788
41831
  const message = "LINES OF must be a table type";
41789
41832
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
@@ -46921,16 +46964,21 @@ const _type_utils_1 = __webpack_require__(/*! ../_type_utils */ "./node_modules/
46921
46964
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
46922
46965
  class InsertInternal {
46923
46966
  runSyntax(node, input) {
46924
- var _a, _b;
46967
+ var _a, _b, _c;
46925
46968
  let targetType;
46926
46969
  const t = node.findDirectExpression(Expressions.Target);
46927
46970
  if (t) {
46928
46971
  targetType = target_1.Target.runSyntax(t, input);
46929
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;
46930
46977
  if (!(targetType instanceof basic_1.TableType)
46931
46978
  && !(targetType instanceof basic_1.VoidType)
46932
46979
  && !(targetType instanceof basic_1.AnyType)
46933
46980
  && !(targetType instanceof basic_1.UnknownType)
46981
+ && genericByKey === false
46934
46982
  && targetType !== undefined) {
46935
46983
  const message = "INSERT target must be a table";
46936
46984
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
@@ -46985,7 +47033,7 @@ class InsertInternal {
46985
47033
  error = true;
46986
47034
  }
46987
47035
  else if ((sourceType instanceof basic_1.StringType || sourceType instanceof basic_1.CharacterType)
46988
- && ((_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
46989
47037
  && (source === null || source === void 0 ? void 0 : source.findDirectExpression(Expressions.Constant)) === undefined
46990
47038
  && (targetType instanceof basic_1.IntegerType
46991
47039
  || targetType instanceof basic_1.Integer8Type
@@ -46998,7 +47046,7 @@ class InsertInternal {
46998
47046
  }
46999
47047
  else if (sourceType instanceof basic_1.CharacterType
47000
47048
  && targetType instanceof basic_1.CharacterType
47001
- && ((_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
47002
47050
  && sourceType.getLength() !== targetType.getLength()) {
47003
47051
  // character literal of different length than the row type
47004
47052
  error = true;
@@ -52466,6 +52514,7 @@ const field_chain_1 = __webpack_require__(/*! ../expressions/field_chain */ "./n
52466
52514
  const _reference_1 = __webpack_require__(/*! ../_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
52467
52515
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
52468
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");
52469
52518
  class Write {
52470
52519
  runSyntax(node, input) {
52471
52520
  // todo, more
@@ -52485,7 +52534,9 @@ class Write {
52485
52534
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message));
52486
52535
  return;
52487
52536
  }
52537
+ // a utclong is written as a time stamp, although it is not character-like elsewhere
52488
52538
  if (s === second
52539
+ && !(type instanceof basic_1.UTCLongType)
52489
52540
  && new _type_utils_1.TypeUtils(input.scope).isCharLike(type) === false
52490
52541
  && new _type_utils_1.TypeUtils(input.scope).isHexLike(type) === false) {
52491
52542
  const message = "Source not character like";
@@ -69484,6 +69535,12 @@ class DataDefinition extends _abstract_object_1.AbstractObject {
69484
69535
  this.parse();
69485
69536
  return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.description;
69486
69537
  }
69538
+ /** SOURCE_TYPE from the abapGit XML, eg. "W" view entity, "P" projection view, "V" DDIC-based view */
69539
+ getSourceType() {
69540
+ var _a;
69541
+ this.parse();
69542
+ return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.sourceType;
69543
+ }
69487
69544
  parseType(reg) {
69488
69545
  this.parse();
69489
69546
  if (this.typeCache === undefined || this.typeCacheData !== this.parsedData) {
@@ -69525,15 +69582,17 @@ class DataDefinition extends _abstract_object_1.AbstractObject {
69525
69582
  return ret;
69526
69583
  }
69527
69584
  parse() {
69528
- var _a, _b;
69585
+ var _a, _b, _c, _d, _e, _f;
69529
69586
  if (this.isDirty() === false) {
69530
69587
  return { updated: false, runtime: 0 };
69531
69588
  }
69532
69589
  const start = Date.now();
69590
+ const ddls = (_d = (_c = (_b = (_a = this.parseRaw2()) === null || _a === void 0 ? void 0 : _a.abapGit) === null || _b === void 0 ? void 0 : _b["asx:abap"]) === null || _c === void 0 ? void 0 : _c["asx:values"]) === null || _d === void 0 ? void 0 : _d.DDLS;
69533
69591
  this.parsedData = {
69534
69592
  sqlViewName: undefined,
69535
69593
  definitionName: undefined,
69536
- description: this.findDescription(),
69594
+ sourceType: typeof (ddls === null || ddls === void 0 ? void 0 : ddls.SOURCE_TYPE) === "string" ? ddls.SOURCE_TYPE.trim() : undefined,
69595
+ description: undefined,
69537
69596
  fields: [],
69538
69597
  sources: [],
69539
69598
  relations: [],
@@ -69541,14 +69600,16 @@ class DataDefinition extends _abstract_object_1.AbstractObject {
69541
69600
  tree: undefined,
69542
69601
  };
69543
69602
  this.parsedData.tree = new cds_parser_1.CDSParser().parse(this.findSourceFile());
69544
- this.findSQLViewName(this.parsedData.tree);
69603
+ const leadingAnnotations = this.findLeadingAnnotations(this.parsedData.tree);
69604
+ this.findSQLViewName(leadingAnnotations);
69605
+ this.parsedData.description = this.findDescription(leadingAnnotations, ddls === null || ddls === void 0 ? void 0 : ddls.DDTEXT);
69545
69606
  if (this.parsedData.tree) {
69546
- for (const c of ((_a = this.parsedData.tree) === null || _a === void 0 ? void 0 : _a.getChildren()) || []) {
69607
+ for (const c of ((_e = this.parsedData.tree) === null || _e === void 0 ? void 0 : _e.getChildren()) || []) {
69547
69608
  if (c.get() instanceof expressions_1.CDSAnnotation) {
69548
69609
  continue;
69549
69610
  }
69550
69611
  if (c instanceof nodes_1.ExpressionNode) {
69551
- this.parsedData.definitionName = (_b = c.findFirstExpression(expressions_1.CDSName)) === null || _b === void 0 ? void 0 : _b.concatTokens().replace(/ /g, "");
69612
+ this.parsedData.definitionName = (_f = c.findFirstExpression(expressions_1.CDSName)) === null || _f === void 0 ? void 0 : _f.concatTokens().replace(/ /g, "");
69552
69613
  break;
69553
69614
  }
69554
69615
  }
@@ -69566,39 +69627,51 @@ class DataDefinition extends _abstract_object_1.AbstractObject {
69566
69627
  return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.tree;
69567
69628
  }
69568
69629
  //////////
69569
- findSQLViewName(tree) {
69630
+ /** annotations before the entity definition, ie. not the ones on elements or parameters */
69631
+ findLeadingAnnotations(tree) {
69570
69632
  var _a;
69571
- let annotations = tree === null || tree === void 0 ? void 0 : tree.findDirectExpressions(expressions_1.CDSAnnotation);
69572
- if (annotations === undefined) {
69573
- const file = this.findSourceFile();
69574
- if (file === undefined) {
69575
- return;
69576
- }
69577
- // Keep SQL view lookup available even when the view body cannot be parsed.
69578
- const tokens = cds_lexer_1.CDSLexer.run(file).filter(t => !(t instanceof tokens_1.Comment));
69579
- const leadingAnnotations = (0, combi_1.seq)((0, combi_1.starPrio)(expressions_1.CDSAnnotation), (0, combi_1.starPrio)((0, combi_1.regex)(/.*/)));
69580
- annotations = (_a = combi_1.Combi.run(leadingAnnotations, tokens, version_1.defaultRelease)) === null || _a === void 0 ? void 0 : _a.filter((n) => n instanceof nodes_1.ExpressionNode && n.get() instanceof expressions_1.CDSAnnotation);
69633
+ if (tree !== undefined) {
69634
+ return tree.findDirectExpressions(expressions_1.CDSAnnotation);
69635
+ }
69636
+ const file = this.findSourceFile();
69637
+ if (file === undefined) {
69638
+ return [];
69581
69639
  }
69582
- for (const annotation of annotations || []) {
69640
+ // Keep header annotations available even when the definition body cannot be parsed.
69641
+ const tokens = cds_lexer_1.CDSLexer.run(file).filter(t => !(t instanceof tokens_1.Comment));
69642
+ const leadingAnnotations = (0, combi_1.seq)((0, combi_1.starPrio)(expressions_1.CDSAnnotation), (0, combi_1.starPrio)((0, combi_1.regex)(/.*/)));
69643
+ return ((_a = combi_1.Combi.run(leadingAnnotations, tokens, version_1.defaultRelease)) === null || _a === void 0 ? void 0 : _a.filter((n) => n instanceof nodes_1.ExpressionNode && n.get() instanceof expressions_1.CDSAnnotation)) || [];
69644
+ }
69645
+ /** values of the leading annotations with the given name, as written in the source */
69646
+ findLeadingAnnotationValues(annotations, name) {
69647
+ const ret = [];
69648
+ for (const annotation of annotations) {
69583
69649
  const tokens = annotation.getTokens().map(t => t.getStr());
69584
69650
  const colon = tokens.indexOf(":");
69585
- if (tokens.slice(0, colon).join("") !== "@AbapCatalog.sqlViewName") {
69586
- continue;
69651
+ if (colon >= 0 && tokens.slice(0, colon).join("") === name) {
69652
+ ret.push(tokens.slice(colon + 1).join(" "));
69587
69653
  }
69588
- const match = tokens.slice(colon + 1).join(" ").match(/^'([\w/]+)'$/);
69654
+ }
69655
+ return ret;
69656
+ }
69657
+ findSQLViewName(annotations) {
69658
+ for (const value of this.findLeadingAnnotationValues(annotations, "@AbapCatalog.sqlViewName")) {
69659
+ const match = value.match(/^'([\w/]+)'$/);
69589
69660
  if (match) {
69590
69661
  this.parsedData.sqlViewName = match[1].toUpperCase();
69591
69662
  return;
69592
69663
  }
69593
69664
  }
69594
69665
  }
69595
- findDescription() {
69596
- var _a;
69597
- const match = (_a = this.findSourceFile()) === null || _a === void 0 ? void 0 : _a.getRaw().match(/@EndUserText\.label: '([\w,.:-=#%&() ]+)'/);
69598
- if (match) {
69599
- return match[1];
69666
+ /** entity level EndUserText.label annotation, with fallback to DDTEXT from the abapGit XML */
69667
+ findDescription(annotations, ddtext) {
69668
+ for (const value of this.findLeadingAnnotationValues(annotations, "@EndUserText.label")) {
69669
+ const match = value.match(/^'([\s\S]*)'$/);
69670
+ if (match) {
69671
+ return match[1].replace(/\\(['\\])/g, "$1");
69672
+ }
69600
69673
  }
69601
- return undefined;
69674
+ return typeof ddtext === "string" && ddtext !== "" ? ddtext : undefined;
69602
69675
  }
69603
69676
  findFieldNames(tree) {
69604
69677
  var _a, _b, _c;
@@ -69752,6 +69825,10 @@ const domain_1 = __webpack_require__(/*! ./domain */ "./node_modules/@abaplint/c
69752
69825
  const _identifier_1 = __webpack_require__(/*! ../abap/4_file_information/_identifier */ "./node_modules/@abaplint/core/build/src/abap/4_file_information/_identifier.js");
69753
69826
  const identifier_1 = __webpack_require__(/*! ../abap/1_lexer/tokens/identifier */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/identifier.js");
69754
69827
  const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
69828
+ function toNumber(value) {
69829
+ const parsed = parseInt(value !== null && value !== void 0 ? value : "", 10);
69830
+ return isNaN(parsed) ? undefined : parsed;
69831
+ }
69755
69832
  class DataElement extends _abstract_object_1.AbstractObject {
69756
69833
  constructor() {
69757
69834
  super(...arguments);
@@ -69801,10 +69878,33 @@ class DataElement extends _abstract_object_1.AbstractObject {
69801
69878
  if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
69802
69879
  return this.parsedXML.datatype;
69803
69880
  }
69804
- if (reg && ((_b = this.parsedXML) === null || _b === void 0 ? void 0 : _b.refkind) === "D" && this.parsedXML.domname) {
69881
+ return (_b = this.findDomain(reg)) === null || _b === void 0 ? void 0 : _b.getDataType();
69882
+ }
69883
+ /** DDIC length, eg. number of digits for DEC, which parseType() cannot give.
69884
+ * Taken from the same place as getDataType(), ie. the data element or its domain. */
69885
+ getLength(reg) {
69886
+ var _a, _b;
69887
+ this.parse();
69888
+ if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
69889
+ return toNumber(this.parsedXML.leng);
69890
+ }
69891
+ return (_b = this.findDomain(reg)) === null || _b === void 0 ? void 0 : _b.getLength();
69892
+ }
69893
+ /** DDIC decimals, taken from the same place as getDataType(), ie. the data element or its domain. */
69894
+ getDecimals(reg) {
69895
+ var _a, _b;
69896
+ this.parse();
69897
+ if ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype) {
69898
+ return toNumber(this.parsedXML.decimals);
69899
+ }
69900
+ return (_b = this.findDomain(reg)) === null || _b === void 0 ? void 0 : _b.getDecimals();
69901
+ }
69902
+ findDomain(reg) {
69903
+ var _a;
69904
+ if (reg && ((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.refkind) === "D" && this.parsedXML.domname) {
69805
69905
  const domain = reg.getObject("DOMA", this.parsedXML.domname);
69806
69906
  if (domain instanceof domain_1.Domain) {
69807
- return domain.getDataType();
69907
+ return domain;
69808
69908
  }
69809
69909
  }
69810
69910
  return undefined;
@@ -70140,6 +70240,10 @@ const xml_utils_1 = __webpack_require__(/*! ../xml_utils */ "./node_modules/@aba
70140
70240
  const _identifier_1 = __webpack_require__(/*! ../abap/4_file_information/_identifier */ "./node_modules/@abaplint/core/build/src/abap/4_file_information/_identifier.js");
70141
70241
  const identifier_1 = __webpack_require__(/*! ../abap/1_lexer/tokens/identifier */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/identifier.js");
70142
70242
  const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
70243
+ function toNumber(value) {
70244
+ const parsed = parseInt(value !== null && value !== void 0 ? value : "", 10);
70245
+ return isNaN(parsed) ? undefined : parsed;
70246
+ }
70143
70247
  class Domain extends _abstract_object_1.AbstractObject {
70144
70248
  getType() {
70145
70249
  return "DOMA";
@@ -70159,6 +70263,16 @@ class Domain extends _abstract_object_1.AbstractObject {
70159
70263
  this.parse();
70160
70264
  return (_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.datatype;
70161
70265
  }
70266
+ getLength() {
70267
+ var _a;
70268
+ this.parse();
70269
+ return toNumber((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.length);
70270
+ }
70271
+ getDecimals() {
70272
+ var _a;
70273
+ this.parse();
70274
+ return toNumber((_a = this.parsedXML) === null || _a === void 0 ? void 0 : _a.decimals);
70275
+ }
70162
70276
  getAllowedNaming() {
70163
70277
  return {
70164
70278
  maxLength: 30,
@@ -76824,7 +76938,7 @@ class Registry {
76824
76938
  }
76825
76939
  static abaplintVersion() {
76826
76940
  // magic, see build script "version.js"
76827
- return "2.120.118";
76941
+ return "2.120.120";
76828
76942
  }
76829
76943
  getDDICReferences() {
76830
76944
  return this.ddicReferences;
@@ -82731,6 +82845,8 @@ const RESERVED_ELEMENT_NAMES = ["BEGIN", "NUMBER", "POSITION", "ZONE", "HANDLER"
82731
82845
  const MAX_LABEL_LENGTH = 40;
82732
82846
  // Annotations which are not supported in CDS view entities
82733
82847
  const VIEW_ENTITY_FORBIDDEN_ANNOTATIONS = ["Semantics.unitOfMeasure", "Semantics.currencyCode"];
82848
+ // Select list elements which are expressions, ie. not plain fields
82849
+ const CALCULATED_ELEMENT = [expressions_1.CDSCast, expressions_1.CDSCase, expressions_1.CDSArithmetics, expressions_1.CDSArithParen, expressions_1.CDSFunction, expressions_1.CDSAggregate, expressions_1.CDSString, expressions_1.CDSInteger];
82734
82850
  class CDSCheckSyntax {
82735
82851
  constructor() {
82736
82852
  this.conf = new CDSCheckSyntaxConf();
@@ -82742,7 +82858,9 @@ class CDSCheckSyntax {
82742
82858
  shortDescription: "Checks CDS source, field, type, and semantic annotation references",
82743
82859
  extendedInformation: `Performs semantic checks which require other DDIC objects to be available.
82744
82860
 
82745
- Missing objects are only reported when their names match the configured errorNamespace.`,
82861
+ Missing objects are only reported when their names match the configured errorNamespace.
82862
+
82863
+ SOURCE_TYPE in the abapGit XML is checked to match the DDL source, W view entity, P projection view, V DDIC-based view.`,
82746
82864
  tags: [_irule_1.RuleTag.Syntax],
82747
82865
  };
82748
82866
  }
@@ -82754,6 +82872,7 @@ Missing objects are only reported when their names match the configured errorNam
82754
82872
  }
82755
82873
  initialize(reg) {
82756
82874
  this.reg = reg;
82875
+ this.businessObjectTargets = undefined;
82757
82876
  return this;
82758
82877
  }
82759
82878
  run(object) {
@@ -82770,13 +82889,17 @@ Missing objects are only reported when their names match the configured errorNam
82770
82889
  const sources = this.findSources(tree, ddic, issues, file);
82771
82890
  this.checkRelations(tree, ddic, issues, file);
82772
82891
  this.checkTypes(tree, ddic, issues, file);
82773
- this.checkRootProjection(tree, ddic, issues, file);
82892
+ if (this.checkRootProjection(tree, ddic, issues, file) === false) {
82893
+ this.checkTransactionalProjection(tree, ddic, issues, file);
82894
+ }
82895
+ this.checkCalculatedAssociationPaths(tree, issues, file);
82774
82896
  this.checkFieldAnnotations(tree, ddic, issues, file);
82775
82897
  this.checkLabels(tree, issues, file);
82776
82898
  this.checkViewEntityAnnotations(tree, issues, file);
82777
82899
  this.checkSearchable(tree, issues, file);
82778
82900
  this.checkReservedNames(tree, issues, file);
82779
82901
  this.checkFields(tree, sources, object, issues, file);
82902
+ this.checkSourceType(tree, object, issues);
82780
82903
  return issues;
82781
82904
  }
82782
82905
  findSources(tree, ddic, issues, file) {
@@ -82831,17 +82954,18 @@ Missing objects are only reported when their names match the configured errorNam
82831
82954
  }
82832
82955
  }
82833
82956
  }
82957
+ /** returns true if an issue was reported */
82834
82958
  checkRootProjection(tree, ddic, issues, file) {
82835
82959
  var _a;
82836
82960
  const projection = tree.findFirstExpression(expressions_1.CDSDefineProjection);
82837
82961
  const rootToken = projection === null || projection === void 0 ? void 0 : projection.findDirectTokenByText("ROOT");
82838
82962
  if (projection === undefined || rootToken === undefined) {
82839
- return;
82963
+ return false;
82840
82964
  }
82841
82965
  const names = projection.findDirectExpressions(expressions_1.CDSName);
82842
82966
  const projectedEntityNode = names[1];
82843
82967
  if (projectedEntityNode === undefined) {
82844
- return;
82968
+ return false;
82845
82969
  }
82846
82970
  const projectedEntityName = this.name(projectedEntityNode);
82847
82971
  const projectedEntity = ddic.lookupTableOrView(projectedEntityName).object;
@@ -82849,7 +82973,161 @@ Missing objects are only reported when their names match the configured errorNam
82849
82973
  && ((_a = projectedEntity.getTree()) === null || _a === void 0 ? void 0 : _a.findDirectTokenByText("ROOT")) === undefined) {
82850
82974
  const message = `ROOT keyword not valid since ${projectedEntityName} is not a root property`;
82851
82975
  issues.push(issue_1.Issue.atToken(file, rootToken, message, this.getMetadata().key, this.conf.severity));
82976
+ return true;
82977
+ }
82978
+ return false;
82979
+ }
82980
+ /** a transactional projection(no provider contract or TRANSACTIONAL_QUERY) requires a business object entity */
82981
+ checkTransactionalProjection(tree, ddic, issues, file) {
82982
+ const projection = tree.findFirstExpression(expressions_1.CDSDefineProjection);
82983
+ if (projection === undefined || projection.findDirectTokenByText("TRANSIENT") !== undefined) {
82984
+ return;
82985
+ }
82986
+ const contract = projection.findDirectExpression(expressions_1.CDSProviderContract);
82987
+ if (contract !== undefined && contract.findDirectTokenByText("TRANSACTIONAL_QUERY") === undefined) {
82988
+ return;
82989
+ }
82990
+ const projectedEntityNode = projection.findDirectExpressions(expressions_1.CDSName)[1];
82991
+ if (projectedEntityNode === undefined) {
82992
+ return;
82993
+ }
82994
+ const projectedEntityName = this.name(projectedEntityNode);
82995
+ const projectedEntity = ddic.lookupTableOrView(projectedEntityName).object;
82996
+ if (!(projectedEntity instanceof objects_1.DataDefinition)) {
82997
+ return;
82998
+ }
82999
+ const projectedTree = projectedEntity.getTree();
83000
+ // only plain select based views are checked, ie. not projections, abstract or custom entities
83001
+ if (projectedTree === undefined || !(projectedTree.get() instanceof expressions_1.CDSDefineView)) {
83002
+ return;
83003
+ }
83004
+ if (projectedTree.findDirectTokenByText("ROOT") !== undefined
83005
+ || projectedTree.findAllExpressionsRecursive(expressions_1.CDSComposition).length > 0
83006
+ || projectedTree.findAllExpressionsRecursive(expressions_1.CDSAssociation).some(a => a.findDirectTokenByText("PARENT") !== undefined)) {
83007
+ return;
83008
+ }
83009
+ const candidates = [projectedEntityName.toUpperCase(), projectedEntity.getName().toUpperCase()];
83010
+ const definitionName = projectedEntity.getDefinitionName();
83011
+ if (definitionName !== undefined) {
83012
+ candidates.push(definitionName.toUpperCase());
83013
+ }
83014
+ const targets = this.findBusinessObjectTargets();
83015
+ if (candidates.some(c => targets.has(c))) {
83016
+ return;
82852
83017
  }
83018
+ const message = `Transactional projection on ${projectedEntityName} not possible, ` +
83019
+ `${projectedEntityName} is not a root entity or part of a composition`;
83020
+ issues.push(issue_1.Issue.atToken(file, projectedEntityNode.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
83021
+ }
83022
+ /** names of entities targeted by a composition or an association to parent in any DDLS in the registry */
83023
+ findBusinessObjectTargets() {
83024
+ if (this.businessObjectTargets !== undefined) {
83025
+ return this.businessObjectTargets;
83026
+ }
83027
+ const targets = new Set();
83028
+ for (const obj of this.reg.getObjectsByType("DDLS")) {
83029
+ const tree = obj.getTree();
83030
+ if (tree === undefined) {
83031
+ continue;
83032
+ }
83033
+ const relations = [];
83034
+ for (const composition of tree.findAllExpressionsRecursive(expressions_1.CDSComposition)) {
83035
+ const relation = composition.findDirectExpression(expressions_1.CDSRelation);
83036
+ if (relation) {
83037
+ relations.push(relation);
83038
+ }
83039
+ }
83040
+ for (const association of tree.findAllExpressionsRecursive(expressions_1.CDSAssociation)) {
83041
+ const relation = association.findDirectExpression(expressions_1.CDSRelation);
83042
+ if (relation && association.findDirectTokenByText("PARENT") !== undefined) {
83043
+ relations.push(relation);
83044
+ }
83045
+ }
83046
+ for (const relation of relations) {
83047
+ const name = relation.getDirectTokens().map(t => t.getStr()).join("");
83048
+ if (name !== "") {
83049
+ targets.add(name.toUpperCase());
83050
+ }
83051
+ }
83052
+ }
83053
+ this.businessObjectTargets = targets;
83054
+ return targets;
83055
+ }
83056
+ /** path expressions are not possible via an association whose ON condition uses a calculated element */
83057
+ checkCalculatedAssociationPaths(tree, issues, file) {
83058
+ var _a, _b;
83059
+ for (const select of tree.findAllExpressionsRecursive(expressions_1.CDSSelect)) {
83060
+ const elements = select.findDirectExpressions(expressions_1.CDSElement);
83061
+ const calculated = new Map();
83062
+ for (const element of elements) {
83063
+ const name = (_a = element.findDirectExpression(expressions_1.CDSAs)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(expressions_1.CDSName);
83064
+ if (name !== undefined && element.findDirectExpressionsMulti(CALCULATED_ELEMENT).length > 0) {
83065
+ calculated.set(this.name(name).toUpperCase(), this.name(name));
83066
+ }
83067
+ }
83068
+ if (calculated.size === 0) {
83069
+ continue;
83070
+ }
83071
+ const marked = new Map();
83072
+ for (const association of select.findDirectExpressions(expressions_1.CDSAssociation)) {
83073
+ const relation = association.findDirectExpression(expressions_1.CDSRelation);
83074
+ const condition = association.findDirectExpression(expressions_1.CDSCondition);
83075
+ if (relation === undefined || condition === undefined) {
83076
+ continue;
83077
+ }
83078
+ const aliasNode = (_b = relation.findDirectExpression(expressions_1.CDSAs)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(expressions_1.CDSName);
83079
+ const alias = aliasNode ? this.name(aliasNode) : relation.getDirectTokens().map(t => t.getStr()).join("");
83080
+ for (const prefixed of condition.findAllExpressionsRecursive(expressions_1.CDSPrefixedName)) {
83081
+ const names = prefixed.findDirectExpressions(expressions_1.CDSName);
83082
+ if (names.length !== 2 || this.name(names[0]).toUpperCase() !== "$PROJECTION") {
83083
+ continue;
83084
+ }
83085
+ const element = calculated.get(this.name(names[1]).toUpperCase());
83086
+ if (element !== undefined && marked.has(alias.toUpperCase()) === false) {
83087
+ marked.set(alias.toUpperCase(), element);
83088
+ }
83089
+ }
83090
+ }
83091
+ if (marked.size === 0) {
83092
+ continue;
83093
+ }
83094
+ const usages = [...elements];
83095
+ for (const clause of select.findDirectExpressionsMulti([expressions_1.CDSWhere, expressions_1.CDSGroupBy, expressions_1.CDSHaving])) {
83096
+ usages.push(clause);
83097
+ }
83098
+ for (const usage of usages) {
83099
+ for (const prefixed of this.findPrefixedNames(usage)) {
83100
+ const names = prefixed.findDirectExpressions(expressions_1.CDSName);
83101
+ if (names.length < 2) {
83102
+ continue;
83103
+ }
83104
+ const alias = this.name(names[0]);
83105
+ const element = marked.get(alias.toUpperCase());
83106
+ if (element === undefined) {
83107
+ continue;
83108
+ }
83109
+ const message = `Path expression via ${alias} not possible, ` +
83110
+ `its ON condition uses calculated element ${element}`;
83111
+ issues.push(issue_1.Issue.atToken(file, names[0].getFirstToken(), message, this.getMetadata().key, this.conf.severity));
83112
+ }
83113
+ }
83114
+ }
83115
+ }
83116
+ /** outermost prefixed names, skipping annotations */
83117
+ findPrefixedNames(node) {
83118
+ const ret = [];
83119
+ for (const child of node.getChildren()) {
83120
+ if (!(child instanceof nodes_1.ExpressionNode) || child.get() instanceof expressions_1.CDSAnnotation) {
83121
+ continue;
83122
+ }
83123
+ else if (child.get() instanceof expressions_1.CDSPrefixedName) {
83124
+ ret.push(child);
83125
+ }
83126
+ else {
83127
+ ret.push(...this.findPrefixedNames(child));
83128
+ }
83129
+ }
83130
+ return ret;
82853
83131
  }
82854
83132
  checkFieldAnnotations(tree, ddic, issues, file) {
82855
83133
  const definition = tree.findFirstExpression(expressions_1.CDSDefineAbstract);
@@ -83039,8 +83317,37 @@ Missing objects are only reported when their names match the configured errorNam
83039
83317
  }
83040
83318
  }
83041
83319
  }
83320
+ /** SOURCE_TYPE in the XML must match the DDL source, only the confirmed W/P/V mappings are checked */
83321
+ checkSourceType(tree, object, issues) {
83322
+ const sourceType = object.getSourceType();
83323
+ const xmlFile = object.getXMLFile();
83324
+ if (sourceType === undefined || xmlFile === undefined || ["W", "P", "V"].includes(sourceType) === false) {
83325
+ return;
83326
+ }
83327
+ // other definitions(abstract, custom, table functions, etc.) are skipped
83328
+ let expected = undefined;
83329
+ if (tree.get() instanceof expressions_1.CDSDefineView && tree.findDirectTokenByText("WRITABLE") === undefined) {
83330
+ if (tree.findDirectTokenByText("ENTITY") !== undefined) {
83331
+ expected = "W";
83332
+ }
83333
+ else if (object.getSQLViewName() !== undefined) {
83334
+ expected = "V";
83335
+ }
83336
+ }
83337
+ else if (tree.get() instanceof expressions_1.CDSDefineProjection && tree.findDirectTokenByText("ENTITY") !== undefined) {
83338
+ expected = "P";
83339
+ }
83340
+ if (expected === undefined || expected === sourceType) {
83341
+ return;
83342
+ }
83343
+ const xml = xmlFile.getRaw();
83344
+ const index = xml.indexOf("<SOURCE_TYPE>");
83345
+ const row = index < 0 ? 1 : xml.substring(0, index).split("\n").length;
83346
+ const message = `SOURCE_TYPE "${sourceType}" does not match DDL source, expected "${expected}"`;
83347
+ issues.push(issue_1.Issue.atRow(xmlFile, row, message, this.getMetadata().key, this.conf.severity));
83348
+ }
83042
83349
  checkFields(tree, sources, object, issues, file) {
83043
- var _a;
83350
+ var _a, _b;
83044
83351
  const associationNames = new Set();
83045
83352
  for (const association of ((_a = object.getParsedData()) === null || _a === void 0 ? void 0 : _a.associations) || []) {
83046
83353
  associationNames.add(association.name.toUpperCase());
@@ -83048,6 +83355,21 @@ Missing objects are only reported when their names match the configured errorNam
83048
83355
  associationNames.add(association.as.toUpperCase());
83049
83356
  }
83050
83357
  }
83358
+ for (const composition of tree.findAllExpressionsRecursive(expressions_1.CDSComposition)) {
83359
+ const relation = composition.findDirectExpression(expressions_1.CDSRelation);
83360
+ if (relation === undefined) {
83361
+ continue;
83362
+ }
83363
+ // direct tokens exclude the alias and parameters, and include a namespace like /ABC/
83364
+ const name = relation.getDirectTokens().map(t => t.getStr()).join("");
83365
+ if (name !== "") {
83366
+ associationNames.add(name.toUpperCase());
83367
+ }
83368
+ const alias = (_b = relation.findDirectExpression(expressions_1.CDSAs)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(expressions_1.CDSName);
83369
+ if (alias) {
83370
+ associationNames.add(this.name(alias).toUpperCase());
83371
+ }
83372
+ }
83051
83373
  for (const element of tree.findAllExpressionsRecursive(expressions_1.CDSElement)) {
83052
83374
  const prefixed = element.findDirectExpression(expressions_1.CDSPrefixedName);
83053
83375
  if (prefixed === undefined) {
@@ -115591,12 +115913,21 @@ ENDWHILE.`,
115591
115913
  }
115592
115914
  const reads = this.reads(procedure, move.source);
115593
115915
  if (reads === undefined
115594
- || reads.locals.some(l => l.writes().some(w => w.index > from && w.index < to))
115916
+ || reads.locals.some(l => this.changedIn(procedure, l, from, to))
115595
115917
  || reads.others.some(o => this.writtenIn(procedure, o, from, to))) {
115596
115918
  return false;
115597
115919
  }
115598
115920
  return reads.others.length === 0 || this.mayChangeOtherData(procedure, from, to, reads.receivers) === false;
115599
115921
  }
115922
+ /** written in the loop body, or declared inline in it: the inline declaration is not one of the writes(),
115923
+ * but sets the variable in every iteration, possibly from data the loop changes */
115924
+ changedIn(procedure, local, from, to) {
115925
+ if (local.writes().some(w => w.index > from && w.index < to)) {
115926
+ return true;
115927
+ }
115928
+ const index = local.inline && local.declaration !== undefined ? procedure.index(local.declaration) : -1;
115929
+ return index > from && index < to;
115930
+ }
115600
115931
  writtenIn(procedure, identifier, from, to) {
115601
115932
  for (const reference of procedure.analysis.referencesTo(identifier)) {
115602
115933
  if (reference.referenceType !== _reference_1.ReferenceType.DataWriteReference || !procedure.contains(reference.position)) {
@@ -118628,14 +118959,22 @@ var __importStar = (this && this.__importStar) || (function () {
118628
118959
  Object.defineProperty(exports, "__esModule", ({ value: true }));
118629
118960
  exports.UnsecureFAE = exports.UnsecureFAEConf = void 0;
118630
118961
  const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
118962
+ const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/index.js"));
118963
+ const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "./node_modules/@abaplint/core/build/src/abap/3_structures/structures/index.js"));
118631
118964
  const issue_1 = __webpack_require__(/*! ../issue */ "./node_modules/@abaplint/core/build/src/issue.js");
118632
118965
  const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "./node_modules/@abaplint/core/build/src/rules/_basic_rule_config.js");
118633
118966
  const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/core/build/src/rules/_irule.js");
118634
118967
  const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
118635
118968
  const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/syntax.js");
118969
+ const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
118970
+ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_scope_type.js");
118636
118971
  class UnsecureFAEConf extends _basic_rule_config_1.BasicRuleConfig {
118637
118972
  }
118638
118973
  exports.UnsecureFAEConf = UnsecureFAEConf;
118974
+ const PROCEDURES = [Structures.Method, Structures.Form, Structures.FunctionModule];
118975
+ const LOOPS = [Structures.Loop, Structures.Do, Structures.While, Structures.Select, Structures.LoopAtScreen];
118976
+ const CALLS = [Statements.Call, Statements.CallFunction, Statements.Perform, Statements.Submit,
118977
+ Statements.RaiseEvent, Statements.CallTransaction];
118639
118978
  class UnsecureFAE {
118640
118979
  constructor() {
118641
118980
  this.conf = new UnsecureFAEConf();
@@ -118645,8 +118984,24 @@ class UnsecureFAE {
118645
118984
  key: "unsecure_fae",
118646
118985
  title: "Unsecure FAE",
118647
118986
  shortDescription: `Checks for unsecure FAE`,
118648
- extendedInformation: `Issues from rule check_syntax must be fixed before this rule takes effect`,
118987
+ extendedInformation: `Issues from rule check_syntax must be fixed before this rule takes effect
118988
+
118989
+ The driver table of FOR ALL ENTRIES is considered checked, and no issue is reported, if
118990
+ * the SELECT is in the IF or ELSEIF branch of a condition "itab IS NOT INITIAL", "NOT itab IS INITIAL"
118991
+ or "lines( itab ) > 0", also combined with AND, or
118992
+ * "IF itab IS INITIAL. RETURN. ENDIF." or "CHECK itab IS NOT INITIAL." precedes the SELECT in the same method,
118993
+ form or function module, at the same or an outer block level, not inside a loop,
118994
+
118995
+ and the driver table is not changed between the check and the SELECT, or in a loop around the SELECT inside the
118996
+ checked region. If the driver table is not a local variable or parameter, a method, function or form call in
118997
+ between also invalidates the check.`,
118649
118998
  tags: [_irule_1.RuleTag.Experimental, _irule_1.RuleTag.Performance],
118999
+ badExample: `SELECT * FROM t000 FOR ALL ENTRIES IN @lt_list
119000
+ WHERE mandt = @lt_list-table_line INTO TABLE @DATA(lt_t000).`,
119001
+ goodExample: `IF lt_list IS NOT INITIAL.
119002
+ SELECT * FROM t000 FOR ALL ENTRIES IN @lt_list
119003
+ WHERE mandt = @lt_list-table_line INTO TABLE @DATA(lt_t000).
119004
+ ENDIF.`,
118650
119005
  };
118651
119006
  }
118652
119007
  getConfig() {
@@ -118660,7 +119015,6 @@ class UnsecureFAE {
118660
119015
  this.conf = conf;
118661
119016
  }
118662
119017
  run(obj) {
118663
- var _a;
118664
119018
  const issues = [];
118665
119019
  if (!(obj instanceof _abap_object_1.ABAPObject)) {
118666
119020
  return issues;
@@ -118670,15 +119024,193 @@ class UnsecureFAE {
118670
119024
  return issues;
118671
119025
  }
118672
119026
  for (const f of obj.getABAPFiles()) {
118673
- // todo
118674
- for (const e of ((_a = f.getStructure()) === null || _a === void 0 ? void 0 : _a.findAllExpressions(Expressions.SQLForAllEntries)) || []) {
118675
- const token = e.getFirstToken();
118676
- const message = "Unsecure FAE";
118677
- issues.push(issue_1.Issue.atToken(f, token, message, this.getMetadata().key, this.getConfig().severity));
119027
+ const structure = f.getStructure();
119028
+ if (structure === undefined) {
119029
+ continue;
119030
+ }
119031
+ for (const statement of structure.findAllStatementNodes()) {
119032
+ for (const e of statement.findAllExpressions(Expressions.SQLForAllEntries)) {
119033
+ if (this.isChecked(f, structure, statement, e, syntaxResult.spaghetti)) {
119034
+ continue;
119035
+ }
119036
+ const token = e.getFirstToken();
119037
+ const message = "Unsecure FAE";
119038
+ issues.push(issue_1.Issue.atToken(f, token, message, this.getMetadata().key, this.getConfig().severity));
119039
+ }
118678
119040
  }
118679
119041
  }
118680
119042
  return issues;
118681
119043
  }
119044
+ ////////////////
119045
+ isChecked(file, root, statement, fae, spaghetti) {
119046
+ var _a;
119047
+ const source = fae.findDirectExpression(Expressions.SQLSource);
119048
+ const name = source === null || source === void 0 ? void 0 : source.concatTokens().replace(/^@/, "").replace(/\s/g, "").toUpperCase();
119049
+ if (name === undefined || /^[\w/<>~]+((->|=>)[\w/~]+)?$/.test(name) === false) {
119050
+ return false;
119051
+ }
119052
+ const path = this.findPath(root, statement, []);
119053
+ if (path === undefined) {
119054
+ return false;
119055
+ }
119056
+ const local = this.isLocal(file, name, statement.getStart(), spaghetti);
119057
+ for (let i = path.length - 1; i >= 0; i--) {
119058
+ const node = path[i];
119059
+ const type = node.get();
119060
+ if (PROCEDURES.some(p => type instanceof p)) {
119061
+ break;
119062
+ }
119063
+ const child = (_a = path[i + 1]) !== null && _a !== void 0 ? _a : statement;
119064
+ const inner = path.slice(i + 1);
119065
+ // IF itab IS NOT INITIAL. SELECT ... ENDIF.
119066
+ if ((type instanceof Structures.If || type instanceof Structures.ElseIf) && child.get() instanceof Structures.Body) {
119067
+ const header = node.findDirectStatement(type instanceof Structures.If ? Statements.If : Statements.ElseIf);
119068
+ const cond = header === null || header === void 0 ? void 0 : header.findDirectExpression(Expressions.Cond);
119069
+ if (header && cond && this.notInitial(cond, name)
119070
+ && this.unchanged(file, inner, statement, header.getEnd(), name, local)) {
119071
+ return true;
119072
+ }
119073
+ }
119074
+ // IF itab IS INITIAL. RETURN. ENDIF. or CHECK itab IS NOT INITIAL. before the SELECT
119075
+ const outer = path.slice(0, i + 1);
119076
+ if (type instanceof Structures.Body
119077
+ && outer.some(n => PROCEDURES.some(p => n.get() instanceof p))
119078
+ && outer.some(n => LOOPS.some(l => n.get() instanceof l)) === false) {
119079
+ for (const sibling of node.getChildren()) {
119080
+ if (sibling === child) {
119081
+ break;
119082
+ }
119083
+ const content = sibling instanceof nodes_1.StructureNode && sibling.get() instanceof Structures.Normal
119084
+ ? sibling.getFirstChild() : sibling;
119085
+ if ((content instanceof nodes_1.StructureNode || content instanceof nodes_1.StatementNode)
119086
+ && this.leavesIfInitial(content, name)
119087
+ && this.unchanged(file, inner, statement, sibling.getLastToken().getEnd(), name, local)) {
119088
+ return true;
119089
+ }
119090
+ }
119091
+ }
119092
+ }
119093
+ return false;
119094
+ }
119095
+ findPath(node, target, path) {
119096
+ for (const child of node.getChildren()) {
119097
+ if (child === target) {
119098
+ return [...path, node];
119099
+ }
119100
+ else if (child instanceof nodes_1.StructureNode) {
119101
+ const found = this.findPath(child, target, [...path, node]);
119102
+ if (found) {
119103
+ return found;
119104
+ }
119105
+ }
119106
+ }
119107
+ return undefined;
119108
+ }
119109
+ /** local variable or parameter of the procedure, calls cannot change it */
119110
+ isLocal(file, name, position, spaghetti) {
119111
+ if (name.includes("->") || name.includes("=>") || name.startsWith("<")) {
119112
+ return false;
119113
+ }
119114
+ let scope = spaghetti.lookupPosition(position, file.getFilename());
119115
+ while ((scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype) === _scope_type_1.ScopeType.OpenSQL) {
119116
+ scope = scope.getParent();
119117
+ }
119118
+ const stype = scope === null || scope === void 0 ? void 0 : scope.getIdentifier().stype;
119119
+ if (stype !== _scope_type_1.ScopeType.Method && stype !== _scope_type_1.ScopeType.Form && stype !== _scope_type_1.ScopeType.FunctionModule) {
119120
+ return false;
119121
+ }
119122
+ return (scope === null || scope === void 0 ? void 0 : scope.getData().vars[name]) !== undefined;
119123
+ }
119124
+ /** "itab IS NOT INITIAL" or "lines( itab ) > 0", possibly combined with AND */
119125
+ notInitial(cond, name) {
119126
+ const children = cond.getChildren();
119127
+ if (children.some(c => ["OR", "EQUIV"].includes(c.concatTokens().toUpperCase()))) {
119128
+ return false;
119129
+ }
119130
+ for (const child of children) {
119131
+ if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.Compare) {
119132
+ const text = this.normalize(child);
119133
+ if ([`${name} IS NOT INITIAL`, `NOT ${name} IS INITIAL`,
119134
+ `LINES( ${name} ) > 0`, `LINES( ${name} ) GT 0`, `LINES( ${name} ) <> 0`, `LINES( ${name} ) NE 0`,
119135
+ `LINES( ${name} ) >= 1`, `LINES( ${name} ) GE 1`].includes(text)) {
119136
+ return true;
119137
+ }
119138
+ }
119139
+ else if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.CondSub
119140
+ && child.getFirstToken().getStr().toUpperCase() !== "NOT") {
119141
+ const sub = child.findDirectExpression(Expressions.Cond);
119142
+ if (sub && this.notInitial(sub, name)) {
119143
+ return true;
119144
+ }
119145
+ }
119146
+ }
119147
+ return false;
119148
+ }
119149
+ /** "itab IS INITIAL" or "lines( itab ) = 0", possibly combined with OR */
119150
+ initial(cond, name) {
119151
+ const children = cond.getChildren();
119152
+ if (children.some(c => ["AND", "EQUIV"].includes(c.concatTokens().toUpperCase()))) {
119153
+ return false;
119154
+ }
119155
+ return children.some(c => c instanceof nodes_1.ExpressionNode && c.get() instanceof Expressions.Compare
119156
+ && [`${name} IS INITIAL`, `NOT ${name} IS NOT INITIAL`,
119157
+ `LINES( ${name} ) = 0`, `LINES( ${name} ) EQ 0`, `LINES( ${name} ) < 1`, `LINES( ${name} ) LT 1`]
119158
+ .includes(this.normalize(c)));
119159
+ }
119160
+ /** "IF itab IS INITIAL. RETURN. ENDIF." or "CHECK itab IS NOT INITIAL." */
119161
+ leavesIfInitial(node, name) {
119162
+ var _a, _b;
119163
+ var _c;
119164
+ if (node instanceof nodes_1.StatementNode) {
119165
+ const cond = node.get() instanceof Statements.Check ? node.findDirectExpression(Expressions.Cond) : undefined;
119166
+ return cond !== undefined && this.notInitial(cond, name);
119167
+ }
119168
+ if (!(node.get() instanceof Structures.If)
119169
+ || node.findDirectStructure(Structures.Else) !== undefined
119170
+ || node.findDirectStructure(Structures.ElseIf) !== undefined) {
119171
+ return false;
119172
+ }
119173
+ const statements = (_c = (_a = node.findDirectStructure(Structures.Body)) === null || _a === void 0 ? void 0 : _a.findAllStatementNodes()) !== null && _c !== void 0 ? _c : [];
119174
+ if (statements.length !== 1 || !(statements[0].get() instanceof Statements.Return)) {
119175
+ return false;
119176
+ }
119177
+ const cond = (_b = node.findDirectStatement(Statements.If)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.Cond);
119178
+ return cond !== undefined && this.initial(cond, name);
119179
+ }
119180
+ normalize(node) {
119181
+ return node.concatTokens().toUpperCase().replace(/\s+/g, " ");
119182
+ }
119183
+ /** the driver table is not changed after the check and before the SELECT, nor in a loop around the SELECT
119184
+ * inside the checked region */
119185
+ unchanged(file, inner, statement, from, name, local) {
119186
+ const loop = inner.find(n => LOOPS.some(l => n.get() instanceof l));
119187
+ const to = loop === undefined ? statement.getStart() : loop.getLastToken().getEnd();
119188
+ for (const s of file.getStatements()) {
119189
+ if (s === statement || !s.getStart().isAfter(from) || !s.getStart().isBefore(to)) {
119190
+ continue;
119191
+ }
119192
+ if (this.writes(s, name) || (local === false && this.calls(s))) {
119193
+ return false;
119194
+ }
119195
+ }
119196
+ return true;
119197
+ }
119198
+ writes(statement, name) {
119199
+ for (const target of [...statement.findAllExpressions(Expressions.Target),
119200
+ ...statement.findAllExpressions(Expressions.FSTarget)]) {
119201
+ const text = target.concatTokens().replace(/\s/g, "").toUpperCase();
119202
+ if (text === name || (text.startsWith(name) && /^[^\w/]/.test(text.substring(name.length)))) {
119203
+ return true;
119204
+ }
119205
+ }
119206
+ return false;
119207
+ }
119208
+ calls(statement) {
119209
+ const type = statement.get();
119210
+ return CALLS.some(c => type instanceof c)
119211
+ || statement.findFirstExpression(Expressions.MethodCall) !== undefined
119212
+ || statement.findFirstExpression(Expressions.MethodSource) !== undefined;
119213
+ }
118682
119214
  }
118683
119215
  exports.UnsecureFAE = UnsecureFAE;
118684
119216
  //# sourceMappingURL=unsecure_fae.js.map
@@ -122891,6 +123423,9 @@ class CDSMetadata {
122891
123423
  }
122892
123424
  }
122893
123425
  }
123426
+ else if (def instanceof cds.CDSDefineHierarchy) {
123427
+ this.hierarchy(root, result);
123428
+ }
122894
123429
  else {
122895
123430
  this.signature(root, result);
122896
123431
  }
@@ -122931,7 +123466,7 @@ class CDSMetadata {
122931
123466
  // the first name is the projection's own, the second the projected entity
122932
123467
  const name = root.findDirectExpressions(cds.CDSName)[1];
122933
123468
  if (name) {
122934
- ret.push(name.concatTokens().toUpperCase());
123469
+ ret.push(name.concatTokens().replace(/ /g, "").toUpperCase());
122935
123470
  }
122936
123471
  }
122937
123472
  for (const s of root.findAllExpressions(cds.CDSSource)) {
@@ -123020,7 +123555,7 @@ class CDSMetadata {
123020
123555
  return undefined;
123021
123556
  }
123022
123557
  const rest = children.slice(to + 1).map(c => c.concatTokens().toUpperCase());
123023
- const target = children.slice(to + 1).find(c => c.get() instanceof cds.CDSName)?.concatTokens();
123558
+ const target = children.slice(to + 1).find(c => c.get() instanceof cds.CDSName)?.concatTokens().replace(/ /g, "");
123024
123559
  if (target === undefined) {
123025
123560
  return undefined;
123026
123561
  }
@@ -123033,6 +123568,52 @@ class CDSMetadata {
123033
123568
  }
123034
123569
  return { target, type };
123035
123570
  }
123571
+ /** hierarchies list their elements directly under the root, after the "{" and separated by ",":
123572
+ * [annotations] [KEY] path [AS alias]. Associations of the SOURCE entity can be exposed. */
123573
+ hierarchy(root, result) {
123574
+ const children = root.getChildren();
123575
+ const token = (c) => c instanceof abaplint.Nodes.TokenNode ? c.getFirstToken().getStr().toUpperCase() : "";
123576
+ const source = children[children.findIndex(c => token(c) === "SOURCE") + 1];
123577
+ const sources = source?.get() instanceof cds.CDSName ? [source.concatTokens().toUpperCase()] : [];
123578
+ let annotations = [];
123579
+ let key = false;
123580
+ let path = [];
123581
+ let as;
123582
+ for (const child of children.slice(children.findIndex(c => token(c) === "{") + 1)) {
123583
+ const text = token(child);
123584
+ if (child.get() instanceof cds.CDSAnnotation) {
123585
+ annotations.push(CDSMetadata.annotation(child));
123586
+ }
123587
+ else if (text === "KEY") {
123588
+ key = true;
123589
+ }
123590
+ else if (child.get() instanceof cds.CDSPrefixedName) {
123591
+ path = child.findAllExpressions(cds.CDSName).map(n => n.concatTokens());
123592
+ }
123593
+ else if (child.get() instanceof cds.CDSAs) {
123594
+ as = this.alias(child);
123595
+ }
123596
+ else if (text === "," || text === "}") {
123597
+ if (path.length > 0) {
123598
+ const name = as ?? path[path.length - 1];
123599
+ const inherited = this.sourceAssociation(sources, path[path.length - 1]);
123600
+ if (inherited) {
123601
+ result.associations.push({ ...inherited, name, exposed: true, annotations });
123602
+ }
123603
+ else {
123604
+ result.fields.push({ name, key, virtual: false, annotations });
123605
+ }
123606
+ }
123607
+ annotations = [];
123608
+ key = false;
123609
+ path = [];
123610
+ as = undefined;
123611
+ if (text === "}") {
123612
+ return;
123613
+ }
123614
+ }
123615
+ }
123616
+ }
123036
123617
  /** abstract and custom entities and table functions list their elements inline: name : type ; */
123037
123618
  signature(root, result) {
123038
123619
  let inBody = false;
@@ -125118,7 +125699,8 @@ const constant_1 = __webpack_require__(/*! ./constant */ "./node_modules/@abapli
125118
125699
  class CallTransformationParametersTranspiler {
125119
125700
  transpile(node, traversal) {
125120
125701
  if (node.getFirstChild()?.get() instanceof abaplint.Expressions.Dynamic) {
125121
- return new chunk_1.Chunk().append(node.concatTokens(), node, traversal);
125702
+ // a dynamic parameter table named with its body suffix: (lt_x[])
125703
+ return new chunk_1.Chunk().append(node.concatTokens().replace(/\[\]\s*\)$/, ")"), node, traversal);
125122
125704
  }
125123
125705
  else {
125124
125706
  const res = new chunk_1.Chunk().appendString("{");
@@ -125237,6 +125819,11 @@ class CompareTranspiler {
125237
125819
  else if (concat.endsWith("IS ASSIGNED")) {
125238
125820
  return new chunk_1.Chunk().appendString("abap.compare.assigned(").appendChunk(s0).appendString(")");
125239
125821
  }
125822
+ // a table parameter is often named with its body suffix (it_x[] IS
125823
+ // SUPPLIED): the parameter is it_x, "[]" is no part of a JS name
125824
+ if (/ IS (NOT )?(SUPPLIED|REQUESTED)$/.test(concat)) {
125825
+ concat = concat.replace(/\[\](?= IS )/, "");
125826
+ }
125240
125827
  if (concat.endsWith(" IS SUPPLIED")) {
125241
125828
  if (concat.startsWith("NOT ")) {
125242
125829
  concat = concat.replace("NOT ", "");
@@ -128437,11 +129024,12 @@ const let_1 = __webpack_require__(/*! ./let */ "./node_modules/@abaplint/transpi
128437
129024
  const value_body_1 = __webpack_require__(/*! ./value_body */ "./node_modules/@abaplint/transpiler/build/src/expressions/value_body.js");
128438
129025
  class SourceTranspiler {
128439
129026
  addGet;
128440
- int8;
128441
- /** int8: the calculation type is int8, each operation gets its left operand as an int8 */
128442
- constructor(addGet = false, int8 = false) {
129027
+ calculation;
129028
+ /** calculation: the calculation type the target gives integer operands, each operation
129029
+ * gets its left operand as an int8, or as a decfloat34 when the target is p, f or decfloat34 */
129030
+ constructor(addGet = false, calculation) {
128443
129031
  this.addGet = addGet;
128444
- this.int8 = int8;
129032
+ this.calculation = calculation;
128445
129033
  }
128446
129034
  // the operands of a chain of & / && (the rearranger leaves them as a binary
128447
129035
  // tree of Source nodes); an empty list when the node is not such a chain
@@ -128509,8 +129097,8 @@ class SourceTranspiler {
128509
129097
  break;
128510
129098
  }
128511
129099
  }
128512
- // int8: whether the operand left of the next operator is already an int8
128513
- let leftIsInt8 = false;
129100
+ // whether the operand left of the next operator already has the calculation type
129101
+ let leftIsCalculation = false;
128514
129102
  for (let i = startIdx; i < children.length; i++) {
128515
129103
  const c = children[i];
128516
129104
  const isLast = i === children.length - 1;
@@ -128536,17 +129124,18 @@ class SourceTranspiler {
128536
129124
  prefixNegated = false;
128537
129125
  }
128538
129126
  // "/" rounds in calculation type int8, the runtime's divide() does not know the target
128539
- const operator = this.int8 === true && c.concatTokens().trim() === "/"
129127
+ const operator = this.calculation === "int8" && c.concatTokens().trim() === "/"
128540
129128
  ? new chunk_1.Chunk().append("abap.operators.divideInt8", c, traversal)
128541
129129
  : traversal.traverse(c);
128542
- if (this.int8 === true && leftIsInt8 === false) {
128543
- ret = new chunk_1.Chunk().appendChunk(operator).appendString("(new abap.types.Integer8().set(").appendChunk(ret).appendString("),");
129130
+ if (this.calculation !== undefined && leftIsCalculation === false) {
129131
+ const type = this.calculation === "int8" ? "Integer8" : "DecFloat34";
129132
+ ret = new chunk_1.Chunk().appendChunk(operator).appendString(`(new abap.types.${type}().set(`).appendChunk(ret).appendString("),");
128544
129133
  }
128545
129134
  else {
128546
129135
  ret = new chunk_1.Chunk().appendChunk(operator).appendString("(").appendChunk(ret).appendString(",");
128547
129136
  }
128548
- // the result of an operation with an int8 operand is an int8
128549
- leftIsInt8 = true;
129137
+ // the result of an operation with an int8 or decfloat34 operand has that type
129138
+ leftIsCalculation = true;
128550
129139
  post.appendString(")");
128551
129140
  if (this.addGet) {
128552
129141
  post.append(".get()", c, traversal);
@@ -128563,8 +129152,8 @@ class SourceTranspiler {
128563
129152
  }
128564
129153
  }
128565
129154
  else if (c.get() instanceof core_1.Expressions.Source) {
128566
- ret.appendChunk(new SourceTranspiler(this.addGet, this.int8).transpile(c, traversal));
128567
- leftIsInt8 = c.findDirectExpression(core_1.Expressions.ArithOperator) !== undefined;
129155
+ ret.appendChunk(new SourceTranspiler(this.addGet, this.calculation).transpile(c, traversal));
129156
+ leftIsCalculation = c.findDirectExpression(core_1.Expressions.ArithOperator) !== undefined;
128568
129157
  }
128569
129158
  else if (c.get() instanceof core_1.Expressions.Arrow) {
128570
129159
  ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(").get().");
@@ -131488,7 +132077,8 @@ class HandleABAP {
131488
132077
  output.chunk.runIndentationLogic(this.options?.ignoreSourceMap);
131489
132078
  }
131490
132079
  if (this.options?.addCommonJS === true) {
131491
- ret.map(output => output.chunk = this.addImportsAndExports(output));
132080
+ const owner = this.findOwnerRequiredByLocals(obj, ret);
132081
+ ret.map(output => output.chunk = this.addImportsAndExports(output, owner));
131492
132082
  }
131493
132083
  return ret;
131494
132084
  }
@@ -131542,8 +132132,33 @@ class HandleABAP {
131542
132132
  }
131543
132133
  return ret;
131544
132134
  }
131545
- addImportsAndExports(output) {
132135
+ /** A local class inheriting from its own global class: the locals module needs the owner
132136
+ * defined, and the owner module awaits the locals before it is defined. Under top-level await
132137
+ * that import cycle never settles. When the locals require the owner, the locals take it from
132138
+ * abap.Classes and the owner imports its locals right after registering itself, still before its
132139
+ * static values and class constructors, which may use the locals */
132140
+ findOwnerRequiredByLocals(obj, output) {
132141
+ if (!(obj instanceof abaplint.Objects.Class)) {
132142
+ return undefined;
132143
+ }
132144
+ const main = obj.getMainABAPFile()?.getFilename().replace(".abap", ".mjs").toLowerCase();
132145
+ const locals = output.find(o => o.filename.endsWith(".clas.locals.mjs"));
132146
+ if (main === undefined || locals === undefined
132147
+ || locals.requires.some(r => r.filename.replace(".abap", ".mjs").toLowerCase() === main) === false) {
132148
+ return undefined;
132149
+ }
132150
+ const name = obj.getName();
132151
+ return {
132152
+ main: main,
132153
+ locals: locals.filename,
132154
+ registration: "abap.Classes['" + name.toUpperCase() + "'] = " + traversal_1.Traversal.escapeNamespace(name.toLowerCase()) + ";",
132155
+ lookup: "abap.Classes['" + name.toUpperCase() + "']",
132156
+ };
132157
+ }
132158
+ addImportsAndExports(output, deferred) {
131546
132159
  const contents = new chunk_1.Chunk();
132160
+ const isMain = deferred !== undefined && output.filename === deferred.main;
132161
+ const isLocals = deferred !== undefined && output.filename === deferred.locals;
131547
132162
  for (const r of output.requires) {
131548
132163
  const name = r.name?.toLowerCase();
131549
132164
  const filename = r.filename.replace(".abap", ".mjs");
@@ -131551,6 +132166,18 @@ class HandleABAP {
131551
132166
  continue;
131552
132167
  }
131553
132168
  const specifier = (0, output_layout_1.importPath)(this.layout.file(output.object, output.filename), this.layout.sourceModule(r.filename));
132169
+ if (isMain && filename.toLowerCase() === deferred.locals) {
132170
+ const occurrences = output.chunk.getCode().split(deferred.registration).length - 1;
132171
+ if (occurrences !== 1) {
132172
+ throw new Error("HandleABAP, class registration not found once in " + output.filename + ", cannot defer its locals");
132173
+ }
132174
+ output.chunk.replaceAll(deferred.registration, deferred.registration + "\nawait import(\"" + specifier + "\");");
132175
+ continue;
132176
+ }
132177
+ else if (isLocals && filename.toLowerCase() === deferred.main && name) {
132178
+ contents.appendString("const " + traversal_1.Traversal.escapeNamespace(name) + " = " + deferred.lookup + ";\n");
132179
+ continue;
132180
+ }
131554
132181
  if (name) {
131555
132182
  contents.appendString("const {" + traversal_1.Traversal.escapeNamespace(name) + "} = await import(\"" + specifier + "\");\n");
131556
132183
  }
@@ -131653,13 +132280,13 @@ class HandleDataDefinition {
131653
132280
  const cds = this.metadata.build(obj);
131654
132281
  const type = this.withoutAssociations(obj.parseType(reg), cds);
131655
132282
  const typeFactory = new type_factory_registry_1.TypeFactoryRegistry(filename);
131656
- const body = `abap.DDIC["${obj.getName().toUpperCase()}"] = {
131657
- "objectType": "DDLS",
131658
- "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type, typeFactory)},
131659
- "keyFields": ${JSON.stringify(cds?.fields.filter(f => f.key).map(f => f.name.toUpperCase()) ?? [])},
131660
- "description": ${JSON.stringify(obj.getDescription())},
131661
- "sqlViewName": ${JSON.stringify(obj.getSQLViewName())},
131662
- "cds": ${JSON.stringify(cds)},
132283
+ const body = `abap.DDIC["${obj.getName().toUpperCase()}"] = {
132284
+ "objectType": "DDLS",
132285
+ "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type, typeFactory)},
132286
+ "keyFields": ${JSON.stringify(cds?.fields.filter(f => f.key).map(f => f.name.toUpperCase()) ?? [])},
132287
+ "description": ${JSON.stringify(obj.getDescription())},
132288
+ "sqlViewName": ${JSON.stringify(obj.getSQLViewName())},
132289
+ "cds": ${JSON.stringify(cds)},
131663
132290
  };`;
131664
132291
  const chunk = new chunk_1.Chunk(body);
131665
132292
  const helpers = typeFactory.finalize(chunk);
@@ -131726,6 +132353,9 @@ class HandleDataElement {
131726
132353
  "objectType": "DTEL",
131727
132354
  "type": ${transpile_types_1.TranspileTypes.toTypeFunction(type, typeFactory)},
131728
132355
  "domain": ${JSON.stringify(obj.getDomainName())},
132356
+ "datatype": ${JSON.stringify(obj.getDataType(reg))},
132357
+ "length": ${JSON.stringify(obj.getLength(reg))},
132358
+ "decimals": ${JSON.stringify(obj.getDecimals(reg))},
131729
132359
  "fixedValues": ${JSON.stringify(fixedValues)},
131730
132360
  "description": ${JSON.stringify(obj.getDescription())},
131731
132361
  };`;
@@ -132656,12 +133286,12 @@ class Initialization {
132656
133286
  script(reg, dbSetup, options, useImport) {
132657
133287
  let ret = "";
132658
133288
  if (useImport === true) {
132659
- ret = `/* eslint-disable import/newline-after-import */
133289
+ ret = `/* eslint-disable import/newline-after-import */
132660
133290
  import "./_top.mjs";\n`;
132661
133291
  }
132662
133292
  else {
132663
- ret = `/* eslint-disable import/newline-after-import */
132664
- import runtime from "@abaplint/runtime";
133293
+ ret = `/* eslint-disable import/newline-after-import */
133294
+ import runtime from "@abaplint/runtime";
132665
133295
  globalThis.abap = new runtime.ABAP();\n`;
132666
133296
  }
132667
133297
  if (options?.setup?.filename === undefined || options?.setup?.filename === "") {
@@ -141720,8 +142350,9 @@ class MoveTranspiler {
141720
142350
  ? this.correspondingGeneric(sourceExpression, targets[0], traversal)
141721
142351
  : undefined;
141722
142352
  if (source === undefined) {
141723
- source = this.isInt8Calculation(node, sourceExpression, targetExpressions.length, traversal)
141724
- ? new source_1.SourceTranspiler(false, true).transpile(sourceExpression, traversal)
142353
+ const calculation = this.integerCalculation(node, sourceExpression, targetExpressions.length, traversal);
142354
+ source = calculation !== undefined
142355
+ ? new source_1.SourceTranspiler(false, calculation).transpile(sourceExpression, traversal)
141725
142356
  : traversal.traverse(sourceExpression);
141726
142357
  }
141727
142358
  switch (second) {
@@ -141806,20 +142437,35 @@ class MoveTranspiler {
141806
142437
  // when the target or an operand is int8: i * i into int8 is exact up to 2^62, and "/"
141807
142438
  // rounds. The runtime decides by the operands alone and does not know the target, so here
141808
142439
  // the operands are converted to int8 before the calculation. Only for an i or int8 target
141809
- // and operands whose type is known to be i or int8, and not for **, which counts as f
141810
- isInt8Calculation(node, source, targets, traversal) {
142440
+ // and operands whose type is known to be i or int8, and not for **, which counts as f.
142441
+ // With a p, f or decfloat34 target the calculation type is that of the target, and an int8
142442
+ // result outside the int8 range is no overflow: the operands are converted to decfloat34,
142443
+ // exact for sums, differences and products of int8, so the runtime does not raise for them
142444
+ integerCalculation(node, source, targets, traversal) {
141811
142445
  if (source === undefined
141812
142446
  || targets !== 1
141813
142447
  || source.findFirstExpression(abaplint.Expressions.ArithOperator) === undefined) {
141814
- return false;
142448
+ return undefined;
141815
142449
  }
141816
142450
  const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
141817
142451
  const target = traversal.determineType(node, scope);
142452
+ const wide = target instanceof abaplint.BasicTypes.PackedType
142453
+ || target instanceof abaplint.BasicTypes.FloatType
142454
+ || target instanceof abaplint.BasicTypes.DecFloat34Type;
141818
142455
  const found = { int8: target instanceof abaplint.BasicTypes.Integer8Type };
141819
- if (found.int8 === false && !(target instanceof abaplint.BasicTypes.IntegerType)) {
141820
- return false;
142456
+ if (found.int8 === false && wide === false && !(target instanceof abaplint.BasicTypes.IntegerType)) {
142457
+ return undefined;
141821
142458
  }
141822
- return this.integerOperands(source, scope, found) && found.int8;
142459
+ else if (this.integerOperands(source, scope, found) === false || found.int8 === false) {
142460
+ return undefined;
142461
+ }
142462
+ else if (wide === true) {
142463
+ // DIV and MOD of a decfloat34 go through a double in the runtime, they stay int8
142464
+ const divMod = source.findAllExpressions(abaplint.Expressions.ArithOperator)
142465
+ .some(o => ["DIV", "MOD"].includes(o.concatTokens().toUpperCase()));
142466
+ return divMod ? undefined : "decfloat34";
142467
+ }
142468
+ return "int8";
141823
142469
  }
141824
142470
  integerOperands(node, scope, found) {
141825
142471
  for (const c of node.getChildren()) {
@@ -144243,9 +144889,12 @@ abap.builtin.sy.get().dbcnt.set(${target}.getArrayLength());
144243
144889
  + ` : ${code}.get())`;
144244
144890
  }
144245
144891
  dynamicSQLClause(keyword, code) {
144892
+ // a dynamic ORDER BY may separate its columns with blanks, as Open SQL
144893
+ // allows; abap.dynamicOrderBy puts the commas SQL needs between them
144894
+ const list = (text) => keyword === "ORDER BY" ? `abap.dynamicOrderBy(${text})` : text;
144246
144895
  return `(${code} instanceof abap.types.Table || ${code} instanceof abap.types.HashedTable`
144247
- + ` ? (${code}.array().length === 0 ? "" : "${keyword} " + ${code}.array().map(row => row.get()).join(", "))`
144248
- + ` : (("" + ${code}.get()).trim() === "" ? "" : "${keyword} " + ${code}.get()))`;
144896
+ + ` ? (${code}.array().length === 0 ? "" : "${keyword} " + ${list(`${code}.array().map(row => row.get()).join(", ")`)})`
144897
+ + ` : (("" + ${code}.get()).trim() === "" ? "" : "${keyword} " + ${list(`${code}.get()`)}))`;
144249
144898
  }
144250
144899
  dynamicHavingClause(code) {
144251
144900
  return `((value) => {