misc-template-rule.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 target_version_1 = require("../../update-tool/target-version");
  11. const migration_rule_1 = require("../../update-tool/migration-rule");
  12. const literal_1 = require("../typescript/literal");
  13. /**
  14. * Rule that walks through every template and reports if there are
  15. * instances of outdated Angular CDK API that can't be migrated automatically.
  16. */
  17. class MiscTemplateRule extends migration_rule_1.MigrationRule {
  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.ruleEnabled = this.targetVersion === target_version_1.TargetVersion.V6;
  23. }
  24. visitTemplate(template) {
  25. // Migration for https://github.com/angular/components/pull/10325 (v6)
  26. literal_1.findAllSubstringIndices(template.content, 'cdk-focus-trap').forEach(offset => {
  27. this.failures.push({
  28. filePath: template.filePath,
  29. position: template.getCharacterAndLineOfPosition(template.start + offset),
  30. message: `Found deprecated element selector "cdk-focus-trap" which has been ` +
  31. `changed to an attribute selector "[cdkTrapFocus]".`
  32. });
  33. });
  34. }
  35. }
  36. exports.MiscTemplateRule = MiscTemplateRule;
  37. //# sourceMappingURL=misc-template-rule.js.map