idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
34,600 | public static boolean tryMergeBlock ( Node block , boolean alwaysMerge ) { checkState ( block . isBlock ( ) ) ; Node parent = block . getParent ( ) ; boolean canMerge = alwaysMerge || canMergeBlock ( block ) ; if ( isStatementBlock ( parent ) && canMerge ) { Node previous = block ; while ( block . hasChildren ( ) ) { Node child = block . removeFirstChild ( ) ; parent . addChildAfter ( child , previous ) ; previous = child ; } parent . removeChild ( block ) ; return true ; } else { return false ; } } | Merge a block with its parent block . |
34,601 | public static boolean canMergeBlock ( Node block ) { for ( Node c = block . getFirstChild ( ) ; c != null ; c = c . getNext ( ) ) { switch ( c . getToken ( ) ) { case LABEL : if ( canMergeBlock ( c ) ) { continue ; } else { return false ; } case CONST : case LET : case CLASS : case FUNCTION : return false ; default : continue ; } } return true ; } | A check inside a block to see if there are const let class or function declarations to be safe and not hoist them into the upper block . |
34,602 | public static Node getFunctionBody ( Node fn ) { checkArgument ( fn . isFunction ( ) , fn ) ; return fn . getLastChild ( ) ; } | Return a BLOCK node for the given FUNCTION node . |
34,603 | public static boolean isMethodDeclaration ( Node n ) { if ( n . isFunction ( ) ) { Node parent = n . getParent ( ) ; switch ( parent . getToken ( ) ) { case GETTER_DEF : case SETTER_DEF : case MEMBER_FUNCTION_DEF : return true ; case COMPUTED_PROP : return parent . getLastChild ( ) == n && ( parent . getBooleanProp ( Node . COMPUTED_PROP_METHOD ) || parent . getBooleanProp ( Node . COMPUTED_PROP_GETTER ) || parent . getBooleanProp ( Node . COMPUTED_PROP_SETTER ) ) ; default : return false ; } } else { return false ; } } | Is this node a class or object literal member function? |
34,604 | static boolean isFunctionExpression ( Node n ) { return n . isFunction ( ) && ! NodeUtil . isFunctionDeclaration ( n ) && ! NodeUtil . isMethodDeclaration ( n ) ; } | Is a FUNCTION node a function expression? |
34,605 | public static boolean isNameDeclOrSimpleAssignLhs ( Node n , Node parent ) { return ( parent . isAssign ( ) && parent . getFirstChild ( ) == n ) || NodeUtil . isNameDeclaration ( parent ) ; } | Determines whether this node is strictly on the left hand side of an assign or var initialization . Notably this does not include all L - values only statements where the node is used only as an L - value . |
34,606 | public static boolean isLValue ( Node n ) { switch ( n . getToken ( ) ) { case NAME : case GETPROP : case GETELEM : break ; default : return false ; } Node parent = n . getParent ( ) ; if ( parent == null ) { return false ; } switch ( parent . getToken ( ) ) { case IMPORT_SPEC : return parent . getLastChild ( ) == n ; case VAR : case LET : case CONST : case REST : case PARAM_LIST : case IMPORT : case INC : case DEC : case CATCH : return true ; case CLASS : case FUNCTION : case DEFAULT_VALUE : case FOR : case FOR_IN : case FOR_OF : case FOR_AWAIT_OF : return parent . getFirstChild ( ) == n ; case ARRAY_PATTERN : case STRING_KEY : case COMPUTED_PROP : return isLhsByDestructuring ( n ) ; default : return NodeUtil . isAssignmentOp ( parent ) && parent . getFirstChild ( ) == n ; } } | Determines whether this node is used as an L - value . Notice that sometimes names are used as both L - values and R - values . |
34,607 | public static boolean isDeclarationLValue ( Node n ) { boolean isLValue = isLValue ( n ) ; if ( ! isLValue ) { return false ; } Node parent = n . getParent ( ) ; switch ( parent . getToken ( ) ) { case IMPORT_SPEC : case VAR : case LET : case CONST : case PARAM_LIST : case IMPORT : case CATCH : case CLASS : case FUNCTION : return true ; case STRING_KEY : return isNameDeclaration ( parent . getParent ( ) . getGrandparent ( ) ) ; case OBJECT_PATTERN : case ARRAY_PATTERN : return isNameDeclaration ( parent . getGrandparent ( ) ) ; default : return false ; } } | Determines whether this node is used as an L - value that is a declaration . |
34,608 | public static Node getDeclaringParent ( Node targetNode ) { Node rootTarget = getRootTarget ( targetNode ) ; Node parent = rootTarget . getParent ( ) ; if ( parent . isRest ( ) || parent . isDefaultValue ( ) ) { parent = parent . getParent ( ) ; checkState ( parent . isParamList ( ) , parent ) ; } else if ( parent . isDestructuringLhs ( ) ) { parent = parent . getParent ( ) ; checkState ( isNameDeclaration ( parent ) , parent ) ; } else if ( parent . isClass ( ) || parent . isFunction ( ) ) { checkState ( targetNode == parent . getFirstChild ( ) , targetNode ) ; } else if ( parent . isImportSpec ( ) ) { checkState ( targetNode == parent . getSecondChild ( ) , targetNode ) ; parent = parent . getGrandparent ( ) ; checkState ( parent . isImport ( ) , parent ) ; } else { checkState ( parent . isParamList ( ) || isNameDeclaration ( parent ) || parent . isImport ( ) || parent . isCatch ( ) , parent ) ; } return parent ; } | Returns the node that is effectively declaring the given target . |
34,609 | public static Node getRootTarget ( Node targetNode ) { Node enclosingTarget = targetNode ; for ( Node nextTarget = getEnclosingTarget ( enclosingTarget ) ; nextTarget != null ; nextTarget = getEnclosingTarget ( enclosingTarget ) ) { enclosingTarget = nextTarget ; } return enclosingTarget ; } | Returns the outermost target enclosing the given assignment target . |
34,610 | private static Node getEnclosingTarget ( Node targetNode ) { checkState ( checkNotNull ( targetNode ) . isValidAssignmentTarget ( ) , targetNode ) ; Node parent = checkNotNull ( targetNode . getParent ( ) , targetNode ) ; boolean targetIsFirstChild = parent . getFirstChild ( ) == targetNode ; if ( parent . isDefaultValue ( ) || parent . isRest ( ) ) { checkState ( targetIsFirstChild , parent ) ; targetNode = parent ; parent = checkNotNull ( targetNode . getParent ( ) ) ; targetIsFirstChild = targetNode == parent . getFirstChild ( ) ; } switch ( parent . getToken ( ) ) { case ARRAY_PATTERN : return parent ; case OBJECT_PATTERN : return parent ; case COMPUTED_PROP : checkState ( ! targetIsFirstChild , parent ) ; case STRING_KEY : Node grandparent = checkNotNull ( parent . getParent ( ) , parent ) ; checkState ( grandparent . isObjectPattern ( ) , grandparent ) ; return grandparent ; case PARAM_LIST : case LET : case CONST : case VAR : return null ; case FUNCTION : case CLASS : checkState ( targetIsFirstChild , targetNode ) ; return null ; case FOR_IN : case FOR_OF : case FOR_AWAIT_OF : checkState ( targetIsFirstChild , targetNode ) ; return null ; case DESTRUCTURING_LHS : checkState ( targetIsFirstChild , targetNode ) ; return null ; case IMPORT : return null ; case IMPORT_SPEC : checkState ( ! targetIsFirstChild , parent ) ; return null ; case CATCH : return null ; default : checkState ( isAssignmentOp ( parent ) && targetIsFirstChild , parent ) ; return null ; } } | Returns the immediately enclosing target node for a given target node or null if none found . |
34,611 | public static boolean isLhsByDestructuring ( Node n ) { switch ( n . getToken ( ) ) { case NAME : case GETPROP : case GETELEM : return isLhsByDestructuringHelper ( n ) ; default : return false ; } } | Returns true if the node is a lhs value of a destructuring assignment . |
34,612 | static String getObjectLitKeyName ( Node key ) { Node keyNode = getObjectLitKeyNode ( key ) ; if ( keyNode != null ) { return keyNode . getString ( ) ; } throw new IllegalStateException ( "Unexpected node type: " + key ) ; } | Get the name of an object literal key . |
34,613 | static Node getObjectLitKeyNode ( Node key ) { switch ( key . getToken ( ) ) { case STRING_KEY : case GETTER_DEF : case SETTER_DEF : case MEMBER_FUNCTION_DEF : return key ; case COMPUTED_PROP : return key . getFirstChild ( ) . isString ( ) ? key . getFirstChild ( ) : null ; default : break ; } throw new IllegalStateException ( "Unexpected node type: " + key ) ; } | Get the Node that defines the name of an object literal key . |
34,614 | static boolean isNestedObjectPattern ( Node n ) { checkState ( n . isObjectPattern ( ) ) ; for ( Node key = n . getFirstChild ( ) ; key != null ; key = key . getNext ( ) ) { Node value = key . getFirstChild ( ) ; if ( value != null && ( value . isObjectLit ( ) || value . isArrayLit ( ) || value . isDestructuringPattern ( ) ) ) { return true ; } } return false ; } | Determine whether the destructuring object pattern is nested |
34,615 | static boolean isNestedArrayPattern ( Node n ) { checkState ( n . isArrayPattern ( ) ) ; for ( Node key = n . getFirstChild ( ) ; key != null ; key = key . getNext ( ) ) { if ( key . hasChildren ( ) ) { return true ; } } return false ; } | Determine whether the destructuring array pattern is nested |
34,616 | 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 ) ; } } | 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 . |
34,617 | static void copyNameAnnotations ( Node source , Node destination ) { if ( source . getBooleanProp ( Node . IS_CONSTANT_NAME ) ) { destination . putBooleanProp ( Node . IS_CONSTANT_NAME , true ) ; } } | Copy any annotations that follow a named value . |
34,618 | private static Node getAddingRoot ( Node n ) { Node addingRoot = null ; Node ancestor = n ; crawl_ancestors : while ( null != ( ancestor = ancestor . getParent ( ) ) ) { switch ( ancestor . getToken ( ) ) { case SCRIPT : case MODULE_BODY : addingRoot = ancestor ; break crawl_ancestors ; case FUNCTION : addingRoot = ancestor . getLastChild ( ) ; break crawl_ancestors ; default : continue crawl_ancestors ; } } checkState ( addingRoot . isBlock ( ) || addingRoot . isModuleBody ( ) || addingRoot . isScript ( ) ) ; checkState ( ! addingRoot . hasChildren ( ) || ! addingRoot . getFirstChild ( ) . isScript ( ) ) ; return addingRoot ; } | Gets a Node at the top of the current scope where we can add new var declarations as children . |
34,619 | static Node newQName ( AbstractCompiler compiler , String name , Node basisNode , String originalName ) { Node node = newQName ( compiler , name ) ; useSourceInfoForNewQName ( node , basisNode ) ; if ( ! originalName . equals ( node . getOriginalName ( ) ) ) { node . setOriginalName ( originalName ) ; } return node ; } | Creates a node representing a qualified name copying over the source location information from the basis node and assigning the given original name to the node . |
34,620 | private static void useSourceInfoForNewQName ( Node newQName , Node basisNode ) { if ( newQName . getStaticSourceFile ( ) == null ) { newQName . setStaticSourceFileFrom ( basisNode ) ; newQName . setSourceEncodedPosition ( basisNode . getSourcePosition ( ) ) ; } if ( newQName . getOriginalName ( ) == null ) { newQName . putProp ( Node . ORIGINALNAME_PROP , basisNode . getOriginalName ( ) ) ; } for ( Node child = newQName . getFirstChild ( ) ; child != null ; child = child . getNext ( ) ) { useSourceInfoForNewQName ( child , basisNode ) ; } } | Custom update new QName node with source info from another node . |
34,621 | static Node getRootOfQualifiedName ( Node qName ) { for ( Node current = qName ; true ; current = current . getFirstChild ( ) ) { if ( current . isName ( ) || current . isThis ( ) || current . isSuper ( ) ) { return current ; } checkState ( current . isGetProp ( ) , "Not a getprop node: " , current ) ; } } | Gets the root node of a qualified name . Must be either NAME THIS or SUPER . |
34,622 | static boolean isValidSimpleName ( String name ) { return TokenStream . isJSIdentifier ( name ) && ! TokenStream . isKeyword ( name ) && isLatin ( name ) ; } | Determines whether the given name is a valid variable name . |
34,623 | public static boolean isValidQualifiedName ( FeatureSet mode , String name ) { if ( name . endsWith ( "." ) || name . startsWith ( "." ) ) { return false ; } List < String > parts = Splitter . on ( '.' ) . splitToList ( name ) ; for ( String part : parts ) { if ( ! isValidPropertyName ( mode , part ) ) { return false ; } } return isValidSimpleName ( parts . get ( 0 ) ) ; } | Determines whether the given name is a valid qualified name . |
34,624 | static Collection < Node > getVarsDeclaredInBranch ( Node root ) { VarCollector collector = new VarCollector ( ) ; visitPreOrder ( root , collector , MATCH_NOT_FUNCTION ) ; return collector . vars . values ( ) ; } | Retrieves vars declared in the current node tree excluding descent scopes . |
34,625 | public static List < Node > findLhsNodesInNode ( Node assigningParent ) { checkArgument ( isNameDeclaration ( assigningParent ) || assigningParent . isParamList ( ) || isAssignmentOp ( assigningParent ) || assigningParent . isCatch ( ) || assigningParent . isDestructuringLhs ( ) || assigningParent . isDefaultValue ( ) || assigningParent . isImport ( ) || isEnhancedFor ( assigningParent ) , assigningParent ) ; ArrayList < Node > lhsNodes = new ArrayList < > ( ) ; getLhsNodesHelper ( assigningParent , lhsNodes ) ; return lhsNodes ; } | Retrieves lhs nodes declared or assigned in a given assigning parent node . |
34,626 | static Node newVarNode ( String name , Node value ) { Node lhs = IR . name ( name ) ; if ( value != null ) { lhs . srcref ( value ) ; } return newVarNode ( lhs , value ) ; } | Create a VAR node containing the given name and initial value expression . |
34,627 | static int getNodeTypeReferenceCount ( Node node , Token type , Predicate < Node > traverseChildrenPred ) { return getCount ( node , new MatchNodeType ( type ) , traverseChildrenPred ) ; } | Finds the number of times a type is referenced within the node tree . |
34,628 | static int getNameReferenceCount ( Node node , String name ) { return getCount ( node , new MatchNameNode ( name ) , Predicates . alwaysTrue ( ) ) ; } | Finds the number of times a simple name is referenced within the node tree . |
34,629 | public static void visitPreOrder ( Node node , Visitor visitor ) { visitPreOrder ( node , visitor , Predicates . alwaysTrue ( ) ) ; } | A pre - order traversal calling Visitor . visit for each decendent . |
34,630 | public static void visitPreOrder ( Node node , Visitor visitor , Predicate < Node > traverseChildrenPred ) { visitor . visit ( node ) ; if ( traverseChildrenPred . apply ( node ) ) { for ( Node c = node . getFirstChild ( ) ; c != null ; c = c . getNext ( ) ) { visitPreOrder ( c , visitor , traverseChildrenPred ) ; } } } | A pre - order traversal calling Visitor . visit for each child matching the predicate . |
34,631 | public static void visitPostOrder ( Node node , Visitor visitor ) { visitPostOrder ( node , visitor , Predicates . alwaysTrue ( ) ) ; } | A post - order traversal calling Visitor . visit for each decendent . |
34,632 | static boolean isConstantByConvention ( CodingConvention convention , Node node ) { Node parent = node . getParent ( ) ; if ( parent . isGetProp ( ) && node == parent . getLastChild ( ) ) { return convention . isConstantKey ( node . getString ( ) ) ; } else if ( mayBeObjectLitKey ( node ) ) { return convention . isConstantKey ( node . getString ( ) ) ; } else if ( node . isName ( ) ) { return convention . isConstant ( node . getString ( ) ) ; } return false ; } | Whether the given name is constant by coding convention . |
34,633 | static boolean isConstantDeclaration ( CodingConvention convention , JSDocInfo info , Node node ) { if ( node . isName ( ) && node . getParent ( ) . isConst ( ) ) { return true ; } else if ( node . isName ( ) && isLhsByDestructuring ( node ) && getRootTarget ( node ) . getGrandparent ( ) . isConst ( ) ) { return true ; } if ( info != null && info . isConstant ( ) ) { return true ; } if ( node . getBooleanProp ( Node . IS_CONSTANT_VAR ) ) { return true ; } switch ( node . getToken ( ) ) { case NAME : return NodeUtil . isConstantByConvention ( convention , node ) ; case GETPROP : return node . isQualifiedName ( ) && NodeUtil . isConstantByConvention ( convention , node . getLastChild ( ) ) ; default : break ; } return false ; } | Temporary function to determine if a node is constant in the old or new world . This does not check its inputs carefully because it will go away once we switch to the new world . |
34,634 | public static Node getNodeByLineCol ( Node ancestor , int lineNo , int columNo ) { checkArgument ( ancestor . isScript ( ) ) ; Node current = ancestor ; Node result = null ; while ( current != null ) { int currLineNo = current . getLineno ( ) ; checkState ( current . getLineno ( ) <= lineNo ) ; Node nextSibling = current . getNext ( ) ; if ( nextSibling != null ) { int nextSiblingLineNo = nextSibling . getLineno ( ) ; int nextSiblingColumNo = getColumnNoBase1 ( nextSibling ) ; if ( result != null && lineNo == nextSiblingLineNo && columNo == nextSiblingColumNo ) { if ( result . hasChildren ( ) && ! nextSibling . hasChildren ( ) ) { return nextSibling ; } return result ; } if ( lineNo > nextSiblingLineNo || ( lineNo > currLineNo && lineNo == nextSiblingLineNo ) || ( lineNo == nextSiblingLineNo && columNo > nextSiblingColumNo ) ) { current = nextSibling ; continue ; } } int currColumNo = getColumnNoBase1 ( current ) ; if ( currLineNo == lineNo ) { if ( currColumNo > columNo ) { return result ; } if ( currColumNo + current . getLength ( ) >= columNo ) { result = current ; } } current = current . getFirstChild ( ) ; } return result ; } | Column number 1 represents a cursor at the start of the line . |
34,635 | static Node newCallNode ( Node callTarget , Node ... parameters ) { boolean isFreeCall = ! isGet ( callTarget ) ; Node call = IR . call ( callTarget ) ; call . putBooleanProp ( Node . FREE_CALL , isFreeCall ) ; for ( Node parameter : parameters ) { call . addChildToBack ( parameter ) ; } return call ; } | A new CALL node with the FREE_CALL set based on call target . |
34,636 | private static Node getNthSibling ( Node first , int index ) { Node sibling = first ; while ( index != 0 && sibling != null ) { sibling = sibling . getNext ( ) ; index -- ; } return sibling ; } | Given the first sibling this returns the nth sibling or null if no such sibling exists . This is like getChildAtIndex but returns null for non - existent indexes . |
34,637 | static Node getArgumentForFunction ( Node function , int index ) { checkState ( function . isFunction ( ) ) ; return getNthSibling ( function . getSecondChild ( ) . getFirstChild ( ) , index ) ; } | Given the function this returns the nth argument or null if no such parameter exists . |
34,638 | static Node getArgumentForCallOrNew ( Node call , int index ) { checkState ( isCallOrNew ( call ) ) ; return getNthSibling ( call . getSecondChild ( ) , index ) ; } | Given the new or call this returns the nth argument of the call or null if no such argument exists . |
34,639 | static boolean isInvocationTarget ( Node n ) { Node parent = n . getParent ( ) ; return parent != null && ( isCallOrNew ( parent ) || parent . isTaggedTemplateLit ( ) ) && parent . getFirstChild ( ) == n ; } | Returns whether this is a target of a call or new . |
34,640 | public static JSTypeExpression getDeclaredTypeExpression ( Node declaration ) { checkArgument ( declaration . isName ( ) || declaration . isStringKey ( ) ) ; JSDocInfo nameJsdoc = getBestJSDocInfo ( declaration ) ; if ( nameJsdoc != null ) { return nameJsdoc . getType ( ) ; } Node parent = declaration . getParent ( ) ; if ( parent . isRest ( ) || parent . isDefaultValue ( ) ) { parent = parent . getParent ( ) ; } if ( parent . isParamList ( ) ) { JSDocInfo functionJsdoc = getBestJSDocInfo ( parent . getParent ( ) ) ; if ( functionJsdoc != null ) { return functionJsdoc . getParameterType ( declaration . getString ( ) ) ; } } return null ; } | Return declared JSDoc type for the given name declaration or null if none present . |
34,641 | public static JSDocInfo getBestJSDocInfo ( Node n ) { Node jsdocNode = getBestJSDocInfoNode ( n ) ; return jsdocNode == null ? null : jsdocNode . getJSDocInfo ( ) ; } | Find the best JSDoc for the given node . |
34,642 | public static Node getBestLValue ( Node n ) { Node parent = n . getParent ( ) ; if ( isFunctionDeclaration ( n ) || isClassDeclaration ( n ) ) { return n . getFirstChild ( ) ; } else if ( n . isClassMembers ( ) ) { return getBestLValue ( parent ) ; } else if ( parent . isName ( ) ) { return parent ; } else if ( parent . isAssign ( ) ) { return parent . getFirstChild ( ) ; } else if ( mayBeObjectLitKey ( parent ) || parent . isComputedProp ( ) ) { return parent ; } else if ( ( parent . isHook ( ) && parent . getFirstChild ( ) != n ) || parent . isOr ( ) || parent . isAnd ( ) || ( parent . isComma ( ) && parent . getFirstChild ( ) != n ) ) { return getBestLValue ( parent ) ; } else if ( parent . isCast ( ) ) { return getBestLValue ( parent ) ; } return null ; } | Find the l - value that the given r - value is being assigned to . |
34,643 | 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 ) ; } } | Recurses through a tree marking all function nodes as changed . |
34,644 | public static void markFunctionsDeleted ( Node node , AbstractCompiler compiler ) { if ( node . isFunction ( ) ) { compiler . reportFunctionDeleted ( node ) ; } for ( Node child = node . getFirstChild ( ) ; child != null ; child = child . getNext ( ) ) { markFunctionsDeleted ( child , compiler ) ; } } | Recurses through a tree marking all function nodes deleted . |
34,645 | public static List < Node > getParentChangeScopeNodes ( List < Node > scopeNodes ) { Set < Node > parentScopeNodes = new LinkedHashSet < > ( scopeNodes ) ; for ( Node scopeNode : scopeNodes ) { parentScopeNodes . add ( getEnclosingChangeScopeRoot ( scopeNode ) ) ; } return new ArrayList < > ( parentScopeNodes ) ; } | Returns the list of scope nodes which are parents of the provided list of scope nodes . |
34,646 | public static List < Node > removeNestedChangeScopeNodes ( List < Node > scopeNodes ) { Set < Node > uniqueScopeNodes = new LinkedHashSet < > ( scopeNodes ) ; for ( Node scopeNode : scopeNodes ) { for ( Node ancestor = scopeNode . getParent ( ) ; ancestor != null ; ancestor = ancestor . getParent ( ) ) { if ( isChangeScopeRoot ( ancestor ) && uniqueScopeNodes . contains ( ancestor ) ) { uniqueScopeNodes . remove ( scopeNode ) ; break ; } } } return new ArrayList < > ( uniqueScopeNodes ) ; } | Removes any scope nodes from the provided list that are nested within some other scope node also in the list . Returns the modified list . |
34,647 | static int getInvocationArgsCount ( Node invocation ) { if ( invocation . isTaggedTemplateLit ( ) ) { Iterable < Node > args = new TemplateArgsIterable ( invocation . getLastChild ( ) ) ; return Iterables . size ( args ) + 1 ; } else { return invocation . getChildCount ( ) - 1 ; } } | Returns the number of arguments in this invocation . For template literals it takes into account the implicit first argument of ITemplateArray |
34,648 | static void getAllVarsDeclaredInFunction ( final Map < String , Var > nameVarMap , final List < Var > orderedVars , AbstractCompiler compiler , ScopeCreator scopeCreator , final Scope scope ) { checkState ( nameVarMap . isEmpty ( ) ) ; checkState ( orderedVars . isEmpty ( ) ) ; checkState ( scope . isFunctionScope ( ) , scope ) ; ScopedCallback finder = new ScopedCallback ( ) { public void enterScope ( NodeTraversal t ) { Scope currentScope = t . getScope ( ) ; for ( Var v : currentScope . getVarIterable ( ) ) { nameVarMap . put ( v . getName ( ) , v ) ; orderedVars . add ( v ) ; } } public void exitScope ( NodeTraversal t ) { } public final boolean shouldTraverse ( NodeTraversal t , Node n , Node parent ) { return ! n . isFunction ( ) || n == scope . getRootNode ( ) ; } public void visit ( NodeTraversal t , Node n , Node parent ) { } } ; NodeTraversal t = new NodeTraversal ( compiler , finder , scopeCreator ) ; t . traverseAtScope ( scope ) ; } | Records a mapping of names to vars of everything reachable in a function . Should only be called with a function scope . Does not enter new control flow areas aka embedded functions . |
34,649 | public static boolean isObjLitProperty ( Node node ) { return node . isStringKey ( ) || node . isGetterDef ( ) || node . isSetterDef ( ) || node . isMemberFunctionDef ( ) || node . isComputedProp ( ) ; } | Returns true if the node is a property of an object literal . |
34,650 | static void addFeatureToScript ( Node scriptNode , Feature feature ) { checkState ( scriptNode . isScript ( ) , scriptNode ) ; FeatureSet currentFeatures = getFeatureSetOfScript ( scriptNode ) ; FeatureSet newFeatures = currentFeatures != null ? currentFeatures . with ( feature ) : FeatureSet . BARE_MINIMUM . with ( feature ) ; scriptNode . putProp ( Node . FEATURE_SET , newFeatures ) ; } | Adds the given features to a SCRIPT node s FeatureSet property . |
34,651 | JSType inferType ( ) { JSType inferredType = inferTypeWithoutUsingDefaultValue ( ) ; if ( ! inferredType . isUnknownType ( ) && hasDefaultValue ( ) ) { JSType defaultValueType = getDefaultValue ( ) . getJSType ( ) ; if ( defaultValueType == null ) { defaultValueType = registry . getNativeType ( JSTypeNative . UNKNOWN_TYPE ) ; } return registry . createUnionType ( inferredType . restrictByNotUndefined ( ) , defaultValueType ) ; } else { return inferredType ; } } | Infers the type of this target |
34,652 | public void process ( Node externs , Node root ) { checkState ( compiler . getLifeCycleStage ( ) . isNormalized ( ) ) ; if ( ! allowRemovalOfExternProperties ) { referencedPropertyNames . addAll ( compiler . getExternProperties ( ) ) ; } traverseAndRemoveUnusedReferences ( root ) ; GatherGettersAndSetterProperties . update ( compiler , externs , root ) ; } | Traverses the root removing all unused variables . Multiple traversals may occur to ensure all unused variables are removed . |
34,653 | private void traverseAndRemoveUnusedReferences ( Node root ) { Scope scope = scopeCreator . createScope ( root . getParent ( ) , null ) ; if ( ! scope . hasSlot ( NodeUtil . JSC_PROPERTY_NAME_FN ) ) { scope . declare ( NodeUtil . JSC_PROPERTY_NAME_FN , null , null ) ; } worklist . add ( new Continuation ( root , scope ) ) ; while ( ! worklist . isEmpty ( ) ) { Continuation continuation = worklist . remove ( ) ; continuation . apply ( ) ; } removeUnreferencedVarsAndPolyfills ( ) ; removeIndependentlyRemovableProperties ( ) ; for ( Scope fparamScope : allFunctionParamScopes ) { removeUnreferencedFunctionArgs ( fparamScope ) ; } } | Traverses a node recursively . Call this once per pass . |
34,654 | private void traverseClass ( Node classNode , Scope scope ) { checkArgument ( classNode . isClass ( ) ) ; if ( NodeUtil . isClassDeclaration ( classNode ) ) { traverseClassDeclaration ( classNode , scope ) ; } else { traverseClassExpression ( classNode , scope ) ; } } | Handle a class that is not the RHS child of an assignment or a variable declaration initializer . |
34,655 | private void traverseFunction ( Node function , Scope parentScope ) { checkState ( function . getChildCount ( ) == 3 , function ) ; checkState ( function . isFunction ( ) , function ) ; final Node paramlist = NodeUtil . getFunctionParameters ( function ) ; final Node body = function . getLastChild ( ) ; checkState ( body . getNext ( ) == null && body . isBlock ( ) , body ) ; Scope fparamScope = scopeCreator . createScope ( function , parentScope ) ; Scope fbodyScope = scopeCreator . createScope ( body , fparamScope ) ; Node nameNode = function . getFirstChild ( ) ; if ( ! nameNode . getString ( ) . isEmpty ( ) ) { VarInfo varInfo = traverseNameNode ( nameNode , fparamScope ) ; if ( NodeUtil . isExpressionResultUsed ( function ) ) { varInfo . hasNonLocalOrNonLiteralValue = true ; } } traverseChildren ( paramlist , fparamScope ) ; traverseChildren ( body , fbodyScope ) ; allFunctionParamScopes . add ( fparamScope ) ; } | Traverses a function |
34,656 | private void removeUnreferencedFunctionArgs ( Scope fparamScope ) { if ( ! removeGlobals ) { return ; } Node function = fparamScope . getRootNode ( ) ; checkState ( function . isFunction ( ) ) ; if ( NodeUtil . isGetOrSetKey ( function . getParent ( ) ) ) { return ; } Node argList = NodeUtil . getFunctionParameters ( function ) ; maybeRemoveUnusedTrailingParameters ( argList , fparamScope ) ; markUnusedParameters ( argList , fparamScope ) ; } | Removes unreferenced arguments from a function declaration and when possible the function s callSites . |
34,657 | private void markUnusedParameters ( Node paramList , Scope fparamScope ) { for ( Node param = paramList . getFirstChild ( ) ; param != null ; param = param . getNext ( ) ) { if ( param . isUnusedParameter ( ) ) { continue ; } Node lValue = nameOfParam ( param ) ; if ( lValue == null ) { continue ; } VarInfo varInfo = traverseNameNode ( lValue , fparamScope ) ; if ( varInfo . isRemovable ( ) ) { param . setUnusedParameter ( true ) ; compiler . reportChangeToEnclosingScope ( paramList ) ; } } } | Mark any remaining unused parameters as being unused so it can be used elsewhere . |
34,658 | private void maybeRemoveUnusedTrailingParameters ( Node argList , Scope fparamScope ) { Node lastArg ; while ( ( lastArg = argList . getLastChild ( ) ) != null ) { Node lValue = lastArg ; if ( lastArg . isDefaultValue ( ) ) { lValue = lastArg . getFirstChild ( ) ; if ( NodeUtil . mayHaveSideEffects ( lastArg . getLastChild ( ) , compiler ) ) { break ; } } if ( lValue . isRest ( ) ) { lValue = lValue . getFirstChild ( ) ; } if ( lValue . isDestructuringPattern ( ) ) { if ( lValue . hasChildren ( ) ) { break ; } else { NodeUtil . deleteNode ( lastArg , compiler ) ; continue ; } } VarInfo varInfo = getVarInfo ( getVarForNameNode ( lValue , fparamScope ) ) ; if ( varInfo . isRemovable ( ) ) { NodeUtil . deleteNode ( lastArg , compiler ) ; } else { break ; } } } | Strip as many unreferenced args off the end of the function declaration as possible . We start from the end of the function declaration because removing parameters from the middle of the param list could mess up the interpretation of parameters being sent over by any function calls . |
34,659 | private void removeUnreferencedVarsAndPolyfills ( ) { for ( Entry < Var , VarInfo > entry : varInfoMap . entrySet ( ) ) { Var var = entry . getKey ( ) ; VarInfo varInfo = entry . getValue ( ) ; if ( ! varInfo . isRemovable ( ) ) { continue ; } varInfo . removeAllRemovables ( ) ; Node nameNode = var . nameNode ; Node toRemove = nameNode . getParent ( ) ; if ( toRemove == null || alreadyRemoved ( toRemove ) ) { } else if ( NodeUtil . isFunctionExpression ( toRemove ) ) { if ( ! preserveFunctionExpressionNames ) { Node fnNameNode = toRemove . getFirstChild ( ) ; compiler . reportChangeToEnclosingScope ( fnNameNode ) ; fnNameNode . setString ( "" ) ; } } else { checkState ( toRemove . isParamList ( ) || ( toRemove . getParent ( ) . isParamList ( ) && ( toRemove . isDefaultValue ( ) || toRemove . isRest ( ) ) ) , "unremoved code: %s" , toRemove ) ; } } Iterator < PolyfillInfo > iter = polyfills . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { PolyfillInfo polyfill = iter . next ( ) ; if ( polyfill . isRemovable ) { polyfill . removable . remove ( compiler ) ; iter . remove ( ) ; } } } | Removes any vars in the scope that were not referenced . Removes any assignments to those variables as well . |
34,660 | private static boolean isLocalDefaultValueAssignment ( Node targetNode , Node valueNode ) { return valueNode . isOr ( ) && targetNode . isQualifiedName ( ) && valueNode . getFirstChild ( ) . isEquivalentTo ( targetNode ) && NodeUtil . evaluatesToLocalValue ( valueNode . getLastChild ( ) ) ; } | True if targetNode is a qualified name and the valueNode is of the form targetQualifiedName || localValue . |
34,661 | private PolyfillInfo createPolyfillInfo ( Node call , Scope scope , String name ) { checkState ( scope . isGlobal ( ) ) ; checkState ( call . getParent ( ) . isExprResult ( ) ) ; RemovableBuilder builder = new RemovableBuilder ( ) ; for ( Node n = call . getFirstChild ( ) . getNext ( ) ; n != null ; n = n . getNext ( ) ) { builder . addContinuation ( new Continuation ( n , scope ) ) ; } Polyfill removable = builder . buildPolyfill ( call . getParent ( ) ) ; int lastDot = name . lastIndexOf ( "." ) ; if ( lastDot < 0 ) { return new GlobalPolyfillInfo ( removable , name ) ; } String owner = name . substring ( 0 , lastDot ) ; String prop = name . substring ( lastDot + 1 ) ; boolean typed = call . getJSType ( ) != null ; if ( owner . endsWith ( DOT_PROTOTYPE ) ) { owner = owner . substring ( 0 , owner . length ( ) - DOT_PROTOTYPE . length ( ) ) ; return new PrototypePropertyPolyfillInfo ( removable , prop , typed ? compiler . getTypeRegistry ( ) . getType ( scope , owner ) : null ) ; } ObjectType ownerInstanceType = typed ? ObjectType . cast ( compiler . getTypeRegistry ( ) . getType ( scope , owner ) ) : null ; JSType ownerCtorType = ownerInstanceType != null ? ownerInstanceType . getConstructor ( ) : null ; return new StaticPropertyPolyfillInfo ( removable , prop , ownerCtorType , owner ) ; } | Makes a new PolyfillInfo including the correct Removable . Parses the name to determine whether this is a global static or prototype polyfill . |
34,662 | private static Set < JsArray < String > > assoc ( ) { return new TreeSet < > ( Ordering . < String > natural ( ) . lexicographical ( ) . onResultOf ( JsArray :: asList ) ) ; } | Returns an associative multimap . |
34,663 | public final boolean isNominalConstructor ( ) { if ( isConstructor ( ) || isInterface ( ) ) { FunctionType fn = toMaybeFunctionType ( ) ; if ( fn == null ) { return false ; } if ( fn . getSource ( ) != null ) { return true ; } return fn . isNativeObjectType ( ) ; } return false ; } | Whether this type is the original constructor of a nominal type . Does not include structural constructors . |
34,664 | private String deepestResolvedTypeNameOf ( ObjectType objType ) { if ( ! objType . isResolved ( ) || ! ( objType instanceof ProxyObjectType ) ) { return objType . getReferenceName ( ) ; } ObjectType internal = ( ( ProxyObjectType ) objType ) . getReferencedObjTypeInternal ( ) ; return ( internal != null && internal . isNominalType ( ) ) ? deepestResolvedTypeNameOf ( internal ) : null ; } | Named types may be proxies of concrete types . |
34,665 | protected JSType findPropertyTypeWithoutConsideringTemplateTypes ( String propertyName ) { ObjectType autoboxObjType = ObjectType . cast ( autoboxesTo ( ) ) ; if ( autoboxObjType != null ) { return autoboxObjType . findPropertyType ( propertyName ) ; } return null ; } | Looks up a property on this type but without properly replacing any templates in the result . |
34,666 | public JSType autobox ( ) { JSType restricted = restrictByNotNullOrUndefined ( ) ; JSType autobox = restricted . autoboxesTo ( ) ; return autobox == null ? restricted : autobox ; } | Dereferences a type for property access . |
34,667 | @ SuppressWarnings ( "AmbiguousMethodReference" ) static JSType getLeastSupertype ( JSType thisType , JSType thatType ) { boolean areEquivalent = thisType . isEquivalentTo ( thatType ) ; return areEquivalent ? thisType : filterNoResolvedType ( thisType . registry . createUnionType ( thisType , thatType ) ) ; } | A generic implementation meant to be used as a helper for common getLeastSupertype implementations . |
34,668 | static boolean isSubtypeHelper ( JSType thisType , JSType thatType , ImplCache implicitImplCache , SubtypingMode subtypingMode ) { checkNotNull ( thisType ) ; if ( thatType . isUnknownType ( ) ) { return true ; } if ( thatType . isAllType ( ) ) { return true ; } if ( thisType . isEquivalentTo ( thatType , implicitImplCache . isStructuralTyping ( ) ) ) { return true ; } if ( thatType . isUnionType ( ) ) { UnionType union = thatType . toMaybeUnionType ( ) ; ImmutableList < JSType > alternates = union . getAlternates ( ) ; for ( int i = 0 ; i < alternates . size ( ) ; i ++ ) { JSType element = alternates . get ( i ) ; if ( thisType . isSubtype ( element , implicitImplCache , subtypingMode ) ) { return true ; } } return false ; } if ( subtypingMode == SubtypingMode . IGNORE_NULL_UNDEFINED && ( thisType . isNullType ( ) || thisType . isVoidType ( ) ) ) { return true ; } TemplateTypeMap thisTypeParams = thisType . getTemplateTypeMap ( ) ; TemplateTypeMap thatTypeParams = thatType . getTemplateTypeMap ( ) ; boolean templateMatch = true ; if ( isBivariantType ( thatType ) ) { TemplateType key = thisType . registry . getObjectElementKey ( ) ; JSType thisElement = thisTypeParams . getResolvedTemplateType ( key ) ; JSType thatElement = thatTypeParams . getResolvedTemplateType ( key ) ; templateMatch = thisElement . isSubtype ( thatElement , implicitImplCache , subtypingMode ) || thatElement . isSubtype ( thisElement , implicitImplCache , subtypingMode ) ; } else if ( isIThenableSubtype ( thatType ) ) { TemplateType key = thisType . registry . getThenableValueKey ( ) ; JSType thisElement = thisTypeParams . getResolvedTemplateType ( key ) ; JSType thatElement = thatTypeParams . getResolvedTemplateType ( key ) ; templateMatch = thisElement . isSubtype ( thatElement , implicitImplCache , subtypingMode ) ; } else { templateMatch = thisTypeParams . checkEquivalenceHelper ( thatTypeParams , EquivalenceMethod . INVARIANT , subtypingMode ) ; } if ( ! templateMatch ) { return false ; } if ( implicitImplCache . shouldMatchStructurally ( thisType , thatType ) ) { return thisType . toMaybeObjectType ( ) . isStructuralSubtype ( thatType . toMaybeObjectType ( ) , implicitImplCache , subtypingMode ) ; } if ( thisType . isTemplatizedType ( ) ) { return thisType . toMaybeTemplatizedType ( ) . getReferencedType ( ) . isSubtype ( thatType , implicitImplCache , subtypingMode ) ; } if ( thatType instanceof ProxyObjectType ) { return thisType . isSubtype ( ( ( ProxyObjectType ) thatType ) . getReferencedTypeInternal ( ) , implicitImplCache , subtypingMode ) ; } return false ; } | if implicitImplCache is null there is no structural interface matching |
34,669 | static boolean isBivariantType ( JSType type ) { ObjectType objType = type . toObjectType ( ) ; return objType != null && BIVARIANT_TYPES . contains ( objType . getReferenceName ( ) ) ; } | Determines if the supplied type should be checked as a bivariant templatized type rather the standard invariant templatized type rules . |
34,670 | static boolean isIThenableSubtype ( JSType type ) { if ( type . isTemplatizedType ( ) ) { TemplatizedType ttype = type . toMaybeTemplatizedType ( ) ; return ttype . getTemplateTypeMap ( ) . hasTemplateKey ( ttype . registry . getThenableValueKey ( ) ) ; } return false ; } | Determines if the specified type is exempt from standard invariant templatized typing rules . |
34,671 | public final JSType resolve ( ErrorReporter reporter ) { if ( resolved ) { if ( resolveResult == null ) { return this ; } return resolveResult ; } resolved = true ; resolveResult = resolveInternal ( reporter ) ; resolveResult . setResolvedTypeInternal ( resolveResult ) ; return resolveResult ; } | Resolve this type in the given scope . |
34,672 | static final JSType safeResolve ( JSType type , ErrorReporter reporter ) { return type == null ? null : type . resolve ( reporter ) ; } | A null - safe resolve . |
34,673 | public final String toAnnotationString ( Nullability nullability ) { return nullability == Nullability . EXPLICIT ? appendAsNonNull ( new StringBuilder ( ) , true ) . toString ( ) : appendTo ( new StringBuilder ( ) , true ) . toString ( ) ; } | Don t call from this package ; use appendAsNonNull instead . |
34,674 | public JSType getInstantiatedTypeArgument ( JSType supertype ) { TemplateType templateType = Iterables . getOnlyElement ( supertype . getTemplateTypeMap ( ) . getTemplateKeys ( ) ) ; return getTemplateTypeMap ( ) . getResolvedTemplateType ( templateType ) ; } | Returns the template type argument in this type s map corresponding to the supertype s template parameter or the UNKNOWN_TYPE if the supertype template key is not present . |
34,675 | public Collection < NameInfo > getAllNameInfo ( ) { List < NameInfo > result = new ArrayList < > ( propertyNameInfo . values ( ) ) ; result . addAll ( varNameInfo . values ( ) ) ; return result ; } | Returns information on all prototype properties . |
34,676 | private NameInfo getNameInfoForName ( String name , SymbolType type ) { Map < String , NameInfo > map = type == PROPERTY ? propertyNameInfo : varNameInfo ; if ( map . containsKey ( name ) ) { return map . get ( name ) ; } else { NameInfo nameInfo = new NameInfo ( name ) ; map . put ( name , nameInfo ) ; symbolGraph . createNode ( nameInfo ) ; return nameInfo ; } } | Gets the name info for the property or variable of a given name and creates a new one if necessary . |
34,677 | private void trackMessage ( NodeTraversal t , JsMessage message , String msgName , Node msgNode , boolean isUnnamedMessage ) { if ( ! isUnnamedMessage ) { MessageLocation location = new MessageLocation ( message , msgNode ) ; messageNames . put ( msgName , location ) ; } else { Var var = t . getScope ( ) . getVar ( msgName ) ; if ( var != null ) { unnamedMessages . put ( var , message ) ; } } } | Track a message for later retrieval . |
34,678 | private static boolean isLegalMessageVarAlias ( Node msgNode , String msgKey ) { if ( msgNode . isGetProp ( ) && msgNode . isQualifiedName ( ) && msgNode . getLastChild ( ) . getString ( ) . equals ( msgKey ) ) { return true ; } if ( msgNode . getGrandparent ( ) . isObjectPattern ( ) && msgNode . isName ( ) ) { String aliasName = ( msgNode . getOriginalName ( ) != null ) ? msgNode . getOriginalName ( ) : msgNode . getString ( ) ; if ( aliasName . equals ( msgKey ) ) { return true ; } } return false ; } | Defines any special cases that are exceptions to what would otherwise be illegal message assignments . |
34,679 | private JsMessage getTrackedMessage ( NodeTraversal t , String msgName ) { boolean isUnnamedMessage = isUnnamedMessageName ( msgName ) ; if ( ! isUnnamedMessage ) { MessageLocation location = messageNames . get ( msgName ) ; return location == null ? null : location . message ; } else { Var var = t . getScope ( ) . getVar ( msgName ) ; if ( var != null ) { return unnamedMessages . get ( var ) ; } } return null ; } | Get a previously tracked message . |
34,680 | private void checkIfMessageDuplicated ( String msgName , Node msgNode ) { if ( messageNames . containsKey ( msgName ) ) { MessageLocation location = messageNames . get ( msgName ) ; compiler . report ( JSError . make ( msgNode , MESSAGE_DUPLICATE_KEY , msgName , location . messageNode . getSourceFileName ( ) , Integer . toString ( location . messageNode . getLineno ( ) ) ) ) ; } } | Checks if message already processed . If so - it generates message duplicated compiler error . |
34,681 | private static boolean maybeInitMetaDataFromJsDoc ( Builder builder , Node node ) { boolean messageHasDesc = false ; JSDocInfo info = node . getJSDocInfo ( ) ; if ( info != null ) { String desc = info . getDescription ( ) ; if ( desc != null ) { builder . setDesc ( desc ) ; messageHasDesc = true ; } if ( info . isHidden ( ) ) { builder . setIsHidden ( true ) ; } if ( info . getMeaning ( ) != null ) { builder . setMeaning ( info . getMeaning ( ) ) ; } } return messageHasDesc ; } | Initializes the meta data in a message builder given a node that may contain JsDoc properties . |
34,682 | private static void extractFromReturnDescendant ( Builder builder , Node node ) throws MalformedException { switch ( node . getToken ( ) ) { case STRING : builder . appendStringPart ( node . getString ( ) ) ; break ; case NAME : builder . appendPlaceholderReference ( node . getString ( ) ) ; break ; case ADD : for ( Node child : node . children ( ) ) { extractFromReturnDescendant ( builder , child ) ; } break ; default : throw new MalformedException ( "STRING, NAME, or ADD node expected; found: " + node . getToken ( ) , node ) ; } } | Appends value parts to the message builder by traversing the descendants of the given RETURN node . |
34,683 | private static void parseMessageTextNode ( Builder builder , Node node ) throws MalformedException { String value = extractStringFromStringExprNode ( node ) ; while ( true ) { int phBegin = value . indexOf ( PH_JS_PREFIX ) ; if ( phBegin < 0 ) { builder . appendStringPart ( value ) ; return ; } else { if ( phBegin > 0 ) { builder . appendStringPart ( value . substring ( 0 , phBegin ) ) ; } int phEnd = value . indexOf ( PH_JS_SUFFIX , phBegin ) ; if ( phEnd < 0 ) { throw new MalformedException ( "Placeholder incorrectly formatted in: " + builder . getKey ( ) , node ) ; } String phName = value . substring ( phBegin + PH_JS_PREFIX . length ( ) , phEnd ) ; builder . appendPlaceholderReference ( phName ) ; int nextPos = phEnd + PH_JS_SUFFIX . length ( ) ; if ( nextPos < value . length ( ) ) { value = value . substring ( nextPos ) ; } else { return ; } } } } | Appends the message parts in a JS message value extracted from the given text node . |
34,684 | private void visitFallbackFunctionCall ( NodeTraversal t , Node call ) { if ( call . getChildCount ( ) != 3 || ! call . getSecondChild ( ) . isName ( ) || ! call . getLastChild ( ) . isName ( ) ) { compiler . report ( JSError . make ( call , BAD_FALLBACK_SYNTAX ) ) ; return ; } Node firstArg = call . getSecondChild ( ) ; String name = firstArg . getOriginalName ( ) ; if ( name == null ) { name = firstArg . getString ( ) ; } JsMessage firstMessage = getTrackedMessage ( t , name ) ; if ( firstMessage == null ) { compiler . report ( JSError . make ( firstArg , FALLBACK_ARG_ERROR , name ) ) ; return ; } Node secondArg = firstArg . getNext ( ) ; name = secondArg . getOriginalName ( ) ; if ( name == null ) { name = secondArg . getString ( ) ; } JsMessage secondMessage = getTrackedMessage ( t , name ) ; if ( secondMessage == null ) { compiler . report ( JSError . make ( secondArg , FALLBACK_ARG_ERROR , name ) ) ; return ; } processMessageFallback ( call , firstMessage , secondMessage ) ; } | Visit a call to goog . getMsgWithFallback . |
34,685 | boolean isMessageName ( String identifier , boolean isNewStyleMessage ) { return identifier . startsWith ( MSG_PREFIX ) && ( style == JsMessage . Style . CLOSURE || isNewStyleMessage || ! identifier . endsWith ( DESC_SUFFIX ) ) ; } | Returns whether the given JS identifier is a valid JS message name . |
34,686 | public static synchronized DiagnosticGroup forType ( DiagnosticType type ) { singletons . computeIfAbsent ( type , DiagnosticGroup :: new ) ; return singletons . get ( type ) ; } | Create a diagnostic group that matches only the given type . |
34,687 | boolean isSubGroup ( DiagnosticGroup group ) { for ( DiagnosticType type : group . types ) { if ( ! matches ( type ) ) { return false ; } } return true ; } | Returns whether all of the types in the given group are in this group . |
34,688 | private static void checkWith ( NodeTraversal t , Node n ) { JSDocInfo info = n . getJSDocInfo ( ) ; boolean allowWith = info != null && info . getSuppressions ( ) . contains ( "with" ) ; if ( ! allowWith ) { t . report ( n , USE_OF_WITH ) ; } } | Reports a warning for with statements . |
34,689 | private static boolean isDeclaration ( Node n ) { switch ( n . getParent ( ) . getToken ( ) ) { case LET : case CONST : case VAR : case CATCH : return true ; case FUNCTION : return n == n . getParent ( ) . getFirstChild ( ) ; case PARAM_LIST : return n . getGrandparent ( ) . isFunction ( ) ; default : return false ; } } | Determines if the given name is a declaration which can be a declaration of a variable function or argument . |
34,690 | private static void checkAssignment ( NodeTraversal t , Node n ) { if ( n . getFirstChild ( ) . isName ( ) ) { if ( "arguments" . equals ( n . getFirstChild ( ) . getString ( ) ) ) { t . report ( n , ARGUMENTS_ASSIGNMENT ) ; } else if ( "eval" . equals ( n . getFirstChild ( ) . getString ( ) ) ) { t . report ( n , EVAL_ASSIGNMENT ) ; } } } | Checks that an assignment is not to the arguments object . |
34,691 | private static void checkDelete ( NodeTraversal t , Node n ) { if ( n . getFirstChild ( ) . isName ( ) ) { Var v = t . getScope ( ) . getVar ( n . getFirstChild ( ) . getString ( ) ) ; if ( v != null ) { t . report ( n , DELETE_VARIABLE ) ; } } } | Checks that variables functions and arguments are not deleted . |
34,692 | private static void checkObjectLiteralOrClass ( NodeTraversal t , Node n ) { Set < String > getters = new HashSet < > ( ) ; Set < String > setters = new HashSet < > ( ) ; Set < String > staticGetters = new HashSet < > ( ) ; Set < String > staticSetters = new HashSet < > ( ) ; for ( Node key = n . getFirstChild ( ) ; key != null ; key = key . getNext ( ) ) { if ( key . isEmpty ( ) || key . isComputedProp ( ) ) { continue ; } if ( key . isSpread ( ) ) { continue ; } String keyName = key . getString ( ) ; if ( ! key . isSetterDef ( ) ) { Set < String > set = key . isStaticMember ( ) ? staticGetters : getters ; if ( ! set . add ( keyName ) ) { if ( n . isClassMembers ( ) ) { t . report ( key , DUPLICATE_CLASS_METHODS , keyName ) ; } else { t . report ( key , DUPLICATE_OBJECT_KEY , keyName ) ; } } } if ( ! key . isGetterDef ( ) ) { Set < String > set = key . isStaticMember ( ) ? staticSetters : setters ; if ( ! set . add ( keyName ) ) { if ( n . isClassMembers ( ) ) { t . report ( key , DUPLICATE_CLASS_METHODS , keyName ) ; } else { t . report ( key , DUPLICATE_OBJECT_KEY , keyName ) ; } } } } } | Checks that object literal keys or class method names are valid . |
34,693 | private void addExportMethod ( Map < String , Node > exports , String export , Node context ) { String methodOwnerName = null ; boolean isEs5StylePrototypeAssignment = false ; String propertyName = null ; if ( context . getFirstChild ( ) . isGetProp ( ) ) { Node node = context . getFirstChild ( ) ; Node ownerNode = node . getFirstChild ( ) ; methodOwnerName = ownerNode . getQualifiedName ( ) ; if ( ownerNode . isGetProp ( ) && ownerNode . getLastChild ( ) . getString ( ) . equals ( PROTOTYPE_PROPERTY ) ) { isEs5StylePrototypeAssignment = true ; } propertyName = node . getSecondChild ( ) . getString ( ) ; } boolean useExportSymbol = true ; if ( isEs5StylePrototypeAssignment ) { useExportSymbol = false ; } else if ( methodOwnerName != null && exports . containsKey ( methodOwnerName ) ) { useExportSymbol = false ; } if ( useExportSymbol ) { addExportSymbolCall ( export , context ) ; } else { addExportPropertyCall ( methodOwnerName , context , export , propertyName ) ; } } | Emits a call to either goog . exportProperty or goog . exportSymbol . |
34,694 | private static int jsSplitMatch ( String stringValue , int startIndex , String separator ) { if ( startIndex + separator . length ( ) > stringValue . length ( ) ) { return - 1 ; } int matchIndex = stringValue . indexOf ( separator , startIndex ) ; if ( matchIndex < 0 ) { return - 1 ; } return matchIndex ; } | Support function for jsSplit find the first occurrence of separator within stringValue starting at startIndex . |
34,695 | private String [ ] jsSplit ( String stringValue , String separator , int limit ) { checkArgument ( limit >= 0 ) ; checkArgument ( stringValue != null ) ; if ( limit == 0 ) { return new String [ 0 ] ; } if ( separator == null ) { return new String [ ] { stringValue } ; } List < String > splitStrings = new ArrayList < > ( ) ; if ( separator . isEmpty ( ) ) { for ( int i = 0 ; i < stringValue . length ( ) && i < limit ; i ++ ) { splitStrings . add ( stringValue . substring ( i , i + 1 ) ) ; } } else { int startIndex = 0 ; int matchIndex ; while ( ( matchIndex = jsSplitMatch ( stringValue , startIndex , separator ) ) >= 0 && splitStrings . size ( ) < limit ) { splitStrings . add ( stringValue . substring ( startIndex , matchIndex ) ) ; startIndex = matchIndex + separator . length ( ) ; } if ( splitStrings . size ( ) < limit ) { if ( startIndex < stringValue . length ( ) ) { splitStrings . add ( stringValue . substring ( startIndex ) ) ; } else { splitStrings . add ( "" ) ; } } } return splitStrings . toArray ( new String [ 0 ] ) ; } | Implement the JS String . split method using a string separator . |
34,696 | final PropertyAccessKind getPropertyAccessKind ( String property ) { return getExternGetterAndSetterProperties ( ) . getOrDefault ( property , PropertyAccessKind . NORMAL ) . unionWith ( getSourceGetterAndSetterProperties ( ) . getOrDefault ( property , PropertyAccessKind . NORMAL ) ) ; } | Returns any property seen in the externs or source with the given name was a getter setter or both . |
34,697 | void setAnnotation ( String key , Object object ) { checkArgument ( object != null , "The stored annotation value cannot be null." ) ; Preconditions . checkArgument ( ! annotationMap . containsKey ( key ) , "Cannot overwrite the existing annotation '%s'." , key ) ; annotationMap . put ( key , object ) ; } | Sets an annotation for the given key . |
34,698 | private Node tryFoldAddConstantString ( Node n , Node left , Node right ) { if ( left . isString ( ) || right . isString ( ) || left . isArrayLit ( ) || right . isArrayLit ( ) ) { String leftString = NodeUtil . getStringValue ( left ) ; String rightString = NodeUtil . getStringValue ( right ) ; if ( leftString != null && rightString != null ) { Node newStringNode = IR . string ( leftString + rightString ) ; n . replaceWith ( newStringNode ) ; reportChangeToEnclosingScope ( newStringNode ) ; return newStringNode ; } } return n ; } | Try to fold an ADD node with constant operands |
34,699 | private Node tryFoldShift ( Node n , Node left , Node right ) { if ( left . isNumber ( ) && right . isNumber ( ) ) { double result ; double lval = left . getDouble ( ) ; double rval = right . getDouble ( ) ; if ( ! ( rval >= 0 && rval < 32 ) ) { return n ; } int rvalInt = ( int ) rval ; if ( rvalInt != rval ) { report ( FRACTIONAL_BITWISE_OPERAND , right ) ; return n ; } if ( Math . floor ( lval ) != lval ) { report ( FRACTIONAL_BITWISE_OPERAND , left ) ; return n ; } int bits = jsConvertDoubleToBits ( lval ) ; switch ( n . getToken ( ) ) { case LSH : result = bits << rvalInt ; break ; case RSH : result = bits >> rvalInt ; break ; case URSH : result = 0xffffffffL & ( bits >>> rvalInt ) ; break ; default : throw new AssertionError ( "Unknown shift operator: " + n . getToken ( ) ) ; } Node newNumber = IR . number ( result ) ; reportChangeToEnclosingScope ( n ) ; n . replaceWith ( newNumber ) ; return newNumber ; } return n ; } | Try to fold shift operations |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.