@abaplint/core 2.93.19 → 2.93.21

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.
@@ -5,18 +5,10 @@ const Expressions = require("../../2_statements/expressions");
5
5
  const basic_1 = require("../../types/basic");
6
6
  const component_compare_1 = require("./component_compare");
7
7
  const inline_data_1 = require("./inline_data");
8
- const inline_fs_1 = require("./inline_fs");
8
+ const fstarget_1 = require("./fstarget");
9
9
  const target_1 = require("./target");
10
10
  class LoopGroupBy {
11
11
  runSyntax(node, scope, filename) {
12
- const components = [];
13
- for (const c of node.findDirectExpressions(Expressions.LoopGroupByComponent)) {
14
- components.push({ name: c.getFirstToken().getStr(), type: new basic_1.VoidType("todoGroupBy") });
15
- }
16
- if (components.length === 0) {
17
- return;
18
- }
19
- const sourceType = new basic_1.StructureType(components);
20
12
  for (const t of node.findAllExpressions(Expressions.Target)) {
21
13
  const inline = t.findDirectExpression(Expressions.InlineData);
22
14
  if (inline) {
@@ -26,10 +18,19 @@ class LoopGroupBy {
26
18
  new target_1.Target().runSyntax(t, scope, filename);
27
19
  }
28
20
  }
29
- const inlinefs = node.findFirstExpression(Expressions.InlineFS);
30
- if (inlinefs) {
31
- new inline_fs_1.InlineFS().runSyntax(inlinefs, scope, filename, sourceType);
21
+ for (const t of node.findAllExpressions(Expressions.FSTarget)) {
22
+ new fstarget_1.FSTarget().runSyntax(t, scope, filename, new basic_1.VoidType("todoGroupBy"));
23
+ }
24
+ /*
25
+ const components: IStructureComponent[] = [];
26
+ for (const c of node.findDirectExpressions(Expressions.LoopGroupByComponent)) {
27
+ components.push({name: c.getFirstToken().getStr(), type: new VoidType("todoGroupBy")});
28
+ }
29
+ if (components.length === 0) {
30
+ return;
32
31
  }
32
+ */
33
+ // const sourceType = new StructureType(components);
33
34
  for (const c of node.findDirectExpressions(Expressions.LoopGroupByComponent)) {
34
35
  for (const t of c.findDirectExpressions(Expressions.ComponentCompareSimple)) {
35
36
  new component_compare_1.ComponentCompare().runSyntax(t, scope, filename);
@@ -63,7 +63,7 @@ class Registry {
63
63
  }
64
64
  static abaplintVersion() {
65
65
  // magic, see build script "version.sh"
66
- return "2.93.19";
66
+ return "2.93.21";
67
67
  }
68
68
  getDDICReferences() {
69
69
  return this.references;
@@ -921,7 +921,7 @@ ${indentation}RAISE EXCEPTION ${uniqueName2}.`;
921
921
  return issue_1.Issue.atToken(lowFile, high.getFirstToken(), "Downport, simple REF move", this.getMetadata().key, this.conf.severity, fix);
922
922
  }
923
923
  downportLoopGroup(high, lowFile, highSyntax, highFile) {
924
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
924
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
925
925
  if (!(high.get() instanceof Statements.Loop)) {
926
926
  return undefined;
927
927
  }
@@ -929,11 +929,15 @@ ${indentation}RAISE EXCEPTION ${uniqueName2}.`;
929
929
  if (group === undefined) {
930
930
  return undefined;
931
931
  }
932
- const groupTargetName = ((_a = group.findFirstExpression(Expressions.TargetField)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "nameNotFound";
933
- const loopSourceName = ((_b = high.findFirstExpression(Expressions.SimpleSource2)) === null || _b === void 0 ? void 0 : _b.concatTokens()) || "nameNotFound";
934
- const loopTargetName = ((_c = high.findFirstExpression(Expressions.TargetField)) === null || _c === void 0 ? void 0 : _c.concatTokens()) || "nameNotFound";
935
- const groupTarget = ((_d = group.findDirectExpression(Expressions.LoopGroupByTarget)) === null || _d === void 0 ? void 0 : _d.concatTokens()) || "";
936
- const isReference = (_e = high.findFirstExpression(Expressions.LoopTarget)) === null || _e === void 0 ? void 0 : _e.concatTokens().toUpperCase().startsWith("REFERENCE INTO ");
932
+ const groupTargetName = ((_a = group.findFirstExpression(Expressions.TargetField)) === null || _a === void 0 ? void 0 : _a.concatTokens())
933
+ || ((_b = group.findFirstExpression(Expressions.TargetFieldSymbol)) === null || _b === void 0 ? void 0 : _b.concatTokens().replace("<", "_").replace(">", "_"))
934
+ || "nameNotFound";
935
+ const loopSourceName = ((_c = high.findFirstExpression(Expressions.SimpleSource2)) === null || _c === void 0 ? void 0 : _c.concatTokens()) || "nameNotFound";
936
+ const loopTargetName = ((_d = high.findFirstExpression(Expressions.TargetField)) === null || _d === void 0 ? void 0 : _d.concatTokens())
937
+ || ((_e = high.findFirstExpression(Expressions.TargetFieldSymbol)) === null || _e === void 0 ? void 0 : _e.concatTokens())
938
+ || "nameNotFound";
939
+ const groupTarget = ((_f = group.findDirectExpression(Expressions.LoopGroupByTarget)) === null || _f === void 0 ? void 0 : _f.concatTokens()) || "";
940
+ const isReference = (_g = high.findFirstExpression(Expressions.LoopTarget)) === null || _g === void 0 ? void 0 : _g.concatTokens().toUpperCase().startsWith("REFERENCE INTO ");
937
941
  let loopSourceRowType = "typeNotFound";
938
942
  const spag = highSyntax.spaghetti.lookupPosition(high.getFirstToken().getStart(), lowFile.getFilename());
939
943
  if (spag !== undefined) {
@@ -948,8 +952,8 @@ ${indentation}RAISE EXCEPTION ${uniqueName2}.`;
948
952
  let groupCountName = undefined;
949
953
  for (const c of group.findAllExpressions(Expressions.LoopGroupByComponent)) {
950
954
  const name = c.findFirstExpression(Expressions.ComponentName);
951
- let type = ((_f = c.findFirstExpression(Expressions.Source)) === null || _f === void 0 ? void 0 : _f.concatTokens()) || "todo";
952
- if ((_g = c.concatTokens()) === null || _g === void 0 ? void 0 : _g.toUpperCase().endsWith(" = GROUP SIZE")) {
955
+ let type = ((_h = c.findFirstExpression(Expressions.Source)) === null || _h === void 0 ? void 0 : _h.concatTokens()) || "todo";
956
+ if ((_j = c.concatTokens()) === null || _j === void 0 ? void 0 : _j.toUpperCase().endsWith(" = GROUP SIZE")) {
953
957
  type = "i";
954
958
  groupCountName = name === null || name === void 0 ? void 0 : name.concatTokens();
955
959
  }
@@ -960,13 +964,23 @@ ${indentation}RAISE EXCEPTION ${uniqueName2}.`;
960
964
  }
961
965
  code += ` ${name === null || name === void 0 ? void 0 : name.concatTokens()} TYPE ${type},\n`;
962
966
  }
967
+ const s = group.findDirectExpression(Expressions.Source);
968
+ let singleName = "";
969
+ if (s) {
970
+ let type = s.concatTokens();
971
+ type = type.replace(loopTargetName, loopSourceRowType);
972
+ type = type.replace("->", "-");
973
+ singleName = s.concatTokens().split("-")[1];
974
+ code += ` ${singleName} TYPE ${type},\n`;
975
+ condition = singleName + " = " + s.concatTokens();
976
+ }
963
977
  const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
964
978
  const uniqueFS = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
965
979
  code += ` items LIKE ${loopSourceName},
966
980
  END OF ${groupTargetName}type.
967
981
  DATA ${groupTargetName}tab TYPE STANDARD TABLE OF ${groupTargetName}type WITH DEFAULT KEY.
968
982
  DATA ${uniqueName} LIKE LINE OF ${groupTargetName}tab.
969
- LOOP AT ${loopSourceName} ${(_h = high.findFirstExpression(Expressions.LoopTarget)) === null || _h === void 0 ? void 0 : _h.concatTokens()}.
983
+ LOOP AT ${loopSourceName} ${(_k = high.findFirstExpression(Expressions.LoopTarget)) === null || _k === void 0 ? void 0 : _k.concatTokens()}.
970
984
  READ TABLE ${groupTargetName}tab ASSIGNING FIELD-SYMBOL(<${uniqueFS}>) WITH KEY ${condition}.
971
985
  IF sy-subrc = 0.\n`;
972
986
  if (groupCountName !== undefined) {
@@ -978,25 +992,28 @@ ELSE.\n`;
978
992
  for (const c of group.findAllExpressions(Expressions.LoopGroupByComponent)) {
979
993
  code += ` ${uniqueName}-${c.concatTokens().replace("GROUP SIZE", "1")}.\n`;
980
994
  }
995
+ if (singleName !== "") {
996
+ code += ` ${uniqueName}-${singleName} = ${loopTargetName}-${singleName}.\n`;
997
+ }
981
998
  code += ` INSERT ${loopTargetName}${isReference ? "->*" : ""} INTO TABLE ${uniqueName}-items.\n`;
982
999
  code += ` INSERT ${uniqueName} INTO TABLE ${groupTargetName}tab.\n`;
983
1000
  code += `ENDIF.
984
1001
  ENDLOOP.
985
1002
  LOOP AT ${groupTargetName}tab ${groupTarget}.`;
986
1003
  let fix = edit_helper_1.EditHelper.replaceRange(lowFile, high.getFirstToken().getStart(), high.getLastToken().getEnd(), code);
987
- for (const l of ((_j = highFile.getStructure()) === null || _j === void 0 ? void 0 : _j.findAllStructures(Structures.Loop)) || []) {
1004
+ for (const l of ((_l = highFile.getStructure()) === null || _l === void 0 ? void 0 : _l.findAllStructures(Structures.Loop)) || []) {
988
1005
  // make sure to find the correct/current loop statement
989
1006
  if (l.findDirectStatement(Statements.Loop) !== high) {
990
1007
  continue;
991
1008
  }
992
1009
  for (const loop of l.findAllStatements(Statements.Loop)) {
993
- if ((_k = loop.concatTokens()) === null || _k === void 0 ? void 0 : _k.toUpperCase().startsWith("LOOP AT GROUP ")) {
1010
+ if ((_m = loop.concatTokens()) === null || _m === void 0 ? void 0 : _m.toUpperCase().startsWith("LOOP AT GROUP ")) {
994
1011
  const subLoopSource = loop.findFirstExpression(Expressions.SimpleSource2);
995
1012
  if (subLoopSource === undefined) {
996
1013
  continue;
997
1014
  }
998
1015
  const subLoopSourceName = (subLoopSource === null || subLoopSource === void 0 ? void 0 : subLoopSource.concatTokens()) || "nameNotFound";
999
- const subCode = `LOOP AT ${subLoopSourceName}->items`;
1016
+ const subCode = `LOOP AT ${subLoopSourceName}${isReference ? "->" : "-"}items`;
1000
1017
  const subFix = edit_helper_1.EditHelper.replaceRange(lowFile, loop.getFirstToken().getStart(), subLoopSource.getLastToken().getEnd(), subCode);
1001
1018
  fix = edit_helper_1.EditHelper.merge(subFix, fix);
1002
1019
  }
@@ -1085,17 +1102,24 @@ LOOP AT ${groupTargetName}tab ${groupTarget}.`;
1085
1102
  return;
1086
1103
  }
1087
1104
  const valueBody = source.findDirectExpression(Expressions.ValueBody);
1088
- if (valueBody === undefined || valueBody.getChildren().length !== 1) {
1105
+ if (valueBody === undefined) {
1106
+ return;
1107
+ }
1108
+ const fieldAssignments = valueBody.findDirectExpressions(Expressions.FieldAssignment);
1109
+ if (fieldAssignments.length === 0) {
1089
1110
  return;
1090
1111
  }
1091
- const fieldAssignment = valueBody.findDirectExpression(Expressions.FieldAssignment);
1092
- if (fieldAssignment === undefined) {
1112
+ else if (fieldAssignments.length !== valueBody.getChildren().length) {
1093
1113
  return;
1094
1114
  }
1095
1115
  const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
1096
- const code = `CLEAR ${target.concatTokens()}.\n` + indentation + target.concatTokens() + "-" + fieldAssignment.concatTokens();
1116
+ let code = `CLEAR ${target.concatTokens()}.\n`;
1117
+ for (const fieldAssignment of fieldAssignments) {
1118
+ code += indentation + target.concatTokens() + "-" + fieldAssignment.concatTokens() + `.\n`;
1119
+ }
1120
+ code = code.trimEnd();
1097
1121
  const start = high.getFirstToken().getStart();
1098
- const end = high.getLastToken().getStart();
1122
+ const end = high.getLastToken().getEnd();
1099
1123
  const fix = edit_helper_1.EditHelper.replaceRange(lowFile, start, end, code);
1100
1124
  return issue_1.Issue.atToken(lowFile, high.getFirstToken(), "Downport, simple move", this.getMetadata().key, this.conf.severity, fix);
1101
1125
  }
@@ -1322,7 +1346,9 @@ ${indentation} output = ${topTarget}.`;
1322
1346
  return undefined;
1323
1347
  }
1324
1348
  const concat = node.concatTokens().toUpperCase();
1325
- if (concat.includes(" REFERENCE INTO ")) {
1349
+ if (concat.includes(" REFERENCE INTO ")
1350
+ || concat.includes(" GROUP BY ")
1351
+ || concat.startsWith("LOOP AT GROUP ")) {
1326
1352
  return undefined;
1327
1353
  }
1328
1354
  const indentation = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
@@ -1789,7 +1815,8 @@ ${indentation} output = ${topTarget}.`;
1789
1815
  }
1790
1816
  outlineFS(low, high, lowFile, highSyntax) {
1791
1817
  var _a, _b;
1792
- if (!(low.get() instanceof _statement_1.Unknown)) {
1818
+ if (!(low.get() instanceof _statement_1.Unknown)
1819
+ || (high.get() instanceof Statements.Loop)) {
1793
1820
  return undefined;
1794
1821
  }
1795
1822
  for (const i of high.findAllExpressionsRecursive(Expressions.InlineFS)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.93.19",
3
+ "version": "2.93.21",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",