Merge pull request #498 from quicktype/fix-duplicate-declarations

Fix duplicate declarations
This commit is contained in:
Mark Probst 2018-02-06 06:53:23 -08:00 коммит произвёл GitHub
Родитель 24dc4a630e 08e787fecf
Коммит f5feb9efff
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -101,10 +101,14 @@ export function declarationsForGraph(
const topDown = canBeForwardDeclared === undefined;
const declarations: Declaration[] = [];
let forwardedTypes: Set<Type> = Set();
let visitedComponents: Set<OrderedSet<Type>> = Set();
function processGraph(graph: Graph<Type>, _writeComponents: boolean): void {
const componentsGraph = graph.stronglyConnectedComponents();
function visitComponent(component: OrderedSet<Type>): void {
if (visitedComponents.has(component)) return;
visitedComponents = visitedComponents.add(component);
// console.log(`visiting component ${componentName(component)}`);
const declarationNeeded = component.filter(needsDeclaration);
@ -164,6 +168,19 @@ export function declarationsForGraph(
return;
}
/*
if (_writeComponents) {
componentsGraph.nodes.forEach(types => {
console.log(
`scc: ${types
.filter(t => t instanceof ClassType)
.map(t => t.getCombinedName())
.join(", ")}`
);
});
}
*/
const rootsUnordered = componentsGraph.findRoots();
const roots = rootsUnordered;
roots.forEach(component => {

Просмотреть файл

@ -1,6 +1,6 @@
"use strict";
import { Map, Set, OrderedSet } from "immutable";
import { Map, Set, OrderedSet, List } from "immutable";
import { defined, repeated, assert, repeatedCall } from "./Support";
function countComponentGraphNodes(components: number[][]): number {
@ -193,6 +193,10 @@ export class Graph<T> {
return this._nodes.length;
}
get nodes(): List<T> {
return List(this._nodes);
}
findRoots(): OrderedSet<T> {
const roots = findRoots(this._successors);
return OrderedSet(roots.map(n => this._nodes[n]));