@abaplint/core 2.93.81 → 2.93.83
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.
|
@@ -8,11 +8,23 @@ const component_compare_1 = require("../expressions/component_compare");
|
|
|
8
8
|
const component_cond_1 = require("../expressions/component_cond");
|
|
9
9
|
class DeleteInternal {
|
|
10
10
|
runSyntax(node, scope, filename) {
|
|
11
|
+
var _a;
|
|
11
12
|
for (const s of node.findDirectExpressions(Expressions.Source)) {
|
|
12
13
|
new source_1.Source().runSyntax(s, scope, filename);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const target = node.findDirectExpression(Expressions.Target);
|
|
16
|
+
if (target) {
|
|
17
|
+
let tabl = undefined;
|
|
18
|
+
if (node.getChildren().length === 5 && node.getChildren()[2].concatTokens().toUpperCase() === "FROM") {
|
|
19
|
+
// it might be a database table
|
|
20
|
+
tabl = (_a = scope.getDDIC()) === null || _a === void 0 ? void 0 : _a.lookupTableOrView(target.concatTokens());
|
|
21
|
+
if (tabl) {
|
|
22
|
+
scope.getDDICReferences().addUsing(scope.getParentObj(), { object: tabl.object });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (tabl === undefined) {
|
|
26
|
+
new target_1.Target().runSyntax(target, scope, filename);
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
for (const t of node.findDirectExpressions(Expressions.ComponentCompare)) {
|
|
18
30
|
new component_compare_1.ComponentCompare().runSyntax(t, scope, filename);
|
package/build/src/registry.js
CHANGED
|
@@ -36,6 +36,83 @@ class SkipToNextFile extends Error {
|
|
|
36
36
|
this.issue = issue;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
class SpagHelper {
|
|
40
|
+
constructor(spag) {
|
|
41
|
+
this.spag = spag;
|
|
42
|
+
}
|
|
43
|
+
renameVariable(oldName, pos, lowFile, newName) {
|
|
44
|
+
let fix = undefined;
|
|
45
|
+
const references = this.findReferences(oldName, pos);
|
|
46
|
+
references.sort((a, b) => {
|
|
47
|
+
if (a.start.equals(b.start)) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
return a.start.isAfter(b.start) ? 1 : -1;
|
|
51
|
+
});
|
|
52
|
+
for (const r of references) {
|
|
53
|
+
const replace = edit_helper_1.EditHelper.replaceRange(lowFile, r.start, r.end, newName);
|
|
54
|
+
if (fix === undefined) {
|
|
55
|
+
fix = replace;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
fix = edit_helper_1.EditHelper.merge(replace, fix);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return fix;
|
|
62
|
+
}
|
|
63
|
+
findReferences(name, pos) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const positions = [];
|
|
66
|
+
function has(element) {
|
|
67
|
+
return positions.some(a => a.start.equals(element.start));
|
|
68
|
+
}
|
|
69
|
+
for (const r of this.spag.getData().references) {
|
|
70
|
+
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))) {
|
|
71
|
+
const sub = {
|
|
72
|
+
start: r.position.getStart(),
|
|
73
|
+
end: r.position.getEnd(),
|
|
74
|
+
};
|
|
75
|
+
if (has(sub) === false) {
|
|
76
|
+
positions.push(sub);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const child of this.spag.getChildren()) {
|
|
81
|
+
const subPositions = new SpagHelper(child).findReferences(name, pos);
|
|
82
|
+
for (const sub of subPositions) {
|
|
83
|
+
if (has(sub) === false) {
|
|
84
|
+
positions.push(sub);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return positions;
|
|
89
|
+
}
|
|
90
|
+
findRecursiveDuplicate(name, skip) {
|
|
91
|
+
var _a;
|
|
92
|
+
const found = this.spag.findVariable(name);
|
|
93
|
+
if ((found === null || found === void 0 ? void 0 : found.getStart().equals(skip)) === false) {
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
for (const child of ((_a = this.spag) === null || _a === void 0 ? void 0 : _a.getChildren()) || []) {
|
|
97
|
+
const sub = new SpagHelper(child).findRecursiveDuplicate(name, skip);
|
|
98
|
+
if (sub) {
|
|
99
|
+
return sub;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
isDuplicateName(name, pos) {
|
|
105
|
+
let parent = this.spag.getParent();
|
|
106
|
+
while ((parent === null || parent === void 0 ? void 0 : parent.getIdentifier().stype) === _scope_type_1.ScopeType.Let
|
|
107
|
+
|| (parent === null || parent === void 0 ? void 0 : parent.getIdentifier().stype) === _scope_type_1.ScopeType.For) {
|
|
108
|
+
parent = parent.getParent();
|
|
109
|
+
}
|
|
110
|
+
if (parent === undefined) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return new SpagHelper(parent).findRecursiveDuplicate(name, pos) !== undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
39
116
|
class Downport {
|
|
40
117
|
constructor() {
|
|
41
118
|
this.conf = new DownportConf();
|
|
@@ -1479,7 +1556,7 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1479
1556
|
const start = loopTargetFieldExpression.getFirstToken().getStart();
|
|
1480
1557
|
const spag = highSyntax.spaghetti.lookupPosition(start, lowFile.getFilename());
|
|
1481
1558
|
if (loopTargetFieldName && spag) {
|
|
1482
|
-
if (
|
|
1559
|
+
if (new SpagHelper(spag).isDuplicateName(loopTargetFieldName, start)) {
|
|
1483
1560
|
this.renameVariable(spag, loopTargetFieldName, start, lowFile, highSyntax);
|
|
1484
1561
|
}
|
|
1485
1562
|
}
|
|
@@ -1726,6 +1803,10 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1726
1803
|
if (firstName === "") {
|
|
1727
1804
|
firstName = name;
|
|
1728
1805
|
}
|
|
1806
|
+
const spag = highSyntax.spaghetti.lookupPosition(init.getFirstToken().getStart(), lowFile.getFilename());
|
|
1807
|
+
if (spag && new SpagHelper(spag).isDuplicateName(name, init.getFirstToken().getStart())) {
|
|
1808
|
+
this.renameVariable(spag, name, init.getFirstToken().getStart(), lowFile, highSyntax);
|
|
1809
|
+
}
|
|
1729
1810
|
const s = (_a = init.findFirstExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens();
|
|
1730
1811
|
const t = (_b = init.findFirstExpression(Expressions.TypeName)) === null || _b === void 0 ? void 0 : _b.concatTokens();
|
|
1731
1812
|
if (s) {
|
|
@@ -1765,8 +1846,9 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1765
1846
|
const abap = `DATA ${uniqueName} TYPE ${type}.\n` +
|
|
1766
1847
|
body +
|
|
1767
1848
|
indentation;
|
|
1849
|
+
const reduceEnd = i.findDirectTokenByText(")");
|
|
1768
1850
|
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getFirstToken().getStart(), abap);
|
|
1769
|
-
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, firstToken.getStart(),
|
|
1851
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, firstToken.getStart(), reduceEnd.getEnd(), uniqueName);
|
|
1770
1852
|
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
1771
1853
|
return issue_1.Issue.atToken(lowFile, firstToken, "Downport REDUCE", this.getMetadata().key, this.conf.severity, fix);
|
|
1772
1854
|
}
|
|
@@ -1924,7 +2006,7 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1924
2006
|
if (spag === undefined) {
|
|
1925
2007
|
continue;
|
|
1926
2008
|
}
|
|
1927
|
-
if (
|
|
2009
|
+
if (new SpagHelper(spag).isDuplicateName(name, c.getFirstToken().getStart())) {
|
|
1928
2010
|
this.renameVariable(spag, name, c.getFirstToken().getStart(), lowFile, highSyntax);
|
|
1929
2011
|
}
|
|
1930
2012
|
const found = spag.findVariable(name);
|
|
@@ -1945,53 +2027,11 @@ ${indentation} output = ${topTarget}.`;
|
|
|
1945
2027
|
return ret;
|
|
1946
2028
|
}
|
|
1947
2029
|
renameVariable(spag, name, pos, lowFile, highSyntax) {
|
|
1948
|
-
|
|
1949
|
-
const
|
|
1950
|
-
const positions = new Set();
|
|
1951
|
-
let fix = undefined;
|
|
1952
|
-
for (const r of spag.getData().references) {
|
|
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);
|
|
1959
|
-
const replace = edit_helper_1.EditHelper.replaceRange(lowFile, r.position.getStart(), r.position.getEnd(), uniqueName);
|
|
1960
|
-
if (fix === undefined) {
|
|
1961
|
-
fix = replace;
|
|
1962
|
-
}
|
|
1963
|
-
else {
|
|
1964
|
-
fix = edit_helper_1.EditHelper.merge(replace, fix);
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
2030
|
+
const newName = this.uniqueName(pos, lowFile.getFilename(), highSyntax);
|
|
2031
|
+
const fix = new SpagHelper(spag).renameVariable(name, pos, lowFile, newName);
|
|
1968
2032
|
const issue = issue_1.Issue.atPosition(lowFile, pos, "Rename before outline", this.getMetadata().key, this.conf.severity, fix);
|
|
1969
2033
|
throw new SkipToNextFile(issue);
|
|
1970
2034
|
}
|
|
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;
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
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;
|
|
1994
|
-
}
|
|
1995
2035
|
findType(i, lowFile, highSyntax, ref = false) {
|
|
1996
2036
|
var _a;
|
|
1997
2037
|
const expr = i.findDirectExpression(Expressions.TypeNameOrInfer);
|