idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
34,800 | void fillSymbolVisibility ( Node externs , Node root ) { CollectFileOverviewVisibility collectPass = new CollectFileOverviewVisibility ( compiler ) ; collectPass . process ( externs , root ) ; ImmutableMap < StaticSourceFile , Visibility > visibilityMap = collectPass . getFileOverviewVisibilityMap ( ) ; NodeTraversal . traverseRoots ( compiler , new VisibilityCollector ( visibilityMap , compiler . getCodingConvention ( ) ) , externs , root ) ; } | Records the visibility of each symbol . |
34,801 | @ SuppressWarnings ( "ReferenceEquality" ) private void createPropertyScopeFor ( Symbol s ) { if ( s . propertyScope != null ) { return ; } ObjectType type = getType ( s ) == null ? null : getType ( s ) . toObjectType ( ) ; if ( type == null ) { return ; } SymbolScope parentPropertyScope = maybeGetParentPropertyScope ( type ) ; s . setPropertyScope ( new SymbolScope ( null , parentPropertyScope , type , s ) ) ; ObjectType instanceType = type ; Iterable < String > propNames = type . getOwnPropertyNames ( ) ; if ( instanceType . isFunctionPrototypeType ( ) ) { if ( instanceType . getOwnerFunction ( ) . hasInstanceType ( ) ) { instanceType = instanceType . getOwnerFunction ( ) . getInstanceType ( ) ; propNames = Iterables . concat ( propNames , instanceType . getOwnPropertyNames ( ) ) ; } } for ( String propName : propNames ) { StaticSlot newProp = instanceType . getSlot ( propName ) ; if ( newProp . getDeclaration ( ) == null ) { continue ; } Symbol oldProp = symbols . get ( newProp . getDeclaration ( ) . getNode ( ) , s . getName ( ) + "." + propName ) ; if ( symbols . get ( newProp . getDeclaration ( ) . getNode ( ) , newProp . getName ( ) ) != null ) { if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Found duplicate symbol " + newProp ) ; } continue ; } Symbol newSym = copySymbolTo ( newProp , s . propertyScope ) ; if ( oldProp != null ) { if ( newSym . getJSDocInfo ( ) == null ) { newSym . setJSDocInfo ( oldProp . getJSDocInfo ( ) ) ; } newSym . setPropertyScope ( oldProp . propertyScope ) ; for ( Reference ref : oldProp . references . values ( ) ) { newSym . defineReferenceAt ( ref . getNode ( ) ) ; } removeSymbol ( oldProp ) ; } } } | This function uses == to compare types to be exact same instances . |
34,802 | private SymbolScope maybeGetParentPropertyScope ( ObjectType symbolObjectType ) { ObjectType proto = symbolObjectType . getImplicitPrototype ( ) ; if ( proto == null || proto == symbolObjectType ) { return null ; } final Symbol parentSymbol ; if ( isEs6ClassConstructor ( proto ) ) { parentSymbol = getSymbolDeclaredBy ( proto . toMaybeFunctionType ( ) ) ; } else if ( proto . getConstructor ( ) != null ) { parentSymbol = getSymbolForInstancesOf ( proto . getConstructor ( ) ) ; } else { return null ; } if ( parentSymbol == null ) { return null ; } createPropertyScopeFor ( parentSymbol ) ; return parentSymbol . getPropertyScope ( ) ; } | If this type has an implicit prototype set returns the SymbolScope corresponding to the properties of the implicit prototype . Otherwise returns null . |
34,803 | void fillSuperReferences ( Node externs , Node root ) { NodeTraversal . Callback collectSuper = new AbstractPostOrderCallback ( ) { public void visit ( NodeTraversal t , Node n , Node parent ) { if ( ! n . isSuper ( ) || n . getJSType ( ) == null ) { return ; } Symbol classSymbol = getSymbolForTypeHelper ( n . getJSType ( ) , false ) ; if ( classSymbol != null ) { classSymbol . defineReferenceAt ( n ) ; } } } ; NodeTraversal . traverseRoots ( compiler , collectSuper , externs , root ) ; } | Fill in references to super variables . |
34,804 | private boolean isSymbolDuplicatedExternOnWindow ( Symbol symbol ) { Node node = symbol . getDeclarationNode ( ) ; return ! node . isIndexable ( ) && node . isGetProp ( ) && node . getFirstChild ( ) . isName ( ) && node . getFirstChild ( ) . getString ( ) . equals ( "window" ) ; } | Heuristic method to check whether symbol was created by DeclaredGlobalExternsOnWindow . java pass . |
34,805 | private int getLexicalScopeDepth ( SymbolScope scope ) { if ( scope . isLexicalScope ( ) || scope . isDocScope ( ) ) { return scope . getScopeDepth ( ) ; } else { checkState ( scope . isPropertyScope ( ) ) ; Symbol sym = scope . getSymbolForScope ( ) ; checkNotNull ( sym ) ; return getLexicalScopeDepth ( getScope ( sym ) ) + 1 ; } } | For a lexical scope just returns the normal scope depth . |
34,806 | private void removeDuplicateDeclarations ( Node externs , Node root ) { Callback tickler = new ScopeTicklingCallback ( ) ; ScopeCreator scopeCreator = new Es6SyntacticScopeCreator ( compiler , new DuplicateDeclarationHandler ( ) ) ; NodeTraversal t = new NodeTraversal ( compiler , tickler , scopeCreator ) ; t . traverseRoots ( externs , root ) ; } | Remove duplicate VAR declarations . |
34,807 | private boolean isRemovableValue ( Node n ) { switch ( n . getToken ( ) ) { case TEMPLATELIT : case ARRAYLIT : for ( Node child = n . getFirstChild ( ) ; child != null ; child = child . getNext ( ) ) { if ( ( ! child . isEmpty ( ) ) && ! isRemovableValue ( child ) ) { return false ; } } return true ; case REGEXP : case STRING : case NUMBER : case NULL : case TRUE : case FALSE : case TEMPLATELIT_STRING : return true ; case TEMPLATELIT_SUB : case CAST : case NOT : case VOID : case NEG : return isRemovableValue ( n . getFirstChild ( ) ) ; default : return false ; } } | So we don t need to update the graph . |
34,808 | private void warnAboutNamespaceAliasing ( Name nameObj , Ref ref ) { compiler . report ( JSError . make ( ref . getNode ( ) , UNSAFE_NAMESPACE_WARNING , nameObj . getFullName ( ) ) ) ; } | Reports a warning because a namespace was aliased . |
34,809 | private void warnAboutNamespaceRedefinition ( Name nameObj , Ref ref ) { compiler . report ( JSError . make ( ref . getNode ( ) , NAMESPACE_REDEFINED_WARNING , nameObj . getFullName ( ) ) ) ; } | Reports a warning because a namespace was redefined . |
34,810 | private void flattenReferencesToCollapsibleDescendantNames ( Name n , String alias ) { if ( n . props == null || n . isCollapsingExplicitlyDenied ( ) ) { return ; } for ( Name p : n . props ) { String propAlias = appendPropForAlias ( alias , p . getBaseName ( ) ) ; boolean isAllowedToCollapse = propertyCollapseLevel != PropertyCollapseLevel . MODULE_EXPORT || p . isModuleExport ( ) ; if ( isAllowedToCollapse && p . canCollapse ( ) ) { flattenReferencesTo ( p , propAlias ) ; } else if ( isAllowedToCollapse && p . isSimpleStubDeclaration ( ) && ! p . isCollapsingExplicitlyDenied ( ) ) { flattenSimpleStubDeclaration ( p , propAlias ) ; } flattenReferencesToCollapsibleDescendantNames ( p , propAlias ) ; } } | Flattens all references to collapsible properties of a global name except their initial definitions . Recurs on subnames . |
34,811 | private void flattenSimpleStubDeclaration ( Name name , String alias ) { Ref ref = Iterables . getOnlyElement ( name . getRefs ( ) ) ; Node nameNode = NodeUtil . newName ( compiler , alias , ref . getNode ( ) , name . getFullName ( ) ) ; Node varNode = IR . var ( nameNode ) . useSourceInfoIfMissingFrom ( nameNode ) ; checkState ( ref . getNode ( ) . getParent ( ) . isExprResult ( ) ) ; Node parent = ref . getNode ( ) . getParent ( ) ; Node grandparent = parent . getParent ( ) ; grandparent . replaceChild ( parent , varNode ) ; compiler . reportChangeToEnclosingScope ( varNode ) ; } | Flattens a stub declaration . This is mostly a hack to support legacy users . |
34,812 | private void flattenReferencesTo ( Name n , String alias ) { String originalName = n . getFullName ( ) ; for ( Ref r : n . getRefs ( ) ) { if ( r == n . getDeclaration ( ) ) { continue ; } Node rParent = r . getNode ( ) . getParent ( ) ; if ( ! NodeUtil . mayBeObjectLitKey ( r . getNode ( ) ) && ( r . getTwin ( ) == null || r . isSet ( ) ) ) { flattenNameRef ( alias , r . getNode ( ) , rParent , originalName ) ; } else if ( r . getNode ( ) . isStringKey ( ) && r . getNode ( ) . getParent ( ) . isObjectPattern ( ) ) { Node newNode = IR . name ( alias ) . srcref ( r . getNode ( ) ) ; NodeUtil . copyNameAnnotations ( r . getNode ( ) , newNode ) ; DestructuringGlobalNameExtractor . reassignDestructringLvalue ( r . getNode ( ) , newNode , null , r , compiler ) ; } } if ( n . props != null ) { for ( Name p : n . props ) { flattenPrefixes ( alias , p , 1 ) ; } } } | Flattens all references to a collapsible property of a global name except its initial definition . |
34,813 | private void flattenPrefixes ( String alias , Name n , int depth ) { String originalName = n . getFullName ( ) ; Ref decl = n . getDeclaration ( ) ; if ( decl != null && decl . getNode ( ) != null && decl . getNode ( ) . isGetProp ( ) ) { flattenNameRefAtDepth ( alias , decl . getNode ( ) , depth , originalName ) ; } for ( Ref r : n . getRefs ( ) ) { if ( r == decl ) { continue ; } if ( r . getTwin ( ) == null || r . isSet ( ) ) { flattenNameRefAtDepth ( alias , r . getNode ( ) , depth , originalName ) ; } } if ( n . props != null ) { for ( Name p : n . props ) { flattenPrefixes ( alias , p , depth + 1 ) ; } } } | Flattens all occurrences of a name as a prefix of subnames beginning with a particular subname . |
34,814 | private void flattenNameRefAtDepth ( String alias , Node n , int depth , String originalName ) { Token nType = n . getToken ( ) ; boolean isQName = nType == Token . NAME || nType == Token . GETPROP ; boolean isObjKey = NodeUtil . mayBeObjectLitKey ( n ) ; checkState ( isObjKey || isQName ) ; if ( isQName ) { for ( int i = 1 ; i < depth && n . hasChildren ( ) ; i ++ ) { n = n . getFirstChild ( ) ; } if ( n . isGetProp ( ) && n . getFirstChild ( ) . isGetProp ( ) ) { flattenNameRef ( alias , n . getFirstChild ( ) , n , originalName ) ; } } } | Flattens a particular prefix of a single name reference . |
34,815 | private void collapseDeclarationOfNameAndDescendants ( Name n , String alias ) { boolean canCollapseChildNames = n . canCollapseUnannotatedChildNames ( ) ; if ( canCollapse ( n ) ) { updateGlobalNameDeclaration ( n , alias , canCollapseChildNames ) ; } if ( n . props == null ) { return ; } for ( Name p : n . props ) { collapseDeclarationOfNameAndDescendants ( p , appendPropForAlias ( alias , p . getBaseName ( ) ) ) ; } } | Collapses definitions of the collapsible properties of a global name . Recurs on subnames that also represent JavaScript objects with collapsible properties . |
34,816 | private void checkForHosedThisReferences ( Node function , JSDocInfo docInfo , final Name name ) { boolean isAllowedToReferenceThis = ( docInfo != null && ( docInfo . isConstructorOrInterface ( ) || docInfo . hasThisType ( ) ) ) || function . isArrowFunction ( ) ; if ( ! isAllowedToReferenceThis ) { NodeTraversal . traverse ( compiler , function . getLastChild ( ) , new NodeTraversal . AbstractShallowCallback ( ) { public void visit ( NodeTraversal t , Node n , Node parent ) { if ( n . isThis ( ) ) { compiler . report ( JSError . make ( n , UNSAFE_THIS , name . getFullName ( ) ) ) ; } } } ) ; } } | Warns about any references to this in the given FUNCTION . The function is getting collapsed so the references will change . |
34,817 | private void declareVariablesForObjLitValues ( Name objlitName , String alias , Node objlit , Node varNode , Node nameToAddAfter , Node varParent ) { int arbitraryNameCounter = 0 ; boolean discardKeys = ! objlitName . shouldKeepKeys ( ) ; for ( Node key = objlit . getFirstChild ( ) , nextKey ; key != null ; key = nextKey ) { Node value = key . getFirstChild ( ) ; nextKey = key . getNext ( ) ; switch ( key . getToken ( ) ) { case GETTER_DEF : case SETTER_DEF : case COMPUTED_PROP : case SPREAD : continue ; case STRING_KEY : case MEMBER_FUNCTION_DEF : break ; default : throw new IllegalStateException ( "Unexpected child of OBJECTLIT: " + key . toStringTree ( ) ) ; } boolean isJsIdentifier = ! key . isNumber ( ) && TokenStream . isJSIdentifier ( key . getString ( ) ) ; String propName = isJsIdentifier ? key . getString ( ) : String . valueOf ( ++ arbitraryNameCounter ) ; String qName = objlitName . getFullName ( ) + '.' + propName ; Name p = nameMap . get ( qName ) ; if ( p != null && ! canCollapse ( p ) ) { continue ; } String propAlias = appendPropForAlias ( alias , propName ) ; Node refNode = null ; if ( discardKeys ) { objlit . removeChild ( key ) ; value . detach ( ) ; } else { refNode = IR . name ( propAlias ) ; if ( key . getBooleanProp ( Node . IS_CONSTANT_NAME ) ) { refNode . putBooleanProp ( Node . IS_CONSTANT_NAME , true ) ; } key . replaceChild ( value , refNode ) ; compiler . reportChangeToEnclosingScope ( refNode ) ; } Node nameNode = IR . name ( propAlias ) ; nameNode . addChildToFront ( value ) ; if ( key . getBooleanProp ( Node . IS_CONSTANT_NAME ) ) { nameNode . putBooleanProp ( Node . IS_CONSTANT_NAME , true ) ; } Node newVar = IR . var ( nameNode ) . useSourceInfoIfMissingFromForTree ( key ) ; if ( nameToAddAfter != null ) { varParent . addChildAfter ( newVar , nameToAddAfter ) ; } else { varParent . addChildBefore ( newVar , varNode ) ; } compiler . reportChangeToEnclosingScope ( newVar ) ; nameToAddAfter = newVar ; if ( isJsIdentifier && p != null ) { if ( ! discardKeys ) { p . addAliasingGetClonedFromDeclaration ( refNode ) ; } p . updateRefNode ( p . getDeclaration ( ) , nameNode ) ; if ( value . isFunction ( ) ) { checkForHosedThisReferences ( value , key . getJSDocInfo ( ) , p ) ; } } } } | Declares global variables to serve as aliases for the values in an object literal optionally removing all of the object literal s keys and values . |
34,818 | private void addStubsForUndeclaredProperties ( Name n , String alias , Node parent , Node addAfter ) { checkState ( n . canCollapseUnannotatedChildNames ( ) , n ) ; checkArgument ( NodeUtil . isStatementBlock ( parent ) , parent ) ; checkNotNull ( addAfter ) ; if ( n . props == null ) { return ; } for ( Name p : n . props ) { if ( p . needsToBeStubbed ( ) ) { String propAlias = appendPropForAlias ( alias , p . getBaseName ( ) ) ; Node nameNode = IR . name ( propAlias ) ; Node newVar = IR . var ( nameNode ) . useSourceInfoIfMissingFromForTree ( addAfter ) ; parent . addChildAfter ( newVar , addAfter ) ; addAfter = newVar ; compiler . reportChangeToEnclosingScope ( newVar ) ; if ( p . getFirstRef ( ) . getNode ( ) . getLastChild ( ) . getBooleanProp ( Node . IS_CONSTANT_NAME ) ) { nameNode . putBooleanProp ( Node . IS_CONSTANT_NAME , true ) ; compiler . reportChangeToEnclosingScope ( nameNode ) ; } } } } | Adds global variable stubs for any properties of a global name that are only set in a local scope or read but never set . |
34,819 | protected void report ( DiagnosticType diagnostic , Node n ) { JSError error = JSError . make ( n , diagnostic , n . toString ( ) ) ; compiler . report ( error ) ; } | Helper method for reporting an error to the compiler when applying a peephole optimization . |
34,820 | protected boolean areNodesEqualForInlining ( Node n1 , Node n2 ) { checkNotNull ( compiler ) ; return compiler . areNodesEqualForInlining ( n1 , n2 ) ; } | Are the nodes equal for the purpose of inlining? If type aware optimizations are on type equality is checked . |
34,821 | @ JsMethod ( name = "getClassJsDoc" , namespace = "jscomp" ) public static String getClassJsDoc ( String jsDoc ) { if ( Strings . isNullOrEmpty ( jsDoc ) ) { return null ; } Config config = Config . builder ( ) . setLanguageMode ( LanguageMode . ECMASCRIPT3 ) . setStrictMode ( Config . StrictMode . SLOPPY ) . setJsDocParsingMode ( JsDocParsing . INCLUDE_DESCRIPTIONS_WITH_WHITESPACE ) . build ( ) ; JsDocInfoParser parser = new JsDocInfoParser ( new JsDocTokenStream ( jsDoc . substring ( 3 ) ) , jsDoc , 0 , null , config , ErrorReporter . NULL_INSTANCE ) ; parser . parse ( ) ; JSDocInfo parsed = parser . retrieveAndResetParsedJSDocInfo ( ) ; JSDocInfo classComments = parsed . cloneClassDoc ( ) ; JSDocInfoPrinter printer = new JSDocInfoPrinter ( true , true ) ; String comment = printer . print ( classComments ) ; if ( comment == null || RegExp . compile ( "\\s*/\\*\\*\\s*\\*/\\s*" ) . test ( comment ) ) { return null ; } return comment . trim ( ) ; } | Gets JS Doc that should be retained on a class . Used to upgrade ES5 to ES6 classes and separate class from constructor comments . |
34,822 | @ JsMethod ( name = "getConstructorJsDoc" , namespace = "jscomp" ) public static String getConstructorJsDoc ( String jsDoc ) { if ( Strings . isNullOrEmpty ( jsDoc ) ) { return null ; } Config config = Config . builder ( ) . setLanguageMode ( LanguageMode . ECMASCRIPT3 ) . setStrictMode ( Config . StrictMode . SLOPPY ) . setJsDocParsingMode ( JsDocParsing . INCLUDE_DESCRIPTIONS_WITH_WHITESPACE ) . build ( ) ; JsDocInfoParser parser = new JsDocInfoParser ( new JsDocTokenStream ( jsDoc . substring ( 3 ) ) , jsDoc , 0 , null , config , ErrorReporter . NULL_INSTANCE ) ; parser . parse ( ) ; JSDocInfo parsed = parser . retrieveAndResetParsedJSDocInfo ( ) ; JSDocInfo params = parsed . cloneConstructorDoc ( ) ; if ( parsed . getParameterNames ( ) . isEmpty ( ) && parsed . getSuppressions ( ) . isEmpty ( ) ) { return null ; } JSDocInfoPrinter printer = new JSDocInfoPrinter ( true , true ) ; return printer . print ( params ) . trim ( ) ; } | Gets JS Doc that should be moved to a constructor . Used to upgrade ES5 to ES6 classes and separate class from constructor comments . |
34,823 | public ImmutableList < Require > getRequires ( ) { if ( hasFullParseDependencyInfo ) { return ImmutableList . copyOf ( orderedRequires ) ; } return getDependencyInfo ( ) . getRequires ( ) ; } | Gets a list of types depended on by this input . |
34,824 | ImmutableCollection < Require > getKnownRequires ( ) { return concat ( dependencyInfo != null ? dependencyInfo . getRequires ( ) : ImmutableList . of ( ) , extraRequires ) ; } | Gets a list of namespaces and paths depended on by this input but does not attempt to regenerate the dependency information . Typically this occurs from module rewriting . |
34,825 | ImmutableCollection < String > getKnownProvides ( ) { return concat ( dependencyInfo != null ? dependencyInfo . getProvides ( ) : ImmutableList . < String > of ( ) , extraProvides ) ; } | Gets a list of types provided but does not attempt to regenerate the dependency information . Typically this occurs from module rewriting . |
34,826 | public boolean addOrderedRequire ( Require require ) { if ( ! orderedRequires . contains ( require ) ) { orderedRequires . add ( require ) ; return true ; } return false ; } | Registers a type that this input depends on in the order seen in the file . |
34,827 | public boolean addDynamicRequire ( String require ) { if ( ! dynamicRequires . contains ( require ) ) { dynamicRequires . add ( require ) ; return true ; } return false ; } | Registers a type that this input depends on in the order seen in the file . The type was loaded dynamically so while it is part of the dependency graph it does not need sorted before this input . |
34,828 | DependencyInfo getDependencyInfo ( ) { if ( dependencyInfo == null ) { dependencyInfo = generateDependencyInfo ( ) ; } if ( ! extraRequires . isEmpty ( ) || ! extraProvides . isEmpty ( ) ) { dependencyInfo = SimpleDependencyInfo . builder ( getName ( ) , getName ( ) ) . setProvides ( concat ( dependencyInfo . getProvides ( ) , extraProvides ) ) . setRequires ( concat ( dependencyInfo . getRequires ( ) , extraRequires ) ) . setTypeRequires ( dependencyInfo . getTypeRequires ( ) ) . setLoadFlags ( dependencyInfo . getLoadFlags ( ) ) . setHasExternsAnnotation ( dependencyInfo . getHasExternsAnnotation ( ) ) . setHasNoCompileAnnotation ( dependencyInfo . getHasNoCompileAnnotation ( ) ) . build ( ) ; extraRequires . clear ( ) ; extraProvides . clear ( ) ; } return dependencyInfo ; } | Returns the DependencyInfo object generating it lazily if necessary . |
34,829 | public void setModule ( JSModule module ) { checkArgument ( module == null || this . module == null || this . module == module ) ; this . module = module ; } | Sets the module to which the input belongs . |
34,830 | private boolean isUnextendableNativeClass ( NodeTraversal t , String className ) { switch ( className ) { case "Array" : case "ArrayBuffer" : case "Boolean" : case "DataView" : case "Date" : case "Float32Array" : case "Function" : case "Generator" : case "GeneratorFunction" : case "Int16Array" : case "Int32Array" : case "Int8Array" : case "InternalError" : case "Map" : case "Number" : case "Promise" : case "Proxy" : case "RegExp" : case "Set" : case "String" : case "Symbol" : case "TypedArray" : case "Uint16Array" : case "Uint32Array" : case "Uint8Array" : case "Uint8ClampedArray" : case "WeakMap" : case "WeakSet" : return ! isDefinedInSources ( t , className ) ; default : return false ; } } | Is the given class a native class for which we cannot properly transpile extension? |
34,831 | private boolean isDefinedInSources ( NodeTraversal t , String varName ) { Var objectVar = t . getScope ( ) . getVar ( varName ) ; return objectVar != null && ! objectVar . isExtern ( ) ; } | Is a variable with the given name defined in the source code being compiled? |
34,832 | static MinimizedCondition fromConditionNode ( Node n ) { checkState ( n . getParent ( ) != null ) ; switch ( n . getToken ( ) ) { case NOT : case AND : case OR : case HOOK : case COMMA : return computeMinimizedCondition ( n ) ; default : return unoptimized ( n ) ; } } | Returns a MinimizedCondition that represents the condition node after minimization . |
34,833 | static MeasuredNode pickBest ( MeasuredNode a , MeasuredNode b ) { if ( a . length == b . length ) { return ( b . isChanged ( ) ) ? a : b ; } return ( a . length < b . length ) ? a : b ; } | return the best prefer unchanged |
34,834 | private static MinimizedCondition computeMinimizedCondition ( Node n ) { switch ( n . getToken ( ) ) { case NOT : { MinimizedCondition subtree = computeMinimizedCondition ( n . getFirstChild ( ) ) ; MeasuredNode positive = pickBest ( MeasuredNode . addNode ( n , subtree . positive ) , subtree . negative ) ; MeasuredNode negative = pickBest ( subtree . negative . negate ( ) , subtree . positive ) ; return new MinimizedCondition ( positive , negative ) ; } case AND : case OR : { Node complementNode = new Node ( n . getToken ( ) == Token . AND ? Token . OR : Token . AND ) . srcref ( n ) ; MinimizedCondition leftSubtree = computeMinimizedCondition ( n . getFirstChild ( ) ) ; MinimizedCondition rightSubtree = computeMinimizedCondition ( n . getLastChild ( ) ) ; MeasuredNode positive = pickBest ( MeasuredNode . addNode ( n , leftSubtree . positive , rightSubtree . positive ) , MeasuredNode . addNode ( complementNode , leftSubtree . negative , rightSubtree . negative ) . negate ( ) ) ; MeasuredNode negative = pickBest ( MeasuredNode . addNode ( n , leftSubtree . positive , rightSubtree . positive ) . negate ( ) , MeasuredNode . addNode ( complementNode , leftSubtree . negative , rightSubtree . negative ) . change ( ) ) ; return new MinimizedCondition ( positive , negative ) ; } case HOOK : { Node cond = n . getFirstChild ( ) ; Node thenNode = cond . getNext ( ) ; Node elseNode = thenNode . getNext ( ) ; MinimizedCondition thenSubtree = computeMinimizedCondition ( thenNode ) ; MinimizedCondition elseSubtree = computeMinimizedCondition ( elseNode ) ; MeasuredNode positive = MeasuredNode . addNode ( n , MeasuredNode . forNode ( cond ) , thenSubtree . positive , elseSubtree . positive ) ; MeasuredNode negative = MeasuredNode . addNode ( n , MeasuredNode . forNode ( cond ) , thenSubtree . negative , elseSubtree . negative ) ; return new MinimizedCondition ( positive , negative ) ; } case COMMA : { Node lhs = n . getFirstChild ( ) ; MinimizedCondition rhsSubtree = computeMinimizedCondition ( lhs . getNext ( ) ) ; MeasuredNode positive = MeasuredNode . addNode ( n , MeasuredNode . forNode ( lhs ) , rhsSubtree . positive ) ; MeasuredNode negative = MeasuredNode . addNode ( n , MeasuredNode . forNode ( lhs ) , rhsSubtree . negative ) ; return new MinimizedCondition ( positive , negative ) ; } default : { MeasuredNode pos = MeasuredNode . forNode ( n ) ; MeasuredNode neg = pos . negate ( ) ; return new MinimizedCondition ( pos , neg ) ; } } } | Minimize the condition at the given node . |
34,835 | static Node withType ( Node n , JSType t ) { if ( t != null ) { n . setJSType ( t ) ; } return n ; } | Adds the type t to Node n and returns n . Does nothing if t is null . |
34,836 | static JSType createType ( boolean shouldCreate , JSTypeRegistry registry , JSTypeNative typeName ) { if ( ! shouldCreate ) { return null ; } return registry . getNativeType ( typeName ) ; } | Returns the JSType as specified by the typeName . Returns null if shouldCreate is false . |
34,837 | static JSType createGenericType ( boolean shouldCreate , JSTypeRegistry registry , JSTypeNative typeName , JSType typeArg ) { if ( ! shouldCreate ) { return null ; } ObjectType genericType = ( ObjectType ) ( registry . getNativeType ( typeName ) ) ; ObjectType uninstantiated = genericType . getRawType ( ) ; return registry . instantiateGenericType ( uninstantiated , ImmutableList . of ( typeArg ) ) ; } | Returns the JSType as specified by the typeName and instantiated by the typeArg . Returns null if shouldCreate is false . |
34,838 | private void addToUseIfLocal ( String name , Node node , ReachingUses use ) { Var var = allVarsInFn . get ( name ) ; if ( var == null ) { return ; } if ( ! escaped . contains ( var ) ) { use . mayUseMap . put ( var , node ) ; } } | Sets the variable for the given name to the node value in the upward exposed lattice . Do nothing if the variable name is one of the escaped variable . |
34,839 | private void removeFromUseIfLocal ( String name , ReachingUses use ) { Var var = allVarsInFn . get ( name ) ; if ( var == null ) { return ; } if ( ! escaped . contains ( var ) ) { use . mayUseMap . removeAll ( var ) ; } } | Removes the variable for the given name from the node value in the upward exposed lattice . Do nothing if the variable name is one of the escaped variable . |
34,840 | static final JSType getTemplateTypeOfThenable ( JSTypeRegistry registry , JSType maybeThenable ) { return maybeThenable . restrictByNotNullOrUndefined ( ) . getInstantiatedTypeArgument ( registry . getNativeType ( JSTypeNative . I_THENABLE_TYPE ) ) ; } | If this object is known to be an IThenable returns the type it resolves to . |
34,841 | static final JSType wrapInIThenable ( JSTypeRegistry registry , JSType maybeThenable ) { JSType unwrapped = getResolvedType ( registry , maybeThenable ) ; return registry . createTemplatizedType ( registry . getNativeObjectType ( JSTypeNative . I_THENABLE_TYPE ) , unwrapped ) ; } | Wraps the given type in an IThenable . |
34,842 | private static String formatOutput ( String js , boolean export ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "(function(window){" ) ; output . append ( "var $wnd=" ) . append ( export ? "this" : "{'Error':{}}" ) . append ( ";" ) ; output . append ( "var $doc={},$moduleName,$moduleBase;" ) ; output . append ( js ) ; output . append ( "this['$gwtExport']=$wnd;$wnd=this;typeof gwtOnLoad==='function'&&gwtOnLoad()" ) ; String globalObject = "this&&this.self||" + "(typeof window!=='undefined'?window:(typeof global!=='undefined'?global:this))" ; output . append ( "}).call(" ) . append ( globalObject ) . append ( "," ) . append ( globalObject ) . append ( ");" ) ; return output . toString ( ) ; } | Formats the application s JS code for output . |
34,843 | public static CharRanges withRanges ( int ... ranges ) { if ( ( ranges . length & 1 ) != 0 ) { throw new IllegalArgumentException ( ) ; } for ( int i = 1 ; i < ranges . length ; ++ i ) { if ( ranges [ i ] <= ranges [ i - 1 ] ) { throw new IllegalArgumentException ( ranges [ i ] + " > " + ranges [ i - 1 ] ) ; } } return new CharRanges ( ranges ) ; } | Returns an instance containing the given ranges . |
34,844 | static boolean isStartOfIcuMessage ( String part ) { if ( ! part . startsWith ( "{" ) ) { return false ; } int commaIndex = part . indexOf ( ',' , 1 ) ; if ( commaIndex <= 1 ) { return false ; } int nextBracketIndex = part . indexOf ( '{' , 1 ) ; return ( nextBracketIndex == - 1 || nextBracketIndex > commaIndex ) && ( part . startsWith ( "plural," , commaIndex + 1 ) || part . startsWith ( "select," , commaIndex + 1 ) ) ; } | Detects an ICU - formatted plural or select message . Any placeholders occurring inside these messages must be rewritten in ICU format . |
34,845 | private static SAXParser createSAXParser ( ) throws ParserConfigurationException , SAXException { SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setValidating ( false ) ; factory . setXIncludeAware ( false ) ; factory . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; factory . setFeature ( "http://xml.org/sax/features/external-parameter-entities" , false ) ; factory . setFeature ( "http://apache.org/xml/features/nonvalidating/load-external-dtd" , false ) ; factory . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; SAXParser parser = factory . newSAXParser ( ) ; XMLReader xmlReader = parser . getXMLReader ( ) ; xmlReader . setEntityResolver ( NOOP_RESOLVER ) ; return parser ; } | Inlined from guava - internal . |
34,846 | protected String locate ( String scriptAddress , String name ) { String canonicalizedPath = canonicalizePath ( scriptAddress , name ) ; String normalizedPath = canonicalizedPath ; if ( ModuleLoader . isAmbiguousIdentifier ( canonicalizedPath ) ) { normalizedPath = ModuleLoader . MODULE_SLASH + canonicalizedPath ; } if ( modulePaths . contains ( normalizedPath ) ) { return canonicalizedPath ; } for ( String rootPath : moduleRootPaths ) { String modulePath = rootPath + normalizedPath ; if ( modulePaths . contains ( modulePath ) ) { return canonicalizedPath ; } } return null ; } | Locates the module with the given name but returns null if there is no JS file in the expected location . |
34,847 | static Binding from ( Export boundExport , Node sourceNode ) { return new AutoValue_Binding ( boundExport . moduleMetadata ( ) , sourceNode , boundExport , false , null , CreatedBy . EXPORT ) ; } | Binding for an exported value that is not a module namespace object . |
34,848 | Binding copy ( Node sourceNode , CreatedBy createdBy ) { checkNotNull ( sourceNode ) ; return new AutoValue_Binding ( metadata ( ) , sourceNode , originatingExport ( ) , isModuleNamespace ( ) , closureNamespace ( ) , createdBy ) ; } | Copies the binding with a new source node and CreatedBy binding . |
34,849 | void reportError ( Node n , Var var , String name ) { JSDocInfo info = NodeUtil . getBestJSDocInfo ( n ) ; if ( info == null || ! info . getSuppressions ( ) . contains ( "const" ) ) { Node declNode = var . getNode ( ) ; String declaredPosition = declNode . getSourceFileName ( ) + ":" + declNode . getLineno ( ) ; compiler . report ( JSError . make ( n , CONST_REASSIGNED_VALUE_ERROR , name , declaredPosition ) ) ; } } | Reports a reassigned constant error . |
34,850 | static final JSType getElementType ( JSType iterableOrIterator , JSTypeRegistry typeRegistry ) { TemplateTypeMap templateTypeMap = iterableOrIterator . autobox ( ) . getTemplateTypeMap ( ) ; if ( templateTypeMap . hasTemplateKey ( typeRegistry . getIterableTemplate ( ) ) ) { return templateTypeMap . getResolvedTemplateType ( typeRegistry . getIterableTemplate ( ) ) ; } else if ( templateTypeMap . hasTemplateKey ( typeRegistry . getIteratorTemplate ( ) ) ) { return templateTypeMap . getResolvedTemplateType ( typeRegistry . getIteratorTemplate ( ) ) ; } else if ( templateTypeMap . hasTemplateKey ( typeRegistry . getAsyncIterableTemplate ( ) ) ) { return templateTypeMap . getResolvedTemplateType ( typeRegistry . getAsyncIterableTemplate ( ) ) ; } else if ( templateTypeMap . hasTemplateKey ( typeRegistry . getAsyncIteratorTemplate ( ) ) ) { return templateTypeMap . getResolvedTemplateType ( typeRegistry . getAsyncIteratorTemplate ( ) ) ; } return typeRegistry . getNativeType ( UNKNOWN_TYPE ) ; } | Returns the given Iterable s element type . |
34,851 | void putBranchNode ( int lineNumber , int branchNumber , Node block ) { Preconditions . checkArgument ( lineNumber > 0 , "Expected non-zero positive integer as line number: %s" , lineNumber ) ; Preconditions . checkArgument ( branchNumber > 0 , "Expected non-zero positive integer as branch number: %s" , branchNumber ) ; branchNodes . put ( BranchIndexPair . of ( lineNumber - 1 , branchNumber - 1 ) , block ) ; } | Store a node to be instrumented later for branch coverage . |
34,852 | Node getBranchNode ( int lineNumber , int branchNumber ) { Preconditions . checkArgument ( lineNumber > 0 , "Expected non-zero positive integer as line number: %s" , lineNumber ) ; Preconditions . checkArgument ( branchNumber > 0 , "Expected non-zero positive integer as branch number: %s" , branchNumber ) ; return branchNodes . get ( BranchIndexPair . of ( lineNumber - 1 , branchNumber - 1 ) ) ; } | Get the block node to be instrumented for branch coverage . |
34,853 | void addBranches ( int lineNumber , int numberOfBranches ) { int lineIdx = lineNumber - 1 ; Integer currentValue = branchesInLine . get ( Integer . valueOf ( lineIdx ) ) ; if ( currentValue == null ) { branchesInLine . put ( lineIdx , numberOfBranches ) ; } else { branchesInLine . put ( lineIdx , currentValue + numberOfBranches ) ; } } | Add a number of branches to a line . |
34,854 | int getNumBranches ( int lineNumber ) { Integer numBranches = branchesInLine . get ( lineNumber - 1 ) ; if ( numBranches == null ) { return 0 ; } else { return numBranches ; } } | Get the number of branches on a line |
34,855 | private static void populateDefaults ( JSDocInfo info ) { if ( info . getVisibility ( ) == null ) { info . setVisibility ( Visibility . INHERITED ) ; } } | Generate defaults when certain parameters are not specified . |
34,856 | public void markAnnotation ( String annotation , int lineno , int charno ) { JSDocInfo . Marker marker = currentInfo . addMarker ( ) ; if ( marker != null ) { JSDocInfo . TrimmedStringPosition position = new JSDocInfo . TrimmedStringPosition ( ) ; position . setItem ( annotation ) ; position . setPositionInformation ( lineno , charno , lineno , charno + annotation . length ( ) ) ; marker . setAnnotation ( position ) ; populated = true ; } currentMarker = marker ; } | Adds a marker to the current JSDocInfo and populates the marker with the annotation information . |
34,857 | public void markText ( String text , int startLineno , int startCharno , int endLineno , int endCharno ) { if ( currentMarker != null ) { JSDocInfo . StringPosition position = new JSDocInfo . StringPosition ( ) ; position . setItem ( text ) ; position . setPositionInformation ( startLineno , startCharno , endLineno , endCharno ) ; currentMarker . setDescription ( position ) ; } } | Adds a textual block to the current marker . |
34,858 | public void markTypeNode ( Node typeNode , int lineno , int startCharno , int endLineno , int endCharno , boolean hasLC ) { if ( currentMarker != null ) { JSDocInfo . TypePosition position = new JSDocInfo . TypePosition ( ) ; position . setItem ( typeNode ) ; position . setHasBrackets ( hasLC ) ; position . setPositionInformation ( lineno , startCharno , endLineno , endCharno ) ; currentMarker . setType ( position ) ; } } | Adds a type declaration to the current marker . |
34,859 | public void markName ( String name , Node templateNode , int lineno , int charno ) { if ( currentMarker != null ) { JSDocInfo . TrimmedStringPosition position = new JSDocInfo . TrimmedStringPosition ( ) ; position . setItem ( name ) ; position . setPositionInformation ( lineno , charno , lineno , charno + name . length ( ) ) ; JSDocInfo . NamePosition nodePos = new JSDocInfo . NamePosition ( ) ; Node node = Node . newString ( Token . NAME , name , lineno , charno ) ; node . setLength ( name . length ( ) ) ; if ( templateNode != null ) { node . setStaticSourceFileFrom ( templateNode ) ; } nodePos . setItem ( node ) ; nodePos . setPositionInformation ( lineno , charno , lineno , charno + name . length ( ) ) ; currentMarker . setNameNode ( nodePos ) ; } } | Adds a name declaration to the current marker . |
34,860 | public boolean recordVisibility ( Visibility visibility ) { if ( currentInfo . getVisibility ( ) == null ) { populated = true ; currentInfo . setVisibility ( visibility ) ; return true ; } else { return false ; } } | Records a visibility . |
34,861 | public boolean recordParameter ( String parameterName , JSTypeExpression type ) { if ( ! hasAnySingletonTypeTags ( ) && currentInfo . declareParam ( type , parameterName ) ) { populated = true ; return true ; } else { return false ; } } | Records a typed parameter . |
34,862 | public boolean recordParameterDescription ( String parameterName , String description ) { if ( currentInfo . documentParam ( parameterName , description ) ) { populated = true ; return true ; } else { return false ; } } | Records a parameter s description . |
34,863 | public boolean recordTemplateTypeName ( String name ) { if ( currentInfo . declareTemplateTypeName ( name ) ) { populated = true ; return true ; } else { return false ; } } | Records a template type name . |
34,864 | public boolean recordTypeTransformation ( String name , Node expr ) { if ( currentInfo . declareTypeTransformation ( name , expr ) ) { populated = true ; return true ; } else { return false ; } } | Records a type transformation expression together with its template type name . |
34,865 | public boolean recordThrowType ( JSTypeExpression type ) { if ( type != null && ! hasAnySingletonTypeTags ( ) ) { currentInfo . declareThrows ( type ) ; populated = true ; return true ; } return false ; } | Records a thrown type . |
34,866 | public boolean recordThrowDescription ( JSTypeExpression type , String description ) { if ( currentInfo . documentThrows ( type , description ) ) { populated = true ; return true ; } else { return false ; } } | Records a throw type s description . |
34,867 | public boolean addAuthor ( String author ) { if ( currentInfo . documentAuthor ( author ) ) { populated = true ; return true ; } else { return false ; } } | Adds an author to the current information . |
34,868 | public boolean addReference ( String reference ) { if ( currentInfo . documentReference ( reference ) ) { populated = true ; return true ; } else { return false ; } } | Adds a reference ( |
34,869 | public boolean recordVersion ( String version ) { if ( currentInfo . documentVersion ( version ) ) { populated = true ; return true ; } else { return false ; } } | Records the version . |
34,870 | public boolean recordDeprecationReason ( String reason ) { if ( currentInfo . setDeprecationReason ( reason ) ) { populated = true ; return true ; } else { return false ; } } | Records the deprecation reason . |
34,871 | public boolean recordModifies ( Set < String > modifies ) { if ( ! hasAnySingletonSideEffectTags ( ) && currentInfo . setModifies ( modifies ) ) { populated = true ; return true ; } else { return false ; } } | Records the list of modifies warnings . |
34,872 | public boolean recordType ( JSTypeExpression type ) { if ( type != null && ! hasAnyTypeRelatedTags ( ) ) { currentInfo . setType ( type ) ; populated = true ; return true ; } else { return false ; } } | Records a type . |
34,873 | public boolean recordReturnType ( JSTypeExpression jsType ) { if ( jsType != null && currentInfo . getReturnType ( ) == null && ! hasAnySingletonTypeTags ( ) ) { currentInfo . setReturnType ( jsType ) ; populated = true ; return true ; } else { return false ; } } | Records a return type . |
34,874 | public boolean recordReturnDescription ( String description ) { if ( currentInfo . documentReturn ( description ) ) { populated = true ; return true ; } else { return false ; } } | Records a return description |
34,875 | public boolean recordDefineType ( JSTypeExpression type ) { if ( type != null && ! currentInfo . isConstant ( ) && ! currentInfo . isDefine ( ) && recordType ( type ) ) { currentInfo . setDefine ( true ) ; populated = true ; return true ; } else { return false ; } } | Records the type of a define . |
34,876 | public boolean recordEnumParameterType ( JSTypeExpression type ) { if ( type != null && ! hasAnyTypeRelatedTags ( ) ) { currentInfo . setEnumParameterType ( type ) ; populated = true ; return true ; } else { return false ; } } | Records a parameter type to an enum . |
34,877 | public boolean recordBaseType ( JSTypeExpression jsType ) { if ( jsType != null && ! hasAnySingletonTypeTags ( ) && ! currentInfo . hasBaseType ( ) ) { currentInfo . setBaseType ( jsType ) ; populated = true ; return true ; } else { return false ; } } | Records a base type . |
34,878 | public boolean changeBaseType ( JSTypeExpression jsType ) { if ( jsType != null && ! hasAnySingletonTypeTags ( ) ) { currentInfo . setBaseType ( jsType ) ; populated = true ; return true ; } else { return false ; } } | Changes a base type even if one has already been set on currentInfo . |
34,879 | public boolean recordClosurePrimitiveId ( String closurePrimitiveId ) { if ( closurePrimitiveId != null && currentInfo . getClosurePrimitiveId ( ) == null ) { currentInfo . setClosurePrimitiveId ( closurePrimitiveId ) ; populated = true ; return true ; } else { return false ; } } | Records an identifier for a Closure Primitive . function . |
34,880 | public boolean recordFileOverview ( String description ) { if ( currentInfo . documentFileOverview ( description ) ) { populated = true ; return true ; } else { return false ; } } | Records a fileoverview description . |
34,881 | public boolean recordImplementedInterface ( JSTypeExpression interfaceName ) { if ( interfaceName != null && currentInfo . addImplementedInterface ( interfaceName ) ) { populated = true ; return true ; } else { return false ; } } | Records an implemented interface . |
34,882 | public boolean recordExtendedInterface ( JSTypeExpression interfaceType ) { if ( interfaceType != null && currentInfo . addExtendedInterface ( interfaceType ) ) { populated = true ; return true ; } else { return false ; } } | Records an extended interface type . |
34,883 | public boolean recordLends ( JSTypeExpression name ) { if ( ! hasAnyTypeRelatedTags ( ) ) { currentInfo . setLendsName ( name ) ; populated = true ; return true ; } else { return false ; } } | Records that we re lending to another name . |
34,884 | public boolean recordDisposesParameter ( List < String > parameterNames ) { for ( String parameterName : parameterNames ) { if ( ( currentInfo . hasParameter ( parameterName ) || parameterName . equals ( "*" ) ) && currentInfo . setDisposedParameter ( parameterName ) ) { populated = true ; } else { return false ; } } return true ; } | Records a parameter that gets disposed . |
34,885 | private void reusePreviouslyUsedVariableMap ( SortedSet < Assignment > varsToRename ) { checkNotNull ( prevUsedRenameMap . getNewNameToOriginalNameMap ( ) ) ; for ( Assignment a : varsToRename ) { String prevNewName = prevUsedRenameMap . lookupNewName ( a . oldName ) ; if ( prevNewName == null || reservedNames . contains ( prevNewName ) ) { continue ; } if ( a . isLocal || ( ! externNames . contains ( a . oldName ) && prevNewName . startsWith ( prefix ) ) ) { reservedNames . add ( prevNewName ) ; finalizeNameAssignment ( a , prevNewName ) ; } } } | Runs through the assignments and reuses as many names as possible from the previously used variable map . Updates reservedNames with the set of names that were reused . |
34,886 | private void assignNames ( SortedSet < Assignment > varsToRename ) { NameGenerator globalNameGenerator = null ; NameGenerator localNameGenerator = null ; globalNameGenerator = nameGenerator ; nameGenerator . reset ( reservedNames , prefix , reservedCharacters ) ; localNameGenerator = prefix . isEmpty ( ) ? globalNameGenerator : nameGenerator . clone ( reservedNames , "" , reservedCharacters ) ; List < Assignment > pendingAssignments = new ArrayList < > ( ) ; List < String > generatedNamesForAssignments = new ArrayList < > ( ) ; for ( Assignment a : varsToRename ) { if ( a . newName != null ) { continue ; } if ( externNames . contains ( a . oldName ) ) { continue ; } String newName ; if ( a . isLocal ) { newName = localNameGenerator . generateNextName ( ) ; finalizeNameAssignment ( a , newName ) ; } else { newName = globalNameGenerator . generateNextName ( ) ; pendingAssignments . add ( a ) ; generatedNamesForAssignments . add ( newName ) ; } reservedNames . add ( newName ) ; } int numPendingAssignments = generatedNamesForAssignments . size ( ) ; for ( int i = 0 ; i < numPendingAssignments ; ) { SortedSet < Assignment > varsByOrderOfOccurrence = new TreeSet < > ( ORDER_OF_OCCURRENCE_COMPARATOR ) ; int len = generatedNamesForAssignments . get ( i ) . length ( ) ; for ( int j = i ; j < numPendingAssignments && generatedNamesForAssignments . get ( j ) . length ( ) == len ; j ++ ) { varsByOrderOfOccurrence . add ( pendingAssignments . get ( j ) ) ; } for ( Assignment a : varsByOrderOfOccurrence ) { finalizeNameAssignment ( a , generatedNamesForAssignments . get ( i ) ) ; ++ i ; } } } | Determines which new names to substitute for the original names . |
34,887 | private void finalizeNameAssignment ( Assignment a , String newName ) { a . setNewName ( newName ) ; renameMap . put ( a . oldName , newName ) ; } | Makes a final name assignment . |
34,888 | public String version ( ) { if ( ES3 . contains ( this ) ) { return "es3" ; } if ( ES5 . contains ( this ) ) { return "es5" ; } if ( ES6_MODULES . contains ( this ) ) { return "es6" ; } if ( ES7_MODULES . contains ( this ) ) { return "es7" ; } if ( ES8_MODULES . contains ( this ) ) { return "es8" ; } if ( ES2018_MODULES . contains ( this ) ) { return "es9" ; } if ( ES2019_MODULES . contains ( this ) ) { return "es_2019" ; } if ( ES_NEXT . contains ( this ) ) { return "es_next" ; } if ( ES_UNSUPPORTED . contains ( this ) ) { return "es_unsupported" ; } if ( TYPESCRIPT . contains ( this ) ) { return "ts" ; } throw new IllegalStateException ( this . toString ( ) ) ; } | Returns a string representation suitable for encoding in depgraph and deps . js files . |
34,889 | public static FeatureSet valueOf ( String name ) { switch ( name ) { case "es3" : return ES3 ; case "es5" : return ES5 ; case "es6-impl" : case "es6" : return ES6 ; case "typeCheckSupported" : return TYPE_CHECK_SUPPORTED ; case "es7" : return ES7 ; case "es8" : return ES8 ; case "es2018" : case "es9" : return ES2018 ; case "es_2019" : return ES2019 ; case "es_next" : return ES_NEXT ; case "ts" : return TYPESCRIPT ; default : throw new IllegalArgumentException ( "No such FeatureSet: " + name ) ; } } | Parses known strings into feature sets . |
34,890 | public String computeDependencyCalls ( ) throws IOException { Map < String , DependencyInfo > depsFiles = parseDepsFiles ( ) ; if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "preparsedFiles: " + depsFiles ) ; } Map < String , DependencyInfo > jsFiles = parseSources ( depsFiles . keySet ( ) ) ; if ( errorManager . getErrorCount ( ) > 0 ) { return null ; } cleanUpDuplicatedFiles ( depsFiles , jsFiles ) ; jsFiles = removeMungedSymbols ( depsFiles , jsFiles ) ; validateDependencies ( depsFiles . values ( ) , jsFiles . values ( ) ) ; if ( errorManager . getErrorCount ( ) > 0 ) { return null ; } ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; writeDepsContent ( depsFiles , jsFiles , new PrintStream ( output ) ) ; return new String ( output . toByteArray ( ) , UTF_8 ) ; } | Performs the parsing inputs and writing of outputs . |
34,891 | protected void cleanUpDuplicatedFiles ( Map < String , DependencyInfo > depsFiles , Map < String , DependencyInfo > jsFiles ) { Set < String > depsPathsCopy = new HashSet < > ( depsFiles . keySet ( ) ) ; for ( String path : depsPathsCopy ) { if ( mergeStrategy != InclusionStrategy . WHEN_IN_SRCS ) { jsFiles . remove ( path ) ; } } for ( String path : jsFiles . keySet ( ) ) { depsFiles . remove ( path ) ; } } | Removes duplicated depsInfo from jsFiles if this info already present in some of the parsed deps . js |
34,892 | private void addToProvideMap ( Iterable < DependencyInfo > depInfos , Map < String , DependencyInfo > providesMap , boolean isFromDepsFile ) { for ( DependencyInfo depInfo : depInfos ) { List < String > provides = new ArrayList < > ( depInfo . getProvides ( ) ) ; if ( isFromDepsFile ) { provides . add ( loader . resolve ( PathUtil . makeAbsolute ( depInfo . getPathRelativeToClosureBase ( ) , closurePathAbs ) ) . toModuleName ( ) ) ; } else { if ( ! "es6" . equals ( depInfo . getLoadFlags ( ) . get ( "module" ) ) ) { provides . add ( loader . resolve ( depInfo . getName ( ) ) . toModuleName ( ) ) ; } } provides . add ( depInfo . getPathRelativeToClosureBase ( ) ) ; for ( String provide : provides ) { DependencyInfo prevValue = providesMap . put ( provide , depInfo ) ; if ( prevValue != null ) { reportDuplicateProvide ( provide , prevValue , depInfo ) ; } } } } | Adds the given DependencyInfos to the given providesMap . Also checks for and reports duplicate provides . |
34,893 | private Map < String , DependencyInfo > parseDepsFiles ( ) throws IOException { DepsFileParser depsParser = createDepsFileParser ( ) ; Map < String , DependencyInfo > depsFiles = new LinkedHashMap < > ( ) ; for ( SourceFile file : deps ) { if ( ! shouldSkipDepsFile ( file ) ) { List < DependencyInfo > depInfos = depsParser . parseFileReader ( file . getName ( ) , file . getCodeReader ( ) ) ; if ( depInfos . isEmpty ( ) ) { reportNoDepsInDepsFile ( file . getName ( ) ) ; } else { for ( DependencyInfo info : depInfos ) { depsFiles . put ( info . getPathRelativeToClosureBase ( ) , removeRelativePathProvide ( info ) ) ; } } } } for ( SourceFile src : srcs ) { if ( ! shouldSkipDepsFile ( src ) ) { List < DependencyInfo > srcInfos = depsParser . parseFileReader ( src . getName ( ) , src . getCodeReader ( ) ) ; for ( DependencyInfo info : srcInfos ) { depsFiles . put ( info . getPathRelativeToClosureBase ( ) , removeRelativePathProvide ( info ) ) ; } } } return depsFiles ; } | Parses all deps . js files in the deps list and creates a map of closure - relative path - > DependencyInfo . |
34,894 | private Map < String , DependencyInfo > parseSources ( Set < String > preparsedFiles ) throws IOException { Map < String , DependencyInfo > parsedFiles = new LinkedHashMap < > ( ) ; JsFileParser jsParser = new JsFileParser ( errorManager ) . setModuleLoader ( loader ) ; Compiler compiler = new Compiler ( ) ; compiler . init ( ImmutableList . of ( ) , ImmutableList . of ( ) , new CompilerOptions ( ) ) ; for ( SourceFile file : srcs ) { String closureRelativePath = PathUtil . makeRelative ( closurePathAbs , PathUtil . makeAbsolute ( file . getName ( ) ) ) ; if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Closure-relative path: " + closureRelativePath ) ; } if ( InclusionStrategy . WHEN_IN_SRCS == mergeStrategy || ! preparsedFiles . contains ( closureRelativePath ) ) { DependencyInfo depInfo = jsParser . parseFile ( file . getName ( ) , closureRelativePath , file . getCode ( ) ) ; depInfo = new LazyParsedDependencyInfo ( depInfo , new JsAst ( file ) , compiler ) ; file . clearCachedSource ( ) ; parsedFiles . put ( closureRelativePath , depInfo ) ; } } return parsedFiles ; } | Parses all source files for dependency information . |
34,895 | private void writeDepsContent ( Map < String , DependencyInfo > depsFiles , Map < String , DependencyInfo > jsFiles , PrintStream out ) throws IOException { writeDepInfos ( out , jsFiles . values ( ) ) ; if ( mergeStrategy == InclusionStrategy . ALWAYS ) { Multimap < String , DependencyInfo > infosIndex = Multimaps . index ( depsFiles . values ( ) , DependencyInfo :: getName ) ; for ( String depsPath : infosIndex . keySet ( ) ) { String path = formatPathToDepsFile ( depsPath ) ; out . println ( "\n// Included from: " + path ) ; writeDepInfos ( out , infosIndex . get ( depsPath ) ) ; } } } | Creates the content to put into the output deps . js file . If mergeDeps is true then all of the dependency information in the providedDeps will be included in the output . |
34,896 | private void addReturnTypeIfMissing ( PolymerClassDefinition cls , String getterPropName , JSTypeExpression jsType ) { Node classMembers = NodeUtil . getClassMembers ( cls . definition ) ; Node getter = NodeUtil . getFirstGetterMatchingKey ( classMembers , getterPropName ) ; if ( getter != null ) { JSDocInfo info = NodeUtil . getBestJSDocInfo ( getter ) ; if ( info == null || ! info . hasReturnType ( ) ) { JSDocInfoBuilder builder = JSDocInfoBuilder . maybeCopyFrom ( info ) ; builder . recordReturnType ( jsType ) ; getter . setJSDocInfo ( builder . build ( ) ) ; } } } | Adds return type information to class getters |
34,897 | private void addPropertiesConfigObjectReflection ( PolymerClassDefinition cls , Node propertiesLiteral ) { checkNotNull ( propertiesLiteral ) ; checkState ( propertiesLiteral . isObjectLit ( ) ) ; Node parent = propertiesLiteral . getParent ( ) ; Node objReflectCall = IR . call ( NodeUtil . newQName ( compiler , "$jscomp.reflectObject" ) , cls . target . cloneTree ( ) , propertiesLiteral . detach ( ) ) . useSourceInfoIfMissingFromForTree ( propertiesLiteral ) ; parent . addChildToFront ( objReflectCall ) ; compiler . reportChangeToEnclosingScope ( parent ) ; } | Wrap the properties config object in an objectReflect call |
34,898 | private void appendPropertiesToBlock ( List < MemberDefinition > props , Node block , String basePath ) { for ( MemberDefinition prop : props ) { Node propertyNode = IR . exprResult ( NodeUtil . newQName ( compiler , basePath + prop . name . getString ( ) ) ) ; if ( prop . name . isQuotedString ( ) ) { continue ; } propertyNode . useSourceInfoIfMissingFromForTree ( prop . name ) ; JSDocInfoBuilder info = JSDocInfoBuilder . maybeCopyFrom ( prop . info ) ; JSTypeExpression propType = PolymerPassStaticUtils . getTypeFromProperty ( prop , compiler ) ; if ( propType == null ) { return ; } info . recordType ( propType ) ; propertyNode . getFirstChild ( ) . setJSDocInfo ( info . build ( ) ) ; block . addChildToBack ( propertyNode ) ; } } | Appends all of the given properties to the given block . |
34,899 | private void removePropertyDocs ( final Node objLit , PolymerClassDefinition . DefinitionType defType ) { for ( MemberDefinition prop : PolymerPassStaticUtils . extractProperties ( objLit , defType , compiler , null ) ) { prop . name . removeProp ( Node . JSDOC_INFO_PROP ) ; } } | Remove all JSDocs from properties of a class definition |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.