OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:js/js.dart'; |
| 6 |
| 7 import 'package:dart_style/dart_style.dart'; |
| 8 |
| 9 @JS() |
| 10 @anonymous |
| 11 class FormatResult { |
| 12 external factory FormatResult({String code, String error}); |
| 13 external String get code; |
| 14 external String get error; |
| 15 } |
| 16 |
| 17 @JS('exports.formatCode') |
| 18 external set formatCode(Function formatter); |
| 19 |
| 20 void main() { |
| 21 formatCode = allowInterop((String source) { |
| 22 var formatter = new DartFormatter(); |
| 23 try { |
| 24 return new FormatResult( |
| 25 code: new DartFormatter().format(source)); |
| 26 } on FormatterException { |
| 27 // Do nothing. |
| 28 } |
| 29 |
| 30 // Maybe it's a statement. |
| 31 try { |
| 32 return new FormatResult( |
| 33 code: formatter.formatStatement(source)); |
| 34 } on FormatterException catch (err) { |
| 35 return new FormatResult(code: source, error: "$err"); |
| 36 } |
| 37 }); |
| 38 } |
OLD | NEW |