-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
CompilerOptions.java
3064 lines (2546 loc) · 94 KB
/
CompilerOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2009 The Closure Compiler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.javascript.jscomp;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.javascript.jscomp.parsing.Config;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.SourcePosition;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Compiler options
* @author nicksantos@google.com (Nick Santos)
*/
public class CompilerOptions {
// The number of characters after which we insert a line break in the code
static final int DEFAULT_LINE_LENGTH_THRESHOLD = 500;
/**
* A common enum for compiler passes that can run either globally or locally.
*/
public enum Reach {
ALL,
LOCAL_ONLY,
NONE
}
// TODO(nicksantos): All public properties of this class should be made
// package-private, and have a public setter.
/**
* The JavaScript language version accepted.
*/
private LanguageMode languageIn;
/**
* The JavaScript language version that should be produced.
*/
private LanguageMode languageOut;
/**
* The builtin set of externs to be used
*/
private Environment environment;
/**
* If true, don't transpile ES6 to ES3.
* WARNING: Enabling this option will likely cause the compiler to crash
* or produce incorrect output.
*/
boolean skipTranspilationAndCrash = false;
/**
* Allow disabling ES6 to ES3 transpilation.
*/
public void setSkipTranspilationAndCrash(boolean value) {
skipTranspilationAndCrash = value;
}
/**
* Whether to infer consts. This should not be configurable by
* external clients. This is a transitional flag for a new type
* of const analysis.
*
* TODO(nicksantos): Remove this option.
*/
boolean inferConsts = true;
// TODO(tbreisacher): Remove this method after ctemplate issues are solved.
public void setInferConst(boolean value) {
inferConsts = value;
}
/**
* Whether the compiler should assume that a function's "this" value
* never needs coercion (for example in non-strict "null" or "undefined" will
* be coerced to the global "this" and primitives to objects).
*/
private boolean assumeStrictThis;
private boolean allowHotswapReplaceScript = false;
private boolean preserveDetailedSourceInfo = false;
private boolean continueAfterErrors = false;
/**
* Whether the compiler should generate an output file that represents the type-only interface
* of the code being compiled. This is useful for incremental type checking.
*/
private boolean generateTypedExterns;
public void setIncrementalTypeChecking(boolean value) {
generateTypedExterns = value;
if (value) {
setPreserveTypeAnnotations(value);
setOutputJs(OutputJs.NORMAL);
}
}
public boolean shouldGenerateTypedExterns() {
return generateTypedExterns;
}
private Config.JsDocParsing parseJsDocDocumentation = Config.JsDocParsing.TYPES_ONLY;
/**
* Even if checkTypes is disabled, clients such as IDEs might want to still infer types.
*/
boolean inferTypes;
private boolean useNewTypeInference;
private boolean runOTIAfterNTI = true;
/**
* Relevant only when {@link #useNewTypeInference} and {@link #runOTIAfterNTI} are both true,
* where we normally disable OTI errors.
* If you want both NTI and OTI errors in this case, set to true.
* E.g. if using using a warnings guard to filter NTI or OTI warnings in new or legacy code,
* respectively.
* This will be removed when NTI entirely replaces OTI.
*/
boolean reportOTIErrorsUnderNTI = false;
/**
* Configures the compiler to skip as many passes as possible.
* If transpilation is requested, it will be run, but all others passes will be skipped.
*/
boolean skipNonTranspilationPasses;
/**
* Configures the compiler to run expensive sanity checks after
* every pass. Only intended for internal development.
*/
DevMode devMode;
/**
* Configures the compiler to log a hash code of the AST after
* every pass. Only intended for internal development.
*/
private boolean checkDeterminism;
//--------------------------------
// Input Options
//--------------------------------
DependencyOptions dependencyOptions = new DependencyOptions();
/** Returns localized replacement for MSG_* variables */
public MessageBundle messageBundle = null;
//--------------------------------
// Checks
//--------------------------------
/** Checks that all symbols are defined */
// TODO(tbreisacher): Remove this and deprecate the corresponding setter.
public boolean checkSymbols;
/** Checks for suspicious statements that have no effect */
public boolean checkSuspiciousCode;
/** Checks types on expressions */
public boolean checkTypes;
public CheckLevel reportMissingOverride;
/**
* Flags a warning if a property is missing the @override annotation, but it
* overrides a base class property.
*/
public void setReportMissingOverride(CheckLevel level) {
reportMissingOverride = level;
}
public CheckLevel checkGlobalNamesLevel;
/**
* Checks the integrity of references to qualified global names.
* (e.g. "a.b")
*/
public void setCheckGlobalNamesLevel(CheckLevel level) {
checkGlobalNamesLevel = level;
}
@Deprecated
public CheckLevel brokenClosureRequiresLevel;
/**
* Sets the check level for bad Closure require calls.
* Do not use; this should always be an error.
*/
@Deprecated
public void setBrokenClosureRequiresLevel(CheckLevel level) {
brokenClosureRequiresLevel = level;
}
public CheckLevel checkGlobalThisLevel;
/**
* Checks for certain uses of the {@code this} keyword that are considered
* unsafe because they are likely to reference the global {@code this}
* object unintentionally.
*
* If this is off, but collapseProperties is on, then the compiler will
* usually ignore you and run this check anyways.
*/
public void setCheckGlobalThisLevel(CheckLevel level) {
this.checkGlobalThisLevel = level;
}
public CheckLevel checkMissingGetCssNameLevel;
/**
* Checks that certain string literals only appear in strings used as
* goog.getCssName arguments.
*/
public void setCheckMissingGetCssNameLevel(CheckLevel level) {
this.checkMissingGetCssNameLevel = level;
}
/**
* Regex of string literals that may only appear in goog.getCssName arguments.
*/
public String checkMissingGetCssNameBlacklist;
/**
* A set of extra annotation names which are accepted and silently ignored
* when encountered in a source file. Defaults to null which has the same
* effect as specifying an empty set.
*/
Set<String> extraAnnotationNames;
/**
* Policies to determine the disposal checking level.
*/
public enum DisposalCheckingPolicy {
/**
* Don't check any disposal.
*/
OFF,
/**
* Default/conservative disposal checking.
*/
ON,
/**
* Aggressive disposal checking.
*/
AGGRESSIVE,
}
/**
* Check for patterns that are known to cause memory leaks.
*/
DisposalCheckingPolicy checkEventfulObjectDisposalPolicy;
public void setCheckEventfulObjectDisposalPolicy(DisposalCheckingPolicy policy) {
this.checkEventfulObjectDisposalPolicy = policy;
// The CheckEventfulObjectDisposal pass requires types so enable inferring types if
// this pass is enabled.
if (policy != DisposalCheckingPolicy.OFF) {
this.inferTypes = true;
}
}
public DisposalCheckingPolicy getCheckEventfulObjectDisposalPolicy() {
return checkEventfulObjectDisposalPolicy;
}
/**
* Used for projects that are not well maintained, but are still used.
* Does not allow promoting warnings to errors, and disables some potentially
* risky optimizations.
*/
boolean legacyCodeCompile = false;
public boolean getLegacyCodeCompile() {
return this.legacyCodeCompile;
}
public void setLegacyCodeCompile(boolean legacy) {
this.legacyCodeCompile = legacy;
}
//--------------------------------
// Optimizations
//--------------------------------
/** Prefer commas over semicolons when doing statement fusion */
boolean aggressiveFusion;
/** Folds constants (e.g. (2 + 3) to 5) */
public boolean foldConstants;
/** Remove assignments to values that can not be referenced */
public boolean deadAssignmentElimination;
/** Inlines constants (symbols that are all CAPS) */
public boolean inlineConstantVars;
/** Inlines global functions */
public boolean inlineFunctions;
/**
* For projects that want to avoid the creation of giant functions after
* inlining.
*/
int maxFunctionSizeAfterInlining;
static final int UNLIMITED_FUN_SIZE_AFTER_INLINING = -1;
/** Inlines functions defined in local scopes */
public boolean inlineLocalFunctions;
/** More aggressive function inlining */
boolean assumeClosuresOnlyCaptureReferences;
/** Inlines properties */
private boolean inlineProperties;
/** Move code to a deeper module */
public boolean crossModuleCodeMotion;
/**
* Don't generate stub functions when moving methods deeper.
*
* Note, switching on this option may break existing code that depends on
* enumerating prototype methods for mixin behavior, such as goog.mixin or
* goog.object.extend, since the prototype assignments will be removed from
* the parent module and moved to a later module.
**/
boolean crossModuleCodeMotionNoStubMethods;
/**
* Whether when module B depends on module A and module B declares a symbol,
* this symbol can be seen in A after B has been loaded. This is often true,
* but may not be true when loading code using nested eval.
*/
boolean parentModuleCanSeeSymbolsDeclaredInChildren;
/** Merge two variables together as one. */
public boolean coalesceVariableNames;
/** Move methods to a deeper module */
public boolean crossModuleMethodMotion;
/** Inlines trivial getters */
boolean inlineGetters;
/** Inlines variables */
public boolean inlineVariables;
/** Inlines variables */
boolean inlineLocalVariables;
// TODO(user): This is temporary. Once flow sensitive inlining is stable
// Remove this.
public boolean flowSensitiveInlineVariables;
/** Removes code associated with unused global names */
public boolean smartNameRemoval;
/** Removes code associated with unused global names */
boolean extraSmartNameRemoval;
/** Removes code that will never execute */
public boolean removeDeadCode;
public enum ExtractPrototypeMemberDeclarationsMode {
OFF,
USE_GLOBAL_TEMP,
USE_IIFE
}
/** Extracts common prototype member declarations */
ExtractPrototypeMemberDeclarationsMode extractPrototypeMemberDeclarations;
/** Removes unused member prototypes */
public boolean removeUnusedPrototypeProperties;
/** Tells AnalyzePrototypeProperties it can remove externed props. */
public boolean removeUnusedPrototypePropertiesInExterns;
/** Removes unused member properties */
public boolean removeUnusedClassProperties;
/** Removes unused constructor properties */
boolean removeUnusedConstructorProperties;
/** Removes unused variables */
public boolean removeUnusedVars;
/** Removes unused variables in local scope. */
public boolean removeUnusedLocalVars;
/** Collapses multiple variable declarations into one */
public boolean collapseVariableDeclarations;
/**
* Collapses anonymous function declarations into named function
* declarations
*/
public boolean collapseAnonymousFunctions;
/**
* If set to a non-empty set, those strings literals will be aliased to a
* single global instance per string, to avoid creating more objects than
* necessary.
*/
public Set<String> aliasableStrings;
/**
* A blacklist in the form of a regular expression to block strings that
* contains certain words from being aliased.
* If the value is the empty string, no words are blacklisted.
*/
public String aliasStringsBlacklist;
/**
* Aliases all string literals to global instances, to avoid creating more
* objects than necessary (if true, overrides any set of strings passed in
* to aliasableStrings)
*/
public boolean aliasAllStrings;
/** Print string usage as part of the compilation log. */
boolean outputJsStringUsage;
/** Converts quoted property accesses to dot syntax (a['b'] → a.b) */
public boolean convertToDottedProperties;
/** Reduces the size of common function expressions. */
public boolean rewriteFunctionExpressions;
/**
* Remove unused and constant parameters.
*/
public boolean optimizeParameters;
/**
* Remove unused return values.
*/
public boolean optimizeReturns;
/**
* Remove unused parameters from call sites.
*/
public boolean optimizeCalls;
/**
* Provide formal names for elements of arguments array.
*/
public boolean optimizeArgumentsArray;
/** Chains calls to functions that return this. */
boolean chainCalls;
/** Use type information to enable additional optimization opportunities. */
boolean useTypesForOptimization;
//--------------------------------
// Renaming
//--------------------------------
/** Controls which variables get renamed. */
public VariableRenamingPolicy variableRenaming;
/** Controls which properties get renamed. */
PropertyRenamingPolicy propertyRenaming;
/** Controls label renaming. */
public boolean labelRenaming;
/** Reserve property names on the global this object. */
public boolean reserveRawExports;
/** Should shadow variable names in outer scope. */
boolean shadowVariables;
/**
* Use a renaming heuristic with better stability across source
* changes. With this option each symbol is more likely to receive
* the same name between builds. The cost may be a slight increase
* in code size.
*/
boolean preferStableNames;
/**
* Generate pseudo names for variables and properties for debugging purposes.
*/
public boolean generatePseudoNames;
/** Specifies a prefix for all globals */
public String renamePrefix;
/**
* Specifies the name of an object that will be used to store all non-extern
* globals.
*/
public String renamePrefixNamespace;
/**
* Used by tests of the RescopeGlobalSymbols pass to avoid having declare 2
* modules in simple cases.
*/
boolean renamePrefixNamespaceAssumeCrossModuleNames = false;
void setRenamePrefixNamespaceAssumeCrossModuleNames(boolean assume) {
renamePrefixNamespaceAssumeCrossModuleNames = assume;
}
/** Flattens multi-level property names (e.g. a$b = x) */
public boolean collapseProperties;
/** Split object literals into individual variables when possible. */
boolean collapseObjectLiterals;
public void setCollapseObjectLiterals(boolean enabled) {
collapseObjectLiterals = enabled;
}
/**
* Devirtualize prototype method by rewriting them to be static calls that
* take the this pointer as their first argument
*/
public boolean devirtualizePrototypeMethods;
/**
* Use @nosideeffects annotations, function bodies and name graph
* to determine if calls have side effects. Requires --check_types.
*/
public boolean computeFunctionSideEffects;
/**
* Where to save debug report for compute function side effects.
*/
String debugFunctionSideEffectsPath;
/**
* Rename private properties to disambiguate between unrelated fields based on
* the coding convention.
*/
boolean disambiguatePrivateProperties;
/**
* Rename properties to disambiguate between unrelated fields based on
* type information.
*/
private boolean disambiguateProperties;
/** Rename unrelated properties to the same name to reduce code size. */
private boolean ambiguateProperties;
/** Input sourcemap files, indexed by the JS files they refer to */
ImmutableMap<String, SourceMapInput> inputSourceMaps;
/** Give anonymous functions names for easier debugging */
public AnonymousFunctionNamingPolicy anonymousFunctionNaming;
/** Input anonymous function renaming map. */
VariableMap inputAnonymousFunctionNamingMap;
/**
* Input variable renaming map.
* <p>During renaming, the compiler uses this map and the inputPropertyMap to
* try to preserve renaming mappings from a previous compilation.
* The application is delta encoding: keeping the diff between consecutive
* versions of one's code small.
* The compiler does NOT guarantee to respect these maps; projects should not
* use these maps to prevent renaming or to select particular names.
* Point questioners to this post:
* http://closuretools.blogspot.com/2011/01/property-by-any-other-name-part-3.html
*/
VariableMap inputVariableMap;
/** Input property renaming map. */
VariableMap inputPropertyMap;
/** Whether to export test functions. */
public boolean exportTestFunctions;
/** Whether to declare globals declared in externs as properties on window */
boolean declaredGlobalExternsOnWindow;
/** Shared name generator */
NameGenerator nameGenerator;
//--------------------------------
// Special-purpose alterations
//--------------------------------
/**
* Replace UI strings with chrome.i18n.getMessage calls.
* Used by Chrome extensions/apps.
*/
boolean replaceMessagesWithChromeI18n;
String tcProjectId;
public void setReplaceMessagesWithChromeI18n(
boolean replaceMessagesWithChromeI18n,
String tcProjectId) {
if (replaceMessagesWithChromeI18n
&& messageBundle != null
&& !(messageBundle instanceof EmptyMessageBundle)) {
throw new RuntimeException("When replacing messages with"
+ " chrome.i18n.getMessage, a message bundle should not be specified.");
}
this.replaceMessagesWithChromeI18n = replaceMessagesWithChromeI18n;
this.tcProjectId = tcProjectId;
}
/** Inserts run-time type assertions for debugging. */
boolean runtimeTypeCheck;
/**
* A JS function to be used for logging run-time type assertion
* failures. It will be passed the warning as a string and the
* faulty expression as arguments.
*/
String runtimeTypeCheckLogFunction;
/** A CodingConvention to use during the compile. */
private CodingConvention codingConvention;
public String syntheticBlockStartMarker;
public String syntheticBlockEndMarker;
/** Compiling locale */
public String locale;
/** Sets the special "COMPILED" value to true */
public boolean markAsCompiled;
/** Processes goog.provide() and goog.require() calls */
public boolean closurePass;
/** Do not strip goog.provide()/goog.require() calls from the code. */
private boolean preserveGoogProvidesAndRequires;
/** Processes jQuery aliases */
public boolean jqueryPass;
/** Processes AngularJS-specific annotations */
boolean angularPass;
/** Processes Polymer calls */
boolean polymerPass;
/** Processes the output of the Dart Dev Compiler */
boolean dartPass;
/** Processes the output of J2CL */
boolean j2clPass;
/** Remove goog.abstractMethod assignments. */
boolean removeAbstractMethods;
/** Remove goog.asserts calls. */
boolean removeClosureAsserts;
/** Gather CSS names (requires closurePass) */
public boolean gatherCssNames;
/** Names of types to strip */
public Set<String> stripTypes;
/** Name suffixes that determine which variables and properties to strip */
public Set<String> stripNameSuffixes;
/** Name prefixes that determine which variables and properties to strip */
public Set<String> stripNamePrefixes;
/** Qualified type name prefixes that determine which types to strip */
public Set<String> stripTypePrefixes;
/** Custom passes */
protected transient
Multimap<CustomPassExecutionTime, CompilerPass> customPasses;
/** Mark no side effect calls */
public boolean markNoSideEffectCalls;
/** Replacements for @defines. Will be Boolean, Numbers, or Strings */
private Map<String, Object> defineReplacements;
/** What kind of processing to do for goog.tweak functions. */
private TweakProcessing tweakProcessing;
/** Replacements for tweaks. Will be Boolean, Numbers, or Strings */
private Map<String, Object> tweakReplacements;
/** Move top-level function declarations to the top */
public boolean moveFunctionDeclarations;
/** Instrumentation template to use with #recordFunctionInformation */
public Instrumentation instrumentationTemplate;
String appNameStr;
/**
* App identifier string for use by the instrumentation template's
* app_name_setter. @see #instrumentationTemplate
*/
public void setAppNameStr(String appNameStr) {
this.appNameStr = appNameStr;
}
/** Record function information */
public boolean recordFunctionInformation;
boolean checksOnly;
static enum OutputJs {
// Don't output anything.
NONE,
// Output a "sentinel" file containing just a comment.
SENTINEL,
// Output the compiled JS.
NORMAL,
}
OutputJs outputJs;
public boolean generateExports;
// TODO(dimvar): generate-exports should always run after typechecking.
// If it runs before, it adds a bunch of properties to Object, which masks
// many type warnings. Cleanup all clients and remove this.
boolean generateExportsAfterTypeChecking;
boolean exportLocalPropertyDefinitions;
/** Map used in the renaming of CSS class names. */
public CssRenamingMap cssRenamingMap;
/** Whitelist used in the renaming of CSS class names. */
Set<String> cssRenamingWhitelist;
/** Process instances of goog.testing.ObjectPropertyString. */
boolean processObjectPropertyString;
/** Replace id generators */
boolean replaceIdGenerators = true; // true by default for legacy reasons.
/** Id generators to replace. */
ImmutableMap<String, RenamingMap> idGenerators;
/** Hash function to use for xid generation. */
Xid.HashFunction xidHashFunction;
/**
* A previous map of ids (serialized to a string by a previous compile).
* This will be used as a hint during the ReplaceIdGenerators pass, which
* will attempt to reuse the same ids.
*/
String idGeneratorsMapSerialized;
/** Configuration strings */
List<String> replaceStringsFunctionDescriptions;
String replaceStringsPlaceholderToken;
// A list of strings that should not be used as replacements
Set<String> replaceStringsReservedStrings;
// A previous map of replacements to strings.
VariableMap replaceStringsInputMap;
/** List of properties that we report invalidation errors for. */
Map<String, CheckLevel> propertyInvalidationErrors;
/** Transform AMD to CommonJS modules. */
boolean transformAMDToCJSModules = false;
/** Rewrite CommonJS modules so that they can be concatenated together. */
boolean processCommonJSModules = false;
/** CommonJS module prefix. */
List<String> moduleRoots = ImmutableList.of(ES6ModuleLoader.DEFAULT_FILENAME_PREFIX);
/** Rewrite polyfills. */
boolean rewritePolyfills = false;
/** Runtime libraries to always inject. */
List<String> forceLibraryInjection = ImmutableList.of();
/** Runtime libraries to never inject. */
boolean preventLibraryInjection = false;
//--------------------------------
// Output options
//--------------------------------
/** Do not strip closure-style type annotations from code. */
public boolean preserveTypeAnnotations;
/** Output in pretty indented format */
public boolean prettyPrint;
/** Line break the output a bit more aggressively */
public boolean lineBreak;
/** Prefer line breaks at end of file */
public boolean preferLineBreakAtEndOfFile;
/** Prints a separator comment before each JS script */
public boolean printInputDelimiter;
/** The string to use as the separator for printInputDelimiter */
public String inputDelimiter = "// Input %num%";
/** Whether to write keyword properties as foo['class'] instead of foo.class; needed for IE8. */
boolean quoteKeywordProperties;
boolean preferSingleQuotes;
/**
* Normally, when there are an equal number of single and double quotes
* in a string, the compiler will use double quotes. Set this to true
* to prefer single quotes.
*/
public void setPreferSingleQuotes(boolean enabled) {
this.preferSingleQuotes = enabled;
}
boolean trustedStrings;
/**
* Some people want to put arbitrary user input into strings, which are then
* run through the compiler. These scripts are then put into HTML.
* By default, we assume strings are untrusted. If the compiler is run
* from the command-line, we assume that strings are trusted.
*/
public void setTrustedStrings(boolean yes) {
trustedStrings = yes;
}
String reportPath;
// Should only be used when debugging compiler bugs using small JS inputs.
boolean printSourceAfterEachPass;
public void setPrintSourceAfterEachPass(boolean printSource) {
this.printSourceAfterEachPass = printSource;
}
/** Where to save a report of global name usage */
public void setReportPath(String reportPath) {
this.reportPath = reportPath;
}
TracerMode tracer;
public TracerMode getTracerMode() {
return tracer;
}
public void setTracerMode(TracerMode mode) {
this.tracer = mode;
}
private boolean colorizeErrorOutput;
public ErrorFormat errorFormat;
private ComposeWarningsGuard warningsGuard = new ComposeWarningsGuard();
int summaryDetailLevel = 1;
int lineLengthThreshold = DEFAULT_LINE_LENGTH_THRESHOLD;
//--------------------------------
// Special Output Options
//--------------------------------
/**
* Whether the exports should be made available via {@link Result} after
* compilation. This is implicitly true if {@link #externExportsPath} is set.
*/
private boolean externExports;
/** The output path for the created externs file. */
String externExportsPath;
String nameReferenceReportPath;
/** Where to save a cross-reference report from the name reference graph */
public void setNameReferenceReportPath(String filePath) {
nameReferenceReportPath = filePath;
}
String nameReferenceGraphPath;
/** Where to save the name reference graph */
public void setNameReferenceGraphPath(String filePath) {
nameReferenceGraphPath = filePath;
}
//--------------------------------
// Debugging Options
//--------------------------------
/** The output path for the source map. */
public String sourceMapOutputPath;
/** The detail level for the generated source map. */
public SourceMap.DetailLevel sourceMapDetailLevel =
SourceMap.DetailLevel.ALL;
/** The source map file format */
public SourceMap.Format sourceMapFormat =
SourceMap.Format.DEFAULT;
public List<SourceMap.LocationMapping> sourceMapLocationMappings =
Collections.emptyList();
/**
* Whether to return strings logged with AbstractCompiler#addToDebugLog
* in the compiler's Result.
*/
boolean useDebugLog;
/**
* Charset to use when generating code. If null, then output ASCII.
*/
Charset outputCharset;
/**
* Transitional option.
*/
boolean enforceAccessControlCodingConventions;
/**
* When set, assume that apparently side-effect free code is meaningful.
*/
boolean protectHiddenSideEffects;
/**
* When enabled, assume that apparently side-effect free code is meaningful.
*/
public void setProtectHiddenSideEffects(boolean enable) {
this.protectHiddenSideEffects = enable;
}
/**
* Data holder Alias Transformation information accumulated during a compile.
*/
private transient AliasTransformationHandler aliasHandler;
/**
* Handler for compiler warnings and errors.
*/
transient ErrorHandler errorHandler;
/**
* Instrument code for the purpose of collecting coverage data.
*/
public boolean instrumentForCoverage;
String instrumentationTemplateFile;
/** List of conformance configs to use in CheckConformance */
private ImmutableList<ConformanceConfig> conformanceConfigs = ImmutableList.of();
/**
* For use in {@value CompilationLevel#WHITESPACE_ONLY} mode, when using goog.module.
*/
boolean wrapGoogModulesForWhitespaceOnly = true;
public void setWrapGoogModulesForWhitespaceOnly(boolean enable) {
this.wrapGoogModulesForWhitespaceOnly = enable;