text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var tslib_1 = require("tslib");
  var manipulation_1 = require("../../manipulation");
  var typescript_1 = require("../../typescript");
  var common_1 = require("../common");
  var ImportSpecifier = /** @class */ (function (_super) {
      tslib_1.__extends(ImportSpecifier, _super);
      function ImportSpecifier() {
          return _super !== null && _super.apply(this, arguments) || this;
      }
      /**
       * Sets the identifier being imported.
       * @param name - Name being imported.
       */
      ImportSpecifier.prototype.setName = function (name) {
          var nameNode = this.getNameNode();
          if (nameNode.getText() === name)
              return this;
          var start = nameNode.getStart();
          manipulation_1.replaceNodeText({
              sourceFile: this.sourceFile,
              start: start,
              replacingLength: nameNode.getWidth(),
              newText: name
          });
          return this;
      };
      /**
       * Gets the name of the import specifier.
       */
      ImportSpecifier.prototype.getName = function () {
          return this.getNameNode().getText();
      };
      /**
       * Gets the name node of what's being imported.
       */
      ImportSpecifier.prototype.getNameNode = function () {
          return this.getNodeFromCompilerNode(this.compilerNode.propertyName || this.compilerNode.name);
      };
      /**
       * Sets the alias for the name being imported.
       * @param alias - Alias to set.
       */
      ImportSpecifier.prototype.setAlias = function (alias) {
          var aliasIdentifier = this.getAliasNode();
          if (aliasIdentifier == null) {
              // trick is to insert an alias with the same name, then rename the alias. TS compiler will take care of the rest.
              var nameNode = this.getNameNode();
              manipulation_1.insertIntoParentTextRange({
                  insertPos: nameNode.getEnd(),
                  parent: this,
                  newText: " as " + nameNode.getText()
              });
              aliasIdentifier = this.getAliasNode();
          }
          aliasIdentifier.rename(alias);
          return this;
      };
      /**
       * Gets the alias identifier, if it exists.
       */
      ImportSpecifier.prototype.getAliasNode = function () {
          if (this.compilerNode.propertyName == null)
              return undefined;
          return this.getNodeFromCompilerNode(this.compilerNode.name);
      };
      /**
       * Gets the import declaration associated with this import specifier.
       */
      ImportSpecifier.prototype.getImportDeclaration = function () {
          return this.getFirstAncestorByKindOrThrow(typescript_1.SyntaxKind.ImportDeclaration);
      };
      /**
       * Remove the import specifier.
       */
      ImportSpecifier.prototype.remove = function () {
          var importDeclaration = this.getImportDeclaration();
          var namedImports = importDeclaration.getNamedImports();
          if (namedImports.length > 1)
              manipulation_1.removeCommaSeparatedChild(this);
          else
              importDeclaration.removeNamedImports();
      };
      return ImportSpecifier;
  }(common_1.Node));
  exports.ImportSpecifier = ImportSpecifier;
  