@abaplint/core 2.102.11 → 2.102.13
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.
- package/build/src/registry.js +1 -1
- package/build/src/rules/downport.js +14 -6
- package/package.json +1 -1
package/build/src/registry.js
CHANGED
|
@@ -26,6 +26,7 @@ const objects_1 = require("../objects");
|
|
|
26
26
|
const _builtin_1 = require("../abap/5_syntax/_builtin");
|
|
27
27
|
const _scope_type_1 = require("../abap/5_syntax/_scope_type");
|
|
28
28
|
const statements_1 = require("../abap/2_statements/statements");
|
|
29
|
+
const crypto = require("node:crypto");
|
|
29
30
|
// todo: refactor each sub-rule to new classes?
|
|
30
31
|
// todo: add configuration
|
|
31
32
|
class DownportConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
@@ -792,7 +793,7 @@ ${indentation}`);
|
|
|
792
793
|
if (tt === undefined) {
|
|
793
794
|
return undefined;
|
|
794
795
|
}
|
|
795
|
-
const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax
|
|
796
|
+
const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
796
797
|
const code = `TYPES ${uniqueName} ${tt.concatTokens()}.\n`;
|
|
797
798
|
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), code);
|
|
798
799
|
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, tt.getFirstToken().getStart(), tt.getLastToken().getEnd(), "TYPE " + uniqueName);
|
|
@@ -2537,15 +2538,21 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
2537
2538
|
}
|
|
2538
2539
|
return undefined;
|
|
2539
2540
|
}
|
|
2540
|
-
uniqueName(position, filename, highSyntax
|
|
2541
|
+
uniqueName(position, filename, highSyntax) {
|
|
2541
2542
|
const spag = highSyntax.spaghetti.lookupPosition(position, filename);
|
|
2542
2543
|
if (spag === undefined) {
|
|
2543
|
-
const name =
|
|
2544
|
+
const name = "temprr" + this.counter;
|
|
2544
2545
|
this.counter++;
|
|
2545
2546
|
return name;
|
|
2546
2547
|
}
|
|
2548
|
+
let postfix = "";
|
|
2549
|
+
if (spag.getIdentifier().stype === _scope_type_1.ScopeType.ClassDefinition) {
|
|
2550
|
+
// try making sure this name is not used in subclasses
|
|
2551
|
+
const hash = crypto.createHash("sha1").update(spag.getIdentifier().sname).digest("hex");
|
|
2552
|
+
postfix = "_" + hash.substring(0, 10);
|
|
2553
|
+
}
|
|
2547
2554
|
while (true) {
|
|
2548
|
-
const name =
|
|
2555
|
+
const name = "temp" + this.counter + postfix;
|
|
2549
2556
|
const exists = this.existsRecursive(spag, name);
|
|
2550
2557
|
this.counter++;
|
|
2551
2558
|
if (exists === false) {
|
|
@@ -2553,13 +2560,14 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
2553
2560
|
}
|
|
2554
2561
|
}
|
|
2555
2562
|
}
|
|
2563
|
+
// todo, optimize, the findVariable() and findType() does a lot of redundant checks
|
|
2556
2564
|
existsRecursive(spag, name) {
|
|
2557
|
-
const existsDirect = spag.findVariable(name);
|
|
2565
|
+
const existsDirect = spag.findVariable(name) || spag.findType(name);
|
|
2558
2566
|
if (existsDirect) {
|
|
2559
2567
|
return true;
|
|
2560
2568
|
}
|
|
2561
2569
|
for (const child of spag.getChildren()) {
|
|
2562
|
-
if (child.findVariable(name) || this.existsRecursive(child, name)) {
|
|
2570
|
+
if (child.findVariable(name) || child.findType(name) || this.existsRecursive(child, name)) {
|
|
2563
2571
|
return true;
|
|
2564
2572
|
}
|
|
2565
2573
|
}
|