Skip to content

Commit

Permalink
Stop generating break and continue statements with no enclosing
Browse files Browse the repository at this point in the history
iteration (and switch, for break) statements. Should fix bug #60.
  • Loading branch information
achudnov committed Jan 2, 2015
1 parent c7b0b14 commit 0aa542f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Language/ECMAScript3/Syntax/Arbitrary.hs
Expand Up @@ -304,16 +304,18 @@ fixBreakContinue = mapM $ \stmt -> evalStateT (fixBC stmt) ([], [])
else liftM (LabelledStmt a lab) $ descendM fixBC s
fixBC stmt@(BreakStmt a mlab) =
do encls <- gets snd
case mlab of
Nothing -> if or $ map isIterSwitch encls then return stmt
case (mlab, encls) of
(_, []) -> return $ EmptyStmt a
(Nothing, _) -> if all isIterSwitch encls
then return stmt
-- if none of the enclosing statements is an
-- iteration or switch statement, substitute
-- the break statement for an empty statement
else return $ EmptyStmt a
Just lab@(Id b _) ->
(Just lab@(Id b _), _) ->
if any (elem (unId lab) . getLabelSet) encls
then return stmt
else if not $ and $ map isIterSwitch encls
else if not $ all isIterSwitch encls
-- if none of the enclosing statements is an
-- iteration or switch statement, substitute
-- the break statement for an empty statement
Expand All @@ -330,13 +332,13 @@ fixBreakContinue = mapM $ \stmt -> evalStateT (fixBC stmt) ([], [])
fixBC stmt@(ContinueStmt a mlab) =
do encls <- gets snd
let enIts = filter isIter encls
case mlab of
Nothing -> if not $ null enIts then return stmt
-- if none of the enclosing statements are
-- iteration statements, substitute the
-- continue statement for an empty statement
else return $ EmptyStmt a
Just lab@(Id b _) ->
case (mlab, enIts) of
-- if none of the enclosing statements are
-- iteration statements, substitute the
-- continue statement for an empty statement
(_, []) -> return $ EmptyStmt a
(Nothing, _) -> return stmt
(Just lab@(Id b _), _) ->
if any (elem (unId lab) . getLabelSet) enIts
then return stmt
else case concatMap getLabelSet enIts of
Expand Down

0 comments on commit 0aa542f

Please sign in to comment.