injection-token-rule.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. /**
  3. * Use of this source code is governed by an MIT-style license that can be
  4. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.InjectionTokenRule = void 0;
  8. const schematics_1 = require("@angular/cdk/schematics");
  9. const ts = require("typescript");
  10. const module_specifiers_1 = require("../../../utils/ng-update/module-specifiers");
  11. class InjectionTokenRule extends schematics_1.Migration {
  12. visitNode(node) {
  13. if (ts.isImportDeclaration(node)) {
  14. this._visitImportDeclaration(node);
  15. }
  16. }
  17. _visitImportDeclaration(node) {
  18. if (!(0, module_specifiers_1.isNgZorroImportDeclaration)(node) || !node.importClause ||
  19. !node.importClause.namedBindings) {
  20. return;
  21. }
  22. const namedBindings = node.importClause.namedBindings;
  23. if (ts.isNamedImports(namedBindings)) {
  24. this._checkInjectionToken(namedBindings);
  25. }
  26. }
  27. _checkInjectionToken(namedImports) {
  28. namedImports.elements.filter(element => ts.isIdentifier(element.name)).forEach(element => {
  29. const importName = element.name.text;
  30. if (this.tokens.indexOf(importName) !== -1) {
  31. this.createFailureAtNode(element, this.getFailure(importName));
  32. }
  33. });
  34. }
  35. }
  36. exports.InjectionTokenRule = InjectionTokenRule;
  37. //# sourceMappingURL=injection-token-rule.js.map