* error occurs during compression.
*/
public String compress(String jsCode) {
String result = jsCode;
try {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
// use the simple compilation level
CompilationLevel.SIMPLE_OPTIMIZATIONS
.setOptionsForCompilationLevel(options);
// add the default externals
List externsList = getDefaultExterns();
JSSourceFile[] externs = new JSSourceFile[externsList.size()];
externsList.toArray(externs);
// The dummy input name "input.js" is used here so that any warnings
// or errors will cite line numbers in terms of input.js.
JSSourceFile[] inputs = new JSSourceFile[1];
inputs[0] = JSSourceFile.fromCode("input", jsCode);
// compile() returns a Result, but it is not needed here.
compiler.compile(externs, inputs, options);
// The compiler is responsible for generating the compiled code; it
// is not accessible via the Result.
result = compiler.toSource();
} catch (Exception e) {
log.error("Not able to compress the given JavaScript", e);
}
return result;
}