Skip to content

Commit

Permalink
Re-enable duplicate name handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Feb 4, 2016
1 parent fda365b commit de5e2ff
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/schema/transform/Sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Transform} from './Transform';
export interface State {
pendingAnonTbl: { [typeId: string]: { type: Type, memberTypeList: Type[] } };
pendingAnonList: Type[];
typeListList: Type[][];
}

function capitalize(match: string, initial: string) {
Expand Down Expand Up @@ -44,13 +45,19 @@ export class Sanitize extends Transform<Sanitize, void, State> {
this.visitType(type);
}

this.state.typeListList.push(typeList);

return(true);
}

renameDuplicates(typeList: Type[]) {
// TODO: handle collisions between names of types and members of doc.

// Sort types by sanitized name and duplicates by original name
// (missing original names sorted after existing original names).

// TODO: merge types with identical contents.
/*

typeList = typeList.sort((a: Type, b: Type) =>
a.safeName.localeCompare(b.safeName) ||
+!!b.name - +!!a.name ||
Expand All @@ -62,16 +69,14 @@ export class Sanitize extends Transform<Sanitize, void, State> {
var name = '';
var suffix = 2;

for(type of typeList) {
for(var type of typeList) {
if(type.safeName == name) {
type.safeName += '_' + (suffix++);
} else {
name = type.safeName;
suffix = 2;
}
}
*/
return(true);
}

finish() {
Expand All @@ -88,6 +93,10 @@ export class Sanitize extends Transform<Sanitize, void, State> {
for(var type of this.state.pendingAnonList) {
if(!type.safeName) type.safeName = 'Type';
}

for(var typeList of this.state.typeListList) {
this.renameDuplicates(typeList);
}
}

visitType(type: Type) {
Expand Down Expand Up @@ -216,7 +225,11 @@ export class Sanitize extends Transform<Sanitize, void, State> {
}
}

protected state: State = { pendingAnonTbl: {}, pendingAnonList: [] };
protected state: State = {
pendingAnonTbl: {},
pendingAnonList: [],
typeListList: []
};

construct = Sanitize;
}

0 comments on commit de5e2ff

Please sign in to comment.