MCPcopy Create free account
hub / github.com/mozilla/rhino / variables

Method variables

rhino/src/main/java/org/mozilla/javascript/Parser.java:2477–2555  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 4

statementHelperMethod · 0.95
forLoopInitMethod · 0.95
letStatementMethod · 0.95
letMethod · 0.95

Calls 15

setTypeMethod · 0.95
lineNumberMethod · 0.95
columnNumberMethod · 0.95
getAndResetJsDocMethod · 0.95
peekTokenMethod · 0.95
getNodeEndMethod · 0.95
reportErrorMethod · 0.95
markDestructuringMethod · 0.95
consumeTokenMethod · 0.95
mustMatchTokenMethod · 0.95
createNameNodeMethod · 0.95

Tested by

no test coverage detected