use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseExportDeclaration.
/*
ExportDeclaration :
export * FromClause ;
export ExportClause [NoReference] FromClause ;
export ExportClause ;
export VariableStatement
export Declaration[Default]
export default AssignmentExpression ;
ExportClause [NoReference] :
{ }
{ ExportsList [?NoReference] }
{ ExportsList [?NoReference] , }
ExportsList [NoReference] :
ExportSpecifier [?NoReference]
ExportsList [?NoReference] , ExportSpecifier [?NoReference]
ExportSpecifier [NoReference] :
[~NoReference] IdentifierReference
[~NoReference] IdentifierReference as IdentifierName
[+NoReference] IdentifierName
[+NoReference] IdentifierName as IdentifierName
*/
private ParseTree parseExportDeclaration() {
SourcePosition start = getTreeStartLocation();
boolean isDefault = false;
boolean isExportAll = false;
boolean isExportSpecifier = false;
boolean needsSemiColon = true;
eat(TokenType.EXPORT);
ParseTree export = null;
ImmutableList<ParseTree> exportSpecifierList = null;
switch(peekType()) {
case STAR:
isExportAll = true;
nextToken();
break;
case IDENTIFIER:
export = parseAsyncFunctionDeclaration();
break;
case FUNCTION:
export = parseFunctionDeclaration();
needsSemiColon = false;
break;
case CLASS:
export = parseClassDeclaration();
needsSemiColon = false;
break;
case DEFAULT:
isDefault = true;
nextToken();
export = parseExpression();
needsSemiColon = false;
break;
case OPEN_CURLY:
isExportSpecifier = true;
exportSpecifierList = parseExportSpecifierSet();
break;
case VAR:
case LET:
case CONST:
default:
// unreachable, parse as a var decl to get a parse error.
export = parseVariableDeclarationList();
break;
}
LiteralToken moduleSpecifier = null;
if (isExportAll || (isExportSpecifier && peekPredefinedString(PredefinedName.FROM))) {
eatPredefinedString(PredefinedName.FROM);
moduleSpecifier = (LiteralToken) eat(TokenType.STRING);
} else if (isExportSpecifier) {
for (ParseTree tree : exportSpecifierList) {
IdentifierToken importedName = tree.asExportSpecifier().importedName;
if (isKeyword(importedName.value)) {
reportError(importedName, "cannot use keyword '%s' here.", importedName.value);
}
}
}
if (needsSemiColon || peekImplicitSemiColon()) {
eatPossiblyImplicitSemiColon();
}
return new ExportDeclarationTree(getTreeLocation(start), isDefault, isExportAll, export, exportSpecifierList, moduleSpecifier);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parse.
private ParseTree parse(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree result = parseAssignment(expressionIn);
if (peek(TokenType.COMMA) && !peek(1, TokenType.ELLIPSIS) && !peek(1, TokenType.CLOSE_PAREN)) {
ImmutableList.Builder<ParseTree> exprs = ImmutableList.builder();
exprs.add(result);
while (peek(TokenType.COMMA) && !peek(1, TokenType.ELLIPSIS) && !peek(1, TokenType.CLOSE_PAREN)) {
eat(TokenType.COMMA);
exprs.add(parseAssignment(expressionIn));
}
return new CommaExpressionTree(getTreeLocation(start), exprs.build());
}
return result;
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree 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)) {
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);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseUnaryExpression.
// 11.4 Unary Operator
private ParseTree parseUnaryExpression() {
SourcePosition start = getTreeStartLocation();
if (peekUnaryOperator()) {
Token operator = nextToken();
ParseTree operand = parseUnaryExpression();
return new UnaryExpressionTree(getTreeLocation(start), operator, operand);
} else if (peekAwaitExpression()) {
return parseAwaitExpression();
} else {
return parseUpdateExpression();
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseConditional.
// 11.12 Conditional Expression
private ParseTree parseConditional(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree condition = parseShortCircuit(expressionIn);
if (peek(TokenType.QUESTION)) {
eat(TokenType.QUESTION);
ParseTree left = parseAssignment(expressionIn);
eat(TokenType.COLON);
ParseTree right = parseAssignment(expressionIn);
return new ConditionalExpressionTree(getTreeLocation(start), condition, left, right);
}
return condition;
}
Aggregations