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 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.MiscClassInheritanceMigration = void 0;
|
---|
11 | const schematics_1 = require("@angular/cdk/schematics");
|
---|
12 | const ts = require("typescript");
|
---|
13 | /**
|
---|
14 | * Migration that checks for classes that extend Angular Material classes which
|
---|
15 | * have changed their API.
|
---|
16 | */
|
---|
17 | class MiscClassInheritanceMigration extends schematics_1.Migration {
|
---|
18 | constructor() {
|
---|
19 | super(...arguments);
|
---|
20 | // Only enable this rule if the migration targets version 6. The rule
|
---|
21 | // currently only includes migrations for V6 deprecations.
|
---|
22 | this.enabled = this.targetVersion === schematics_1.TargetVersion.V6;
|
---|
23 | }
|
---|
24 | visitNode(node) {
|
---|
25 | if (ts.isClassDeclaration(node)) {
|
---|
26 | this._visitClassDeclaration(node);
|
---|
27 | }
|
---|
28 | }
|
---|
29 | _visitClassDeclaration(node) {
|
---|
30 | const baseTypes = schematics_1.determineBaseTypes(node);
|
---|
31 | const className = node.name ? node.name.text : '{unknown-name}';
|
---|
32 | if (!baseTypes) {
|
---|
33 | return;
|
---|
34 | }
|
---|
35 | // Migration for: https://github.com/angular/components/pull/10293 (v6)
|
---|
36 | if (baseTypes.includes('MatFormFieldControl')) {
|
---|
37 | const hasFloatLabelMember = node.members.filter(member => member.name)
|
---|
38 | .find(member => member.name.getText() === 'shouldLabelFloat');
|
---|
39 | if (!hasFloatLabelMember) {
|
---|
40 | this.createFailureAtNode(node, `Found class "${className}" which extends ` +
|
---|
41 | `"${'MatFormFieldControl'}". This class must define ` +
|
---|
42 | `"${'shouldLabelFloat'}" which is now a required property.`);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 | exports.MiscClassInhe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