@abaplint/cli 2.120.102 → 2.120.104

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/cli.js +221 -95
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -28178,16 +28178,19 @@ class SortedKeyWrite {
28178
28178
  if (this.procedure === undefined) {
28179
28179
  return;
28180
28180
  }
28181
- // any assignment of a field symbol or reference ends its binding
28182
- for (const fs of node.findAllExpressions(Expressions.FSTarget)) {
28183
- this.unbind(fs.findFirstExpression(Expressions.TargetFieldSymbol), input.scope);
28184
- }
28185
- if (node.get() instanceof Statements.Unassign) {
28186
- this.unbind(node.findDirectExpression(Expressions.TargetFieldSymbol), input.scope);
28187
- }
28188
- for (const target of node.findAllExpressions(Expressions.Target)) {
28189
- if (target.getChildren().length === 1) {
28190
- this.unbind(target.findDirectExpression(Expressions.TargetField), input.scope);
28181
+ // any assignment of a field symbol or reference ends its binding,
28182
+ // skipped when nothing is bound, this runs for every statement
28183
+ if (this.bindings.size > 0) {
28184
+ for (const fs of node.findAllExpressions(Expressions.FSTarget)) {
28185
+ this.unbind(fs.findFirstExpression(Expressions.TargetFieldSymbol), input.scope);
28186
+ }
28187
+ if (node.get() instanceof Statements.Unassign) {
28188
+ this.unbind(node.findDirectExpression(Expressions.TargetFieldSymbol), input.scope);
28189
+ }
28190
+ for (const target of node.findAllExpressions(Expressions.Target)) {
28191
+ if (target.getChildren().length === 1) {
28192
+ this.unbind(target.findDirectExpression(Expressions.TargetField), input.scope);
28193
+ }
28191
28194
  }
28192
28195
  }
28193
28196
  const s = node.get();
@@ -51066,7 +51069,8 @@ class SyntaxLogic {
51066
51069
  }
51067
51070
  }
51068
51071
  }
51069
- if (isStructure || isStatement) {
51072
+ // statements only have expressions and tokens as children, nothing to traverse
51073
+ if (isStructure) {
51070
51074
  this.traverse(child);
51071
51075
  }
51072
51076
  }
@@ -61176,6 +61180,31 @@ exports.MemoryFile = MemoryFile;
61176
61180
 
61177
61181
  /***/ },
61178
61182
 
61183
+ /***/ "../core/build/src/files/raw_rows_cache.js"
61184
+ /*!*************************************************!*\
61185
+ !*** ../core/build/src/files/raw_rows_cache.js ***!
61186
+ \*************************************************/
61187
+ (__unused_webpack_module, exports) {
61188
+
61189
+ "use strict";
61190
+
61191
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
61192
+ exports.getCachedRawRows = getCachedRawRows;
61193
+ const rowCache = new WeakMap();
61194
+ /** getRawRows() splits the source on every call; a file is never changed, edits create a new one,
61195
+ * so the rows can be cached per file object. The result must not be modified */
61196
+ function getCachedRawRows(file) {
61197
+ let rows = rowCache.get(file);
61198
+ if (rows === undefined) {
61199
+ rows = file.getRawRows();
61200
+ rowCache.set(file, rows);
61201
+ }
61202
+ return rows;
61203
+ }
61204
+ //# sourceMappingURL=raw_rows_cache.js.map
61205
+
61206
+ /***/ },
61207
+
61179
61208
  /***/ "../core/build/src/index.js"
61180
61209
  /*!**********************************!*\
61181
61210
  !*** ../core/build/src/index.js ***!
@@ -61360,11 +61389,12 @@ exports.Issue = void 0;
61360
61389
  const position_1 = __webpack_require__(/*! ./position */ "../core/build/src/position.js");
61361
61390
  const virtual_position_1 = __webpack_require__(/*! ./virtual_position */ "../core/build/src/virtual_position.js");
61362
61391
  const severity_1 = __webpack_require__(/*! ./severity */ "../core/build/src/severity.js");
61392
+ const raw_rows_cache_1 = __webpack_require__(/*! ./files/raw_rows_cache */ "../core/build/src/files/raw_rows_cache.js");
61363
61393
  class Issue {
61364
61394
  //////////////////////////
61365
61395
  static atRow(file, row, message, key, severity) {
61366
61396
  const start = new position_1.Position(row, 1);
61367
- const end = new position_1.Position(row, file.getRawRows()[row - 1].length + 1);
61397
+ const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
61368
61398
  severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
61369
61399
  return new Issue({
61370
61400
  filename: file.getFilename(),
@@ -61380,7 +61410,7 @@ class Issue {
61380
61410
  }
61381
61411
  static atPosition(file, start, message, key, severity, fix) {
61382
61412
  const row = start.getRow();
61383
- const end = new position_1.Position(row, file.getRawRows()[row - 1].length + 1);
61413
+ const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
61384
61414
  severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
61385
61415
  return new Issue({
61386
61416
  filename: file.getFilename(),
@@ -73584,6 +73614,8 @@ class Registry {
73584
73614
  this.objects = {};
73585
73615
  this.objectsByType = {};
73586
73616
  this.dependencies = {};
73617
+ /** upper case filename to object containing the file, kept in sync by add/remove methods */
73618
+ this.filenameIndex = new Map();
73587
73619
  this.setConfig(conf ? conf : config_1.Config.getDefault());
73588
73620
  this.clear();
73589
73621
  }
@@ -73592,13 +73624,14 @@ class Registry {
73592
73624
  this.objects = {};
73593
73625
  this.objectsByType = {};
73594
73626
  this.dependencies = {};
73627
+ this.filenameIndex = new Map();
73595
73628
  this.ddicReferences = new ddic_references_1.DDICReferences();
73596
73629
  this.msagReferences = new msag_references_1.MSAGReferences();
73597
73630
  this.macroReferences = new macro_references_1.MacroReferences();
73598
73631
  }
73599
73632
  static abaplintVersion() {
73600
73633
  // magic, see build script "version.js"
73601
- return "2.120.102";
73634
+ return "2.120.104";
73602
73635
  }
73603
73636
  getDDICReferences() {
73604
73637
  return this.ddicReferences;
@@ -73651,11 +73684,13 @@ class Registry {
73651
73684
  }
73652
73685
  getFileByName(filename) {
73653
73686
  const upper = filename.toUpperCase();
73654
- for (const o of this.getObjects()) {
73655
- for (const f of o.getFiles()) {
73656
- if (f.getFilename().toUpperCase() === upper) {
73657
- return f;
73658
- }
73687
+ const obj = this.filenameIndex.get(upper);
73688
+ if (obj === undefined) {
73689
+ return undefined;
73690
+ }
73691
+ for (const f of obj.getFiles()) {
73692
+ if (f.getFilename().toUpperCase() === upper) {
73693
+ return f;
73659
73694
  }
73660
73695
  }
73661
73696
  return undefined;
@@ -73696,6 +73731,7 @@ class Registry {
73696
73731
  removeFile(file) {
73697
73732
  const obj = this.find(file.getObjectName(), file.getObjectType());
73698
73733
  obj.removeFile(file);
73734
+ this.unindexFile(file.getFilename(), obj);
73699
73735
  if (obj.getFiles().length === 0) {
73700
73736
  this.ddicReferences.clear(obj);
73701
73737
  this.msagReferences.clear(obj);
@@ -73722,6 +73758,7 @@ class Registry {
73722
73758
  found = this.findOrCreate(f.getObjectName(), f.getObjectType());
73723
73759
  }
73724
73760
  found.addFile(f);
73761
+ this.filenameIndex.set(filename.toUpperCase(), found);
73725
73762
  }
73726
73763
  return this;
73727
73764
  }
@@ -73790,11 +73827,13 @@ class Registry {
73790
73827
  // assumption: the file is already in the registry
73791
73828
  findObjectForFile(file) {
73792
73829
  const filename = file.getFilename();
73793
- for (const obj of this.getObjects()) {
73794
- for (const ofile of obj.getFiles()) {
73795
- if (ofile.getFilename() === filename) {
73796
- return obj;
73797
- }
73830
+ const obj = this.filenameIndex.get(filename.toUpperCase());
73831
+ if (obj === undefined) {
73832
+ return undefined;
73833
+ }
73834
+ for (const ofile of obj.getFiles()) {
73835
+ if (ofile.getFilename() === filename) {
73836
+ return obj;
73798
73837
  }
73799
73838
  }
73800
73839
  return undefined;
@@ -73886,6 +73925,9 @@ class Registry {
73886
73925
  if (this.objects[remove.getName()][remove.getType()] === undefined) {
73887
73926
  throw new Error("removeObject: object not found");
73888
73927
  }
73928
+ for (const f of remove.getFiles()) {
73929
+ this.unindexFile(f.getFilename(), remove);
73930
+ }
73889
73931
  if (Object.keys(this.objects[remove.getName()]).length === 1) {
73890
73932
  delete this.objects[remove.getName()];
73891
73933
  }
@@ -73899,6 +73941,12 @@ class Registry {
73899
73941
  delete this.objectsByType[remove.getType()][remove.getName()];
73900
73942
  }
73901
73943
  }
73944
+ unindexFile(filename, obj) {
73945
+ const upper = filename.toUpperCase();
73946
+ if (this.filenameIndex.get(upper) === obj) {
73947
+ this.filenameIndex.delete(upper);
73948
+ }
73949
+ }
73902
73950
  find(name, type) {
73903
73951
  const searchType = type ? type : "UNKNOWN";
73904
73952
  const searchName = name.toUpperCase();
@@ -74196,6 +74244,7 @@ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_st
74196
74244
  const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "../core/build/src/abap/1_lexer/tokens/index.js");
74197
74245
  const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
74198
74246
  const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
74247
+ const raw_rows_cache_1 = __webpack_require__(/*! ../files/raw_rows_cache */ "../core/build/src/files/raw_rows_cache.js");
74199
74248
  const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
74200
74249
  const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
74201
74250
  const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
@@ -75502,16 +75551,6 @@ class Hierarchy {
75502
75551
  exports.Hierarchy = Hierarchy;
75503
75552
  ////////////////////////////////////////
75504
75553
  // edits
75505
- const rowCache = new WeakMap();
75506
- /** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
75507
- function rowsOf(file) {
75508
- let rows = rowCache.get(file);
75509
- if (rows === undefined) {
75510
- rows = file.getRawRows();
75511
- rowCache.set(file, rows);
75512
- }
75513
- return rows;
75514
- }
75515
75554
  /** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
75516
75555
  function mergeEdits(file, edits) {
75517
75556
  const list = [];
@@ -75531,7 +75570,7 @@ function deleteRegion(file, first, last) {
75531
75570
  if (first === last && first.getColon() !== undefined) {
75532
75571
  return edit_helper_1.EditHelper.deleteStatement(file, first);
75533
75572
  }
75534
- const rows = rowsOf(file);
75573
+ const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
75535
75574
  const start = first.getStart();
75536
75575
  const end = last.getEnd();
75537
75576
  const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
@@ -75546,7 +75585,7 @@ function deleteStatement(file, statement) {
75546
75585
  }
75547
75586
  /** the source code between two positions, as written */
75548
75587
  function rawText(file, start, end) {
75549
- const rows = rowsOf(file);
75588
+ const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
75550
75589
  if (start.getRow() === end.getRow()) {
75551
75590
  return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
75552
75591
  }
@@ -85456,8 +85495,23 @@ Make sure to test the downported code, it might not always be completely correct
85456
85495
  }
85457
85496
  highSyntaxObj = this.highReg.findObjectForFile(f);
85458
85497
  }
85498
+ // the syntax run is expensive and most statements need no downport, so run it on first use
85499
+ let computedSyntax = undefined;
85500
+ const runHighSyntax = () => {
85501
+ if (computedSyntax === undefined) {
85502
+ computedSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
85503
+ }
85504
+ return computedSyntax;
85505
+ };
85506
+ const highSyntax = {
85507
+ get issues() {
85508
+ return runHighSyntax().issues;
85509
+ },
85510
+ get spaghetti() {
85511
+ return runHighSyntax().spaghetti;
85512
+ },
85513
+ };
85459
85514
  for (const lowFile of lowObj.getABAPFiles()) {
85460
- let highSyntax = undefined;
85461
85515
  const highFile = highObj.getABAPFileByName(lowFile.getFilename());
85462
85516
  if (highFile === undefined) {
85463
85517
  continue;
@@ -85476,9 +85530,6 @@ Make sure to test the downported code, it might not always be completely correct
85476
85530
  // actively editing the files
85477
85531
  continue;
85478
85532
  }
85479
- if (highSyntax === undefined) {
85480
- highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
85481
- }
85482
85533
  let containsUnknown = false;
85483
85534
  const notDownported = [];
85484
85535
  for (let i = 0; i < lowStatements.length; i++) {
@@ -108368,6 +108419,8 @@ const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_i
108368
108419
  const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/build/src/abap/5_syntax/syntax.js");
108369
108420
  const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
108370
108421
  const types_1 = __webpack_require__(/*! ../abap/types */ "../core/build/src/abap/types/index.js");
108422
+ const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
108423
+ const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "../core/build/src/virtual_position.js");
108371
108424
  class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
108372
108425
  constructor() {
108373
108426
  super(...arguments);
@@ -108407,24 +108460,36 @@ ENDMETHOD.`,
108407
108460
  if (this.getConfig().allowInTestclassIncludes === true && file.getFilename().includes(".testclasses.")) {
108408
108461
  return [];
108409
108462
  }
108410
- const staticMethodCalls = this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop());
108463
+ const staticMethodCalls = new Set();
108464
+ for (const s of this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop())) {
108465
+ staticMethodCalls.add(StaticCallViaInstance.positionKey(s));
108466
+ }
108467
+ if (staticMethodCalls.size === 0) {
108468
+ return [];
108469
+ }
108411
108470
  const tokens = file.getTokens();
108412
108471
  for (let i = 0; i < tokens.length - 1; i++) {
108413
108472
  const token = tokens[i];
108414
108473
  if (token.getStr() !== "->") {
108415
108474
  continue;
108416
108475
  }
108417
- const next = tokens[i + 1];
108418
- for (const s of staticMethodCalls) {
108419
- if (s.equals(next.getStart())) {
108420
- const message = "Avoid calling static method via instance";
108421
- issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
108422
- break;
108423
- }
108476
+ const next = tokens[i + 1].getStart();
108477
+ // a plain reference position also matches a token inside a macro call at the same row and column
108478
+ if (staticMethodCalls.has(StaticCallViaInstance.positionKey(next))
108479
+ || (next instanceof virtual_position_1.VirtualPosition
108480
+ && staticMethodCalls.has(StaticCallViaInstance.positionKey(new position_1.Position(next.getRow(), next.getCol()))))) {
108481
+ const message = "Avoid calling static method via instance";
108482
+ issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
108424
108483
  }
108425
108484
  }
108426
108485
  return issues;
108427
108486
  }
108487
+ static positionKey(p) {
108488
+ if (p instanceof virtual_position_1.VirtualPosition) {
108489
+ return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
108490
+ }
108491
+ return p.getRow() + ":" + p.getCol();
108492
+ }
108428
108493
  listMethodCalls(filename, node) {
108429
108494
  const ret = [];
108430
108495
  for (const r of node.getData().references) {
@@ -112015,31 +112080,40 @@ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ ".
112015
112080
  const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
112016
112081
  const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
112017
112082
  const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
112083
+ const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "../core/build/src/virtual_position.js");
112018
112084
  class WorkArea {
112019
112085
  constructor() {
112020
- this.workarea = [];
112086
+ // keyed by identifier position, insertion order is kept
112087
+ this.workarea = new Map();
112021
112088
  }
112022
112089
  push(id) {
112023
- for (const w of this.workarea) {
112024
- if (id.equals(w)) {
112025
- return;
112026
- }
112090
+ const key = WorkArea.buildKey(id);
112091
+ if (this.workarea.has(key) === false) {
112092
+ this.workarea.set(key, id);
112027
112093
  }
112028
- this.workarea.push(id);
112029
112094
  }
112030
112095
  removeIfExists(id) {
112031
- for (let i = 0; i < this.workarea.length; i++) {
112032
- if (id.equals(this.workarea[i])) {
112033
- this.workarea.splice(i, 1);
112034
- return;
112096
+ this.workarea.delete(WorkArea.buildKey(id));
112097
+ }
112098
+ /** removes the identifiers referenced somewhere */
112099
+ removeReferenced(referenced) {
112100
+ for (const key of [...this.workarea.keys()]) {
112101
+ if (referenced.has(key)) {
112102
+ this.workarea.delete(key);
112035
112103
  }
112036
112104
  }
112037
112105
  }
112038
112106
  get() {
112039
- return this.workarea;
112107
+ return [...this.workarea.values()];
112040
112108
  }
112041
112109
  count() {
112042
- return this.workarea.length;
112110
+ return this.workarea.size;
112111
+ }
112112
+ /** identifiers from one macro call share the row and column, the virtual position tells them apart */
112113
+ static buildKey(id) {
112114
+ const start = id.getStart();
112115
+ const key = id.getFilename() + "," + start.getRow() + "," + start.getCol();
112116
+ return start instanceof virtual_position_1.VirtualPosition ? key + "," + start.vrow + "," + start.vcol : key;
112043
112117
  }
112044
112118
  }
112045
112119
  class UnusedTypesConf extends _basic_rule_config_1.BasicRuleConfig {
@@ -112055,6 +112129,8 @@ exports.UnusedTypesConf = UnusedTypesConf;
112055
112129
  class UnusedTypes {
112056
112130
  constructor() {
112057
112131
  this.conf = new UnusedTypesConf();
112132
+ /** keys of the identifiers with a type reference in any object, built once per run when needed */
112133
+ this.referenced = undefined;
112058
112134
  }
112059
112135
  getMetadata() {
112060
112136
  return {
@@ -112078,6 +112154,7 @@ class UnusedTypes {
112078
112154
  }
112079
112155
  initialize(reg) {
112080
112156
  this.reg = reg;
112157
+ this.referenced = undefined;
112081
112158
  return this;
112082
112159
  }
112083
112160
  run(obj) {
@@ -112102,20 +112179,10 @@ class UnusedTypes {
112102
112179
  if (this.workarea.count() === 0) {
112103
112180
  return []; // exit early if all types are used in the current object
112104
112181
  }
112105
- for (const o of this.reg.getObjects()) {
112106
- if (o === obj) {
112107
- continue;
112108
- }
112109
- else if (o instanceof _abap_object_1.ABAPObject) {
112110
- if (this.reg.isDependency(o)) {
112111
- continue; // do not search in dependencies
112112
- }
112113
- const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
112114
- this.traverse(syntax.spaghetti.getTop(), o, false);
112115
- }
112116
- if (this.workarea.count() === 0) {
112117
- return []; // exit early if all types are used
112118
- }
112182
+ // uses in other objects, collected once instead of searching all objects for each object
112183
+ this.workarea.removeReferenced(this.getReferenced());
112184
+ if (this.workarea.count() === 0) {
112185
+ return []; // exit early if all types are used
112119
112186
  }
112120
112187
  // what is left is unused
112121
112188
  const ret = [];
@@ -112159,6 +112226,33 @@ class UnusedTypes {
112159
112226
  return false;
112160
112227
  }
112161
112228
  ////////////////////////////
112229
+ getReferenced() {
112230
+ if (this.referenced === undefined) {
112231
+ const referenced = new Set();
112232
+ for (const o of this.reg.getObjects()) {
112233
+ if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
112234
+ continue; // do not search in dependencies
112235
+ }
112236
+ const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
112237
+ this.collectReferenced(syntax.spaghetti.getTop(), referenced);
112238
+ }
112239
+ this.referenced = referenced;
112240
+ }
112241
+ return this.referenced;
112242
+ }
112243
+ /** same nodes and references as checkNode() with add = false */
112244
+ collectReferenced(node, referenced) {
112245
+ if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
112246
+ for (const r of node.getData().references) {
112247
+ if (r.referenceType === _reference_1.ReferenceType.TypeReference && r.resolved) {
112248
+ referenced.add(WorkArea.buildKey(r.resolved));
112249
+ }
112250
+ }
112251
+ }
112252
+ for (const c of node.getChildren()) {
112253
+ this.collectReferenced(c, referenced);
112254
+ }
112255
+ }
112162
112256
  traverse(node, obj, add) {
112163
112257
  if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
112164
112258
  this.checkNode(node, obj, add);
@@ -112278,17 +112372,17 @@ class WorkArea {
112278
112372
  this.workarea = new Map();
112279
112373
  }
112280
112374
  push(id, count = 1) {
112281
- const key = this.buildKey(id);
112375
+ const key = WorkArea.buildKey(id);
112282
112376
  if (this.workarea.has(key)) {
112283
112377
  return;
112284
112378
  }
112285
- this.workarea.set(key, { id, count });
112379
+ this.workarea.set(key, { id, count, required: count });
112286
112380
  }
112287
112381
  removeIfExists(id) {
112288
112382
  if (id === undefined) {
112289
112383
  return;
112290
112384
  }
112291
- const key = this.buildKey(id);
112385
+ const key = WorkArea.buildKey(id);
112292
112386
  const found = this.workarea.get(key);
112293
112387
  if (found !== undefined) {
112294
112388
  found.count--;
@@ -112297,13 +112391,23 @@ class WorkArea {
112297
112391
  }
112298
112392
  }
112299
112393
  }
112394
+ /** removes the identifiers with enough references, counts include all objects, also the one the
112395
+ * identifiers belong to, so it is compared to the required count and not the remaining count */
112396
+ removeReferenced(counts) {
112397
+ var _a;
112398
+ for (const [key, entry] of this.workarea) {
112399
+ if (((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) >= entry.required) {
112400
+ this.workarea.delete(key);
112401
+ }
112402
+ }
112403
+ }
112300
112404
  get() {
112301
112405
  return [...this.workarea.values()];
112302
112406
  }
112303
112407
  count() {
112304
112408
  return this.workarea.size;
112305
112409
  }
112306
- buildKey(id) {
112410
+ static buildKey(id) {
112307
112411
  const start = id.getStart();
112308
112412
  return id.getFilename() + "," + start.getRow() + "," + start.getCol();
112309
112413
  }
@@ -112311,6 +112415,8 @@ class WorkArea {
112311
112415
  class UnusedVariables {
112312
112416
  constructor() {
112313
112417
  this.conf = new UnusedVariablesConf();
112418
+ /** read, write and type references per identifier key in all objects, built once per run when needed */
112419
+ this.referenceCounts = undefined;
112314
112420
  }
112315
112421
  getMetadata() {
112316
112422
  return {
@@ -112348,6 +112454,7 @@ Errors found in INCLUDES are reported for the main program.`,
112348
112454
  }
112349
112455
  initialize(reg) {
112350
112456
  this.reg = reg;
112457
+ this.referenceCounts = undefined;
112351
112458
  return this;
112352
112459
  }
112353
112460
  run(obj) {
@@ -112375,34 +112482,53 @@ Errors found in INCLUDES are reported for the main program.`,
112375
112482
  if (this.workarea.count() === 0) {
112376
112483
  return this.buildIssues(obj); // exit early if all variables are used
112377
112484
  }
112378
- this.findUses(top, obj);
112379
- for (const o of this.reg.getObjects()) {
112380
- if (o === obj) {
112381
- continue;
112382
- }
112383
- else if (o instanceof _abap_object_1.ABAPObject) {
112384
- if (this.reg.isDependency(o)) {
112485
+ this.findUses(top);
112486
+ if (this.workarea.count() === 0) {
112487
+ return this.buildIssues(obj); // exit early if all variables are used
112488
+ }
112489
+ // uses in other objects, the counts are built once instead of searching all objects for each object
112490
+ this.workarea.removeReferenced(this.getReferenceCounts());
112491
+ return this.buildIssues(obj);
112492
+ }
112493
+ getReferenceCounts() {
112494
+ if (this.referenceCounts === undefined) {
112495
+ const counts = new Map();
112496
+ for (const o of this.reg.getObjects()) {
112497
+ if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
112385
112498
  continue; // do not search in dependencies
112386
112499
  }
112387
112500
  const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
112388
- this.findUses(syntax.spaghetti.getTop(), o);
112389
- if (this.workarea.count() === 0) {
112390
- return this.buildIssues(obj); // exit early if all variables are used
112391
- }
112501
+ this.countUses(syntax.spaghetti.getTop(), counts);
112392
112502
  }
112503
+ this.referenceCounts = counts;
112393
112504
  }
112394
- return this.buildIssues(obj);
112505
+ return this.referenceCounts;
112506
+ }
112507
+ static isUse(r) {
112508
+ return r.referenceType === _reference_1.ReferenceType.DataReadReference
112509
+ || r.referenceType === _reference_1.ReferenceType.DataWriteReference
112510
+ || r.referenceType === _reference_1.ReferenceType.TypeReference;
112395
112511
  }
112396
- findUses(node, obj) {
112512
+ findUses(node) {
112397
112513
  for (const r of node.getData().references) {
112398
- if (r.referenceType === _reference_1.ReferenceType.DataReadReference
112399
- || r.referenceType === _reference_1.ReferenceType.DataWriteReference
112400
- || r.referenceType === _reference_1.ReferenceType.TypeReference) {
112514
+ if (UnusedVariables.isUse(r)) {
112401
112515
  this.workarea.removeIfExists(r.resolved);
112402
112516
  }
112403
112517
  }
112404
112518
  for (const c of node.getChildren()) {
112405
- this.findUses(c, obj);
112519
+ this.findUses(c);
112520
+ }
112521
+ }
112522
+ countUses(node, counts) {
112523
+ var _a;
112524
+ for (const r of node.getData().references) {
112525
+ if (r.resolved !== undefined && UnusedVariables.isUse(r)) {
112526
+ const key = WorkArea.buildKey(r.resolved);
112527
+ counts.set(key, ((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
112528
+ }
112529
+ }
112530
+ for (const c of node.getChildren()) {
112531
+ this.countUses(c, counts);
112406
112532
  }
112407
112533
  }
112408
112534
  buildWorkarea(node, obj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/cli",
3
- "version": "2.120.102",
3
+ "version": "2.120.104",
4
4
  "description": "abaplint - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "homepage": "https://abaplint.org",
41
41
  "devDependencies": {
42
- "@abaplint/core": "^2.120.102",
42
+ "@abaplint/core": "^2.120.104",
43
43
  "@types/chai": "^4.3.20",
44
44
  "@types/minimist": "^1.2.5",
45
45
  "@types/mocha": "^10.0.10",