use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseCaseClauses.
private ImmutableList<ParseTree> parseCaseClauses() {
boolean foundDefaultClause = false;
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
while (true) {
SourcePosition start = getTreeStartLocation();
switch(peekType()) {
case CASE:
eat(TokenType.CASE);
ParseTree expression = parseExpression();
eat(TokenType.COLON);
ImmutableList<ParseTree> statements = parseCaseStatementsOpt();
result.add(new CaseClauseTree(getTreeLocation(start), expression, statements));
break;
case DEFAULT:
if (foundDefaultClause) {
reportError("Switch statements may have at most one default clause");
} else {
foundDefaultClause = true;
}
eat(TokenType.DEFAULT);
eat(TokenType.COLON);
result.add(new DefaultClauseTree(getTreeLocation(start), parseCaseStatementsOpt()));
break;
default:
return result.build();
}
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseAsyncMethod.
private ParseTree parseAsyncMethod(PartialClassElement partial) {
eatPredefinedString(ASYNC);
boolean generator = peek(TokenType.STAR);
if (generator) {
eat(TokenType.STAR);
}
if (peekPropertyName(0)) {
if (peekIdOrKeyword()) {
IdentifierToken name = eatIdOrKeywordAsId();
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.MEMBER).setAsync(true).setGenerator(generator).setStatic(partial.isStatic).setName(name);
parseFunctionTail(builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS);
return builder.build(getTreeLocation(name.getStart()));
} else {
// { 'str'() {} }
// { 123() {} }
// Treat these as if they were computed properties.
ParseTree nameExpr = parseLiteralExpression();
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION).setAsync(true).setGenerator(generator).setStatic(partial.isStatic);
parseFunctionTail(builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS);
ParseTree function = builder.build(getTreeLocation(nameExpr.getStart()));
return new ComputedPropertyMethodTree(getTreeLocation(nameExpr.getStart()), nameExpr, function);
}
} else {
// expect '[' to start computed property name
ParseTree nameExpr = parseComputedPropertyName();
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION).setAsync(true).setGenerator(generator).setStatic(partial.isStatic);
parseFunctionTail(builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS);
ParseTree function = builder.build(getTreeLocation(nameExpr.getStart()));
return new ComputedPropertyMethodTree(getTreeLocation(nameExpr.getStart()), nameExpr, function);
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseEquality.
// 11.9 Equality Expression
private ParseTree parseEquality(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseRelational(expressionIn);
while (peekEqualityOperator()) {
Token operator = nextToken();
ParseTree right = parseRelational(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseUpdateExpression.
private ParseTree parseUpdateExpression() {
SourcePosition start = getTreeStartLocation();
if (peekUpdateOperator()) {
Token operator = nextToken();
ParseTree operand = parseUnaryExpression();
return UpdateExpressionTree.prefix(getTreeLocation(start), operator, operand);
} else {
ParseTree lhs = parseLeftHandSideExpression();
if (peekUpdateOperator() && !peekImplicitSemiColon()) {
// newline not allowed before an update operator.
Token operator = nextToken();
return UpdateExpressionTree.postfix(getTreeLocation(start), operator, lhs);
} else {
return lhs;
}
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseMemberExpressionNoNew.
// 11.2 Member Expression without the new production
private ParseTree parseMemberExpressionNoNew() {
SourcePosition start = getTreeStartLocation();
ParseTree operand;
if (peekImportDot()) {
operand = parseImportDotMeta();
} else if (peekAsyncFunctionStart()) {
operand = parseAsyncFunctionExpression();
} else if (peekFunction()) {
operand = parseFunctionExpression();
} else {
operand = parsePrimaryExpression();
}
while (peekMemberExpressionSuffix()) {
switch(peekType()) {
case OPEN_SQUARE:
eat(TokenType.OPEN_SQUARE);
ParseTree member = parseExpression();
eat(TokenType.CLOSE_SQUARE);
operand = new MemberLookupExpressionTree(getTreeLocation(start), operand, member);
break;
case PERIOD:
eat(TokenType.PERIOD);
IdentifierToken id = eatIdOrKeywordAsId();
operand = new MemberExpressionTree(getTreeLocation(start), operand, id);
break;
case NO_SUBSTITUTION_TEMPLATE:
case TEMPLATE_HEAD:
operand = parseTemplateLiteral(operand);
break;
default:
throw new RuntimeException("unreachable");
}
}
return operand;
}
Aggregations