UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for static analysis and code manipulation.

64 lines (63 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var errors = require("../../../errors"); var common_1 = require("../common"); var utils_1 = require("../../../utils"); exports.ImportClauseBase = common_1.Node; var ImportClause = /** @class */ (function (_super) { tslib_1.__extends(ImportClause, _super); function ImportClause() { return _super !== null && _super.apply(this, arguments) || this; } /** * Gets the default import or throws if it doesn't exit. */ ImportClause.prototype.getDefaultImportOrThrow = function () { return errors.throwIfNullOrUndefined(this.getDefaultImport(), "Expected to find a default import."); }; /** * Gets the default import or returns undefined if it doesn't exist. */ ImportClause.prototype.getDefaultImport = function () { return this.getNodeProperty("name"); }; /** * Gets the named bindings of the import clause or throws if it doesn't exist. */ ImportClause.prototype.getNamedBindingsOrThrow = function () { return errors.throwIfNullOrUndefined(this.getNamedBindings(), "Expected to find an import declaration's named bindings."); }; /** * Gets the named bindings of the import clause or returns undefined if it doesn't exist. */ ImportClause.prototype.getNamedBindings = function () { return this.getNodeProperty("namedBindings"); }; /** * Gets the namespace import if it exists or throws. */ ImportClause.prototype.getNamespaceImportOrThrow = function () { return errors.throwIfNullOrUndefined(this.getNamespaceImport(), "Expected to find a namespace import."); }; /** * Gets the namespace import identifier, if it exists. */ ImportClause.prototype.getNamespaceImport = function () { var namedBindings = this.getNamedBindings(); if (namedBindings == null || !utils_1.TypeGuards.isNamespaceImport(namedBindings)) return undefined; return namedBindings.getNameNode(); }; /** * Gets the namespace import identifier, if it exists. */ ImportClause.prototype.getNamedImports = function () { var namedBindings = this.getNamedBindings(); if (namedBindings == null || !utils_1.TypeGuards.isNamedImports(namedBindings)) return []; return namedBindings.getElements(); }; return ImportClause; }(exports.ImportClauseBase)); exports.ImportClause = ImportClause;