source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/migrations/method-call-arguments.mjs@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 8.8 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.MethodCallArgumentsMigration = void 0;
11const ts = require("typescript");
12const migration_1 = require("../../update-tool/migration");
13const upgrade_data_1 = require("../upgrade-data");
14/**
15 * Migration that visits every TypeScript method call expression and checks if the
16 * argument count is invalid and needs to be *manually* updated.
17 */
18class MethodCallArgumentsMigration extends migration_1.Migration {
19 constructor() {
20 super(...arguments);
21 /** Change data that upgrades to the specified target version. */
22 this.data = upgrade_data_1.getVersionUpgradeData(this, 'methodCallChecks');
23 // Only enable the migration rule if there is upgrade data.
24 this.enabled = this.data.length !== 0;
25 }
26 visitNode(node) {
27 if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
28 this._checkPropertyAccessMethodCall(node);
29 }
30 }
31 _checkPropertyAccessMethodCall(node) {
32 const propertyAccess = node.expression;
33 if (!ts.isIdentifier(propertyAccess.name)) {
34 return;
35 }
36 const hostType = this.typeChecker.getTypeAtLocation(propertyAccess.expression);
37 const hostTypeName = hostType.symbol && hostType.symbol.name;
38 const methodName = propertyAccess.name.text;
39 if (!hostTypeName) {
40 return;
41 }
42 // TODO(devversion): Revisit the implementation of this upgrade rule. It seems difficult
43 // and ambiguous to maintain the data for this rule. e.g. consider a method which has the
44 // same amount of arguments but just had a type change. In that case we could still add
45 // new entries to the upgrade data that match the current argument length to just show
46 // a failure message, but adding that data becomes painful if the method has optional
47 // parameters and it would mean that the error message would always show up, even if the
48 // argument is in some cases still assignable to the new parameter type. We could re-use
49 // the logic we have in the constructor-signature checks to check for assignability and
50 // to make the upgrade data less verbose.
51 const failure = this.data.filter(data => data.method === methodName && data.className === hostTypeName)
52 .map(data => data.invalidArgCounts.find(f => f.count === node.arguments.length))[0];
53 if (!failure) {
54 return;
55 }
56 this.createFailureAtNode(node, `Found call to "${hostTypeName + '.' + methodName}" ` +
57 `with ${failure.count} arguments. Message: ${failure.message}`);
58 }
59}
60exports.MethodCallArgumentsMigration = MethodCallArgumentsMigration;
61//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0aG9kLWNhbGwtYXJndW1lbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL25nLXVwZGF0ZS9taWdyYXRpb25zL21ldGhvZC1jYWxsLWFyZ3VtZW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCxpQ0FBaUM7QUFDakMsMkRBQXNEO0FBR3RELGtEQUFtRTtBQUVuRTs7O0dBR0c7QUFDSCxNQUFhLDRCQUE2QixTQUFRLHFCQUFzQjtJQUF4RTs7UUFDRSxpRUFBaUU7UUFDakUsU0FBSSxHQUE0QixvQ0FBcUIsQ0FBQyxJQUFJLEVBQUUsa0JBQWtCLENBQUMsQ0FBQztRQUVoRiwyREFBMkQ7UUFDM0QsWUFBTyxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsTUFBTSxLQUFLLENBQUMsQ0FBQztJQTZDbkMsQ0FBQztJQTNDVSxTQUFTLENBQUMsSUFBYTtRQUM5QixJQUFJLEVBQUUsQ0FBQyxnQkFBZ0IsQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFFLENBQUMsMEJBQTBCLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxFQUFFO1lBQy9FLElBQUksQ0FBQyw4QkFBOEIsQ0FBQyxJQUFJLENBQUMsQ0FBQztTQUMzQ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IC8vIGFyZ3VtZW50IGlzIGluIHNvbWUgY2FzZXMgc3RpbGwgYXNzaWduYWJsZSB0byB0aGUgbmV3IHBhcmFtZXRlciB0eXBlLiBXZSBjb3VsZCByZS11c2VcbiAgICAvLyB0aGUgbG9naWMgd2UgaGF2ZSBpbiB0aGUgY29uc3RydWN0b3Itc2lnbmF0dXJlIGNoZWNrcyB0byBjaGVjayBmb3IgYXNzaWduYWJpbGl0eSBhbmRcbiAgICAvLyB0byBtYWtlIHRoZSB1cGdyYWRlIGRhdGEgbGVzcyB2ZXJib3NlLlxuICAgIGNvbnN0IGZhaWx1cmUgPVxuICAgICAgICB0aGlzLmRhdGEuZmlsdGVyKGRhdGEgPT4gZGF0YS5tZXRob2QgPT09IG1ldGhvZE5hbWUgJiYgZGF0YS5jbGFzc05hbWUgPT09IGhvc3RUeXBlTmFtZSlcbiAgICAgICAgICAgIC5tYXAoZGF0YSA9PiBkYXRhLmludmFsaWRBcmdDb3VudHMuZmluZChmID0+IGYuY291bnQgPT09IG5vZGUuYXJndW1lbnRzLmxlbmd0aCkpWzBdO1xuXG4gICAgaWYgKCFmYWlsdXJlKSB7XG4gICAgICByZXR1cm47XG4gICAgfVxuXG4gICAgdGhpcy5jcmVhdGVGYWlsdXJlQXROb2RlKFxuICAgICAgICBub2RlLFxuICAgICAgICBgRm91bmQgY2FsbCB0byBcIiR7aG9zdFR5cGVOYW1lICsgJy4nICsgbWV0aG9kTmFtZX1cIiBgICtcbiAgICAgICAgICAgIGB3aXRoICR7ZmFpbHVyZS5jb3VudH0gYXJndW1lbnRzLiBNZXNzYWdlOiAke2ZhaWx1cmUubWVzc2FnZX1gKTtcbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.