private VariableDeclaration variables ( int declType , int pos , boolean isStatement ) throws IOException { int end ; VariableDeclaration pn = new VariableDeclaration ( pos ) ; pn . setType ( declType ) ; pn . setLineno ( ts . lineno ) ; Comment varjsdocNode = getAndResetJsDoc ( ) ; if ( varjsdocNode != null ) { pn . setJsDocNode ( varjsdocNode ) ; } // Example: // var foo = {a: 1, b: 2}, bar = [3, 4]; // var {b: s2, a: s1} = foo, x = 6, y, [s3, s4] = bar; for ( ; ; ) { AstNode destructuring = null ; Name name = null ; int tt = peekToken ( ) , kidPos = ts . tokenBeg ; end = ts . tokenEnd ; if ( tt == Token . LB || tt == Token . LC ) { // Destructuring assignment, e.g., var [a,b] = ... destructuring = destructuringPrimaryExpr ( ) ; end = getNodeEnd ( destructuring ) ; if ( ! ( destructuring instanceof DestructuringForm ) ) reportError ( "msg.bad.assign.left" , kidPos , end - kidPos ) ; markDestructuring ( destructuring ) ; } else { // Simple variable name mustMatchToken ( Token . NAME , "msg.bad.var" , true ) ; name = createNameNode ( ) ; name . setLineno ( ts . getLineno ( ) ) ; if ( inUseStrictDirective ) { String id = ts . getString ( ) ; if ( "eval" . equals ( id ) || "arguments" . equals ( ts . getString ( ) ) ) { reportError ( "msg.bad.id.strict" , id ) ; } } defineSymbol ( declType , ts . getString ( ) , inForInit ) ; } int lineno = ts . lineno ; Comment jsdocNode = getAndResetJsDoc ( ) ; AstNode init = null ; if ( matchToken ( Token . ASSIGN , true ) ) { init = assignExpr ( ) ; end = getNodeEnd ( init ) ; } VariableInitializer vi = new VariableInitializer ( kidPos , end - kidPos ) ; if ( destructuring != null ) { if ( init == null && ! inForInit ) { reportError ( "msg.destruct.assign.no.init" ) ; } vi . setTarget ( destructuring ) ; } else { vi . setTarget ( name ) ; } vi . setInitializer ( init ) ; vi . setType ( declType ) ; vi . setJsDocNode ( jsdocNode ) ; vi . setLineno ( lineno ) ; pn . addVariable ( vi ) ; if ( ! matchToken ( Token . COMMA , true ) ) break ; } pn . setLength ( end - pos ) ; pn . setIsStatement ( isStatement ) ; return pn ; }
Parse a var or const statement or a var init list in a for statement .