1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 02:14:20 +03:00

Assign New changes

and add MetaProperty
This commit is contained in:
joshvera 2018-12-07 17:31:44 -05:00
parent 0ecd0a7e0b
commit 9586b476fd
5 changed files with 22 additions and 4 deletions

View File

@ -633,7 +633,7 @@ instance Evaluatable Await where
eval eval (Await a) = eval a eval eval (Await a) = eval a
-- | An object constructor call in Javascript, Java, etc. -- | An object constructor call in Javascript, Java, etc.
newtype New a = New { newSubject :: [a] } data New a = New { subject :: a , typeParameters :: a, arguments :: [a] }
deriving (Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1, NFData1) deriving (Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1, NFData1)
instance Declarations1 New where instance Declarations1 New where

View File

@ -428,7 +428,7 @@ compoundStatement :: Assignment Term
compoundStatement = makeTerm <$> symbol CompoundStatement <*> children (manyTerm statement) compoundStatement = makeTerm <$> symbol CompoundStatement <*> children (manyTerm statement)
objectCreationExpression :: Assignment Term objectCreationExpression :: Assignment Term
objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> children (Expression.New <$> ((:) <$> term classTypeDesignator <*> (arguments <|> pure [])))) objectCreationExpression = (makeTerm <$> symbol ObjectCreationExpression <*> children (Expression.New <$> term classTypeDesignator <*> emptyTerm <*> (arguments <|> pure [])))
<|> (makeTerm <$> symbol ObjectCreationExpression <*> children (makeAnonClass <$ token AnonNew <* token AnonClass <*> emptyTerm <*> (arguments <|> pure []) <*> (term classBaseClause <|> emptyTerm) <*> (term classInterfaceClause <|> emptyTerm) <*> (makeTerm <$> location <*> manyTerm classMemberDeclaration))) <|> (makeTerm <$> symbol ObjectCreationExpression <*> children (makeAnonClass <$ token AnonNew <* token AnonClass <*> emptyTerm <*> (arguments <|> pure []) <*> (term classBaseClause <|> emptyTerm) <*> (term classInterfaceClause <|> emptyTerm) <*> (makeTerm <$> location <*> manyTerm classMemberDeclaration)))
where makeAnonClass identifier args baseClause interfaceClause declarations = Declaration.Class [] identifier (args <> [baseClause, interfaceClause]) declarations where makeAnonClass identifier args baseClause interfaceClause declarations = Declaration.Class [] identifier (args <> [baseClause, interfaceClause]) declarations

View File

@ -205,6 +205,7 @@ type Syntax = '[
, TypeScript.Syntax.JavaScriptRequire , TypeScript.Syntax.JavaScriptRequire
, [] , []
, Statement.StatementBlock , Statement.StatementBlock
, TypeScript.Syntax.MetaProperty
] ]
type Term = Term.Term (Sum Syntax) Location type Term = Term.Term (Sum Syntax) Location
@ -309,7 +310,13 @@ memberExpression :: Assignment Term
memberExpression = makeTerm <$> (symbol Grammar.MemberExpression <|> symbol Grammar.MemberExpression') <*> children (Expression.MemberAccess <$> term expression <*> propertyIdentifier') memberExpression = makeTerm <$> (symbol Grammar.MemberExpression <|> symbol Grammar.MemberExpression') <*> children (Expression.MemberAccess <$> term expression <*> propertyIdentifier')
newExpression :: Assignment Term newExpression :: Assignment Term
newExpression = makeTerm <$> symbol Grammar.NewExpression <*> children (Expression.New . pure <$> term expression) newExpression = makeTerm <$> symbol Grammar.NewExpression <*> children (Expression.New <$> term constructableExpression <*> (typeArguments' <|> emptyTerm) <*> (arguments <|> pure []))
constructableExpression :: Assignment Term
constructableExpression = this <|> identifier <|> number <|> string <|> templateString <|> regex <|> true <|> false <|> null' <|> undefined <|> object <|> array <|> function <|> arrowFunction <|> class' <|> anonymousClass <|> parenthesizedExpression <|> subscriptExpression <|> memberExpression <|> metaProperty <|> newExpression
metaProperty :: Assignment Term
metaProperty = makeTerm <$> symbol Grammar.MetaProperty <*> (TypeScript.Syntax.MetaProperty <$ rawSource)
updateExpression :: Assignment Term updateExpression :: Assignment Term
updateExpression = makeTerm <$> symbol Grammar.UpdateExpression <*> children (TypeScript.Syntax.Update <$> term expression) updateExpression = makeTerm <$> symbol Grammar.UpdateExpression <*> children (TypeScript.Syntax.Update <$> term expression)
@ -888,9 +895,11 @@ pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> term property
callExpression :: Assignment Term callExpression :: Assignment Term
callExpression = makeCall <$> (symbol CallExpression <|> symbol CallExpression') <*> children ((,,,) <$> term (expression <|> super <|> function) <*> (typeArguments <|> pure []) <*> (arguments <|> (pure <$> term templateString)) <*> emptyTerm) callExpression = makeCall <$> (symbol CallExpression <|> symbol CallExpression') <*> children ((,,,) <$> term (expression <|> super <|> function) <*> (typeArguments <|> pure []) <*> (arguments <|> (pure <$> term templateString)) <*> emptyTerm)
where makeCall loc (subject, typeArgs, args, body) = makeTerm loc (Expression.Call typeArgs subject args body) where makeCall loc (subject, typeArgs, args, body) = makeTerm loc (Expression.Call typeArgs subject args body)
arguments = symbol Arguments *> children (manyTerm (expression <|> spreadElement))
typeArguments = symbol Grammar.TypeArguments *> children (some (term ty)) typeArguments = symbol Grammar.TypeArguments *> children (some (term ty))
arguments :: Assignment [Term]
arguments = symbol Arguments *> children (manyTerm (expression <|> spreadElement))
tryStatement :: Assignment Term tryStatement :: Assignment Term
tryStatement = makeTry <$> symbol TryStatement <*> children ((,,) <$> term statementTerm <*> optional (term catchClause) <*> optional (term finallyClause)) tryStatement = makeTry <$> symbol TryStatement <*> children ((,,) <$> term statementTerm <*> optional (term catchClause) <*> optional (term finallyClause))
where where

View File

@ -688,3 +688,11 @@ instance Evaluatable AbstractClass where
assign classSlot =<< klass (Declaration name) childFrame assign classSlot =<< klass (Declaration name) childFrame
rvalBox unit rvalBox unit
data MetaProperty a = MetaProperty
deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1, Named1, Message1, NFData1)
instance Eq1 MetaProperty where liftEq = genericLiftEq
instance Ord1 MetaProperty where liftCompare = genericLiftCompare
instance Show1 MetaProperty where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable MetaProperty

View File

@ -684,3 +684,4 @@ instance Taggable TypeScript.ThisType
instance Taggable TypeScript.ExistentialType instance Taggable TypeScript.ExistentialType
instance Taggable TypeScript.LiteralType instance Taggable TypeScript.LiteralType
instance Taggable TypeScript.Update instance Taggable TypeScript.Update
instance Taggable TypeScript.MetaProperty