type-inference.js
// the choice of renaming groups.
the choice of renaming groups.
the choice of renaming groups .
function computePropertyRenaming(ast, name) {
    var group2members = {};
    var global = ast.global.rep().id;
    function add(base, id) {
        var key = base.$type_node.rep().id;
        if (key === global)
            return; 
        if (!group2members[key]) {
            group2members[key] = [];
        }
        group2members[key].push(id);
    }
    function visit(node) {
        var clazz = classifyId(node);
        if (clazz !== null && clazz.type === 'property' && clazz.name === name) {
            add(clazz.base, node);
        }
        children(node).forEach(visit);
    }
    visit(ast);
    var groups = [];
    for (var k in group2members) {
        if (!group2members.hasOwnProperty(k))
            continue;
        groups.push(group2members[k]);
    }
    return groups;
}
function computePropertyRenaming ( ast , name ) { var group2members = { } ; var global = ast . global . rep ( ) . id ; function add ( base , id ) { var key = base . $type_node . rep ( ) . id ; if ( key === global ) return ; if ( ! group2members [ key ] ) { group2members [ key ] = [ ] ; } group2members [ key ] . push ( id ) ; } function visit ( node ) { var clazz = classifyId ( node ) ; if ( clazz !== null && clazz . type === 'property' && clazz . name === name ) { add ( clazz . base , node ) ; } children ( node ) . forEach ( visit ) ; } visit ( ast ) ; var groups = [ ] ; for ( var k in group2members ) { if ( ! group2members . hasOwnProperty ( k ) ) continue ; groups . push ( group2members [ k ] ) ; } return groups ; }
the choice of renaming groups.
the choice of renaming groups .
// global variables are kept separate