Enable Dart2 in dart2js by default

Change-Id: Id197fc734bcb45f0805e49e89c0d03419384bb0b
Reviewed-on: https://dart-review.googlesource.com/60448
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index faf1bc6..15b6043 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,21 @@
 
 #### Pub
 
+#### Dart2js
+
+* Dart2js now compiles programs by default with Dart 2.0 semantics. Apps are
+  expected to be bigger than before, because Dart 2.0 has many more implicit
+  checks (similar to the `--checked` flag in Dart 1.0). Other relevant flags:
+
+  * `--omit-implicit-checks`: is a flag that removes most of the extra implicit
+    checks. Only use this if you have enough test coverage to know that the app
+    will work well without the checks. If a check would have failed and it is
+    omitted, your app may crash or behave in unexpected ways.
+
+  * `--no-preview-dart-2`: a temporary flag to revert to Dart 1.0. This flag is
+    temporary and only meant to help users in the migration process. The flag
+    will go away in a future dev release, when we no longer support Dart 1.0.
+
 #### Other Tools
 
 ### Core library changes
diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart
index 53266de..a06b868 100644
--- a/pkg/compiler/lib/src/dart2js.dart
+++ b/pkg/compiler/lib/src/dart2js.dart
@@ -124,7 +124,8 @@
   bool analyzeOnly = false;
   bool trustTypeAnnotations = false;
   bool checkedMode = false;
-  bool strongMode = false;
+  bool strongMode = true;
+  bool forceStrongMode = true;
   List<String> hints = <String>[];
   bool verbose;
   bool throwOnError;
@@ -219,11 +220,16 @@
     passThrough(argument);
   }
 
-  void setStrongMode(_) {
-    strongMode = true;
+  void setForceStrongMode(_) {
+    strongMode = forceStrongMode = true;
     passThrough(Flags.strongMode);
   }
 
+  void setLegacyMode(_) {
+    if (!forceStrongMode) strongMode = false;
+    passThrough(Flags.noPreviewDart2);
+  }
+
   void addInEnvironment(String argument) {
     int eqIndex = argument.indexOf('=');
     String name = argument.substring(2, eqIndex);
@@ -357,9 +363,14 @@
     new OptionHandler(Flags.useContentSecurityPolicy, passThrough),
     new OptionHandler(Flags.enableExperimentalMirrors, passThrough),
     new OptionHandler(Flags.enableAssertMessage, passThrough),
-    new OptionHandler(Flags.strongMode, setStrongMode),
-    new OptionHandler(Flags.previewDart2, setStrongMode),
-    new OptionHandler(Flags.noPreviewDart2, ignoreOption),
+    // TODO(sigmund): ignore this option after we update our test bot
+    // configurations or stop testing Dart1.
+    // At the time this was added, some bots invoked dart2js with
+    // --no-preview-dart-2, but some test files contain extra dart2js options,
+    // including --strong. We want to make sure --strong takes precedence.
+    new OptionHandler(Flags.strongMode, setForceStrongMode),
+    new OptionHandler(Flags.previewDart2, setForceStrongMode),
+    new OptionHandler(Flags.noPreviewDart2, setLegacyMode),
     new OptionHandler(Flags.omitImplicitChecks, passThrough),
     new OptionHandler(Flags.laxRuntimeTypeToString, passThrough),
     new OptionHandler(Flags.benchmarkingProduction, passThrough),
@@ -653,9 +664,13 @@
     Produce JavaScript that can be parsed more quickly by VMs. This option
     usually results in larger JavaScript files with faster startup.
 
-  --preview-dart-2
-    Preview of all Dart 2.0 semantics, this includes generic methods and strong
-    mode type checks. This will be enabled by default very soon.
+  --no-preview-dart-2
+    Temporarily revert to Dart 1.0 semantics.
+
+    By default dart2js compiles programs in Dart 2.0 semantics, which includes
+    generic methods and strong mode type checks. Since apps may have additional
+    checks that fail at runtime, this temporary flag may help in the migration
+    process. See also '--omit-implicit-checks'.
 
 The following advanced options can help reduce the size of the generated code,
 but they may cause programs to behave unexpectedly if assumptions are not met.
diff --git a/pkg/compiler/lib/src/options.dart b/pkg/compiler/lib/src/options.dart
index 1e738ed..866d70c 100644
--- a/pkg/compiler/lib/src/options.dart
+++ b/pkg/compiler/lib/src/options.dart
@@ -231,7 +231,7 @@
   bool useContentSecurityPolicy = false;
 
   /// Enables strong mode in dart2js.
-  bool strongMode = false;
+  bool strongMode = true;
 
   /// When obfuscating for minification, whether to use the frequency of a name
   /// as an heuristic to pick shorter names.
@@ -325,7 +325,8 @@
       ..platformBinaries =
           platformBinaries ?? _extractUriOption(options, '--platform-binaries=')
       ..sourceMapUri = _extractUriOption(options, '--source-map=')
-      ..strongMode = _hasOption(options, Flags.strongMode)
+      ..strongMode = _hasOption(options, Flags.strongMode) ||
+          !_hasOption(options, Flags.noPreviewDart2)
       ..omitImplicitChecks = _hasOption(options, Flags.omitImplicitChecks)
       ..laxRuntimeTypeToString =
           _hasOption(options, Flags.laxRuntimeTypeToString)
diff --git a/tests/compiler/dart2js/codegen/expect_annotations_test.dart b/tests/compiler/dart2js/codegen/expect_annotations_test.dart
index 2b0cbfb..40bbeb5 100644
--- a/tests/compiler/dart2js/codegen/expect_annotations_test.dart
+++ b/tests/compiler/dart2js/codegen/expect_annotations_test.dart
@@ -4,6 +4,7 @@
 
 import 'package:expect/expect.dart';
 import 'package:async_helper/async_helper.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/compiler.dart';
 import 'package:compiler/src/elements/entities.dart';
 import 'package:compiler/src/inferrer/typemasks/masks.dart';
@@ -56,8 +57,8 @@
 }
 
 runTest() async {
-  CompilationResult result =
-      await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES);
+  CompilationResult result = await runCompiler(
+      memorySourceFiles: MEMORY_SOURCE_FILES, options: [Flags.noPreviewDart2]);
   Compiler compiler = result.compiler;
   JClosedWorld closedWorld = compiler.backendClosedWorldForTesting;
   Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation');
diff --git a/tests/compiler/dart2js/codegen/jsarray_indexof_test.dart b/tests/compiler/dart2js/codegen/jsarray_indexof_test.dart
index 2c2b74d..b7ecdeb 100644
--- a/tests/compiler/dart2js/codegen/jsarray_indexof_test.dart
+++ b/tests/compiler/dart2js/codegen/jsarray_indexof_test.dart
@@ -33,9 +33,9 @@
 main() {
   asyncTest(() async {
     print('--test from kernel------------------------------------------------');
-    await runTest([]);
+    await runTest([Flags.noPreviewDart2]);
     print('--test from kernel (trust-type-annotations)-----------------------');
-    await runTest([Flags.trustTypeAnnotations]);
+    await runTest([Flags.noPreviewDart2, Flags.trustTypeAnnotations]);
     print('--test from kernel (strong mode)----------------------------------');
     await runTest([Flags.strongMode]);
     print('--test from kernel (strong mode, omit-implicit.checks)------------');
diff --git a/tests/compiler/dart2js/codegen/trust_type_annotations_test.dart b/tests/compiler/dart2js/codegen/trust_type_annotations_test.dart
index 076929c..b8282c5 100644
--- a/tests/compiler/dart2js/codegen/trust_type_annotations_test.dart
+++ b/tests/compiler/dart2js/codegen/trust_type_annotations_test.dart
@@ -51,7 +51,7 @@
 
 void main() {
   runTest() async {
-    var options = [Flags.trustTypeAnnotations];
+    var options = [Flags.noPreviewDart2, Flags.trustTypeAnnotations];
     var result = await runCompiler(
         memorySourceFiles: {'main.dart': TEST}, options: options);
     var compiler = result.compiler;
diff --git a/tests/compiler/dart2js/compiler_helper.dart b/tests/compiler/dart2js/compiler_helper.dart
index d0fabb9..df85ea4 100644
--- a/tests/compiler/dart2js/compiler_helper.dart
+++ b/tests/compiler/dart2js/compiler_helper.dart
@@ -49,7 +49,11 @@
     void check(String generatedEntry),
     bool returnAll: false}) async {
   OutputCollector outputCollector = returnAll ? new OutputCollector() : null;
-  List<String> options = <String>[Flags.disableTypeInference];
+  // TODO(sigmund): use strong-mode.
+  List<String> options = <String>[
+    Flags.noPreviewDart2,
+    Flags.disableTypeInference
+  ];
   if (enableTypeAssertions) {
     options.add(Flags.enableCheckedMode);
   }
@@ -101,7 +105,7 @@
     int expectedWarnings}) async {
   OutputCollector outputCollector = new OutputCollector();
   DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
-  List<String> options = <String>[];
+  List<String> options = <String>[Flags.noPreviewDart2];
   if (disableInlining) {
     options.add(Flags.disableInlining);
   }
diff --git a/tests/compiler/dart2js/equivalence/id_equivalence_helper.dart b/tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
index 8e9debc..a077442 100644
--- a/tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
+++ b/tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
@@ -577,7 +577,7 @@
       print('--skipped for kernel--------------------------------------------');
     } else {
       print('--from kernel---------------------------------------------------');
-      List<String> options = []..addAll(testOptions);
+      List<String> options = [Flags.noPreviewDart2]..addAll(testOptions);
       if (trustTypeAnnotations) {
         options.add(Flags.trustTypeAnnotations);
       }
diff --git a/tests/compiler/dart2js/equivalence/show_helper.dart b/tests/compiler/dart2js/equivalence/show_helper.dart
index 0cdad7d..b42f560 100644
--- a/tests/compiler/dart2js/equivalence/show_helper.dart
+++ b/tests/compiler/dart2js/equivalence/show_helper.dart
@@ -49,8 +49,8 @@
   }
 
   options = new List<String>.from(options);
-  if (strongMode) {
-    options.add(Flags.strongMode);
+  if (!strongMode) {
+    options.add(Flags.noPreviewDart2);
   }
   if (trustTypeAnnotations) {
     options.add(Flags.trustTypeAnnotations);
diff --git a/tests/compiler/dart2js/inference/list_tracer_test.dart b/tests/compiler/dart2js/inference/list_tracer_test.dart
index 8ee4567..24dcb84 100644
--- a/tests/compiler/dart2js/inference/list_tracer_test.dart
+++ b/tests/compiler/dart2js/inference/list_tracer_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:async_helper/async_helper.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/inferrer/typemasks/masks.dart';
 import 'package:expect/expect.dart';
 
@@ -208,7 +209,9 @@
 
 doTest(String allocation, {bool nullify}) async {
   String source = generateTest(allocation);
-  var result = await runCompiler(memorySourceFiles: {'main.dart': source});
+  var result = await runCompiler(
+      memorySourceFiles: {'main.dart': source},
+      options: [Flags.noPreviewDart2]);
   Expect.isTrue(result.isSuccess);
   var compiler = result.compiler;
   var typesInferrer = compiler.globalInference.typesInferrerInternal;
diff --git a/tests/compiler/dart2js/inference/load_deferred_library_test.dart b/tests/compiler/dart2js/inference/load_deferred_library_test.dart
index 0db1d83..df01c26 100644
--- a/tests/compiler/dart2js/inference/load_deferred_library_test.dart
+++ b/tests/compiler/dart2js/inference/load_deferred_library_test.dart
@@ -30,9 +30,9 @@
 main() async {
   asyncTest(() async {
     print('--test Dart 1 ----------------------------------------------------');
-    await runTest([], trust: false);
+    await runTest([Flags.noPreviewDart2], trust: false);
     print('--test Dart 1 --trust-type-annotations ---------------------------');
-    await runTest([Flags.trustTypeAnnotations]);
+    await runTest([Flags.noPreviewDart2, Flags.trustTypeAnnotations]);
     print('--test Dart 2 ----------------------------------------------------');
     await runTest([Flags.strongMode], trust: false);
     print('--test Dart 2 --omit-implicit-checks -----------------------------');
diff --git a/tests/compiler/dart2js/inference/map_tracer_test.dart b/tests/compiler/dart2js/inference/map_tracer_test.dart
index e383eab..e30eaa8 100644
--- a/tests/compiler/dart2js/inference/map_tracer_test.dart
+++ b/tests/compiler/dart2js/inference/map_tracer_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:async_helper/async_helper.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/compiler.dart';
 import 'package:compiler/src/elements/entities.dart';
 import 'package:compiler/src/inferrer/type_graph_inferrer.dart';
@@ -227,7 +228,9 @@
 doTest(String allocation,
     {String keyElementName, String valueElementName}) async {
   String source = generateTest(allocation);
-  var result = await runCompiler(memorySourceFiles: {'main.dart': source});
+  var result = await runCompiler(
+      memorySourceFiles: {'main.dart': source},
+      options: [Flags.noPreviewDart2]);
   Expect.isTrue(result.isSuccess);
   Compiler compiler = result.compiler;
   TypeMask keyType, valueType;
diff --git a/tests/compiler/dart2js/inference/type_combination_test.dart b/tests/compiler/dart2js/inference/type_combination_test.dart
index 23702fd..4304c1a 100644
--- a/tests/compiler/dart2js/inference/type_combination_test.dart
+++ b/tests/compiler/dart2js/inference/type_combination_test.dart
@@ -4,6 +4,7 @@
 
 import 'package:async_helper/async_helper.dart';
 import 'package:expect/expect.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/common_elements.dart';
 import 'package:compiler/src/compiler.dart';
 import 'package:compiler/src/elements/entities.dart';
@@ -745,8 +746,9 @@
 }
 
 runTests() async {
-  CompilationResult result = await runCompiler(memorySourceFiles: {
-    'main.dart': r'''
+  CompilationResult result = await runCompiler(
+      memorySourceFiles: {
+        'main.dart': r'''
     import 'dart:collection';
     class AList<E> extends ListBase<E> {}
     main() {
@@ -755,7 +757,9 @@
       print('${const []}${const {}}${(){}}${new AList()}');
     }
     '''
-  }, beforeRun: (compiler) => compiler.stopAfterTypeInference = true);
+      },
+      beforeRun: (compiler) => compiler.stopAfterTypeInference = true,
+      options: [Flags.noPreviewDart2]);
   Expect.isTrue(result.isSuccess);
   Compiler compiler = result.compiler;
   JClosedWorld closedWorld = compiler.backendClosedWorldForTesting;
diff --git a/tests/compiler/dart2js/jsinterop/world_test.dart b/tests/compiler/dart2js/jsinterop/world_test.dart
index c47be24..cb9cf2c 100644
--- a/tests/compiler/dart2js/jsinterop/world_test.dart
+++ b/tests/compiler/dart2js/jsinterop/world_test.dart
@@ -6,6 +6,7 @@
 
 import 'package:expect/expect.dart';
 import 'package:async_helper/async_helper.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/common_elements.dart';
 import 'package:compiler/src/compiler.dart';
 import 'package:compiler/src/elements/entities.dart' show ClassEntity;
@@ -18,7 +19,7 @@
 void main() {
   asyncTest(() async {
     print('--test from kernel------------------------------------------------');
-    await testClasses([]);
+    await testClasses([Flags.noPreviewDart2]);
     print('--test from kernel (strong mode)----------------------------------');
     // TODO(johnniwinther): Update the test to be strong mode compliant.
     //await testClasses([Flags.strongMode]);
diff --git a/tests/compiler/dart2js/model/class_set_test.dart b/tests/compiler/dart2js/model/class_set_test.dart
index af328ef..f91acf6 100644
--- a/tests/compiler/dart2js/model/class_set_test.dart
+++ b/tests/compiler/dart2js/model/class_set_test.dart
@@ -601,7 +601,7 @@
         local() {}
       }
       """,
-      options: strongMode ? [Flags.strongMode] : [],
+      options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2],
       testBackendWorld: true);
   JClosedWorld world = env.jClosedWorld;
 
diff --git a/tests/compiler/dart2js/model/constant_expression_evaluate_test.dart b/tests/compiler/dart2js/model/constant_expression_evaluate_test.dart
index c9266c2..885bb45 100644
--- a/tests/compiler/dart2js/model/constant_expression_evaluate_test.dart
+++ b/tests/compiler/dart2js/model/constant_expression_evaluate_test.dart
@@ -671,7 +671,8 @@
   if (!skipKernelList.contains(data.name) && !data.strongModeOnly) {
     print(
         '--test kernel-------------------------------------------------------');
-    await runTest([], (Compiler compiler, FieldEntity field) {
+    await runTest([Flags.noPreviewDart2],
+        (Compiler compiler, FieldEntity field) {
       KernelFrontEndStrategy frontendStrategy = compiler.frontendStrategy;
       KernelToElementMap elementMap = frontendStrategy.elementMap;
       return new KernelEvaluationEnvironment(elementMap, null, field,
diff --git a/tests/compiler/dart2js/model/constant_expression_test.dart b/tests/compiler/dart2js/model/constant_expression_test.dart
index ae5ec8a..901f962 100644
--- a/tests/compiler/dart2js/model/constant_expression_test.dart
+++ b/tests/compiler/dart2js/model/constant_expression_test.dart
@@ -355,7 +355,7 @@
   String source = sb.toString();
   CompilationResult result = await runCompiler(
       memorySourceFiles: {'main.dart': source},
-      options: strongMode ? [Flags.strongMode] : []);
+      options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
   Compiler compiler = result.compiler;
   var elementEnvironment = compiler.frontendStrategy.elementEnvironment;
 
diff --git a/tests/compiler/dart2js/model/strong_mode_closed_world_test.dart b/tests/compiler/dart2js/model/strong_mode_closed_world_test.dart
index 59a8afd7..4a360c9 100644
--- a/tests/compiler/dart2js/model/strong_mode_closed_world_test.dart
+++ b/tests/compiler/dart2js/model/strong_mode_closed_world_test.dart
@@ -140,7 +140,7 @@
   r = new R(); // Create R after call.
 }
 '''
-  }, options: strongMode ? [Flags.strongMode] : []);
+  }, options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
   Expect.isTrue(result.isSuccess);
   Compiler compiler = result.compiler;
 
diff --git a/tests/compiler/dart2js/model/strong_mode_impact_test.dart b/tests/compiler/dart2js/model/strong_mode_impact_test.dart
index 10400b8..908e142 100644
--- a/tests/compiler/dart2js/model/strong_mode_impact_test.dart
+++ b/tests/compiler/dart2js/model/strong_mode_impact_test.dart
@@ -93,7 +93,7 @@
   ImpactCacheDeleter.retainCachesForTesting = true;
   CompilationResult result = await runCompiler(
       memorySourceFiles: {'main.dart': source},
-      options: strongMode ? [Flags.strongMode] : []);
+      options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
   Expect.isTrue(result.isSuccess);
   Compiler compiler = result.compiler;
 
diff --git a/tests/compiler/dart2js/model/subtype_test.dart b/tests/compiler/dart2js/model/subtype_test.dart
index 7a44b77..3f761876 100644
--- a/tests/compiler/dart2js/model/subtype_test.dart
+++ b/tests/compiler/dart2js/model/subtype_test.dart
@@ -59,7 +59,9 @@
       // TODO(johnniwinther): Inheritance with different type arguments is
       // currently not supported by the implementation.
       class C<T1, T2> extends B<T2, T1> /*implements A<A<T1>>*/ {}
-      """, options: strongMode ? [Flags.strongMode] : []).then((env) {
+      """,
+      options:
+          strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S,
         {bool expectMoreSpecific}) {
       testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@@ -311,7 +313,9 @@
         int m4(V v, U u) => null;
         void m5(V v, int i) => null;
       }
-      """, options: strongMode ? [Flags.strongMode] : []).then((env) {
+      """,
+      options:
+          strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S,
         {bool expectMoreSpecific}) {
       testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@@ -361,14 +365,14 @@
 Future testFunctionSubtyping({bool strongMode}) async {
   await TypeEnvironment
       .create(createMethods(functionTypesData),
-          options: strongMode ? [Flags.strongMode] : [])
+          options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
       .then(functionSubtypingHelper);
 }
 
 Future testTypedefSubtyping({bool strongMode}) async {
   await TypeEnvironment
       .create(createTypedefs(functionTypesData),
-          options: strongMode ? [Flags.strongMode] : [])
+          options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
       .then(functionSubtypingHelper);
 }
 
@@ -447,14 +451,14 @@
 Future testFunctionSubtypingOptional({bool strongMode}) async {
   await TypeEnvironment
       .create(createMethods(optionalFunctionTypesData),
-          options: strongMode ? [Flags.strongMode] : [])
+          options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
       .then((env) => functionSubtypingOptionalHelper(env, strongMode));
 }
 
 Future testTypedefSubtypingOptional({bool strongMode}) async {
   await TypeEnvironment
       .create(createTypedefs(optionalFunctionTypesData),
-          options: strongMode ? [Flags.strongMode] : [])
+          options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
       .then((env) => functionSubtypingOptionalHelper(env, strongMode));
 }
 
@@ -521,14 +525,14 @@
 Future testFunctionSubtypingNamed({bool strongMode}) async {
   await TypeEnvironment
       .create(createMethods(namedFunctionTypesData),
-          options: strongMode ? [Flags.strongMode] : [])
+          options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
       .then((env) => functionSubtypingNamedHelper(env, strongMode));
 }
 
 Future testTypedefSubtypingNamed({bool strongMode}) async {
   await TypeEnvironment
       .create(createTypedefs(namedFunctionTypesData),
-          options: strongMode ? [Flags.strongMode] : [])
+          options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
       .then((env) => functionSubtypingNamedHelper(env, strongMode));
 }
 
@@ -580,7 +584,9 @@
       class H<T extends S, S extends T> {}
       class I<T extends S, S extends U, U extends T> {}
       class J<T extends S, S extends U, U extends S> {}
-      """, options: strongMode ? [Flags.strongMode] : []).then((env) {
+      """,
+      options:
+          strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S,
         {bool expectMoreSpecific}) {
       testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@@ -804,7 +810,9 @@
       takeInt(int o) => null;
       takeVoid(void o) => null;
       takeObject(Object o) => null;
-      """, options: strongMode ? [Flags.strongMode] : []).then((env) {
+      """,
+      options:
+          strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S) {
       Expect.equals(expectSubtype, env.isSubtype(T, S), '$T <: $S');
       if (expectSubtype) {
diff --git a/tests/compiler/dart2js/model/subtypeset_test.dart b/tests/compiler/dart2js/model/subtypeset_test.dart
index c48b5bb..fd5e963 100644
--- a/tests/compiler/dart2js/model/subtypeset_test.dart
+++ b/tests/compiler/dart2js/model/subtypeset_test.dart
@@ -51,7 +51,7 @@
         new F();
         new G();
       }
-      """, options: strongMode ? [Flags.strongMode] : []);
+      """, options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
   KClosedWorld world = env.kClosedWorld;
 
   ClassEntity A = env.getElement("A");
diff --git a/tests/compiler/dart2js/needs_no_such_method_test.dart b/tests/compiler/dart2js/needs_no_such_method_test.dart
index 68c216b..5cd35d2 100644
--- a/tests/compiler/dart2js/needs_no_such_method_test.dart
+++ b/tests/compiler/dart2js/needs_no_such_method_test.dart
@@ -5,6 +5,7 @@
 import 'dart:async';
 import 'package:async_helper/async_helper.dart';
 import 'package:expect/expect.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/elements/entities.dart';
 import 'package:compiler/src/elements/names.dart';
 import 'package:compiler/src/universe/call_structure.dart';
@@ -47,7 +48,9 @@
     testMode = '$instantiated';
 
     var env = await TypeEnvironment.create(CLASSES,
-        mainSource: main.toString(), testBackendWorld: true);
+        mainSource: main.toString(),
+        testBackendWorld: true,
+        options: [Flags.noPreviewDart2]);
     foo = new Selector.call(const PublicName('foo'), CallStructure.NO_ARGS);
     bar = new Selector.call(const PublicName('bar'), CallStructure.NO_ARGS);
     baz = new Selector.call(const PublicName('baz'), CallStructure.NO_ARGS);
diff --git a/tests/compiler/dart2js/no_such_method_enabled_test.dart b/tests/compiler/dart2js/no_such_method_enabled_test.dart
index f16b55b..f89588f 100644
--- a/tests/compiler/dart2js/no_such_method_enabled_test.dart
+++ b/tests/compiler/dart2js/no_such_method_enabled_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:async_helper/async_helper.dart';
+import 'package:compiler/src/commandline_options.dart';
 import 'package:compiler/src/common_elements.dart';
 import 'package:compiler/src/compiler.dart';
 import 'package:compiler/src/elements/entities.dart';
@@ -209,8 +210,9 @@
     for (NoSuchMethodTest test in TESTS) {
       print('---- testing -------------------------------------------------');
       print(test.code);
-      CompilationResult result =
-          await runCompiler(memorySourceFiles: {'main.dart': test.code});
+      CompilationResult result = await runCompiler(
+          memorySourceFiles: {'main.dart': test.code},
+          options: [Flags.noPreviewDart2]);
       Compiler compiler = result.compiler;
       checkTest(compiler, test);
     }
diff --git a/tests/compiler/dart2js/rti/disable_rti_test.dart b/tests/compiler/dart2js/rti/disable_rti_test.dart
index a199849..cd7fab0 100644
--- a/tests/compiler/dart2js/rti/disable_rti_test.dart
+++ b/tests/compiler/dart2js/rti/disable_rti_test.dart
@@ -57,9 +57,13 @@
 
 main() {
   runTest() async {
-    CompilationResult result = await runCompiler(
-        memorySourceFiles: {'main.dart': code},
-        options: [Flags.disableRtiOptimization, Flags.disableInlining]);
+    CompilationResult result = await runCompiler(memorySourceFiles: {
+      'main.dart': code
+    }, options: [
+      Flags.noPreviewDart2,
+      Flags.disableRtiOptimization,
+      Flags.disableInlining
+    ]);
     Expect.isTrue(result.isSuccess);
     Compiler compiler = result.compiler;
     JClosedWorld closedWorld = compiler.backendClosedWorldForTesting;
diff --git a/tests/compiler/dart2js/rti/type_representation_test.dart b/tests/compiler/dart2js/rti/type_representation_test.dart
index ffb6fbd..a4a6f9e 100644
--- a/tests/compiler/dart2js/rti/type_representation_test.dart
+++ b/tests/compiler/dart2js/rti/type_representation_test.dart
@@ -67,7 +67,7 @@
 ''';
   CompilationResult result = await runCompiler(
       memorySourceFiles: {'main.dart': source},
-      options: strongMode ? [Flags.strongMode] : []);
+      options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
   Expect.isTrue(result.isSuccess);
   Compiler compiler = result.compiler;
   JavaScriptBackend backend = compiler.backend;
diff --git a/tests/compiler/dart2js/sourcemaps/tools/source_mapping_tester.dart b/tests/compiler/dart2js/sourcemaps/tools/source_mapping_tester.dart
index 4eaf294..6d62f1f3 100644
--- a/tests/compiler/dart2js/sourcemaps/tools/source_mapping_tester.dart
+++ b/tests/compiler/dart2js/sourcemaps/tools/source_mapping_tester.dart
@@ -131,7 +131,7 @@
 }
 
 const Map<String, List<String>> TEST_CONFIGURATIONS = const {
-  'kernel': const [],
+  'kernel': const [Flags.noPreviewDart2],
 };
 
 final Map<String, Uri> TEST_FILES = _computeTestFiles();
diff --git a/tools/testing/dart/test_suite.dart b/tools/testing/dart/test_suite.dart
index 748efd2..84594c8 100644
--- a/tools/testing/dart/test_suite.dart
+++ b/tools/testing/dart/test_suite.dart
@@ -1259,6 +1259,13 @@
     if (options != null) args.addAll(options);
     options = optionsFromFile['dart2jsOptions'] as List<String>;
     if (options != null) args.addAll(options);
+    if (configuration.compiler == Compiler.dart2js) {
+      if (configuration.noPreviewDart2) {
+        args.add("--no-preview-dart-2");
+      } else {
+        args.add("--preview-dart-2");
+      }
+    }
 
     return Command.compilation(Compiler.dart2js.name, outputFile,
         dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides,
@@ -1301,6 +1308,14 @@
       }
     }
 
+    if (configuration.compiler == Compiler.dart2js) {
+      if (configuration.noPreviewDart2) {
+        args.add("--no-preview-dart-2");
+      } else {
+        args.add("--preview-dart-2");
+      }
+    }
+
     var isMultitest = optionsFromFile["isMultitest"] as bool;
     var dartOptions = optionsFromFile["dartOptions"] as List<String>;