From 9586b476fdf94366748a63890f2e14d5aa998991 Mon Sep 17 00:00:00 2001 From: joshvera Date: Fri, 7 Dec 2018 17:31:44 -0500 Subject: [PATCH] Assign New changes and add MetaProperty --- src/Data/Syntax/Expression.hs | 2 +- src/Language/PHP/Assignment.hs | 2 +- src/Language/TypeScript/Assignment.hs | 13 +++++++++++-- src/Language/TypeScript/Syntax/TypeScript.hs | 8 ++++++++ src/Tags/Taggable.hs | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index 3dafe60ab..19b57a23d 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -633,7 +633,7 @@ instance Evaluatable Await where eval eval (Await a) = eval a -- | 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) instance Declarations1 New where diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index a957376b5..92f1ebb51 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -428,7 +428,7 @@ compoundStatement :: Assignment Term compoundStatement = makeTerm <$> symbol CompoundStatement <*> children (manyTerm statement) 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))) where makeAnonClass identifier args baseClause interfaceClause declarations = Declaration.Class [] identifier (args <> [baseClause, interfaceClause]) declarations diff --git a/src/Language/TypeScript/Assignment.hs b/src/Language/TypeScript/Assignment.hs index cd1cff61c..041840fc5 100644 --- a/src/Language/TypeScript/Assignment.hs +++ b/src/Language/TypeScript/Assignment.hs @@ -205,6 +205,7 @@ type Syntax = '[ , TypeScript.Syntax.JavaScriptRequire , [] , Statement.StatementBlock + , TypeScript.Syntax.MetaProperty ] 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') 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 = 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 = 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) - arguments = symbol Arguments *> children (manyTerm (expression <|> spreadElement)) typeArguments = symbol Grammar.TypeArguments *> children (some (term ty)) +arguments :: Assignment [Term] +arguments = symbol Arguments *> children (manyTerm (expression <|> spreadElement)) + tryStatement :: Assignment Term tryStatement = makeTry <$> symbol TryStatement <*> children ((,,) <$> term statementTerm <*> optional (term catchClause) <*> optional (term finallyClause)) where diff --git a/src/Language/TypeScript/Syntax/TypeScript.hs b/src/Language/TypeScript/Syntax/TypeScript.hs index 52cddcde8..b744df59a 100644 --- a/src/Language/TypeScript/Syntax/TypeScript.hs +++ b/src/Language/TypeScript/Syntax/TypeScript.hs @@ -688,3 +688,11 @@ instance Evaluatable AbstractClass where assign classSlot =<< klass (Declaration name) childFrame 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 diff --git a/src/Tags/Taggable.hs b/src/Tags/Taggable.hs index 823c8662c..41e80746e 100644 --- a/src/Tags/Taggable.hs +++ b/src/Tags/Taggable.hs @@ -684,3 +684,4 @@ instance Taggable TypeScript.ThisType instance Taggable TypeScript.ExistentialType instance Taggable TypeScript.LiteralType instance Taggable TypeScript.Update +instance Taggable TypeScript.MetaProperty