use of org.mozilla.javascript.ast.ParenthesizedExpression in project st-js by st-js.
the class RhinoJavaScriptBuilder method paren.
/**
* {@inheritDoc}
*/
@Override
public AstNode paren(AstNode expr) {
ParenthesizedExpression paren = new ParenthesizedExpression();
paren.setExpression(expr);
return paren;
}
use of org.mozilla.javascript.ast.ParenthesizedExpression in project HL4A by HL4A.
the class Parser method parenExpr.
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;
}
}
use of org.mozilla.javascript.ast.ParenthesizedExpression in project HL4A by HL4A.
the class IRFactory method transformParenExpr.
private Node transformParenExpr(ParenthesizedExpression node) {
AstNode expr = node.getExpression();
decompiler.addToken(Token.LP);
int count = 1;
while (expr instanceof ParenthesizedExpression) {
decompiler.addToken(Token.LP);
count++;
expr = ((ParenthesizedExpression) expr).getExpression();
}
Node result = transform(expr);
for (int i = 0; i < count; i++) {
decompiler.addToken(Token.RP);
}
result.putProp(Node.PARENTHESIZED_PROP, Boolean.TRUE);
return result;
}
use of org.mozilla.javascript.ast.ParenthesizedExpression in project HL4A by HL4A.
the class Parser method arrowFunction.
private AstNode arrowFunction(AstNode params) throws IOException {
// line number where source starts
int baseLineno = ts.lineno;
// start of "function" kwd
int functionSourceStart = params != null ? params.getPosition() : -1;
FunctionNode fnNode = new FunctionNode(functionSourceStart);
fnNode.setFunctionType(FunctionNode.ARROW_FUNCTION);
fnNode.setJsDocNode(getAndResetJsDoc());
// Would prefer not to call createDestructuringAssignment until codegen,
// but the symbol definitions have to happen now, before body is parsed.
Map<String, Node> destructuring = new HashMap<String, Node>();
Set<String> paramNames = new HashSet<String>();
PerFunctionVariables savedVars = new PerFunctionVariables(fnNode);
try {
if (params instanceof ParenthesizedExpression) {
fnNode.setParens(0, params.getLength());
AstNode p = ((ParenthesizedExpression) params).getExpression();
if (!(p instanceof EmptyExpression)) {
arrowFunctionParams(fnNode, p, destructuring, paramNames);
}
} else {
arrowFunctionParams(fnNode, params, destructuring, paramNames);
}
if (!destructuring.isEmpty()) {
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);
}
fnNode.setBody(parseFunctionBody(FunctionNode.ARROW_FUNCTION, fnNode));
fnNode.setEncodedSourceBounds(functionSourceStart, ts.tokenEnd);
fnNode.setLength(ts.tokenEnd - functionSourceStart);
} finally {
savedVars.restore();
}
if (fnNode.isGenerator()) {
reportError("msg.arrowfunction.generator");
return makeErrorNode();
}
fnNode.setSourceName(sourceURI);
fnNode.setBaseLineno(baseLineno);
fnNode.setEndLineno(ts.lineno);
return fnNode;
}
Aggregations