From 62db2939f8492f1a152383e9e525e86e9473c7b7 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Thu, 13 Oct 2016 12:34:48 -0500 Subject: [PATCH] Clean and retain elseClause for If statements that are not If statements --- src/Language/JavaScript.hs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Language/JavaScript.hs b/src/Language/JavaScript.hs index efab5d765..9859b127f 100644 --- a/src/Language/JavaScript.hs +++ b/src/Language/JavaScript.hs @@ -163,16 +163,8 @@ toVarDecl child = cofree $ setCategory (extract child) VarDecl :< S.VarDecl chil -- | and satisfies arbitrarily long else-if clauses. toElseIf :: (HasField fields Category) => Term (S.Syntax Text) (Record fields) -> Term (S.Syntax Text) (Record fields) toElseIf child = case unwrap child of - -- Base case, this stops the recursive toElseIf calls. - S.If expr thenClause [] -> cofree $ setCategory (extract child) If :< S.If expr thenClause [] - -- For each If term, determine if the else clause contains another If term. - -- For each nested If term, recursively construct If Syntaxes until the else clause - -- is empty, or the else clause is not a nested If term. - S.If expr thenClause elseClause -> case unwrap . head $ elseClause of - S.If{} -> cofree $ setCategory (extract child) If :< S.If expr thenClause (toElseIf <$> elseClause) - _ -> cofree $ setCategory (extract child) If :< S.If expr thenClause [] - -- This is bottom, to satisfy exhuastive pattern matching. - _ -> cofree $ setCategory (extract child) If :< S.If child child [] + S.If expr thenClause elseClause -> cofree $ setCategory (extract child) If :< S.If expr thenClause (toElseIf <$> elseClause) + _ -> child toTuple :: Term (S.Syntax Text) (Record fields) -> [Term (S.Syntax Text) (Record fields)] toTuple child | S.Indexed [key,value] <- unwrap child = [cofree (extract child :< S.Pair key value)]