blob: 9da1a1e73df572d82f4bd21707f6f10e3e53004f [file] [log] [blame]
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
/** Gets import information about the specified identifier by using the type checker. */
function getImportOfIdentifier(typeChecker, node) {
const symbol = typeChecker.getSymbolAtLocation(node);
if (!symbol || !symbol.declarations.length) {
return null;
}
const decl = symbol.declarations[0];
if (!ts.isImportSpecifier(decl)) {
return null;
}
// Since "decl" is an import specifier, we can walk up three times to get a reference
// to the import declaration node (NamedImports -> ImportClause -> ImportDeclaration).
const importDecl = decl.parent.parent.parent;
if (!ts.isStringLiteral(importDecl.moduleSpecifier)) {
return null;
}
return {
// Handles aliased imports: e.g. "import {Component as myComp} from ...";
name: decl.propertyName ? decl.propertyName.text : decl.name.text,
importModule: importDecl.moduleSpecifier.text,
node: importDecl
};
}
exports.getImportOfIdentifier = getImportOfIdentifier;
//# sourceMappingURL=imports.js.map