本文整理汇总了Java中com.google.javascript.jscomp.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于com.google.javascript.jscomp包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void execute() {
if (this.outputFile == null) {
throw new BuildException("outputFile attribute must be set");
}
Compiler.setLoggingLevel(Level.OFF);
CompilerOptions options = createCompilerOptions();
Compiler compiler = createCompiler(options);
JSSourceFile[] externs = findExternFiles();
JSSourceFile[] sources = findSourceFiles();
log("Compiling " + sources.length + " file(s) with " +
externs.length + " extern(s)");
Result result = compiler.compile(externs, sources, options);
if (result.success) {
writeResult(compiler.toSource());
}
}
示例2: testRequiresAreCaughtBeforeProcessed
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void testRequiresAreCaughtBeforeProcessed() {
String js = "var foo = {}; var bar = new foo.bar.goo();";
JSSourceFile input = JSSourceFile.fromCode("foo.js", js);
Compiler compiler = new Compiler();
CompilerOptions opts = new CompilerOptions();
opts.checkRequires = CheckLevel.WARNING;
opts.closurePass = true;
Result result = compiler.compile(new JSSourceFile[] {},
new JSSourceFile[] {input}, opts);
JSError[] warnings = result.warnings;
assertNotNull(warnings);
assertTrue(warnings.length > 0);
String expectation = "'foo.bar.goo' used but not goog.require'd";
for (JSError warning : warnings) {
if (expectation.equals(warning.description)) {
return;
}
}
fail("Could not find the following warning:" + expectation);
}
示例3: minify
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public byte[] minify(byte[] jsFileContent, String path) {
List<SourceFile> externs = Collections.emptyList();
List<SourceFile> inputs = Arrays.asList(SourceFile.fromCode(path, new String(jsFileContent, StandardCharsets.UTF_8)));
CompilerOptions options = new CompilerOptions();
options.setAngularPass(true);
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
Result result = compiler.compile(externs, inputs, options);
if (result.success) {
return compiler.toSource().getBytes(StandardCharsets.UTF_8);
}
JSError[] errors = result.errors;
StringBuilder errorText = new StringBuilder();
for (JSError error: errors){
errorText.append(error.toString());
}
throw new IllegalArgumentException("Unable to minify, input source\n"+ errorText);
}
示例4: execute
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void execute() {
if (this.outputFile == null) {
throw new BuildException("outputFile attribute must be set");
}
Compiler.setLoggingLevel(Level.OFF);
CompilerOptions options = createCompilerOptions();
Compiler compiler = createCompiler(options);
JSSourceFile[] externs = findExternFiles();
JSSourceFile[] sources = findSourceFiles();
log("Compiling " + sources.length + " file(s) with " +
externs.length + " extern(s)");
Result result = compiler.compile(externs, sources, options);
if (result.success) {
writeResult(compiler.toSource());
} else {
throw new BuildException("Compilation failed.");
}
}
示例5: invoke
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
CompiledScript invoke() throws Exception {
Compiler compiler = new Compiler();
compiler.setLoggingLevel( Level.OFF );
SourceFile input = SourceFile.fromFile( srcFile );
input.setOriginalPath( relSrcFilePath );
Result res = compiler.compile( EMPTY_EXTERNS_SOURCE_FILE, input, options );
if ( res.success ) {
String name = srcFile.getName();
code = new StringBuilder( compiler.toSource() );
code.append( "\n//# sourceMappingURL=" ).append( name ).append( ".map" );
sourcemap = new StringBuilder();
SourceMap sm = compiler.getSourceMap();
sm.appendTo( sourcemap, name );
return this;
}
throw new Exception( "Failed script compilation" );
}
示例6: compile
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void compile(JsonML source) {
if (report != null) {
throw new IllegalStateException(COMPILATION_ALREADY_COMPLETED_MSG);
}
sourceAst = new JsonMLAst(source);
CompilerInput input = new CompilerInput(
sourceAst, "[[jsonmlsource]]", false);
JSModule module = new JSModule("[[jsonmlmodule]]");
module.add(input);
Result result = compiler.compileModules(
ImmutableList.<SourceFile>of(),
ImmutableList.of(module),
options);
report = generateReport(result);
}
示例7: generateReport
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
Report generateReport(Result result) {
// a report may be generated only after actual compilation is complete
if (result == null) {
return null;
}
ArrayList<JsonMLError> errors = Lists.newArrayList();
for (JSError error : result.errors) {
errors.add(JsonMLError.make(error, sourceAst));
}
ArrayList<JsonMLError> warnings = Lists.newArrayList();
for (JSError warning : result.warnings) {
warnings.add(JsonMLError.make(warning, sourceAst));
}
return new Report(
errors.toArray(new JsonMLError[0]),
warnings.toArray(new JsonMLError[0]));
}
示例8: testRequiresAreCaughtBeforeProcessed
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public void testRequiresAreCaughtBeforeProcessed() {
String js = "var foo = {}; var bar = new foo.bar.goo();";
SourceFile input = SourceFile.fromCode("foo.js", js);
Compiler compiler = new Compiler();
CompilerOptions opts = new CompilerOptions();
opts.checkRequires = CheckLevel.WARNING;
opts.closurePass = true;
Result result = compiler.compile(ImmutableList.<SourceFile>of(),
ImmutableList.of(input), opts);
JSError[] warnings = result.warnings;
assertNotNull(warnings);
assertTrue(warnings.length > 0);
String expectation = "'foo.bar.goo' used but not goog.require'd";
for (JSError warning : warnings) {
if (expectation.equals(warning.description)) {
return;
}
}
fail("Could not find the following warning:" + expectation);
}
示例9: compile
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public CompileResult compile(Path path, String code) {
Compiler compiler = compiler();
Result result =
compiler.compile(EXTERNS, SourceFile.fromCode(path.toString(), code), options());
String source = compiler.toSource();
StringBuilder sourceMap = new StringBuilder();
if (result.sourceMap != null) {
try {
result.sourceMap.appendTo(sourceMap, path.toString());
} catch (IOException e) {
// impossible, and not a big deal even if it did happen.
}
}
boolean transpiled = !result.transpiledFiles.isEmpty();
if (result.errors.length > 0) {
throw new TranspilationException(compiler, result.errors, result.warnings);
}
return new CompileResult(
source,
transpiled,
transpiled ? sourceMap.toString() : "");
}
示例10: compile
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public CompileResult compile(Path path, String code) {
Compiler compiler = compiler();
Result result =
compiler.compile(EXTERNS, SourceFile.fromCode(path.toString(), code), options());
String source = compiler.toSource();
StringBuilder sourceMap = new StringBuilder();
if (result.sourceMap != null) {
try {
result.sourceMap.appendTo(sourceMap, path.toString());
} catch (IOException e) {
// impossible, and not a big deal even if it did happen.
}
}
boolean transformed = transformed(result);
return new CompileResult(
source, result.errors, transformed, transformed ? sourceMap.toString() : "");
}
示例11: writeSourceMap
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
private void writeSourceMap(Result result, String sourceMap, String output) {
File file = new File(sourceMap);
try {
StringBuffer buffer = new StringBuffer();
result.sourceMap.appendTo(buffer, output);
Files.createParentDirs(file);
Files.write(buffer.toString().getBytes(), file);
} catch (IOException e) {
getErrorManager()
.reportMessage(
new Status(
StatusType.ERROR,
MessageFormat.format(
resourceBundle
.getString(IConstants.JSConsole_SourceMapFailed),
sourceMap), null));
}
}
示例12: writeSourceMap
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
private void writeSourceMap(Result result, String sourceMap, String output) {
File file = new File(sourceMap);
try {
StringBuffer buffer = new StringBuffer();
result.sourceMap.appendTo(buffer, output);
Files.createParentDirs(file);
Files.write(buffer.toString().getBytes(), file);
} catch (IOException e) {
getErrorManager()
.getConsoleManager()
.reportMessage(
new Status(
StatusType.ERROR,
MessageFormat.format(
resourceBundle
.getString(IConstants.JSConsole_SourceMapFailed),
sourceMap), null));
}
}
示例13: compile
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
/**
* Copied verbatim from com.google.javascript.jscomp.Compiler, except using getter methods instead
* of private fields and running cloneParsedInputs() at the appropriate time.
*/
@Override
public <T1 extends SourceFile, T2 extends SourceFile> Result compile(
List<T1> externs, List<T2> inputs, CompilerOptions options) {
// The compile method should only be called once.
checkState(getRoot() == null);
try {
init(externs, inputs, options);
if (!hasErrors()) {
parseForCompilation();
cloneParsedInputs();
}
if (!hasErrors()) {
if (options.getInstrumentForCoverageOnly()) {
// TODO(bradfordcsmith): The option to instrument for coverage only should belong to the
// runner, not the compiler.
instrumentForCoverage();
} else {
stage1Passes();
if (!hasErrors()) {
stage2Passes();
}
}
performPostCompilationTasks();
}
} finally {
generateReport();
}
return getResult();
}
示例14: main
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Compiler compiler = new Compiler(System.err);
compiler.disableThreads(); // Makes errors easier to track down.
List<SourceFile> inputs = ImmutableList.of(
SourceFile.fromInputStream("stdin", System.in, StandardCharsets.UTF_8)
);
CompilerOptions options = new CompilerOptions();
Result result = compiler.compile(
Collections.<SourceFile>emptyList(), inputs, options);
dump(compiler.getRoot(), 0, System.out);
System.out.append("\n");
}
示例15: createTypesNode
import com.google.javascript.jscomp.Result; //导入依赖的package包/类
private Node createTypesNode() {
if (templateTypesNode == null) {
String typesJs = React.getTypesJs();
Result previousResult = compiler.getResult();
templateTypesNode =
compiler.parse(SourceFile.fromCode(React.TYPES_JS_RESOURCE_PATH, typesJs));
Result result = compiler.getResult();
if ((result.success != previousResult.success && previousResult.success) ||
result.errors.length > previousResult.errors.length ||
result.warnings.length > previousResult.warnings.length) {
String message = "Could not parse " + React.TYPES_JS_RESOURCE_PATH + ".";
if (result.errors.length > 0) {
message += "\nErrors: " + Joiner.on(",").join(result.errors);
}
if (result.warnings.length > 0) {
message += "\nWarnings: " + Joiner.on(",").join(result.warnings);
}
throw new RuntimeException(message);
}
// Gather ReactComponent prototype methods.
NodeTraversal.traverseEs6(
compiler,
templateTypesNode,
new NodeTraversal.AbstractPostOrderCallback() {
@Override public void visit(NodeTraversal t, Node n, Node parent) {
if (!n.isAssign() || !n.getFirstChild().isQualifiedName() ||
!n.getFirstChild().getQualifiedName().startsWith(
"ReactComponent.prototype.") ||
!n.getLastChild().isFunction()) {
return;
}
componentMethodJsDocs.put(
n.getFirstChild().getLastChild().getString(),
n.getJSDocInfo());
}
});
}
return templateTypesNode.cloneTree();
}