use of com.google.javascript.jscomp.parsing.parser.trees.PropertyNameAssignmentTree 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) && !Keywords.isTypeScriptSpecificKeyword(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);
}
use of com.google.javascript.jscomp.parsing.parser.trees.PropertyNameAssignmentTree in project closure-compiler by google.
the class Parser method parseEnumMembers.
private ImmutableList<ParseTree> parseEnumMembers() {
SourceRange range = getTreeLocation(getTreeStartLocation());
IdentifierToken propertyName;
ParseTree member = null;
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
while (peekId()) {
propertyName = parseIdentifierExpression().identifierToken;
member = new PropertyNameAssignmentTree(range, propertyName, null);
result.add(member);
if (!peek(TokenType.CLOSE_CURLY)) {
eat(TokenType.COMMA);
}
}
return result.build();
}
use of com.google.javascript.jscomp.parsing.parser.trees.PropertyNameAssignmentTree in project closure-compiler by google.
the class Parser method parseObjectPatternField.
private ParseTree parseObjectPatternField(PatternKind kind) {
SourcePosition start = getTreeStartLocation();
if (peekType() == TokenType.OPEN_SQUARE) {
ParseTree key = parseComputedPropertyName();
eat(TokenType.COLON);
ParseTree value = parsePatternAssignmentTarget(kind);
return new ComputedPropertyDefinitionTree(getTreeLocation(start), key, value);
}
Token name;
if (peekIdOrKeyword()) {
name = eatIdOrKeywordAsId();
if (!peek(TokenType.COLON)) {
IdentifierToken idToken = (IdentifierToken) name;
if (Keywords.isKeyword(idToken.value) && !Keywords.isTypeScriptSpecificKeyword(idToken.value)) {
reportError("cannot use keyword '%s' here.", name);
}
if (peek(TokenType.EQUAL)) {
IdentifierExpressionTree idTree = new IdentifierExpressionTree(getTreeLocation(start), idToken);
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
return new DefaultParameterTree(getTreeLocation(start), idTree, defaultValue);
}
return new PropertyNameAssignmentTree(getTreeLocation(start), name, null);
}
} else {
name = parseLiteralExpression().literalToken;
}
eat(TokenType.COLON);
ParseTree value = parsePatternAssignmentTarget(kind);
return new PropertyNameAssignmentTree(getTreeLocation(start), name, value);
}
Aggregations