source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/migrations/constructor-signature.mjs

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

initial commit

  • Property mode set to 100644
File size: 20.2 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.ConstructorSignatureMigration = void 0;
11const ts = require("typescript");
12const migration_1 = require("../../update-tool/migration");
13const version_changes_1 = require("../../update-tool/version-changes");
14/**
15 * List of diagnostic codes that refer to pre-emit diagnostics which indicate invalid
16 * new expression or super call signatures. See the list of diagnostics here:
17 *
18 * https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
19 */
20const signatureErrorDiagnostics = [
21 // Type not assignable error diagnostic.
22 2345,
23 // Constructor argument length invalid diagnostics
24 2554,
25 2555,
26 2556,
27 2557,
28];
29/**
30 * Migration that visits every TypeScript new expression or super call and checks if
31 * the parameter type signature is invalid and needs to be updated manually.
32 */
33class ConstructorSignatureMigration extends migration_1.Migration {
34 constructor() {
35 super(...arguments);
36 // Note that the data for this rule is not distinguished based on the target version because
37 // we don't keep track of the new signature and don't want to update incrementally.
38 // See: https://github.com/angular/components/pull/12970#issuecomment-418337566
39 this.data = version_changes_1.getAllChanges(this.upgradeData.constructorChecks);
40 // Only enable the migration rule if there is upgrade data.
41 this.enabled = this.data.length !== 0;
42 }
43 visitNode(node) {
44 if (ts.isSourceFile(node)) {
45 this._visitSourceFile(node);
46 }
47 }
48 /**
49 * Method that will be called for each source file of the upgrade project. In order to
50 * properly determine invalid constructor signatures, we take advantage of the pre-emit
51 * diagnostics from TypeScript.
52 *
53 * By using the diagnostics, the migration can handle type assignability. Not using
54 * diagnostics would mean that we need to use simple type equality checking which is
55 * too strict. See related issue: https://github.com/Microsoft/TypeScript/issues/9879
56 */
57 _visitSourceFile(sourceFile) {
58 // List of classes of which the constructor signature has changed.
59 const diagnostics = ts.getPreEmitDiagnostics(this.program, sourceFile)
60 .filter(diagnostic => signatureErrorDiagnostics.includes(diagnostic.code))
61 .filter(diagnostic => diagnostic.start !== undefined);
62 for (const diagnostic of diagnostics) {
63 const node = findConstructorNode(diagnostic, sourceFile);
64 if (!node) {
65 continue;
66 }
67 const classType = this.typeChecker.getTypeAtLocation(node.expression);
68 const className = classType.symbol && classType.symbol.name;
69 const isNewExpression = ts.isNewExpression(node);
70 // Determine the class names of the actual construct signatures because we cannot assume that
71 // the diagnostic refers to a constructor of the actual expression. In case the constructor
72 // is inherited, we need to detect that the owner-class of the constructor is added to the
73 // constructor checks upgrade data. e.g. `class CustomCalendar extends MatCalendar {}`.
74 const signatureClassNames = classType.getConstructSignatures()
75 .map(signature => getClassDeclarationOfSignature(signature))
76 .map(declaration => declaration && declaration.name ? declaration.name.text : null)
77 .filter(Boolean);
78 // Besides checking the signature class names, we need to check the actual class name because
79 // there can be classes without an explicit constructor.
80 if (!this.data.includes(className) &&
81 !signatureClassNames.some(name => this.data.includes(name))) {
82 continue;
83 }
84 const classSignatures = classType.getConstructSignatures().map(signature => getParameterTypesFromSignature(signature, this.typeChecker));
85 const expressionName = isNewExpression ? `new ${className}` : 'super';
86 const signatures = classSignatures
87 .map(signature => signature.map(t => t === null ? 'any' : this.typeChecker.typeToString(t)))
88 .map(signature => `${expressionName}(${signature.join(', ')})`)
89 .join(' or ');
90 this.createFailureAtNode(node, `Found "${className}" constructed with ` +
91 `an invalid signature. Please manually update the ${expressionName} expression to ` +
92 `match the new signature${classSignatures.length > 1 ? 's' : ''}: ${signatures}`);
93 }
94 }
95}
96exports.ConstructorSignatureMigration = ConstructorSignatureMigration;
97/** Resolves the type for each parameter in the specified signature. */
98function getParameterTypesFromSignature(signature, typeChecker) {
99 return signature.getParameters().map(param => param.declarations ? typeChecker.getTypeAtLocation(param.declarations[0]) : null);
100}
101/**
102 * Walks through each node of a source file in order to find a new-expression node or super-call
103 * expression node that is captured by the specified diagnostic.
104 */
105function findConstructorNode(diagnostic, sourceFile) {
106 let resolvedNode = null;
107 const _visitNode = (node) => {
108 // Check whether the current node contains the diagnostic. If the node contains the diagnostic,
109 // walk deeper in order to find all constructor expression nodes.
110 if (node.getStart() <= diagnostic.start && node.getEnd() >= diagnostic.start) {
111 if (ts.isNewExpression(node) ||
112 (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.SuperKeyword)) {
113 resolvedNode = node;
114 }
115 ts.forEachChild(node, _visitNode);
116 }
117 };
118 ts.forEachChild(sourceFile, _visitNode);
119 return resolvedNode;
120}
121/** Determines the class declaration of the specified construct signature. */
122function getClassDeclarationOfSignature(signature) {
123 let node = signature.getDeclaration();
124 // Handle signatures which don't have an actual declaration. This happens if a class
125 // does not have an explicitly written constructor.
126 if (!node) {
127 return null;
128 }
129 while (!ts.isSourceFile(node = node.parent)) {
130 if (ts.isClassDeclaration(node)) {
131 return node;
132 }
133 }
134 return null;
135}
136//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RydWN0b3Itc2lnbmF0dXJlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL25nLXVwZGF0ZS9taWdyYXRpb25zL2NvbnN0cnVjdG9yLXNpZ25hdHVyZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCxpQ0FBaUM7QUFDakMsMkRBQXNEO0FBQ3RELHVFQUFnRTtBQUdoRTs7Ozs7R0FLRztBQUNILE1BQU0seUJBQXlCLEdBQUc7SUFDaEMsd0NBQXdDO0lBQ3hDLElBQUk7SUFDSixrREFBa0Q7SUFDbEQsSUFBSTtJQUNKLElBQUk7SUFDSixJQUFJO0lBQ0osSUFBSTtDQUNMLENBQUM7QUFFRjs7O0dB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