function importedSymbolsFrom()

in src/submodule-reference.ts [93:136]


function importedSymbolsFrom(
  decl: ts.ImportDeclaration,
  sourceFile: ts.SourceFile,
  typeChecker: ts.TypeChecker,
): ts.Symbol[] {
  const { importClause } = decl;

  if (importClause == null) {
    // This is a "for side effects" import, which isn't relevant for our business here...
    return [];
  }

  const { name, namedBindings } = importClause;
  const imports = new Array<ts.Symbol>();

  if (name != null) {
    const symbol = typeChecker.getSymbolAtLocation(name);
    if (symbol == null) {
      throw new Error(`No symbol was defined for node ${name.getText(sourceFile)}`);
    }
    imports.push(symbol);
  }
  if (namedBindings != null) {
    if (ts.isNamespaceImport(namedBindings)) {
      const { name: bindingName } = namedBindings;
      const symbol = typeChecker.getSymbolAtLocation(bindingName);
      if (symbol == null) {
        throw new Error(`No symbol was defined for node ${bindingName.getText(sourceFile)}`);
      }
      imports.push(symbol);
    } else {
      for (const specifier of namedBindings.elements) {
        const { name: specifierName } = specifier;
        const symbol = typeChecker.getSymbolAtLocation(specifierName);
        if (symbol == null) {
          throw new Error(`No symbol was defined for node ${specifierName.getText(sourceFile)}`);
        }
        imports.push(symbol);
      }
    }
  }

  return imports;
}