function addImportToGraph(importId, parentId, graph, visited) {
  const siblingsId = parentId + "_" + "siblings";
  const visitedId = parentId + "_" + importId;

  if (visited[visitedId] !== VISITED_MARKER) {
    if (!Array.isArray(visited[siblingsId])) {
      visited[siblingsId] = [];
    }

    const siblings = visited[siblingsId];

    if (Array.isArray(graph[importId])) {
      graph[importId] = graph[importId].concat(siblings);
    } else {
      graph[importId] = siblings.slice();
    }

    visited[visitedId] = VISITED_MARKER;

    siblings.push(importId);
  }
}
:import('G') {}

Rule
  composes: ... from 'A'
  composes: ... from 'B'
Rule
  composes: ... from 'A'
  composes: ... from 'A'
  composes: ... from 'C'

Results in:

graph: {
  G: [],
  A: [],
  B: ['A'],
  C: ['A'],
}