Keywords(String value, TokenType type) { this.value = value; this.type = type; this.isTypeScriptSpecificKeyword = isTypeScriptSpecificKeyword(type); }
/** @return whether the next token is an identifier. */ private boolean peekId(int index) { TokenType type = peekType(index); // There are two special cases to handle here: // * outside of strict-mode code strict-mode keywords can be used as identifiers // * when configured to parse TypeScript code the scanner will return TypeScript // keyword token but these contextual keywords can always be used as idenifiers. return TokenType.IDENTIFIER == type || (config.parseTypeSyntax && Keywords.isTypeScriptSpecificKeyword(type)) || (!inStrictContext() && Keywords.isStrictKeyword(type)); }
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); }
IdentifierToken idToken = (IdentifierToken) name; if (Keywords.isKeyword(idToken.value) && !Keywords.isTypeScriptSpecificKeyword(idToken.value)) { reportError("cannot use keyword '" + name + "' here.");