Index: bin/node_format_service.dart |
diff --git a/bin/node_format_service.dart b/bin/node_format_service.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..01970f20fd8ecfbf4b246e761fbc9c4ec84572d8 |
--- /dev/null |
+++ b/bin/node_format_service.dart |
@@ -0,0 +1,41 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
Bob Nystrom
2016/01/27 20:37:13
bin/ isn't the right place for this since it's not
Jacob
2016/01/27 20:56:32
Done.
|
+// 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. |
+ |
+import 'dart:html'; |
+import 'dart:js'; |
+import 'package:js/js.dart'; |
+ |
+import 'package:dart_style/dart_style.dart'; |
+ |
+int width = 80; |
Bob Nystrom
2016/01/27 20:37:13
Is this part of the public API, or just a constant
Jacob
2016/01/27 20:56:32
Done.
Was going to make it part of the api but it
|
+ |
+@JS() |
+@anonymous |
+class FormatResult { |
+ external factory FormatResult({String code, String error}); |
+ external String get code; |
+ external String get error; |
+} |
+ |
+@JS('exports.formatCode') |
+external set formatCode(Function formatter); |
+ |
+void main() { |
+ formatCode = allowInterop((String source) { |
+ try { |
+ return new FormatResult( |
+ code: new DartFormatter(pageWidth: width).format(source)); |
Bob Nystrom
2016/01/27 20:37:13
My little web script isn't a good example. How abo
Jacob
2016/01/27 20:56:32
Done.
|
+ } on FormatterException { |
+ // Do nothing. |
+ } |
+ |
+ // Maybe it's a statement. |
+ try { |
+ return new FormatResult( |
+ code: new DartFormatter(pageWidth: width).formatStatement(source)); |
+ } on FormatterException catch (err) { |
+ return new FormatResult(code: source, error: "$err"); |
+ } |
+ }); |
+} |