| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
import com.google.javascript.jscomp.CompilerOptions.Reach; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public enum CompilationLevel { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
WHITESPACE_ONLY, |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
SIMPLE_OPTIMIZATIONS, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
ADVANCED_OPTIMIZATIONS, |
| 49 |
; |
| 50 |
|
| 51 |
private CompilationLevel() {} |
| 52 |
|
| 53 |
public void setOptionsForCompilationLevel(CompilerOptions options) { |
| 54 |
switch (this) { |
| 55 |
case WHITESPACE_ONLY: |
| 56 |
applyBasicCompilationOptions(options); |
| 57 |
break; |
| 58 |
case SIMPLE_OPTIMIZATIONS: |
| 59 |
applySafeCompilationOptions(options); |
| 60 |
break; |
| 61 |
case ADVANCED_OPTIMIZATIONS: |
| 62 |
applyFullCompilationOptions(options); |
| 63 |
break; |
| 64 |
default: |
| 65 |
throw new RuntimeException("Unknown compilation level."); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public void setDebugOptionsForCompilationLevel(CompilerOptions options) { |
| 70 |
options.anonymousFunctionNaming = AnonymousFunctionNamingPolicy.UNMAPPED; |
| 71 |
options.generatePseudoNames = true; |
| 72 |
options.removeClosureAsserts = false; |
| 73 |
|
| 74 |
options.shadowVariables = false; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
private static void applyBasicCompilationOptions(CompilerOptions options) { |
| 82 |
options.skipAllCompilerPasses(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
private static void applySafeCompilationOptions(CompilerOptions options) { |
| 92 |
|
| 93 |
options.replaceIdGenerators = false; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
options.dependencyOptions.setDependencySorting(true); |
| 98 |
options.closurePass = true; |
| 99 |
options.setRenamingPolicy( |
| 100 |
VariableRenamingPolicy.LOCAL, PropertyRenamingPolicy.OFF); |
| 101 |
options.shadowVariables = true; |
| 102 |
options.setInlineVariables(Reach.LOCAL_ONLY); |
| 103 |
options.flowSensitiveInlineVariables = true; |
| 104 |
options.setInlineFunctions(Reach.LOCAL_ONLY); |
| 105 |
options.setAssumeClosuresOnlyCaptureReferences(false); |
| 106 |
options.checkGlobalThisLevel = CheckLevel.OFF; |
| 107 |
options.foldConstants = true; |
| 108 |
options.coalesceVariableNames = true; |
| 109 |
options.deadAssignmentElimination = true; |
| 110 |
options.collapseVariableDeclarations = true; |
| 111 |
options.convertToDottedProperties = true; |
| 112 |
options.labelRenaming = true; |
| 113 |
options.removeDeadCode = true; |
| 114 |
options.optimizeArgumentsArray = true; |
| 115 |
options.setRemoveUnusedVariables(Reach.LOCAL_ONLY); |
| 116 |
options.collapseObjectLiterals = true; |
| 117 |
options.protectHiddenSideEffects = true; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
private static void applyFullCompilationOptions(CompilerOptions options) { |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
options.dependencyOptions.setDependencySorting(true); |
| 131 |
options.closurePass = true; |
| 132 |
options.foldConstants = true; |
| 133 |
options.coalesceVariableNames = true; |
| 134 |
options.deadAssignmentElimination = true; |
| 135 |
options.extractPrototypeMemberDeclarations = true; |
| 136 |
options.collapseVariableDeclarations = true; |
| 137 |
options.convertToDottedProperties = true; |
| 138 |
options.rewriteFunctionExpressions = true; |
| 139 |
options.labelRenaming = true; |
| 140 |
options.removeDeadCode = true; |
| 141 |
options.optimizeArgumentsArray = true; |
| 142 |
options.collapseObjectLiterals = true; |
| 143 |
options.protectHiddenSideEffects = true; |
| 144 |
|
| 145 |
|
| 146 |
options.removeClosureAsserts = true; |
| 147 |
options.aliasKeywords = true; |
| 148 |
options.reserveRawExports = true; |
| 149 |
options.setRenamingPolicy( |
| 150 |
VariableRenamingPolicy.ALL, PropertyRenamingPolicy.ALL_UNQUOTED); |
| 151 |
options.shadowVariables = true; |
| 152 |
options.removeUnusedPrototypeProperties = true; |
| 153 |
options.removeUnusedPrototypePropertiesInExterns = true; |
| 154 |
options.collapseAnonymousFunctions = true; |
| 155 |
options.collapseProperties = true; |
| 156 |
options.checkGlobalThisLevel = CheckLevel.WARNING; |
| 157 |
options.rewriteFunctionExpressions = true; |
| 158 |
options.smartNameRemoval = true; |
| 159 |
options.inlineConstantVars = true; |
| 160 |
options.setInlineFunctions(Reach.ALL); |
| 161 |
options.setAssumeClosuresOnlyCaptureReferences(false); |
| 162 |
options.inlineGetters = true; |
| 163 |
options.setInlineVariables(Reach.ALL); |
| 164 |
options.flowSensitiveInlineVariables = true; |
| 165 |
options.computeFunctionSideEffects = true; |
| 166 |
|
| 167 |
|
| 168 |
options.setRemoveUnusedVariables(Reach.ALL); |
| 169 |
|
| 170 |
|
| 171 |
options.crossModuleCodeMotion = true; |
| 172 |
options.crossModuleMethodMotion = true; |
| 173 |
|
| 174 |
|
| 175 |
options.devirtualizePrototypeMethods = true; |
| 176 |
options.optimizeParameters = true; |
| 177 |
options.optimizeReturns = true; |
| 178 |
options.optimizeCalls = true; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public void setTypeBasedOptimizationOptions(CompilerOptions options) { |
| 186 |
switch (this) { |
| 187 |
case ADVANCED_OPTIMIZATIONS: |
| 188 |
options.inferTypes = true; |
| 189 |
options.disambiguateProperties = true; |
| 190 |
options.ambiguateProperties = true; |
| 191 |
options.inlineProperties = true; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
options.removeUnusedClassProperties = true; |
| 196 |
break; |
| 197 |
case SIMPLE_OPTIMIZATIONS: |
| 198 |
|
| 199 |
break; |
| 200 |
case WHITESPACE_ONLY: |
| 201 |
break; |
| 202 |
} |
| 203 |
} |
| 204 |
} |