Files
sdk/pkg/dev_compiler/web/main.dart
T
Jenny Messerly 1ef4399df0 Run dartfmt --fix for dart2 on pkg/dev_compiler
This uses optional new/const and `=` in named argument defaults.

All changes are automated, except for:

- utils/dartdevc/BUILD.gn: run DDC build scripts with --preview-dart-2
- pkg/dev_compiler/tool/patch_sdk.dart: add a TODO that Analyzer doesn't
  supporting implicit const in libraries.dart
- pkg/dev_compiler/tool/input_sdk/libraries.dart: was not formatted due
  to the aforementioned Analyzer bug
- tools/bots/test_matrix.json: run DDC sourcemap suite in Dart 2 mode
- pkg/pkg.status: skip pkg/dev_compiler if running in Dart 1 mode

Change-Id: I9b80ccba0c2cc7b66efc662a0b16562e3660aee3
Reviewed-on: https://dart-review.googlesource.com/60402
Commit-Queue: Jenny Messerly <jmesserly@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2018-06-15 00:28:13 +00:00

87 lines
3.0 KiB
Dart
Executable File

#!/usr/bin/env dart
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@JS()
library dev_compiler.web.main;
import 'dart:async';
import 'package:args/command_runner.dart';
import 'package:js/js.dart';
import 'web_command.dart';
@JS(r'$setUpDartDevCompilerInBrowser')
external set setUpCompilerInBrowser(Function function);
Future<Function> _setUpCompilerInBrowser;
main() {
var args = ['compile', '--repl-compile'];
// Avoid race condition when users try to call $setUpDartDevCompilerInBrowser
// before it is ready by installing the method immediately and making the body
// of the method async.
setUpCompilerInBrowser = allowInterop((String sdkUrl,
JSMap<String, String> summaryMap,
Function onCompileReady,
Function onError,
[Function onProgress]) async {
(await _setUpCompilerInBrowser)(
sdkUrl, summaryMap, onCompileReady, onError, onProgress);
});
_runCommand(args);
}
/// Runs a single compile command, and returns an exit code.
_runCommand(List<String> args, {MessageHandler messageHandler}) {
try {
// TODO: Remove CommandRunner and args if possible. May run into issues
// with ArgResults or ArgParsers.
var runner = CommandRunner('dartdevc', 'Dart Development Compiler');
runner.addCommand(WebCompileCommand(messageHandler: messageHandler));
_setUpCompilerInBrowser = runner.run(args) as Future<Function>;
} catch (e, s) {
_handleError(e, s, args, messageHandler: messageHandler);
}
}
/// Handles [error] in a uniform fashion. Calls [messageHandler] with messages.
_handleError(dynamic error, dynamic stackTrace, List<String> args,
{MessageHandler messageHandler}) {
messageHandler ??= print;
if (error is UsageException) {
// Incorrect usage, input file not found, etc.
messageHandler(error);
} else if (error is CompileErrorException) {
// Code has error(s) and failed to compile.
messageHandler(error);
} else {
// Anything else is likely a compiler bug.
//
// --unsafe-force-compile is a bit of a grey area, but it's nice not to
// crash while compiling
// (of course, output code may crash, if it had errors).
//
messageHandler("");
messageHandler("We're sorry, you've found a bug in our compiler.");
messageHandler("You can report this bug at:");
messageHandler(
" https://github.com/dart-lang/sdk/issues/labels/area-dev-compiler");
messageHandler("");
messageHandler(
"Please include the information below in your report, along with");
messageHandler(
"any other information that may help us track it down. Thanks!");
messageHandler("");
messageHandler(" dartdevc arguments: " + args.join(' '));
messageHandler("");
messageHandler("```");
messageHandler(error);
messageHandler(stackTrace);
messageHandler("```");
}
}