@abaplint/transpiler-cli 2.13.43 → 2.13.45

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 +108 -70
  2. package/package.json +3 -3
package/build/bundle.js CHANGED
@@ -30441,7 +30441,7 @@ class CondBody {
30441
30441
  type = source_1.Source.runSyntax(s, input, targetType);
30442
30442
  }
30443
30443
  else {
30444
- source_1.Source.runSyntax(s, input, targetType);
30444
+ source_1.Source.runSyntax(s, input, targetType !== null && targetType !== void 0 ? targetType : type);
30445
30445
  }
30446
30446
  }
30447
30447
  if (scoped === true) {
@@ -34510,7 +34510,7 @@ class Source {
34510
34510
  case "SWITCH":
34511
34511
  {
34512
34512
  const foundType = this.determineType(node, input, targetType);
34513
- const bodyType = switch_body_1.SwitchBody.runSyntax(node.findDirectExpression(Expressions.SwitchBody), input);
34513
+ const bodyType = switch_body_1.SwitchBody.runSyntax(node.findDirectExpression(Expressions.SwitchBody), input, foundType);
34514
34514
  if (foundType === undefined || foundType.isGeneric()) {
34515
34515
  this.addIfInferred(node, input, bodyType);
34516
34516
  }
@@ -35592,7 +35592,7 @@ const source_1 = __webpack_require__(/*! ./source */ "./node_modules/@abaplint/c
35592
35592
  const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
35593
35593
  const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
35594
35594
  class SwitchBody {
35595
- static runSyntax(node, input) {
35595
+ static runSyntax(node, input, targetType) {
35596
35596
  if (node === undefined) {
35597
35597
  return;
35598
35598
  }
@@ -35602,12 +35602,12 @@ class SwitchBody {
35602
35602
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
35603
35603
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
35604
35604
  }
35605
- const type = source_1.Source.runSyntax(thenSource, input);
35605
+ const type = source_1.Source.runSyntax(thenSource, input, targetType);
35606
35606
  for (const s of node.findDirectExpressions(Expressions.Source)) {
35607
35607
  if (s === thenSource) {
35608
35608
  continue;
35609
35609
  }
35610
- source_1.Source.runSyntax(s, input);
35610
+ source_1.Source.runSyntax(s, input, targetType !== null && targetType !== void 0 ? targetType : type);
35611
35611
  }
35612
35612
  return type;
35613
35613
  }
@@ -38739,6 +38739,10 @@ class Constant {
38739
38739
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, found.getToken(), message));
38740
38740
  return new _typed_identifier_1.TypedIdentifier(found.getToken(), input.filename, basic_2.VoidType.get(_syntax_input_1.CheckSyntaxKey), meta, val);
38741
38741
  }
38742
+ if (this.isNameTooLong(found.getName())) {
38743
+ const message = "CONSTANTS name too long, " + found.getName();
38744
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, found.getToken(), message));
38745
+ }
38742
38746
  return new _typed_identifier_1.TypedIdentifier(found.getToken(), input.filename, found.getType(), meta, val);
38743
38747
  }
38744
38748
  const fallback = node.findFirstExpression(Expressions.DefinitionName);
@@ -38747,10 +38751,17 @@ class Constant {
38747
38751
  const message = "not possible to have a name with only digits";
38748
38752
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, fallback.getFirstToken(), message));
38749
38753
  }
38754
+ if (this.isNameTooLong(fallback.concatTokens())) {
38755
+ const message = "CONSTANTS name too long, " + fallback.concatTokens();
38756
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, fallback.getFirstToken(), message));
38757
+ }
38750
38758
  return new _typed_identifier_1.TypedIdentifier(fallback.getFirstToken(), input.filename, new basic_1.UnknownType("constant, fallback"));
38751
38759
  }
38752
38760
  throw new assert_error_1.AssertError("Statement Constant: unexpected structure");
38753
38761
  }
38762
+ isNameTooLong(name) {
38763
+ return name.length > 30;
38764
+ }
38754
38765
  isOnlyDigits(name) {
38755
38766
  return /^[0-9]+$/.test(name);
38756
38767
  }
@@ -39341,6 +39352,10 @@ class Data {
39341
39352
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, id.getToken(), message));
39342
39353
  return new _typed_identifier_1.TypedIdentifier(id.getToken(), input.filename, basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey));
39343
39354
  }
39355
+ if (id && this.isNameTooLong(id.getName())) {
39356
+ const message = "DATA name too long, " + id.getName();
39357
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, id.getToken(), message));
39358
+ }
39344
39359
  if ((id === null || id === void 0 ? void 0 : id.getType().isGeneric()) === true
39345
39360
  && (id === null || id === void 0 ? void 0 : id.getType().containsVoid()) === false) {
39346
39361
  const message = "DATA definition cannot be generic, " + (name === null || name === void 0 ? void 0 : name.concatTokens());
@@ -39354,10 +39369,17 @@ class Data {
39354
39369
  const message = "not possible to have a name with only digits";
39355
39370
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, name.getFirstToken(), message));
39356
39371
  }
39372
+ if (this.isNameTooLong(name.concatTokens())) {
39373
+ const message = "DATA name too long, " + name.concatTokens();
39374
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, name.getFirstToken(), message));
39375
+ }
39357
39376
  return new _typed_identifier_1.TypedIdentifier(name.getFirstToken(), input.filename, new unknown_type_1.UnknownType("data, fallback"));
39358
39377
  }
39359
39378
  return undefined;
39360
39379
  }
39380
+ isNameTooLong(name) {
39381
+ return name.length > 30;
39382
+ }
39361
39383
  isOnlyDigits(name) {
39362
39384
  return /^[0-9]+$/.test(name);
39363
39385
  }
@@ -47974,16 +47996,17 @@ class SyntaxLogic {
47974
47996
  this.reg = reg;
47975
47997
  this.issues = [];
47976
47998
  this.object = object;
47977
- this.scope = _current_scope_1.CurrentScope.buildDefault(this.reg, object);
47978
- this.helpers = {
47979
- oooc: new _object_oriented_1.ObjectOriented(this.scope),
47980
- proc: new _procedural_1.Procedural(this.reg, this.scope),
47981
- };
47982
47999
  }
47983
48000
  run() {
47984
48001
  if (this.object.syntaxResult !== undefined) {
47985
48002
  return this.object.syntaxResult;
47986
48003
  }
48004
+ // the scope is built here instead of in the constructor, cached results must stay cheap
48005
+ this.scope = _current_scope_1.CurrentScope.buildDefault(this.reg, this.object);
48006
+ this.helpers = {
48007
+ oooc: new _object_oriented_1.ObjectOriented(this.scope),
48008
+ proc: new _procedural_1.Procedural(this.reg, this.scope),
48009
+ };
47987
48010
  this.issues = [];
47988
48011
  this.reg.getDDICReferences().clear(this.object);
47989
48012
  this.reg.getMSAGReferences().clear(this.object);
@@ -69469,7 +69492,7 @@ class Registry {
69469
69492
  }
69470
69493
  static abaplintVersion() {
69471
69494
  // magic, see build script "version.js"
69472
- return "2.120.4";
69495
+ return "2.120.5";
69473
69496
  }
69474
69497
  getDDICReferences() {
69475
69498
  return this.ddicReferences;
@@ -97432,35 +97455,38 @@ class UnusedVariablesConf extends _basic_rule_config_1.BasicRuleConfig {
97432
97455
  exports.UnusedVariablesConf = UnusedVariablesConf;
97433
97456
  class WorkArea {
97434
97457
  constructor() {
97435
- this.workarea = [];
97458
+ // keyed by filename + start position, this equals Identifier.equals()
97459
+ this.workarea = new Map();
97436
97460
  }
97437
97461
  push(id, count = 1) {
97438
- for (const w of this.workarea) {
97439
- if (id.equals(w.id)) {
97440
- return;
97441
- }
97462
+ const key = this.buildKey(id);
97463
+ if (this.workarea.has(key)) {
97464
+ return;
97442
97465
  }
97443
- this.workarea.push({ id, count });
97466
+ this.workarea.set(key, { id, count });
97444
97467
  }
97445
97468
  removeIfExists(id) {
97446
97469
  if (id === undefined) {
97447
97470
  return;
97448
97471
  }
97449
- for (let i = 0; i < this.workarea.length; i++) {
97450
- if (id.equals(this.workarea[i].id)) {
97451
- this.workarea[i].count--;
97452
- if (this.workarea[i].count === 0) {
97453
- this.workarea.splice(i, 1);
97454
- }
97455
- return;
97472
+ const key = this.buildKey(id);
97473
+ const found = this.workarea.get(key);
97474
+ if (found !== undefined) {
97475
+ found.count--;
97476
+ if (found.count === 0) {
97477
+ this.workarea.delete(key);
97456
97478
  }
97457
97479
  }
97458
97480
  }
97459
97481
  get() {
97460
- return this.workarea;
97482
+ return [...this.workarea.values()];
97461
97483
  }
97462
97484
  count() {
97463
- return this.workarea.length;
97485
+ return this.workarea.size;
97486
+ }
97487
+ buildKey(id) {
97488
+ const start = id.getStart();
97489
+ return id.getFilename() + "," + start.getRow() + "," + start.getCol();
97464
97490
  }
97465
97491
  }
97466
97492
  class UnusedVariables {
@@ -97594,6 +97620,9 @@ Errors found in INCLUDES are reported for the main program.`,
97594
97620
  }
97595
97621
  buildIssues(obj) {
97596
97622
  const ret = [];
97623
+ const metadata = this.getMetadata();
97624
+ const pragma = metadata.pragma + "";
97625
+ const files = new Map();
97597
97626
  for (const w of this.workarea.get()) {
97598
97627
  const filename = w.id.getFilename();
97599
97628
  if (this.reg.isFileDependency(filename) === true) {
@@ -97602,41 +97631,52 @@ Errors found in INCLUDES are reported for the main program.`,
97602
97631
  else if (obj instanceof objects_1.Program === false && obj.containsFile(filename) === false) {
97603
97632
  continue;
97604
97633
  }
97605
- const statement = this.findStatement(w.id);
97606
- if (statement === null || statement === void 0 ? void 0 : statement.getPragmas().map(t => t.getStr()).includes(this.getMetadata().pragma + "")) {
97607
- continue;
97634
+ if (files.has(filename) === false) {
97635
+ files.set(filename, this.findFile(filename));
97636
+ }
97637
+ const file = files.get(filename);
97638
+ let statement = undefined;
97639
+ let statementIndex = -1;
97640
+ if (file !== undefined) {
97641
+ const statements = file.getStatements();
97642
+ const token = w.id.getToken();
97643
+ for (let i = 0; i < statements.length; i++) {
97644
+ if (statements[i].includesToken(token)) {
97645
+ statement = statements[i];
97646
+ statementIndex = i;
97647
+ break;
97648
+ }
97649
+ }
97608
97650
  }
97609
- else if (this.suppressedbyPseudo(statement, w.id, obj)) {
97610
- continue;
97651
+ if (statement !== undefined && file !== undefined) {
97652
+ if (statement.getPragmas().some(t => t.getStr() === pragma)) {
97653
+ continue;
97654
+ }
97655
+ else if (this.suppressedbyPseudo(file, statementIndex, w.id, obj)) {
97656
+ continue;
97657
+ }
97611
97658
  }
97612
97659
  const name = w.id.getName();
97613
97660
  const message = "Variable \"" + name.toLowerCase() + "\" not used";
97614
- const fix = this.buildFix(w.id, obj);
97615
- ret.push(issue_1.Issue.atIdentifier(w.id, message, this.getMetadata().key, this.conf.severity, fix));
97661
+ const fix = this.buildFix(w.id, obj, statement);
97662
+ ret.push(issue_1.Issue.atIdentifier(w.id, message, metadata.key, this.conf.severity, fix));
97616
97663
  }
97617
97664
  return ret;
97618
97665
  }
97619
- suppressedbyPseudo(statement, v, obj) {
97620
- if (statement === undefined) {
97621
- return false;
97622
- }
97623
- const file = obj.getABAPFileByName(v.getFilename());
97624
- if (file === undefined) {
97666
+ suppressedbyPseudo(file, statementIndex, v, obj) {
97667
+ // pseudo comments are only found in files belonging to the object itself, not in eg. includes
97668
+ if (obj.getABAPFileByName(v.getFilename()) === undefined) {
97625
97669
  return false;
97626
97670
  }
97627
- let next = false;
97628
- for (const s of file.getStatements()) {
97629
- if (next === true && s.get() instanceof _statement_1.Comment) {
97630
- return s.concatTokens().includes(this.getMetadata().pseudoComment + "");
97631
- }
97632
- if (s === statement) {
97633
- next = true;
97634
- }
97635
- }
97636
- return false;
97671
+ const statements = file.getStatements();
97672
+ const next = statements[statementIndex + 1];
97673
+ return (next === null || next === void 0 ? void 0 : next.get()) instanceof _statement_1.Comment
97674
+ && next.concatTokens().includes(this.getMetadata().pseudoComment + "");
97675
+ // removed by dead control flow
97676
+
97637
97677
  }
97638
- findStatement(v) {
97639
- const file = this.reg.getFileByName(v.getFilename());
97678
+ findFile(filename) {
97679
+ const file = this.reg.getFileByName(filename);
97640
97680
  if (file === undefined) {
97641
97681
  return undefined;
97642
97682
  }
@@ -97644,26 +97684,17 @@ Errors found in INCLUDES are reported for the main program.`,
97644
97684
  if (!(object instanceof _abap_object_1.ABAPObject)) {
97645
97685
  return undefined;
97646
97686
  }
97647
- const abapfile = object.getABAPFileByName(v.getFilename());
97648
- if (abapfile === undefined) {
97687
+ return object.getABAPFileByName(filename);
97688
+ }
97689
+ buildFix(v, obj, statement) {
97690
+ if (statement === undefined || !(statement.get() instanceof Statements.Data)) {
97649
97691
  return undefined;
97650
97692
  }
97651
- const statement = edit_helper_1.EditHelper.findStatement(v.getToken(), abapfile);
97652
- return statement;
97653
- }
97654
- buildFix(v, obj) {
97655
97693
  const file = obj.getABAPFileByName(v.getFilename());
97656
97694
  if (file === undefined) {
97657
97695
  return undefined;
97658
97696
  }
97659
- const statement = edit_helper_1.EditHelper.findStatement(v.getToken(), file);
97660
- if (statement === undefined) {
97661
- return undefined;
97662
- }
97663
- else if (statement.get() instanceof Statements.Data) {
97664
- return edit_helper_1.EditHelper.deleteStatement(file, statement);
97665
- }
97666
- return undefined;
97697
+ return edit_helper_1.EditHelper.deleteStatement(file, statement);
97667
97698
  }
97668
97699
  }
97669
97700
  exports.UnusedVariables = UnusedVariables;
@@ -101904,14 +101935,12 @@ const type_name_or_infer_1 = __webpack_require__(/*! ./type_name_or_infer */ "./
101904
101935
  const transpile_types_1 = __webpack_require__(/*! ../transpile_types */ "./node_modules/@abaplint/transpiler/build/src/transpile_types.js");
101905
101936
  const cond_1 = __webpack_require__(/*! ./cond */ "./node_modules/@abaplint/transpiler/build/src/expressions/cond.js");
101906
101937
  const source_1 = __webpack_require__(/*! ./source */ "./node_modules/@abaplint/transpiler/build/src/expressions/source.js");
101938
+ const let_1 = __webpack_require__(/*! ./let */ "./node_modules/@abaplint/transpiler/build/src/expressions/let.js");
101907
101939
  class CondBodyTranspiler {
101908
101940
  transpile(typ, body, traversal) {
101909
101941
  if (!(typ.get() instanceof core_1.Expressions.TypeNameOrInfer)) {
101910
101942
  throw new Error("CondBodyTranspiler, Expected TypeNameOrInfer");
101911
101943
  }
101912
- else if (body.findDirectExpression(core_1.Expressions.Let)) {
101913
- throw new Error("CondBodyTranspiler, Let not supported, todo");
101914
- }
101915
101944
  const whenThen = [];
101916
101945
  const expressions = [];
101917
101946
  for (const c of body.getChildren()) {
@@ -101920,7 +101949,7 @@ class CondBodyTranspiler {
101920
101949
  break;
101921
101950
  }
101922
101951
  }
101923
- else {
101952
+ else if (!(c.get() instanceof core_1.Expressions.Let)) {
101924
101953
  expressions.push(c);
101925
101954
  }
101926
101955
  }
@@ -101932,6 +101961,10 @@ class CondBodyTranspiler {
101932
101961
  const ret = new chunk_1.Chunk();
101933
101962
  ret.appendString("(" + target + ".set(");
101934
101963
  ret.appendString("await (async () => {\n");
101964
+ const llet = body.findDirectExpression(core_1.Expressions.Let);
101965
+ if (llet) {
101966
+ ret.appendString(new let_1.LetTranspiler().transpile(llet, traversal).getCode());
101967
+ }
101935
101968
  for (const { when, then } of whenThen) {
101936
101969
  let condition = "";
101937
101970
  if (when.get() instanceof core_1.Expressions.Cond) {
@@ -104093,7 +104126,12 @@ class SourceTranspiler {
104093
104126
  ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(").dereference()");
104094
104127
  }
104095
104128
  else if (c.get() instanceof core_1.Expressions.TextElement) {
104096
- ret = new chunk_1.Chunk().appendString(`new abap.types.String().set("${c.concatTokens()}")`);
104129
+ const key = c.findFirstExpression(core_1.Expressions.TextElementKey)?.concatTokens().toUpperCase();
104130
+ const textSymbol = key === undefined
104131
+ ? undefined
104132
+ : traversal.getCurrentObject().getTextSymbols()[key]?.entry;
104133
+ const value = textSymbol ?? c.concatTokens();
104134
+ ret = new chunk_1.Chunk().appendString(`new abap.types.String().set(${JSON.stringify(value)})`);
104097
104135
  }
104098
104136
  else if (c.get() instanceof core_1.Expressions.TypeNameOrInfer) {
104099
104137
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.13.43",
3
+ "version": "2.13.45",
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.4",
31
- "@abaplint/transpiler": "^2.13.43",
30
+ "@abaplint/core": "^2.120.5",
31
+ "@abaplint/transpiler": "^2.13.45",
32
32
  "@types/glob": "^8.1.0",
33
33
  "@types/node": "^24.12.2",
34
34
  "@types/progress": "^2.0.7",