static int charno(ParseTree node) { return charno(node.location.start); }
static int charno(com.google.javascript.jscomp.parsing.parser.Token token) { return charno(token.location.start); }
static int charno(ParseTree node) { return charno(node.location.start); }
/** * Check to see if the given block comment looks like it should be JSDoc. */ private void handleBlockComment(Comment comment) { Pattern p = Pattern.compile("(/|(\n[ \t]*))\\*[ \t]*@[a-zA-Z]+[ \t\n{]"); if (p.matcher(comment.value).find()) { errorReporter.warning( SUSPICIOUS_COMMENT_WARNING, sourceName, lineno(comment.location.start), charno(comment.location.start)); } }
void recordTypeSyntax(SourceRange location) { if (hasJsDocTypeAnnotations) { errorReporter.error("Can only have JSDoc or inline type annotations, not both", sourceName, lineno(location.start), charno(location.start)); } }
void recordTypeSyntax(SourceRange location) { if (hasJsDocTypeAnnotations) { errorReporter.error("Can only have JSDoc or inline type annotations, not both", sourceName, lineno(location.start), charno(location.start)); } }
private void checkParenthesizedExpression(ParenExpressionTree exprNode) { if (exprNode.expression.type == ParseTreeType.COMMA_EXPRESSION) { List<ParseTree> commaNodes = exprNode.expression.asCommaExpression().expressions; ParseTree lastChild = Iterables.getLast(commaNodes); if (lastChild.type == ParseTreeType.REST_PARAMETER) { errorReporter.error( "A rest parameter must be in a parameter list.", sourceName, lineno(lastChild), charno(lastChild)); } } }
private void checkParenthesizedExpression(ParenExpressionTree exprNode) { if (exprNode.expression.type == ParseTreeType.COMMA_EXPRESSION) { List<ParseTree> commaNodes = exprNode.expression.asCommaExpression().expressions; ParseTree lastChild = Iterables.getLast(commaNodes); if (lastChild.type == ParseTreeType.REST_PARAMETER) { errorReporter.error( "A rest parameter must be in a parameter list.", sourceName, lineno(lastChild), charno(lastChild)); } } }
Node unsupportedLanguageFeature(ParseTree node, String feature) { errorReporter.error( "unsupported language feature: " + feature, sourceName, lineno(node), charno(node)); return createMissingExpressionNode(); }
JSDocInfo recordJsDoc(SourceRange location, JSDocInfo info) { if (info != null && info.hasTypeInformation()) { hasJsDocTypeAnnotations = true; if (features.version().equals("ts")) { errorReporter.error("Can only have JSDoc or inline type annotations, not both", sourceName, lineno(location.start), charno(location.start)); } } return info; }
Node unsupportedLanguageFeature(ParseTree node, String feature) { errorReporter.error( "unsupported language feature: " + feature, sourceName, lineno(node), charno(node)); return createMissingExpressionNode(); }
void maybeWarnEs6Feature(ParseTree node, Feature feature) { features = features.require(feature); if (!isEs6Mode()) { errorReporter.warning( "this language feature is only supported in es6 mode: " + feature, sourceName, lineno(node), charno(node)); } }
JSDocInfo recordJsDoc(SourceRange location, JSDocInfo info) { if (info != null && info.hasTypeInformation()) { hasJsDocTypeAnnotations = true; if (features.isTypeScript()) { errorReporter.error("Can only have JSDoc or inline type annotations, not both", sourceName, lineno(location.start), charno(location.start)); } } return info; }
void maybeWarnTypeSyntax(ParseTree node, Feature feature) { if (config.languageMode != LanguageMode.ECMASCRIPT6_TYPED) { errorReporter.warning( "type syntax is only supported in ES6 typed mode: " + feature, sourceName, lineno(node), charno(node)); } features = features.require(feature); recordTypeSyntax(node.location); }
Node processForInLoop(ForInStatementTree loopNode) { Node initializer = transform(loopNode.initializer); ImmutableSet<Integer> invalidInitializers = ImmutableSet.of(Token.ARRAYLIT, Token.OBJECTLIT); if (invalidInitializers.contains(initializer.getType())) { errorReporter.error("Invalid LHS for a for-in loop", sourceName, lineno(loopNode.initializer), charno(loopNode.initializer)); } return newNode( Token.FOR, initializer, transform(loopNode.collection), transformBlock(loopNode.body)); }
void maybeWarnForFeature( com.google.javascript.jscomp.parsing.parser.Token token, Feature feature) { features = features.with(feature); if (!isSupportedForInputLanguageMode(feature)) { errorReporter.warning( languageFeatureWarningMessage(feature), sourceName, lineno(token), charno(token)); } }
void maybeWarnForFeature(ParseTree node, Feature feature) { features = features.with(feature); if (!isSupportedForInputLanguageMode(feature)) { errorReporter.warning( languageFeatureWarningMessage(feature), sourceName, lineno(node), charno(node)); } }
void maybeWarnTypeSyntax(ParseTree node, Feature feature) { if (config.languageMode() != LanguageMode.TYPESCRIPT) { errorReporter.warning( "type syntax is only supported in ES6 typed mode: " + feature, sourceName, lineno(node), charno(node)); } features = features.with(feature); recordTypeSyntax(node.location); }
void setSourceInfo( Node node, SourcePosition start, SourcePosition end) { if (node.getLineno() == -1) { // If we didn't already set the line, then set it now. This avoids // cases like ParenthesizedExpression where we just return a previous // node, but don't want the new node to get its parent's line number. int lineno = lineno(start); node.setLineno(lineno); int charno = charno(start); node.setCharno(charno); maybeSetLength(node, start, end); } }
void setSourceInfo( Node node, SourcePosition start, SourcePosition end) { if (node.getLineno() == -1) { // If we didn't already set the line, then set it now. This avoids // cases like ParenthesizedExpression where we just return a previous // node, but don't want the new node to get its parent's line number. int lineno = lineno(start); node.setLineno(lineno); int charno = charno(start); node.setCharno(charno); setLength(node, start, end); } }