Merge pull request #473 from RedBrogdon/newflutter

Updates flutter commit to latest dev channel
diff --git a/Dockerfile b/Dockerfile
index 037148a..7c45a23 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,7 +4,7 @@
 # The specific commit that dart-services should use. This should be kept
 # in sync with the flutter submodule in the dart-services repo.
 # (run `git rev-parse HEAD` from the flutter submodule to retrieve this value.
-ARG FLUTTER_COMMIT=fbabb264e0ab3e090d6ec056e0744aaeb1586735
+ARG FLUTTER_COMMIT=4af66e335f8d87da5cb8c7f2a3e89c1ee02ef23b
 
 # We install unzip and remove the apt-index again to keep the
 # docker image diff small.
diff --git a/flutter b/flutter
index fbabb26..4af66e3 160000
--- a/flutter
+++ b/flutter
@@ -1 +1 @@
-Subproject commit fbabb264e0ab3e090d6ec056e0744aaeb1586735
+Subproject commit 4af66e335f8d87da5cb8c7f2a3e89c1ee02ef23b
diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart
index b2898814..8227bb2 100644
--- a/lib/src/compiler.dart
+++ b/lib/src/compiler.dart
@@ -139,14 +139,12 @@
       List<String> arguments = <String>[
         '--modules=amd',
         if (usingFlutter) ...[
-          '-k',
           '-s',
           _flutterWebManager.summaryFilePath,
           '-s',
           '${_flutterSdk.flutterBinPath}/cache/flutter_web_sdk/flutter_web_sdk/kernel/flutter_ddc_sdk.dill'
         ],
         ...['-o', path.join(temp.path, '$kMainDart.js')],
-        '--single-out-file',
         ...['--module-name', 'dartpad_main'],
         bootstrapPath,
         '--packages=${_flutterWebManager.packagesFilePath}',
@@ -157,16 +155,25 @@
       _logger.info('About to exec "$_dartdevcPath ${arguments.join(' ')}"');
       _logger.info('Compiling: $input');
 
-      final WorkResponse response = await _ddcDriver
-          .doWork(WorkRequest()..arguments.addAll(arguments));
+      final WorkResponse response =
+          await _ddcDriver.doWork(WorkRequest()..arguments.addAll(arguments));
 
       if (response.exitCode != 0) {
         return DDCCompilationResults.failed(<CompilationProblem>[
           CompilationProblem._(response.output),
         ]);
       } else {
+        // The `--single-out-file` option for dartdevc was removed in v2.7.0. As
+        // a result, the JS code produced above does *not* provide a name for
+        // the module it contains. That's a problem for DartPad, since it's
+        // adding the code to a script tag in an iframe rather than loading it
+        // as an individual file from baseURL. As a workaround, this replace
+        // statement injects a name into the module definition.
+        final processedJs = (await mainJs.readAsString())
+            .replaceFirst("define([", "define('dartpad_main', [");
+
         final DDCCompilationResults results = DDCCompilationResults(
-          compiledJS: await mainJs.readAsString(),
+          compiledJS: processedJs,
           modulesBaseUrl: 'https://storage.googleapis.com/'
               'compilation_artifacts/${_flutterSdk.versionFull}/',
         );
diff --git a/pubspec.lock b/pubspec.lock
index 768dd62..afdc9dc 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -28,7 +28,7 @@
       name: appengine
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.10.3"
+    version: "0.10.4"
   args:
     dependency: "direct main"
     description:
@@ -525,7 +525,7 @@
       name: vm_service
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.1.3"
+    version: "2.1.4"
   watcher:
     dependency: transitive
     description:
diff --git a/test/compiler_test.dart b/test/compiler_test.dart
index a9afa97..00dde04 100644
--- a/test/compiler_test.dart
+++ b/test/compiler_test.dart
@@ -99,7 +99,7 @@
         expect(result.success, false);
         expect(result.problems.length, 1);
         expect(result.problems[0].toString(),
-            contains('[error] Expected to find \';\'.'));
+            contains('Error: Expected \';\' after this.'));
       });
     });
 
@@ -110,11 +110,11 @@
         expect(result.success, false);
         expect(result.problems.length, 1);
         expect(result.problems[0].toString(),
-            contains('[error] The function \'print1\' isn\'t defined.'));
+            contains('Error: Method not found: \'print1\'.'));
         expect(result.problems[0].toString(),
-            contains('[error] The function \'print2\' isn\'t defined.'));
+            contains('Error: Method not found: \'print2\'.'));
         expect(result.problems[0].toString(),
-            contains('[error] The function \'print3\' isn\'t defined.'));
+            contains('Error: Method not found: \'print3\'.'));
       });
     });
 
diff --git a/tool/grind.dart b/tool/grind.dart
index 6d93daa..c058294 100644
--- a/tool/grind.dart
+++ b/tool/grind.dart
@@ -155,7 +155,7 @@
   );
 
   // Build the artifacts using DDC:
-  // dart-sdk/bin/dartdevc -k -s kernel/flutter_ddc_sdk.dill
+  // dart-sdk/bin/dartdevc -s kernel/flutter_ddc_sdk.dill
   //     --modules=amd package:flutter_web/animation.dart ...
   final compilerPath =
       path.join(flutterSdkPath.path, 'bin/cache/dart-sdk/bin/dartdevc');
@@ -163,7 +163,6 @@
       'bin/cache/flutter_web_sdk/flutter_web_sdk/kernel/flutter_ddc_sdk.dill');
 
   var args = [
-    '-k',
     '-s',
     dillPath,
     '--modules=amd',
@@ -197,6 +196,47 @@
 }
 
 @Task()
+void setupFlutterSubmodule() {
+  final flutterDir = Directory('flutter');
+
+  // Remove all files currently in the submodule. This is done to clear any
+  // internal state the Flutter/Dart SDKs may have created on their own.
+  flutterDir.listSync().forEach((e) => e.deleteSync(recursive: true));
+
+  // Pull clean files into the submodule, based on whatever commit it's set to.
+  run(
+    'git',
+    arguments: ['submodule', 'update'],
+  );
+
+  // Set up the submodule's copy of the Flutter SDK the way dart-services needs
+  // it.
+  run(
+    path.join(flutterDir.path, 'bin/flutter'),
+    arguments: ['doctor'],
+  );
+
+  run(
+    path.join(flutterDir.path, 'bin/flutter'),
+    arguments: ['config', '--enable-web'],
+  );
+
+  run(
+    path.join(flutterDir.path, 'bin/flutter'),
+    arguments: [
+      'precache',
+      '--web',
+      '--no-android',
+      '--no-ios',
+      '--no-linux',
+      '--no-windows',
+      '--no-macos',
+      '--no-fuchsia',
+    ],
+  );
+}
+
+@Task()
 void fuzz() {
   log('warning: fuzz testing is a noop, see #301');
 }