OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
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 'dart:html'; | |
6 import 'dart:js'; | |
7 import 'package:js/js.dart'; | |
8 | |
9 import 'package:dart_style/dart_style.dart'; | |
10 | |
11 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
| |
12 | |
13 @JS() | |
14 @anonymous | |
15 class FormatResult { | |
16 external factory FormatResult({String code, String error}); | |
17 external String get code; | |
18 external String get error; | |
19 } | |
20 | |
21 @JS('exports.formatCode') | |
22 external set formatCode(Function formatter); | |
23 | |
24 void main() { | |
25 formatCode = allowInterop((String source) { | |
26 try { | |
27 return new FormatResult( | |
28 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.
| |
29 } on FormatterException { | |
30 // Do nothing. | |
31 } | |
32 | |
33 // Maybe it's a statement. | |
34 try { | |
35 return new FormatResult( | |
36 code: new DartFormatter(pageWidth: width).formatStatement(source)); | |
37 } on FormatterException catch (err) { | |
38 return new FormatResult(code: source, error: "$err"); | |
39 } | |
40 }); | |
41 } | |
OLD | NEW |