return externs;
}
private CompilerOptions getClosureCompilerOptions(JsOutputOption jsOutputOption)
throws ParseException {
CompilerOptions options = new CompilerOptions();
WarningLevel.QUIET.setOptionsForWarningLevel(options);
// Basically, use CompilationLevel.ADVANCED_OPTIMIZATIONS:
// Build an identity map of variable names to prevent GWT names from
// being renamed while allowing new global variables to be renamed.
HashMap<String, String> varNames = new HashMap<String, String>();
for (String var : globalVars) {
varNames.put(var, var);
}
options.setInputVariableMapSerialized(VariableMap.fromMap(varNames).toBytes());
if (jsOutputOption == JsOutputOption.OBFUSCATED) {
options.setRenamingPolicy(VariableRenamingPolicy.ALL, PropertyRenamingPolicy.OFF);
options.prettyPrint = false;
// This can help debug renaming policy changes.
// options.generatePseudoNames = true;
} else {
options.setRenamingPolicy(VariableRenamingPolicy.OFF, PropertyRenamingPolicy.OFF);
options.prettyPrint = true;
}
// All the safe optimizations.
options.closurePass = true;
options.foldConstants = true;
options.coalesceVariableNames = true;
options.deadAssignmentElimination = true;
options.setExtractPrototypeMemberDeclarations(true);
options.collapseVariableDeclarations = true;
options.convertToDottedProperties = true;
options.rewriteFunctionExpressions = true;
options.labelRenaming = true;
options.removeDeadCode = true;
options.optimizeArgumentsArray = true;
options.setCollapseObjectLiterals(true);
options.setShadowVariables(true);
// All the advance optimizations.
options.reserveRawExports = true;
options.removeUnusedPrototypeProperties = true;
options.collapseAnonymousFunctions = true;
options.smartNameRemoval = true; // ?
options.inlineConstantVars = true;
options.setInlineFunctions(Reach.ALL);
options.inlineGetters = true;
options.setInlineVariables(Reach.ALL);
options.flowSensitiveInlineVariables = true;
options.computeFunctionSideEffects = true;
// Remove unused vars also removes unused functions.
options.setRemoveUnusedVariable(Reach.ALL);
options.optimizeParameters = true;
options.optimizeReturns = true;
options.optimizeCalls = true;
// Maybe turn these off as well
options.collapseProperties = true; // ?
options.crossModuleCodeMotion = true; // ?
options.crossModuleMethodMotion = true; // ?
options.devirtualizePrototypeMethods = true; // ?
// Advanced optimization, disabled
options.setRemoveClosureAsserts(false);
options.aliasKeywords = false;
options.removeUnusedPrototypePropertiesInExterns = false;
options.checkGlobalThisLevel = CheckLevel.OFF;
options.rewriteFunctionExpressions = false; // Performance hit
// Kindly tell the user that they have JsDocs that we don't understand.
options.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC, CheckLevel.OFF);
return options;
}