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

Unified Diff: bin/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: 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 | « CHANGELOG.md ('k') | dist/dart-style.d.ts » ('j') | tool/grind.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
+ }
+ });
+}
« no previous file with comments | « CHANGELOG.md ('k') | dist/dart-style.d.ts » ('j') | tool/grind.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698