Search in sources :

Example 1 with ClassDeclarationMetadata

use of com.google.javascript.jscomp.Es6RewriteClass.ClassDeclarationMetadata in project closure-compiler by google.

the class Es6TypedToEs6Converter method visitClass.

private void visitClass(NodeTraversal t, Node n, Node parent) {
    maybeAddGenerics(n, n);
    JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
    Node interfaces = (Node) n.getProp(Node.IMPLEMENTS);
    if (interfaces != null) {
        for (Node child : interfaces.children()) {
            Node type = convertWithLocation(child);
            doc.recordImplementedInterface(new JSTypeExpression(type, n.getSourceFileName()));
        }
        n.removeProp(Node.IMPLEMENTS);
    }
    Node superType = n.getSecondChild();
    Node newSuperType = maybeGetQualifiedNameNode(superType);
    if (newSuperType != superType) {
        n.replaceChild(superType, newSuperType);
    }
    Node classMembers = n.getLastChild();
    ClassDeclarationMetadata metadata = ClassDeclarationMetadata.create(n, parent);
    for (Node member : classMembers.children()) {
        if (member.isCallSignature()) {
            compiler.report(JSError.make(n, CALL_SIGNATURE_NOT_SUPPORTED));
            continue;
        }
        if (member.isIndexSignature()) {
            doc.recordImplementedInterface(createIObject(t, member));
            continue;
        }
        // Functions are handled by the regular Es6ToEs3Converter
        if (!member.isMemberVariableDef() && !member.getBooleanProp(Node.COMPUTED_PROP_VARIABLE)) {
            maybeAddVisibility(member);
            continue;
        }
        if (metadata == null) {
            compiler.report(JSError.make(n, CANNOT_CONVERT_MEMBER_VARIABLES));
            return;
        }
        metadata.insertNodeAndAdvance(createPropertyDefinition(t, member, metadata.fullClassName));
        t.reportCodeChange();
    }
    n.setJSDocInfo(doc.build());
    maybeCreateQualifiedDeclaration(t, n, parent);
}
Also used : ClassDeclarationMetadata(com.google.javascript.jscomp.Es6RewriteClass.ClassDeclarationMetadata) TypeDeclarationNode(com.google.javascript.rhino.Node.TypeDeclarationNode) Node(com.google.javascript.rhino.Node) JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Aggregations

ClassDeclarationMetadata (com.google.javascript.jscomp.Es6RewriteClass.ClassDeclarationMetadata)1 JSDocInfoBuilder (com.google.javascript.rhino.JSDocInfoBuilder)1 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)1 Node (com.google.javascript.rhino.Node)1 TypeDeclarationNode (com.google.javascript.rhino.Node.TypeDeclarationNode)1