@@ -118,6 +118,40 @@ spec = do
118118 it " is False when local variable is used as a cache" $ do
119119 hasRedundantLocalVariableReturn (js " function x(m) { var x = 5; var y = 1 + x; g(y); return x; }" ) `shouldBe` False
120120
121+ describe " hasBrokenReturn" $ do
122+ it " is False when there are no functions" $ do
123+ hasBrokenReturn (js " let y = 0; if (x) { y = 0 } " ) `shouldBe` False
124+
125+ it " is False when there is a function that has only a return" $ do
126+ hasBrokenReturn (js " function f(){ return 4 } " ) `shouldBe` False
127+
128+ it " is False when there is a function that has a single flow and return" $ do
129+ hasBrokenReturn (js " function f(){ console.log(2); return 4 } " ) `shouldBe` False
130+
131+ it " is False when there is a function that has an if with no returns " $ do
132+ hasBrokenReturn (js " function f(){ if (x) { console.log(4) } else { console.log(5) } return 4 } " ) `shouldBe` False
133+
134+ it " is False when there is a function that has an if with no returns and no else " $ do
135+ hasBrokenReturn (js " function f(){ if (x) { console.log(4) } return 4 } " ) `shouldBe` False
136+
137+ it " is True when there is a function that has an if with a return and no else and not trailing return " $ do
138+ hasBrokenReturn (js " function f(){ if (x) { return 4 } } " ) `shouldBe` True
139+
140+ it " is True when there is a function that has an if with a return in else but not then and not trailing return " $ do
141+ hasBrokenReturn (js " function f(){ if (x) { } else { return 4 } }" ) `shouldBe` True
142+
143+ it " is True when there is a function that nested ifs with incomplete return and no trailing return " $ do
144+ hasBrokenReturn (js " function f(){ if (x) { if (y) { return 5 } } else { return 4 } }" ) `shouldBe` True
145+
146+ it " is False when there is a function that has an if with a return and no else and trailing return " $ do
147+ hasBrokenReturn (js " function f(){ if (x) { return 4 } return 5; } " ) `shouldBe` False
148+
149+ it " is False when there is a function that has an if with a return in else but not then and trailing return " $ do
150+ hasBrokenReturn (js " function f(){ if (x) { } else { return 4 } return 5; } " ) `shouldBe` False
151+
152+ it " is False when there is a function that nested ifs with complete return and no trailing return " $ do
153+ hasBrokenReturn (js " function f(){ if (x) { if (y) { return 5 } else { return 6 } } else { return 4 } }" ) `shouldBe` False
154+
121155
122156 describe " hasAssignmentCondition" $ do
123157 it " is True when assigns within an if condition" $ do
0 commit comments