From a9e5ff6a110b76b71bc97fb337065153536d16ab Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 13 Apr 2018 10:49:16 -0700 Subject: [PATCH] Assign HashBangLines in JavaScript/TypeScript --- src/Data/Syntax/Statement.hs | 11 +++++++++++ src/Language/TypeScript/Assignment.hs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/Data/Syntax/Statement.hs b/src/Data/Syntax/Statement.hs index 6400c1c50..9f6156afa 100644 --- a/src/Data/Syntax/Statement.hs +++ b/src/Data/Syntax/Statement.hs @@ -303,3 +303,14 @@ instance Show1 ScopeExit where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for ScopeExit instance Evaluatable ScopeExit + +-- | HashBang line (e.g. `#!/usr/bin/env node`) +newtype HashBang a = HashBang ByteString + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1) + +instance Eq1 HashBang where liftEq = genericLiftEq +instance Ord1 HashBang where liftCompare = genericLiftCompare +instance Show1 HashBang where liftShowsPrec = genericLiftShowsPrec + +-- TODO: Implement Eval instance for HashBang +instance Evaluatable HashBang diff --git a/src/Language/TypeScript/Assignment.hs b/src/Language/TypeScript/Assignment.hs index 174a4d76c..51505768a 100644 --- a/src/Language/TypeScript/Assignment.hs +++ b/src/Language/TypeScript/Assignment.hs @@ -70,6 +70,7 @@ type Syntax = '[ , Statement.Finally , Statement.For , Statement.ForEach + , Statement.HashBang , Statement.If , Statement.Match , Statement.Pattern @@ -598,6 +599,7 @@ statement = handleError everything , continueStatement , returnStatement , throwStatement + , hashBang , emptyStatement , labeledStatement ] @@ -625,6 +627,9 @@ returnStatement = makeTerm <$> symbol ReturnStatement <*> children (Statement.Re throwStatement :: Assignment throwStatement = makeTerm <$> symbol Grammar.ThrowStatement <*> children (Statement.Throw <$> term expressions) +hashBang :: Assignment +hashBang = makeTerm <$> symbol HashBangLine <*> (Statement.HashBang <$> source) + labeledStatement :: Assignment labeledStatement = makeTerm <$> symbol Grammar.LabeledStatement <*> children (TypeScript.Syntax.LabeledStatement <$> statementIdentifier <*> term statement)