Search in sources :

Example 6 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class JSDocInfoPrinterTest method setUp.

@Override
protected void setUp() {
    builder = new JSDocInfoBuilder(true);
    jsDocInfoPrinter = new JSDocInfoPrinter(false);
}
Also used : JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Example 7 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class IRFactory method setFileOverviewJsDoc.

private void setFileOverviewJsDoc(Node irNode) {
    // Only after we've seen all @fileoverview entries, attach the
    // last one to the root node, and copy the found license strings
    // to that node.
    JSDocInfo rootNodeJsDoc = fileLevelJsDocBuilder.build();
    if (rootNodeJsDoc != null) {
        irNode.setJSDocInfo(rootNodeJsDoc);
    }
    if (fileOverviewInfo != null) {
        if ((irNode.getJSDocInfo() != null) && (irNode.getJSDocInfo().getLicense() != null)) {
            JSDocInfoBuilder builder = JSDocInfoBuilder.copyFrom(fileOverviewInfo);
            builder.recordLicense(irNode.getJSDocInfo().getLicense());
            fileOverviewInfo = builder.build();
        }
        irNode.setJSDocInfo(fileOverviewInfo);
    }
}
Also used : JSDocInfo(com.google.javascript.rhino.JSDocInfo) JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Example 8 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class JsDocInfoParserTest method testParseLicenseAscii.

public void testParseLicenseAscii() {
    this.fileLevelJsDocBuilder = new JSDocInfoBuilder(false);
    String comment = "@license Foo\n *   Bar\n\n  Baz*/";
    parse(comment);
    JSDocInfo info = this.fileLevelJsDocBuilder.build(true);
    assertThat(info.getLicense()).isEqualTo(" Foo\n   Bar\n\n  Baz");
}
Also used : JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder) JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Example 9 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class Es6RewriteBlockScopedDeclaration method maybeAddConstJSDoc.

private static void maybeAddConstJSDoc(Node srcDeclaration, Node srcParent, Node srcName, Node destDeclaration) {
    if (srcDeclaration.isConst() && // Don't add @const for the left side of a for/in. If we do we get warnings from the NTI.
    !(srcParent.isForIn() && srcDeclaration == srcParent.getFirstChild())) {
        extractInlineJSDoc(srcDeclaration, srcName, destDeclaration);
        JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(destDeclaration.getJSDocInfo());
        builder.recordConstancy();
        destDeclaration.setJSDocInfo(builder.build());
    }
}
Also used : JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Example 10 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class Es6RewriteModules method createExportsObject.

private Node createExportsObject(NodeTraversal t, Node script) {
    String moduleName = t.getInput().getPath().toModuleName();
    Set<String> exportedNames = new HashSet<>();
    Node objLit = IR.objectlit();
    // Going to get renamed by rename global vars, doesn't matter
    Node moduleVar = IR.var(IR.name("exports"), objLit);
    moduleVar.getFirstChild().putBooleanProp(Node.MODULE_EXPORT, true);
    JSDocInfoBuilder infoBuilder = new JSDocInfoBuilder(false);
    infoBuilder.recordConstancy();
    moduleVar.setJSDocInfo(infoBuilder.build());
    script.addChildToBack(moduleVar.useSourceInfoIfMissingFromForTree(script));
    for (Map.Entry<String, NameNodePair> entry : exportsByLocalName.entries()) {
        NameNodePair pair = entry.getValue();
        String exportedName = pair.exportedName;
        Node nodeForSourceInfo = pair.nodeForSourceInfo;
        if (!exportedNames.add(exportedName)) {
            t.report(nodeForSourceInfo, DUPLICATE_EXPORT, exportedName);
            continue;
        }
        String withSuffix = entry.getKey();
        boolean mutated = pair.mutated;
        Node getProp = IR.getprop(IR.name(moduleName), IR.string(exportedName));
        getProp.putBooleanProp(Node.MODULE_EXPORT, true);
        if (typedefs.contains(exportedName)) {
            // /** @typedef {foo} */
            // moduleName.foo;
            JSDocInfoBuilder builder = new JSDocInfoBuilder(true);
            JSTypeExpression typeExpr = new JSTypeExpression(IR.string(exportedName), script.getSourceFileName());
            builder.recordTypedef(typeExpr);
            JSDocInfo info = builder.build();
            getProp.setJSDocInfo(info);
            Node exprResult = IR.exprResult(getProp).useSourceInfoIfMissingFromForTree(nodeForSourceInfo);
            script.addChildToBack(exprResult);
        } else if (mutated || importMap.containsKey(withSuffix)) {
            addGetterExport(script, nodeForSourceInfo, objLit, exportedName, withSuffix);
        } else {
            // This step is done before type checking and the type checker doesn't understand getters.
            // However it does understand aliases. So if an export isn't mutated use an alias to make it
            // actually type checkable.
            // exports.foo = foo;
            Node assign = IR.assign(getProp, NodeUtil.newQName(compiler, withSuffix));
            if (classes.contains(exportedName)) {
                JSDocInfoBuilder builder = new JSDocInfoBuilder(true);
                builder.recordConstancy();
                JSDocInfo info = builder.build();
                assign.setJSDocInfo(info);
            }
            script.addChildToBack(IR.exprResult(assign).useSourceInfoIfMissingFromForTree(nodeForSourceInfo));
        }
    }
    exportsByLocalName.clear();
    return moduleVar;
}
Also used : Node(com.google.javascript.rhino.Node) JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder) JSDocInfo(com.google.javascript.rhino.JSDocInfo) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

JSDocInfoBuilder (com.google.javascript.rhino.JSDocInfoBuilder)40 Node (com.google.javascript.rhino.Node)27 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)18 TypeDeclarationNode (com.google.javascript.rhino.Node.TypeDeclarationNode)10 JSDocInfo (com.google.javascript.rhino.JSDocInfo)8 MemberDefinition (com.google.javascript.jscomp.PolymerPass.MemberDefinition)4 Visibility (com.google.javascript.rhino.JSDocInfo.Visibility)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ClassDeclarationMetadata (com.google.javascript.jscomp.Es6RewriteClass.ClassDeclarationMetadata)1 FeatureSet (com.google.javascript.jscomp.parsing.parser.FeatureSet)1 TypeI (com.google.javascript.rhino.TypeI)1 TypeIRegistry (com.google.javascript.rhino.TypeIRegistry)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1