diff --git a/src/Category.hs b/src/Category.hs index c20175fb3..980ef002a 100644 --- a/src/Category.hs +++ b/src/Category.hs @@ -76,6 +76,8 @@ data Category | Case -- | An expression with an operator. | Operator + -- | An comma operator expression + | CommaOperator -- | An object/dictionary/hash literal. | Object -- | A throw statement. diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 957d408f0..d9804a821 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -57,7 +57,7 @@ summaries (Replace i1 i2) = zipWith (\a b -> "Replaced" <+> "the" <+> a <+> "wit toLeafInfos :: DiffInfo -> [Doc] toLeafInfos LeafInfo{..} = pure $ squotes (toDoc termName) <+> (toDoc categoryName) -toLeafInfos BranchInfo{..} = pretty <$> branches +toLeafInfos BranchInfo{..} = toLeafInfos =<< branches toLeafInfos err@ErrorInfo{} = pure $ pretty err toTermName :: (HasCategory leaf, HasField fields Category, HasField fields Range) => Source Char -> Term leaf (Record fields) -> Text @@ -214,6 +214,7 @@ instance HasCategory Category where C.Class -> "class" C.Method -> "method" C.If -> "if statement" + C.CommaOperator -> "comma operator" instance (HasCategory leaf, HasField fields Category) => HasCategory (Term leaf (Record fields)) where toCategoryName = toCategoryName . category . extract diff --git a/src/Parser.hs b/src/Parser.hs index 297516fcf..f59b65e09 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -55,6 +55,9 @@ termConstructor source sourceSpan info = fmap cofree . construct (base:element:[]) -> withDefaultInfo $ S.SubscriptAccess base element _ -> errorWith children construct children | isOperator (category info) = withDefaultInfo $ S.Operator children + construct children | CommaOperator == category info = withDefaultInfo $ case children of + [child, rest] | S.Indexed cs <- unwrap rest -> S.Indexed $ child : toList cs + _ -> S.Indexed children construct children | Function == category info = case children of (body:[]) -> withDefaultInfo $ S.Function Nothing Nothing body (params:body:[]) | (info :< _) <- runCofree params, Params == category info -> diff --git a/src/Renderer.hs b/src/Renderer.hs index fbbfca8c3..0c537d657 100644 --- a/src/Renderer.hs +++ b/src/Renderer.hs @@ -24,10 +24,12 @@ concatOutputs l = T.intercalate "\n" (toText <$> l) toSeries :: Output -> Series toSeries (JSONOutput series) = series toSeries (SummaryOutput series) = series +toSeries _ = mempty toText :: Output -> Text toText (SplitOutput text) = text toText (PatchOutput text) = text +toText _ = mempty -- | The available types of diff rendering. diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 722f72202..d76c460eb 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -42,7 +42,7 @@ categoriesForLanguage language name = case (language, name) of (JavaScript, "bool_op") -> BinaryOperator -- boolean operator, e.g. ||, &&. (JavaScript, "bitwise_op") -> BinaryOperator -- bitwise operator, e.g. ^, &, etc. (JavaScript, "rel_op") -> BinaryOperator -- relational operator, e.g. >, <, <=, >=, ==, !=. - (JavaScript, "comma_op") -> Operator -- comma operator, e.g. expr1, expr2. + (JavaScript, "comma_op") -> CommaOperator -- comma operator, e.g. expr1, expr2. (JavaScript, "delete_op") -> Operator -- delete operator, e.g. delete x[2]. (JavaScript, "type_op") -> Operator -- type operator, e.g. typeof Object. (JavaScript, "void_op") -> Operator -- void operator, e.g. void 2. diff --git a/test/repos/js-test b/test/repos/js-test index 3af143b53..45875c177 160000 --- a/test/repos/js-test +++ b/test/repos/js-test @@ -1 +1 @@ -Subproject commit 3af143b53c8f9a2a6761d8e9ea91d47982cc3bc0 +Subproject commit 45875c177feba7e9c25f780669e6719c59441a42