Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isImportUsed(importSpecifier, sourceFile, checker) {
var importedSymbol = checker.getSymbolAtLocation(importSpecifier);
if (importedSymbol === undefined) {
return false;
}
var symbol = checker.getAliasedSymbol(importedSymbol);
if (!utils.isSymbolFlagSet(symbol, ts.SymbolFlags.Type)) {
return false;
}
return (ts.forEachChild(sourceFile, function cb(child) {
if (isImportLike(child)) {
return false;
}
var type = getImplicitType(child, checker);
// TODO: checker.typeEquals https://github.com/Microsoft/TypeScript/issues/13502
if (type !== undefined &&
checker.typeToString(type) === checker.symbolToString(symbol)) {
return true;
}
return ts.forEachChild(child, cb);
}) === true);
}
function getImplicitType(node, checker) {
function isNodeAny(node, checker) {
var symbol = checker.getSymbolAtLocation(node);
if (symbol !== undefined && tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)) {
symbol = checker.getAliasedSymbol(symbol);
}
if (symbol !== undefined) {
// NamespaceModule is a type-only namespace without runtime value, its type is 'any' when used as 'ns.Type' -> avoid error
if (tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.NamespaceModule)) {
return false;
}
if (tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Type)) {
return isAny(checker.getDeclaredTypeOfSymbol(symbol));
}
}
// Lowercase JSX elements are assumed to be allowed by design
if (isJsxNativeElement(node)) {
return false;
}
return isAny(checker.getTypeAtLocation(node));
}
var jsxElementTypes = new Set([
let symbol: ts.Symbol | undefined;
const parent = node.parent;
if (parent.kind === ts.SyntaxKind.BindingElement) {
symbol = tc.getTypeAtLocation(parent.parent).getProperty(node.text);
} else if (
(isPropertyAssignment(parent) && parent.name === node) ||
(isShorthandPropertyAssignment(parent) &&
parent.name === node &&
isReassignmentTarget(node))
) {
symbol = tc.getPropertySymbolOfDestructuringAssignment(node);
} else {
symbol = tc.getSymbolAtLocation(node);
}
if (symbol !== undefined && isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)) {
symbol = tc.getAliasedSymbol(symbol);
}
if (
symbol === undefined ||
// if this is a CallExpression and the declaration is a function or method,
// stop here to avoid collecting JsDoc of all overload signatures
(callExpression !== undefined && isFunctionOrMethod(symbol.declarations))
) {
return undefined;
}
return getSymbolDeprecation(symbol);
}
function isNodeAny(node, checker, orUnknown) {
if (orUnknown === void 0) { orUnknown = false; }
var symbol = checker.getSymbolAtLocation(node);
if (symbol !== undefined && tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)) {
symbol = checker.getAliasedSymbol(symbol);
}
if (symbol !== undefined) {
// NamespaceModule is a type-only namespace without runtime value, its type is 'any' when used as 'ns.Type' -> avoid error
if (tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.NamespaceModule)) {
return false;
}
if (tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Type)) {
return isAny(checker.getDeclaredTypeOfSymbol(symbol), orUnknown);
}
}
// Lowercase JSX elements are assumed to be allowed by design
if (isJsxNativeElement(node)) {
return false;
}
return isAny(checker.getTypeAtLocation(node), orUnknown);
function isImportUsed(importSpecifier, sourceFile, checker) {
var importedSymbol = checker.getSymbolAtLocation(importSpecifier);
if (importedSymbol === undefined) {
return false;
}
var symbol = checker.getAliasedSymbol(importedSymbol);
if (!utils.isSymbolFlagSet(symbol, ts.SymbolFlags.Type)) {
return false;
}
return (ts.forEachChild(sourceFile, function cb(child) {
if (isImportLike(child)) {
return false;
}
var type = getImplicitType(child, checker);
// TODO: checker.typeEquals https://github.com/Microsoft/TypeScript/issues/13502
if (type !== undefined &&
checker.typeToString(type) === checker.symbolToString(symbol)) {
return true;
}
return ts.forEachChild(child, cb);
}) === true);
}
function getImplicitType(node, checker) {
function tryGetAliasedSymbol(symbol: ts.Symbol, checker: ts.TypeChecker): ts.Symbol | undefined {
return utils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
? checker.getAliasedSymbol(symbol)
: undefined;
}
function tryGetAliasedSymbol(
symbol: ts.Symbol,
checker: ts.TypeChecker,
): ts.Symbol | null {
return tsutils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
? checker.getAliasedSymbol(symbol)
: null;
}