Add JSON support (#2173)
* Add JSON support This fixes https://github.com/prettier/prettier/issues/1973 by using [json-to-ast] to parse JSON, then converting the AST into a mostly-Babylon AST, so as to piggyback on the existing printer logic. Identifiers and literals are currently printed verbatim from the input, but this could be improved upon later (at least for literals, not sure about identifiers). [json-to-ast]: https://github.com/vtrushin/json-to-ast * Rename `json-to-ast` parser to `json` See https://github.com/prettier/prettier/pull/2173#discussion_r122574644 * json: Use createError to have a pretty error See https://github.com/prettier/prettier/pull/2173#discussion_r122574748 * json: Transform AST without mutations See https://github.com/prettier/prettier/pull/2173#discussion_r122574690
This commit is contained in:
1 parent
59a294fcc9
commit
a42db30946
13 files changed
+281
-2
No files matched your search
+1
-1
@@ -231,7 +231,7 @@ if (argv["help"] || (!filepatterns.length && !stdin)) {
|
||||
" --jsx-bracket-same-line Put > on the last line instead of at a new line.\n" +
|
||||
" --trailing-comma <none|es5|all>\n" +
|
||||
" Print trailing commas wherever possible. Defaults to none.\n" +
|
||||
" --parser <flow|babylon|typescript|postcss>\n" +
|
||||
" --parser <flow|babylon|typescript|postcss|json>\n" +
|
||||
" Specify which parse to use. Defaults to babylon.\n" +
|
||||
" --cursor-offset <int> Print (to stderr) where a cursor at the given position would move to after formatting.\n" +
|
||||
" This option cannot be used with --range-start and --range-end\n" +
|
||||
|
||||
Reference in new issue
Block a user