function getAllScopes(ast, scope, fullText) {
        var curScope = scope;
        var cnt = 0;
        var scopes = [];

        while (curScope) {
            curScope.id = cnt++;
            scopes.push(curScope);

            if (curScope.fnType) {
                // Check for class scopes surrounding the function
                if (curScope.fnType === "FunctionExpression") {
                    var methodDefinitionNode = findSurroundASTNode(ast, curScope.originNode, ["MethodDefinition"]);
                    // class scope found
                    if (methodDefinitionNode && isEqual(methodDefinitionNode.value, curScope.originNode)) {
                        // Change curScope name and originNode to that of methodDefinitionNode
                        curScope.name = methodDefinitionNode.key.name;
                        curScope.originNode = methodDefinitionNode;

                        var classNode = findSurroundASTNode(ast, methodDefinitionNode, ["ClassDeclaration", "ClassExpression"]);

                        if (classNode) {
                            // Class Declaration found add it to scopes
                            var temp = curScope.prev;
                            var newScope = {};
                            newScope.isClass = true;

                            // if the class is class expression, check if it has a name
                            if (classNode.type === "ClassExpression") {
                                var assignmentExpNode = findSurroundASTNode(ast, classNode, ["AssignmentExpression"]);
                                if (assignmentExpNode && assignmentExpNode.left && assignmentExpNode.left.name) {
                                    newScope.name = "class " + assignmentExpNode.left.name;
                                } else {
                                    var varDeclaratorNode = findSurroundASTNode(ast, classNode, ["VariableDeclarator"]);
                                    if (varDeclaratorNode && varDeclaratorNode.id && varDeclaratorNode.id.name) {
                                        newScope.name = "class " + varDeclaratorNode.id.name;
                                    } else {
                                        newScope.name = "class null";
                                    }
                                }
                            } else {
                                newScope.name = "class " + (classNode.id && classNode.id.name);
                            }
                            newScope.originNode = classNode;
                            curScope.prev = newScope;
                            newScope.prev = temp;
                        }
                    } else {
                        // For function expressions, assign name to prefix of the function body
                        curScope.name = "function starting with " +
                            fullText.substr(
                                curScope.originNode.body.start,
                                Math.min(
                                    FUNCTION_BODY_PREFIX_LENGTH,
                                    curScope.originNode.body.end - curScope.originNode.body.start
                                )
                            );
                    }
                } else {
                    // Acorn parse_dammit marks name with '✖' under erroneous declarations, check it
                    if (curScope.fnType === "✖") {
                        curScope.name = "function starting with " +
                            fullText.substr(
                                curScope.originNode.body.start,
                                Math.min(
                                    FUNCTION_BODY_PREFIX_LENGTH,
                                    curScope.originNode.body.end - curScope.originNode.body.start
                                )
                            );
                    } else {
                        curScope.name = curScope.fnType;
                    }
                }
            } else if (!curScope.originNode) {
                curScope.name = "global";
            }

            curScope = curScope.prev;
        }
        return scopes;
    }
function getAllScopes(ast, scope, fullText) {
        var curScope = scope;
        var cnt = 0;
        var scopes = [];

        while (curScope) {
            curScope.id = cnt++;
            scopes.push(curScope);

            if (curScope.fnType) {
                // Check for class scopes surrounding the function
                if (curScope.fnType === "FunctionExpression") {
                    var methodDefinitionNode = findSurroundASTNode(ast, curScope.originNode, ["MethodDefinition"]);
                    // class scope found
                    if (methodDefinitionNode && isEqual(methodDefinitionNode.value, curScope.originNode)) {
                        // Change curScope name and originNode to that of methodDefinitionNode
                        curScope.name = methodDefinitionNode.key.name;
                        curScope.originNode = methodDefinitionNode;

                        var classNode = findSurroundASTNode(ast, methodDefinitionNode, ["ClassDeclaration", "ClassExpression"]);

                        if (classNode) {
                            // Class Declaration found add it to scopes
                            var temp = curScope.prev;
                            var newScope = {};
                            newScope.isClass = true;

                            // if the class is class expression, check if it has a name
                            if (classNode.type === "ClassExpression") {
                                var assignmentExpNode = findSurroundASTNode(ast, classNode, ["AssignmentExpression"]);
                                if (assignmentExpNode && assignmentExpNode.left && assignmentExpNode.left.name) {
                                    newScope.name = "class " + assignmentExpNode.left.name;
                                } else {
                                    var varDeclaratorNode = findSurroundASTNode(ast, classNode, ["VariableDeclarator"]);
                                    if (varDeclaratorNode && varDeclaratorNode.id && varDeclaratorNode.id.name) {
                                        newScope.name = "class " + varDeclaratorNode.id.name;
                                    } else {
                                        newScope.name = "class null";
                                    }
                                }
                            } else {
                                newScope.name = "class " + (classNode.id && classNode.id.name);
                            }
                            newScope.originNode = classNode;
                            curScope.prev = newScope;
                            newScope.prev = temp;
                        }
                    } else {
                        // For function expressions, assign name to prefix of the function body
                        curScope.name = "function starting with " +
                            fullText.substr(
                                curScope.originNode.body.start,
                                Math.min(
                                    FUNCTION_BODY_PREFIX_LENGTH,
                                    curScope.originNode.body.end - curScope.originNode.body.start
                                )
                            );
                    }
                } else {
                    // Acorn parse_dammit marks name with '✖' under erroneous declarations, check it
                    if (curScope.fnType === "✖") {
                        curScope.name = "function starting with " +
                            fullText.substr(
                                curScope.originNode.body.start,
                                Math.min(
                                    FUNCTION_BODY_PREFIX_LENGTH,
                                    curScope.originNode.body.end - curScope.originNode.body.start
                                )
                            );
                    } else {
                        curScope.name = curScope.fnType;
                    }
                }
            } else if (!curScope.originNode) {
                curScope.name = "global";
            }

            curScope = curScope.prev;
        }
        return scopes;
    }
function getAllScopes ( ast , scope , fullText ) { var curScope = scope ; var cnt = 0 ; var scopes = [ ] ; while ( curScope ) { curScope . id = cnt ++ ; scopes . push ( curScope ) ; if ( curScope . fnType ) { // Check for class scopes surrounding the function if ( curScope . fnType === "FunctionExpression" ) { var methodDefinitionNode = findSurroundASTNode ( ast , curScope . originNode , [ "MethodDefinition" ] ) ; // class scope found if ( methodDefinitionNode && isEqual ( methodDefinitionNode . value , curScope . originNode ) ) { // Change curScope name and originNode to that of methodDefinitionNode curScope . name = methodDefinitionNode . key . name ; curScope . originNode = methodDefinitionNode ; var classNode = findSurroundASTNode ( ast , methodDefinitionNode , [ "ClassDeclaration" , "ClassExpression" ] ) ; if ( classNode ) { // Class Declaration found add it to scopes var temp = curScope . prev ; var newScope = { } ; newScope . isClass = true ; // if the class is class expression, check if it has a name if ( classNode . type === "ClassExpression" ) { var assignmentExpNode = findSurroundASTNode ( ast , classNode , [ "AssignmentExpression" ] ) ; if ( assignmentExpNode && assignmentExpNode . left && assignmentExpNode . left . name ) { newScope . name = "class " + assignmentExpNode . left . name ; } else { var varDeclaratorNode = findSurroundASTNode ( ast , classNode , [ "VariableDeclarator" ] ) ; if ( varDeclaratorNode && varDeclaratorNode . id && varDeclaratorNode . id . name ) { newScope . name = "class " + varDeclaratorNode . id . name ; } else { newScope . name = "class null" ; } } } else { newScope . name = "class " + ( classNode . id && classNode . id . name ) ; } newScope . originNode = classNode ; curScope . prev = newScope ; newScope . prev = temp ; } } else { // For function expressions, assign name to prefix of the function body curScope . name = "function starting with " + fullText . substr ( curScope . originNode . body . start , Math . min ( FUNCTION_BODY_PREFIX_LENGTH , curScope . originNode . body . end - curScope . originNode . body . start ) ) ; } } else { // Acorn parse_dammit marks name with '✖' under erroneous declarations, check it if ( curScope . fnType === "✖")  { curScope . name = "function starting with " + fullText . substr ( curScope . originNode . body . start , Math . min ( FUNCTION_BODY_PREFIX_LENGTH , curScope . originNode . body . end - curScope . originNode . body . start ) ) ; } else { curScope . name = curScope . fnType ; } } } else if ( ! curScope . originNode ) { curScope . name = "global" ; } curScope = curScope . prev ; } return scopes ; }
Converts the scopes returned from tern to an array of scopes and adds id and name to the scope
Also checks for class scopes
@param {!ASTNode} ast - ast of the complete file
@param {!Scope} scope - scope returned from tern
@param {!string} fullText - the complete text of a file
@return {!Array.<Scope>}
Converts the scopes returned from tern to an array of scopes and adds id and name to the scope Also checks for class scopes
Get all scopes of the given scope