Package com.google.gwt.thirdparty.javascript.jscomp

Examples of com.google.gwt.thirdparty.javascript.jscomp.CompilerOptions


  public ClosureJsRunner() {
  }

  public void compile(JProgram jprogram, JsProgram program, String[] js,
      JsOutputOption jsOutputOption) {
    CompilerOptions options;
    try {
      options = getClosureCompilerOptions(jsOutputOption);
    } catch (ParseException e) {
      throw new RuntimeException("Error setting closure compiler options", e);
    }
View Full Code Here


    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;
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.thirdparty.javascript.jscomp.CompilerOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.