use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseAsyncFunctionDeclaration.
private ParseTree parseAsyncFunctionDeclaration() {
SourcePosition start = getTreeStartLocation();
eatAsyncFunctionStart();
boolean generator = peek(TokenType.STAR);
if (generator) {
eat(TokenType.STAR);
}
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION).setName(eatId()).setAsync(true);
parseFunctionTail(builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS);
return builder.build(getTreeLocation(start));
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parsePatternAssignmentTarget.
/**
* A PatternAssignmentTarget is the location where the assigned value gets stored, including an
* optional default value.
*
* <dl>
* <dt>Spec AssignmentElement === PatternAssignmentTarget(PatternKind.ANY)
* <dd>Valid in an assignment that is not a formal parameter list or variable declaration.
* Sub-patterns and arbitrary left hand side expressions are allowed.
* <dt>Spec BindingElement === PatternAssignmentElement(PatternKind.INITIALIZER)
* <dd>Valid in a formal parameter list or variable declaration statement. Only sub-patterns and
* identifiers are allowed.
* </dl>
*
* Examples:
*
* <pre>
* <code>
* [a, {foo: b = 'default'}] = someArray; // valid
* [x.a, {foo: x.b = 'default'}] = someArray; // valid
*
* let [a, {foo: b = 'default'}] = someArray; // valid
* let [x.a, {foo: x.b = 'default'}] = someArray; // invalid
*
* function f([a, {foo: b = 'default'}]) {...} // valid
* function f([x.a, {foo: x.b = 'default'}]) {...} // invalid
* </code>
* </pre>
*/
private ParseTree parsePatternAssignmentTarget(PatternKind patternKind) {
SourcePosition start = getTreeStartLocation();
ParseTree assignmentTarget;
assignmentTarget = parsePatternAssignmentTargetNoDefault(patternKind);
if (peek(TokenType.EQUAL)) {
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
assignmentTarget = new DefaultParameterTree(getTreeLocation(start), assignmentTarget, defaultValue);
}
return assignmentTarget;
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseDoWhileStatement.
// 12.6 Iteration Statements
// 12.6.1 The do-while Statement
private ParseTree parseDoWhileStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.DO);
ParseTree body = parseStatement();
eat(TokenType.WHILE);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
// The semicolon after the "do-while" is optional.
if (peek(TokenType.SEMI_COLON)) {
eat(TokenType.SEMI_COLON);
}
return new DoWhileStatementTree(getTreeLocation(start), body, condition);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseLogicalOR.
// 11.11 Logical OR
private ParseTree parseLogicalOR(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseLogicalAND(expressionIn);
while (peek(TokenType.OR)) {
Token operator = eat(TokenType.OR);
ParseTree right = parseLogicalAND(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parsePropertyNameAssignment.
private ParseTree parsePropertyNameAssignment() {
SourcePosition start = getTreeStartLocation();
Token name = eatObjectLiteralPropertyName();
Token colon = eatOpt(TokenType.COLON);
if (colon == null) {
if (name.type != TokenType.IDENTIFIER) {
reportExpectedError(peekToken(), TokenType.COLON);
} else if (Keywords.isKeyword(name.asIdentifier().value)) {
reportError(name, "Cannot use keyword in short object literal");
} else if (peek(TokenType.EQUAL)) {
IdentifierExpressionTree idTree = new IdentifierExpressionTree(getTreeLocation(start), (IdentifierToken) name);
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
return new DefaultParameterTree(getTreeLocation(start), idTree, defaultValue);
}
}
ParseTree value = colon == null ? null : parseAssignmentExpression();
return new PropertyNameAssignmentTree(getTreeLocation(start), name, value);
}
Aggregations