Allow dart2js to compile with the CFE. (#1822)

Adds support for using the common front-end in the dart2js transformer
diff --git a/lib/src/barback/dart2js_transformer.dart b/lib/src/barback/dart2js_transformer.dart
index 28c976a..e9678ff 100644
--- a/lib/src/barback/dart2js_transformer.dart
+++ b/lib/src/barback/dart2js_transformer.dart
@@ -6,6 +6,7 @@
 import 'dart:convert';
 
 import 'package:analyzer/analyzer.dart';
+import 'package:async/async.dart';
 import 'package:barback/barback.dart';
 import 'package:collection/collection.dart';
 import 'package:path/path.dart' as p;
@@ -161,7 +162,8 @@
         suppressPackageWarnings:
             _configBool('suppressPackageWarnings', defaultsTo: true),
         terse: _configBool('terse'),
-        includeSourceMapUrls: _generateSourceMaps);
+        includeSourceMapUrls: _generateSourceMaps,
+        platformBinaries: provider.libraryRoot.resolve('lib/_internal/').path);
   }
 
   /// Parses and returns the "commandLineOptions" configuration option.
@@ -280,7 +282,7 @@
   }
 
   /// A [CompilerInputProvider] for dart2js.
-  Future<String> provideInput(Uri resourceUri) {
+  Future /* <String | List<int>> */ provideInput(Uri resourceUri) {
     // We only expect to get absolute "file:" URLs from dart2js.
     assert(resourceUri.isAbsolute);
     assert(resourceUri.scheme == "file");
@@ -391,11 +393,17 @@
     }
   }
 
-  Future<String> _readResource(Uri url) {
+  Future _readResource(Uri url) {
     return new Future.sync(() {
       // Find the corresponding asset in barback.
       var id = _sourceUrlToId(url);
-      if (id != null) return _transform.readInputAsString(id);
+      if (id != null) {
+        if (id.extension == '.dill') {
+          return collectBytes(_transform.readInput(id));
+        } else {
+          return _transform.readInputAsString(id);
+        }
+      }
 
       // Don't allow arbitrary file paths that point to things not in packages.
       // Doing so won't work in Dartium.
diff --git a/lib/src/barback/pub_package_provider.dart b/lib/src/barback/pub_package_provider.dart
index 482bf05..66cbcb2 100644
--- a/lib/src/barback/pub_package_provider.dart
+++ b/lib/src/barback/pub_package_provider.dart
@@ -75,8 +75,9 @@
     }
 
     // "$sdk" is a pseudo-package that provides access to the Dart library
-    // sources in the SDK. The dart2js transformer uses this to locate the Dart
-    // sources for "dart:" libraries.
+    // sources and kernel .dill files in the SDK. The dart2js transformer uses
+    // this to locate the Dart sources for "dart:" libraries and the
+    // dart2js_platform.dill files.
     if (id.package == r'$sdk') {
       // The asset path contains two "lib" entries. The first represents pub's
       // concept that all public assets are in "lib". The second comes from the
@@ -147,8 +148,10 @@
           files = files.map((file) => file.replaceAll(trailingUnderscore, ""));
         }
 
-        return new Stream.fromIterable(
-            files.where((file) => p.extension(file) == ".dart").map((file) {
+        return new Stream.fromIterable(files
+            .where((file) =>
+                p.extension(file) == '.dart' || p.extension(file) == '.dill')
+            .map((file) {
           var idPath = p.join("lib", "lib", p.relative(file, from: libPath));
           return new AssetId('\$sdk', p.toUri(idPath).toString());
         }));
diff --git a/lib/src/dart.dart b/lib/src/dart.dart
index c5d236d..2dec254 100644
--- a/lib/src/dart.dart
+++ b/lib/src/dart.dart
@@ -68,7 +68,8 @@
     bool suppressPackageWarnings: true,
     bool terse: false,
     bool includeSourceMapUrls: false,
-    bool toDart: false}) async {
+    bool toDart: false,
+    String platformBinaries}) async {
   // dart2js chokes on relative paths. Including "/./" can also confuse it, so
   // we normalize as well.
   entrypoint = p.normalize(p.absolute(entrypoint));
@@ -85,6 +86,9 @@
   if (!suppressPackageWarnings) options.add('--show-package-warnings');
   if (terse) options.add('--terse');
   if (toDart) options.add('--output-type=dart');
+  if (platformBinaries != null) {
+    options.add('--platform-binaries=$platformBinaries');
+  }
 
   var sourceUrl = p.toUri(entrypoint);
   options.add("--out=$sourceUrl.js");