use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class IRFactory method decompileArrayLiteral.
// used for destructuring forms, since we don't transform() them
void decompileArrayLiteral(ArrayLiteral node) {
decompiler.addToken(Token.LB);
List<AstNode> elems = node.getElements();
int size = elems.size();
for (int i = 0; i < size; i++) {
AstNode elem = elems.get(i);
decompile(elem);
if (i < size - 1) {
decompiler.addToken(Token.COMMA);
}
}
decompiler.addToken(Token.RB);
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method assignExpr.
private AstNode assignExpr() throws IOException {
int tt = peekToken();
if (tt == Token.YIELD) {
return returnOrYield(tt, true);
}
AstNode pn = condExpr();
boolean hasEOL = false;
tt = peekTokenOrEOL();
if (tt == Token.EOL) {
hasEOL = true;
tt = peekToken();
}
if (Token.FIRST_ASSIGN <= tt && tt <= Token.LAST_ASSIGN) {
consumeToken();
// Pull out JSDoc info and reset it before recursing.
Comment jsdocNode = getAndResetJsDoc();
markDestructuring(pn);
int opPos = ts.tokenBeg;
pn = new Assignment(tt, pn, assignExpr(), opPos);
if (jsdocNode != null) {
pn.setJsDocNode(jsdocNode);
}
} else if (tt == Token.SEMI) {
// For example: /** @type Number */ C.prototype.x;
if (currentJsDocComment != null) {
pn.setJsDocNode(getAndResetJsDoc());
}
} else if (!hasEOL && tt == Token.ARROW) {
consumeToken();
pn = arrowFunction(pn);
}
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method condExpr.
private AstNode condExpr() throws IOException {
AstNode pn = orExpr();
if (matchToken(Token.HOOK)) {
int line = ts.lineno;
int qmarkPos = ts.tokenBeg, colonPos = -1;
/*
* Always accept the 'in' operator in the middle clause of a ternary,
* where it's unambiguous, even if we might be parsing the init of a
* for statement.
*/
boolean wasInForInit = inForInit;
inForInit = false;
AstNode ifTrue;
try {
ifTrue = assignExpr();
} finally {
inForInit = wasInForInit;
}
if (mustMatchToken(Token.COLON, "msg.no.colon.cond"))
colonPos = ts.tokenBeg;
AstNode ifFalse = assignExpr();
int beg = pn.getPosition(), len = getNodeEnd(ifFalse) - beg;
ConditionalExpression ce = new ConditionalExpression(beg, len);
ce.setLineno(line);
ce.setTestExpression(pn);
ce.setTrueExpression(ifTrue);
ce.setFalseExpression(ifFalse);
ce.setQuestionMarkPosition(qmarkPos - beg);
ce.setColonPosition(colonPos - beg);
pn = ce;
}
return pn;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method function.
private FunctionNode function(int type) throws IOException {
int syntheticType = type;
// line number where source starts
int baseLineno = ts.lineno;
// start of "function" kwd
int functionSourceStart = ts.tokenBeg;
Name name = null;
AstNode memberExprNode = null;
if (matchToken(Token.NAME)) {
name = createNameNode(true, Token.NAME);
if (inUseStrictDirective) {
String id = name.getIdentifier();
if ("eval".equals(id) || "arguments".equals(id)) {
reportError("msg.bad.id.strict", id);
}
}
if (!matchToken(Token.LP)) {
if (compilerEnv.isAllowMemberExprAsFunctionName()) {
AstNode memberExprHead = name;
name = null;
memberExprNode = memberExprTail(false, memberExprHead);
}
mustMatchToken(Token.LP, "msg.no.paren.parms");
}
} else if (matchToken(Token.LP)) {
// Anonymous function: leave name as null
} else {
if (compilerEnv.isAllowMemberExprAsFunctionName()) {
// Note that memberExpr can not start with '(' like
// in function (1+2).toString(), because 'function (' already
// processed as anonymous function
memberExprNode = memberExpr(false);
}
mustMatchToken(Token.LP, "msg.no.paren.parms");
}
int lpPos = currentToken == Token.LP ? ts.tokenBeg : -1;
if (memberExprNode != null) {
syntheticType = FunctionNode.FUNCTION_EXPRESSION;
}
if (syntheticType != FunctionNode.FUNCTION_EXPRESSION && name != null && name.length() > 0) {
// Function statements define a symbol in the enclosing scope
defineSymbol(Token.FUNCTION, name.getIdentifier());
}
FunctionNode fnNode = new FunctionNode(functionSourceStart, name);
fnNode.setFunctionType(type);
if (lpPos != -1)
fnNode.setLp(lpPos - functionSourceStart);
fnNode.setJsDocNode(getAndResetJsDoc());
PerFunctionVariables savedVars = new PerFunctionVariables(fnNode);
try {
parseFunctionParams(fnNode);
fnNode.setBody(parseFunctionBody(type, fnNode));
fnNode.setEncodedSourceBounds(functionSourceStart, ts.tokenEnd);
fnNode.setLength(ts.tokenEnd - functionSourceStart);
if (compilerEnv.isStrictMode() && !fnNode.getBody().hasConsistentReturnUsage()) {
String msg = (name != null && name.length() > 0) ? "msg.no.return.value" : "msg.anon.no.return.value";
addStrictWarning(msg, name == null ? "" : name.getIdentifier());
}
} finally {
savedVars.restore();
}
if (memberExprNode != null) {
// TODO(stevey): fix missing functionality
Kit.codeBug();
// rewrite later
fnNode.setMemberExprNode(memberExprNode);
/* old code:
if (memberExprNode != null) {
pn = nf.createAssignment(Token.ASSIGN, memberExprNode, pn);
if (functionType != FunctionNode.FUNCTION_EXPRESSION) {
// XXX check JScript behavior: should it be createExprStatement?
pn = nf.createExprStatementNoReturn(pn, baseLineno);
}
}
*/
}
fnNode.setSourceName(sourceURI);
fnNode.setBaseLineno(baseLineno);
fnNode.setEndLineno(ts.lineno);
// at the function boundary when checking for redeclarations.
if (compilerEnv.isIdeMode()) {
fnNode.setParentScope(currentScope);
}
return fnNode;
}
use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.
the class Parser method forLoopInit.
private AstNode forLoopInit(int tt) throws IOException {
try {
// checked by variables() and relExpr()
inForInit = true;
AstNode init = null;
if (tt == Token.SEMI) {
init = new EmptyExpression(ts.tokenBeg, 1);
init.setLineno(ts.lineno);
} else if (tt == Token.VAR || tt == Token.LET) {
consumeToken();
init = variables(tt, ts.tokenBeg, false);
} else {
init = expr();
markDestructuring(init);
}
return init;
} finally {
inForInit = false;
}
}
Aggregations