private static JsDocInfoParser getParser(String toParse) { Config config = Config.builder() .setLanguageMode(LanguageMode.ECMASCRIPT3) .setStrictMode(Config.StrictMode.SLOPPY) .build(); JsDocInfoParser parser = new JsDocInfoParser( new JsDocTokenStream(toParse), toParse, 0, null, config, ErrorReporter.NULL_INSTANCE); return parser; }
Node processTypedParameter(TypedParameterTree typeAnnotation) { Node param = transform(typeAnnotation.param); maybeProcessType(param, typeAnnotation.typeAnnotation); return param; }
Node processRestParameter(RestParameterTree tree) { maybeWarnEs6Feature(tree, Feature.REST_PARAMETERS); Node name = newStringNode(Token.NAME, tree.identifier.value); setSourceInfo(name, tree.identifier); return newNode(Token.REST, name); }
Node processImportDecl(ImportDeclarationTree tree) { maybeWarnEs6Feature(tree, Feature.MODULES); Node firstChild = transformOrEmpty(tree.defaultBindingIdentifier, tree); Node secondChild = (tree.nameSpaceImportIdentifier != null) ? newStringNode(Token.IMPORT_STAR, tree.nameSpaceImportIdentifier.value) : transformListOrEmpty(Token.IMPORT_SPECS, tree.importSpecifierList); setSourceInfo(secondChild, tree); Node thirdChild = processString(tree.moduleSpecifier); return newNode(Token.IMPORT, firstChild, secondChild, thirdChild); }
Node processBinaryExpression(BinaryOperatorTree exprNode) { if (hasPendingCommentBefore(exprNode.right)) { return newNode( transformBinaryTokenType(exprNode.operator.type), transform(exprNode.left), transform(exprNode.right)); } else { // No JSDoc, we can traverse out of order. return processBinaryExpressionHelper(exprNode); } }
Node transformOrEmpty(IdentifierToken token, ParseTree parent) { if (token == null) { Node n = newNode(Token.EMPTY); setSourceInfo(n, parent); return n; } return processName(token); }
static FeatureSet detectFeatures( ProgramTree tree, StaticSourceFile sourceFile, String sourceString) { IRFactory irFactory = new IRFactory(sourceString, sourceFile, NULL_CONFIG, NULL_REPORTER, tree.sourceComments); Node n = irFactory.transformDispatcher.process(tree); irFactory.validateAll(n); return irFactory.features; }
Node processLabeledStatement(LabelledStatementTree labelTree) { return newNode(Token.LABEL, transformLabelName(labelTree.name), transform(labelTree.statement)); }
/** * Looks for a type expression at the current token and if found, * returns it. Note that this method consumes input. * * @param token The current token. * @return The type expression found or null if none. */ Node parseAndRecordTypeNode(JsDocToken token) { return parseAndRecordTypeNode(token, stream.getLineno(), stream.getCharno(), token == JsDocToken.LEFT_CURLY, false); }
Node processAmbientDeclaration(AmbientDeclarationTree tree) { maybeWarnTypeSyntax(tree, Feature.AMBIENT_DECLARATION); return newNode(Token.DECLARE, transform(tree.declaration)); }
private Node reportTypeSyntaxWarning(String warning) { addTypeWarning(warning, stream.getLineno(), stream.getCharno()); return null; }
Node processComputedPropertyDefinition(ComputedPropertyDefinitionTree tree) { maybeWarnEs6Feature(tree, Feature.COMPUTED_PROPERTIES); return newNode(Token.COMPUTED_PROP, transform(tree.property), transform(tree.value)); }
/** * Gets the next token of the token stream or the buffered token if a matching * was previously made. */ private JsDocToken next() { if (unreadToken == NO_UNREAD_TOKEN) { return stream.getJsDocToken(); } else { return current(); } }
Node processUpdateExpression(UpdateExpressionTree updateExpr) { Token type = transformUpdateTokenType(updateExpr.operator.type); Node operand = transform(updateExpr.operand); return createUpdateNode( type, updateExpr.operatorPosition == OperatorPosition.POSTFIX, operand); }
Node processParenthesizedExpression(ParenExpressionTree exprNode) { checkParenthesizedExpression(exprNode); return transform(exprNode.expression); }
private Node convertTypeTree(ParseTree typeTree) { maybeWarnTypeSyntax(typeTree, Feature.TYPE_ANNOTATION); return transform(typeTree); }
Node processNewTarget(NewTargetExpressionTree tree) { maybeWarnEs6Feature(tree, Feature.NEW_TARGET); return newNode(Token.NEW_TARGET); }
private boolean inStrictContext() { // TODO(johnlenz): in ECMASCRIPT5/6 is a "mixed" mode and we should track the context // that we are in, if we want to support it. return config.strictMode().isStrict(); }
Node transformOrEmpty(IdentifierToken token, ParseTree parent) { if (token == null) { Node n = newNode(Token.EMPTY); setSourceInfo(n, parent); return n; } return processName(token); }
Node processTypedParameter(TypedParameterTree typeAnnotation) { Node param = transform(typeAnnotation.param); maybeProcessType(param, typeAnnotation.typeAnnotation); return param; }