use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class Es6TypedToEs6Converter method visitNamespaceDeclaration.
private void visitNamespaceDeclaration(NodeTraversal t, Node n, Node parent) {
popNamespace(n, parent);
for (Node name = NodeUtil.getRootOfQualifiedName(n.getFirstChild()); name != n; name = name.getParent()) {
String fullName = maybePrependCurrNamespace(name.getQualifiedName());
if (!convertedNamespaces.contains(fullName)) {
JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
doc.recordConstancy();
Node namespaceDec = NodeUtil.newQNameDeclaration(compiler, fullName, IR.objectlit(), doc.build()).useSourceInfoFromForTree(n);
parent.addChildBefore(namespaceDec, n);
convertedNamespaces.add(fullName);
}
}
replaceWithNodes(t, n, n.getLastChild().children());
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class AngularPass method hotSwapScript.
@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
// Traverses AST looking for nodes annotated with @ngInject.
NodeTraversal.traverseEs6(compiler, scriptRoot, this);
// iterates through annotated nodes adding $inject property to elements.
for (NodeContext entry : injectables) {
String name = entry.getName();
Node fn = entry.getFunctionNode();
List<Node> dependencies = createDependenciesList(fn);
// skips entry if it does not have any dependencies.
if (dependencies.isEmpty()) {
continue;
}
Node dependenciesArray = IR.arraylit(dependencies.toArray(new Node[0]));
// creates `something.$inject = ['param1', 'param2']` node.
Node statement = IR.exprResult(IR.assign(IR.getelem(NodeUtil.newQName(compiler, name), IR.string(INJECT_PROPERTY_NAME)), dependenciesArray));
statement.useSourceInfoFromForTree(entry.getNode());
statement.setOriginalName(name);
// Set the visibility of the newly created property.
JSDocInfoBuilder newPropertyDoc = new JSDocInfoBuilder(false);
newPropertyDoc.recordVisibility(Visibility.PUBLIC);
statement.getFirstChild().setJSDocInfo(newPropertyDoc.build());
// adds `something.$inject = [...]` node after the annotated node or the following
// goog.inherits call.
Node insertionPoint = entry.getTarget();
Node next = insertionPoint.getNext();
while (next != null && NodeUtil.isExprCall(next) && compiler.getCodingConvention().getClassesDefinedByCall(next.getFirstChild()) != null) {
insertionPoint = next;
next = insertionPoint.getNext();
}
insertionPoint.getParent().addChildAfter(statement, insertionPoint);
compiler.reportChangeToEnclosingScope(statement);
}
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class ClosureRewriteModule method markConst.
private void markConst(Node n) {
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
builder.recordConstancy();
n.setJSDocInfo(builder.build());
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class CheckSideEffects method addExtern.
private void addExtern() {
Node name = IR.name(PROTECTOR_FN);
name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
Node var = IR.var(name);
JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
var.setJSDocInfo(builder.build());
CompilerInput input = compiler.getSynthesizedExternsInput();
Node root = input.getAstRoot(compiler);
name.setStaticSourceFileFrom(root);
var.setStaticSourceFileFrom(root);
root.addChildToBack(var);
compiler.reportChangeToEnclosingScope(var);
}
use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.
the class Es6ToEs3ClassSideInheritance method copyStaticMembers.
private void copyStaticMembers(JavascriptClass superClass, JavascriptClass subClass, Node inheritsCall, FindStaticMembers findStaticMembers) {
for (Node staticMember : superClass.staticMembers) {
checkState(staticMember.isAssign(), staticMember);
String memberName = staticMember.getFirstChild().getLastChild().getString();
if (superClass.definedProperties.contains(memberName)) {
continue;
}
if (isOverriden(subClass, memberName)) {
continue;
}
if (findStaticMembers.isBefore(inheritsCall, staticMember)) {
// is done by copying, rather than prototype manipulation.
continue;
}
JSDocInfoBuilder info = JSDocInfoBuilder.maybeCopyFrom(staticMember.getJSDocInfo());
Node function = staticMember.getLastChild();
Node sourceInfoNode = function;
if (function.isFunction()) {
sourceInfoNode = function.getFirstChild();
Node params = NodeUtil.getFunctionParameters(function);
checkState(params.isParamList(), params);
for (Node param : params.children()) {
if (param.getJSDocInfo() != null) {
String name = param.getString();
info.recordParameter(name, param.getJSDocInfo().getType());
}
}
}
Node subclassNameNode = inheritsCall.getSecondChild();
Node superclassNameNode = subclassNameNode.getNext();
Node assign = IR.assign(IR.getprop(subclassNameNode.cloneTree(), IR.string(memberName)), IR.getprop(superclassNameNode.cloneTree(), IR.string(memberName)));
info.addSuppression("visibility");
assign.setJSDocInfo(info.build());
Node exprResult = IR.exprResult(assign);
exprResult.useSourceInfoIfMissingFromForTree(sourceInfoNode);
Node inheritsExpressionResult = inheritsCall.getParent();
inheritsExpressionResult.getParent().addChildAfter(exprResult, inheritsExpressionResult);
compiler.reportChangeToEnclosingScope(inheritsExpressionResult);
// Add the static member to the subclass so that subclasses also copy this member.
subClass.staticMembers.add(assign);
}
}
Aggregations