@abaplint/cli 2.120.105 → 2.120.106

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 +242 -3
  2. package/package.json +2 -2
package/build/cli.js CHANGED
@@ -28348,6 +28348,236 @@ exports.SortedKeyWrite = SortedKeyWrite;
28348
28348
 
28349
28349
  /***/ },
28350
28350
 
28351
+ /***/ "../core/build/src/abap/5_syntax/_super_constructor_call.js"
28352
+ /*!******************************************************************!*\
28353
+ !*** ../core/build/src/abap/5_syntax/_super_constructor_call.js ***!
28354
+ \******************************************************************/
28355
+ (__unused_webpack_module, exports, __webpack_require__) {
28356
+
28357
+ "use strict";
28358
+
28359
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
28360
+ if (k2 === undefined) k2 = k;
28361
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28362
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28363
+ desc = { enumerable: true, get: function() { return m[k]; } };
28364
+ }
28365
+ Object.defineProperty(o, k2, desc);
28366
+ }) : (function(o, m, k, k2) {
28367
+ if (k2 === undefined) k2 = k;
28368
+ o[k2] = m[k];
28369
+ }));
28370
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28371
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
28372
+ }) : function(o, v) {
28373
+ o["default"] = v;
28374
+ });
28375
+ var __importStar = (this && this.__importStar) || (function () {
28376
+ var ownKeys = function(o) {
28377
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28378
+ var ar = [];
28379
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28380
+ return ar;
28381
+ };
28382
+ return ownKeys(o);
28383
+ };
28384
+ return function (mod) {
28385
+ if (mod && mod.__esModule) return mod;
28386
+ var result = {};
28387
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
28388
+ __setModuleDefault(result, mod);
28389
+ return result;
28390
+ };
28391
+ })();
28392
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
28393
+ exports.SuperConstructorCall = void 0;
28394
+ const Expressions = __importStar(__webpack_require__(/*! ../2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
28395
+ const Statements = __importStar(__webpack_require__(/*! ../2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
28396
+ const _statement_1 = __webpack_require__(/*! ../2_statements/statements/_statement */ "../core/build/src/abap/2_statements/statements/_statement.js");
28397
+ const dash_1 = __webpack_require__(/*! ../1_lexer/tokens/dash */ "../core/build/src/abap/1_lexer/tokens/dash.js");
28398
+ const identifier_1 = __webpack_require__(/*! ../1_lexer/tokens/identifier */ "../core/build/src/abap/1_lexer/tokens/identifier.js");
28399
+ const virtual_position_1 = __webpack_require__(/*! ../../virtual_position */ "../core/build/src/virtual_position.js");
28400
+ const _syntax_input_1 = __webpack_require__(/*! ./_syntax_input */ "../core/build/src/abap/5_syntax/_syntax_input.js");
28401
+ /** The constructor of a subclass must call SUPER->CONSTRUCTOR, and before the call instance
28402
+ * attributes, instance methods and ME cannot be used. Runs when the method has been traversed,
28403
+ * scopeNode is the outermost scope of the method, holding the references of its body. */
28404
+ class SuperConstructorCall {
28405
+ static check(method, scopeNode, input) {
28406
+ var _a;
28407
+ const methodStatement = method.findDirectStatement(Statements.MethodImplementation);
28408
+ const methodName = (_a = methodStatement === null || methodStatement === void 0 ? void 0 : methodStatement.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
28409
+ if (methodStatement === undefined || (methodName === null || methodName === void 0 ? void 0 : methodName.toUpperCase()) !== "CONSTRUCTOR") {
28410
+ return;
28411
+ }
28412
+ const classDefinition = input.scope.findClassDefinition(input.scope.getName());
28413
+ const superName = classDefinition === null || classDefinition === void 0 ? void 0 : classDefinition.getSuperClass();
28414
+ if (classDefinition === undefined || superName === undefined || superName.toUpperCase() === "OBJECT") {
28415
+ return;
28416
+ }
28417
+ const statements = method.findAllStatementNodes();
28418
+ for (const s of statements) {
28419
+ const type = s.get();
28420
+ if (type instanceof _statement_1.Unknown || type instanceof _statement_1.MacroCall
28421
+ || s.getFirstToken().getStart() instanceof virtual_position_1.VirtualPosition) {
28422
+ return;
28423
+ }
28424
+ }
28425
+ const callIndex = statements.findIndex(s => SuperConstructorCall.isSuperConstructorCall(s));
28426
+ // at most one issue is reported per constructor
28427
+ if (callIndex < 0) {
28428
+ const message = "The constructor of a subclass must call SUPER->CONSTRUCTOR";
28429
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodStatement.getFirstToken(), message));
28430
+ return;
28431
+ }
28432
+ // the statements before the call, the call itself can pass instance attributes, eg. previous = previous,
28433
+ // declarations can refer to instance attributes for typing, eg. DATA ls_row LIKE LINE OF mt_table
28434
+ const before = statements.slice(1, callIndex)
28435
+ .filter(s => !(s.get() instanceof _statement_1.NativeSQL) && !SuperConstructorCall.isDeclaration(s));
28436
+ const offending = SuperConstructorCall.findInstanceAccess(before, classDefinition, scopeNode, input);
28437
+ if (offending !== undefined) {
28438
+ const message = "Instance attributes, instance methods and ME can only be accessed after SUPER->CONSTRUCTOR is called";
28439
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, offending, message));
28440
+ }
28441
+ }
28442
+ static isDeclaration(statement) {
28443
+ const type = statement.get();
28444
+ return type instanceof Statements.Data
28445
+ || type instanceof Statements.DataBegin
28446
+ || type instanceof Statements.DataEnd
28447
+ || type instanceof Statements.Constant
28448
+ || type instanceof Statements.ConstantBegin
28449
+ || type instanceof Statements.ConstantEnd
28450
+ || type instanceof Statements.Type
28451
+ || type instanceof Statements.TypeBegin
28452
+ || type instanceof Statements.TypeEnd
28453
+ || type instanceof Statements.Static
28454
+ || type instanceof Statements.StaticBegin
28455
+ || type instanceof Statements.StaticEnd
28456
+ || type instanceof Statements.IncludeType
28457
+ || type instanceof Statements.FieldSymbol;
28458
+ }
28459
+ static isSuperConstructorCall(statement) {
28460
+ const tokens = statement.getTokens();
28461
+ for (let i = 0; i < tokens.length - 2; i++) {
28462
+ if (tokens[i].getStr().toUpperCase() === "SUPER"
28463
+ && tokens[i + 1].getStr() === "->"
28464
+ && tokens[i + 2].getStr().toUpperCase() === "CONSTRUCTOR") {
28465
+ return true;
28466
+ }
28467
+ }
28468
+ return false;
28469
+ }
28470
+ /** returns the first offending token */
28471
+ static findInstanceAccess(statements, classDefinition, scopeNode, input) {
28472
+ const instance = SuperConstructorCall.listInstanceMembers(classDefinition, input);
28473
+ const references = SuperConstructorCall.listReferences(scopeNode, input.filename);
28474
+ for (const statement of statements) {
28475
+ const tokens = statement.getTokens();
28476
+ for (let i = 0; i < tokens.length; i++) {
28477
+ const token = tokens[i];
28478
+ if (SuperConstructorCall.isMe(tokens, i)) {
28479
+ return token;
28480
+ }
28481
+ const resolved = references.get(SuperConstructorCall.key(token));
28482
+ if (resolved !== undefined
28483
+ && resolved.some(r => instance.has(r))
28484
+ && SuperConstructorCall.isOwnAccess(tokens, i)) {
28485
+ return token;
28486
+ }
28487
+ }
28488
+ }
28489
+ return undefined;
28490
+ }
28491
+ /** ME used as a value, me->component is allowed for constants and static components,
28492
+ * instance components are found via the references */
28493
+ static isMe(tokens, index) {
28494
+ var _a;
28495
+ const token = tokens[index];
28496
+ if (!(token instanceof identifier_1.Identifier) || token.getStr().toUpperCase() !== "ME") {
28497
+ return false;
28498
+ }
28499
+ const prev = tokens[index - 1];
28500
+ if (prev !== undefined && (prev instanceof dash_1.Dash || ["->", "=>", "~"].includes(prev.getStr()))) {
28501
+ return false;
28502
+ }
28503
+ return ((_a = tokens[index + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) !== "->";
28504
+ }
28505
+ /** the member is accessed via the implicit or explicit self reference, not via another object or class */
28506
+ static isOwnAccess(tokens, index) {
28507
+ var _a;
28508
+ const prev = tokens[index - 1];
28509
+ if (prev === undefined) {
28510
+ return true;
28511
+ }
28512
+ else if (prev.getStr() === "->") {
28513
+ return ((_a = tokens[index - 2]) === null || _a === void 0 ? void 0 : _a.getStr().toUpperCase()) === "ME";
28514
+ }
28515
+ return !(prev instanceof dash_1.Dash || ["=>", "~"].includes(prev.getStr()));
28516
+ }
28517
+ /** instance attributes and methods of the class, its super classes and implemented interfaces */
28518
+ static listInstanceMembers(classDefinition, input) {
28519
+ const ret = new Set();
28520
+ const visited = new Set();
28521
+ const stack = [classDefinition];
28522
+ while (stack.length > 0) {
28523
+ const current = stack.pop();
28524
+ const name = current.getName().toUpperCase();
28525
+ if (visited.has(name)) {
28526
+ continue;
28527
+ }
28528
+ visited.add(name);
28529
+ for (const a of current.getAttributes().getInstance()) {
28530
+ ret.add(a);
28531
+ }
28532
+ for (const m of current.getMethodDefinitions().getAll()) {
28533
+ if (m.isStatic() === false) {
28534
+ ret.add(m);
28535
+ }
28536
+ }
28537
+ for (const i of current.getImplementing()) {
28538
+ const intf = input.scope.findInterfaceDefinition(i.name);
28539
+ if (intf !== undefined) {
28540
+ stack.push(intf);
28541
+ }
28542
+ }
28543
+ if ("getSuperClass" in current) {
28544
+ const sup = input.scope.findClassDefinition(current.getSuperClass());
28545
+ if (sup !== undefined) {
28546
+ stack.push(sup);
28547
+ }
28548
+ }
28549
+ }
28550
+ return ret;
28551
+ }
28552
+ /** resolved references of the method body by token position */
28553
+ static listReferences(node, filename) {
28554
+ var _a;
28555
+ const ret = new Map();
28556
+ const stack = node ? [node] : [];
28557
+ while (stack.length > 0) {
28558
+ const current = stack.pop();
28559
+ stack.push(...current.getChildren());
28560
+ for (const r of current.getData().references) {
28561
+ if (r.resolved === undefined || r.position.getFilename() !== filename) {
28562
+ continue;
28563
+ }
28564
+ const key = SuperConstructorCall.key(r.position.getToken());
28565
+ const list = (_a = ret.get(key)) !== null && _a !== void 0 ? _a : [];
28566
+ list.push(r.resolved);
28567
+ ret.set(key, list);
28568
+ }
28569
+ }
28570
+ return ret;
28571
+ }
28572
+ static key(token) {
28573
+ return token.getRow() + ":" + token.getCol();
28574
+ }
28575
+ }
28576
+ exports.SuperConstructorCall = SuperConstructorCall;
28577
+ //# sourceMappingURL=_super_constructor_call.js.map
28578
+
28579
+ /***/ },
28580
+
28351
28581
  /***/ "../core/build/src/abap/5_syntax/_syntax_input.js"
28352
28582
  /*!********************************************************!*\
28353
28583
  !*** ../core/build/src/abap/5_syntax/_syntax_input.js ***!
@@ -50804,6 +51034,7 @@ const field_group_1 = __webpack_require__(/*! ./statements/field_group */ "../co
50804
51034
  const stuff_1 = __webpack_require__(/*! ../../stuff */ "../core/build/src/stuff.js");
50805
51035
  const _loop_table_change_1 = __webpack_require__(/*! ./_loop_table_change */ "../core/build/src/abap/5_syntax/_loop_table_change.js");
50806
51036
  const _sorted_key_write_1 = __webpack_require__(/*! ./_sorted_key_write */ "../core/build/src/abap/5_syntax/_sorted_key_write.js");
51037
+ const _super_constructor_call_1 = __webpack_require__(/*! ./_super_constructor_call */ "../core/build/src/abap/5_syntax/_super_constructor_call.js");
50807
51038
  // -----------------------------------
50808
51039
  const map = {};
50809
51040
  function addToMap(handler) {
@@ -51150,6 +51381,9 @@ class SyntaxLogic {
51150
51381
  else if (stru instanceof Structures.Try) {
51151
51382
  try_1.Try.runSyntax(node, input);
51152
51383
  }
51384
+ else if (stru instanceof Structures.Method) {
51385
+ this.currentMethod = node;
51386
+ }
51153
51387
  return false;
51154
51388
  }
51155
51389
  updateScopeStatement(node) {
@@ -51197,12 +51431,17 @@ class SyntaxLogic {
51197
51431
  this.scope.pop(node.getLastToken().getEnd());
51198
51432
  }
51199
51433
  else if (s instanceof Statements.EndMethod) {
51434
+ let popped = undefined;
51200
51435
  if (this.scope.getType() === _scope_type_1.ScopeType.Method) {
51201
- this.scope.pop(node.getLastToken().getEnd());
51436
+ popped = this.scope.pop(node.getLastToken().getEnd());
51202
51437
  }
51203
51438
  if (this.scope.getType() === _scope_type_1.ScopeType.MethodInstance) {
51204
- this.scope.pop(node.getLastToken().getEnd());
51439
+ popped = this.scope.pop(node.getLastToken().getEnd());
51440
+ }
51441
+ if (this.currentMethod !== undefined && popped !== undefined) {
51442
+ _super_constructor_call_1.SuperConstructorCall.check(this.currentMethod, popped.getTop(), input);
51205
51443
  }
51444
+ this.currentMethod = undefined;
51206
51445
  }
51207
51446
  }
51208
51447
  updateSelectionEventScope(node) {
@@ -73639,7 +73878,7 @@ class Registry {
73639
73878
  }
73640
73879
  static abaplintVersion() {
73641
73880
  // magic, see build script "version.js"
73642
- return "2.120.105";
73881
+ return "2.120.106";
73643
73882
  }
73644
73883
  getDDICReferences() {
73645
73884
  return this.ddicReferences;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/cli",
3
- "version": "2.120.105",
3
+ "version": "2.120.106",
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.105",
42
+ "@abaplint/core": "^2.120.106",
43
43
  "@types/chai": "^4.3.20",
44
44
  "@types/minimist": "^1.2.5",
45
45
  "@types/mocha": "^10.0.10",