本文整理汇总了Java中com.google.javascript.jscomp.Compiler.getRoot方法的典型用法代码示例。如果您正苦于以下问题:Java Compiler.getRoot方法的具体用法?Java Compiler.getRoot怎么用?Java Compiler.getRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.Compiler
的用法示例。
在下文中一共展示了Compiler.getRoot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
protected void generate() {
jettisonNodes();
Compiler c = getCompiler();
Node rootNode = c.getRoot();
if (JAMOpts.noExterns) {
externs = JSExp.createEmpty(this);
root = JSExp.create(this, rootNode);
} else {
// The compiler's root consists of the externs first and the user
// scripts second. We want the user scripts only.
externs = JSExp.create(this, rootNode.getFirstChild());
root = JSExp.create(this, rootNode.getChildAtIndex(1));
}
}
示例2: compileToScriptRoot
import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/** Returns the root script node produced from the compiled JS input. */
private static Node compileToScriptRoot(Compiler compiler) {
Node root = compiler.getRoot();
// The last child of the compiler root is a Block node, and the first child
// of that is the Script node.
return root.getLastChild().getFirstChild();
}
示例3: uneval
import com.google.javascript.jscomp.Compiler; //导入方法依赖的package包/类
/**
* Morally this is function has the type:
* AnalyzerCallback -> EvalString -> Bool -> Maybe ResultVar -> Maybe String
*/
public String uneval(AnalyzerCallback callback, String source, boolean aliasedEval, String resVar) {
logger.debug("Starting on: " + source);
// TODO: Immediately fail on aliased calls. Not hard to handle, but no real use cases yet.
if (aliasedEval)
return null;
Compiler comp = parseString(source);
Node root = comp.getRoot();
// Input was not syntactically valid (s \notin P)
if (comp.getErrorCount() > 0)
throw new IllegalArgumentException("Invalid abstract expression: " + source);
// log(comp.toSource());
String code = getConst(root);
if (code != null) {
// Strip the outermost quotes on our (string) input.
if (code.startsWith("\"") && code.endsWith("\""))
code = code.substring(1, code.length() - 1);
// Someone might actually call eval(""), but that is fine. Calling x = eval("") is too, return undefined.
if (code.isEmpty())
return resVar == null ? "" : resVar + " = undefined";
comp = parseString(code);
// TODO: Check for shadowing.
// We got a constant string that wasn't valid javascript. Weird, but legal, so return a syntax error.
if (comp.getErrorCount() > 0)
return "throw new SyntaxError()";
logger.debug("Valid program");
// Basic sanity checking complete; jump to the interesting work for the constant string case.
return unevalConst(callback, comp, resVar);
}
logger.debug("Not a constant string");
// So e = ".." + x1 + ".." + x2 + ..
// A map of all the x_n's in the input (the caller guarantees they are fresh). Used for reconstructing the
// AST once we have constant folded them away.
Set<String> holeNames = newSet();
// Treat the input as e = ".." + "x1" + ".." + "x2" + .. and constant fold.
fillHolesAndConstantFold(comp, root, holeNames);
code = getConst(root);
if (code != null) {
// We got a string after constant folding. Drop the quotes and parse it.
if (code.startsWith("\"") && code.endsWith("\""))
code = code.substring(1, code.length() - 1);
comp = parseString(code);
if (comp.getErrorCount() > 0)
throw new IllegalArgumentException("Invalid abstract expression");
// Uneval the input by undoing the constant folding in a clever way.
return contractEval(callback, comp, holeNames, resVar);
}
logger.debug("Failed to refactor, returning null");
return null;
}