Skip to content

Commit

Permalink
Fix: no-useless-return stack overflow on unreachable loops (fixes #7583
Browse files Browse the repository at this point in the history
…) (#7584)
  • Loading branch information
not-an-aardvark authored and ilyavolodin committed Nov 14, 2016
1 parent dbff37a commit c4dd015
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/no-useless-return.js
Expand Up @@ -107,6 +107,7 @@ module.exports = {

create(context) {
const segmentInfoMap = new WeakMap();
const usedUnreachableSegments = new WeakSet();
let scopeInfo = null;

/**
Expand Down Expand Up @@ -175,8 +176,10 @@ module.exports = {
*/
function markReturnStatementsOnSegmentAsUsed(segment) {
if (!segment.reachable) {
usedUnreachableSegments.add(segment);
segment.allPrevSegments
.filter(isReturned)
.filter(prevSegment => !usedUnreachableSegments.has(prevSegment))
.forEach(markReturnStatementsOnSegmentAsUsed);
return;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/no-useless-return.js
Expand Up @@ -148,6 +148,15 @@ ruleTester.run("no-useless-return", rule, {
else return;
return 5;
}
`,

// https://github.com/eslint/eslint/issues/7583
`
function foo() {
return;
while (foo) return;
foo;
}
`
],

Expand Down

0 comments on commit c4dd015

Please sign in to comment.