diff --git a/src/Language/TypeScript/Assignment.hs b/src/Language/TypeScript/Assignment.hs index 66ca5485d..8ed6c81a9 100644 --- a/src/Language/TypeScript/Assignment.hs +++ b/src/Language/TypeScript/Assignment.hs @@ -144,6 +144,8 @@ type Syntax = '[ , TypeScript.Syntax.JsxClosingElement , TypeScript.Syntax.JsxExpression , TypeScript.Syntax.JsxAttribute + , TypeScript.Syntax.JsxFragment + , TypeScript.Syntax.JsxNamespaceName , TypeScript.Syntax.OptionalParameter , TypeScript.Syntax.RequiredParameter , TypeScript.Syntax.RestParameter @@ -196,8 +198,8 @@ expression = handleError everything super, object, array, - jsxElement, - jsxSelfClosingElement, + jsxElement', + jsxFragment, class', anonymousClass, function, @@ -352,26 +354,44 @@ object = makeTerm <$> (symbol Object <|> symbol ObjectPattern) <*> children (Lit array :: Assignment array = makeTerm <$> (symbol Array <|> symbol ArrayPattern) <*> children (Literal.Array <$> manyTerm (expression <|> spreadElement)) +jsxElement' :: Assignment +jsxElement' = choice [ jsxElement, jsxSelfClosingElement ] + jsxElement :: Assignment -jsxElement = makeTerm <$> symbol Grammar.JsxElement <*> children (TypeScript.Syntax.JsxElement <$> term jsxOpeningElement' <*> manyTerm (jsxElement <|> jsxSelfClosingElement <|> jsxExpression' <|> jsxText) <*> term jsxClosingElement') +jsxElement = makeTerm <$> symbol Grammar.JsxElement <*> children (TypeScript.Syntax.JsxElement <$> term jsxOpeningElement' <*> manyTerm jsxChild <*> term jsxClosingElement') + +jsxFragment :: Assignment +jsxFragment = makeTerm <$> symbol Grammar.JsxFragment <*> children (TypeScript.Syntax.JsxFragment <$> manyTerm jsxChild) + +jsxChild :: Assignment +jsxChild = choice [ jsxElement', jsxExpression', jsxText ] jsxSelfClosingElement :: Assignment -jsxSelfClosingElement = makeTerm <$> symbol Grammar.JsxSelfClosingElement <*> children (TypeScript.Syntax.JsxSelfClosingElement <$> term identifier <*> manyTerm (jsxAttribute <|> jsxExpression')) +jsxSelfClosingElement = makeTerm <$> symbol Grammar.JsxSelfClosingElement <*> children (TypeScript.Syntax.JsxSelfClosingElement <$> term jsxElementName <*> manyTerm jsxAttribute') + +jsxAttribute' = jsxAttribute <|> jsxExpression' jsxOpeningElement' :: Assignment -jsxOpeningElement' = makeTerm <$> symbol Grammar.JsxOpeningElement <*> children (TypeScript.Syntax.JsxOpeningElement <$> term identifier <*> manyTerm (jsxAttribute <|> jsxExpression')) +jsxOpeningElement' = makeTerm <$> symbol Grammar.JsxOpeningElement <*> children (TypeScript.Syntax.JsxOpeningElement <$> term jsxElementName <*> manyTerm jsxAttribute') + +jsxElementName :: Assignment +jsxElementName = choice [ identifier, nestedIdentifier, jsxNamespaceName ] + +jsxNamespaceName :: Assignment +jsxNamespaceName = makeTerm <$> symbol Grammar.JsxNamespaceName <*> children (TypeScript.Syntax.JsxNamespaceName <$> identifier <*> identifier) jsxExpression' :: Assignment -jsxExpression' = makeTerm <$> symbol Grammar.JsxExpression <*> children (TypeScript.Syntax.JsxExpression <$> term (expressions <|> spreadElement)) +jsxExpression' = makeTerm <$> symbol Grammar.JsxExpression <*> children (TypeScript.Syntax.JsxExpression <$> term (expressions <|> spreadElement <|> emptyTerm)) jsxText :: Assignment jsxText = makeTerm <$> symbol Grammar.JsxText <*> (TypeScript.Syntax.JsxText <$> source) jsxClosingElement' :: Assignment -jsxClosingElement' = makeTerm <$> symbol Grammar.JsxClosingElement <*> children (TypeScript.Syntax.JsxClosingElement <$> term identifier) +jsxClosingElement' = makeTerm <$> symbol Grammar.JsxClosingElement <*> children (TypeScript.Syntax.JsxClosingElement <$> term jsxElementName) jsxAttribute :: Assignment -jsxAttribute = makeTerm <$> symbol Grammar.JsxAttribute <*> children (TypeScript.Syntax.JsxAttribute <$> term propertyIdentifier <*> term (number <|> string <|> jsxExpression')) +jsxAttribute = makeTerm <$> symbol Grammar.JsxAttribute <*> children (TypeScript.Syntax.JsxAttribute <$> term (propertyIdentifier <|> jsxNamespaceName) <*> (term jsxAttributeValue <|> emptyTerm)) + where jsxAttributeValue = choice [ string, jsxExpression', jsxElement', jsxFragment ] propertyIdentifier :: Assignment propertyIdentifier = makeTerm <$> symbol PropertyIdentifier <*> (Syntax.Identifier <$> source) diff --git a/src/Language/TypeScript/Syntax.hs b/src/Language/TypeScript/Syntax.hs index aa4103a8e..347f2e597 100644 --- a/src/Language/TypeScript/Syntax.hs +++ b/src/Language/TypeScript/Syntax.hs @@ -493,3 +493,17 @@ data RestParameter a = RestParameter { _restParameterContext :: ![a], _restParam instance Eq1 RestParameter where liftEq = genericLiftEq instance Ord1 RestParameter where liftCompare = genericLiftCompare instance Show1 RestParameter where liftShowsPrec = genericLiftShowsPrec + +data JsxFragment a = JsxFragment [a] + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 JsxFragment where liftEq = genericLiftEq +instance Ord1 JsxFragment where liftCompare = genericLiftCompare +instance Show1 JsxFragment where liftShowsPrec = genericLiftShowsPrec + +data JsxNamespaceName a = JsxNamespaceName a a + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 JsxNamespaceName where liftEq = genericLiftEq +instance Ord1 JsxNamespaceName where liftCompare = genericLiftCompare +instance Show1 JsxNamespaceName where liftShowsPrec = genericLiftShowsPrec diff --git a/test/fixtures/typescript/jsx-elements.A.ts b/test/fixtures/typescript/jsx-elements.A.ts index ad867ed78..6ed522a83 100644 --- a/test/fixtures/typescript/jsx-elements.A.ts +++ b/test/fixtures/typescript/jsx-elements.A.ts @@ -1 +1,3 @@ -var a = {children} \ No newline at end of file +var a = {children} +var b = +var c = diff --git a/test/fixtures/typescript/jsx-elements.diffA-B.txt b/test/fixtures/typescript/jsx-elements.diffA-B.txt index cd1f6951a..cdee6e494 100644 --- a/test/fixtures/typescript/jsx-elements.diffA-B.txt +++ b/test/fixtures/typescript/jsx-elements.diffA-B.txt @@ -22,4 +22,16 @@ (JsxExpression (Identifier)) (JsxClosingElement - (Identifier)))))) + (Identifier))))) + {-(VariableDeclaration + {-(Assignment + {-(Empty)-} + {-(Identifier)-} + {-(JsxElement{-(JsxOpeningElement{-(NestedIdentifier{-(Identifier)-}{-(Identifier)-})-})-}{-(JsxClosingElement{-(NestedIdentifier{-(Identifier)-}{-(Identifier)-})-})-})-}) + -})-} + {-(VariableDeclaration + {-(Assignment + {-(Empty)-} + {-(Identifier)-} + {-(JsxSelfClosingElement{-(NestedIdentifier{-(Identifier)-}{-(Identifier)-})-}{-(JsxAttribute{-(Identifier)-}{-(Empty)-})-}{-(JsxAttribute{-(Identifier)-}{-(TextElement)-})-})-} + )-})-}) diff --git a/test/fixtures/typescript/jsx-elements.diffB-A.txt b/test/fixtures/typescript/jsx-elements.diffB-A.txt index 4cef88579..b41facd71 100644 --- a/test/fixtures/typescript/jsx-elements.diffB-A.txt +++ b/test/fixtures/typescript/jsx-elements.diffB-A.txt @@ -22,4 +22,14 @@ (JsxExpression (Identifier)) (JsxClosingElement - (Identifier)))))) + (Identifier))))) + {+(VariableDeclaration + {+(Assignment + {+(Empty)+} + {+(Identifier)+} + {+(JsxElement{+(JsxOpeningElement{+(NestedIdentifier{+(Identifier)+}{+(Identifier)+})+})+}{+(JsxClosingElement{+(NestedIdentifier{+(Identifier)+}{+(Identifier)+})+})+})+})+})+} + {+(VariableDeclaration + {+(Assignment + {+(Empty)+} + {+(Identifier)+} + {+(JsxSelfClosingElement{+(NestedIdentifier{+(Identifier)+}{+(Identifier)+})+}{+(JsxAttribute{+(Identifier)+}{+(Empty)+})+}{+(JsxAttribute{+(Identifier)+}{+(TextElement)+})+})+})+})+}) diff --git a/test/fixtures/typescript/jsx-elements.parseA.txt b/test/fixtures/typescript/jsx-elements.parseA.txt index 72387143d..42d46254f 100644 --- a/test/fixtures/typescript/jsx-elements.parseA.txt +++ b/test/fixtures/typescript/jsx-elements.parseA.txt @@ -16,4 +16,30 @@ (JsxExpression (Identifier)) (JsxClosingElement - (Identifier)))))) + (Identifier))))) + (VariableDeclaration + (Assignment + (Empty) + (Identifier) + (JsxElement + (JsxOpeningElement + (NestedIdentifier + (Identifier) (Identifier))) + (JsxClosingElement + (NestedIdentifier + (Identifier) + (Identifier)))))) + (VariableDeclaration + (Assignment + (Empty) + (Identifier) + (JsxSelfClosingElement + (NestedIdentifier + (Identifier) + (Identifier)) + (JsxAttribute + (Identifier) + (Empty)) + (JsxAttribute + (Identifier) + (TextElement)))))) diff --git a/vendor/effects b/vendor/effects index 7b905b290..665d14c75 160000 --- a/vendor/effects +++ b/vendor/effects @@ -1 +1 @@ -Subproject commit 7b905b290f746c07f6a5486afd9fd881cfd30caf +Subproject commit 665d14c75881ddedb3aa6fa9ee0c46bfb898b3df diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 179099a20..a7c77ef54 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 179099a20135bfcee635e469022c77f04df20b07 +Subproject commit a7c77ef5459e4f610bd82ce203984f408bc106c2