Repository: google/closure-compiler
Pull request #1072 (2015-08-12 23:48:59)

Revert "Initial support for the --env flag"
All these file moves are hard to land when two trees are out of sync. Rollingback temporarily so that we can sync trees first.


Patch:
diff --git a/build.xml b/build.xml
index d472483dd..556f0ab24 100644
--- a/build.xml
+++ b/build.xml
@@ -173,16 +173,15 @@
     <copy todir="${classes.dir}/com/google/javascript/jscomp/js">
       <fileset dir="${src.dir}/com/google/javascript/jscomp/js" />
     </copy>
-
-    <!-- Zip the externs and move them to the classes folder -->
-    <zip destfile="${classes.dir}/externs.zip" basedir="${externs.dir}" includes="**/*.js" />
   </target>
 
   <target name="jar"
           depends="compile"
           description="package compiler as an executable jar">
+    <zip destfile="${build.dir}/externs.zip" basedir="${externs.dir}" includes="*.js" />
     <jar destfile="${compiler-jarfile}" update="true">
       <fileset dir="${classes.dir}" />
+      <fileset dir="${build.dir}" includes="externs.zip" />
       <zipfileset src="${lib.dir}/args4j.jar"/>
       <zipfileset src="${lib.dir}/guava.jar"/>
       <zipfileset src="${lib.dir}/gson.jar"/>
@@ -342,6 +341,7 @@
   <target name="webservice-jar"
           description="package the compiler and Webservice classes"
           depends="webservice-compile, compile">
+   <zip destfile="${build.dir}/externs.zip" basedir="${externs.dir}" includes="*.js" />
    <jar destfile="${webservice-jarfile}" update="true">
      <zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
      <fileset dir="${classes.dir}" />
@@ -379,6 +379,7 @@
   <target name="refasterjs-jar"
           description="Packages the compiler and RefasterJS classes"
           depends="refasterjs-compile, compile">
+   <zip destfile="${build.dir}/externs.zip" basedir="${externs.dir}" includes="*.js" />
    <jar destfile="${refasterjs-jarfile}" update="true">
      <zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
      <fileset dir="${build.dir}" includes="externs.zip" />
diff --git a/externs/browser/chrome.js b/externs/chrome.js
similarity index 100%
rename from externs/browser/chrome.js
rename to externs/chrome.js
diff --git a/externs/browser/deprecated.js b/externs/deprecated.js
similarity index 100%
rename from externs/browser/deprecated.js
rename to externs/deprecated.js
diff --git a/externs/browser/fetchapi.js b/externs/fetchapi.js
similarity index 100%
rename from externs/browser/fetchapi.js
rename to externs/fetchapi.js
diff --git a/externs/browser/fileapi.js b/externs/fileapi.js
similarity index 100%
rename from externs/browser/fileapi.js
rename to externs/fileapi.js
diff --git a/externs/browser/flash.js b/externs/flash.js
similarity index 100%
rename from externs/browser/flash.js
rename to externs/flash.js
diff --git a/externs/browser/gecko_css.js b/externs/gecko_css.js
similarity index 100%
rename from externs/browser/gecko_css.js
rename to externs/gecko_css.js
diff --git a/externs/browser/gecko_dom.js b/externs/gecko_dom.js
similarity index 100%
rename from externs/browser/gecko_dom.js
rename to externs/gecko_dom.js
diff --git a/externs/browser/gecko_event.js b/externs/gecko_event.js
similarity index 100%
rename from externs/browser/gecko_event.js
rename to externs/gecko_event.js
diff --git a/externs/browser/gecko_xml.js b/externs/gecko_xml.js
similarity index 100%
rename from externs/browser/gecko_xml.js
rename to externs/gecko_xml.js
diff --git a/externs/browser/google.js b/externs/google.js
similarity index 100%
rename from externs/browser/google.js
rename to externs/google.js
diff --git a/externs/browser/html5.js b/externs/html5.js
similarity index 100%
rename from externs/browser/html5.js
rename to externs/html5.js
diff --git a/externs/browser/ie_css.js b/externs/ie_css.js
similarity index 100%
rename from externs/browser/ie_css.js
rename to externs/ie_css.js
diff --git a/externs/browser/ie_dom.js b/externs/ie_dom.js
similarity index 100%
rename from externs/browser/ie_dom.js
rename to externs/ie_dom.js
diff --git a/externs/browser/ie_event.js b/externs/ie_event.js
similarity index 100%
rename from externs/browser/ie_event.js
rename to externs/ie_event.js
diff --git a/externs/browser/ie_vml.js b/externs/ie_vml.js
similarity index 100%
rename from externs/browser/ie_vml.js
rename to externs/ie_vml.js
diff --git a/externs/browser/intl.js b/externs/intl.js
similarity index 100%
rename from externs/browser/intl.js
rename to externs/intl.js
diff --git a/externs/browser/iphone.js b/externs/iphone.js
similarity index 100%
rename from externs/browser/iphone.js
rename to externs/iphone.js
diff --git a/externs/browser/mediasource.js b/externs/mediasource.js
similarity index 100%
rename from externs/browser/mediasource.js
rename to externs/mediasource.js
diff --git a/externs/browser/page_visibility.js b/externs/page_visibility.js
similarity index 100%
rename from externs/browser/page_visibility.js
rename to externs/page_visibility.js
diff --git a/externs/browser/streamsapi.js b/externs/streamsapi.js
similarity index 100%
rename from externs/browser/streamsapi.js
rename to externs/streamsapi.js
diff --git a/externs/browser/v8.js b/externs/v8.js
similarity index 100%
rename from externs/browser/v8.js
rename to externs/v8.js
diff --git a/externs/browser/w3c_anim_timing.js b/externs/w3c_anim_timing.js
similarity index 100%
rename from externs/browser/w3c_anim_timing.js
rename to externs/w3c_anim_timing.js
diff --git a/externs/browser/w3c_audio.js b/externs/w3c_audio.js
similarity index 100%
rename from externs/browser/w3c_audio.js
rename to externs/w3c_audio.js
diff --git a/externs/browser/w3c_batterystatus.js b/externs/w3c_batterystatus.js
similarity index 100%
rename from externs/browser/w3c_batterystatus.js
rename to externs/w3c_batterystatus.js
diff --git a/externs/browser/w3c_css.js b/externs/w3c_css.js
similarity index 100%
rename from externs/browser/w3c_css.js
rename to externs/w3c_css.js
diff --git a/externs/browser/w3c_css3d.js b/externs/w3c_css3d.js
similarity index 100%
rename from externs/browser/w3c_css3d.js
rename to externs/w3c_css3d.js
diff --git a/externs/browser/w3c_device_sensor_event.js b/externs/w3c_device_sensor_event.js
similarity index 100%
rename from externs/browser/w3c_device_sensor_event.js
rename to externs/w3c_device_sensor_event.js
diff --git a/externs/browser/w3c_dom1.js b/externs/w3c_dom1.js
similarity index 100%
rename from externs/browser/w3c_dom1.js
rename to externs/w3c_dom1.js
diff --git a/externs/browser/w3c_dom2.js b/externs/w3c_dom2.js
similarity index 100%
rename from externs/browser/w3c_dom2.js
rename to externs/w3c_dom2.js
diff --git a/externs/browser/w3c_dom3.js b/externs/w3c_dom3.js
similarity index 100%
rename from externs/browser/w3c_dom3.js
rename to externs/w3c_dom3.js
diff --git a/externs/browser/w3c_elementtraversal.js b/externs/w3c_elementtraversal.js
similarity index 100%
rename from externs/browser/w3c_elementtraversal.js
rename to externs/w3c_elementtraversal.js
diff --git a/externs/browser/w3c_encoding.js b/externs/w3c_encoding.js
similarity index 100%
rename from externs/browser/w3c_encoding.js
rename to externs/w3c_encoding.js
diff --git a/externs/browser/w3c_event.js b/externs/w3c_event.js
similarity index 100%
rename from externs/browser/w3c_event.js
rename to externs/w3c_event.js
diff --git a/externs/browser/w3c_event3.js b/externs/w3c_event3.js
similarity index 100%
rename from externs/browser/w3c_event3.js
rename to externs/w3c_event3.js
diff --git a/externs/browser/w3c_geolocation.js b/externs/w3c_geolocation.js
similarity index 100%
rename from externs/browser/w3c_geolocation.js
rename to externs/w3c_geolocation.js
diff --git a/externs/browser/w3c_indexeddb.js b/externs/w3c_indexeddb.js
similarity index 100%
rename from externs/browser/w3c_indexeddb.js
rename to externs/w3c_indexeddb.js
diff --git a/externs/browser/w3c_navigation_timing.js b/externs/w3c_navigation_timing.js
similarity index 100%
rename from externs/browser/w3c_navigation_timing.js
rename to externs/w3c_navigation_timing.js
diff --git a/externs/browser/w3c_range.js b/externs/w3c_range.js
similarity index 100%
rename from externs/browser/w3c_range.js
rename to externs/w3c_range.js
diff --git a/externs/browser/w3c_rtc.js b/externs/w3c_rtc.js
similarity index 100%
rename from externs/browser/w3c_rtc.js
rename to externs/w3c_rtc.js
diff --git a/externs/browser/w3c_selectors.js b/externs/w3c_selectors.js
similarity index 100%
rename from externs/browser/w3c_selectors.js
rename to externs/w3c_selectors.js
diff --git a/externs/browser/w3c_serviceworker.js b/externs/w3c_serviceworker.js
similarity index 100%
rename from externs/browser/w3c_serviceworker.js
rename to externs/w3c_serviceworker.js
diff --git a/externs/browser/w3c_webcrypto.js b/externs/w3c_webcrypto.js
similarity index 100%
rename from externs/browser/w3c_webcrypto.js
rename to externs/w3c_webcrypto.js
diff --git a/externs/browser/w3c_xml.js b/externs/w3c_xml.js
similarity index 100%
rename from externs/browser/w3c_xml.js
rename to externs/w3c_xml.js
diff --git a/externs/browser/webgl.js b/externs/webgl.js
similarity index 100%
rename from externs/browser/webgl.js
rename to externs/webgl.js
diff --git a/externs/browser/webkit_css.js b/externs/webkit_css.js
similarity index 100%
rename from externs/browser/webkit_css.js
rename to externs/webkit_css.js
diff --git a/externs/browser/webkit_dom.js b/externs/webkit_dom.js
similarity index 100%
rename from externs/browser/webkit_dom.js
rename to externs/webkit_dom.js
diff --git a/externs/browser/webkit_event.js b/externs/webkit_event.js
similarity index 100%
rename from externs/browser/webkit_event.js
rename to externs/webkit_event.js
diff --git a/externs/browser/webkit_notifications.js b/externs/webkit_notifications.js
similarity index 100%
rename from externs/browser/webkit_notifications.js
rename to externs/webkit_notifications.js
diff --git a/externs/browser/webstorage.js b/externs/webstorage.js
similarity index 100%
rename from externs/browser/webstorage.js
rename to externs/webstorage.js
diff --git a/externs/browser/window.js b/externs/window.js
similarity index 100%
rename from externs/browser/window.js
rename to externs/window.js
diff --git a/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java b/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
index 2cdb1e541..8b2fc0d7a 100644
--- a/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
+++ b/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
@@ -821,11 +821,11 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
   protected int doRun() throws FlagUsageException, IOException {
     Compiler.setLoggingLevel(Level.parse(config.loggingLevel));
 
+    List<SourceFile> externs = createExterns();
+
     compiler = createCompiler();
     B options = createOptions();
 
-    List<SourceFile> externs = createExterns(options);
-
     List<JSModule> modules = null;
     Result result = null;
 
@@ -1086,8 +1086,8 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
     return UTF_8;
   }
 
-  protected List<SourceFile> createExterns(CompilerOptions options)
-      throws FlagUsageException, IOException {
+  protected List<SourceFile> createExterns() throws FlagUsageException,
+      IOException {
     return isInTestMode() ? externsSupplierForTesting.get() :
         createExternInputs(config.externs);
   }
diff --git a/src/com/google/javascript/jscomp/CommandLineRunner.java b/src/com/google/javascript/jscomp/CommandLineRunner.java
index 7bf5030d6..d6d15fc60 100644
--- a/src/com/google/javascript/jscomp/CommandLineRunner.java
+++ b/src/com/google/javascript/jscomp/CommandLineRunner.java
@@ -65,6 +65,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -379,6 +380,12 @@ public class CommandLineRunner extends
         "QUIET, DEFAULT, VERBOSE")
     private WarningLevel warningLevel = WarningLevel.DEFAULT;
 
+    @Option(name = "--use_only_custom_externs",
+        hidden = true,
+        handler = BooleanOptionHandler.class,
+        usage = "Specifies whether the default externs should be excluded")
+    private boolean useOnlyCustomExterns = false;
+
     @Option(name = "--debug",
         hidden = true,
         handler = BooleanOptionHandler.class,
@@ -582,13 +589,6 @@ public class CommandLineRunner extends
         usage = "A list of JS Conformance configurations in text protocol buffer format.")
     private List<String> conformanceConfigs = new ArrayList<>();
 
-    @Option(name = "--env",
-        hidden = true,
-        usage = "Determines the set of builtin externs to load. "
-            + "Options: BROWSER, CUSTOM. Defaults to BROWSER.")
-    private CompilerOptions.Environment environment =
-        CompilerOptions.Environment.BROWSER;
-
     @Argument
     private List<String> arguments = new ArrayList<>();
     private final CmdLineParser parser;
@@ -1128,8 +1128,6 @@ public class CommandLineRunner extends
       level.setDebugOptionsForCompilationLevel(options);
     }
 
-    options.setEnvironment(flags.environment);
-
     options.setChecksOnly(flags.checksOnly);
 
     if (flags.useTypesForOptimization) {
@@ -1193,15 +1191,15 @@ public class CommandLineRunner extends
   }
 
   @Override
-  protected List<SourceFile> createExterns(CompilerOptions options)
-      throws FlagUsageException, IOException {
-    List<SourceFile> externs = super.createExterns(options);
-    if (isInTestMode()) {
+  protected List<SourceFile> createExterns() throws FlagUsageException,
+      IOException {
+    List<SourceFile> externs = super.createExterns();
+    if (flags.useOnlyCustomExterns || isInTestMode()) {
       return externs;
     } else {
-      List<SourceFile> builtinExterns = getBuiltinExterns(options);
-      builtinExterns.addAll(externs);
-      return builtinExterns;
+      List<SourceFile> defaultExterns = getDefaultExterns();
+      defaultExterns.addAll(externs);
+      return defaultExterns;
     }
   }
 
@@ -1240,42 +1238,79 @@ public class CommandLineRunner extends
     return builder.build();
   }
 
-  // The core language externs expected in externs.zip, in sorted order.
-  private static final List<String> BUILTIN_LANG_EXTERNS = ImmutableList.of(
-      "es3.js",
-      "es5.js",
-      "es6.js",
-      "es6_collections.js");
-
-  // Externs expected in externs.zip, in sorted order.
-  // Externs not included in this list will be added last
-  private static final List<String> BUILTIN_EXTERN_DEP_ORDER = ImmutableList.of(
-    //-- browser externs --
-    "browser/intl.js",
-    "browser/w3c_event.js",
-    "browser/w3c_event3.js",
-    "browser/gecko_event.js",
-    "browser/ie_event.js",
-    "browser/webkit_event.js",
-    "browser/w3c_device_sensor_event.js",
-    "browser/w3c_dom1.js",
-    "browser/w3c_dom2.js",
-    "browser/w3c_dom3.js",
-    "browser/gecko_dom.js",
-    "browser/ie_dom.js",
-    "browser/webkit_dom.js",
-    "browser/w3c_css.js",
-    "browser/gecko_css.js",
-    "browser/ie_css.js",
-    "browser/webkit_css.js"
-  );
+  // The externs expected in externs.zip, in sorted order.
+  private static final List<String> DEFAULT_EXTERNS_NAMES = ImmutableList.of(
+    // JS externs
+    "es3.js",
+    "es5.js",
+    "es6.js",
+    "es6_collections.js",
+    "intl.js",
+
+    // Event APIs
+    "w3c_event.js",
+    "w3c_event3.js",
+    "gecko_event.js",
+    "ie_event.js",
+    "webkit_event.js",
+    "w3c_device_sensor_event.js",
+
+    // DOM apis
+    "w3c_dom1.js",
+    "w3c_dom2.js",
+    "w3c_dom3.js",
+    "gecko_dom.js",
+    "ie_dom.js",
+    "webkit_dom.js",
+
+    // CSS apis
+    "w3c_css.js",
+    "gecko_css.js",
+    "ie_css.js",
+    "webkit_css.js",
+
+    // Top-level namespaces
+    "google.js",
+
+    "chrome.js",
+
+    "deprecated.js",
+    "fetchapi.js",
+    "fileapi.js",
+    "flash.js",
+    "gecko_xml.js",
+    "html5.js",
+    "ie_vml.js",
+    "iphone.js",
+    "mediasource.js",
+    "page_visibility.js",
+    "streamsapi.js",
+    "v8.js",
+    "webstorage.js",
+    "w3c_anim_timing.js",
+    "w3c_audio.js",
+    "w3c_batterystatus.js",
+    "w3c_encoding.js",
+    "w3c_css3d.js",
+    "w3c_elementtraversal.js",
+    "w3c_geolocation.js",
+    "w3c_indexeddb.js",
+    "w3c_navigation_timing.js",
+    "w3c_range.js",
+    "w3c_rtc.js",
+    "w3c_selectors.js",
+    "w3c_serviceworker.js",
+    "w3c_webcrypto.js",
+    "w3c_xml.js",
+    "window.js",
+    "webkit_notifications.js",
+    "webgl.js");
 
   /**
    * @return a mutable list
    * @throws IOException
    */
-  public static List<SourceFile> getBuiltinExterns(CompilerOptions options)
-      throws IOException {
+  public static List<SourceFile> getDefaultExterns() throws IOException {
     InputStream input = CommandLineRunner.class.getResourceAsStream(
         "/externs.zip");
     if (input == null) {
@@ -1285,54 +1320,30 @@ public class CommandLineRunner extends
     Preconditions.checkNotNull(input);
 
     ZipInputStream zip = new ZipInputStream(input);
-    final String envPrefix = options.getEnvironment().toString().toLowerCase()
-        + "/";
-
     Map<String, SourceFile> externsMap = new HashMap<>();
     for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
-      // Only load externs in the root folder or in a subfolder matching
-      // the specified environment
-      if (entry.getName().indexOf("/") < 0 ||
-          (entry.getName().indexOf(envPrefix) == 0 &&
-              entry.getName().length() > envPrefix.length())) {
-        BufferedInputStream entryStream = new BufferedInputStream(
-            ByteStreams.limit(zip, entry.getSize()));
-        externsMap.put(entry.getName(),
-            SourceFile.fromInputStream(
-                // Give the files an odd prefix, so that they do not conflict
-                // with the user's files.
-                "externs.zip//" + entry.getName(),
-                entryStream,
-                UTF_8));
-      }
-    }
-
-    List<SourceFile> externs = new ArrayList<>();
-
-    // The externs for core JS objects are loaded in all environments.
-    for (String key : BUILTIN_LANG_EXTERNS) {
-      Preconditions.checkState(
-          externsMap.containsKey(key),
-          "Externs zip must contain " + key + ".");
-      externs.add(externsMap.remove(key));
+      BufferedInputStream entryStream = new BufferedInputStream(
+          ByteStreams.limit(zip, entry.getSize()));
+      externsMap.put(entry.getName(),
+          SourceFile.fromInputStream(
+              // Give the files an odd prefix, so that they do not conflict
+              // with the user's files.
+              "externs.zip//" + entry.getName(),
+              entryStream,
+              UTF_8));
     }
 
-    // Order matters, so extern resources which have dependencies must be added
-    // to the result list in the expected order.
-    for (String key : BUILTIN_EXTERN_DEP_ORDER) {
-      if (key.indexOf(envPrefix) < 0) {
-        continue;
-      }
+    Preconditions.checkState(
+        externsMap.keySet().equals(new HashSet<>(DEFAULT_EXTERNS_NAMES)),
+        "Externs zip must match our hard-coded list of externs.");
 
-      Preconditions.checkState(
-          externsMap.containsKey(key),
-          "Externs zip must contain " + key + " when environment is " +
-              options.getEnvironment().toString());
-      externs.add(externsMap.remove(key));
+    // Order matters, so the resources must be added to the result list
+    // in the expected order.
+    List<SourceFile> externs = new ArrayList<>();
+    for (String key : DEFAULT_EXTERNS_NAMES) {
+      externs.add(externsMap.get(key));
     }
 
-    externs.addAll(externsMap.values());
-
     return externs;
   }
 
diff --git a/src/com/google/javascript/jscomp/CompilerOptions.java b/src/com/google/javascript/jscomp/CompilerOptions.java
index d90142cbd..cbdd3214c 100644
--- a/src/com/google/javascript/jscomp/CompilerOptions.java
+++ b/src/com/google/javascript/jscomp/CompilerOptions.java
@@ -76,11 +76,6 @@ public class CompilerOptions implements Serializable {
    */
   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
@@ -966,9 +961,6 @@ public class CompilerOptions implements Serializable {
     languageIn = LanguageMode.ECMASCRIPT3;
     languageOut = LanguageMode.NO_TRANSPILE;
 
-    // Which environment to use
-    environment = Environment.BROWSER;
-
     // Language variation
     acceptTypeSyntax = false;
 
@@ -1655,17 +1647,6 @@ public class CompilerOptions implements Serializable {
     return languageOut;
   }
 
-  /**
-   * Set which set of builtin externs to use.
-   */
-  public void setEnvironment(Environment environment) {
-    this.environment = environment;
-  }
-
-  public Environment getEnvironment() {
-    return environment;
-  }
-
   /**
    * @return whether we are currently transpiling from ES6 to a lower version.
    */
@@ -2570,20 +2551,4 @@ public class CompilerOptions implements Serializable {
       }
     }
   }
-
-  /**
-   * An environment specifies the built-in externs that are loaded for a given
-   * compilation.
-   */
-  public static enum Environment {
-    /**
-     * Hand crafted externs that have traditionally been the default externs.
-     */
-    BROWSER,
-
-    /**
-     * Only language externs are loaded.
-     */
-    CUSTOM
-  }
 }
diff --git a/src/com/google/javascript/jscomp/ant/CompileTask.java b/src/com/google/javascript/jscomp/ant/CompileTask.java
index 7ec9e4117..3c2a99dd3 100644
--- a/src/com/google/javascript/jscomp/ant/CompileTask.java
+++ b/src/com/google/javascript/jscomp/ant/CompileTask.java
@@ -76,7 +76,7 @@ public final class CompileTask
   private String encoding = "UTF-8";
   private String outputEncoding = "UTF-8";
   private CompilationLevel compilationLevel;
-  private CompilerOptions.Environment environment;
+  private boolean customExternsOnly;
   private boolean manageDependencies;
   private boolean prettyPrint;
   private boolean printInputDelimiter;
@@ -104,7 +104,7 @@ public final class CompileTask
     this.warningLevel = WarningLevel.DEFAULT;
     this.debugOptions = false;
     this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
-    this.environment = CompilerOptions.Environment.BROWSER;
+    this.customExternsOnly = false;
     this.manageDependencies = false;
     this.prettyPrint = false;
     this.printInputDelimiter = false;
@@ -172,25 +172,6 @@ public final class CompileTask
     }
   }
 
-  /**
-   * Set the environment which determines the builtin extern set.
-   * @param value The name of the environment.
-   *     (BROWSER, CUSTOM).
-   */
-  public void setEnvironment(String value) {
-    switch (value) {
-      case "BROWSER":
-        this.environment = CompilerOptions.Environment.BROWSER;
-        break;
-      case "CUSTOM":
-        this.environment = CompilerOptions.Environment.CUSTOM;
-        break;
-      default:
-        throw new BuildException(
-            "Unrecognized 'environment' option value (" + value + ")");
-    }
-  }
-
   /**
    * Enable debugging options.
    * @param value True if debug mode is enabled.
@@ -221,6 +202,13 @@ public final class CompileTask
     this.manageDependencies = value;
   }
 
+  /**
+   * Use only custom externs.
+   */
+  public void setCustomExternsOnly(boolean value) {
+    this.customExternsOnly = value;
+  }
+
   /**
    * Set output file.
    */
@@ -364,7 +352,7 @@ public final class CompileTask
     CompilerOptions options = createCompilerOptions();
     Compiler compiler = createCompiler(options);
 
-    List<SourceFile> externs = findExternFiles(options);
+    List<SourceFile> externs = findExternFiles();
     List<SourceFile> sources = findSourceFiles();
 
     if (isStale() || forceRecompile) {
@@ -433,8 +421,6 @@ public final class CompileTask
       this.compilationLevel.setDebugOptionsForCompilationLevel(options);
     }
 
-    options.setEnvironment(this.environment);
-
     options.setPrettyPrint(this.prettyPrint);
     options.setPrintInputDelimiter(this.printInputDelimiter);
     options.setPreferSingleQuotes(this.preferSingleQuotes);
@@ -611,9 +597,11 @@ public final class CompileTask
     return compiler;
   }
 
-  private List<SourceFile> findExternFiles(CompilerOptions options) {
+  private List<SourceFile> findExternFiles() {
     List<SourceFile> files = new LinkedList();
-    files.addAll(getBuiltinExterns(options));
+    if (!this.customExternsOnly) {
+      files.addAll(getDefaultExterns());
+    }
 
     for (FileList list : this.externFileLists) {
       files.addAll(findJavaScriptFiles(list));
@@ -660,9 +648,9 @@ public final class CompileTask
    *
    * Adapted from {@link CommandLineRunner}.
    */
-  private List<SourceFile> getBuiltinExterns(CompilerOptions options) {
+  private List<SourceFile> getDefaultExterns() {
     try {
-      return CommandLineRunner.getBuiltinExterns(options);
+      return CommandLineRunner.getDefaultExterns();
     } catch (IOException e) {
       throw new BuildException(e);
     }
diff --git a/src/com/google/javascript/refactoring/RefasterJs.java b/src/com/google/javascript/refactoring/RefasterJs.java
index 06fb5d5cd..dc161f1b5 100644
--- a/src/com/google/javascript/refactoring/RefasterJs.java
+++ b/src/com/google/javascript/refactoring/RefasterJs.java
@@ -21,7 +21,6 @@ import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.javascript.jscomp.CommandLineRunner;
-import com.google.javascript.jscomp.CompilerOptions;
 import com.google.javascript.jscomp.ErrorManager;
 import com.google.javascript.jscomp.SourceFile;
 
@@ -68,10 +67,9 @@ final class RefasterJs {
       usage = "Location of the JS file to use as the RefasterJS template.")
   private String refasterJsTemplate = null;
 
-  @Option(name = "--env",
-      usage = "Which set of externs to include. Defaults to BROWSER.")
-  private CompilerOptions.Environment environment =
-      CompilerOptions.Environment.BROWSER;
+  @Option(name = "--include_default_externs",
+      usage = "Whether to include the standard JavaScript externs. Defaults to true.")
+  private boolean includeDefaultExterns = true;
 
   @Option(name = "--dry_run",
       usage = "Use this to display what changes would be made without applying the changes.")
@@ -110,10 +108,9 @@ final class RefasterJs {
 
     RefasterJsScanner scanner = new RefasterJsScanner();
     scanner.loadRefasterJsTemplate(refasterJsTemplate);
-    CompilerOptions options = new CompilerOptions();
-    options.setEnvironment(environment);
     RefactoringDriver driver = new RefactoringDriver.Builder(scanner)
-        .addExterns(CommandLineRunner.getBuiltinExterns(options))
+        .addExterns(includeDefaultExterns
+            ? CommandLineRunner.getDefaultExterns() : ImmutableList.<SourceFile>of())
         .addExternsFromFile(getExterns())
         .addInputsFromFile(fileInputs)
         .build();


Test patch:
diff --git a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java
index 3100d7264..6793e0596 100644
--- a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java
+++ b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java
@@ -900,7 +900,7 @@ public final class CommandLineRunnerTest extends TestCase {
 
   public void testOnlyClosureDependenciesEmptyEntryPoints() throws Exception {
     // Prevents this from trying to load externs.zip
-    args.add("--env=CUSTOM");
+    args.add("--use_only_custom_externs=true");
 
     args.add("--only_closure_dependencies=true");
     try {
@@ -1007,7 +1007,7 @@ public final class CommandLineRunnerTest extends TestCase {
 
   public void testSourceMapLocationsTranslations3() {
     // Prevents this from trying to load externs.zip
-    args.add("--env=CUSTOM");
+    args.add("--use_only_custom_externs=true");
 
     args.add("--js_output_file");
     args.add("/path/to/out.js");
@@ -1280,7 +1280,7 @@ public final class CommandLineRunnerTest extends TestCase {
   }
 
   public void testNoSrCFilesWithManifest() throws IOException {
-    args.add("--env=CUSTOM");
+    args.add("--use_only_custom_externs=true");
     args.add("--output_manifest=test.MF");
     CommandLineRunner runner = createCommandLineRunner(new String[0]);
     String expectedMessage = "";