Parse a 'var' or 'const' statement, or a 'var' init list in a for statement. @param declType A token value: either VAR, CONST, or LET depending on context. @param pos the position where the node should start. It's sometimes the var/const/let keyword, and other times the beginning of the first t
(int declType, int pos, boolean isStatement)
| 2475 | * @return the parsed variable list |
| 2476 | */ |
| 2477 | private VariableDeclaration variables(int declType, int pos, boolean isStatement) |
| 2478 | throws IOException { |
| 2479 | int end; |
| 2480 | VariableDeclaration pn = new VariableDeclaration(pos); |
| 2481 | pn.setType(declType); |
| 2482 | pn.setLineColumnNumber(lineNumber(), columnNumber()); |
| 2483 | Comment varjsdocNode = getAndResetJsDoc(); |
| 2484 | if (varjsdocNode != null) { |
| 2485 | pn.setJsDocNode(varjsdocNode); |
| 2486 | } |
| 2487 | // Example: |
| 2488 | // var foo = {a: 1, b: 2}, bar = [3, 4]; |
| 2489 | // var {b: s2, a: s1} = foo, x = 6, y, [s3, s4] = bar; |
| 2490 | for (; ; ) { |
| 2491 | AstNode destructuring = null; |
| 2492 | Name name = null; |
| 2493 | int tt = peekToken(), kidPos = ts.tokenBeg; |
| 2494 | end = ts.tokenEnd; |
| 2495 | |
| 2496 | if (tt == Token.LB || tt == Token.LC) { |
| 2497 | // Destructuring assignment, e.g., var [a,b] = ... |
| 2498 | |
| 2499 | // TODO: support default values inside destructured assignment |
| 2500 | // eg: for (let { x = 3 } = {}) ... |
| 2501 | destructuring = destructuringPrimaryExpr(); |
| 2502 | end = getNodeEnd(destructuring); |
| 2503 | |
| 2504 | if (!(destructuring instanceof DestructuringForm)) |
| 2505 | reportError("msg.bad.assign.left", kidPos, end - kidPos); |
| 2506 | markDestructuring(destructuring); |
| 2507 | } else { |
| 2508 | // Simple variable name |
| 2509 | if (tt == Token.UNDEFINED) { |
| 2510 | consumeToken(); |
| 2511 | } else { |
| 2512 | mustMatchToken(Token.NAME, "msg.bad.var", true); |
| 2513 | } |
| 2514 | name = createNameNode(); |
| 2515 | name.setLineColumnNumber(lineNumber(), columnNumber()); |
| 2516 | if (inUseStrictDirective) { |
| 2517 | String id = ts.getString(); |
| 2518 | if ("eval".equals(id) || "arguments".equals(ts.getString())) { |
| 2519 | reportError("msg.bad.id.strict", id); |
| 2520 | } |
| 2521 | } |
| 2522 | defineSymbol(declType, ts.getString(), inForInit); |
| 2523 | } |
| 2524 | |
| 2525 | int lineno = lineNumber(), column = columnNumber(); |
| 2526 | |
| 2527 | Comment jsdocNode = getAndResetJsDoc(); |
| 2528 | |
| 2529 | AstNode init = null; |
| 2530 | if (matchToken(Token.ASSIGN, true)) { |
| 2531 | init = assignExpr(); |
| 2532 | end = getNodeEnd(init); |
| 2533 | } |
| 2534 |
no test coverage detected