Given a node tree, finds all the VAR declarations in that tree that are
not in an inner scope. Then adds a new VAR node at the top of the current
scope that redeclares them, if necessary.
334121
static void redeclareVarsInsideBranch(Node branch) {
    Collection<Node> vars = getVarsDeclaredInBranch(branch);
    if (vars.isEmpty()) {
      return;
    }

    Node parent = getAddingRoot(branch);
    for (Node nameNode : vars) {
      Node var = IR.var(
          IR.name(nameNode.getString())
              .srcref(nameNode))
          .srcref(nameNode);
      copyNameAnnotations(nameNode, var.getFirstChild());
      parent.addChildToFront(var);
    }
  }
91859
function (node) {
            if (node.type !== "VariableDeclaration") {
                return false;
            }
            // 
            var firstDeclaration = node.declarations[0];
            if(firstDeclaration.init == null) {
                return false;
            }
            if (firstDeclaration.init.type === "CallExpression" &&
                firstDeclaration.init.callee.name === "require") {
                return true;
            }
            // .add
            if (firstDeclaration.init.type === "MemberExpression" &&
                firstDeclaration.init.object.type === "CallExpression" &&
                firstDeclaration.init.object.callee.name === "require") {
                return true;
            }
        }
601505
function(name, nodes) {
          return (name === 'declaration' && nodes.content[0].content[0].type === 'variable') || (name === 'variable' && nodes.content[0].type === 'ident');
        }
1324458
static void markNewScopesChanged(Node node, AbstractCompiler compiler) {
    if (node.isFunction()) {
      compiler.reportChangeToChangeScope(node);
    }
    for (Node child = node.getFirstChild(); child != null; child = child.getNext()) {
      markNewScopesChanged(child, compiler);
    }
  }
1223607
private void lookForVariableAccess(OptFunctionNode fn, Node n)
    {
        switch (n.getType()) {
            case Token.TYPEOFNAME:
            {
                // TYPEOFNAME may be used with undefined names, which is why
                // this is handled separately from GETVAR above.
                int varIndex = fn.fnode.getIndexForNameNode(n);
                if (varIndex > -1 && !itsNotDefSet.get(varIndex))
                    itsUseBeforeDefSet.set(varIndex);
            }
            break;
            case Token.DEC :
            case Token.INC :
            {
                Node child = n.getFirstChild();
                if (child.getType() == Token.GETVAR) {
                    int varIndex = fn.getVarIndex(child);
                    if (!itsNotDefSet.get(varIndex))
                        itsUseBeforeDefSet.set(varIndex);
                    itsNotDefSet.set(varIndex);
                } else {
                    lookForVariableAccess(fn, child);
                }
            }
            break;
            case Token.SETVAR :
            case Token.SETCONSTVAR :
            {
                Node lhs = n.getFirstChild();
                Node rhs = lhs.getNext();
                lookForVariableAccess(fn, rhs);
                itsNotDefSet.set(fn.getVarIndex(n));
            }
            break;
            case Token.GETVAR :
            {
                int varIndex = fn.getVarIndex(n);
                if (!itsNotDefSet.get(varIndex))
                    itsUseBeforeDefSet.set(varIndex);
            }
            break;
            default :
                Node child = n.getFirstChild();
                while (child != null) {
                    lookForVariableAccess(fn, child);
                    child = child.getNext();
                }
                break;
        }
    }
483942
static boolean isBlockScopedDeclaration(Node n) {
    if (n.isName()) {
      switch (n.getParent().getToken()) {
        case LET:
        case CONST:
        case CATCH:
          return true;
        case CLASS:
          return n.getParent().getFirstChild() == n;
        case FUNCTION:
          return isBlockScopedFunctionDeclaration(n.getParent());
        default:
          break;
      }
    }
    return false;
  }
670651
Map<String, DefineInfo> collectDefines(Node externs, Node root) {
    GlobalNamespace namespace = null;
    if (namespaceSupplier != null) {
      namespace = namespaceSupplier.get();
    }
    if (namespace == null) {
      namespace = new GlobalNamespace(compiler, externs, root);
    }

    // namespace =
    //     namespaceSupplier != nul
    //         ? namespaceSupplier.get()
    //         : new GlobalNamespace(compiler, externs, root);

    // Find all the global names with a @define annotation
    List<Name> listOfDefines = new ArrayList<>();
    for (Name name : namespace.getNameIndex().values()) {
      Ref decl = name.getDeclaration();
      if (name.getJSDocInfo() != null && name.getJSDocInfo().isDefine()) {
        // Process defines should not depend on check types being enabled,
        // so we look for the JSDoc instead of the inferred type.
        if (isValidDefineType(name.getJSDocInfo().getType())) {
          listOfDefines.add(name);
        } else {
          JSError error = JSError.make(decl.getNode(), INVALID_DEFINE_TYPE_ERROR);
          compiler.report(error);
        }
      } else {
        for (Ref ref : name.getRefs()) {
          if (ref == decl) {
            // Declarations were handled above.
            continue;
          }

          Node n = ref.getNode();
          Node parent = ref.getNode().getParent();
          JSDocInfo info = n.getJSDocInfo();
          if (info == null && parent.isVar() && parent.hasOneChild()) {
            info = parent.getJSDocInfo();
          }

          if (info != null && info.isDefine()) {
            listOfDefines.add(name);
            break;
          }
        }
      }
    }

    CollectDefines pass = new CollectDefines(namespace, listOfDefines);
    NodeTraversal.traverseRoots(compiler, pass, externs, root);
    return pass.allDefines;
  }
860791
function(path) {
            const { node } = path;

            if (node.declarations.length < 2) {
              return;
            }

            const inits = [];
            const empty = [];
            for (const decl of node.declarations) {
              if (!decl.init) {
                empty.push(decl);
              } else {
                inits.push(decl);
              }
            }

            // This is based on exprimintation but there is a significant
            // imrpovement when we place empty vars at the top in smaller
            // files. Whereas it hurts in larger files.
            if (this.fitsInSlidingWindow) {
              node.declarations = empty.concat(inits);
            } else {
              node.declarations = inits.concat(empty);
            }
          }
1175144
def addBinding(self, node, value):
        
        # assert value.source in (node, node.parent):
        for scope in self.scopeStack[::-1]:
            if value.name in scope:
                break
        existing = scope.get(value.name)

        if (existing and not isinstance(existing, Builtin) and
                not self.differentForks(node, existing.source)):

            parent_stmt = self.getParent(value.source)
            if isinstance(existing, Importation) and isinstance(parent_stmt, FOR_TYPES):
                self.report(messages.ImportShadowedByLoopVar,
                            node, value.name, existing.source)

            elif scope is self.scope:
                if (isinstance(parent_stmt, ast.comprehension) and
                        not isinstance(self.getParent(existing.source),
                                       (FOR_TYPES, ast.comprehension))):
                    self.report(messages.RedefinedInListComp,
                                node, value.name, existing.source)
                elif not existing.used and value.redefines(existing):
                    if value.name != '_' or isinstance(existing, Importation):
                        if not is_typing_overload(existing, self.scopeStack):
                            self.report(messages.RedefinedWhileUnused,
                                        node, value.name, existing.source)

            elif isinstance(existing, Importation) and value.redefines(existing):
                existing.redefined.append(node)

        if value.name in self.scope:
            # then assume the rebound name is used as a global or within a loop
            value.used = self.scope[value.name].used

        self.scope[value.name] = value
1295950
def FOR(self, node):
        """"""
        vars = []

        def collectLoopVars(n):
            if isinstance(n, ast.Name):
                vars.append(n.id)
            elif isinstance(n, ast.expr_context):
                return
            else:
                for c in ast.iter_child_nodes(n):
                    collectLoopVars(c)

        collectLoopVars(node.target)
        for varn in vars:
            if (isinstance(self.scope.get(varn), Importation)
                    # unused ones will get an unused import warning
                    and self.scope[varn].used):
                self.report(messages.ImportShadowedByLoopVar,
                            node, varn, self.scope[varn].source)

        self.handle_children(node)
1312836
Var declare(String name, Node nameNode, CompilerInput input) {
    checkArgument(!name.isEmpty());
    // Make sure that it's declared only once
    checkState(getOwnSlot(name) == null);
    Var var = new Var(name, nameNode, this, getVarCount(), input);
    declareInternal(name, var);
    return var;
  }
7911
def check_declared(self, node):
        """"""

        for ident in node.undeclared_identifiers():
            if ident != 'context' and\
                    ident not in self.declared.union(self.locally_declared):
                self.undeclared.add(ident)
        for ident in node.declared_identifiers():
            self.locally_declared.add(ident)
296594
function collectUnusedVariables(scope, unusedVars) {
	            var variables = scope.variables;
	            var childScopes = scope.childScopes;
	            var i, l;
	            if (scope.type !== "TDZ" && (scope.type !== "global" || config.vars === "all")) {
	                for (i = 0, l = variables.length; i < l; ++i) {
	                    var variable = variables[i];
	
	                    // skip a variable of class itself name in the class scope
	                    if (scope.type === "class" && scope.block.id === variable.identifiers[0]) {
	                        continue;
	                    }
	
	                    // skip function expression names and variables marked with markVariableAsUsed()
	                    if (scope.functionExpressionScope || variable.eslintUsed) {
	                        continue;
	                    }
	
	                    // skip implicit "arguments" variable
	                    if (scope.type === "function" && variable.name === "arguments" && variable.identifiers.length === 0) {
	                        continue;
	                    }
	
	                    // explicit global variables don't have definitions.
	                    var def = variable.defs[0];
	
	                    if (def) {
	                        var type = def.type;
	                        // skip catch variables
	                        if (type === "CatchClause") {
	                            if (config.caughtErrors === "none") {
	                                continue;
	                            }
	
	                            // skip ignored parameters
	                            if (config.caughtErrorsIgnorePattern && config.caughtErrorsIgnorePattern.test(def.name.name)) {
	                                continue;
	                            }
	                        }
	                        if (type === "Parameter") {
	                            // skip any setter argument
	                            if (def.node.parent.type === "Property" && def.node.parent.kind === "set") {
	                                continue;
	                            }
	
	                            // if "args" option is "none", skip any parameter
	                            if (config.args === "none") {
	                                continue;
	                            }
	
	                            // skip ignored parameters
	                            if (config.argsIgnorePattern && config.argsIgnorePattern.test(def.name.name)) {
	                                continue;
	                            }
	
	                            // if "args" option is "after-used", skip all but the last parameter
	                            if (config.args === "after-used" && def.index < def.node.params.length - 1) {
	                                continue;
	                            }
	                        } else {
	                            // skip ignored variables
	                            if (config.varsIgnorePattern && config.varsIgnorePattern.test(def.name.name)) {
	                                continue;
	                            }
	                        }
	                        if (def.node.type === 'VariableDeclarator') {
				        		// Variables can be marked as 'exported' in a comment if they are used as global variables
								var comments = def.parent.leadingComments;
								var report = true;
								if (Array.isArray(comments)) {
									for (var k = 0, len = comments.length; k < len; k++) {
										if (comments[k].type === "Block" && comments[k].value.toLowerCase().indexOf('exported') >= 0){ //$NON-NLS-1$
											report = false;
											break;
										}
									}
								}
								if (!report) {
									continue;
								}
							}
	                    }
	                    if (!isUsedVariable(variable) && !isExported(variable)) {
	                    	if(def) {
	                    		type = def.type;
	                    		variable.data = {
		                    		0: variable.identifiers[0].name,
		                    		nls: 'no-unused-vars-unused',
		                    		pid: 'no-unused-vars-unused'
		                    	};
		                    	if(type === "Parameter") {
		                    		continue;
		                    	}
		                    	if(type === "ImportBinding") {
		                    		variable.data.pid = 'no-unused-vars-import';
		                    	} else if(def.node.type === "FunctionDeclaration") {
		                    		var tern = context.getTern();
		                    		var refQuery = {
		                    			end: def.node.id.start
		                    		};
		                    		var filename = tern.file.name;
		                    		var refs = tern.findRefs(refQuery, tern.file);
		                    		var result = [];
		                    		if (refs && Array.isArray(refs.refs)) {
		                    			// filtering the refs from the current file - remove the one that matches the current node
		                    			refs.refs.forEach(function(match) {
		                    				if (match.file !== filename) {
		                    					// any match in a different file is a good match
		                    					result.push(match);
		                    				}
		                    			});
		                    		}
		                    		if (result.length > 0) {
		                    			continue;
		                    		}
		                    		variable.data.pid = variable.data.nls = 'no-unused-vars-unused-funcdecl';
		                    	} else if(typeof variable.isread === "boolean" && !variable.isread) {
		                    		variable.data.pid = variable.data.nls = 'no-unused-vars-unread';
		                    	}
	                    	}
	                        unusedVars.push(variable);
	                    }
	                }
	            }
	            for (i = 0, l = childScopes.length; i < l; ++i) {
	                collectUnusedVariables(childScopes[i], unusedVars);
	            }
	            return unusedVars;
	        }
800006
function VariableDeclaration(node, parent, scope, file) {
    if (!isLet(node, parent)) return;

    if (isLetInitable(node) && file.transformers["es6.spec.blockScoping"].canTransform()) {
      var nodes = [node];

      for (var i = 0; i < node.declarations.length; i++) {
        var decl = node.declarations[i];
        if (decl.init) {
          var assign = t.assignmentExpression("=", decl.id, decl.init);
          assign._ignoreBlockScopingTDZ = true;
          nodes.push(t.expressionStatement(assign));
        }
        decl.init = file.addHelper("temporal-undefined");
      }

      node._blockHoist = 2;

      return nodes;
    }
  }
1308750
function isVar(node, parent) {
  return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
}
497229
function checkVariableDeclaration(node) {
            const parent = node.parent;
            const type = node.kind;

            if (!options[type]) {
                return;
            }

            const declarations = node.declarations;
            const declarationCounts = countDeclarations(declarations);
            const mixedRequires = declarations.some(isRequire) && !declarations.every(isRequire);

            if (options[type].initialized === MODE_ALWAYS) {
                if (options.separateRequires && mixedRequires) {
                    context.report({
                        node,
                        message: "Split requires to be separated into a single block."
                    });
                }
            }

            // consecutive
            const nodeIndex = (parent.body && parent.body.length > 0 && parent.body.indexOf(node)) || 0;

            if (nodeIndex > 0) {
                const previousNode = parent.body[nodeIndex - 1];
                const isPreviousNodeDeclaration = previousNode.type === "VariableDeclaration";
                const declarationsWithPrevious = declarations.concat(previousNode.declarations || []);

                if (
                    isPreviousNodeDeclaration &&
                    previousNode.kind === type &&
                    !(declarationsWithPrevious.some(isRequire) && !declarationsWithPrevious.every(isRequire))
                ) {
                    const previousDeclCounts = countDeclarations(previousNode.declarations);

                    if (options[type].initialized === MODE_CONSECUTIVE && options[type].uninitialized === MODE_CONSECUTIVE) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    } else if (options[type].initialized === MODE_CONSECUTIVE && declarationCounts.initialized > 0 && previousDeclCounts.initialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with initialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    } else if (options[type].uninitialized === MODE_CONSECUTIVE &&
                            declarationCounts.uninitialized > 0 &&
                            previousDeclCounts.uninitialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with uninitialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                }
            }

            // always
            if (!hasOnlyOneStatement(type, declarations)) {
                if (options[type].initialized === MODE_ALWAYS && options[type].uninitialized === MODE_ALWAYS) {
                    context.report({
                        node,
                        message: "Combine this with the previous '{{type}}' statement.",
                        data: {
                            type
                        },
                        fix: joinDeclarations(declarations)
                    });
                } else {
                    if (options[type].initialized === MODE_ALWAYS && declarationCounts.initialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with initialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                    if (options[type].uninitialized === MODE_ALWAYS && declarationCounts.uninitialized > 0) {
                        if (node.parent.left === node && (node.parent.type === "ForInStatement" || node.parent.type === "ForOfStatement")) {
                            return;
                        }
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with uninitialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                }
            }

            // never
            if (parent.type !== "ForStatement" || parent.init !== node) {
                const totalDeclarations = declarationCounts.uninitialized + declarationCounts.initialized;

                if (totalDeclarations > 1) {
                    if (options[type].initialized === MODE_NEVER && options[type].uninitialized === MODE_NEVER) {

                        // both initialized and uninitialized
                        context.report({
                            node,
                            message: "Split '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    } else if (options[type].initialized === MODE_NEVER && declarationCounts.initialized > 0) {

                        // initialized
                        context.report({
                            node,
                            message: "Split initialized '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    } else if (options[type].uninitialized === MODE_NEVER && declarationCounts.uninitialized > 0) {

                        // uninitialized
                        context.report({
                            node,
                            message: "Split uninitialized '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    }
                }
            }
        }
549404
def add_variable(self, node):
        
        if node.name not in self.variable_names:
            self.variables.append(node)
            self.variable_names.add(node.name)
            node.parent = self