prettier: Hang formatting nested functions
Hey, I just found that prettier hangs when formatting this:
someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
anotherFunction();
});
});
});
});
});
});
});
});
});
(I’m embarrassed to have this piece of code in a codebase, it’s because of a limitation of a third-party library 😄)
If I remove two of the innermost nested calls, prettier does end and format correctly (it takes a while, though). So it seems that it’s not a hang but rather just taking exponentially forever when dealing with this (messed up) code.
I’m running prettier 1.0.2
on macOS 10.12.4 through the CLI: prettier file.js
Thanks
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 17 (13 by maintainers)
Commits related to this issue
- Do not print the sub-tree when using prettier-ignore In #1250, @jeresig reported that adding // prettier-ignore on a file that has a ton of conditional group still took 1.7s. The issue is that we're ... — committed to vjeux/prettier by vjeux 7 years ago
- Bail when traversing === groups This is the second part of the fix for the performance regression seen in #1250. In #1217, for correctness reasons, we're now traversing all the conditional groups. Th... — committed to vjeux/prettier by vjeux 7 years ago
- Do not print the sub-tree when using prettier-ignore (#1286) In #1250, @jeresig reported that adding // prettier-ignore on a file that has a ton of conditional group still took 1.7s. The issue is tha... — committed to prettier/prettier by vjeux 7 years ago
- Bail when traversing === groups This is the second part of the fix for the performance regression seen in #1250. In #1217, for correctness reasons, we're now traversing all the conditional groups. Th... — committed to vjeux/prettier by vjeux 7 years ago
- Bail when traversing === groups (#1294) This is the second part of the fix for the performance regression seen in #1250. In #1217, for correctness reasons, we're now traversing all the conditional gr... — committed to prettier/prettier by vjeux 7 years ago
- Add caching for printing For printing the last argument expansion, we need to print the same node a bit differently with a flag. It's not easy to re-print just the node that is different so we end up... — committed to vjeux/prettier by vjeux 7 years ago
- Add caching for printing For printing the last argument expansion, we need to print the same node a bit differently with a flag. It's not easy to re-print just the node that is different so we end up... — committed to vjeux/prettier by vjeux 7 years ago
- Add caching for printing (#2259) * Add caching for printing For printing the last argument expansion, we need to print the same node a bit differently with a flag. It's not easy to re-print just t... — committed to prettier/prettier by vjeux 7 years ago
it’s not a bug for me. that code is not serious and is totally ridiculous. you shoul separate it into separate functions and can be banned with 2 eslint rules (im calling it no nested hell)
@tunnckoCore prettier doesn’t make assumptions in how you actually write your program, it is going to format it. The problem here is that there is some exponential aspect inside of prettier that triggers here, so we should ensure that it doesn’t happen.
@vjeux @jlongster thank you for being so receptive, responsive, and making prettier great!
(One day I’d ❤️ to have prettier format my HTML — following its two core principles: parse and re-print, acknowledge maximum line length — as well 😃).