private void eatAsyncFunctionStart() { eatPredefinedString(ASYNC); eat(TokenType.FUNCTION); }
private ParseTree parseAwaitExpression() { SourcePosition start = getTreeStartLocation(); if (functionContextStack.isEmpty() || !functionContextStack.peekLast().isAsynchronous) { reportError("'await' used in a non-async function context"); } eatPredefinedString(AWAIT); ParseTree expression = parseUnaryExpression(); return new AwaitExpressionTree(getTreeLocation(start), expression); }
private ParseTree parseForAwaitOfStatement(SourcePosition start, ParseTree initializer) { eatPredefinedString(PredefinedName.OF); ParseTree collection = parseExpression(); eat(TokenType.CLOSE_PAREN); ParseTree body = parseStatement(); return new ForAwaitOfStatementTree(getTreeLocation(start), initializer, collection, body); }
private ParseTree parseNewDotSomething() { // currently only "target" is valid after "new." SourcePosition start = getTreeStartLocation(); eat(TokenType.NEW); eat(TokenType.PERIOD); eatPredefinedString("target"); return new NewTargetExpressionTree(getTreeLocation(start)); }
private ParseTree parseForOfStatement( SourcePosition start, ParseTree initializer) { eatPredefinedString(PredefinedName.OF); ParseTree collection = parseExpression(); eat(TokenType.CLOSE_PAREN); ParseTree body = parseStatement(); return new ForOfStatementTree( getTreeLocation(start), initializer, collection, body); }
private ParseTree parseForOfStatement( SourcePosition start, ParseTree initializer) { eatPredefinedString(PredefinedName.OF); ParseTree collection = parseExpression(); eat(TokenType.CLOSE_PAREN); ParseTree body = parseStatement(); return new ForOfStatementTree( getTreeLocation(start), initializer, collection, body); }
private ParseTree parseExportSpecifier() { SourcePosition start = getTreeStartLocation(); IdentifierToken importedName = eatIdOrKeywordAsId(); IdentifierToken destinationName = null; if (peekPredefinedString(PredefinedName.AS)) { eatPredefinedString(PredefinedName.AS); destinationName = eatIdOrKeywordAsId(); } return new ExportSpecifierTree( getTreeLocation(start), importedName, destinationName); }
private ParseTree parseExportSpecifier() { SourcePosition start = getTreeStartLocation(); IdentifierToken importedName = eatIdOrKeywordAsId(); IdentifierToken destinationName = null; if (peekPredefinedString(PredefinedName.AS)) { eatPredefinedString(PredefinedName.AS); destinationName = eatIdOrKeywordAsId(); } return new ExportSpecifierTree( getTreeLocation(start), importedName, destinationName); }
private ParseTree parseNewDotSomething() { // currently only "target" is valid after "new." features = features.require(Feature.NEW_TARGET); SourcePosition start = getTreeStartLocation(); eat(TokenType.NEW); eat(TokenType.PERIOD); eatPredefinedString("target"); return new NewTargetExpressionTree(getTreeLocation(start)); }
private ParseTree parseImportSpecifier() { SourcePosition start = getTreeStartLocation(); IdentifierToken importedName = eatIdOrKeywordAsId(); IdentifierToken destinationName = null; if (peekPredefinedString(PredefinedName.AS)) { eatPredefinedString(PredefinedName.AS); destinationName = eatId(); } else if (isKeyword(importedName.value)) { reportExpectedError(null, PredefinedName.AS); } return new ImportSpecifierTree( getTreeLocation(start), importedName, destinationName); }
private ParseTree parseImportSpecifier() { SourcePosition start = getTreeStartLocation(); IdentifierToken importedName = eatIdOrKeywordAsId(); IdentifierToken destinationName = null; if (peekPredefinedString(PredefinedName.AS)) { eatPredefinedString(PredefinedName.AS); destinationName = eatId(); } else if (Keywords.isKeyword(importedName.value)) { reportExpectedError(null, PredefinedName.AS); } return new ImportSpecifierTree( getTreeLocation(start), importedName, destinationName); }
private ParseTree parseComprehensionFor() { SourcePosition start = getTreeStartLocation(); eat(TokenType.FOR); eat(TokenType.OPEN_PAREN); ParseTree initializer; if (peekId()) { initializer = parseIdentifierExpression(); } else { initializer = parsePattern(PatternKind.ANY); } eatPredefinedString(PredefinedName.OF); ParseTree collection = parseAssignmentExpression(); eat(TokenType.CLOSE_PAREN); return new ComprehensionForTree( getTreeLocation(start), initializer, collection); }
private ParseTree parseComprehensionFor() { SourcePosition start = getTreeStartLocation(); eat(TokenType.FOR); eat(TokenType.OPEN_PAREN); ParseTree initializer; if (peekId()) { initializer = parseIdentifierExpression(); } else { initializer = parsePattern(PatternKind.ANY); } eatPredefinedString(PredefinedName.OF); ParseTree collection = parseAssignmentExpression(); eat(TokenType.CLOSE_PAREN); return new ComprehensionForTree( getTreeLocation(start), initializer, collection); }
private ParseTree parseAsyncArrowFunction(Expression expressionIn) { SourcePosition start = getTreeStartLocation(); eatPredefinedString(ASYNC); if (peekImplicitSemiColon()) { reportError("No newline allowed between `async` and arrow function parameter list"); } FormalParameterListTree arrowParameterList = null; if (peek(TokenType.OPEN_PAREN)) { // async (...) => arrowParameterList = parseFormalParameterList(ParamContext.IMPLEMENTATION); } else { // async arg => final IdentifierExpressionTree singleParameter = parseIdentifierExpression(); arrowParameterList = new FormalParameterListTree( singleParameter.location, ImmutableList.<ParseTree>of(singleParameter)); } if (peekImplicitSemiColon()) { reportError("No newline allowed before '=>'"); } eat(TokenType.ARROW); ParseTree arrowFunctionBody = parseArrowFunctionBody(expressionIn, FunctionFlavor.ASYNCHRONOUS); FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.ARROW) .setAsync(true) .setFormalParameterList(arrowParameterList) .setFunctionBody(arrowFunctionBody); return builder.build(getTreeLocation(start)); }
if (peek(TokenType.STAR)) { eat(TokenType.STAR); eatPredefinedString(PredefinedName.AS); nameSpaceImportIdentifier = eatId(); } else { eatPredefinedString(PredefinedName.FROM); Token moduleStr = eat(TokenType.STRING); LiteralToken moduleSpecifier = (moduleStr == null)
private ParseTree parseSetAccessor(PartialClassElement partial) { eatPredefinedString(PredefinedName.SET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); FormalParameterListTree parameter = parseSetterParameterList(); ParseTree returnType = maybeParseColonType(); if (returnType != null) { reportError(scanner.peekToken(), "setter should not have any returns"); } BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.SETTER); return new SetAccessorTree( getTreeLocation(partial.start), propertyName, partial.isStatic, parameter, body); } else { ParseTree property = parseComputedPropertyName(); FormalParameterListTree parameter = parseSetterParameterList(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.SETTER); return new ComputedPropertySetterTree( getTreeLocation(partial.start), property, partial.isStatic, partial.accessModifier, parameter, body); } }
if (peek(TokenType.STAR)) { eat(TokenType.STAR); eatPredefinedString(PredefinedName.AS); nameSpaceImportIdentifier = eatId(); } else { eatPredefinedString(PredefinedName.FROM); Token moduleStr = eat(TokenType.STRING); LiteralToken moduleSpecifier = (moduleStr == null)
private ParseTree parseGetAccessor(TokenType access) { SourcePosition start = getTreeStartLocation(); boolean isStatic = eatOpt(TokenType.STATIC) != null; eatPredefinedString(PredefinedName.GET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); return new GetAccessorTree(getTreeLocation(start), propertyName, isStatic, returnType, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); return new ComputedPropertyGetterTree( getTreeLocation(start), property, isStatic, access, returnType, body); } }
private ParseTree parseGetAccessor(PartialClassElement partial) { eatPredefinedString(PredefinedName.GET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.GETTER); return new GetAccessorTree( getTreeLocation(partial.start), propertyName, partial.isStatic, returnType, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.GETTER); return new ComputedPropertyGetterTree( getTreeLocation(partial.start), property, partial.isStatic, partial.accessModifier, returnType, body); } }
private ParseTree parseSetAccessor(TokenType access) { SourcePosition start = getTreeStartLocation(); boolean isStatic = eatOpt(TokenType.STATIC) != null; eatPredefinedString(PredefinedName.SET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); IdentifierToken parameter = eatId(); ParseTree type = maybeParseColonType(); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); if (returnType != null) { reportError(scanner.peekToken(), "setter should not have any returns"); } BlockTree body = parseFunctionBody(); return new SetAccessorTree( getTreeLocation(start), propertyName, isStatic, parameter, type, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); IdentifierToken parameter = eatId(); ParseTree type = maybeParseColonType(); eat(TokenType.CLOSE_PAREN); BlockTree body = parseFunctionBody(); return new ComputedPropertySetterTree( getTreeLocation(start), property, isStatic, access, parameter, type, body); } }