Prevent parens around BindExpressions as properties of MemberExpressions (#6159)
parent
dcf4c21171
commit
f8875c1caa
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()]
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
|
|
@ -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()];
|
||||
|
|
Loading…
Reference in New Issue