misc-class-inheritance-rule.js 1.9 KB

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