type-inference.js
// Somewhat optimistically, we assume that the user wants to rename the both types of references.
Somewhat optimistically, we assume that the user wants to rename the both types of references.
Somewhat optimistically we assume that the user wants to rename the both types of references .
function computeGlobalVariableRenaming(ast, name) {
    var ids = [];
    var global = ast.global.rep();
    function visit(node, shadowed) {
        switch (node.type) {
            case 'Identifier':
            case 'Literal':
                var clazz = classifyId(node);
                if (clazz !== null && clazz.name === name) {
                    if (clazz.type === 'variable' && !shadowed) {
                        ids.push(node);
                    } else if (clazz.type === 'property' && clazz.base.$type_node.rep() === global) {
                        ids.push(node);
                    }
                }
                break;
            case 'FunctionDeclaration':
            case 'FunctionExpression':
            case 'ArrowFunctionExpression':
            case 'CatchClause':
                if (node.$env.has(name)) {
                    if (!shadowed && node.type === 'FunctionDeclaration' && node.id.name === name) {
                        ids.push(node.id); 
                    }
                    shadowed = true;
                }
                break;
        }
        var list = children(node);
        for (var i=0; i<list.length; i++) {
            visit(list[i], shadowed);
        }
    }
    visit(ast, false);
    return [ids];
}
function computeGlobalVariableRenaming ( ast , name ) { var ids = [ ] ; var global = ast . global . rep ( ) ; function visit ( node , shadowed ) { switch ( node . type ) { case 'Identifier' : case 'Literal' : var clazz = classifyId ( node ) ; if ( clazz !== null && clazz . name === name ) { if ( clazz . type === 'variable' && ! shadowed ) { ids . push ( node ) ; } else if ( clazz . type === 'property' && clazz . base . $type_node . rep ( ) === global ) { ids . push ( node ) ; } } break ; case 'FunctionDeclaration' : case 'FunctionExpression' : case 'ArrowFunctionExpression' : case 'CatchClause' : if ( node . $env . has ( name ) ) { if ( ! shadowed && node . type === 'FunctionDeclaration' && node . id . name === name ) { ids . push ( node . id ) ; } shadowed = true ; } break ; } var list = children ( node ) ; for ( var i = 0 ; i < list . length ; i ++ ) { visit ( list [ i ] , shadowed ) ; } } visit ( ast , false ) ; return [ ids ] ; }
Somewhat optimistically, we assume that the user wants to rename the both types of references.
Somewhat optimistically we assume that the user wants to rename the both types of references .
// name belongs to outer scope