idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
35,200
private ParseTree parseLabelledStatement ( ) { SourcePosition start = getTreeStartLocation ( ) ; IdentifierToken name = eatId ( ) ; eat ( TokenType . COLON ) ; return new LabelledStatementTree ( getTreeLocation ( start ) , name , parseStatement ( ) ) ; }
12 . 12 Labelled Statement
35,201
private ParseTree parseThrowStatement ( ) { SourcePosition start = getTreeStartLocation ( ) ; eat ( TokenType . THROW ) ; ParseTree value = null ; if ( peekImplicitSemiColon ( ) ) { reportError ( "semicolon/newline not allowed after 'throw'" ) ; } else { value = parseExpression ( ) ; } eatPossibleImplicitSemiColon ( ) ; return new ThrowStatementTree ( getTreeLocation ( start ) , value ) ; }
12 . 13 Throw Statement
35,202
private ParseTree parseTryStatement ( ) { SourcePosition start = getTreeStartLocation ( ) ; eat ( TokenType . TRY ) ; ParseTree body = parseBlock ( ) ; ParseTree catchBlock = null ; if ( peek ( TokenType . CATCH ) ) { catchBlock = parseCatch ( ) ; } ParseTree finallyBlock = null ; if ( peek ( TokenType . FINALLY ) ) { finallyBlock = parseFinallyBlock ( ) ; } if ( catchBlock == null && finallyBlock == null ) { reportError ( "'catch' or 'finally' expected." ) ; } return new TryStatementTree ( getTreeLocation ( start ) , body , catchBlock , finallyBlock ) ; }
12 . 14 Try Statement
35,203
private ParseTree parseDebuggerStatement ( ) { SourcePosition start = getTreeStartLocation ( ) ; eat ( TokenType . DEBUGGER ) ; eatPossibleImplicitSemiColon ( ) ; return new DebuggerStatementTree ( getTreeLocation ( start ) ) ; }
12 . 15 The Debugger Statement
35,204
private ParseTree parsePrimaryExpression ( ) { switch ( peekType ( ) ) { case CLASS : return parseClassExpression ( ) ; case SUPER : return parseSuperExpression ( ) ; case THIS : return parseThisExpression ( ) ; case IMPORT : return parseDynamicImportExpression ( ) ; case IDENTIFIER : case TYPE : case DECLARE : case MODULE : case NAMESPACE : return parseIdentifierExpression ( ) ; case NUMBER : case STRING : case TRUE : case FALSE : case NULL : return parseLiteralExpression ( ) ; case NO_SUBSTITUTION_TEMPLATE : case TEMPLATE_HEAD : return parseTemplateLiteral ( null ) ; case OPEN_SQUARE : return parseArrayInitializer ( ) ; case OPEN_CURLY : return parseObjectLiteral ( ) ; case OPEN_PAREN : return parseCoverParenthesizedExpressionAndArrowParameterList ( ) ; case SLASH : case SLASH_EQUAL : return parseRegularExpressionLiteral ( ) ; default : return parseMissingPrimaryExpression ( ) ; } }
11 . 1 Primary Expressions
35,205
private ParseTree parseArrayLiteral ( ) { SourcePosition start = getTreeStartLocation ( ) ; ImmutableList . Builder < ParseTree > elements = ImmutableList . builder ( ) ; eat ( TokenType . OPEN_SQUARE ) ; Token trailingCommaToken = null ; while ( peek ( TokenType . COMMA ) || peek ( TokenType . SPREAD ) || peekAssignmentExpression ( ) ) { trailingCommaToken = null ; if ( peek ( TokenType . COMMA ) ) { elements . add ( new NullTree ( getTreeLocation ( getTreeStartLocation ( ) ) ) ) ; } else { if ( peek ( TokenType . SPREAD ) ) { recordFeatureUsed ( Feature . SPREAD_EXPRESSIONS ) ; elements . add ( parseSpreadExpression ( ) ) ; } else { elements . add ( parseAssignmentExpression ( ) ) ; } } if ( ! peek ( TokenType . CLOSE_SQUARE ) ) { trailingCommaToken = eat ( TokenType . COMMA ) ; } } eat ( TokenType . CLOSE_SQUARE ) ; maybeReportTrailingComma ( trailingCommaToken ) ; return new ArrayLiteralExpressionTree ( getTreeLocation ( start ) , elements . build ( ) ) ; }
11 . 1 . 4 Array Literal Expression
35,206
private ParseTree parseObjectLiteral ( ) { SourcePosition start = getTreeStartLocation ( ) ; ImmutableList . Builder < ParseTree > result = ImmutableList . builder ( ) ; eat ( TokenType . OPEN_CURLY ) ; Token commaToken = null ; while ( peek ( TokenType . SPREAD ) || peekPropertyNameOrComputedProp ( 0 ) || peek ( TokenType . STAR ) || peekAccessibilityModifier ( ) ) { commaToken = null ; result . add ( parsePropertyAssignment ( ) ) ; commaToken = eatOpt ( TokenType . COMMA ) ; if ( commaToken == null ) { break ; } } eat ( TokenType . CLOSE_CURLY ) ; maybeReportTrailingComma ( commaToken ) ; return new ObjectLiteralExpressionTree ( getTreeLocation ( start ) , result . build ( ) ) ; }
11 . 1 . 4 Object Literal Expression
35,207
private ParseTree transformLeftHandSideExpression ( ParseTree tree ) { switch ( tree . type ) { case ARRAY_LITERAL_EXPRESSION : case OBJECT_LITERAL_EXPRESSION : resetScanner ( tree ) ; return parseLeftHandSidePattern ( ) ; default : return tree ; } }
Transforms a LeftHandSideExpression into a LeftHandSidePattern if possible . This returns the transformed tree if it parses as a LeftHandSidePattern otherwise it returns the original tree .
35,208
private ParseTree parseConditional ( Expression expressionIn ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree condition = parseLogicalOR ( expressionIn ) ; if ( peek ( TokenType . QUESTION ) ) { eat ( TokenType . QUESTION ) ; ParseTree left = parseAssignment ( expressionIn ) ; eat ( TokenType . COLON ) ; ParseTree right = parseAssignment ( expressionIn ) ; return new ConditionalExpressionTree ( getTreeLocation ( start ) , condition , left , right ) ; } return condition ; }
11 . 12 Conditional Expression
35,209
private ParseTree parseLogicalOR ( Expression expressionIn ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree left = parseLogicalAND ( expressionIn ) ; while ( peek ( TokenType . OR ) ) { Token operator = eat ( TokenType . OR ) ; ParseTree right = parseLogicalAND ( expressionIn ) ; left = new BinaryOperatorTree ( getTreeLocation ( start ) , left , operator , right ) ; } return left ; }
11 . 11 Logical OR
35,210
private ParseTree parseEquality ( Expression expressionIn ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree left = parseRelational ( expressionIn ) ; while ( peekEqualityOperator ( ) ) { Token operator = nextToken ( ) ; ParseTree right = parseRelational ( expressionIn ) ; left = new BinaryOperatorTree ( getTreeLocation ( start ) , left , operator , right ) ; } return left ; }
11 . 9 Equality Expression
35,211
private ParseTree parseRelational ( Expression expressionIn ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree left = parseShiftExpression ( ) ; while ( peekRelationalOperator ( expressionIn ) ) { Token operator = nextToken ( ) ; ParseTree right = parseShiftExpression ( ) ; left = new BinaryOperatorTree ( getTreeLocation ( start ) , left , operator , right ) ; } return left ; }
11 . 8 Relational
35,212
private ParseTree parseShiftExpression ( ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree left = parseAdditiveExpression ( ) ; while ( peekShiftOperator ( ) ) { Token operator = nextToken ( ) ; ParseTree right = parseAdditiveExpression ( ) ; left = new BinaryOperatorTree ( getTreeLocation ( start ) , left , operator , right ) ; } return left ; }
11 . 7 Shift Expression
35,213
private ParseTree parseAdditiveExpression ( ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree left = parseMultiplicativeExpression ( ) ; while ( peekAdditiveOperator ( ) ) { Token operator = nextToken ( ) ; ParseTree right = parseMultiplicativeExpression ( ) ; left = new BinaryOperatorTree ( getTreeLocation ( start ) , left , operator , right ) ; } return left ; }
11 . 6 Additive Expression
35,214
private ParseTree parseMultiplicativeExpression ( ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree left = parseExponentiationExpression ( ) ; while ( peekMultiplicativeOperator ( ) ) { Token operator = nextToken ( ) ; ParseTree right = parseExponentiationExpression ( ) ; left = new BinaryOperatorTree ( getTreeLocation ( start ) , left , operator , right ) ; } return left ; }
11 . 5 Multiplicative Expression
35,215
private ParseTree parseUnaryExpression ( ) { SourcePosition start = getTreeStartLocation ( ) ; if ( peekUnaryOperator ( ) ) { Token operator = nextToken ( ) ; ParseTree operand = parseUnaryExpression ( ) ; return new UnaryExpressionTree ( getTreeLocation ( start ) , operator , operand ) ; } else if ( peekAwaitExpression ( ) ) { return parseAwaitExpression ( ) ; } else { return parseUpdateExpression ( ) ; } }
11 . 4 Unary Operator
35,216
@ SuppressWarnings ( "incomplete-switch" ) private ParseTree parseLeftHandSideExpression ( ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree operand = parseNewExpression ( ) ; if ( ! ( operand instanceof NewExpressionTree ) || ( ( NewExpressionTree ) operand ) . arguments != null ) { while ( peekCallSuffix ( ) ) { switch ( peekType ( ) ) { case OPEN_PAREN : ArgumentListTree arguments = parseArguments ( ) ; operand = new CallExpressionTree ( getTreeLocation ( start ) , operand , arguments ) ; break ; case OPEN_SQUARE : eat ( TokenType . OPEN_SQUARE ) ; ParseTree member = parseExpression ( ) ; eat ( TokenType . CLOSE_SQUARE ) ; operand = new MemberLookupExpressionTree ( getTreeLocation ( start ) , operand , member ) ; break ; case PERIOD : eat ( TokenType . PERIOD ) ; IdentifierToken id = eatIdOrKeywordAsId ( ) ; operand = new MemberExpressionTree ( getTreeLocation ( start ) , operand , id ) ; break ; case NO_SUBSTITUTION_TEMPLATE : case TEMPLATE_HEAD : operand = parseTemplateLiteral ( operand ) ; break ; default : throw new AssertionError ( "unexpected case: " + peekType ( ) ) ; } } } return operand ; }
Also inlines the call expression productions
35,217
private ParseTree parseMemberExpressionNoNew ( ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree operand ; if ( peekAsyncFunctionStart ( ) ) { operand = parseAsyncFunctionExpression ( ) ; } else if ( peekFunction ( ) ) { operand = parseFunctionExpression ( ) ; } else { operand = parsePrimaryExpression ( ) ; } while ( peekMemberExpressionSuffix ( ) ) { switch ( peekType ( ) ) { case OPEN_SQUARE : eat ( TokenType . OPEN_SQUARE ) ; ParseTree member = parseExpression ( ) ; eat ( TokenType . CLOSE_SQUARE ) ; operand = new MemberLookupExpressionTree ( getTreeLocation ( start ) , operand , member ) ; break ; case PERIOD : eat ( TokenType . PERIOD ) ; IdentifierToken id = eatIdOrKeywordAsId ( ) ; operand = new MemberExpressionTree ( getTreeLocation ( start ) , operand , id ) ; break ; case NO_SUBSTITUTION_TEMPLATE : case TEMPLATE_HEAD : operand = parseTemplateLiteral ( operand ) ; break ; default : throw new RuntimeException ( "unreachable" ) ; } } return operand ; }
11 . 2 Member Expression without the new production
35,218
private ParseTree parsePatternAssignmentTarget ( PatternKind patternKind ) { SourcePosition start = getTreeStartLocation ( ) ; ParseTree assignmentTarget ; assignmentTarget = parsePatternAssignmentTargetNoDefault ( patternKind ) ; if ( peek ( TokenType . EQUAL ) ) { eat ( TokenType . EQUAL ) ; ParseTree defaultValue = parseAssignmentExpression ( ) ; assignmentTarget = new DefaultParameterTree ( getTreeLocation ( start ) , assignmentTarget , defaultValue ) ; } return assignmentTarget ; }
A PatternAssignmentTarget is the location where the assigned value gets stored including an optional default value .
35,219
private IdentifierToken eatId ( ) { if ( peekId ( ) ) { return eatIdOrKeywordAsId ( ) ; } else { reportExpectedError ( peekToken ( ) , TokenType . IDENTIFIER ) ; if ( peekIdOrKeyword ( ) ) { return eatIdOrKeywordAsId ( ) ; } else { return null ; } } }
Consumes an identifier token that is not a reserved word .
35,220
private IdentifierToken eatIdOrKeywordAsId ( ) { Token token = nextToken ( ) ; if ( token . type == TokenType . IDENTIFIER ) { return ( IdentifierToken ) token ; } else if ( Keywords . isKeyword ( token . type ) ) { return new IdentifierToken ( token . location , Keywords . get ( token . type ) . toString ( ) ) ; } else { reportExpectedError ( token , TokenType . IDENTIFIER ) ; } return null ; }
Consumes an identifier token that may be a reserved word i . e . an IdentifierName not necessarily an Identifier .
35,221
private Token eat ( TokenType expectedTokenType ) { Token token = nextToken ( ) ; if ( token . type != expectedTokenType ) { reportExpectedError ( token , expectedTokenType ) ; return null ; } return token ; }
Consumes the next token . If the consumed token is not of the expected type then report an error and return null . Otherwise return the consumed token .
35,222
private Token nextToken ( ) { Token token = scanner . nextToken ( ) ; lastSourcePosition = token . location . end ; return token ; }
Consumes the next token and returns it . Will return a never ending stream of TokenType . END_OF_FILE at the end of the file so callers don t have to check for EOF explicitly .
35,223
private LiteralToken nextRegularExpressionLiteralToken ( ) { LiteralToken token = scanner . nextRegularExpressionLiteralToken ( ) ; lastSourcePosition = token . location . end ; return token ; }
Consumes a regular expression literal token and returns it .
35,224
private TemplateLiteralToken nextTemplateLiteralToken ( ) { TemplateLiteralToken token = scanner . nextTemplateLiteralToken ( ) ; lastSourcePosition = token . location . end ; return token ; }
Consumes a template literal token and returns it .
35,225
private Parser createLookaheadParser ( ) { return new Parser ( config , new LookaheadErrorReporter ( ) , this . scanner . getFile ( ) , this . scanner . getOffset ( ) , inGeneratorContext ( ) ) ; }
Forks the parser at the current point and returns a new parser for speculative parsing .
35,226
private FlowScope maybeRestrictName ( FlowScope blindScope , Node node , JSType originalType , JSType restrictedType ) { if ( restrictedType != null && restrictedType != originalType ) { return declareNameInScope ( blindScope , node , restrictedType ) ; } return blindScope ; }
If the restrictedType differs from the originalType then we should branch the current flow scope and create a new flow scope with the name declared with the new type .
35,227
private FlowScope caseIn ( Node object , String propertyName , FlowScope blindScope ) { JSType jsType = object . getJSType ( ) ; jsType = this . getRestrictedWithoutNull ( jsType ) ; jsType = this . getRestrictedWithoutUndefined ( jsType ) ; boolean hasProperty = false ; ObjectType objectType = ObjectType . cast ( jsType ) ; if ( objectType != null ) { hasProperty = objectType . hasProperty ( propertyName ) ; } if ( ! hasProperty ) { String qualifiedName = object . getQualifiedName ( ) ; if ( qualifiedName != null ) { String propertyQualifiedName = qualifiedName + "." + propertyName ; if ( blindScope . getSlot ( propertyQualifiedName ) == null ) { JSType unknownType = typeRegistry . getNativeType ( JSTypeNative . UNKNOWN_TYPE ) ; return blindScope . inferQualifiedSlot ( object , propertyQualifiedName , unknownType , unknownType , false ) ; } } } return blindScope ; }
Given property in object ensures that the object has the property in the informed scope by defining it as a qualified name if the object type lacks the property and it s not in the blind scope .
35,228
private static FlowScope unwrap ( FlowScope scope ) { while ( scope instanceof RefinementTrackingFlowScope ) { scope = ( ( RefinementTrackingFlowScope ) scope ) . delegate ; } return scope ; }
Unwraps any RefinementTrackingFlowScopes .
35,229
public Node parseHelperCode ( Reducer reducer ) { Node root = compiler . parseSyntheticCode ( reducer . getClass ( ) + ":helper" , reducer . getHelperSource ( ) ) ; return ( root != null ) ? root . removeFirstChild ( ) : null ; }
Parse helper code needed by a reducer .
35,230
private static ImmutableMap < String , Annotation > buildAnnotations ( Iterable < String > whitelist ) { ImmutableMap . Builder < String , Annotation > annotationsBuilder = ImmutableMap . builder ( ) ; annotationsBuilder . putAll ( Annotation . recognizedAnnotations ) ; for ( String unrecognizedAnnotation : whitelist ) { if ( ! unrecognizedAnnotation . isEmpty ( ) && ! Annotation . recognizedAnnotations . containsKey ( unrecognizedAnnotation ) ) { annotationsBuilder . put ( unrecognizedAnnotation , Annotation . NOT_IMPLEMENTED ) ; } } return annotationsBuilder . build ( ) ; }
Create the annotation names from the user - specified annotation whitelist .
35,231
void processScope ( Scope scope ) { boolean shouldAddToBlockStack = ! scope . isHoistScope ( ) ; this . narrowScope = scope ; if ( shouldAddToBlockStack ) { blockStack . add ( new BasicBlock ( null , scope . getRootNode ( ) ) ) ; } ( new NodeTraversal ( compiler , this , scopeCreator ) ) . traverseAtScope ( scope ) ; if ( shouldAddToBlockStack ) { pop ( blockStack ) ; } this . narrowScope = null ; }
Targets reference collection to a particular scope .
35,232
public boolean shouldTraverse ( NodeTraversal nodeTraversal , Node n , Node parent ) { if ( NodeUtil . isHoistedFunctionDeclaration ( n ) ) { Node nameNode = n . getFirstChild ( ) ; Var functionVar = nodeTraversal . getScope ( ) . getVar ( nameNode . getString ( ) ) ; checkNotNull ( functionVar ) ; if ( finishedFunctionTraverse . contains ( functionVar ) ) { return false ; } startedFunctionTraverse . add ( functionVar ) ; } if ( isBlockBoundary ( n , parent ) ) { blockStack . add ( new BasicBlock ( peek ( blockStack ) , n ) ) ; } if ( ( n . isDefaultValue ( ) || n . isDestructuringLhs ( ) ) && n . hasTwoChildren ( ) ) { Scope scope = nodeTraversal . getScope ( ) ; nodeTraversal . traverseInnerNode ( n . getSecondChild ( ) , n , scope ) ; nodeTraversal . traverseInnerNode ( n . getFirstChild ( ) , n , scope ) ; return false ; } return true ; }
Updates block stack .
35,233
public void setPositionInformation ( int startLineno , int startCharno , int endLineno , int endCharno ) { if ( startLineno > endLineno ) { throw new IllegalStateException ( "Recorded bad position information\n" + "start-line: " + startLineno + "\n" + "end-line: " + endLineno ) ; } else if ( startLineno == endLineno && startCharno >= endCharno ) { throw new IllegalStateException ( "Recorded bad position information\n" + "line: " + startLineno + "\n" + "start-char: " + startCharno + "\n" + "end-char: " + endCharno ) ; } this . startLineno = startLineno ; this . startCharno = startCharno ; this . endLineno = endLineno ; this . endCharno = endCharno ; }
Sets the position information contained in this source position .
35,234
static String removeExtraneousSlashes ( String s ) { int lastNonSlash = NON_SLASH_MATCHER . lastIndexIn ( s ) ; if ( lastNonSlash != - 1 ) { s = s . substring ( 0 , lastNonSlash + 1 ) ; } return SLASH_MATCHER . collapseFrom ( s , '/' ) ; }
Removes extra slashes from a path . Leading slash is preserved trailing slash is stripped and any runs of more than one slash in the middle is replaced by a single slash .
35,235
public static String makeAbsolute ( String path , String rootPath ) { if ( ! isAbsolute ( path ) ) { path = rootPath + "/" + path ; } return collapseDots ( path ) ; }
Converts the given path into an absolute one . This prepends the given rootPath and removes all . s from the path . If an absolute path is given it will not be prefixed .
35,236
public static String makeRelative ( String basePath , String targetPath ) { if ( isAbsolute ( basePath ) != isAbsolute ( targetPath ) ) { throw new IllegalArgumentException ( "Paths must both be relative or both absolute.\n" + " basePath: " + basePath + "\n" + " targetPath: " + targetPath ) ; } basePath = collapseDots ( basePath ) ; targetPath = collapseDots ( targetPath ) ; String [ ] baseFragments = basePath . split ( "/" ) ; String [ ] targetFragments = targetPath . split ( "/" ) ; int i = - 1 ; do { i += 1 ; if ( i == baseFragments . length && i == targetFragments . length ) { return "." ; } else if ( i == baseFragments . length ) { return Joiner . on ( "/" ) . join ( Lists . newArrayList ( Arrays . asList ( targetFragments ) . listIterator ( i ) ) ) ; } else if ( i == targetFragments . length ) { return Strings . repeat ( "../" , baseFragments . length - i - 1 ) + ".." ; } } while ( baseFragments [ i ] . equals ( targetFragments [ i ] ) ) ; return Strings . repeat ( "../" , baseFragments . length - i ) + Joiner . on ( "/" ) . join ( Lists . newArrayList ( Arrays . asList ( targetFragments ) . listIterator ( i ) ) ) ; }
Returns targetPath relative to basePath .
35,237
protected void initialize ( ) { orderedWorkSet . clear ( ) ; for ( DiGraphNode < N , Branch > node : cfg . getDirectedGraphNodes ( ) ) { node . setAnnotation ( new FlowState < > ( createInitialEstimateLattice ( ) , createInitialEstimateLattice ( ) ) ) ; if ( node != cfg . getImplicitReturn ( ) ) { orderedWorkSet . add ( node ) ; } } }
Initializes the work list and the control flow graph .
35,238
protected boolean flow ( DiGraphNode < N , Branch > node ) { FlowState < L > state = node . getAnnotation ( ) ; if ( isForward ( ) ) { L outBefore = state . out ; state . out = flowThrough ( node . getValue ( ) , state . in ) ; return ! outBefore . equals ( state . out ) ; } else { L inBefore = state . in ; state . in = flowThrough ( node . getValue ( ) , state . out ) ; return ! inBefore . equals ( state . in ) ; } }
Performs a single flow through a node .
35,239
List < Result > getResult ( ) { return ImmutableList . copyOf ( Iterables . filter ( results . values ( ) , USED_RESULTS ) ) ; }
Get the list of all replacements performed .
35,240
VariableMap getStringMap ( ) { ImmutableMap . Builder < String , String > map = ImmutableMap . builder ( ) ; for ( Result result : Iterables . filter ( results . values ( ) , USED_RESULTS ) ) { map . put ( result . replacement , result . original ) ; } VariableMap stringMap = new VariableMap ( map . build ( ) ) ; return stringMap ; }
Get the list of replaces as a VariableMap
35,241
private void doSubstitutions ( NodeTraversal t , Config config , Node n ) { if ( n . isTaggedTemplateLit ( ) ) { compiler . report ( JSError . make ( n , STRING_REPLACEMENT_TAGGED_TEMPLATE ) ) ; return ; } checkState ( n . isNew ( ) || n . isCall ( ) ) ; if ( ! config . isReplaceAll ( ) ) { for ( int parameter : config . parameters ) { Node arg = n . getChildAtIndex ( parameter ) ; if ( arg != null ) { replaceExpression ( t , arg , n ) ; } } } else { Node firstParam = n . getSecondChild ( ) ; for ( Node arg = firstParam ; arg != null ; arg = arg . getNext ( ) ) { arg = replaceExpression ( t , arg , n ) ; } } }
Replace the parameters specified in the config if possible .
35,242
private Node replaceExpression ( NodeTraversal t , Node expr , Node parent ) { Node replacement ; String key = null ; String replacementString ; switch ( expr . getToken ( ) ) { case STRING : key = expr . getString ( ) ; replacementString = getReplacement ( key ) ; replacement = IR . string ( replacementString ) ; break ; case TEMPLATELIT : case ADD : case NAME : StringBuilder keyBuilder = new StringBuilder ( ) ; Node keyNode = IR . string ( "" ) ; replacement = buildReplacement ( t , expr , keyNode , keyBuilder ) ; key = keyBuilder . toString ( ) ; if ( key . equals ( placeholderToken ) ) { return expr ; } replacementString = getReplacement ( key ) ; keyNode . setString ( replacementString ) ; break ; default : return expr ; } checkNotNull ( key ) ; checkNotNull ( replacementString ) ; recordReplacement ( key ) ; replacement . useSourceInfoIfMissingFromForTree ( expr ) ; parent . replaceChild ( expr , replacement ) ; t . reportCodeChange ( ) ; return replacement ; }
Replaces a string expression with a short encoded string expression .
35,243
private String getReplacement ( String key ) { Result result = results . get ( key ) ; if ( result != null ) { return result . replacement ; } String replacement = nameGenerator . generateNextName ( ) ; result = new Result ( key , replacement ) ; results . put ( key , result ) ; return replacement ; }
Get a replacement string for the provide key text .
35,244
private void recordReplacement ( String key ) { Result result = results . get ( key ) ; checkState ( result != null ) ; result . didReplacement = true ; }
Record the location the replacement was made .
35,245
private static String getMethodFromDeclarationName ( String fullDeclarationName ) { String [ ] parts = fullDeclarationName . split ( "\\.prototype\\." ) ; checkState ( parts . length == 1 || parts . length == 2 ) ; if ( parts . length == 2 ) { return parts [ 1 ] ; } return null ; }
From a provide name extract the method name .
35,246
private static String getClassFromDeclarationName ( String fullDeclarationName ) { String [ ] parts = fullDeclarationName . split ( "\\.prototype\\." ) ; checkState ( parts . length == 1 || parts . length == 2 ) ; if ( parts . length == 2 ) { return parts [ 0 ] ; } return null ; }
From a provide name extract the class name .
35,247
private void parseConfiguration ( List < String > functionsToInspect ) { for ( String function : functionsToInspect ) { Config config = parseConfiguration ( function ) ; functions . put ( config . name , config ) ; String method = getMethodFromDeclarationName ( config . name ) ; if ( method != null ) { methods . put ( method , config . name ) ; } } }
Build the data structures need by this pass from the provided list of functions and methods .
35,248
private static DefaultNameGenerator createNameGenerator ( Iterable < String > reserved ) { final String namePrefix = "" ; final char [ ] reservedChars = new char [ 0 ] ; return new DefaultNameGenerator ( ImmutableSet . copyOf ( reserved ) , namePrefix , reservedChars ) ; }
Use a name generate to create names so the names overlap with the names used for variable and properties .
35,249
private static SubclassType typeofClassDefiningName ( Node callName ) { String methodName = null ; if ( callName . isGetProp ( ) ) { methodName = callName . getLastChild ( ) . getString ( ) ; } else if ( callName . isName ( ) ) { String name = callName . getString ( ) ; int dollarIndex = name . lastIndexOf ( '$' ) ; if ( dollarIndex != - 1 ) { methodName = name . substring ( dollarIndex + 1 ) ; } } if ( methodName != null ) { if ( methodName . equals ( "inherits" ) ) { return SubclassType . INHERITS ; } else if ( methodName . equals ( "mixin" ) ) { return SubclassType . MIXIN ; } } return null ; }
Determines whether the given node is a class - defining name like inherits or mixin .
35,250
public UnionTypeBuilder addAlternates ( ImmutableList < JSType > list ) { for ( int i = 0 ; i < list . size ( ) ; i ++ ) { addAlternate ( list . get ( i ) ) ; } return this ; }
adding a union as an alternate .
35,251
private JSType reduceAlternatesWithoutUnion ( ) { JSType wildcard = getNativeWildcardType ( ) ; if ( wildcard != null ) { return containsVoidType ? null : wildcard ; } int size = alternates . size ( ) ; if ( size > maxUnionSize ) { return registry . getNativeType ( UNKNOWN_TYPE ) ; } else if ( size > 1 ) { return null ; } else if ( size == 1 ) { return alternates . get ( 0 ) ; } else { return registry . getNativeType ( NO_TYPE ) ; } }
Reduce the alternates into a non - union type . If the alternates can t be accurately represented with a non - union type return null .
35,252
private JSType getNativeWildcardType ( ) { if ( isAllType ) { return registry . getNativeType ( ALL_TYPE ) ; } else if ( isNativeUnknownType ) { if ( areAllUnknownsChecked ) { return registry . getNativeType ( CHECKED_UNKNOWN_TYPE ) ; } else { return registry . getNativeType ( UNKNOWN_TYPE ) ; } } return null ; }
Returns ALL_TYPE UNKNOWN_TYPE or CHECKED_UNKNOWN_TYPE as specified by the flags or null
35,253
public JSType build ( ) { if ( result == null ) { result = reduceAlternatesWithoutUnion ( ) ; if ( result == null ) { result = new UnionType ( registry , ImmutableList . copyOf ( getAlternates ( ) ) ) ; } } return result ; }
Creates a union .
35,254
private boolean canOptimizeObjectCreate ( Node firstParam ) { Node curParam = firstParam ; while ( curParam != null ) { if ( ! isOptimizableKey ( curParam ) ) { return false ; } curParam = curParam . getNext ( ) ; if ( curParam == null ) { return false ; } curParam = curParam . getNext ( ) ; } return true ; }
Returns whether the given call to goog . object . create can be converted to an object literal .
35,255
private boolean canOptimizeObjectCreateSet ( Node firstParam ) { if ( firstParam != null && firstParam . getNext ( ) == null && ! ( firstParam . isNumber ( ) || firstParam . isString ( ) ) ) { return false ; } Node curParam = firstParam ; Set < String > keys = new HashSet < > ( ) ; while ( curParam != null ) { if ( ! isOptimizableKey ( curParam ) ) { return false ; } if ( curParam . isString ( ) || curParam . isNumber ( ) ) { String key = curParam . isString ( ) ? curParam . getString ( ) : numberToString ( curParam . getDouble ( ) ) ; if ( ! keys . add ( key ) ) { compiler . report ( JSError . make ( firstParam . getPrevious ( ) , DUPLICATE_SET_MEMBER , key ) ) ; return false ; } } curParam = curParam . getNext ( ) ; } return true ; }
Returns whether the given call to goog . object . createSet can be converted to an object literal .
35,256
private void maybeProcessDomTagName ( Node n ) { if ( NodeUtil . isLValue ( n ) ) { return ; } String prefix = "goog$dom$TagName$" ; String tagName ; if ( n . isName ( ) && n . getString ( ) . startsWith ( prefix ) ) { tagName = n . getString ( ) . substring ( prefix . length ( ) ) ; } else if ( n . isGetProp ( ) && ! n . getParent ( ) . isGetProp ( ) && n . getFirstChild ( ) . matchesQualifiedName ( "goog.dom.TagName" ) ) { tagName = n . getSecondChild ( ) . getString ( ) . replaceFirst ( ".*\\$" , "" ) ; } else { return ; } Node stringNode = IR . string ( tagName ) . srcref ( n ) ; n . replaceWith ( stringNode ) ; compiler . reportChangeToEnclosingScope ( stringNode ) ; }
Converts the given node to string if it is safe to do so .
35,257
static String getGlobalNameOfEsModuleLocalVariable ( ModuleMetadata moduleMetadata , String variableName ) { return variableName + "$$" + getGlobalName ( moduleMetadata , null ) ; }
Returns the global name of a variable declared in an ES module .
35,258
static String getGlobalName ( Export export ) { if ( export . moduleMetadata ( ) . isEs6Module ( ) ) { if ( export . localName ( ) . equals ( Export . DEFAULT_EXPORT_NAME ) ) { return getGlobalNameOfAnonymousDefaultExport ( export . moduleMetadata ( ) ) ; } return getGlobalNameOfEsModuleLocalVariable ( export . moduleMetadata ( ) , export . localName ( ) ) ; } return getGlobalName ( export . moduleMetadata ( ) , export . closureNamespace ( ) ) + "." + export . exportName ( ) ; }
Returns the post - transpilation globalized name of the export .
35,259
static String getGlobalName ( Binding binding ) { if ( binding . isModuleNamespace ( ) ) { return getGlobalName ( binding . metadata ( ) , binding . closureNamespace ( ) ) ; } return getGlobalName ( binding . originatingExport ( ) ) ; }
Returns the post - transpilation globalized name of the binding .
35,260
public static Matcher anything ( ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { return true ; } } ; }
Returns a Matcher that matches every node .
35,261
public static Matcher allOf ( final Matcher ... matchers ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { for ( Matcher m : matchers ) { if ( ! m . matches ( node , metadata ) ) { return false ; } } return true ; } } ; }
Returns a Matcher that returns true only if all of the provided matchers match .
35,262
public static Matcher not ( final Matcher matcher ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { return ! matcher . matches ( node , metadata ) ; } } ; }
Returns a Matcher that matches the opposite of the provided matcher .
35,263
public static Matcher constructor ( final String name ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { JSDocInfo info = node . getJSDocInfo ( ) ; if ( info != null && info . isConstructor ( ) ) { Node firstChild = node . getFirstChild ( ) ; if ( name == null ) { return true ; } if ( ( firstChild . isGetProp ( ) || firstChild . isName ( ) ) && firstChild . matchesQualifiedName ( name ) ) { return true ; } } return false ; } } ; }
Returns a matcher that matches constructor definitions of the specified name .
35,264
public static Matcher newClass ( ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { return node . isNew ( ) ; } } ; }
Returns a Matcher that matches constructing new objects . This will match the NEW node of the JS Compiler AST .
35,265
public static Matcher newClass ( final String className ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { if ( ! node . isNew ( ) ) { return false ; } JSType providedJsType = getJsType ( metadata , className ) ; if ( providedJsType == null ) { return false ; } JSType jsType = node . getJSType ( ) ; if ( jsType == null ) { return false ; } jsType = jsType . restrictByNotNullOrUndefined ( ) ; return areTypesEquivalentIgnoringGenerics ( jsType , providedJsType ) ; } } ; }
Returns a Matcher that matches constructing objects of the provided class name . This will match the NEW node of the JS Compiler AST .
35,266
public static Matcher functionCall ( final String name ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { return node . isCall ( ) && propertyAccess ( name ) . matches ( node . getFirstChild ( ) , metadata ) ; } } ; }
Returns a Matcher that matches all nodes that are function calls that match the provided name .
35,267
public static Matcher functionCallWithNumArgs ( final int numArgs ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { return node . isCall ( ) && ( node . getChildCount ( ) - 1 ) == numArgs ; } } ; }
Returns a Matcher that matches any function call that has the given number of arguments .
35,268
public static Matcher functionCallWithNumArgs ( final String name , final int numArgs ) { return allOf ( functionCallWithNumArgs ( numArgs ) , functionCall ( name ) ) ; }
Returns a Matcher that matches any function call that has the given number of arguments and the given name .
35,269
public static Matcher propertyAccess ( final String name ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { if ( node . isGetProp ( ) ) { if ( name == null ) { return true ; } if ( node . matchesQualifiedName ( name ) ) { return true ; } else if ( name . contains ( ".prototype." ) ) { return matchesPrototypeInstanceVar ( node , metadata , name ) ; } } return false ; } } ; }
Returns a Matcher that matches nodes representing a GETPROP access of an object property .
35,270
public static Matcher enumDefinition ( ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { JSType jsType = node . getJSType ( ) ; return jsType != null && jsType . isEnumType ( ) ; } } ; }
Returns a Matcher that matches definitions of any enum .
35,271
public static Matcher enumDefinitionOfType ( final String type ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { JSType providedJsType = getJsType ( metadata , type ) ; if ( providedJsType == null ) { return false ; } providedJsType = providedJsType . restrictByNotNullOrUndefined ( ) ; JSType jsType = node . getJSType ( ) ; return jsType != null && jsType . isEnumType ( ) && providedJsType . isEquivalentTo ( jsType . toMaybeEnumType ( ) . getElementsType ( ) . getPrimitiveType ( ) ) ; } } ; }
Returns a Matcher that matches definitions of an enum of the given type .
35,272
public static Matcher assignmentWithRhs ( final Matcher rhsMatcher ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { return node . isAssign ( ) && rhsMatcher . matches ( node . getLastChild ( ) , metadata ) ; } } ; }
Returns a Matcher that matches an ASSIGN node where the RHS of the assignment matches the given rhsMatcher .
35,273
public static Matcher constructorPropertyDeclaration ( ) { return new Matcher ( ) { public boolean matches ( Node node , NodeMetadata metadata ) { if ( ! node . isAssign ( ) || ! node . getFirstChild ( ) . isGetProp ( ) || ! node . getFirstFirstChild ( ) . isThis ( ) ) { return false ; } while ( node != null && ! node . isFunction ( ) ) { node = node . getParent ( ) ; } if ( node != null && node . isFunction ( ) ) { JSDocInfo jsDoc = NodeUtil . getBestJSDocInfo ( node ) ; if ( jsDoc != null ) { return jsDoc . isConstructor ( ) ; } } return false ; } } ; }
Returns a Matcher that matches against properties that are declared in the constructor .
35,274
private static ImmutableList < String > createRootPaths ( Iterable < String > roots , PathResolver resolver , PathEscaper escaper ) { Set < String > builder = new TreeSet < > ( Comparator . comparingInt ( String :: length ) . thenComparing ( String :: compareTo ) . reversed ( ) ) ; for ( String root : roots ) { String rootModuleName = escaper . escape ( resolver . apply ( root ) ) ; if ( isAmbiguousIdentifier ( rootModuleName ) ) { rootModuleName = MODULE_SLASH + rootModuleName ; } builder . add ( rootModuleName ) ; } return ImmutableList . copyOf ( builder ) ; }
Normalizes the given root paths which are path prefixes to be removed from a module path when resolved .
35,275
static String normalize ( String path , Iterable < String > moduleRootPaths ) { String normalizedPath = path ; if ( isAmbiguousIdentifier ( normalizedPath ) ) { normalizedPath = MODULE_SLASH + normalizedPath ; } for ( String moduleRoot : moduleRootPaths ) { if ( normalizedPath . startsWith ( moduleRoot ) ) { String trailing = normalizedPath . substring ( moduleRoot . length ( ) ) ; if ( trailing . startsWith ( MODULE_SLASH ) ) { return trailing . substring ( MODULE_SLASH . length ( ) ) ; } } } return path ; }
Normalizes the name and resolves it against the module roots .
35,276
public static < NODE , EDGE > FixedPointGraphTraversal < NODE , EDGE > newTraversal ( EdgeCallback < NODE , EDGE > callback ) { return new FixedPointGraphTraversal < > ( callback ) ; }
Helper method for creating new traversals .
35,277
public void computeFixedPoint ( DiGraph < N , E > graph ) { Set < N > nodes = new LinkedHashSet < > ( ) ; for ( DiGraphNode < N , E > node : graph . getDirectedGraphNodes ( ) ) { nodes . add ( node . getValue ( ) ) ; } computeFixedPoint ( graph , nodes ) ; }
Compute a fixed point for the given graph .
35,278
public void computeFixedPoint ( DiGraph < N , E > graph , N entry ) { Set < N > entrySet = new LinkedHashSet < > ( ) ; entrySet . add ( entry ) ; computeFixedPoint ( graph , entrySet ) ; }
Compute a fixed point for the given graph entering from the given node .
35,279
public void computeFixedPoint ( DiGraph < N , E > graph , Set < N > entrySet ) { int cycleCount = 0 ; long nodeCount = graph . getNodeCount ( ) ; long maxIterations = Math . max ( nodeCount * nodeCount * nodeCount , 100 ) ; LinkedHashSet < DiGraphNode < N , E > > workSet = new LinkedHashSet < > ( ) ; for ( N n : entrySet ) { workSet . add ( graph . getDirectedGraphNode ( n ) ) ; } for ( ; ! workSet . isEmpty ( ) && cycleCount < maxIterations ; cycleCount ++ ) { DiGraphNode < N , E > source = workSet . iterator ( ) . next ( ) ; N sourceValue = source . getValue ( ) ; workSet . remove ( source ) ; List < DiGraphEdge < N , E > > outEdges = source . getOutEdges ( ) ; for ( DiGraphEdge < N , E > edge : outEdges ) { N destNode = edge . getDestination ( ) . getValue ( ) ; if ( callback . traverseEdge ( sourceValue , edge . getValue ( ) , destNode ) ) { workSet . add ( edge . getDestination ( ) ) ; } } } checkState ( cycleCount != maxIterations , NON_HALTING_ERROR_MSG ) ; }
Compute a fixed point for the given graph entering from the given nodes .
35,280
private static void moveAllFollowing ( Node start , Node srcParent , Node destParent ) { for ( Node n = start . getNext ( ) ; n != null ; n = start . getNext ( ) ) { boolean isFunctionDeclaration = NodeUtil . isFunctionDeclaration ( n ) ; srcParent . removeChild ( n ) ; if ( isFunctionDeclaration ) { destParent . addChildToFront ( n ) ; } else { destParent . addChildToBack ( n ) ; } } }
Move all the child nodes following start in srcParent to the end of destParent s child list .
35,281
private static boolean hasBlockScopedVarsFollowing ( Node start ) { for ( Node n = start . getNext ( ) ; n != null ; n = n . getNext ( ) ) { if ( n . isLet ( ) || n . isConst ( ) ) { return true ; } } return false ; }
Detect any block - scoped declarations that are younger siblings of the given starting point .
35,282
public void traverse ( Node root ) { try { initTraversal ( root ) ; curNode = root ; pushScope ( root ) ; traverseBranch ( root , null ) ; popScope ( ) ; } catch ( Error | Exception unexpectedException ) { throwUnexpectedException ( unexpectedException ) ; } }
Traverses a parse tree recursively .
35,283
public static void traverse ( AbstractCompiler compiler , Node root , Callback cb ) { NodeTraversal t = new NodeTraversal ( compiler , cb , new Es6SyntacticScopeCreator ( compiler ) ) ; t . traverse ( root ) ; }
Traverses using the ES6SyntacticScopeCreator
35,284
public static void traversePostOrder ( AbstractCompiler compiler , Node root , AbstractPostOrderCallbackInterface cb ) { traverse ( compiler , root , makePostOrderCallback ( cb ) ) ; }
Traverses in post order .
35,285
public void traverseFunctionOutOfBand ( Node node , AbstractScope < ? , ? > scope ) { checkNotNull ( scope ) ; checkState ( node . isFunction ( ) , node ) ; checkNotNull ( scope . getRootNode ( ) ) ; initTraversal ( node ) ; curNode = node . getParent ( ) ; pushScope ( scope , true ) ; traverseBranch ( node , curNode ) ; popScope ( true ) ; }
Traverse a function out - of - band of normal traversal .
35,286
public int getLineNumber ( ) { Node cur = curNode ; while ( cur != null ) { int line = cur . getLineno ( ) ; if ( line >= 0 ) { return line ; } cur = cur . getParent ( ) ; } return 0 ; }
Gets the current line number or zero if it cannot be determined . The line number is retrieved lazily as a running time optimization .
35,287
public int getCharno ( ) { Node cur = curNode ; while ( cur != null ) { int line = cur . getCharno ( ) ; if ( line >= 0 ) { return line ; } cur = cur . getParent ( ) ; } return 0 ; }
Gets the current char number or zero if it cannot be determined . The line number is retrieved lazily as a running time optimization .
35,288
public CompilerInput getInput ( ) { if ( compilerInput == null && inputId != null ) { compilerInput = compiler . getInput ( inputId ) ; } return compilerInput ; }
Gets the current input source .
35,289
public JSModule getModule ( ) { CompilerInput input = getInput ( ) ; return input == null ? null : input . getModule ( ) ; }
Gets the current input module .
35,290
private void handleModule ( Node n , Node parent ) { pushScope ( n ) ; curNode = n ; if ( callback . shouldTraverse ( this , n , parent ) ) { curNode = n ; traverseChildren ( n ) ; callback . visit ( this , n , parent ) ; } popScope ( ) ; }
Traverses a module .
35,291
private void traverseBranch ( Node n , Node parent ) { switch ( n . getToken ( ) ) { case SCRIPT : handleScript ( n , parent ) ; return ; case FUNCTION : handleFunction ( n , parent ) ; return ; case MODULE_BODY : handleModule ( n , parent ) ; return ; default : break ; } curNode = n ; if ( ! callback . shouldTraverse ( this , n , parent ) ) { return ; } Token type = n . getToken ( ) ; if ( type == Token . CLASS ) { traverseClass ( n ) ; } else if ( type == Token . CLASS_MEMBERS ) { traverseClassMembers ( n ) ; } else if ( useBlockScope && NodeUtil . createsBlockScope ( n ) ) { traverseBlockScope ( n ) ; } else { traverseChildren ( n ) ; } curNode = n ; callback . visit ( this , n , parent ) ; }
Traverses a branch .
35,292
private void traverseFunction ( Node n , Node parent ) { final Node fnName = n . getFirstChild ( ) ; boolean isFunctionDeclaration = parent != null && NodeUtil . isFunctionDeclaration ( n ) ; if ( isFunctionDeclaration ) { traverseBranch ( fnName , n ) ; } curNode = n ; pushScope ( n ) ; if ( ! isFunctionDeclaration ) { traverseBranch ( fnName , n ) ; } final Node args = fnName . getNext ( ) ; final Node body = args . getNext ( ) ; traverseBranch ( args , n ) ; traverseBranch ( body , n ) ; popScope ( ) ; }
Traverses a function .
35,293
private void traverseClassMembers ( Node n ) { for ( Node child = n . getFirstChild ( ) ; child != null ; ) { Node next = child . getNext ( ) ; if ( child . isComputedProp ( ) ) { curNode = n ; if ( callback . shouldTraverse ( this , child , n ) ) { traverseBranch ( child . getLastChild ( ) , child ) ; curNode = n ; callback . visit ( this , child , n ) ; } } else { traverseBranch ( child , n ) ; } child = next ; } }
Traverse class members excluding keys of computed props .
35,294
public AbstractScope < ? , ? > getAbstractScope ( ) { AbstractScope < ? , ? > scope = scopes . peek ( ) ; for ( Node scopeRoot : scopeRoots ) { scope = scopeCreator . createScope ( scopeRoot , scope ) ; scopes . push ( scope ) ; } scopeRoots . clear ( ) ; return scope ; }
Gets the current scope .
35,295
private AbstractScope < ? , ? > instantiateScopes ( int count ) { checkArgument ( count <= scopeRoots . size ( ) ) ; AbstractScope < ? , ? > scope = scopes . peek ( ) ; for ( int i = 0 ; i < count ; i ++ ) { scope = scopeCreator . createScope ( scopeRoots . get ( i ) , scope ) ; scopes . push ( scope ) ; } scopeRoots . subList ( 0 , count ) . clear ( ) ; return scope ; }
Instantiate some but not necessarily all scopes from stored roots .
35,296
@ SuppressWarnings ( "unchecked" ) public ControlFlowGraph < Node > getControlFlowGraph ( ) { ControlFlowGraph < Node > result ; Object o = cfgs . peek ( ) ; if ( o instanceof Node ) { Node cfgRoot = ( Node ) o ; ControlFlowAnalysis cfa = new ControlFlowAnalysis ( compiler , false , true ) ; cfa . process ( null , cfgRoot ) ; result = cfa . getCfg ( ) ; cfgs . pop ( ) ; cfgs . push ( result ) ; } else { result = ( ControlFlowGraph < Node > ) o ; } return result ; }
Gets the control flow graph for the current JS scope .
35,297
public Node getScopeRoot ( ) { int roots = scopeRoots . size ( ) ; if ( roots > 0 ) { return scopeRoots . get ( roots - 1 ) ; } else { AbstractScope < ? , ? > s = scopes . peek ( ) ; return s != null ? s . getRootNode ( ) : null ; } }
Returns the current scope s root .
35,298
private void initScopeRoots ( Node n ) { Deque < Node > queuedScopeRoots = new ArrayDeque < > ( ) ; while ( n != null ) { if ( isScopeRoot ( n ) ) { queuedScopeRoots . addFirst ( n ) ; } n = n . getParent ( ) ; } for ( Node queuedScopeRoot : queuedScopeRoots ) { pushScope ( queuedScopeRoot ) ; } }
Prefills the scopeRoots stack up to a given spot in the AST . Allows for starting traversal at any spot while still having correct scope state .
35,299
JSType meet ( JSType that ) { JSType meetPrimitive = primitiveType . getGreatestSubtype ( that ) ; if ( meetPrimitive . isEmptyType ( ) ) { return null ; } else { return new EnumElementType ( registry , meetPrimitive , name , getEnumType ( ) ) ; } }
Returns the infimum of a enum element type and another type or null if the infimum is empty .