forked from dart-lang/dart_style
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support deploying an npm package exporting a formatCode method.
BUG= [email protected] Review URL: https://codereview.chromium.org//1640023002 .
- Loading branch information
Showing
6 changed files
with
120 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Type definitions for dart-style | ||
|
||
interface FormatResult { | ||
code?: string; | ||
error?: string; | ||
} | ||
|
||
export function formatCode(code: string): FormatResult; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: dart_style | ||
version: 0.2.4 | ||
version: 0.2.6 | ||
author: Dart Team <[email protected]> | ||
description: Opinionated, automatic Dart source code formatter. | ||
homepage: https://github.com/dart-lang/dart_style | ||
|
@@ -10,10 +10,13 @@ dependencies: | |
args: '>=0.12.1 <0.14.0' | ||
path: '>=1.0.0 <2.0.0' | ||
source_span: '>=1.1.1 <2.0.0' | ||
|
||
dev_dependencies: | ||
async: '>=1.0.0 <=2.0.0' | ||
browser: '>=0.10.0 <0.11.0' | ||
grinder: '^0.7.2' | ||
grinder: '^0.8.0' | ||
js: ^0.6.0 | ||
node_preamble: ^1.0.0 | ||
pub_semver: '^1.2.3' | ||
scheduled_test: '>=0.12.0 <0.13.0' | ||
test: '>=0.12.0 <0.13.0' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
}); | ||
} |