use of com.google.javascript.rhino.JSDocInfoBuilder 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);
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class Es6TypedToEs6Converter method visitAmbientDeclaration.
private void visitAmbientDeclaration(NodeTraversal t, Node n, Node parent) {
if (!n.isFromExterns()) {
compiler.report(JSError.make(n, DECLARE_IN_NON_EXTERNS));
}
Node insertionPoint = n;
Node topLevel = parent;
boolean insideExport = parent.isExport();
if (insideExport) {
insertionPoint = parent;
topLevel = parent.getParent();
}
// The node can have multiple children if transformed from an ambient namespace declaration.
for (Node c : n.children()) {
if (c.isConst()) {
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(c.getJSDocInfo());
builder.recordConstancy();
c.setToken(Token.VAR);
c.setJSDocInfo(builder.build());
}
Node toAdd = c.detach();
if (insideExport && !toAdd.isExprResult()) {
// We want to keep the "export" declaration in externs
toAdd = new Node(Token.EXPORT, toAdd).srcref(parent);
}
topLevel.addChildBefore(toAdd, insertionPoint);
}
insertionPoint.detach();
t.reportCodeChange();
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class Es6TypedToEs6Converter method maybeAddVisibility.
private void maybeAddVisibility(Node n) {
Visibility access = (Visibility) n.getProp(Node.ACCESS_MODIFIER);
if (access != null) {
if (n.isComputedProp()) {
compiler.report(JSError.make(n, COMPUTED_PROP_ACCESS_MODIFIER));
}
JSDocInfoBuilder memberDoc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
memberDoc.recordVisibility(access);
n.setJSDocInfo(memberDoc.build());
n.removeProp(Node.ACCESS_MODIFIER);
}
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class Es6TypedToEs6Converter method visitEnum.
private void visitEnum(NodeTraversal t, Node n, Node parent) {
Node name = n.getFirstChild();
Node members = n.getLastChild();
double nextValue = 0;
Node[] stringKeys = new Node[members.getChildCount()];
int i = 0;
for (Node child = members.getFirstChild(); child != null; child = child.getNext(), i++) {
if (child.hasChildren()) {
nextValue = child.getFirstChild().getDouble() + 1;
} else {
child.addChildToFront(IR.number(nextValue++));
}
stringKeys[i] = child;
}
members.detachChildren();
String oldName = name.getString();
String qName = maybePrependCurrNamespace(oldName);
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
builder.recordEnumParameterType(new JSTypeExpression(IR.string("number"), n.getSourceFileName()));
Node newDec = NodeUtil.newQNameDeclaration(compiler, qName, IR.objectlit(stringKeys), builder.build()).useSourceInfoFromForTree(n);
n.setJSDocInfo(null);
parent.replaceChild(n, newDec);
t.reportCodeChange();
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class Es6TypedToEs6Converter method maybeAddGenerics.
private void maybeAddGenerics(Node n, Node jsDocNode) {
Node name = n.getFirstChild();
Node generics = (Node) name.getProp(Node.GENERIC_TYPE_LIST);
if (generics != null) {
JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(jsDocNode.getJSDocInfo());
// Discard the type bound (the "extends" part) for now
for (Node typeName : generics.children()) {
doc.recordTemplateTypeName(typeName.getString());
if (typeName.hasChildren()) {
compiler.report(JSError.make(name, CANNOT_CONVERT_BOUNDED_GENERICS));
typeName.removeChildren();
}
}
name.removeProp(Node.GENERIC_TYPE_LIST);
jsDocNode.setJSDocInfo(doc.build());
}
}
Aggregations