1
1
mirror of https://github.com/github/semantic.git synced 2025-01-08 16:39:47 +03:00

Add public field definition and class body statements

This commit is contained in:
joshvera 2017-08-28 19:04:40 -04:00
parent 0106509adc
commit be8b303ccc

View File

@ -169,6 +169,7 @@ type Syntax = '[
, Language.TypeScript.Syntax.New , Language.TypeScript.Syntax.New
, Language.TypeScript.Syntax.Update , Language.TypeScript.Syntax.Update
, Language.TypeScript.Syntax.Await , Language.TypeScript.Syntax.Await
, Language.TypeScript.Syntax.PublicFieldDefinition
, Type.Visibility , Type.Visibility
, [] , []
] ]
@ -195,6 +196,12 @@ data Intersection a = Intersection { intersectionLeft :: !a, intersectionRight :
instance Eq1 Intersection where liftEq = genericLiftEq instance Eq1 Intersection where liftEq = genericLiftEq
instance Show1 Intersection where liftShowsPrec = genericLiftShowsPrec instance Show1 Intersection where liftShowsPrec = genericLiftShowsPrec
data PublicFieldDefinition a = PublicFieldDefinition { publicFieldPropertyName :: !a, publicFieldValue :: !a }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable)
instance Eq1 PublicFieldDefinition where liftEq = genericLiftEq
instance Show1 PublicFieldDefinition where liftShowsPrec = genericLiftShowsPrec
data Function a = Function { functionTypeParameters :: !a, functionFormalParameters :: ![a], functionType :: !a } data Function a = Function { functionTypeParameters :: !a, functionFormalParameters :: ![a], functionType :: !a }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable)
@ -689,15 +696,13 @@ null' :: Assignment
null' = makeTerm <$> symbol Null <*> (Literal.Null <$ source) null' = makeTerm <$> symbol Null <*> (Literal.Null <$ source)
anonymousClass :: Assignment anonymousClass :: Assignment
anonymousClass = makeTerm <$> symbol Grammar.AnonymousClass <*> children (Declaration.Class <$> pure [] <*> emptyTerm <*> superclass <*> classBodyStatements) anonymousClass = makeTerm <$> symbol Grammar.AnonymousClass <*> children (Declaration.Class <$> pure [] <*> emptyTerm <*> (classHeritage' <|> pure []) <*> classBodyStatements)
where superclass = pure <$ symbol Grammar.ClassHeritage <*> children expression
abstractClass :: Assignment abstractClass :: Assignment
abstractClass = makeTerm <$> symbol Grammar.AbstractClass <*> (Language.TypeScript.Syntax.AbstractClass <$> identifier <*> (typeParameters <|> emptyTerm) <*> (classHeritage <|> pure []) <*> classBodyStatements) abstractClass = makeTerm <$> symbol Grammar.AbstractClass <*> (Language.TypeScript.Syntax.AbstractClass <$> identifier <*> (typeParameters <|> emptyTerm) <*> (classHeritage' <|> pure []) <*> classBodyStatements)
where classHeritage = (\a b -> a : b : []) <$> (extendsClause' <|> emptyTerm) <*> implementsClause'
classHeritage' :: Assignment classHeritage' :: HasCallStack => Assignment.Assignment [] Grammar [Term]
classHeritage' = makeTerm <$> symbol Grammar.ClassHeritage <*> (Language.TypeScript.Syntax.ClassHeritage <$> (extendsClause' <|> emptyTerm) <*> implementsClause') classHeritage' = symbol Grammar.ClassHeritage *> children (((\a b -> a : b : []) <$> extendsClause' <*> implementsClause') <|> (pure <$> implementsClause'))
extendsClause' :: Assignment extendsClause' :: Assignment
extendsClause' = makeTerm <$> symbol Grammar.ExtendsClause <*> children (Language.TypeScript.Syntax.ExtendsClause <$> many ty) extendsClause' = makeTerm <$> symbol Grammar.ExtendsClause <*> children (Language.TypeScript.Syntax.ExtendsClause <$> many ty)
@ -759,9 +764,8 @@ literal =
<|> makeTerm <$> symbol Regex <*> (Literal.TextElement <$> source) <|> makeTerm <$> symbol Regex <*> (Literal.TextElement <$> source)
class' :: Assignment class' :: Assignment
class' = makeClass <$> symbol Class <*> children ((,,,) <$> expression <*> (many typeParameter' <|> pure []) <*> (superclass <|> pure []) <*> classBodyStatements) class' = makeClass <$> symbol Class <*> children ((,,,) <$> expression <*> (many typeParameter' <|> pure []) <*> (classHeritage' <|> pure []) <*> classBodyStatements)
where superclass = pure <$ symbol Grammar.ClassHeritage <*> children expression where makeClass loc (expression, typeParams, classHeritage, statements) = makeTerm loc (Declaration.Class typeParams expression classHeritage statements)
makeClass loc (expression, typeParams, superclass', statements) = makeTerm loc (Declaration.Class typeParams expression superclass' statements)
object :: Assignment object :: Assignment
object = makeTerm <$> symbol Object <*> children (Literal.Hash <$> many (pair <|> spreadElement <|> methodDefinition <|> assignmentPattern <|> shorthandPropertyIdentifier)) object = makeTerm <$> symbol Object <*> children (Literal.Hash <$> many (pair <|> spreadElement <|> methodDefinition <|> assignmentPattern <|> shorthandPropertyIdentifier))
@ -817,7 +821,7 @@ readonly' = makeTerm <$> symbol Readonly <*> (Type.Readonly <$ source)
methodDefinition :: Assignment methodDefinition :: Assignment
methodDefinition = makeMethod <$> methodDefinition = makeMethod <$>
symbol MethodDefinition symbol MethodDefinition
<*> children ((,,,,,) <$> (fromMaybe <$> emptyTerm <*> optional accessibilityModifier') <*> (fromMaybe <$> emptyTerm <*> optional readonly') <*> emptyTerm <*> emptyTerm <*> callSignatureParts <*> emptyTerm) <*> children ((,,,,,) <$> (fromMaybe <$> emptyTerm <*> optional accessibilityModifier') <*> (fromMaybe <$> emptyTerm <*> optional readonly') <*> emptyTerm <*> emptyTerm <*> callSignatureParts <*> statementBlock)
where where
makeMethod loc (modifier, readonly, receiver, propertyName', (typeParameters', params, ty'), statements) = makeTerm loc (Declaration.Method [modifier, readonly, typeParameters', ty'] receiver propertyName' params statements) makeMethod loc (modifier, readonly, receiver, propertyName', (typeParameters', params, ty'), statements) = makeTerm loc (Declaration.Method [modifier, readonly, typeParameters', ty'] receiver propertyName' params statements)
@ -933,7 +937,11 @@ statementBlock :: Assignment
statementBlock = makeTerm <$> symbol StatementBlock <*> children (many statement) statementBlock = makeTerm <$> symbol StatementBlock <*> children (many statement)
classBodyStatements :: HasCallStack => Assignment.Assignment [] Grammar [Term] classBodyStatements :: HasCallStack => Assignment.Assignment [] Grammar [Term]
classBodyStatements = symbol ClassBody *> children (many statement) classBodyStatements = symbol ClassBody *> children (many (methodDefinition <|> publicFieldDefinition <|> comment))
publicFieldDefinition :: Assignment
publicFieldDefinition = makeTerm <$> symbol Grammar.PublicFieldDefinition <*> (Language.TypeScript.Syntax.PublicFieldDefinition <$> propertyName <*> (expression <|> emptyTerm))
statement :: Assignment statement :: Assignment
statement = handleError $ (term everything) statement = handleError $ (term everything)