Skip to content

Commit 1dc79fa

Browse files
lauraharkercopybara-github
authored andcommitted
Always set ClosureUnawareMode.SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION & remove the flag
ClosureUnawareMode.SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION was already the default, but we are just removing the ability to opt out. The mode for handling @closureUnaware blocks is now specified within the annotation itself (e.g., @closureUnaware {SIMPLE} or @closureUnaware {WHITESPACE}), making the global CompilerOptions.ClosureUnawareMode redundant. PiperOrigin-RevId: 892379719
1 parent 7d8392b commit 1dc79fa

4 files changed

Lines changed: 2 additions & 53 deletions

File tree

src/com/google/javascript/jscomp/AstValidator.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ enum TypeInfoValidation {
6868
/** Validate that all required inlinings were performed. */
6969
private final boolean shouldValidateRequiredInlinings;
7070

71-
private final boolean shouldValidateFeaturesInClosureUnaware;
72-
7371
public AstValidator(
7472
AbstractCompiler compiler,
7573
ViolationHandler handler,
@@ -79,9 +77,6 @@ public AstValidator(
7977
this.violationHandler = handler;
8078
this.isScriptFeatureValidationEnabled = validateScriptFeatures;
8179
this.shouldValidateRequiredInlinings = shouldValidateRequiredInlinings;
82-
this.shouldValidateFeaturesInClosureUnaware =
83-
compiler.getOptions().getClosureUnawareMode()
84-
== CompilerOptions.ClosureUnawareMode.SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION;
8580
}
8681

8782
public AstValidator(AbstractCompiler compiler) {
@@ -2131,14 +2126,6 @@ private void validateMaximumChildCount(Node n, int i) {
21312126
}
21322127

21332128
private void validateFeature(Feature feature, Node n) {
2134-
if (!shouldValidateFeaturesInClosureUnaware && n.getIsInClosureUnawareSubtree()) {
2135-
// Closure-unaware code is currently hidden from transpilation passes in the compiler when
2136-
// options.setClosureUnawareMode(Mode.PASS_THROUGH) is enabled, so the AST
2137-
// might still contain features that should have been transpiled.
2138-
// TODO: b/321233583 - Once JSCompiler always transpiles closure-unaware code, remove this
2139-
// early-return to validate that all closure-unaware code is transpiled properly.
2140-
return;
2141-
}
21422129
FeatureSet allowbleFeatures = compiler.getAllowableFeatures();
21432130
// Checks that feature present in the AST is recorded in the compiler's featureSet.
21442131
if (!n.isFromExterns() && !allowbleFeatures.has(feature)) {

src/com/google/javascript/jscomp/ClosureUnawareOptions.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ private void setTranspilationOptions() {
8787
// DiagnosticGroups.UNTRANSPILABLE_FEATURES: features JSCompiler will never transpile but
8888
// can pass through unchanged to the output, such as newer regex syntax.
8989
shadowOptions.setWarningLevel(DiagnosticGroups.UNTRANSPILABLE_FEATURES, CheckLevel.OFF);
90-
91-
// No point in trying to run the TranspileAndOptimizeClosureUnaware pass recursively - we don't
92-
// support nesting @closureUnaware code blocks.
93-
shadowOptions.setClosureUnawareMode(CompilerOptions.ClosureUnawareMode.PASS_THROUGH);
9490
}
9591

9692
private void setSafeOptimizationAssumptions() {

src/com/google/javascript/jscomp/CompilerOptions.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,34 +2898,6 @@ String getReplaceStringsPlaceholderToken() {
28982898
return this.replaceStringsPlaceholderToken;
28992899
}
29002900

2901-
/**
2902-
* How @closureUnaware code blocks should be handled.
2903-
*
2904-
* <p>PASS_THROUGH: they are entirely hidden from the compiler, as if they were an evaled string.
2905-
*
2906-
* <p>SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION: This is *experimental* - we want to support some
2907-
* minimal transpilation & safe optimizations. TODO: b/421971366 - implement this flag.
2908-
*/
2909-
public enum ClosureUnawareMode {
2910-
PASS_THROUGH,
2911-
SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION
2912-
}
2913-
2914-
private ClosureUnawareMode closureUnawareMode =
2915-
ClosureUnawareMode.SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION;
2916-
2917-
/**
2918-
* Opts into experimental support for transpiling/optimizing @closureUnaware code blocks, rather
2919-
* than just passing them through compilation unchanged.
2920-
*/
2921-
public void setClosureUnawareMode(ClosureUnawareMode mode) {
2922-
this.closureUnawareMode = mode;
2923-
}
2924-
2925-
ClosureUnawareMode getClosureUnawareMode() {
2926-
return this.closureUnawareMode;
2927-
}
2928-
29292901
public void setPrettyPrint(boolean prettyPrint) {
29302902
this.prettyPrint = prettyPrint;
29312903
}

src/com/google/javascript/jscomp/DefaultPassConfig.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ protected PassListBuilder getTranspileOnlyPasses() {
148148

149149
TranspilationPasses.addTranspilationRuntimeLibraries(passes);
150150

151-
if (options.getClosureUnawareMode()
152-
== CompilerOptions.ClosureUnawareMode.SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION) {
153-
passes.maybeAdd(transpileOnlyClosureUnaware);
154-
}
151+
passes.maybeAdd(transpileOnlyClosureUnaware);
155152

156153
if (options.needsTranspilationFrom(ES2015) && options.getRewritePolyfills()) {
157154
if (options.getIsolatePolyfills()) {
@@ -870,10 +867,7 @@ private PassListBuilder getEarlyOptimizationPasses() {
870867
passes.maybeAdd(j2clPass);
871868
}
872869

873-
if (options.getClosureUnawareMode()
874-
== CompilerOptions.ClosureUnawareMode.SIMPLE_OPTIMIZATIONS_AND_TRANSPILATION) {
875-
passes.maybeAdd(transpileAndOptimizeClosureUnaware);
876-
}
870+
passes.maybeAdd(transpileAndOptimizeClosureUnaware);
877871

878872
TranspilationPasses.addTranspilationRuntimeLibraries(passes);
879873

0 commit comments

Comments
 (0)