Merge pull request #498 from quicktype/fix-duplicate-declarations
Fix duplicate declarations
This commit is contained in:
Коммит
f5feb9efff
|
@ -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]));
|
||||
|
|
Загрузка…
Ссылка в новой задаче