本文整理汇总了Java中com.google.javascript.jscomp.NodeTraversal.reportCodeChange方法的典型用法代码示例。如果您正苦于以下问题:Java NodeTraversal.reportCodeChange方法的具体用法?Java NodeTraversal.reportCodeChange怎么用?Java NodeTraversal.reportCodeChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.NodeTraversal
的用法示例。
在下文中一共展示了NodeTraversal.reportCodeChange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: splitNameDeclarationsAndRemoveDestructuring
import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
/**
* Does two simplifications to const/let/var nodes.
* 1. Splits them so that each declaration is a separate statement.
* 2. Removes non-import destructuring statements, which we assume are not type declarations.
*/
static void splitNameDeclarationsAndRemoveDestructuring(Node n, NodeTraversal t) {
checkArgument(NodeUtil.isNameDeclaration(n));
while (n.hasChildren()) {
Node lhsToSplit = n.getLastChild();
if (lhsToSplit.isDestructuringLhs() && !isImportRhs(lhsToSplit.getLastChild())) {
// Remove destructuring statements, which we assume are not type declarations
NodeUtil.markFunctionsDeleted(lhsToSplit, t.getCompiler());
NodeUtil.removeChild(n, lhsToSplit);
t.reportCodeChange();
continue;
}
if (n.hasOneChild()) {
return;
}
// A name declaration with more than one LHS is split into separate declarations.
Node rhs = lhsToSplit.hasChildren() ? lhsToSplit.removeFirstChild() : null;
Node newDeclaration =
NodeUtil.newDeclaration(lhsToSplit.detach(), rhs, n.getToken()).srcref(n);
n.getParent().addChildAfter(newDeclaration, n);
t.reportCodeChange();
}
}
示例2: propagateJsdocAtName
import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void propagateJsdocAtName(NodeTraversal t, Node nameNode) {
checkArgument(
nameNode.isQualifiedName() || nameNode.isStringKey() || nameNode.isDestructuringLhs(),
nameNode);
Node jsdocNode = NodeUtil.getBestJSDocInfoNode(nameNode);
JSDocInfo originalJsdoc = jsdocNode.getJSDocInfo();
if (!isConstToBeInferred(originalJsdoc, nameNode)) {
return;
}
Node rhs = NodeUtil.getRValueOfLValue(nameNode);
if (rhs == null) {
return;
}
JSDocInfo newJsdoc = JsdocUtil.getJSDocForRhs(rhs, originalJsdoc);
if (newJsdoc == null && ClassUtil.isThisProp(nameNode)) {
Var decl = findNameDeclaration(t.getScope(), rhs);
newJsdoc = JsdocUtil.getJSDocForName(decl, originalJsdoc);
}
if (newJsdoc != null) {
jsdocNode.setJSDocInfo(newJsdoc);
t.reportCodeChange();
}
}
示例3: visit
import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, final Node n, final Node parent) {
if (NodeUtil.isNameDeclaration(n)) {
RequireDetector detector = new RequireDetector();
traverseEs6(t.getCompiler(), n, detector);
if (detector.foundRequire) {
Node addAfter = n;
for (Node last = n.getLastChild();
last != null && last != n.getFirstChild();
last = n.getLastChild()) {
n.removeChild(last);
Node newDecl = declaration(last, n.getToken()).srcrefTree(last);
parent.addChildAfter(newDecl, addAfter);
addAfter = newDecl;
t.reportCodeChange();
}
}
}
}
示例4: visit
import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getToken()) {
case TRY:
case LABEL:
case DEFAULT_CASE:
case CASE:
case DO:
case WHILE:
case FOR:
case FOR_IN:
case FOR_OF:
case IF:
case SWITCH:
if (n.getParent() != null) {
Node children = n.removeChildren();
parent.addChildrenAfter(children, n);
NodeUtil.removeChild(parent, n);
t.reportCodeChange();
}
break;
case VAR:
case LET:
case CONST:
splitNameDeclarationsAndRemoveDestructuring(n, t);
break;
case BLOCK:
if (!parent.isFunction()) {
parent.addChildrenAfter(n.removeChildren(), n);
n.detach();
t.reportCodeChange(parent);
}
break;
default:
break;
}
}
示例5: visitScript
import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void visitScript(NodeTraversal t, Node script) {
if (currentModule == null) {
return;
}
// Remove any 'use strict' directives. The compiler adds these by default to
// closure modules and will generate a warning if specified directly.
// TODO: remove when https://github.com/google/closure-compiler/issues/1263 is fixed.
Set<String> directives = script.getDirectives();
if (directives != null && directives.contains("use strict")) {
// Directives is likely an immutable collection, so we need to make a copy.
Set<String> newDirectives = new HashSet<>();
newDirectives.addAll(directives);
newDirectives.remove("use strict");
script.setDirectives(newDirectives);
}
processModuleExportRefs(t);
Node moduleBody = createModuleBody();
moduleBody.srcrefTree(script);
if (script.getChildCount() > 0) {
moduleBody.addChildrenToBack(script.removeChildren());
}
script.addChildToBack(moduleBody);
script.putBooleanProp(Node.GOOG_MODULE, true);
t.getInput().addProvide(currentModule);
traverseEs6(t.getCompiler(), script, new TypeCleanup());
googRequireExpr.clear();
currentModule = null;
t.reportCodeChange();
}
示例6: visitRequireCall
import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void visitRequireCall(NodeTraversal t, Node require, Node parent) {
Path currentFile = inputFs.getPath(t.getSourceName());
String modulePath = require.getSecondChild().getString();
if (modulePath.isEmpty()) {
t.report(require, REQUIRE_INVALID_MODULE_ID);
return;
}
String moduleId = null;
if (modulePath.startsWith(".") || modulePath.startsWith("/")) {
Path moduleFile = currentFile.getParent().resolve(modulePath).normalize();
if (modulePath.endsWith("/")
|| isDirectory(moduleFile)
&& !modulePath.endsWith(".js")
&& !Files.exists(moduleFile.resolveSibling(moduleFile.getFileName() + ".js"))) {
moduleFile = moduleFile.resolve("index.js");
}
moduleId = NODE.newId(moduleFile).getOriginalName();
} else if (nodeLibrary.canRequireId(modulePath)) {
moduleId = nodeLibrary.normalizeRequireId(modulePath);
}
if (moduleId != null) {
// Only register the require statement on this module if it occurs at the global
// scope. Assume other require statements are not declared at the global scope to
// avoid create a circular dependency. While node can handle these, by returning
// a partial definition of the required module, the cycle would be an error for
// the compiler. For more information on how Node handles cycles, see:
// http://www.nodejs.org/api/modules.html#modules_cycles
if (t.getScope().isGlobal()) {
Node googRequire = call(getprop(name("goog"), string("require")), string(moduleId));
// ClosureCheckModule enforces that goog.require statements are at the top level. To
// compensate, if we have a require statement that is not at the top level, we introduce
// a hidden variable at the top level that does the actual require. The compiler should
// always inline the require making this effectively a no-op.
//
// Example:
// var Foo = require('./foo').Foo;
//
// Becomes:
// var _some_hidden_name = require('./foo');
// var Foo = _some_hidden_name.Foo;
if (!parent.isName()) {
String hiddenName = Types.toInternalVar(moduleId);
JSDocInfoBuilder infoBuilder = new JSDocInfoBuilder(false);
infoBuilder.recordConstancy();
googRequireExpr.put(
hiddenName, var(name(hiddenName).setJSDocInfo(infoBuilder.build()), googRequire));
googRequire = name(hiddenName);
}
parent.replaceChild(require, googRequire.srcrefTree(require));
t.getInput().addRequire(moduleId);
} else {
// For goog.module('foo'), ClosureRewriteModule produces module$exports$foo = {};, so
// we use the transformed name in the direct reference.
parent.replaceChild(require, name("module$exports$" + moduleId).srcrefTree(require));
}
t.reportCodeChange();
}
// Else we have an unrecognized module ID. Do nothing, leaving it to the
// type-checking gods.
}