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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« 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