Lucas Azzola
e78e07e2ad
refactor(multiparser): move css expression doc printing to transformCssDoc ( #2214 )
2017-06-21 13:41:24 -07:00
Joseph Frazier
69808cebfb
Format JSON literals like object literals ( #2181 )
...
* Format JSON literals like object literals
Following up on commit a42db30 (https://github.com/prettier/prettier/issues/2173 ),
this change makes it so that literals in JSON files are formatted as
they would be in an object literal. This normalizes trailing zeroes,
exponential notation, unnecessarily escaped characters, etc.
It works by using babylon to parse literals as expressions, and putting
the result in the AST instead of a `json-literal` node. Since JSON
string literals have to be double-quoted, there's a new
`__prettier__isJson` flag on each node, which is used by the printer to
force double-quotes.
* json: Check options.parser when formatting StringLiteral
This is instead of having a custom AST property. See
https://github.com/prettier/prettier/pull/2181#discussion_r122578251
* multiparser: Use babylon.parseExpression
See https://github.com/prettier/prettier/pull/2181#discussion_r122578354
* json: Don't split result AST node into two
See https://github.com/prettier/prettier/pull/2181#discussion_r122578499
* json: Don't use babylon parser to build expression nodes
See https://github.com/prettier/prettier/pull/2181#discussion_r122579052
* Revert "multiparser: Use babylon.parseExpression"
This reverts commit 3d7a4362880d39fac0cea88b5d0186a29538cf6f.
* Remove unused parameter from babylon parser
* json: Remove unused constructorTypes
2017-06-17 20:49:22 -04:00
Joseph Frazier
a42db30946
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
2017-06-17 10:36:42 -10:00
Lucas Azzola
c669a1db72
TypeScript: group function params in call/construct signatures, fixes #2163 ( #2169 )
2017-06-17 12:09:18 +10:00
Stephen Wan
a005211c96
Fix extra semicolon in ambient typescript declaration emit ( #2165 ) ( #2167 )
...
* fix(typescript): add failing ambient declaration test
* fix(typescript): fix failing test case for ambient function exports
2017-06-16 08:20:59 -10:00
Lucas Azzola
7e60d70f97
fix(typescript): always break interfaces onto multiple lines, fixes #2159 ( #2161 )
2017-06-15 14:34:54 -10:00
Lucas Azzola
9e7b02d50e
Print {} in import if it's in the source, fixes #2145 ( #2150 )
2017-06-15 20:19:01 +10:00
Lucas Azzola
b7e1c366e0
Vue: pretty-print binding syntax ( #2108 )
...
* feat(vue): pretty-print :class attributes
* feat(vue): switch to brand new custom parser API! 🎉
* refactor(vue): move AST manipulation to post-parse
2017-06-14 22:33:15 +10:00
Christopher Chedeau
abfdbe1896
Upgrade typescript to 2.4 ( #2120 )
...
Fixes #2117
2017-06-13 09:47:40 -07:00
Rodrigo Pombo
8dd0cb2a05
Format CSS in template literals with expressions ( #2102 )
...
* Add support for styled-jsx with expressions
* Lint
* Fix require for Node 4
* Re-create template-literal document when replacing placeholders
* Add support for styled-components with expressions
* Fix merge
* Move css library detection to functions
2017-06-13 09:45:16 -07:00
Lucas Azzola
fbf9064090
refactor(multiparser): move some logic from printer.js to multiparser.js ( #2109 )
2017-06-12 08:06:41 -07:00
Lucas Azzola
486a89bfdc
fix(typescript): workaround - don't wrap directives in parens, fixes #2074 ( #2107 )
2017-06-11 19:10:56 -07:00
Lucas Azzola
e8f12cf621
TypeScript: Remove parens from type annotations where possible ( #2098 )
...
* fix(typescript): remove parens from union types where possible, fixes #1885
* fix(typescript): ensure parenthesis removal is stable
* fix(typescript): don't strip parens around function type
2017-06-11 18:06:47 -07:00
Lucas Azzola
9c608d2ec1
fix(typescript): use printFunctionParams for call/construct signature, fixes #2105 ( #2106 )
2017-06-11 16:06:38 -07:00
Lucas Azzola
ec7d99439d
fix(typescript): print arrow function type params on same line as params, fixes #2099 ( #2101 )
2017-06-11 07:30:51 -07:00
Lucas Azzola
4395e09b78
fix(import): allow break with both default named import, fixes #2050 ( #2096 )
2017-06-10 21:55:21 -07:00
Lucas Azzola
a79a444bac
fix(variable-declarator): indent first variable in one-var scenario, fixes #2072 ( #2095 )
2017-06-10 21:19:50 -07:00
Lucas Azzola
d1b94c540c
Implement parser switching (HTML, Vue, styled-components) ( #2086 )
...
* feat(multiparser): implement switching from html -> css,js,ts
* feat(multiparser): use quasi value instead of originalText
2017-06-10 08:03:39 -07:00
Lucas Azzola
77f0c05d2a
fix(method-chain): break on non-literal computed member expression, fixes #2075 ( #2087 )
2017-06-10 07:47:22 -07:00
Lucas Azzola
1e08f03554
fix(typescript): break on multiple interface extends, fixes #2043 ( #2085 )
2017-06-10 07:46:59 -07:00
Lucas Azzola
d00956d51d
feat(html): add parse5/htmlparser2 printer ( #2083 )
2017-06-09 19:22:59 -07:00
Christopher Chedeau
f399e90bc2
Preserve lines after directives ( #2070 )
...
Looks like we were only doing it at the top level, we should do it everywhere.
Fixes #2067
2017-06-08 17:10:01 -07:00
Christopher Chedeau
939734b75e
Use ifBreak instead of shouldBreak ( #2063 )
...
shouldBreak is only a heuristic to enforce a break, if it breaks "naturally", then it won't be applied.
Fixes #2055
2017-06-08 11:47:49 -07:00
Christopher Chedeau
883e637fa9
Support the Keyword type ( #2056 )
...
This is an issue in https://github.com/eslint/typescript-eslint-parser/issues/315
Fixes #2049
2017-06-08 09:25:28 -07:00
Christopher Chedeau
924363193b
Check if the next group has comments ( #2040 )
...
Fixes #1958
Fixes #1959
2017-06-07 15:20:11 -07:00
Christopher Chedeau
b730f4eccf
Add group around TSMethodSignature ( #2037 )
...
This ensures that the comment size is not taken into account during measurement
Fixes #1976
2017-06-07 14:20:55 -07:00
Christopher Chedeau
ccda4c7115
Break decorator before content ( #2032 )
...
Fixes #1996
2017-06-07 12:40:47 -07:00
Christopher Chedeau
c7cacf0529
Break if string | null ( #2028 )
...
We were a bit too aggressive around the `| null` heuristic.
Fixes #2002
2017-06-07 11:51:32 -07:00
Christopher Chedeau
c9c8512170
Only prevent lone set if there's no type annotations ( #2026 )
...
If there are, it's not ambiguous.
Fixes #2023
2017-06-07 11:51:25 -07:00
Christopher Chedeau
5ba0b0ec87
Add semi for functions without body ( #2025 )
...
We don't need to be overly restrictive and should add the semi if there's no body
Fixes #2003
2017-06-07 11:51:17 -07:00
Joseph Frazier
b20437ad13
Use printStatementSequence() to print SwitchCase consequent ( #2011 )
...
I noticed the duplicated code while working on commit 0cfd772
(https://github.com/prettier/prettier/pull/2008 )
2017-06-06 14:58:20 -07:00
Joseph Frazier
0cfd772fd2
Protect SwitchCase statements from ASI ( #2008 )
...
* Add no-semi test with SequenceExpression
Adapted from https://github.com/prettier/prettier/issues/2006
* Protect SequenceExpressions from ASI
Fixes https://github.com/prettier/prettier/issues/2006
* Add test for ASI protection of SequenceExpression outside SwitchCase
See https://github.com/prettier/prettier/pull/2008#issuecomment-306614217
* Revert "Protect SequenceExpressions from ASI"
This reverts commit ca644fad8072c90a977ad8a2f29674bc72f679e8.
* Protect SwitchCase statements from ASI
See https://github.com/prettier/prettier/pull/2008#issuecomment-306614217
Fixes https://github.com/prettier/prettier/issues/2006
2017-06-06 14:28:51 -07:00
Rodrigo Pombo
d4774edd03
Parse CSS in template literals (styled-jsx) ( #1984 )
...
* Add basic styled-jsx parsing
* Use eval("require")
* Remove template literal raw and cooked values when it contains CSS
* Set postcss parser to options and group subtree parts
* Gracefully give up TemplateLiteral formatting when it fails
2017-06-06 08:28:13 -07:00
Joseph Frazier
d9e4d8f1b8
Remove unnecessary 'else' after 'return' ( #1987 )
...
As mentioned in at the end of
https://github.com/prettier/prettier/pull/1983/files#r120222081
2017-06-05 15:12:59 -07:00
Karl O'Keeffe
73432c2ce7
Position JSX whitespace ({" "}) at the end of lines ( #1964 )
...
* Position JSX whitespace at the end of lines
Currently we place JSX whitespace at the beginning of lines.
* Use `isLiteral` when determining JSX whitespace
2017-06-05 21:52:54 +01:00
Jon Wong
e33d6773d6
Adding support for graphql ( #1982 )
...
* Initial GraphQL implementation
This is the bare minimum amount of code to make graphql work. Turns out it's pretty easy to add support for other languages :)
* Fixing support for `graphql` parsing
There was a few structural changes with the addition of CSS and Typescript that we had to take into account.
* Fixing file glob, adding `graphql` to yarn.lock
* Removing extraneous file
* Adding `graphql` parser, style changes
* Splitting out graphql printer
* Removing merge conflict
* Fixing yarn.lock
* Addressing code review, using `createError`
* Adding release config
* Using exact version
* Removing destructuring
2017-06-05 12:34:08 -07:00
Lucas Azzola
31ab3b6036
feat(css): split postcss printer into separate file ( #1969 )
2017-06-05 07:28:38 -07:00
Lucas Azzola
642ac7e230
fix(typescript): print semi in class index signatures, fixes #1960 ( #1961 )
2017-06-04 07:21:33 -07:00
Lucas Azzola
6697122e28
fix(decorators): do not inline methods with decorators with babylon, fixes #1933 ( #1934 )
2017-06-03 05:24:24 -07:00
Lucas Azzola
649cec7fdd
TypeScript: fix trailing comma in enum ( #1938 )
...
* fix(typescript): fix trailing comma in enum, fixes #1932
* fix(typescript): use --trailing-comma es5 for enums
2017-06-03 05:20:36 -07:00
Lucas Azzola
c57f2ab507
fix(typescript): no semi after export default abstract class, fixes #1926 ( #1937 )
2017-06-03 05:19:39 -07:00
Lucas Azzola
2ef169eb67
fix(typescript): print semi with inline interfaces/types, fixes #1930 ( #1936 )
2017-06-03 05:18:59 -07:00
Christopher Chedeau
dae7203be6
Fix As parenthesis for real ( #1923 )
...
Instead of doing it inside of object, we need to have them use the existing mechanism that checks if the left-most character is a paren.
2017-06-02 16:08:45 -07:00
Christopher Chedeau
3264da9cab
Fix leading comment ( #1920 )
...
It turns out that leading comment is attached to the CallExpression which is the last one and not the first one if they fit in a single line, so we want to not check that one.
Fixes #1892
2017-06-02 15:50:43 -07:00
Christopher Chedeau
323d64fb84
Port intersection inlining logic to TypeScript ( #1919 )
...
Fixes #1880
2017-06-02 15:40:33 -07:00
Christopher Chedeau
0d239477cb
Use semi-colon for object separator ( #1918 )
...
Looks like the convention for typescript separator is `;` whereas for flow it's `,`. Let's migrate to that.
Fixes #1896
Fixes #1879
Fixes #1874
2017-06-02 15:32:51 -07:00
Christopher Chedeau
2f9ea794db
Always expand enums ( #1914 )
...
We do the same for classes, and it's usually written that way even if it fits in one line, even in the TS docs: https://www.typescriptlang.org/docs/handbook/enums.html
Fixes #1873
2017-06-02 15:09:55 -07:00
Christopher Chedeau
a255977009
Do not make variable multilines inside of for loop ( #1912 )
...
Fixes #1876
2017-06-02 15:00:16 -07:00
Christopher Chedeau
e58dd2bf0b
Add semi for ts function declarations without body ( #1911 )
...
Fixes #1891
2017-06-02 14:49:37 -07:00
Christopher Chedeau
6933d16125
Inline decorators with no arguments ( #1910 )
...
Fixes #1898
2017-06-02 14:40:39 -07:00