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);
}
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);
}
}
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");
}
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());
}
}
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;
}
Aggregations