@abaplint/core 2.93.79 → 2.93.81

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.
@@ -63,7 +63,7 @@ class Registry {
63
63
  }
64
64
  static abaplintVersion() {
65
65
  // magic, see build script "version.sh"
66
- return "2.93.79";
66
+ return "2.93.81";
67
67
  }
68
68
  getDDICReferences() {
69
69
  return this.references;
@@ -24,6 +24,7 @@ const tokens_1 = require("../abap/1_lexer/tokens");
24
24
  const include_graph_1 = require("../utils/include_graph");
25
25
  const objects_1 = require("../objects");
26
26
  const _builtin_1 = require("../abap/5_syntax/_builtin");
27
+ const _scope_type_1 = require("../abap/5_syntax/_scope_type");
27
28
  // todo: refactor each sub-rule to new classes?
28
29
  // todo: add configuration
29
30
  class DownportConf extends _basic_rule_config_1.BasicRuleConfig {
@@ -1459,28 +1460,40 @@ ${indentation} output = ${topTarget}.`;
1459
1460
  return undefined;
1460
1461
  }
1461
1462
  outlineFor(forLoop, indentation, lowFile, highSyntax) {
1462
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1463
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1463
1464
  let body = "";
1464
1465
  let end = "";
1465
1466
  const loopSource = (_a = forLoop.findFirstExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens();
1466
- let loopTargetField = (_b = forLoop.findFirstExpression(Expressions.TargetField)) === null || _b === void 0 ? void 0 : _b.concatTokens();
1467
- const of = (_c = forLoop.findExpressionAfterToken("OF")) === null || _c === void 0 ? void 0 : _c.concatTokens();
1467
+ let loopTargetFieldExpression = forLoop.findFirstExpression(Expressions.TargetField);
1468
+ let loopTargetFieldName = loopTargetFieldExpression === null || loopTargetFieldExpression === void 0 ? void 0 : loopTargetFieldExpression.concatTokens();
1469
+ const of = forLoop.findExpressionAfterToken("OF");
1468
1470
  if (of !== undefined) {
1469
- loopTargetField = of;
1470
- }
1471
- if (((_e = (_d = forLoop.findDirectExpression(Expressions.InlineLoopDefinition)) === null || _d === void 0 ? void 0 : _d.getFirstChild()) === null || _e === void 0 ? void 0 : _e.get()) instanceof Expressions.TargetFieldSymbol) {
1472
- loopTargetField = undefined;
1471
+ loopTargetFieldExpression = of;
1472
+ loopTargetFieldName = of === null || of === void 0 ? void 0 : of.concatTokens();
1473
+ }
1474
+ if (((_c = (_b = forLoop.findDirectExpression(Expressions.InlineLoopDefinition)) === null || _b === void 0 ? void 0 : _b.getFirstChild()) === null || _c === void 0 ? void 0 : _c.get()) instanceof Expressions.TargetFieldSymbol) {
1475
+ loopTargetFieldExpression = undefined;
1476
+ loopTargetFieldName = undefined;
1477
+ }
1478
+ if (loopTargetFieldExpression) {
1479
+ const start = loopTargetFieldExpression.getFirstToken().getStart();
1480
+ const spag = highSyntax.spaghetti.lookupPosition(start, lowFile.getFilename());
1481
+ if (loopTargetFieldName && spag) {
1482
+ if (this.isDuplicateName(spag, loopTargetFieldName, start)) {
1483
+ this.renameVariable(spag, loopTargetFieldName, start, lowFile, highSyntax);
1484
+ }
1485
+ }
1473
1486
  }
1474
- let cond = ((_f = forLoop.findDirectExpression(Expressions.ComponentCond)) === null || _f === void 0 ? void 0 : _f.concatTokens()) || "";
1487
+ let cond = ((_d = forLoop.findDirectExpression(Expressions.ComponentCond)) === null || _d === void 0 ? void 0 : _d.concatTokens()) || "";
1475
1488
  if (cond !== "") {
1476
1489
  cond = " WHERE " + cond;
1477
1490
  }
1478
1491
  const loop = forLoop.findDirectExpression(Expressions.InlineLoopDefinition);
1479
- const indexInto = (_g = loop === null || loop === void 0 ? void 0 : loop.findExpressionAfterToken("INTO")) === null || _g === void 0 ? void 0 : _g.concatTokens();
1492
+ const indexInto = (_e = loop === null || loop === void 0 ? void 0 : loop.findExpressionAfterToken("INTO")) === null || _e === void 0 ? void 0 : _e.concatTokens();
1480
1493
  if (forLoop.findDirectTokenByText("UNTIL")
1481
1494
  || forLoop.findDirectTokenByText("WHILE")) {
1482
1495
  const fieldDef = forLoop.findDirectExpression(Expressions.InlineFieldDefinition);
1483
- const field = (_h = fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.findFirstExpression(Expressions.Field)) === null || _h === void 0 ? void 0 : _h.concatTokens();
1496
+ const field = (_f = fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.findFirstExpression(Expressions.Field)) === null || _f === void 0 ? void 0 : _f.concatTokens();
1484
1497
  const indexBackup = this.uniqueName(forLoop.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
1485
1498
  body += indentation + "DATA " + field + " TYPE i.\n";
1486
1499
  const second = fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.getChildren()[2];
@@ -1502,10 +1515,10 @@ ${indentation} output = ${topTarget}.`;
1502
1515
  }
1503
1516
  end += indentation + "ENDWHILE";
1504
1517
  }
1505
- else if (loopTargetField !== undefined) {
1506
- let from = (_j = forLoop.findExpressionAfterToken("FROM")) === null || _j === void 0 ? void 0 : _j.concatTokens();
1518
+ else if (loopTargetFieldName !== undefined) {
1519
+ let from = (_g = forLoop.findExpressionAfterToken("FROM")) === null || _g === void 0 ? void 0 : _g.concatTokens();
1507
1520
  from = from ? " FROM " + from : "";
1508
- let to = (_k = forLoop.findExpressionAfterToken("TO")) === null || _k === void 0 ? void 0 : _k.concatTokens();
1521
+ let to = (_h = forLoop.findExpressionAfterToken("TO")) === null || _h === void 0 ? void 0 : _h.concatTokens();
1509
1522
  to = to ? " TO " + to : "";
1510
1523
  let gby = "";
1511
1524
  for (const lg of forLoop.findDirectExpressions(Expressions.LoopGroupByComponent)) {
@@ -1542,19 +1555,19 @@ ${indentation} output = ${topTarget}.`;
1542
1555
  inGroup = "-items";
1543
1556
  }
1544
1557
  let into = "INTO DATA";
1545
- if (loopTargetField.startsWith("<")) {
1558
+ if (loopTargetFieldName.startsWith("<")) {
1546
1559
  into = "ASSIGNING FIELD-SYMBOL";
1547
1560
  }
1548
1561
  // todo, also backup sy-index / sy-tabix here?
1549
- body += indentation + `LOOP AT ${loopSource}${inGroup} ${into}(${loopTargetField})${from}${to}${cond}${gby}.\n`;
1562
+ body += indentation + `LOOP AT ${loopSource}${inGroup} ${into}(${loopTargetFieldName})${from}${to}${cond}${gby}.\n`;
1550
1563
  if (indexInto) {
1551
1564
  body += indentation + " DATA(" + indexInto + ") = sy-tabix.\n";
1552
1565
  }
1553
1566
  end = "ENDLOOP";
1554
1567
  }
1555
- else if (loopTargetField === undefined) {
1568
+ else if (loopTargetFieldName === undefined) {
1556
1569
  // todo, also backup sy-index / sy-tabix here?
1557
- const loopTargetFieldSymbol = (_l = forLoop.findFirstExpression(Expressions.TargetFieldSymbol)) === null || _l === void 0 ? void 0 : _l.concatTokens();
1570
+ const loopTargetFieldSymbol = (_j = forLoop.findFirstExpression(Expressions.TargetFieldSymbol)) === null || _j === void 0 ? void 0 : _j.concatTokens();
1558
1571
  body += indentation + `LOOP AT ${loopSource} ASSIGNING FIELD-SYMBOL(${loopTargetFieldSymbol})${cond}.\n`;
1559
1572
  if (indexInto) {
1560
1573
  body += indentation + " DATA(" + indexInto + ") = sy-tabix.\n";
@@ -1934,9 +1947,15 @@ ${indentation} output = ${topTarget}.`;
1934
1947
  renameVariable(spag, name, pos, lowFile, highSyntax) {
1935
1948
  var _a, _b;
1936
1949
  const uniqueName = this.uniqueName(pos, lowFile.getFilename(), highSyntax);
1950
+ const positions = new Set();
1937
1951
  let fix = undefined;
1938
1952
  for (const r of spag.getData().references) {
1939
1953
  if (((_a = r.resolved) === null || _a === void 0 ? void 0 : _a.getName()) === name && ((_b = r.resolved) === null || _b === void 0 ? void 0 : _b.getStart().equals(pos))) {
1954
+ const key = JSON.stringify(r.position.getStart());
1955
+ if (positions.has(key)) {
1956
+ continue;
1957
+ }
1958
+ positions.add(key);
1940
1959
  const replace = edit_helper_1.EditHelper.replaceRange(lowFile, r.position.getStart(), r.position.getEnd(), uniqueName);
1941
1960
  if (fix === undefined) {
1942
1961
  fix = replace;
@@ -1949,16 +1968,29 @@ ${indentation} output = ${topTarget}.`;
1949
1968
  const issue = issue_1.Issue.atPosition(lowFile, pos, "Rename before outline", this.getMetadata().key, this.conf.severity, fix);
1950
1969
  throw new SkipToNextFile(issue);
1951
1970
  }
1952
- isDuplicateName(spag, name, pos) {
1953
- var _a;
1954
- let isDuplicate = false;
1955
- for (const child of ((_a = spag.getParent()) === null || _a === void 0 ? void 0 : _a.getChildren()) || []) {
1956
- const found = child.findVariable(name);
1957
- if ((found === null || found === void 0 ? void 0 : found.getStart().equals(pos)) === false) {
1958
- isDuplicate = true;
1971
+ findRecursiveDuplicate(spag, name, skip) {
1972
+ const found = spag.findVariable(name);
1973
+ if ((found === null || found === void 0 ? void 0 : found.getStart().equals(skip)) === false) {
1974
+ return found;
1975
+ }
1976
+ for (const child of (spag === null || spag === void 0 ? void 0 : spag.getChildren()) || []) {
1977
+ const sub = this.findRecursiveDuplicate(child, name, skip);
1978
+ if (sub) {
1979
+ return sub;
1959
1980
  }
1960
1981
  }
1961
- return isDuplicate;
1982
+ return undefined;
1983
+ }
1984
+ isDuplicateName(spag, name, pos) {
1985
+ let parent = spag.getParent();
1986
+ while ((parent === null || parent === void 0 ? void 0 : parent.getIdentifier().stype) === _scope_type_1.ScopeType.Let
1987
+ || (parent === null || parent === void 0 ? void 0 : parent.getIdentifier().stype) === _scope_type_1.ScopeType.For) {
1988
+ parent = parent.getParent();
1989
+ }
1990
+ if (parent === undefined) {
1991
+ return undefined;
1992
+ }
1993
+ return this.findRecursiveDuplicate(parent, name, pos) !== undefined;
1962
1994
  }
1963
1995
  findType(i, lowFile, highSyntax, ref = false) {
1964
1996
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.93.79",
3
+ "version": "2.93.81",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",