use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseRegularExpressionLiteral.
private ParseTree parseRegularExpressionLiteral() {
SourcePosition start = getTreeStartLocation();
LiteralToken literal = nextRegularExpressionLiteralToken();
return new LiteralExpressionTree(getTreeLocation(start), literal);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseIdentifierExpression.
private IdentifierExpressionTree parseIdentifierExpression() {
SourcePosition start = getTreeStartLocation();
IdentifierToken identifier = eatId();
return new IdentifierExpressionTree(getTreeLocation(start), identifier);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseImportDeclaration.
private ParseTree parseImportDeclaration() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.IMPORT);
// import ModuleSpecifier ;
if (peek(TokenType.STRING)) {
LiteralToken moduleSpecifier = eat(TokenType.STRING).asLiteral();
eatPossiblyImplicitSemiColon();
return new ImportDeclarationTree(getTreeLocation(start), null, null, null, moduleSpecifier);
}
// import ImportedDefaultBinding from ModuleSpecifier
// import NameSpaceImport from ModuleSpecifier
// import NamedImports from ModuleSpecifier ;
// import ImportedDefaultBinding , NameSpaceImport from ModuleSpecifier ;
// import ImportedDefaultBinding , NamedImports from ModuleSpecifier ;
IdentifierToken defaultBindingIdentifier = null;
IdentifierToken nameSpaceImportIdentifier = null;
ImmutableList<ParseTree> identifierSet = null;
boolean parseExplicitNames = true;
if (peekId()) {
defaultBindingIdentifier = eatId();
if (peek(TokenType.COMMA)) {
eat(TokenType.COMMA);
} else {
parseExplicitNames = false;
}
} else if (Keywords.isKeyword(peekType())) {
Token keyword = nextToken();
reportError(keyword, "cannot use keyword '%s' here.", keyword);
}
if (parseExplicitNames) {
if (peek(TokenType.STAR)) {
eat(TokenType.STAR);
eatPredefinedString(PredefinedName.AS);
nameSpaceImportIdentifier = eatId();
} else {
identifierSet = parseImportSpecifierSet();
}
}
eatPredefinedString(PredefinedName.FROM);
Token moduleStr = eat(TokenType.STRING);
LiteralToken moduleSpecifier = (moduleStr == null) ? null : moduleStr.asLiteral();
eatPossiblyImplicitSemiColon();
return new ImportDeclarationTree(getTreeLocation(start), defaultBindingIdentifier, identifierSet, nameSpaceImportIdentifier, moduleSpecifier);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseTemplateLiteral.
/**
* Constructs a template literal expression tree. "operand" is used to handle the case like
* "foo`bar`", which is a CallExpression or MemberExpression that calls the function foo() with
* the template literal as the argument (with extra handling). In this case, operand would be
* "foo", which is the callsite.
*
* <p>We store this operand in the TemplateLiteralExpressionTree and generate a TAGGED_TEMPLATELIT
* node if it's not null later when transpiling.
*
* @param operand A non-null value would represent the callsite
* @return The template literal expression
*/
private TemplateLiteralExpressionTree parseTemplateLiteral(ParseTree operand) {
SourcePosition start = operand == null ? getTreeStartLocation() : operand.location.start;
Token token = nextToken();
if (!(token instanceof TemplateLiteralToken)) {
reportError(token, "Unexpected template literal token %s.", token.type.toString());
}
boolean isTaggedTemplate = operand != null;
TemplateLiteralToken templateToken = (TemplateLiteralToken) token;
if (!isTaggedTemplate) {
reportTemplateErrorIfPresent(templateToken);
}
ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();
elements.add(new TemplateLiteralPortionTree(templateToken.location, templateToken));
if (templateToken.type == TokenType.NO_SUBSTITUTION_TEMPLATE) {
return new TemplateLiteralExpressionTree(getTreeLocation(start), operand, elements.build());
}
// `abc${
ParseTree expression = parseExpression();
elements.add(new TemplateSubstitutionTree(expression.location, expression));
while (!errorReporter.hadError()) {
templateToken = nextTemplateLiteralToken();
if (templateToken.type == TokenType.ERROR || templateToken.type == TokenType.END_OF_FILE) {
break;
}
if (!isTaggedTemplate) {
reportTemplateErrorIfPresent(templateToken);
}
elements.add(new TemplateLiteralPortionTree(templateToken.location, templateToken));
if (templateToken.type == TokenType.TEMPLATE_TAIL) {
break;
}
expression = parseExpression();
elements.add(new TemplateSubstitutionTree(expression.location, expression));
}
return new TemplateLiteralExpressionTree(getTreeLocation(start), operand, elements.build());
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseParameter.
private ParseTree parseParameter() {
SourcePosition start = getTreeStartLocation();
ParseTree parameter = null;
if (peek(TokenType.ELLIPSIS)) {
parameter = parseIterRest(PatternKind.INITIALIZER);
} else if (peekId()) {
parameter = parseIdentifierExpression();
} else if (peekPatternStart()) {
parameter = parsePattern(PatternKind.INITIALIZER);
} else {
throw new IllegalStateException("parseParameterCalled() without confirming a parameter exists.");
}
if (!parameter.isRestParameter() && peek(TokenType.EQUAL)) {
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
parameter = new DefaultParameterTree(getTreeLocation(start), parameter, defaultValue);
}
return parameter;
}
Aggregations