idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
35,000
@ SuppressWarnings ( "unchecked" ) public final Set < String > getDirectives ( ) { return ( Set < String > ) getProp ( Prop . DIRECTIVES ) ; }
Returns the set of ES5 directives for this node .
35,001
@ GwtIncompatible ( "ObjectOutput" ) private void writeEncodedInt ( ObjectOutput out , int value ) throws IOException { while ( value > 0X7f || value < 0 ) { out . writeByte ( ( ( value & 0X7f ) | 0x80 ) ) ; value >>>= 7 ; } out . writeByte ( value ) ; }
Encode integers using variable length encoding .
35,002
private static Node normalizeAssignmentOp ( Node n ) { Node lhs = n . getFirstChild ( ) ; Node rhs = n . getLastChild ( ) ; Node newRhs = new Node ( NodeUtil . getOpFromAssignmentOp ( n ) , lhs . cloneTree ( ) , rhs . cloneTree ( ) ) . srcrefTree ( n ) ; return replace ( n , IR . assign ( lhs . cloneTree ( ) , newRhs ) . srcrefTree ( n ) ) ; }
Transforms a + = b to a = a + b .
35,003
private Node renameProperty ( Node propertyName ) { checkArgument ( propertyName . isString ( ) ) ; if ( ! renameProperties ) { return propertyName ; } Node call = IR . call ( IR . name ( NodeUtil . JSC_PROPERTY_NAME_FN ) . srcref ( propertyName ) , propertyName ) ; call . srcref ( propertyName ) ; call . putBooleanProp ( Node . FREE_CALL , true ) ; call . putBooleanProp ( Node . IS_CONSTANT_NAME , true ) ; return call ; }
Wraps a property string in a JSCompiler_renameProperty call .
35,004
private void replaceGetCompilerOverridesCalls ( List < TweakFunctionCall > calls ) { for ( TweakFunctionCall call : calls ) { Node callNode = call . callNode ; Node objNode = createCompilerDefaultValueOverridesVarNode ( callNode ) ; callNode . replaceWith ( objNode ) ; compiler . reportChangeToEnclosingScope ( objNode ) ; } }
Passes the compiler default value overrides to the JS by replacing calls to goog . tweak . getCompilerOverrids_ with a map of tweak ID - > default value ;
35,005
private void stripAllCalls ( Map < String , TweakInfo > tweakInfos ) { for ( TweakInfo tweakInfo : tweakInfos . values ( ) ) { boolean isRegistered = tweakInfo . isRegistered ( ) ; for ( TweakFunctionCall functionCall : tweakInfo . functionCalls ) { Node callNode = functionCall . callNode ; Node parent = callNode . getParent ( ) ; if ( functionCall . tweakFunc . isGetterFunction ( ) ) { Node newValue ; if ( isRegistered ) { newValue = tweakInfo . getDefaultValueNode ( ) . cloneNode ( ) ; } else { TweakFunction registerFunction = functionCall . tweakFunc . registerFunction ; newValue = registerFunction . createDefaultValueNode ( ) ; } parent . replaceChild ( callNode , newValue ) ; compiler . reportChangeToEnclosingScope ( parent ) ; } else { Node voidZeroNode = IR . voidNode ( IR . number ( 0 ) . srcref ( callNode ) ) . srcref ( callNode ) ; parent . replaceChild ( callNode , voidZeroNode ) ; compiler . reportChangeToEnclosingScope ( parent ) ; } } } }
Removes all CALL nodes in the given TweakInfos replacing calls to getter functions with the tweak s default value .
35,006
private Node createCompilerDefaultValueOverridesVarNode ( Node sourceInformationNode ) { Node objNode = IR . objectlit ( ) . srcref ( sourceInformationNode ) ; for ( Entry < String , Node > entry : compilerDefaultValueOverrides . entrySet ( ) ) { Node objKeyNode = IR . stringKey ( entry . getKey ( ) ) . useSourceInfoIfMissingFrom ( sourceInformationNode ) ; Node objValueNode = entry . getValue ( ) . cloneNode ( ) . useSourceInfoIfMissingFrom ( sourceInformationNode ) ; objKeyNode . addChildToBack ( objValueNode ) ; objNode . addChildToBack ( objKeyNode ) ; } return objNode ; }
Creates a JS object that holds a map of tweakId - > default value override .
35,007
private void applyCompilerDefaultValueOverrides ( Map < String , TweakInfo > tweakInfos ) { for ( Entry < String , Node > entry : compilerDefaultValueOverrides . entrySet ( ) ) { String tweakId = entry . getKey ( ) ; TweakInfo tweakInfo = tweakInfos . get ( tweakId ) ; if ( tweakInfo == null ) { compiler . report ( JSError . make ( UNKNOWN_TWEAK_WARNING , tweakId ) ) ; } else { TweakFunction registerFunc = tweakInfo . registerCall . tweakFunc ; Node value = entry . getValue ( ) ; if ( ! registerFunc . isValidNodeType ( value . getToken ( ) ) ) { compiler . report ( JSError . make ( INVALID_TWEAK_DEFAULT_VALUE_WARNING , tweakId , registerFunc . getName ( ) , registerFunc . getExpectedTypeName ( ) ) ) ; } else { tweakInfo . defaultValueNode = value ; } } } }
Sets the default values of tweaks based on compiler options .
35,008
private Node tryFoldTry ( Node n ) { checkState ( n . isTry ( ) , n ) ; Node body = n . getFirstChild ( ) ; Node catchBlock = body . getNext ( ) ; Node finallyBlock = catchBlock . getNext ( ) ; if ( ! catchBlock . hasChildren ( ) && ( finallyBlock == null || ! finallyBlock . hasChildren ( ) ) ) { n . removeChild ( body ) ; n . replaceWith ( body ) ; reportChangeToEnclosingScope ( body ) ; return body ; } if ( ! body . hasChildren ( ) ) { NodeUtil . redeclareVarsInsideBranch ( catchBlock ) ; reportChangeToEnclosingScope ( n ) ; if ( finallyBlock != null ) { n . removeChild ( finallyBlock ) ; n . replaceWith ( finallyBlock ) ; } else { n . detach ( ) ; } return finallyBlock ; } return n ; }
Remove try blocks without catch blocks and with empty or not existent finally blocks . Or only leave the finally blocks if try body blocks are empty
35,009
private Node tryFoldExpr ( Node subtree ) { Node result = trySimplifyUnusedResult ( subtree . getFirstChild ( ) ) ; if ( result == null ) { Node parent = subtree . getParent ( ) ; if ( parent . isLabel ( ) ) { Node replacement = IR . block ( ) . srcref ( subtree ) ; parent . replaceChild ( subtree , replacement ) ; subtree = replacement ; } else { subtree . detach ( ) ; subtree = null ; } } return subtree ; }
Try folding EXPR_RESULT nodes by removing useless Ops and expressions .
35,010
private Node tryOptimizeSwitch ( Node n ) { checkState ( n . isSwitch ( ) , n ) ; Node defaultCase = tryOptimizeDefaultCase ( n ) ; if ( defaultCase == null || n . getLastChild ( ) . isDefaultCase ( ) ) { Node cond = n . getFirstChild ( ) ; Node prev = null ; Node next = null ; Node cur ; for ( cur = cond . getNext ( ) ; cur != null ; cur = next ) { next = cur . getNext ( ) ; if ( ! mayHaveSideEffects ( cur . getFirstChild ( ) ) && isUselessCase ( cur , prev , defaultCase ) ) { removeCase ( n , cur ) ; } else { prev = cur ; } } if ( NodeUtil . isLiteralValue ( cond , false ) ) { Node caseLabel ; TernaryValue caseMatches = TernaryValue . TRUE ; for ( cur = cond . getNext ( ) ; cur != null ; cur = next ) { next = cur . getNext ( ) ; caseLabel = cur . getFirstChild ( ) ; caseMatches = PeepholeFoldConstants . evaluateComparison ( this , Token . SHEQ , cond , caseLabel ) ; if ( caseMatches == TernaryValue . TRUE ) { break ; } else if ( caseMatches == TernaryValue . UNKNOWN ) { break ; } else { removeCase ( n , cur ) ; } } if ( cur != null && caseMatches == TernaryValue . TRUE ) { Node matchingCase = cur ; Node matchingCaseBlock = matchingCase . getLastChild ( ) ; while ( cur != null ) { Node block = cur . getLastChild ( ) ; Node lastStm = block . getLastChild ( ) ; boolean isLastStmRemovableBreak = false ; if ( lastStm != null && isExit ( lastStm ) ) { removeIfUnnamedBreak ( lastStm ) ; isLastStmRemovableBreak = true ; } next = cur . getNext ( ) ; if ( cur != matchingCase ) { while ( block . hasChildren ( ) ) { matchingCaseBlock . addChildToBack ( block . getFirstChild ( ) . detach ( ) ) ; } reportChangeToEnclosingScope ( cur ) ; cur . detach ( ) ; } cur = next ; if ( isLastStmRemovableBreak ) { break ; } } for ( ; cur != null ; cur = next ) { next = cur . getNext ( ) ; removeCase ( n , cur ) ; } cur = cond . getNext ( ) ; if ( cur != null && cur . getNext ( ) == null ) { return tryRemoveSwitchWithSingleCase ( n , false ) ; } } } } return tryRemoveSwitch ( n ) ; }
Remove useless switches and cases .
35,011
private void removeCase ( Node switchNode , Node caseNode ) { NodeUtil . redeclareVarsInsideBranch ( caseNode ) ; switchNode . removeChild ( caseNode ) ; reportChangeToEnclosingScope ( switchNode ) ; }
Remove the case from the switch redeclaring any variables declared in it .
35,012
Node tryOptimizeBlock ( Node n ) { for ( Node c = n . getFirstChild ( ) ; c != null ; ) { Node next = c . getNext ( ) ; if ( ! isUnremovableNode ( c ) && ! mayHaveSideEffects ( c ) ) { checkNormalization ( ! NodeUtil . isFunctionDeclaration ( n ) , "function declaration" ) ; n . removeChild ( c ) ; reportChangeToEnclosingScope ( n ) ; markFunctionsDeleted ( c ) ; } else { tryOptimizeConditionalAfterAssign ( c ) ; } c = next ; } if ( n . isSyntheticBlock ( ) || n . isScript ( ) || n . getParent ( ) == null ) { return n ; } Node parent = n . getParent ( ) ; if ( NodeUtil . tryMergeBlock ( n , false ) ) { reportChangeToEnclosingScope ( parent ) ; return null ; } return n ; }
Try removing unneeded block nodes and their useless children
35,013
private void tryOptimizeConditionalAfterAssign ( Node n ) { Node next = n . getNext ( ) ; if ( isSimpleAssignment ( n ) && isConditionalStatement ( next ) ) { Node lhsAssign = getSimpleAssignmentName ( n ) ; Node condition = getConditionalStatementCondition ( next ) ; if ( lhsAssign . isName ( ) && condition . isName ( ) && lhsAssign . getString ( ) . equals ( condition . getString ( ) ) ) { Node rhsAssign = getSimpleAssignmentValue ( n ) ; TernaryValue value = NodeUtil . getImpureBooleanValue ( rhsAssign ) ; if ( value != TernaryValue . UNKNOWN ) { Node replacementConditionNode = NodeUtil . booleanNode ( value . toBoolean ( true ) ) ; condition . replaceWith ( replacementConditionNode ) ; reportChangeToEnclosingScope ( replacementConditionNode ) ; } } } }
Attempt to replace the condition of if or hook immediately that is a reference to a name that is assigned immediately before .
35,014
Node tryFoldWhile ( Node n ) { checkArgument ( n . isWhile ( ) ) ; Node cond = NodeUtil . getConditionExpression ( n ) ; if ( NodeUtil . getPureBooleanValue ( cond ) != TernaryValue . FALSE ) { return n ; } NodeUtil . redeclareVarsInsideBranch ( n ) ; reportChangeToEnclosingScope ( n . getParent ( ) ) ; NodeUtil . removeChild ( n . getParent ( ) , n ) ; return null ; }
Removes WHILEs that always evaluate to false .
35,015
Node tryFoldFor ( Node n ) { checkArgument ( n . isVanillaFor ( ) ) ; Node init = n . getFirstChild ( ) ; Node cond = init . getNext ( ) ; Node increment = cond . getNext ( ) ; if ( ! init . isEmpty ( ) && ! NodeUtil . isNameDeclaration ( init ) ) { init = trySimplifyUnusedResult ( init ) ; if ( init == null ) { init = IR . empty ( ) . srcref ( n ) ; n . addChildToFront ( init ) ; } } if ( ! increment . isEmpty ( ) ) { increment = trySimplifyUnusedResult ( increment ) ; if ( increment == null ) { increment = IR . empty ( ) . srcref ( n ) ; n . addChildAfter ( increment , cond ) ; } } if ( ! n . getFirstChild ( ) . isEmpty ( ) ) { return n ; } if ( NodeUtil . getImpureBooleanValue ( cond ) != TernaryValue . FALSE ) { return n ; } Node parent = n . getParent ( ) ; NodeUtil . redeclareVarsInsideBranch ( n ) ; if ( ! mayHaveSideEffects ( cond ) ) { NodeUtil . removeChild ( parent , n ) ; } else { Node statement = IR . exprResult ( cond . detach ( ) ) . useSourceInfoIfMissingFrom ( cond ) ; if ( parent . isLabel ( ) ) { Node block = IR . block ( ) ; block . useSourceInfoIfMissingFrom ( statement ) ; block . addChildToFront ( statement ) ; statement = block ; } parent . replaceChild ( n , statement ) ; } reportChangeToEnclosingScope ( parent ) ; return null ; }
Removes FORs that always evaluate to false .
35,016
Node tryFoldDoAway ( Node n ) { checkArgument ( n . isDo ( ) ) ; Node cond = NodeUtil . getConditionExpression ( n ) ; if ( NodeUtil . getImpureBooleanValue ( cond ) != TernaryValue . FALSE ) { return n ; } Node block = NodeUtil . getLoopCodeBlock ( n ) ; if ( n . getParent ( ) . isLabel ( ) || hasUnnamedBreakOrContinue ( block ) ) { return n ; } Node parent = n . getParent ( ) ; n . replaceWith ( block . detach ( ) ) ; if ( mayHaveSideEffects ( cond ) ) { Node condStatement = IR . exprResult ( cond . detach ( ) ) . srcref ( cond ) ; parent . addChildAfter ( condStatement , block ) ; } reportChangeToEnclosingScope ( parent ) ; return block ; }
Removes DOs that always evaluate to false . This leaves the statements that were in the loop in a BLOCK node . The block will be removed in a later pass if possible .
35,017
Node tryFoldEmptyDo ( Node n ) { checkArgument ( n . isDo ( ) ) ; Node body = NodeUtil . getLoopCodeBlock ( n ) ; if ( body . isBlock ( ) && ! body . hasChildren ( ) ) { Node cond = NodeUtil . getConditionExpression ( n ) ; Node forNode = IR . forNode ( IR . empty ( ) . srcref ( n ) , cond . detach ( ) , IR . empty ( ) . srcref ( n ) , body . detach ( ) ) ; n . replaceWith ( forNode ) ; reportChangeToEnclosingScope ( forNode ) ; return forNode ; } return n ; }
Removes DOs that have empty bodies into FORs which are much easier for the CFA to analyze .
35,018
Node tryOptimizeObjectPattern ( Node pattern ) { checkArgument ( pattern . isObjectPattern ( ) , pattern ) ; if ( pattern . hasChildren ( ) && pattern . getLastChild ( ) . isRest ( ) ) { return pattern ; } for ( Node child = pattern . getFirstChild ( ) ; child != null ; ) { Node key = child ; child = key . getNext ( ) ; if ( ! key . isStringKey ( ) ) { continue ; } if ( isRemovableDestructuringTarget ( key . getOnlyChild ( ) ) ) { key . detach ( ) ; reportChangeToEnclosingScope ( pattern ) ; } } return pattern ; }
Removes string keys with an empty pattern as their child
35,019
Node tryOptimizeArrayPattern ( Node pattern ) { checkArgument ( pattern . isArrayPattern ( ) , pattern ) ; for ( Node lastChild = pattern . getLastChild ( ) ; lastChild != null ; ) { if ( lastChild . isEmpty ( ) || isRemovableDestructuringTarget ( lastChild ) ) { Node prev = lastChild . getPrevious ( ) ; pattern . removeChild ( lastChild ) ; lastChild = prev ; reportChangeToEnclosingScope ( pattern ) ; } else { break ; } } return pattern ; }
Removes trailing EMPTY nodes and empty array patterns
35,020
static boolean hasUnnamedBreakOrContinue ( Node n ) { return NodeUtil . has ( n , IS_UNNAMED_BREAK_PREDICATE , CAN_CONTAIN_BREAK_PREDICATE ) || NodeUtil . has ( n , IS_UNNAMED_CONTINUE_PREDICATE , CAN_CONTAIN_CONTINUE_PREDICATE ) ; }
Returns whether a node has any unhandled breaks or continue .
35,021
private void tryFoldForCondition ( Node forCondition ) { if ( NodeUtil . getPureBooleanValue ( forCondition ) == TernaryValue . TRUE ) { reportChangeToEnclosingScope ( forCondition ) ; forCondition . replaceWith ( IR . empty ( ) ) ; } }
Remove always true loop conditions .
35,022
private void visitBlockScopedName ( NodeTraversal t , Node decl , Node nameNode ) { Scope scope = t . getScope ( ) ; Node parent = decl . getParent ( ) ; if ( ( decl . isLet ( ) || decl . isConst ( ) ) && ! nameNode . hasChildren ( ) && ( parent == null || ! parent . isForIn ( ) ) && inLoop ( decl ) ) { Node undefined = createUndefinedNode ( ) . srcref ( nameNode ) ; nameNode . addChildToFront ( undefined ) ; compiler . reportChangeToEnclosingScope ( undefined ) ; } String oldName = nameNode . getString ( ) ; Scope hoistScope = scope . getClosestHoistScope ( ) ; if ( scope != hoistScope ) { String newName = oldName ; if ( hoistScope . hasSlot ( oldName ) || undeclaredNames . contains ( oldName ) ) { do { newName = oldName + "$" + compiler . getUniqueNameIdSupplier ( ) . get ( ) ; } while ( hoistScope . hasSlot ( newName ) ) ; nameNode . setString ( newName ) ; compiler . reportChangeToEnclosingScope ( nameNode ) ; Node scopeRoot = scope . getRootNode ( ) ; renameTable . put ( scopeRoot , oldName , newName ) ; } Var oldVar = scope . getVar ( oldName ) ; scope . undeclare ( oldVar ) ; hoistScope . declare ( newName , nameNode , oldVar . input ) ; } }
Renames block - scoped declarations that shadow a variable in an outer scope
35,023
private boolean inLoop ( Node n ) { Node enclosingNode = NodeUtil . getEnclosingNode ( n , isLoopOrFunction ) ; return enclosingNode != null && ! enclosingNode . isFunction ( ) ; }
Whether n is inside a loop . If n is inside a function which is inside a loop we do not consider it to be inside a loop .
35,024
private Node createAssignNode ( Node lhs , Node rhs ) { Node assignNode = IR . assign ( lhs , rhs ) ; if ( shouldAddTypesOnNewAstNodes ) { assignNode . setJSType ( rhs . getJSType ( ) ) ; } return assignNode ; }
Creates an ASSIGN node with type information matching its RHS .
35,025
private Node createCommaNode ( Node expr1 , Node expr2 ) { Node commaNode = IR . comma ( expr1 , expr2 ) ; if ( shouldAddTypesOnNewAstNodes ) { commaNode . setJSType ( expr2 . getJSType ( ) ) ; } return commaNode ; }
Creates a COMMA node with type information matching its second argument .
35,026
public String getLine ( int lineNumber ) { findLineOffsets ( ) ; if ( lineNumber > lineOffsets . length ) { return null ; } if ( lineNumber < 1 ) { lineNumber = 1 ; } int pos = lineOffsets [ lineNumber - 1 ] ; String js = "" ; try { js = getCode ( ) ; } catch ( IOException e ) { return null ; } if ( js . indexOf ( '\n' , pos ) == - 1 ) { if ( pos >= js . length ( ) ) { return null ; } else { return js . substring ( pos ) ; } } else { return js . substring ( pos , js . indexOf ( '\n' , pos ) ) ; } }
Gets the source line for the indicated line number .
35,027
public Region getRegion ( int lineNumber ) { String js = "" ; try { js = getCode ( ) ; } catch ( IOException e ) { return null ; } int pos = 0 ; int startLine = Math . max ( 1 , lineNumber - ( SOURCE_EXCERPT_REGION_LENGTH + 1 ) / 2 + 1 ) ; for ( int n = 1 ; n < startLine ; n ++ ) { int nextpos = js . indexOf ( '\n' , pos ) ; if ( nextpos == - 1 ) { break ; } pos = nextpos + 1 ; } int end = pos ; int endLine = startLine ; for ( int n = 0 ; n < SOURCE_EXCERPT_REGION_LENGTH ; n ++ , endLine ++ ) { end = js . indexOf ( '\n' , end ) ; if ( end == - 1 ) { break ; } end ++ ; } if ( lineNumber >= endLine ) { return null ; } if ( end == - 1 ) { int last = js . length ( ) - 1 ; if ( js . charAt ( last ) == '\n' ) { return new SimpleRegion ( startLine , endLine , js . substring ( pos , last ) ) ; } else { return new SimpleRegion ( startLine , endLine , js . substring ( pos ) ) ; } } else { return new SimpleRegion ( startLine , endLine , js . substring ( pos , end ) ) ; } }
Get a region around the indicated line number . The exact definition of a region is implementation specific but it must contain the line indicated by the line number . A region must not start or end by a carriage return .
35,028
@ GwtIncompatible ( "com.google.io.Files" ) public void save ( String filename ) throws IOException { Files . write ( toBytes ( ) , new File ( filename ) ) ; }
Saves the variable map to a file .
35,029
@ GwtIncompatible ( "java.io.ByteArrayOutputStream" ) public byte [ ] toBytes ( ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; Writer writer = new OutputStreamWriter ( baos , UTF_8 ) ; try { for ( Map . Entry < String , String > entry : ImmutableSortedSet . copyOf ( comparingByKey ( ) , map . entrySet ( ) ) ) { writer . write ( escape ( entry . getKey ( ) ) ) ; writer . write ( SEPARATOR ) ; writer . write ( escape ( entry . getValue ( ) ) ) ; writer . write ( '\n' ) ; } writer . close ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } return baos . toByteArray ( ) ; }
Serializes the variable map to a byte array .
35,030
public boolean parseTypeTransformation ( ) { Config config = Config . builder ( ) . setLanguageMode ( Config . LanguageMode . ECMASCRIPT6 ) . setStrictMode ( Config . StrictMode . SLOPPY ) . build ( ) ; ParseResult result = ParserRunner . parse ( sourceFile , typeTransformationString , config , errorReporter ) ; Node ast = result . ast ; if ( ! ast . isScript ( ) || ! ast . getFirstChild ( ) . isExprResult ( ) ) { warnInvalidExpression ( "type transformation" , ast ) ; return false ; } Node expr = ast . getFirstFirstChild ( ) ; if ( ! validTypeTransformationExpression ( expr ) ) { return false ; } fixLineNumbers ( expr ) ; typeTransformationAst = expr ; return true ; }
Takes a type transformation expression transforms it to an AST using the ParserRunner of the JSCompiler and then verifies that it is a valid AST .
35,031
private boolean validBooleanExpression ( Node expr ) { if ( isBooleanOperation ( expr ) ) { return validBooleanOperation ( expr ) ; } if ( ! isOperation ( expr ) ) { warnInvalidExpression ( "boolean" , expr ) ; return false ; } if ( ! isValidPredicate ( getCallName ( expr ) ) ) { warnInvalid ( "boolean predicate" , expr ) ; return false ; } Keywords keyword = nameToKeyword ( getCallName ( expr ) ) ; if ( ! checkParameterCount ( expr , keyword ) ) { return false ; } switch ( keyword . kind ) { case TYPE_PREDICATE : return validTypePredicate ( expr , getCallParamCount ( expr ) ) ; case STRING_PREDICATE : return validStringPredicate ( expr , getCallParamCount ( expr ) ) ; case TYPEVAR_PREDICATE : return validTypevarPredicate ( expr , getCallParamCount ( expr ) ) ; default : throw new IllegalStateException ( "Invalid boolean expression" ) ; } }
A boolean expression must be a boolean predicate or a boolean type predicate
35,032
private boolean validOperationExpression ( Node expr ) { String name = getCallName ( expr ) ; Keywords keyword = nameToKeyword ( name ) ; switch ( keyword ) { case COND : return validConditionalExpression ( expr ) ; case MAPUNION : return validMapunionExpression ( expr ) ; case MAPRECORD : return validMaprecordExpression ( expr ) ; case TYPEOFVAR : return validTypeOfVarExpression ( expr ) ; case INSTANCEOF : return validInstanceOfExpression ( expr ) ; case PRINTTYPE : return validPrintTypeExpression ( expr ) ; case PROPTYPE : return validPropTypeExpression ( expr ) ; default : throw new IllegalStateException ( "Invalid type transformation operation" ) ; } }
An operation expression is a cond or a mapunion
35,033
private boolean validTypeTransformationExpression ( Node expr ) { if ( ! isValidExpression ( expr ) ) { warnInvalidExpression ( "type transformation" , expr ) ; return false ; } if ( isTypeVar ( expr ) || isTypeName ( expr ) ) { return true ; } String name = getCallName ( expr ) ; if ( ! isValidKeyword ( name ) ) { warnInvalidExpression ( "type transformation" , expr ) ; return false ; } Keywords keyword = nameToKeyword ( name ) ; switch ( keyword . kind ) { case TYPE_CONSTRUCTOR : return validTypeExpression ( expr ) ; case OPERATION : return validOperationExpression ( expr ) ; default : throw new IllegalStateException ( "Invalid type transformation expression" ) ; } }
Checks the structure of the AST of a type transformation expression in
35,034
private boolean removeIIFEWrapper ( Node root ) { checkState ( root . isScript ( ) ) ; Node n = root . getFirstChild ( ) ; while ( n != null && n . isEmpty ( ) ) { n = n . getNext ( ) ; } if ( n == null || ! n . isExprResult ( ) || n . getNext ( ) != null ) { return false ; } if ( n != null && n . getFirstChild ( ) != null && n . getFirstChild ( ) . isNot ( ) ) { n = n . getFirstChild ( ) ; } Node call = n . getFirstChild ( ) ; if ( call == null || ! call . isCall ( ) ) { return false ; } Node fnc ; if ( call . getFirstChild ( ) . isFunction ( ) ) { fnc = n . getFirstFirstChild ( ) ; } else if ( call . getFirstChild ( ) . isGetProp ( ) && call . getFirstFirstChild ( ) . isFunction ( ) && call . getFirstFirstChild ( ) . getNext ( ) . isString ( ) && call . getFirstFirstChild ( ) . getNext ( ) . getString ( ) . equals ( "call" ) ) { fnc = call . getFirstFirstChild ( ) ; if ( ! ( call . getSecondChild ( ) != null && ( call . getSecondChild ( ) . isThis ( ) || call . getSecondChild ( ) . matchesQualifiedName ( EXPORTS ) ) ) ) { return false ; } } else { return false ; } if ( NodeUtil . doesFunctionReferenceOwnArgumentsObject ( fnc ) ) { return false ; } CompilerInput ci = compiler . getInput ( root . getInputId ( ) ) ; ModulePath modulePath = ci . getPath ( ) ; if ( modulePath == null ) { return false ; } String iifeLabel = getModuleName ( modulePath ) + "_iifeWrapper" ; FunctionToBlockMutator mutator = new FunctionToBlockMutator ( compiler , compiler . getUniqueNameIdSupplier ( ) ) ; Node block = mutator . mutateWithoutRenaming ( iifeLabel , fnc , call , null , false , false ) ; root . removeChildren ( ) ; root . addChildrenToFront ( block . removeChildren ( ) ) ; reportNestedScopesDeleted ( fnc ) ; compiler . reportChangeToEnclosingScope ( root ) ; return true ; }
UMD modules are often wrapped in an IIFE for cases where they are used as scripts instead of modules . Remove the wrapper .
35,035
private void removeWebpackModuleShim ( Node root ) { checkState ( root . isScript ( ) ) ; Node n = root . getFirstChild ( ) ; while ( n != null && n . isEmpty ( ) ) { n = n . getNext ( ) ; } if ( n == null || ! n . isExprResult ( ) || n . getNext ( ) != null ) { return ; } Node call = n . getFirstChild ( ) ; if ( call == null || ! call . isCall ( ) ) { return ; } Node fnc ; if ( call . getFirstChild ( ) . isFunction ( ) ) { fnc = n . getFirstFirstChild ( ) ; } else if ( call . getFirstChild ( ) . isGetProp ( ) && call . getFirstFirstChild ( ) . isFunction ( ) && call . getFirstFirstChild ( ) . getNext ( ) . matchesQualifiedName ( "call" ) ) { fnc = call . getFirstFirstChild ( ) ; } else { return ; } Node params = NodeUtil . getFunctionParameters ( fnc ) ; Node moduleParam = null ; Node param = params . getFirstChild ( ) ; int paramNumber = 0 ; while ( param != null ) { paramNumber ++ ; if ( param . isName ( ) && param . getString ( ) . equals ( MODULE ) ) { moduleParam = param ; break ; } param = param . getNext ( ) ; } if ( moduleParam == null ) { return ; } boolean isFreeCall = call . getBooleanProp ( Node . FREE_CALL ) ; Node arg = call . getChildAtIndex ( isFreeCall ? paramNumber : paramNumber + 1 ) ; if ( arg == null ) { return ; } if ( arg . isCall ( ) && arg . getFirstChild ( ) . isCall ( ) && isCommonJsImport ( arg . getFirstChild ( ) ) && arg . getSecondChild ( ) . isName ( ) && arg . getSecondChild ( ) . getString ( ) . equals ( MODULE ) ) { String importPath = getCommonJsImportPath ( arg . getFirstChild ( ) ) ; ModulePath modulePath = compiler . getInput ( root . getInputId ( ) ) . getPath ( ) . resolveJsModule ( importPath , arg . getSourceFileName ( ) , arg . getLineno ( ) , arg . getCharno ( ) ) ; if ( modulePath == null ) { return ; } if ( modulePath . toString ( ) . contains ( "/buildin/module.js" ) ) { arg . detach ( ) ; param . detach ( ) ; compiler . reportChangeToChangeScope ( fnc ) ; compiler . reportChangeToEnclosingScope ( fnc ) ; } } }
For AMD wrappers webpack adds a shim for the module variable . We need that to be a free var so we remove the shim .
35,036
public static LinkedFlowScope createEntryLattice ( TypedScope scope ) { return new LinkedFlowScope ( HamtPMap . < TypedScope , OverlayScope > empty ( ) , scope , scope ) ; }
Creates an entry lattice for the flow .
35,037
public StaticTypedSlot getSlot ( String name ) { OverlayScope scope = getOverlayScopeForVar ( name , false ) ; return scope != null ? scope . getSlot ( name ) : syntacticScope . getSlot ( name ) ; }
Get the slot for the given symbol .
35,038
private static boolean equalSlots ( StaticTypedSlot slotA , StaticTypedSlot slotB ) { return slotA == slotB || ! slotA . getType ( ) . differsFrom ( slotB . getType ( ) ) ; }
Determines whether two slots are meaningfully different for the purposes of data flow analysis .
35,039
void updateAfterDeserialize ( Node jsRoot ) { this . jsRoot = jsRoot ; if ( ! tracksAstSize ( ) ) { return ; } this . initAstSize = this . astSize = NodeUtil . countAstSize ( this . jsRoot ) ; if ( ! tracksSize ( ) ) { return ; } PerformanceTrackerCodeSizeEstimator estimator = PerformanceTrackerCodeSizeEstimator . estimate ( this . jsRoot , tracksGzSize ( ) ) ; this . initCodeSize = this . codeSize = estimator . getCodeSize ( ) ; if ( tracksGzSize ( ) ) { this . initGzCodeSize = this . gzCodeSize = estimator . getZippedCodeSize ( ) ; } }
Updates the saved jsRoot and resets the size tracking fields accordingly .
35,040
void recordPassStop ( String passName , long runtime ) { int allocMem = getAllocatedMegabytes ( ) ; Stats logStats = this . currentPass . pop ( ) ; checkState ( passName . equals ( logStats . pass ) ) ; this . log . add ( logStats ) ; logStats . runtime = runtime ; logStats . allocMem = allocMem ; logStats . runs = 1 ; if ( this . codeChange . hasCodeChanged ( ) ) { logStats . changes = 1 ; } if ( passName . equals ( PassNames . PARSE_INPUTS ) ) { recordParsingStop ( logStats ) ; } else if ( this . codeChange . hasCodeChanged ( ) && tracksAstSize ( ) ) { recordOtherPassStop ( logStats ) ; } }
Collects information about a pass P after P finishes running eg how much time P took and what was its impact on code size .
35,041
private void loadGraph ( ) throws ServiceException { dependencies . clear ( ) ; logger . info ( "Loading dependency graph" ) ; ErrorManager errorManager = new LoggerErrorManager ( logger ) ; DepsFileParser parser = new DepsFileParser ( errorManager ) ; List < DependencyInfo > depInfos = parser . parseFile ( getName ( ) , getContent ( ) ) ; if ( ! parser . didParseSucceed ( ) ) { throw new ServiceException ( "Problem parsing " + getName ( ) + ". See logs for details." ) ; } for ( DependencyInfo depInfo : depInfos ) { for ( String provide : depInfo . getProvides ( ) ) { DependencyInfo existing = dependencies . get ( provide ) ; if ( existing != null && ! existing . equals ( depInfo ) ) { throw new ServiceException ( "Duplicate provide of " + provide + ". Was provided by " + existing . getPathRelativeToClosureBase ( ) + " and " + depInfo . getPathRelativeToClosureBase ( ) ) ; } dependencies . put ( provide , depInfo ) ; } } List < String > provides = new ArrayList < > ( ) ; provides . add ( CLOSURE_BASE_PROVIDE ) ; dependencies . put ( CLOSURE_BASE_PROVIDE , SimpleDependencyInfo . builder ( CLOSURE_BASE , CLOSURE_BASE ) . setProvides ( provides ) . build ( ) ) ; errorManager . generateReport ( ) ; logger . info ( "Dependencies loaded" ) ; }
Loads the dependency graph .
35,042
Node createIf ( Node cond , Node then ) { return IR . ifNode ( cond , then ) ; }
Returns a new IF node .
35,043
Node createFor ( Node init , Node cond , Node incr , Node body ) { return IR . forNode ( init , cond , incr , body ) ; }
Returns a new FOR node .
35,044
Node createThisForFunction ( Node functionNode ) { final Node result = IR . thisNode ( ) ; if ( isAddingTypes ( ) ) { result . setJSType ( getTypeOfThisForFunctionNode ( functionNode ) ) ; } return result ; }
Creates a THIS node with the correct type for the given function node .
35,045
Node createSuperForFunction ( Node functionNode ) { final Node result = IR . superNode ( ) ; if ( isAddingTypes ( ) ) { result . setJSType ( getTypeOfSuperForFunctionNode ( functionNode ) ) ; } return result ; }
Creates a SUPER node with the correct type for the given function node .
35,046
Node createThisAliasReferenceForFunction ( String aliasName , Node functionNode ) { final Node result = IR . name ( aliasName ) ; if ( isAddingTypes ( ) ) { result . setJSType ( getTypeOfThisForFunctionNode ( functionNode ) ) ; } return result ; }
Creates a NAME node having the type of this appropriate for the given function node .
35,047
Node createThisAliasDeclarationForFunction ( String aliasName , Node functionNode ) { return createSingleConstNameDeclaration ( aliasName , createThis ( getTypeOfThisForFunctionNode ( functionNode ) ) ) ; }
Creates a statement declaring a const alias for this to be used in the given function node .
35,048
Node createSingleConstNameDeclaration ( String variableName , Node value ) { return IR . constNode ( createName ( variableName , value . getJSType ( ) ) , value ) ; }
Creates a new const declaration statement for a single variable name .
35,049
Node createArgumentsReference ( ) { Node result = IR . name ( "arguments" ) ; if ( isAddingTypes ( ) ) { result . setJSType ( argumentsTypeSupplier . get ( ) ) ; } return result ; }
Creates a reference to arguments with the type specified in externs or unknown if the externs for it weren t included .
35,050
Node createObjectDotAssignCall ( Scope scope , JSType returnType , Node ... args ) { Node objAssign = createQName ( scope , "Object.assign" ) ; Node result = createCall ( objAssign , args ) ; if ( isAddingTypes ( ) ) { JSType objAssignType = registry . createFunctionTypeWithVarArgs ( returnType , registry . getNativeType ( JSTypeNative . OBJECT_TYPE ) , registry . createUnionType ( JSTypeNative . OBJECT_TYPE , JSTypeNative . NULL_TYPE ) ) ; objAssign . setJSType ( objAssignType ) ; result . setJSType ( returnType ) ; } return result ; }
Creates a call to Object . assign that returns the specified type .
35,051
Node createAssignStatement ( Node lhs , Node rhs ) { return exprResult ( createAssign ( lhs , rhs ) ) ; }
Creates a statement lhs = rhs ; .
35,052
Node createAssign ( Node lhs , Node rhs ) { Node result = IR . assign ( lhs , rhs ) ; if ( isAddingTypes ( ) ) { result . setJSType ( rhs . getJSType ( ) ) ; } return result ; }
Creates an assignment expression lhs = rhs
35,053
private JSType getVarNameType ( Scope scope , String name ) { Var var = scope . getVar ( name ) ; JSType type = null ; if ( var != null ) { Node nameDefinitionNode = var . getNode ( ) ; if ( nameDefinitionNode != null ) { type = nameDefinitionNode . getJSType ( ) ; } } if ( type == null ) { type = unknownType ; } return type ; }
Look up the correct type for the given name in the given scope .
35,054
private static boolean nodesHaveSameControlFlow ( Node node1 , Node node2 ) { Node node1DeepestControlDependentBlock = closestControlDependentAncestor ( node1 ) ; Node node2DeepestControlDependentBlock = closestControlDependentAncestor ( node2 ) ; if ( node1DeepestControlDependentBlock == node2DeepestControlDependentBlock ) { if ( node2DeepestControlDependentBlock != null ) { if ( node2DeepestControlDependentBlock . isCase ( ) ) { return false ; } Predicate < Node > isEarlyExitPredicate = new Predicate < Node > ( ) { public boolean apply ( Node input ) { Token nodeType = input . getToken ( ) ; return nodeType == Token . RETURN || nodeType == Token . BREAK || nodeType == Token . CONTINUE ; } } ; return ! NodeUtil . has ( node2DeepestControlDependentBlock , isEarlyExitPredicate , NOT_FUNCTION_PREDICATE ) ; } else { return true ; } } else { return false ; } }
Returns true if the two nodes have the same control flow properties that is is node1 be executed every time node2 is executed and vice versa?
35,055
private static boolean isControlDependentChild ( Node child ) { Node parent = child . getParent ( ) ; if ( parent == null ) { return false ; } ArrayList < Node > siblings = new ArrayList < > ( ) ; Iterables . addAll ( siblings , parent . children ( ) ) ; int indexOfChildInParent = siblings . indexOf ( child ) ; switch ( parent . getToken ( ) ) { case IF : case HOOK : return ( indexOfChildInParent == 1 || indexOfChildInParent == 2 ) ; case FOR : case FOR_IN : return indexOfChildInParent != 0 ; case SWITCH : return indexOfChildInParent > 0 ; case WHILE : case DO : case AND : case OR : case FUNCTION : return true ; default : return false ; } }
Returns true if the number of times the child executes depends on the parent .
35,056
private static boolean nodeHasCall ( Node node ) { return NodeUtil . has ( node , new Predicate < Node > ( ) { public boolean apply ( Node input ) { return input . isCall ( ) || input . isNew ( ) || input . isTaggedTemplateLit ( ) ; } } , NOT_FUNCTION_PREDICATE ) ; }
Returns true if a node has a CALL or a NEW descendant .
35,057
public static List < SourceFile > prepareExterns ( CompilerOptions . Environment env , Map < String , SourceFile > externs ) { List < SourceFile > out = new ArrayList < > ( ) ; for ( String key : BUILTIN_LANG_EXTERNS ) { Preconditions . checkState ( externs . containsKey ( key ) , "Externs must contain builtin: %s" , key ) ; out . add ( externs . remove ( key ) ) ; } if ( env == CompilerOptions . Environment . BROWSER ) { for ( String key : BROWSER_EXTERN_DEP_ORDER ) { Preconditions . checkState ( externs . containsKey ( key ) , "Externs must contain builtin for env %s: %s" , env , key ) ; out . add ( externs . remove ( key ) ) ; } out . addAll ( externs . values ( ) ) ; } return out ; }
Filters and orders the passed externs for the specified environment .
35,058
void setValidityCheck ( PassFactory validityCheck ) { this . validityCheck = validityCheck ; this . changeVerifier = new ChangeVerifier ( compiler ) . snapshot ( jsRoot ) ; }
Adds a checker to be run after every pass . Intended for development .
35,059
public void process ( Node externs , Node root ) { progress = 0.0 ; progressStep = 0.0 ; if ( progressRange != null ) { progressStep = ( progressRange . maxValue - progressRange . initialValue ) / passes . size ( ) ; progress = progressRange . initialValue ; } for ( CompilerPass pass : passes ) { if ( Thread . interrupted ( ) ) { throw new RuntimeException ( new InterruptedException ( ) ) ; } pass . process ( externs , root ) ; if ( hasHaltingErrors ( ) ) { return ; } } }
Run all the passes in the optimizer .
35,060
private void maybeRunValidityCheck ( String passName , Node externs , Node root ) { if ( validityCheck == null ) { return ; } try { validityCheck . create ( compiler ) . process ( externs , root ) ; changeVerifier . checkRecordedChanges ( passName , jsRoot ) ; } catch ( Exception e ) { throw new IllegalStateException ( "Validity checks failed for pass: " + passName , e ) ; } }
Runs the validity check if it is available .
35,061
private boolean canDecomposeSimply ( Node classNode ) { Node enclosingStatement = checkNotNull ( NodeUtil . getEnclosingStatement ( classNode ) , classNode ) ; if ( enclosingStatement == classNode ) { return true ; } else { Node classNodeParent = classNode . getParent ( ) ; if ( NodeUtil . isNameDeclaration ( enclosingStatement ) && classNodeParent . isName ( ) && classNodeParent . isFirstChildOf ( enclosingStatement ) ) { return true ; } else if ( enclosingStatement . isExprResult ( ) && classNodeParent . isOnlyChildOf ( enclosingStatement ) && classNodeParent . isAssign ( ) && classNode . isSecondChildOf ( classNodeParent ) ) { Node lhsNode = classNodeParent . getFirstChild ( ) ; return ! NodeUtil . mayHaveSideEffects ( lhsNode , compiler ) ; } else { return false ; } } }
Find common cases where we can safely decompose class extends expressions which are not qualified names . Enables transpilation of complex extends expressions .
35,062
private void decomposeInIIFE ( NodeTraversal t , Node classNode ) { Node functionBody = IR . block ( ) ; Node function = IR . function ( IR . name ( "" ) , IR . paramList ( ) , functionBody ) ; Node call = NodeUtil . newCallNode ( function ) ; classNode . replaceWith ( call ) ; functionBody . addChildToBack ( IR . returnNode ( classNode ) ) ; call . useSourceInfoIfMissingFromForTree ( classNode ) ; t . reportCodeChange ( call ) ; extractExtends ( t , classNode ) ; }
When a class is used in an expressions where adding an alias as the previous statement might change execution order of a side - effect causing statement wrap the class in an IIFE so that decomposition can happen safely .
35,063
boolean provablyExecutesBefore ( BasicBlock thatBlock ) { BasicBlock currentBlock ; for ( currentBlock = thatBlock ; currentBlock != null && currentBlock != this ; currentBlock = currentBlock . getParent ( ) ) { } if ( currentBlock == this ) { return true ; } return isGlobalScopeBlock ( ) && thatBlock . isGlobalScopeBlock ( ) ; }
Determines whether this block is guaranteed to begin executing before the given block does .
35,064
private void maybeCollapseIntoForStatements ( Node n , Node parent ) { if ( parent == null || ! NodeUtil . isStatementBlock ( parent ) ) { return ; } if ( ! n . isExprResult ( ) && ! n . isVar ( ) ) { return ; } Node nextSibling = n . getNext ( ) ; if ( nextSibling == null ) { return ; } else if ( nextSibling . isForIn ( ) || nextSibling . isForOf ( ) ) { Node forNode = nextSibling ; Node forVar = forNode . getFirstChild ( ) ; if ( forVar . isName ( ) && n . isVar ( ) && n . hasOneChild ( ) ) { Node name = n . getFirstChild ( ) ; if ( ! name . hasChildren ( ) && forVar . getString ( ) . equals ( name . getString ( ) ) ) { parent . removeChild ( n ) ; forNode . replaceChild ( forVar , n ) ; compiler . reportChangeToEnclosingScope ( parent ) ; } } } else if ( nextSibling . isVanillaFor ( ) && nextSibling . getFirstChild ( ) . isEmpty ( ) ) { if ( NodeUtil . containsType ( n , Token . IN ) ) { return ; } Node forNode = nextSibling ; Node oldInitializer = forNode . getFirstChild ( ) ; parent . removeChild ( n ) ; Node newInitializer ; if ( n . isVar ( ) ) { newInitializer = n ; } else { checkState ( n . hasOneChild ( ) , n ) ; newInitializer = n . getFirstChild ( ) ; n . removeChild ( newInitializer ) ; } forNode . replaceChild ( oldInitializer , newInitializer ) ; compiler . reportChangeToEnclosingScope ( forNode ) ; } }
Collapse VARs and EXPR_RESULT node into FOR loop initializers where possible .
35,065
private static String longToPaddedString ( long v , int digitsColumnWidth ) { int digitWidth = numDigits ( v ) ; StringBuilder sb = new StringBuilder ( ) ; appendSpaces ( sb , digitsColumnWidth - digitWidth ) ; sb . append ( v ) ; return sb . toString ( ) ; }
Converts v to a string and pads it with up to 16 spaces for improved alignment .
35,066
static void appendSpaces ( StringBuilder sb , int numSpaces ) { if ( numSpaces > 16 ) { logger . warning ( "Tracer.appendSpaces called with large numSpaces" ) ; numSpaces = 16 ; } while ( numSpaces >= 5 ) { sb . append ( " " ) ; numSpaces -= 5 ; } switch ( numSpaces ) { case 1 : sb . append ( " " ) ; break ; case 2 : sb . append ( " " ) ; break ; case 3 : sb . append ( " " ) ; break ; case 4 : sb . append ( " " ) ; break ; } }
Gets a string of spaces of the length specified .
35,067
static int addTracingStatistic ( TracingStatistic tracingStatistic ) { if ( tracingStatistic . enable ( ) ) { extraTracingStatistics . add ( tracingStatistic ) ; return extraTracingStatistics . lastIndexOf ( tracingStatistic ) ; } else { return - 1 ; } }
Adds a new tracing statistic to a trace
35,068
long stop ( int silenceThreshold ) { checkState ( Thread . currentThread ( ) == startThread ) ; ThreadTrace trace = getThreadTrace ( ) ; if ( ! trace . isInitialized ( ) ) { return 0 ; } stopTimeMs = clock . currentTimeMillis ( ) ; if ( extraTracingValues != null ) { for ( int i = 0 ; i < extraTracingValues . length ; i ++ ) { long value = extraTracingStatistics . get ( i ) . stop ( startThread ) ; extraTracingValues [ i ] = value - extraTracingValues [ i ] ; } } if ( ! trace . isInitialized ( ) ) { return 0 ; } trace . endEvent ( this , silenceThreshold ) ; return stopTimeMs - startTimeMs ; }
Stop the trace . This may only be done once and must be done from the same thread that started it .
35,069
static void initCurrentThreadTrace ( ) { ThreadTrace events = getThreadTrace ( ) ; if ( ! events . isEmpty ( ) ) { logger . log ( Level . WARNING , "Non-empty timer log:\n" + events , new Throwable ( ) ) ; clearThreadTrace ( ) ; events = getThreadTrace ( ) ; } events . init ( ) ; }
Initialize the trace associated with the current thread by clearing out any existing trace . There shouldn t be a trace so if one is found we log it as an error .
35,070
static void logCurrentThreadTrace ( ) { ThreadTrace trace = getThreadTrace ( ) ; if ( ! trace . isInitialized ( ) ) { logger . log ( Level . INFO , "Tracer log requested for this thread but was not " + "initialized using Tracer.initCurrentThreadTrace()." , new Throwable ( ) ) ; return ; } if ( ! trace . isEmpty ( ) ) { logger . log ( Level . INFO , "timers:\n{0}" , getCurrentThreadTraceReport ( ) ) ; } }
Logs a timer report similar to the one described in the class comment .
35,071
static Stat getStatsForType ( String type ) { Stat stat = getThreadTrace ( ) . stats . get ( type ) ; return stat != null ? stat : ZERO_STAT ; }
Gets the Stat for a tracer type ; never returns null
35,072
static ThreadTrace getThreadTrace ( ) { ThreadTrace t = traces . get ( ) ; if ( t == null ) { t = new ThreadTrace ( ) ; t . prettyPrint = defaultPrettyPrint ; traces . set ( t ) ; } return t ; }
Get the ThreadTrace for the current thread creating one if necessary .
35,073
private void addScopeVariables ( ) { int num = 0 ; for ( Var v : orderedVars ) { scopeVariables . put ( v . getName ( ) , num ) ; num ++ ; } }
Parameters belong to the function scope but variables defined in the function body belong to the function body scope . Assign a unique index to each variable regardless of which scope it s in .
35,074
void markAllParametersEscaped ( ) { Node paramList = NodeUtil . getFunctionParameters ( jsScope . getRootNode ( ) ) ; for ( Node arg = paramList . getFirstChild ( ) ; arg != null ; arg = arg . getNext ( ) ) { if ( arg . isRest ( ) || arg . isDefaultValue ( ) ) { escaped . add ( jsScope . getVar ( arg . getFirstChild ( ) . getString ( ) ) ) ; } else { escaped . add ( jsScope . getVar ( arg . getString ( ) ) ) ; } } }
Give up computing liveness of formal parameter by putting all the parameter names in the escaped set .
35,075
public CheckLevel level ( JSError error ) { return error . sourceName != null && error . sourceName . contains ( part ) ? super . level ( error ) : null ; }
Does not touch warnings in other paths .
35,076
public Iterable < ObjectType > getCtorImplementedInterfaces ( ) { LinkedHashSet < ObjectType > resolvedImplementedInterfaces = new LinkedHashSet < > ( ) ; for ( ObjectType obj : getReferencedObjTypeInternal ( ) . getCtorImplementedInterfaces ( ) ) { resolvedImplementedInterfaces . add ( obj . visit ( replacer ) . toObjectType ( ) ) ; } return resolvedImplementedInterfaces ; }
an UnsupportedOperationException .
35,077
private void checkTypeDeprecation ( NodeTraversal t , Node n ) { if ( ! shouldEmitDeprecationWarning ( t , n ) ) { return ; } ObjectType instanceType = n . getJSType ( ) . toMaybeFunctionType ( ) . getInstanceType ( ) ; String deprecationInfo = getTypeDeprecationInfo ( instanceType ) ; if ( deprecationInfo == null ) { return ; } DiagnosticType message = deprecationInfo . isEmpty ( ) ? DEPRECATED_CLASS : DEPRECATED_CLASS_REASON ; compiler . report ( JSError . make ( n , message , instanceType . toString ( ) , deprecationInfo ) ) ; }
Reports deprecation issue with regard to a type usage .
35,078
private void checkNameDeprecation ( NodeTraversal t , Node n ) { if ( ! n . isName ( ) ) { return ; } if ( ! shouldEmitDeprecationWarning ( t , n ) ) { return ; } Var var = t . getScope ( ) . getVar ( n . getString ( ) ) ; JSDocInfo docInfo = var == null ? null : var . getJSDocInfo ( ) ; if ( docInfo != null && docInfo . isDeprecated ( ) ) { if ( docInfo . getDeprecationReason ( ) != null ) { compiler . report ( JSError . make ( n , DEPRECATED_NAME_REASON , n . getString ( ) , docInfo . getDeprecationReason ( ) ) ) ; } else { compiler . report ( JSError . make ( n , DEPRECATED_NAME , n . getString ( ) ) ) ; } } }
Checks the given NAME node to ensure that access restrictions are obeyed .
35,079
private void checkPropertyDeprecation ( NodeTraversal t , PropertyReference propRef ) { if ( ! shouldEmitDeprecationWarning ( t , propRef ) ) { return ; } if ( propRef . getSourceNode ( ) . getParent ( ) . isNew ( ) ) { return ; } ObjectType objectType = castToObject ( dereference ( propRef . getReceiverType ( ) ) ) ; String propertyName = propRef . getName ( ) ; if ( objectType != null ) { String deprecationInfo = getPropertyDeprecationInfo ( objectType , propertyName ) ; if ( deprecationInfo != null ) { if ( ! deprecationInfo . isEmpty ( ) ) { compiler . report ( JSError . make ( propRef . getSourceNode ( ) , DEPRECATED_PROP_REASON , propertyName , propRef . getReadableTypeNameOrDefault ( ) , deprecationInfo ) ) ; } else { compiler . report ( JSError . make ( propRef . getSourceNode ( ) , DEPRECATED_PROP , propertyName , propRef . getReadableTypeNameOrDefault ( ) ) ) ; } } } }
Checks the given GETPROP node to ensure that access restrictions are obeyed .
35,080
private void checkKeyVisibilityConvention ( Node key , Node parent ) { JSDocInfo info = key . getJSDocInfo ( ) ; if ( info == null ) { return ; } if ( ! isPrivateByConvention ( key . getString ( ) ) ) { return ; } Node assign = parent . getParent ( ) ; if ( assign == null || ! assign . isAssign ( ) ) { return ; } Node left = assign . getFirstChild ( ) ; if ( ! left . isGetProp ( ) || ! left . getLastChild ( ) . getString ( ) . equals ( "prototype" ) ) { return ; } Visibility declaredVisibility = info . getVisibility ( ) ; if ( declaredVisibility != Visibility . INHERITED && declaredVisibility != Visibility . PRIVATE ) { compiler . report ( JSError . make ( key , CONVENTION_MISMATCH ) ) ; } }
Determines whether the given OBJECTLIT property visibility violates the coding convention .
35,081
private void checkNameVisibility ( Scope scope , Node name ) { if ( ! name . isName ( ) ) { return ; } Var var = scope . getVar ( name . getString ( ) ) ; if ( var == null ) { return ; } Visibility v = checkPrivateNameConvention ( AccessControlUtils . getEffectiveNameVisibility ( name , var , defaultVisibilityForFiles ) , name ) ; switch ( v ) { case PACKAGE : if ( ! isPackageAccessAllowed ( var , name ) ) { compiler . report ( JSError . make ( name , BAD_PACKAGE_PROPERTY_ACCESS , name . getString ( ) , var . getSourceFile ( ) . getName ( ) ) ) ; } break ; case PRIVATE : if ( ! isPrivateAccessAllowed ( var , name ) ) { compiler . report ( JSError . make ( name , BAD_PRIVATE_GLOBAL_ACCESS , name . getString ( ) , var . getSourceFile ( ) . getName ( ) ) ) ; } break ; default : break ; } }
Reports an error if the given name is not visible in the current context .
35,082
private void checkFinalClassOverrides ( Node ctor ) { if ( ! isFunctionOrClass ( ctor ) ) { return ; } JSType type = ctor . getJSType ( ) . toMaybeFunctionType ( ) ; if ( type != null && type . isConstructor ( ) ) { JSType finalParentClass = getSuperClassInstanceIfFinal ( bestInstanceTypeForMethodOrCtor ( ctor ) ) ; if ( finalParentClass != null ) { compiler . report ( JSError . make ( ctor , EXTEND_FINAL_CLASS , type . getDisplayName ( ) , finalParentClass . getDisplayName ( ) ) ) ; } } }
Checks if a constructor is trying to override a final class .
35,083
static ObjectType getCanonicalInstance ( ObjectType obj ) { FunctionType ctor = obj . getConstructor ( ) ; return ctor == null ? obj : ctor . getInstanceType ( ) ; }
Return an object with the same nominal type as obj but without any possible extra properties that exist on obj .
35,084
private void checkPropertyVisibility ( PropertyReference propRef ) { if ( NodeUtil . isEs6ConstructorMemberFunctionDef ( propRef . getSourceNode ( ) ) ) { return ; } JSType rawReferenceType = typeOrUnknown ( propRef . getReceiverType ( ) ) . autobox ( ) ; ObjectType referenceType = castToObject ( rawReferenceType ) ; String propertyName = propRef . getName ( ) ; boolean isPrivateByConvention = isPrivateByConvention ( propertyName ) ; if ( isPrivateByConvention && propertyIsDeclaredButNotPrivate ( propRef ) ) { compiler . report ( JSError . make ( propRef . getSourceNode ( ) , CONVENTION_MISMATCH ) ) ; return ; } StaticSourceFile definingSource = AccessControlUtils . getDefiningSource ( propRef . getSourceNode ( ) , referenceType , propertyName ) ; boolean isOverride = propRef . isDocumentedDeclaration ( ) || propRef . isOverride ( ) ; ObjectType objectType = AccessControlUtils . getObjectType ( referenceType , isOverride , propertyName ) ; Visibility fileOverviewVisibility = defaultVisibilityForFiles . get ( definingSource ) ; Visibility visibility = getEffectivePropertyVisibility ( propRef , referenceType , defaultVisibilityForFiles , enforceCodingConventions ? compiler . getCodingConvention ( ) : null ) ; if ( isOverride ) { Visibility overriding = getOverridingPropertyVisibility ( propRef ) ; if ( overriding != null ) { checkPropertyOverrideVisibilityIsSame ( overriding , visibility , fileOverviewVisibility , propRef ) ; } } JSType reportType = rawReferenceType ; if ( objectType != null ) { Node node = objectType . getOwnPropertyDefSite ( propertyName ) ; if ( node == null ) { return ; } reportType = objectType ; definingSource = node . getStaticSourceFile ( ) ; } else if ( ! isPrivateByConvention && fileOverviewVisibility == null ) { return ; } StaticSourceFile referenceSource = propRef . getSourceNode ( ) . getStaticSourceFile ( ) ; if ( isOverride ) { boolean sameInput = referenceSource != null && referenceSource . getName ( ) . equals ( definingSource . getName ( ) ) ; checkPropertyOverrideVisibility ( propRef , visibility , fileOverviewVisibility , reportType , sameInput ) ; } else { checkPropertyAccessVisibility ( propRef , visibility , reportType , referenceSource , definingSource ) ; } }
Reports an error if the given property is not visible in the current context .
35,085
private boolean canAccessDeprecatedTypes ( NodeTraversal t ) { Node scopeRoot = t . getClosestHoistScopeRoot ( ) ; if ( NodeUtil . isFunctionBlock ( scopeRoot ) ) { scopeRoot = scopeRoot . getParent ( ) ; } Node scopeRootParent = scopeRoot . getParent ( ) ; return ( deprecationDepth > 0 ) || ( getTypeDeprecationInfo ( getTypeOfThis ( scopeRoot ) ) != null ) || ( scopeRootParent != null && scopeRootParent . isAssign ( ) && getTypeDeprecationInfo ( bestInstanceTypeForMethodOrCtor ( scopeRoot ) ) != null ) ; }
Returns whether it s currently OK to access deprecated names and properties .
35,086
private static String getTypeDeprecationInfo ( JSType type ) { if ( type == null ) { return null ; } String depReason = getDeprecationReason ( type . getJSDocInfo ( ) ) ; if ( depReason != null ) { return depReason ; } ObjectType objType = castToObject ( type ) ; if ( objType != null ) { ObjectType implicitProto = objType . getImplicitPrototype ( ) ; if ( implicitProto != null ) { return getTypeDeprecationInfo ( implicitProto ) ; } } return null ; }
Returns the deprecation reason for the type if it is marked as being deprecated . Returns empty string if the type is deprecated but no reason was given . Returns null if the type is not deprecated .
35,087
private boolean isPropertyDeclaredConstant ( ObjectType objectType , String prop ) { if ( enforceCodingConventions && compiler . getCodingConvention ( ) . isConstant ( prop ) ) { return true ; } for ( ; objectType != null ; objectType = objectType . getImplicitPrototype ( ) ) { JSDocInfo docInfo = objectType . getOwnPropertyJSDocInfo ( prop ) ; if ( docInfo != null && docInfo . isConstant ( ) ) { return true ; } } return false ; }
Returns if a property is declared constant .
35,088
private static String getPropertyDeprecationInfo ( ObjectType type , String prop ) { String depReason = getDeprecationReason ( type . getOwnPropertyJSDocInfo ( prop ) ) ; if ( depReason != null ) { return depReason ; } ObjectType implicitProto = type . getImplicitPrototype ( ) ; if ( implicitProto != null ) { return getPropertyDeprecationInfo ( implicitProto , prop ) ; } return null ; }
Returns the deprecation reason for the property if it is marked as being deprecated . Returns empty string if the property is deprecated but no reason was given . Returns null if the property is not deprecated .
35,089
private void visitArrayLitOrCallWithSpread ( Node spreadParent ) { if ( spreadParent . isArrayLit ( ) ) { visitArrayLitContainingSpread ( spreadParent ) ; } else if ( spreadParent . isCall ( ) ) { visitCallContainingSpread ( spreadParent ) ; } else { checkArgument ( spreadParent . isNew ( ) , spreadParent ) ; visitNewWithSpread ( spreadParent ) ; } }
Processes array literals or calls to eliminate spreads .
35,090
private void visitArrayLitContainingSpread ( Node spreadParent ) { checkArgument ( spreadParent . isArrayLit ( ) ) ; List < Node > groups = extractSpreadGroups ( spreadParent ) ; final Node baseArrayLit ; if ( groups . get ( 0 ) . isArrayLit ( ) ) { baseArrayLit = groups . remove ( 0 ) ; } else { baseArrayLit = arrayLitWithJSType ( ) ; } final Node joinedGroups ; if ( groups . isEmpty ( ) ) { joinedGroups = baseArrayLit ; } else { Node concat = IR . getprop ( baseArrayLit , IR . string ( "concat" ) ) . setJSType ( concatFnType ) ; joinedGroups = IR . call ( concat , groups . toArray ( new Node [ 0 ] ) ) ; } joinedGroups . useSourceInfoIfMissingFromForTree ( spreadParent ) ; joinedGroups . setJSType ( arrayType ) ; spreadParent . replaceWith ( joinedGroups ) ; compiler . reportChangeToEnclosingScope ( joinedGroups ) ; }
Processes array literals containing spreads .
35,091
private void visitCallContainingSpread ( Node spreadParent ) { checkArgument ( spreadParent . isCall ( ) ) ; Node callee = spreadParent . getFirstChild ( ) ; boolean calleeMayHaveSideEffects = NodeUtil . mayHaveSideEffects ( callee , compiler ) ; spreadParent . removeChild ( callee ) ; final Node joinedGroups ; if ( spreadParent . hasOneChild ( ) && isSpreadOfArguments ( spreadParent . getOnlyChild ( ) ) ) { joinedGroups = spreadParent . removeFirstChild ( ) . removeFirstChild ( ) ; } else { List < Node > groups = extractSpreadGroups ( spreadParent ) ; checkState ( ! groups . isEmpty ( ) ) ; if ( groups . size ( ) == 1 ) { joinedGroups = groups . remove ( 0 ) ; } else { Node baseArrayLit = groups . get ( 0 ) . isArrayLit ( ) ? groups . remove ( 0 ) : arrayLitWithJSType ( ) ; Node concat = IR . getprop ( baseArrayLit , IR . string ( "concat" ) ) . setJSType ( concatFnType ) ; joinedGroups = IR . call ( concat , groups . toArray ( new Node [ 0 ] ) ) . setJSType ( arrayType ) ; } joinedGroups . setJSType ( arrayType ) ; } final Node callToApply ; if ( calleeMayHaveSideEffects && callee . isGetProp ( ) ) { JSType receiverType = callee . getFirstChild ( ) . getJSType ( ) ; Node freshVar = IR . name ( FRESH_SPREAD_VAR + compiler . getUniqueNameIdSupplier ( ) . get ( ) ) . setJSType ( receiverType ) ; Node freshVarDeclaration = IR . var ( freshVar . cloneTree ( ) ) ; Node statementContainingSpread = NodeUtil . getEnclosingStatement ( spreadParent ) ; freshVarDeclaration . useSourceInfoIfMissingFromForTree ( statementContainingSpread ) ; statementContainingSpread . getParent ( ) . addChildBefore ( freshVarDeclaration , statementContainingSpread ) ; callee . addChildToFront ( IR . assign ( freshVar . cloneTree ( ) , callee . removeFirstChild ( ) ) . setJSType ( receiverType ) ) ; callToApply = IR . call ( getpropInferringJSType ( callee , "apply" ) , freshVar . cloneTree ( ) , joinedGroups ) ; } else { Node context = ( callee . isGetProp ( ) || callee . isGetElem ( ) ) ? callee . getFirstChild ( ) . cloneTree ( ) : nullWithJSType ( ) ; callToApply = IR . call ( getpropInferringJSType ( callee , "apply" ) , context , joinedGroups ) ; } callToApply . setJSType ( spreadParent . getJSType ( ) ) ; callToApply . useSourceInfoIfMissingFromForTree ( spreadParent ) ; spreadParent . replaceWith ( callToApply ) ; compiler . reportChangeToEnclosingScope ( callToApply ) ; }
Processes calls containing spreads .
35,092
private void visitNewWithSpread ( Node spreadParent ) { checkArgument ( spreadParent . isNew ( ) ) ; Node callee = spreadParent . removeFirstChild ( ) ; List < Node > groups = extractSpreadGroups ( spreadParent ) ; final Node baseArrayLit ; if ( groups . get ( 0 ) . isArrayLit ( ) ) { baseArrayLit = groups . remove ( 0 ) ; } else { baseArrayLit = arrayLitWithJSType ( ) ; } baseArrayLit . addChildToFront ( nullWithJSType ( ) ) ; Node joinedGroups = groups . isEmpty ( ) ? baseArrayLit : IR . call ( IR . getprop ( baseArrayLit , IR . string ( "concat" ) ) . setJSType ( concatFnType ) , groups . toArray ( new Node [ 0 ] ) ) . setJSType ( arrayType ) ; if ( FeatureSet . ES3 . contains ( compiler . getOptions ( ) . getOutputFeatureSet ( ) ) ) { Es6ToEs3Util . cannotConvert ( compiler , spreadParent , "\"...\" passed to a constructor (consider using --language_out=ES5)" ) ; } Node bindApply = getpropInferringJSType ( IR . getprop ( getpropInferringJSType ( IR . name ( "Function" ) . setJSType ( functionFunctionType ) , "prototype" ) , "bind" ) . setJSType ( u2uFunctionType ) , "apply" ) ; Node result = IR . newNode ( callInferringJSType ( bindApply , callee , joinedGroups ) ) . setJSType ( spreadParent . getJSType ( ) ) ; result . useSourceInfoIfMissingFromForTree ( spreadParent ) ; spreadParent . replaceWith ( result ) ; compiler . reportChangeToEnclosingScope ( result ) ; }
Processes new calls containing spreads .
35,093
private static boolean checkPostExpressions ( Node n , Node expressionRoot , Predicate < Node > predicate ) { for ( Node p = n ; p != expressionRoot ; p = p . getParent ( ) ) { for ( Node cur = p . getNext ( ) ; cur != null ; cur = cur . getNext ( ) ) { if ( predicate . apply ( cur ) ) { return true ; } } } return false ; }
Given an expression by its root and sub - expression n return true if the predicate is true for some expression evaluated after n .
35,094
private static boolean checkPreExpressions ( Node n , Node expressionRoot , Predicate < Node > predicate ) { for ( Node p = n ; p != expressionRoot ; p = p . getParent ( ) ) { Node oldestSibling = p . getParent ( ) . getFirstChild ( ) ; if ( oldestSibling . isDestructuringPattern ( ) ) { if ( p . isDestructuringPattern ( ) ) { if ( p . getNext ( ) != null && predicate . apply ( p . getNext ( ) ) ) { return true ; } } continue ; } for ( Node cur = oldestSibling ; cur != p ; cur = cur . getNext ( ) ) { if ( predicate . apply ( cur ) ) { return true ; } } } return false ; }
Given an expression by its root and sub - expression n return true if the predicate is true for some expression evaluated before n .
35,095
static PolymerClassDefinition extractFromClassNode ( Node classNode , AbstractCompiler compiler , GlobalNamespace globalNames ) { checkState ( classNode != null && classNode . isClass ( ) ) ; Node propertiesDescriptor = null ; Node propertiesGetter = NodeUtil . getFirstGetterMatchingKey ( NodeUtil . getClassMembers ( classNode ) , "properties" ) ; if ( propertiesGetter != null ) { if ( ! propertiesGetter . isStaticMember ( ) ) { compiler . report ( JSError . make ( classNode , PolymerPassErrors . POLYMER_CLASS_PROPERTIES_NOT_STATIC ) ) ; } else { for ( Node child : NodeUtil . getFunctionBody ( propertiesGetter . getFirstChild ( ) ) . children ( ) ) { if ( child . isReturn ( ) ) { if ( child . hasChildren ( ) && child . getFirstChild ( ) . isObjectLit ( ) ) { propertiesDescriptor = child . getFirstChild ( ) ; break ; } else { compiler . report ( JSError . make ( propertiesGetter , PolymerPassErrors . POLYMER_CLASS_PROPERTIES_INVALID ) ) ; } } } } } Node target ; if ( NodeUtil . isNameDeclaration ( classNode . getGrandparent ( ) ) ) { target = IR . name ( classNode . getParent ( ) . getString ( ) ) ; } else if ( classNode . getParent ( ) . isAssign ( ) && classNode . getParent ( ) . getFirstChild ( ) . isQualifiedName ( ) ) { target = classNode . getParent ( ) . getFirstChild ( ) ; } else if ( ! classNode . getFirstChild ( ) . isEmpty ( ) ) { target = classNode . getFirstChild ( ) ; } else { compiler . report ( JSError . make ( classNode , PolymerPassErrors . POLYMER_CLASS_UNNAMED ) ) ; return null ; } JSDocInfo classInfo = NodeUtil . getBestJSDocInfo ( classNode ) ; JSDocInfo ctorInfo = null ; Node constructor = NodeUtil . getEs6ClassConstructorMemberFunctionDef ( classNode ) ; if ( constructor != null ) { ctorInfo = NodeUtil . getBestJSDocInfo ( constructor ) ; } List < MemberDefinition > allProperties = PolymerPassStaticUtils . extractProperties ( propertiesDescriptor , DefinitionType . ES6Class , compiler , constructor ) ; List < MemberDefinition > methods = new ArrayList < > ( ) ; for ( Node keyNode : NodeUtil . getClassMembers ( classNode ) . children ( ) ) { if ( ! keyNode . isMemberFunctionDef ( ) ) { continue ; } methods . add ( new MemberDefinition ( NodeUtil . getBestJSDocInfo ( keyNode ) , keyNode , keyNode . getFirstChild ( ) ) ) ; } return new PolymerClassDefinition ( DefinitionType . ES6Class , classNode , target , propertiesDescriptor , classInfo , new MemberDefinition ( ctorInfo , null , constructor ) , null , allProperties , methods , null , null ) ; }
Validates the class definition and if valid extracts the class definition from the AST . As opposed to the Polymer 1 extraction this operation is non - destructive .
35,096
private static void overwriteMembersIfPresent ( List < MemberDefinition > list , List < MemberDefinition > newMembers ) { for ( MemberDefinition newMember : newMembers ) { for ( MemberDefinition member : list ) { if ( member . name . getString ( ) . equals ( newMember . name . getString ( ) ) ) { list . remove ( member ) ; break ; } } list . add ( newMember ) ; } }
Appends a list of new MemberDefinitions to the end of a list and removes any previous MemberDefinition in the list which has the same name as the new member .
35,097
private void tryReplaceSuper ( Node superNode ) { checkState ( ! superclasses . isEmpty ( ) , "`super` cannot appear outside a function" ) ; Optional < Node > currentSuperclass = superclasses . peek ( ) ; if ( ! currentSuperclass . isPresent ( ) || ! currentSuperclass . get ( ) . isQualifiedName ( ) ) { return ; } Node fullyQualifiedSuperRef = currentSuperclass . get ( ) . cloneTree ( ) ; superNode . replaceWith ( fullyQualifiedSuperRef ) ; compiler . reportChangeToEnclosingScope ( fullyQualifiedSuperRef ) ; }
Replaces super with Super . Class if in a static class method with a qname superclass
35,098
private boolean isSafeValue ( Scope scope , Node argument ) { if ( NodeUtil . isSomeCompileTimeConstStringValue ( argument ) ) { return true ; } else if ( argument . isAdd ( ) ) { Node left = argument . getFirstChild ( ) ; Node right = argument . getLastChild ( ) ; return isSafeValue ( scope , left ) && isSafeValue ( scope , right ) ; } else if ( argument . isName ( ) ) { String name = argument . getString ( ) ; Var var = scope . getVar ( name ) ; if ( var == null || ! var . isInferredConst ( ) ) { return false ; } Node initialValue = var . getInitialValue ( ) ; if ( initialValue == null ) { return false ; } return isSafeValue ( var . getScope ( ) , initialValue ) ; } return false ; }
Checks if the method call argument is made of constant string literals .
35,099
final void remove ( AbstractCompiler compiler ) { if ( isDetached ( ) ) { return ; } Node statement = getRemovableNode ( ) ; NodeUtil . deleteNode ( statement , compiler ) ; statement . removeChildren ( ) ; }
Remove this potential declaration completely . Usually this is because the same symbol has already been declared in this file .