@abaplint/transpiler-cli 2.14.30 → 2.14.31

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/bundle.js +247 -116
  2. package/package.json +3 -3
package/build/bundle.js CHANGED
@@ -46337,6 +46337,7 @@ var __importStar = (this && this.__importStar) || (function () {
46337
46337
  Object.defineProperty(exports, "__esModule", ({ value: true }));
46338
46338
  exports.ModifyInternal = void 0;
46339
46339
  const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
46340
+ const nodes_1 = __webpack_require__(/*! ../../nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
46340
46341
  const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
46341
46342
  const target_1 = __webpack_require__(/*! ../expressions/target */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/target.js");
46342
46343
  const fstarget_1 = __webpack_require__(/*! ../expressions/fstarget */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/fstarget.js");
@@ -46345,15 +46346,22 @@ const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@ab
46345
46346
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
46346
46347
  class ModifyInternal {
46347
46348
  runSyntax(node, input) {
46348
- for (const s of node.findDirectExpressions(Expressions.Source)) {
46349
- source_1.Source.runSyntax(s, input);
46350
- }
46349
+ var _a;
46351
46350
  // there is only one
46352
46351
  const target = node.findFirstExpression(Expressions.Target);
46353
- const targetExpression = target;
46354
- if (targetExpression) {
46355
- // it might be a dynamic target
46356
- const targetType = target_1.Target.runSyntax(targetExpression, input);
46352
+ // it might be a dynamic target
46353
+ const targetType = target ? target_1.Target.runSyntax(target, input) : undefined;
46354
+ // the FROM work area has the row type of the table, used for inferring "#"
46355
+ const rowType = targetType instanceof basic_1.TableType ? targetType.getRowType() : undefined;
46356
+ const children = node.getChildren();
46357
+ for (let i = 0; i < children.length; i++) {
46358
+ const s = children[i];
46359
+ if (s instanceof nodes_1.ExpressionNode && s.get() instanceof Expressions.Source) {
46360
+ const isFrom = ((_a = children[i - 1]) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === "FROM";
46361
+ source_1.Source.runSyntax(s, input, isFrom ? rowType : undefined);
46362
+ }
46363
+ }
46364
+ if (target) {
46357
46365
  if (targetType instanceof basic_1.VoidType
46358
46366
  || targetType instanceof basic_1.AnyType
46359
46367
  || targetType instanceof basic_1.UnknownType) {
@@ -52216,7 +52224,8 @@ class SyntaxLogic {
52216
52224
  }
52217
52225
  }
52218
52226
  }
52219
- if (isStructure || isStatement) {
52227
+ // statements only have expressions and tokens as children, nothing to traverse
52228
+ if (isStructure) {
52220
52229
  this.traverse(child);
52221
52230
  }
52222
52231
  }
@@ -62326,6 +62335,31 @@ exports.MemoryFile = MemoryFile;
62326
62335
 
62327
62336
  /***/ },
62328
62337
 
62338
+ /***/ "./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js"
62339
+ /*!***********************************************************************!*\
62340
+ !*** ./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js ***!
62341
+ \***********************************************************************/
62342
+ (__unused_webpack_module, exports) {
62343
+
62344
+ "use strict";
62345
+
62346
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
62347
+ exports.getCachedRawRows = getCachedRawRows;
62348
+ const rowCache = new WeakMap();
62349
+ /** getRawRows() splits the source on every call; a file is never changed, edits create a new one,
62350
+ * so the rows can be cached per file object. The result must not be modified */
62351
+ function getCachedRawRows(file) {
62352
+ let rows = rowCache.get(file);
62353
+ if (rows === undefined) {
62354
+ rows = file.getRawRows();
62355
+ rowCache.set(file, rows);
62356
+ }
62357
+ return rows;
62358
+ }
62359
+ //# sourceMappingURL=raw_rows_cache.js.map
62360
+
62361
+ /***/ },
62362
+
62329
62363
  /***/ "./node_modules/@abaplint/core/build/src/index.js"
62330
62364
  /*!********************************************************!*\
62331
62365
  !*** ./node_modules/@abaplint/core/build/src/index.js ***!
@@ -62510,11 +62544,12 @@ exports.Issue = void 0;
62510
62544
  const position_1 = __webpack_require__(/*! ./position */ "./node_modules/@abaplint/core/build/src/position.js");
62511
62545
  const virtual_position_1 = __webpack_require__(/*! ./virtual_position */ "./node_modules/@abaplint/core/build/src/virtual_position.js");
62512
62546
  const severity_1 = __webpack_require__(/*! ./severity */ "./node_modules/@abaplint/core/build/src/severity.js");
62547
+ const raw_rows_cache_1 = __webpack_require__(/*! ./files/raw_rows_cache */ "./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js");
62513
62548
  class Issue {
62514
62549
  //////////////////////////
62515
62550
  static atRow(file, row, message, key, severity) {
62516
62551
  const start = new position_1.Position(row, 1);
62517
- const end = new position_1.Position(row, file.getRawRows()[row - 1].length + 1);
62552
+ const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
62518
62553
  severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
62519
62554
  return new Issue({
62520
62555
  filename: file.getFilename(),
@@ -62530,7 +62565,7 @@ class Issue {
62530
62565
  }
62531
62566
  static atPosition(file, start, message, key, severity, fix) {
62532
62567
  const row = start.getRow();
62533
- const end = new position_1.Position(row, file.getRawRows()[row - 1].length + 1);
62568
+ const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
62534
62569
  severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
62535
62570
  return new Issue({
62536
62571
  filename: file.getFilename(),
@@ -74734,6 +74769,8 @@ class Registry {
74734
74769
  this.objects = {};
74735
74770
  this.objectsByType = {};
74736
74771
  this.dependencies = {};
74772
+ /** upper case filename to object containing the file, kept in sync by add/remove methods */
74773
+ this.filenameIndex = new Map();
74737
74774
  this.setConfig(conf ? conf : config_1.Config.getDefault());
74738
74775
  this.clear();
74739
74776
  }
@@ -74742,13 +74779,14 @@ class Registry {
74742
74779
  this.objects = {};
74743
74780
  this.objectsByType = {};
74744
74781
  this.dependencies = {};
74782
+ this.filenameIndex = new Map();
74745
74783
  this.ddicReferences = new ddic_references_1.DDICReferences();
74746
74784
  this.msagReferences = new msag_references_1.MSAGReferences();
74747
74785
  this.macroReferences = new macro_references_1.MacroReferences();
74748
74786
  }
74749
74787
  static abaplintVersion() {
74750
74788
  // magic, see build script "version.js"
74751
- return "2.120.103";
74789
+ return "2.120.105";
74752
74790
  }
74753
74791
  getDDICReferences() {
74754
74792
  return this.ddicReferences;
@@ -74801,11 +74839,13 @@ class Registry {
74801
74839
  }
74802
74840
  getFileByName(filename) {
74803
74841
  const upper = filename.toUpperCase();
74804
- for (const o of this.getObjects()) {
74805
- for (const f of o.getFiles()) {
74806
- if (f.getFilename().toUpperCase() === upper) {
74807
- return f;
74808
- }
74842
+ const obj = this.filenameIndex.get(upper);
74843
+ if (obj === undefined) {
74844
+ return undefined;
74845
+ }
74846
+ for (const f of obj.getFiles()) {
74847
+ if (f.getFilename().toUpperCase() === upper) {
74848
+ return f;
74809
74849
  }
74810
74850
  }
74811
74851
  return undefined;
@@ -74846,6 +74886,7 @@ class Registry {
74846
74886
  removeFile(file) {
74847
74887
  const obj = this.find(file.getObjectName(), file.getObjectType());
74848
74888
  obj.removeFile(file);
74889
+ this.unindexFile(file.getFilename(), obj);
74849
74890
  if (obj.getFiles().length === 0) {
74850
74891
  this.ddicReferences.clear(obj);
74851
74892
  this.msagReferences.clear(obj);
@@ -74872,6 +74913,7 @@ class Registry {
74872
74913
  found = this.findOrCreate(f.getObjectName(), f.getObjectType());
74873
74914
  }
74874
74915
  found.addFile(f);
74916
+ this.filenameIndex.set(filename.toUpperCase(), found);
74875
74917
  }
74876
74918
  return this;
74877
74919
  }
@@ -74940,11 +74982,13 @@ class Registry {
74940
74982
  // assumption: the file is already in the registry
74941
74983
  findObjectForFile(file) {
74942
74984
  const filename = file.getFilename();
74943
- for (const obj of this.getObjects()) {
74944
- for (const ofile of obj.getFiles()) {
74945
- if (ofile.getFilename() === filename) {
74946
- return obj;
74947
- }
74985
+ const obj = this.filenameIndex.get(filename.toUpperCase());
74986
+ if (obj === undefined) {
74987
+ return undefined;
74988
+ }
74989
+ for (const ofile of obj.getFiles()) {
74990
+ if (ofile.getFilename() === filename) {
74991
+ return obj;
74948
74992
  }
74949
74993
  }
74950
74994
  return undefined;
@@ -75036,6 +75080,9 @@ class Registry {
75036
75080
  if (this.objects[remove.getName()][remove.getType()] === undefined) {
75037
75081
  throw new Error("removeObject: object not found");
75038
75082
  }
75083
+ for (const f of remove.getFiles()) {
75084
+ this.unindexFile(f.getFilename(), remove);
75085
+ }
75039
75086
  if (Object.keys(this.objects[remove.getName()]).length === 1) {
75040
75087
  delete this.objects[remove.getName()];
75041
75088
  }
@@ -75049,6 +75096,12 @@ class Registry {
75049
75096
  delete this.objectsByType[remove.getType()][remove.getName()];
75050
75097
  }
75051
75098
  }
75099
+ unindexFile(filename, obj) {
75100
+ const upper = filename.toUpperCase();
75101
+ if (this.filenameIndex.get(upper) === obj) {
75102
+ this.filenameIndex.delete(upper);
75103
+ }
75104
+ }
75052
75105
  find(name, type) {
75053
75106
  const searchType = type ? type : "UNKNOWN";
75054
75107
  const searchName = name.toUpperCase();
@@ -75346,6 +75399,7 @@ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_st
75346
75399
  const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/index.js");
75347
75400
  const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
75348
75401
  const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/syntax.js");
75402
+ const raw_rows_cache_1 = __webpack_require__(/*! ../files/raw_rows_cache */ "./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js");
75349
75403
  const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
75350
75404
  const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "./node_modules/@abaplint/core/build/src/abap/types/_typed_identifier.js");
75351
75405
  const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
@@ -76652,16 +76706,6 @@ class Hierarchy {
76652
76706
  exports.Hierarchy = Hierarchy;
76653
76707
  ////////////////////////////////////////
76654
76708
  // edits
76655
- const rowCache = new WeakMap();
76656
- /** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
76657
- function rowsOf(file) {
76658
- let rows = rowCache.get(file);
76659
- if (rows === undefined) {
76660
- rows = file.getRawRows();
76661
- rowCache.set(file, rows);
76662
- }
76663
- return rows;
76664
- }
76665
76709
  /** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
76666
76710
  function mergeEdits(file, edits) {
76667
76711
  const list = [];
@@ -76681,7 +76725,7 @@ function deleteRegion(file, first, last) {
76681
76725
  if (first === last && first.getColon() !== undefined) {
76682
76726
  return edit_helper_1.EditHelper.deleteStatement(file, first);
76683
76727
  }
76684
- const rows = rowsOf(file);
76728
+ const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
76685
76729
  const start = first.getStart();
76686
76730
  const end = last.getEnd();
76687
76731
  const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
@@ -76696,7 +76740,7 @@ function deleteStatement(file, statement) {
76696
76740
  }
76697
76741
  /** the source code between two positions, as written */
76698
76742
  function rawText(file, start, end) {
76699
- const rows = rowsOf(file);
76743
+ const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
76700
76744
  if (start.getRow() === end.getRow()) {
76701
76745
  return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
76702
76746
  }
@@ -86606,8 +86650,23 @@ Make sure to test the downported code, it might not always be completely correct
86606
86650
  }
86607
86651
  highSyntaxObj = this.highReg.findObjectForFile(f);
86608
86652
  }
86653
+ // the syntax run is expensive and most statements need no downport, so run it on first use
86654
+ let computedSyntax = undefined;
86655
+ const runHighSyntax = () => {
86656
+ if (computedSyntax === undefined) {
86657
+ computedSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
86658
+ }
86659
+ return computedSyntax;
86660
+ };
86661
+ const highSyntax = {
86662
+ get issues() {
86663
+ return runHighSyntax().issues;
86664
+ },
86665
+ get spaghetti() {
86666
+ return runHighSyntax().spaghetti;
86667
+ },
86668
+ };
86609
86669
  for (const lowFile of lowObj.getABAPFiles()) {
86610
- let highSyntax = undefined;
86611
86670
  const highFile = highObj.getABAPFileByName(lowFile.getFilename());
86612
86671
  if (highFile === undefined) {
86613
86672
  continue;
@@ -86626,9 +86685,6 @@ Make sure to test the downported code, it might not always be completely correct
86626
86685
  // actively editing the files
86627
86686
  continue;
86628
86687
  }
86629
- if (highSyntax === undefined) {
86630
- highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
86631
- }
86632
86688
  let containsUnknown = false;
86633
86689
  const notDownported = [];
86634
86690
  for (let i = 0; i < lowStatements.length; i++) {
@@ -109518,6 +109574,8 @@ const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/c
109518
109574
  const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/syntax.js");
109519
109575
  const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
109520
109576
  const types_1 = __webpack_require__(/*! ../abap/types */ "./node_modules/@abaplint/core/build/src/abap/types/index.js");
109577
+ const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
109578
+ const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "./node_modules/@abaplint/core/build/src/virtual_position.js");
109521
109579
  class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
109522
109580
  constructor() {
109523
109581
  super(...arguments);
@@ -109557,24 +109615,36 @@ ENDMETHOD.`,
109557
109615
  if (this.getConfig().allowInTestclassIncludes === true && file.getFilename().includes(".testclasses.")) {
109558
109616
  return [];
109559
109617
  }
109560
- const staticMethodCalls = this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop());
109618
+ const staticMethodCalls = new Set();
109619
+ for (const s of this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop())) {
109620
+ staticMethodCalls.add(StaticCallViaInstance.positionKey(s));
109621
+ }
109622
+ if (staticMethodCalls.size === 0) {
109623
+ return [];
109624
+ }
109561
109625
  const tokens = file.getTokens();
109562
109626
  for (let i = 0; i < tokens.length - 1; i++) {
109563
109627
  const token = tokens[i];
109564
109628
  if (token.getStr() !== "->") {
109565
109629
  continue;
109566
109630
  }
109567
- const next = tokens[i + 1];
109568
- for (const s of staticMethodCalls) {
109569
- if (s.equals(next.getStart())) {
109570
- const message = "Avoid calling static method via instance";
109571
- issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
109572
- break;
109573
- }
109631
+ const next = tokens[i + 1].getStart();
109632
+ // a plain reference position also matches a token inside a macro call at the same row and column
109633
+ if (staticMethodCalls.has(StaticCallViaInstance.positionKey(next))
109634
+ || (next instanceof virtual_position_1.VirtualPosition
109635
+ && staticMethodCalls.has(StaticCallViaInstance.positionKey(new position_1.Position(next.getRow(), next.getCol()))))) {
109636
+ const message = "Avoid calling static method via instance";
109637
+ issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
109574
109638
  }
109575
109639
  }
109576
109640
  return issues;
109577
109641
  }
109642
+ static positionKey(p) {
109643
+ if (p instanceof virtual_position_1.VirtualPosition) {
109644
+ return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
109645
+ }
109646
+ return p.getRow() + ":" + p.getCol();
109647
+ }
109578
109648
  listMethodCalls(filename, node) {
109579
109649
  const ret = [];
109580
109650
  for (const r of node.getData().references) {
@@ -113165,31 +113235,40 @@ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ ".
113165
113235
  const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "./node_modules/@abaplint/core/build/src/edit_helper.js");
113166
113236
  const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
113167
113237
  const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/_statement.js");
113238
+ const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "./node_modules/@abaplint/core/build/src/virtual_position.js");
113168
113239
  class WorkArea {
113169
113240
  constructor() {
113170
- this.workarea = [];
113241
+ // keyed by identifier position, insertion order is kept
113242
+ this.workarea = new Map();
113171
113243
  }
113172
113244
  push(id) {
113173
- for (const w of this.workarea) {
113174
- if (id.equals(w)) {
113175
- return;
113176
- }
113245
+ const key = WorkArea.buildKey(id);
113246
+ if (this.workarea.has(key) === false) {
113247
+ this.workarea.set(key, id);
113177
113248
  }
113178
- this.workarea.push(id);
113179
113249
  }
113180
113250
  removeIfExists(id) {
113181
- for (let i = 0; i < this.workarea.length; i++) {
113182
- if (id.equals(this.workarea[i])) {
113183
- this.workarea.splice(i, 1);
113184
- return;
113251
+ this.workarea.delete(WorkArea.buildKey(id));
113252
+ }
113253
+ /** removes the identifiers referenced somewhere */
113254
+ removeReferenced(referenced) {
113255
+ for (const key of [...this.workarea.keys()]) {
113256
+ if (referenced.has(key)) {
113257
+ this.workarea.delete(key);
113185
113258
  }
113186
113259
  }
113187
113260
  }
113188
113261
  get() {
113189
- return this.workarea;
113262
+ return [...this.workarea.values()];
113190
113263
  }
113191
113264
  count() {
113192
- return this.workarea.length;
113265
+ return this.workarea.size;
113266
+ }
113267
+ /** identifiers from one macro call share the row and column, the virtual position tells them apart */
113268
+ static buildKey(id) {
113269
+ const start = id.getStart();
113270
+ const key = id.getFilename() + "," + start.getRow() + "," + start.getCol();
113271
+ return start instanceof virtual_position_1.VirtualPosition ? key + "," + start.vrow + "," + start.vcol : key;
113193
113272
  }
113194
113273
  }
113195
113274
  class UnusedTypesConf extends _basic_rule_config_1.BasicRuleConfig {
@@ -113205,6 +113284,8 @@ exports.UnusedTypesConf = UnusedTypesConf;
113205
113284
  class UnusedTypes {
113206
113285
  constructor() {
113207
113286
  this.conf = new UnusedTypesConf();
113287
+ /** keys of the identifiers with a type reference in any object, built once per run when needed */
113288
+ this.referenced = undefined;
113208
113289
  }
113209
113290
  getMetadata() {
113210
113291
  return {
@@ -113228,6 +113309,7 @@ class UnusedTypes {
113228
113309
  }
113229
113310
  initialize(reg) {
113230
113311
  this.reg = reg;
113312
+ this.referenced = undefined;
113231
113313
  return this;
113232
113314
  }
113233
113315
  run(obj) {
@@ -113252,20 +113334,10 @@ class UnusedTypes {
113252
113334
  if (this.workarea.count() === 0) {
113253
113335
  return []; // exit early if all types are used in the current object
113254
113336
  }
113255
- for (const o of this.reg.getObjects()) {
113256
- if (o === obj) {
113257
- continue;
113258
- }
113259
- else if (o instanceof _abap_object_1.ABAPObject) {
113260
- if (this.reg.isDependency(o)) {
113261
- continue; // do not search in dependencies
113262
- }
113263
- const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
113264
- this.traverse(syntax.spaghetti.getTop(), o, false);
113265
- }
113266
- if (this.workarea.count() === 0) {
113267
- return []; // exit early if all types are used
113268
- }
113337
+ // uses in other objects, collected once instead of searching all objects for each object
113338
+ this.workarea.removeReferenced(this.getReferenced());
113339
+ if (this.workarea.count() === 0) {
113340
+ return []; // exit early if all types are used
113269
113341
  }
113270
113342
  // what is left is unused
113271
113343
  const ret = [];
@@ -113309,6 +113381,33 @@ class UnusedTypes {
113309
113381
  return false;
113310
113382
  }
113311
113383
  ////////////////////////////
113384
+ getReferenced() {
113385
+ if (this.referenced === undefined) {
113386
+ const referenced = new Set();
113387
+ for (const o of this.reg.getObjects()) {
113388
+ if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
113389
+ continue; // do not search in dependencies
113390
+ }
113391
+ const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
113392
+ this.collectReferenced(syntax.spaghetti.getTop(), referenced);
113393
+ }
113394
+ this.referenced = referenced;
113395
+ }
113396
+ return this.referenced;
113397
+ }
113398
+ /** same nodes and references as checkNode() with add = false */
113399
+ collectReferenced(node, referenced) {
113400
+ if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
113401
+ for (const r of node.getData().references) {
113402
+ if (r.referenceType === _reference_1.ReferenceType.TypeReference && r.resolved) {
113403
+ referenced.add(WorkArea.buildKey(r.resolved));
113404
+ }
113405
+ }
113406
+ }
113407
+ for (const c of node.getChildren()) {
113408
+ this.collectReferenced(c, referenced);
113409
+ }
113410
+ }
113312
113411
  traverse(node, obj, add) {
113313
113412
  if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
113314
113413
  this.checkNode(node, obj, add);
@@ -113428,17 +113527,17 @@ class WorkArea {
113428
113527
  this.workarea = new Map();
113429
113528
  }
113430
113529
  push(id, count = 1) {
113431
- const key = this.buildKey(id);
113530
+ const key = WorkArea.buildKey(id);
113432
113531
  if (this.workarea.has(key)) {
113433
113532
  return;
113434
113533
  }
113435
- this.workarea.set(key, { id, count });
113534
+ this.workarea.set(key, { id, count, required: count });
113436
113535
  }
113437
113536
  removeIfExists(id) {
113438
113537
  if (id === undefined) {
113439
113538
  return;
113440
113539
  }
113441
- const key = this.buildKey(id);
113540
+ const key = WorkArea.buildKey(id);
113442
113541
  const found = this.workarea.get(key);
113443
113542
  if (found !== undefined) {
113444
113543
  found.count--;
@@ -113447,13 +113546,23 @@ class WorkArea {
113447
113546
  }
113448
113547
  }
113449
113548
  }
113549
+ /** removes the identifiers with enough references, counts include all objects, also the one the
113550
+ * identifiers belong to, so it is compared to the required count and not the remaining count */
113551
+ removeReferenced(counts) {
113552
+ var _a;
113553
+ for (const [key, entry] of this.workarea) {
113554
+ if (((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) >= entry.required) {
113555
+ this.workarea.delete(key);
113556
+ }
113557
+ }
113558
+ }
113450
113559
  get() {
113451
113560
  return [...this.workarea.values()];
113452
113561
  }
113453
113562
  count() {
113454
113563
  return this.workarea.size;
113455
113564
  }
113456
- buildKey(id) {
113565
+ static buildKey(id) {
113457
113566
  const start = id.getStart();
113458
113567
  return id.getFilename() + "," + start.getRow() + "," + start.getCol();
113459
113568
  }
@@ -113461,6 +113570,8 @@ class WorkArea {
113461
113570
  class UnusedVariables {
113462
113571
  constructor() {
113463
113572
  this.conf = new UnusedVariablesConf();
113573
+ /** read, write and type references per identifier key in all objects, built once per run when needed */
113574
+ this.referenceCounts = undefined;
113464
113575
  }
113465
113576
  getMetadata() {
113466
113577
  return {
@@ -113498,6 +113609,7 @@ Errors found in INCLUDES are reported for the main program.`,
113498
113609
  }
113499
113610
  initialize(reg) {
113500
113611
  this.reg = reg;
113612
+ this.referenceCounts = undefined;
113501
113613
  return this;
113502
113614
  }
113503
113615
  run(obj) {
@@ -113525,34 +113637,53 @@ Errors found in INCLUDES are reported for the main program.`,
113525
113637
  if (this.workarea.count() === 0) {
113526
113638
  return this.buildIssues(obj); // exit early if all variables are used
113527
113639
  }
113528
- this.findUses(top, obj);
113529
- for (const o of this.reg.getObjects()) {
113530
- if (o === obj) {
113531
- continue;
113532
- }
113533
- else if (o instanceof _abap_object_1.ABAPObject) {
113534
- if (this.reg.isDependency(o)) {
113640
+ this.findUses(top);
113641
+ if (this.workarea.count() === 0) {
113642
+ return this.buildIssues(obj); // exit early if all variables are used
113643
+ }
113644
+ // uses in other objects, the counts are built once instead of searching all objects for each object
113645
+ this.workarea.removeReferenced(this.getReferenceCounts());
113646
+ return this.buildIssues(obj);
113647
+ }
113648
+ getReferenceCounts() {
113649
+ if (this.referenceCounts === undefined) {
113650
+ const counts = new Map();
113651
+ for (const o of this.reg.getObjects()) {
113652
+ if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
113535
113653
  continue; // do not search in dependencies
113536
113654
  }
113537
113655
  const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
113538
- this.findUses(syntax.spaghetti.getTop(), o);
113539
- if (this.workarea.count() === 0) {
113540
- return this.buildIssues(obj); // exit early if all variables are used
113541
- }
113656
+ this.countUses(syntax.spaghetti.getTop(), counts);
113542
113657
  }
113658
+ this.referenceCounts = counts;
113543
113659
  }
113544
- return this.buildIssues(obj);
113660
+ return this.referenceCounts;
113545
113661
  }
113546
- findUses(node, obj) {
113662
+ static isUse(r) {
113663
+ return r.referenceType === _reference_1.ReferenceType.DataReadReference
113664
+ || r.referenceType === _reference_1.ReferenceType.DataWriteReference
113665
+ || r.referenceType === _reference_1.ReferenceType.TypeReference;
113666
+ }
113667
+ findUses(node) {
113547
113668
  for (const r of node.getData().references) {
113548
- if (r.referenceType === _reference_1.ReferenceType.DataReadReference
113549
- || r.referenceType === _reference_1.ReferenceType.DataWriteReference
113550
- || r.referenceType === _reference_1.ReferenceType.TypeReference) {
113669
+ if (UnusedVariables.isUse(r)) {
113551
113670
  this.workarea.removeIfExists(r.resolved);
113552
113671
  }
113553
113672
  }
113554
113673
  for (const c of node.getChildren()) {
113555
- this.findUses(c, obj);
113674
+ this.findUses(c);
113675
+ }
113676
+ }
113677
+ countUses(node, counts) {
113678
+ var _a;
113679
+ for (const r of node.getData().references) {
113680
+ if (r.resolved !== undefined && UnusedVariables.isUse(r)) {
113681
+ const key = WorkArea.buildKey(r.resolved);
113682
+ counts.set(key, ((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
113683
+ }
113684
+ }
113685
+ for (const c of node.getChildren()) {
113686
+ this.countUses(c, counts);
113556
113687
  }
113557
113688
  }
113558
113689
  buildWorkarea(node, obj) {
@@ -117329,14 +117460,20 @@ class DatabaseSetup {
117329
117460
  for (const obj of this.reg.getObjects()) {
117330
117461
  if (obj instanceof abaplint.Objects.Table
117331
117462
  && obj.getTableCategory() === abaplint.Objects.TableCategory.Transparent) {
117332
- statements.push(schemaGenerator.buildTABL(obj).trim());
117463
+ const statement = schemaGenerator.buildTABL(obj).trim();
117464
+ if (statement.length > 0) {
117465
+ statements.push(statement);
117466
+ }
117333
117467
  }
117334
117468
  }
117335
117469
  // CREATE VIEWs after TABLEs
117336
117470
  // todo: what if the view is based on another view?
117337
117471
  for (const obj of this.reg.getObjects()) {
117338
117472
  if (obj instanceof abaplint.Objects.View) {
117339
- statements.push(schemaGenerator.buildVIEW(obj).trim());
117473
+ const statement = schemaGenerator.buildVIEW(obj).trim();
117474
+ if (statement.length > 0) {
117475
+ statements.push(statement);
117476
+ }
117340
117477
  }
117341
117478
  }
117342
117479
  return statements;
@@ -123887,7 +124024,8 @@ class TableExpressionTranspiler {
123887
124024
  else {
123888
124025
  // conditions
123889
124026
  for (const c of node.getChildren()) {
123890
- if (c === keyName || ["KEY", "COMPONENTS"].includes(c.concatTokens().toUpperCase())) {
124027
+ // only the keywords, a component can be named "key" or "components"
124028
+ if (c === keyName || (c instanceof core_1.Nodes.TokenNode && ["KEY", "COMPONENTS"].includes(c.concatTokens().toUpperCase()))) {
123891
124029
  continue;
123892
124030
  }
123893
124031
  if (c instanceof core_1.Nodes.ExpressionNode && c.get() instanceof core_1.Expressions.ComponentChainSimple) {
@@ -141828,10 +141966,14 @@ class Traversal {
141828
141966
  if (this.getCurrentObject().getABAPFileByName(filename) !== undefined) {
141829
141967
  return true;
141830
141968
  }
141831
- const file = this.reg.getFileByName(filename);
141832
- const found = file ? this.reg.findObjectForFile(file) : undefined;
141969
+ const found = this.findObjectForFilename(filename);
141833
141970
  return found instanceof abaplint.Objects.Program && found.isInclude();
141834
141971
  }
141972
+ /** the object containing the file, undefined if the file is not in the registry */
141973
+ findObjectForFilename(filename) {
141974
+ const file = this.reg.getFileByName(filename);
141975
+ return file === undefined ? undefined : this.reg.findObjectForFile(file);
141976
+ }
141835
141977
  traverse(node) {
141836
141978
  if (node instanceof abaplint.Nodes.StructureNode) {
141837
141979
  return this.traverseStructure(node);
@@ -141986,17 +142128,12 @@ class Traversal {
141986
142128
  let name = t.getStr().toLowerCase().replace(/^!/, "");
141987
142129
  if (filename && this.isCurrentObjectFile(filename) === false) {
141988
142130
  // the prefix is from a different object
141989
- const file = this.reg.getFileByName(filename);
141990
- if (file) {
141991
- const found = this.reg.findObjectForFile(file);
141992
- if (found) {
141993
- if (found instanceof abaplint.Objects.Interface) {
141994
- return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + found.getName().toLowerCase() + "$" + name;
141995
- }
141996
- else {
141997
- return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + name;
141998
- }
141999
- }
142131
+ const found = this.findObjectForFilename(filename);
142132
+ if (found instanceof abaplint.Objects.Interface) {
142133
+ return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + found.getName().toLowerCase() + "$" + name;
142134
+ }
142135
+ else if (found) {
142136
+ return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + name;
142000
142137
  }
142001
142138
  }
142002
142139
  const className = this.isStaticClassAttribute(t);
@@ -142261,12 +142398,7 @@ class Traversal {
142261
142398
  isTypePool(token) {
142262
142399
  const ref = this.findReadOrWriteReference(token);
142263
142400
  if (ref?.getFilename().endsWith(".type.abap")) {
142264
- const file = this.reg.getFileByName(ref.getFilename());
142265
- if (file === undefined) {
142266
- return undefined;
142267
- }
142268
- const obj = this.reg.findObjectForFile(file);
142269
- return obj?.getName();
142401
+ return this.findObjectForFilename(ref.getFilename())?.getName();
142270
142402
  }
142271
142403
  return undefined;
142272
142404
  }
@@ -142706,8 +142838,7 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
142706
142838
  findEnumValueIndex(identifier) {
142707
142839
  // the enum can be declared in another object, eg. a global interface the class implements
142708
142840
  const filename = identifier.getFilename();
142709
- const raw = this.reg.getFileByName(filename);
142710
- const obj = raw === undefined ? undefined : this.reg.findObjectForFile(raw);
142841
+ const obj = this.findObjectForFilename(filename);
142711
142842
  const file = obj instanceof abaplint.ABAPObject ? obj.getABAPFileByName(filename) : undefined;
142712
142843
  for (const enumeration of file?.getStructure()?.findAllStructures(abaplint.Structures.TypeEnum) || []) {
142713
142844
  const values = enumeration.getChildren().filter(c => c instanceof abaplint.Nodes.StatementNode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.14.30",
3
+ "version": "2.14.31",
4
4
  "description": "Transpiler - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -27,8 +27,8 @@
27
27
  "author": "abaplint",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@abaplint/core": "^2.120.103",
31
- "@abaplint/transpiler": "^2.14.30",
30
+ "@abaplint/core": "^2.120.105",
31
+ "@abaplint/transpiler": "^2.14.31",
32
32
  "@types/glob": "^9.0.0",
33
33
  "@types/node": "^26.6.6",
34
34
  "@types/progress": "^2.0.7",