private void recordComment(int lineno, String comment) { if (scannedComments == null) { scannedComments = new ArrayList<Comment>(); } Comment commentNode = new Comment(ts.tokenBeg, ts.getTokenLength(), ts.commentType, comment); if (ts.commentType == Token.CommentType.JSDOC && compilerEnv.isRecordingLocalJsDocComments()) { currentJsDocComment = commentNode; } commentNode.setLineno(lineno); scannedComments.add(commentNode); }
private WithStatement withStatement() throws IOException { if (currentToken != Token.WITH) codeBug(); consumeToken(); Comment withComment = getAndResetJsDoc(); int lineno = ts.lineno, pos = ts.tokenBeg, lp = -1, rp = -1; if (mustMatchToken(Token.LP, "msg.no.paren.with")) lp = ts.tokenBeg; AstNode obj = expr(); if (mustMatchToken(Token.RP, "msg.no.paren.after.with")) rp = ts.tokenBeg; AstNode body = statement(); WithStatement pn = new WithStatement(pos, getNodeEnd(body) - pos); pn.setJsDocNode(withComment); pn.setExpression(obj); pn.setStatement(body); pn.setParens(lp, rp); pn.setLineno(lineno); return pn; }
private AstNode parenExpr() throws IOException { boolean wasInForInit = inForInit; inForInit = false; try { Comment jsdocNode = getAndResetJsDoc(); int lineno = ts.lineno; int begin = ts.tokenBeg; AstNode e = (peekToken() == Token.RP ? new EmptyExpression(begin) : expr()); if (peekToken() == Token.FOR) { return generatorExpression(e, begin); } ParenthesizedExpression pn = new ParenthesizedExpression(e); if (jsdocNode == null) { jsdocNode = getAndResetJsDoc(); } if (jsdocNode != null) { pn.setJsDocNode(jsdocNode); } mustMatchToken(Token.RP, "msg.no.paren"); if (e.getType() == Token.EMPTY && peekToken() != Token.ARROW) { reportError("msg.syntax"); return makeErrorNode(); } pn.setLength(ts.tokenEnd - pn.getPosition()); pn.setLineno(lineno); return pn; } finally { inForInit = wasInForInit; } }
/** * Gets the JsDoc comment string attached to this node. * @return the comment string or {@code null} if no JsDoc is attached to * this node */ public String getJsDoc() { Comment comment = getJsDocNode(); if (comment != null) { return comment.getValue(); } return null; }
private Comment getAndResetJsDoc() { Comment saved = currentJsDocComment; currentJsDocComment = null; return saved; }
private void parseFunctionParams(FunctionNode fnNode) throws IOException { if (matchToken(Token.RP)) { fnNode.setRp(ts.tokenBeg - fnNode.getPosition()); return; } // Would prefer not to call createDestructuringAssignment until codegen, // but the symbol definitions have to happen now, before body is parsed. Map<String, Node> destructuring = null; Set<String> paramNames = new HashSet<String>(); do { int tt = peekToken(); if (tt == Token.LB || tt == Token.LC) { AstNode expr = destructuringPrimaryExpr(); markDestructuring(expr); fnNode.addParam(expr); // Destructuring assignment for parameters: add a dummy // parameter name, and add a statement to the body to initialize // variables from the destructuring assignment if (destructuring == null) { destructuring = new HashMap<String, Node>(); } String pname = currentScriptOrFn.getNextTempName(); defineSymbol(Token.LP, pname, false); destructuring.put(pname, expr); } else { if (mustMatchToken(Token.NAME, "msg.no.parm")) { Name paramNameNode = createNameNode(); Comment jsdocNodeForName = getAndResetJsDoc(); if (jsdocNodeForName != null) { paramNameNode.setJsDocNode(jsdocNodeForName); } fnNode.addParam(paramNameNode); String paramName = ts.getString(); defineSymbol(Token.LP, paramName); if (this.inUseStrictDirective) { if ("eval".equals(paramName) || "arguments".equals(paramName)) { reportError("msg.bad.id.strict", paramName); } if (paramNames.contains(paramName)) addError("msg.dup.param.strict", paramName); paramNames.add(paramName); } } else { fnNode.addParam(makeErrorNode()); } } } while (matchToken(Token.COMMA)); if (destructuring != null) { Node destructuringNode = new Node(Token.COMMA); // Add assignment helper for each destructuring parameter for (Map.Entry<String, Node> param: destructuring.entrySet()) { Node assign = createDestructuringAssignment(Token.VAR, param.getValue(), createName(param.getKey())); destructuringNode.addChildToBack(assign); } fnNode.putProp(Node.DESTRUCTURING_PARAMS, destructuringNode); } if (mustMatchToken(Token.RP, "msg.no.paren.after.parms")) { fnNode.setRp(ts.tokenBeg - fnNode.getPosition()); } }
/** * Sets the JsDoc comment string attached to this node. */ public void setJsDocNode(Comment jsdocNode) { putProp(JSDOC_PROP, jsdocNode); }
/** * Gets the JsDoc Comment object attached to this node. * @return the Comment or {@code null} if no JsDoc is attached to * this node */ public Comment getJsDocNode() { return (Comment) getProp(JSDOC_PROP); }