Prevent parens around BindExpressions as properties of MemberExpressions (#6159)

master
Lucas Duailibe 2019-05-27 13:58:26 -03:00 committed by GitHub
parent dcf4c21171
commit f8875c1caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View File

@ -399,6 +399,20 @@ new a::b();
new (a::b)();
```
### JavaScript: Prevent adding unnecessary parentheses around bind expressions in member expressions' properties ([#6159] by [@duailibe])
<!-- prettier-ignore -->
```js
// Input
f[a::b];
// Output (Prettier stable)
f[(a::b)];
// Output (Prettier master);
f[a::b];
```
[#5979]: https://github.com/prettier/prettier/pull/5979
[#6086]: https://github.com/prettier/prettier/pull/6086
[#6088]: https://github.com/prettier/prettier/pull/6088
@ -418,6 +432,7 @@ new (a::b)();
[#6148]: https://github.com/prettier/prettier/pull/6148
[#6146]: https://github.com/prettier/prettier/pull/6146
[#6152]: https://github.com/prettier/prettier/pull/6152
[#6159]: https://github.com/prettier/prettier/pull/6159
[@belochub]: https://github.com/belochub
[@brainkim]: https://github.com/brainkim
[@duailibe]: https://github.com/duailibe

View File

@ -711,7 +711,9 @@ function needsParens(path, options) {
(parent.type === "BindExpression" &&
name === "callee" &&
parent.callee === node) ||
parent.type === "MemberExpression" ||
(parent.type === "MemberExpression" &&
name === "object" &&
parent.object === node) ||
(parent.type === "NewExpression" &&
name === "callee" &&
parent.callee === node)

View File

@ -79,6 +79,8 @@ b.c::d.e;
(b::c::d).e;
new (a::b)();
new f(a::b);
f[a::b];
f[a::b()];
=====================================output=====================================
(a || b)::c;
@ -113,6 +115,8 @@ b.c::d.e;
(b::c::d).e;
new (a::b)();
new f(a::b);
f[a::b];
f[a::b()];
================================================================================
`;
@ -156,6 +160,8 @@ b.c::d.e;
(b::c::d).e;
new (a::b)();
new f(a::b);
f[a::b];
f[a::b()];
=====================================output=====================================
;(a || b)::c
@ -190,6 +196,8 @@ b.c::d.e
;(b::c::d).e
new (a::b)()
new f(a::b)
f[a::b]
f[a::b()]
================================================================================
`;

View File

@ -30,3 +30,5 @@ b.c::d.e;
(b::c::d).e;
new (a::b)();
new f(a::b);
f[a::b];
f[a::b()];