use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseShortCircuit.
private ParseTree parseShortCircuit(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseLogicalOR(expressionIn);
if (peek(TokenType.QUESTION_QUESTION)) {
if (left.type == ParseTreeType.BINARY_OPERATOR) {
BinaryOperatorTree binaryTree = left.asBinaryOperator();
if (binaryTree.operator.type == TokenType.AND || binaryTree.operator.type == TokenType.OR) {
reportError("Logical OR and logical AND require parentheses when used with '??'");
}
}
return parseNullishCoalesce(expressionIn, left, start);
} else {
return left;
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseForStatement.
// 12.6.3 The for Statement
// 12.6.4 The for-in Statement
// The for-of Statement
// The for-await-of Statement
private ParseTree parseForStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.FOR);
boolean awaited = peekPredefinedString(AWAIT);
if (awaited) {
eatPredefinedString(AWAIT);
}
eat(TokenType.OPEN_PAREN);
if (peekVariableDeclarationList()) {
VariableDeclarationListTree variables = parseVariableDeclarationListNoIn();
if (peek(TokenType.IN)) {
if (awaited) {
reportError("for-await-of is the only allowed asynchronous iteration");
}
// for-in: only one declaration allowed
if (variables.declarations.size() > 1) {
reportError("for-in statement may not have more than one variable declaration");
}
VariableDeclarationTree declaration = variables.declarations.get(0);
if (declaration.initializer != null) {
// http://esdiscuss.org/topic/initializer-expression-on-for-in-syntax-subject
if (config.atLeast6) {
reportError("for-in statement may not have initializer");
} else {
errorReporter.reportWarning(declaration.location.start, "for-in statement should not have initializer");
}
}
return parseForInStatement(start, variables);
} else if (peekPredefinedString(PredefinedName.OF)) {
// for-of: only one declaration allowed
if (variables.declarations.size() > 1) {
if (awaited) {
reportError("for-await-of statement may not have more than one variable declaration");
} else {
reportError("for-of statement may not have more than one variable declaration");
}
}
// for-of: initializer is illegal
VariableDeclarationTree declaration = variables.declarations.get(0);
if (declaration.initializer != null) {
if (awaited) {
reportError("for-await-of statement may not have initializer");
} else {
reportError("for-of statement may not have initializer");
}
}
if (awaited) {
return parseForAwaitOfStatement(start, variables);
} else {
return parseForOfStatement(start, variables);
}
} else {
// "Vanilla" for statement: const/destructuring must have initializer
checkVanillaForInitializers(variables);
return parseForStatement(start, variables);
}
}
if (peek(TokenType.SEMI_COLON)) {
return parseForStatement(start, null);
}
ParseTree initializer = parseExpressionNoIn();
if (peek(TokenType.IN) || peek(TokenType.EQUAL) || peekPredefinedString(PredefinedName.OF)) {
initializer = transformLeftHandSideExpression(initializer);
if (!initializer.isValidAssignmentTarget()) {
reportError("invalid assignment target");
}
}
if (peek(TokenType.IN) || peekPredefinedString(PredefinedName.OF)) {
if (initializer.type != ParseTreeType.BINARY_OPERATOR && initializer.type != ParseTreeType.COMMA_EXPRESSION) {
if (peek(TokenType.IN)) {
return parseForInStatement(start, initializer);
} else {
// for {await}? ( _ of _ )
if (awaited) {
return parseForAwaitOfStatement(start, initializer);
} else {
return parseForOfStatement(start, initializer);
}
}
}
}
return parseForStatement(start, initializer);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseForStatement.
// 12.6.3 The for Statement
private ParseTree parseForStatement(SourcePosition start, ParseTree initializer) {
if (initializer == null) {
initializer = new NullTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
}
eat(TokenType.SEMI_COLON);
ParseTree condition;
if (!peek(TokenType.SEMI_COLON)) {
condition = parseExpression();
} else {
condition = new NullTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
}
eat(TokenType.SEMI_COLON);
ParseTree increment;
if (!peek(TokenType.CLOSE_PAREN)) {
increment = parseExpression();
} else {
increment = new NullTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
}
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new ForStatementTree(getTreeLocation(start), initializer, condition, increment, body);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseClass.
private ParseTree parseClass(boolean isExpression) {
SourcePosition start = getTreeStartLocation();
eat(TokenType.CLASS);
IdentifierToken name = null;
if (!isExpression || peekId()) {
name = eatId();
}
ParseTree superClass = null;
if (peek(TokenType.EXTENDS)) {
eat(TokenType.EXTENDS);
superClass = parseExpression();
}
eat(TokenType.OPEN_CURLY);
ImmutableList<ParseTree> elements = parseClassElements();
eat(TokenType.CLOSE_CURLY);
return new ClassDeclarationTree(getTreeLocation(start), name, superClass, elements);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseForAwaitOfStatement.
private ParseTree parseForAwaitOfStatement(SourcePosition start, ParseTree initializer) {
eatPredefinedString(PredefinedName.OF);
ParseTree collection = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new ForAwaitOfStatementTree(getTreeLocation(start), initializer, collection, body);
}
Aggregations