type-inference.js
// which the property is accessed. Variables may be global or local.
which the property is accessed. Variables may be global or local.
which the property is accessed . Variables may be global or local .
function classifyId(node) {
    if (node.type != 'Identifier' && (node.type !== 'Literal' || typeof node.value !== 'string'))
        return null; 
    var parent = node.$parent;
    switch (parent.type) {
        case 'MemberExpression':
            if (!parent.computed && parent.property === node && node.type === 'Identifier') {
                return {type:"property", base:parent.object, name:node.name};
            } else if (parent.computed && parent.property === node && node.type === 'Literal') {
                return {type:"property", base:parent.object, name:node.value};
            }
            break;
        case 'Property':
            if (parent.key === node) {
                if (node.type === 'Identifier') {
                    return {type:"property", base:parent.$parent, name:node.name};
                } else if (node.type === 'Literal') {
                    return {type:"property", base:parent.$parent, name:node.value};
                }
            }
            break;
        case 'BreakStatement':
        case 'ContinueStatement':
            if (parent.label === node) {
                return {type:"label", name:node.name};
            }
            break;
        case 'LabeledStatement':
            if (parent.label === node) {
                return {type:"label", name:node.name};
            }
            break;
        case 'ImportSpecifier':
        case 'ImportDefaultSpecifier':
        case 'ImportNamespaceSpecifier':
        case 'ExportSpecifier':
            if (parent.local === node) {
                return {type:"variable", name:node.name};
            } else {
                return null; 
            }
            break;
    }
    if (node.type === 'Identifier')
        return {type:"variable", name:node.name};
    else
        return null;
}
function classifyId ( node ) { if ( node . type != 'Identifier' && ( node . type !== 'Literal' || typeof node . value !== 'string' ) ) return null ; var parent = node . $parent ; switch ( parent . type ) { case 'MemberExpression' : if ( ! parent . computed && parent . property === node && node . type === 'Identifier' ) { return { type : "property" , base : parent . object , name : node . name } ; } else if ( parent . computed && parent . property === node && node . type === 'Literal' ) { return { type : "property" , base : parent . object , name : node . value } ; } break ; case 'Property' : if ( parent . key === node ) { if ( node . type === 'Identifier' ) { return { type : "property" , base : parent . $parent , name : node . name } ; } else if ( node . type === 'Literal' ) { return { type : "property" , base : parent . $parent , name : node . value } ; } } break ; case 'BreakStatement' : case 'ContinueStatement' : if ( parent . label === node ) { return { type : "label" , name : node . name } ; } break ; case 'LabeledStatement' : if ( parent . label === node ) { return { type : "label" , name : node . name } ; } break ; case 'ImportSpecifier' : case 'ImportDefaultSpecifier' : case 'ImportNamespaceSpecifier' : case 'ExportSpecifier' : if ( parent . local === node ) { return { type : "variable" , name : node . name } ; } else { return null ; } break ; } if ( node . type === 'Identifier' ) return { type : "variable" , name : node . name } ; else return null ; }
which the property is accessed.
which the property is accessed .
// only identifiers and string literals can be IDs // Module member renaming not supported.