Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1255)

Unified Diff: tool/node_format_service.dart

Issue 1640023002: Support deploying an npm package exporting a formatCode method. (Closed) Base URL: git@github.com:dart-lang/dart_style.git@master
Patch Set: ptal Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tool/grind.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/node_format_service.dart
diff --git a/tool/node_format_service.dart b/tool/node_format_service.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3af071b8cbce6967228234895537bcfa14dc8a0c
--- /dev/null
+++ b/tool/node_format_service.dart
@@ -0,0 +1,38 @@
+// 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.
+
+import 'package:js/js.dart';
+
+import 'package:dart_style/dart_style.dart';
+
+@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) {
+ var formatter = new DartFormatter();
+ try {
+ return new FormatResult(
+ code: new DartFormatter().format(source));
+ } on FormatterException {
+ // Do nothing.
+ }
+
+ // Maybe it's a statement.
+ try {
+ return new FormatResult(
+ code: formatter.formatStatement(source));
+ } on FormatterException catch (err) {
+ return new FormatResult(code: source, error: "$err");
+ }
+ });
+}
« no previous file with comments | « tool/grind.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698