/** Returns true if the string value should be treated as a keyword in the current context. */ private boolean isKeyword(String value) { return Keywords.isKeyword(value, config.parseTypeSyntax); }
private boolean peekPropertyName(int tokenIndex) { TokenType type = peekType(tokenIndex); switch (type) { case IDENTIFIER: case STRING: case NUMBER: return true; default: return Keywords.isKeyword(type); } }
private boolean peekPropertyName(int tokenIndex) { TokenType type = peekType(tokenIndex); switch (type) { case IDENTIFIER: case STRING: case NUMBER: return true; default: return Keywords.isKeyword(type); } }
private boolean peekClassElement() { Token token = peekToken(); switch (token.type) { case IDENTIFIER: case STAR: case STATIC: case OPEN_SQUARE: case SEMI_COLON: return true; default: return Keywords.isKeyword(token.type); } }
private boolean peekIdOrKeyword() { TokenType type = peekType(); return TokenType.IDENTIFIER == type || Keywords.isKeyword(type); }
private boolean peekIdOrKeyword() { TokenType type = peekType(); return TokenType.IDENTIFIER == type || Keywords.isKeyword(type); }
private boolean peekInterfaceElement() { Token token = peekToken(); switch (token.type) { case NEW: case IDENTIFIER: case OPEN_SQUARE: case STAR: case OPEN_ANGLE: case OPEN_PAREN: return true; default: return Keywords.isKeyword(token.type); } }
private boolean peekInterfaceElement() { Token token = peekToken(); switch (token.type) { case NEW: case IDENTIFIER: case OPEN_SQUARE: case STAR: case OPEN_ANGLE: case OPEN_PAREN: return true; default: return Keywords.isKeyword(token.type); } }
private boolean peekClassElement() { Token token = peekToken(); switch (token.type) { case IDENTIFIER: case NUMBER: case STAR: case STATIC: case STRING: case OPEN_SQUARE: case SEMI_COLON: return true; default: return Keywords.isKeyword(token.type); } }
/** * Consumes an identifier token that may be a reserved word, i.e. * an IdentifierName, not necessarily an Identifier. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatIdOrKeywordAsId() { Token token = nextToken(); if (token.type == TokenType.IDENTIFIER) { return (IdentifierToken) token; } else if (Keywords.isKeyword(token.type)) { return new IdentifierToken( token.location, Keywords.get(token.type).toString()); } else { reportExpectedError(token, TokenType.IDENTIFIER); } return null; }
/** * Consumes an identifier token that may be a reserved word, i.e. * an IdentifierName, not necessarily an Identifier. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatIdOrKeywordAsId() { Token token = nextToken(); if (token.type == TokenType.IDENTIFIER) { return (IdentifierToken) token; } else if (Keywords.isKeyword(token.type)) { return new IdentifierToken( token.location, Keywords.get(token.type).toString()); } else { reportExpectedError(token, TokenType.IDENTIFIER); } return null; }
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 parsePropertyAssignmentGenerator() { TokenType type = peekType(1); if (type == TokenType.STRING || type == TokenType.NUMBER || type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) { // parseMethodDeclaration will consume the '*'. return parseClassMemberDeclaration(false, false, null); } else { SourcePosition start = getTreeStartLocation(); eat(TokenType.STAR); ParseTree name = parseComputedPropertyName(); ParseTree value = parseFunctionTail( start, null, false, true, null, FunctionDeclarationTree.Kind.EXPRESSION); return new ComputedPropertyMethodTree(getTreeLocation(start), null, name, value); } }
private ParseTree parsePropertyAssignmentGenerator() { TokenType type = peekType(1); if (type == TokenType.STRING || type == TokenType.NUMBER || type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) { // parseMethodDeclaration will consume the '*'. return parseClassMemberDeclaration(); } else { SourcePosition start = getTreeStartLocation(); eat(TokenType.STAR); ParseTree name = parseComputedPropertyName(); FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION); parseFunctionTail(builder, FunctionFlavor.GENERATOR); ParseTree value = builder.build(getTreeLocation(start)); return new ComputedPropertyMethodTree(getTreeLocation(start), null, name, value); } }
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, /* includeTypeScriptKeywords= */ false)) { 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); }
} else if (type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) { name = eatIdOrKeywordAsId(); } else if (type == TokenType.OPEN_SQUARE) { // IndexSignature
} else if (type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) { name = eatIdOrKeywordAsId(); } else if (type == TokenType.OPEN_SQUARE) { // IndexSignature
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); }
if (!peek(TokenType.COLON)) { IdentifierToken idToken = (IdentifierToken) name; if (Keywords.isKeyword(idToken.value, /* includeTypeScriptKeywords = */ false)) { reportError("cannot use keyword '%s' here.", name);
if (!peek(TokenType.COLON)) { IdentifierToken idToken = (IdentifierToken) name; if (Keywords.isKeyword(idToken.value) && !Keywords.isTypeScriptSpecificKeyword(idToken.value)) { reportError("cannot use keyword '" + name + "' here.");