Logo Search packages:      
Sourcecode: yui-compressor version File versions  Download package

Node org::mozilla::javascript::Parser::variables ( boolean  inFor,
int  declType 
) throws IOException, ParserException [inline, private]

Parse a 'var' or 'const' statement, or a 'var' init list in a for statement.

Parameters:
inFor true if we are currently in the midst of the init clause of a for.
declType A token value: either VAR, CONST, or LET depending on context.
Returns:
The parsed statement
Exceptions:
IOException 
ParserException 

Definition at line 1366 of file Parser.java.

References org::mozilla::javascript::Decompiler::addName(), org::mozilla::javascript::Decompiler::addToken(), org::mozilla::javascript::TokenStream::getLineno(), and org::mozilla::javascript::TokenStream::getString().

    {
        Node result = nf.createVariables(declType, ts.getLineno());
        boolean first = true;
        for (;;) {
            Node destructuring = null;
            String s = null;
            int tt = peekToken();
            if (tt == Token.LB || tt == Token.LC) {
                // Destructuring assignment, e.g., var [a,b] = ...
                destructuring = primaryExpr();
            } else {
                // Simple variable name
                mustMatchToken(Token.NAME, "msg.bad.var");
                s = ts.getString();
    
                if (!first)
                    decompiler.addToken(Token.COMMA);
                first = false;
    
                decompiler.addName(s);
                defineSymbol(declType, inFor, s);
            }
    
            Node init = null;
            if (matchToken(Token.ASSIGN)) {
                decompiler.addToken(Token.ASSIGN);
                init = assignExpr(inFor);
            }
    
            if (destructuring != null) {
                if (init == null) {
                    if (!inFor)
                        reportError("msg.destruct.assign.no.init");
                    nf.addChildToBack(result, destructuring);
                } else {
                    nf.addChildToBack(result,
                        nf.createDestructuringAssignment(declType,
                            destructuring, init));
                }
            } else {
                Node name = nf.createName(s);
                if (init != null)
                    nf.addChildToBack(name, init);
                nf.addChildToBack(result, name);
            }
    
            if (!matchToken(Token.COMMA))
                break;
        }
        return result;
    }


Generated by  Doxygen 1.6.0   Back to index