{-# LANGUAGE BangPatterns #-}

-- |
-- Simple dead call elimination in foreign modules.
module Language.PureScript.DCE.Foreign
  ( runForeignModuleDeadCodeElimination,
  )
where

import Data.Foldable (foldr')
import Data.Graph (graphFromEdges, reachable, transposeG)
import Data.List (nub)
import Data.Maybe (catMaybes, mapMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Language.JavaScript.Parser.AST
  ( JSArrayElement (..),
    JSBlock (..),
    JSClassElement (..),
    JSClassHeritage (..),
    JSCommaList (..),
    JSCommaTrailingList (..),
    JSExportClause (..),
    JSExportDeclaration (..),
    JSExportSpecifier (..),
    JSExpression (..),
    JSIdent (..),
    JSMethodDefinition (..),
    JSModuleItem (..),
    JSObjectProperty (..),
    JSStatement (..),
    JSSwitchParts (..),
    JSTemplatePart (..),
    JSTryCatch (..),
    JSTryFinally (..),
    JSVarInitializer (..),
  )
import Language.PureScript.Names (Ident, runIdent)

-- | Filter export statements in a foreign module.  This is not 100% safe.  It
-- might remove declarations that are used somewhere in the foreign module (for
-- example by using @'eval'@).
runForeignModuleDeadCodeElimination :: [Ident] -> [JSModuleItem] -> [JSModuleItem]
runForeignModuleDeadCodeElimination :: [Ident] -> [JSModuleItem] -> [JSModuleItem]
runForeignModuleDeadCodeElimination [Ident]
is [JSModuleItem]
items = forall a. Eq a => [a] -> [a]
nub [JSModuleItem]
allReachable
  where
    allReachable :: [JSModuleItem]
    allReachable :: [JSModuleItem]
allReachable = do
      Vertex
ePoint <- forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Text -> Maybe Vertex
vertexForKey forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ident -> Text
runIdent) [Ident]
is
      Vertex
reachableNode <- Graph -> Vertex -> [Vertex]
reachable (Graph -> Graph
transposeG Graph
graph) Vertex
ePoint
      forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (JSModuleItem, Text, [Text]) -> JSModuleItem
jsM forall a b. (a -> b) -> a -> b
$ Vertex -> (JSModuleItem, Text, [Text])
fromVertex Vertex
reachableNode

    -- Build a graph of exports statements.  Its initial set of edges point from
    -- an export statement to all other export statements that are using it.
    -- When checking if we need to include that vartex we just check if there is
    -- a path from a vertex to one of `entryPointVertices`.
    exps :: [JSModuleItem]
    exps :: [JSModuleItem]
exps = forall a. (a -> Bool) -> [a] -> [a]
filter JSModuleItem -> Bool
isExportModuleItem [JSModuleItem]
items

    (Graph
graph, Vertex -> (JSModuleItem, Text, [Text])
fromVertex, Text -> Maybe Vertex
vertexForKey) = forall key node.
Ord key =>
[(node, key, [key])]
-> (Graph, Vertex -> (node, key, [key]), key -> Maybe Vertex)
graphFromEdges [(JSModuleItem, Text, [Text])]
verts

    jsM :: (JSModuleItem, Text, [Text]) -> JSModuleItem
    jsM :: (JSModuleItem, Text, [Text]) -> JSModuleItem
jsM (JSModuleItem
a, Text
_, [Text]
_) = JSModuleItem
a

    verts :: [(JSModuleItem, Text, [Text])]
    verts :: [(JSModuleItem, Text, [Text])]
verts = [JSModuleItem]
items forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= JSModuleItem -> [(JSModuleItem, Text, [Text])]
toVert
      where
        toVert :: JSModuleItem -> [(JSModuleItem, Text, [Text])]
        toVert :: JSModuleItem -> [(JSModuleItem, Text, [Text])]
toVert item :: JSModuleItem
item@(JSModuleExportDeclaration JSAnnot
_ JSExportDeclaration
jsExportDec) = JSModuleItem -> Text -> (JSModuleItem, Text, [Text])
mkVertex JSModuleItem
item forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSExportDeclaration -> [Text]
exportNames JSExportDeclaration
jsExportDec
        toVert item :: JSModuleItem
item@(JSModuleStatementListItem JSStatement
stmt) = JSModuleItem -> Text -> (JSModuleItem, Text, [Text])
mkVertex JSModuleItem
item forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSStatement -> [Text]
toplevelNames JSStatement
stmt
        toVert JSModuleItem
_ = []

        mkVertex :: JSModuleItem -> Text -> (JSModuleItem, Text, [Text])
        mkVertex :: JSModuleItem -> Text -> (JSModuleItem, Text, [Text])
mkVertex JSModuleItem
item Text
name =
          (JSModuleItem
item, Text
name, forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr' (Text -> JSModuleItem -> [Text] -> [Text]
accumulateDependents Text
name) [] [JSModuleItem]
exps)

        accumulateDependents :: Text -> JSModuleItem -> [Text] -> [Text]
        accumulateDependents :: Text -> JSModuleItem -> [Text] -> [Text]
accumulateDependents Text
name JSModuleItem
item [Text]
acc =
          if Text -> JSModuleItem -> Bool
isNameUsedByItem Text
name JSModuleItem
item
            then JSModuleItem -> [Text]
exportedModuleItemName JSModuleItem
item forall a. [a] -> [a] -> [a]
++ [Text]
acc
            else [Text]
acc

-- | foldr over `JSCommaList`
foldrJSCommaList :: (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList :: forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList a -> b -> b
_ JSCommaList a
JSLNil b
b = b
b
foldrJSCommaList a -> b -> b
fn (JSLOne a
a) !b
b = a -> b -> b
fn a
a b
b
foldrJSCommaList a -> b -> b
fn (JSLCons JSCommaList a
as JSAnnot
_ a
a) !b
b = forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList a -> b -> b
fn JSCommaList a
as (a -> b -> b
fn a
a b
b)

toList :: JSCommaList a -> [a]
toList :: forall a. JSCommaList a -> [a]
toList JSCommaList a
ls = forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList (:) JSCommaList a
ls []

toplevelNames :: JSStatement -> [Text]
toplevelNames :: JSStatement -> [Text]
toplevelNames (JSFunction JSAnnot
_ (JSIdentName JSAnnot
_ String
name) JSAnnot
_ JSCommaList JSExpression
_ JSAnnot
_ JSBlock
_ JSSemi
_) = [String -> Text
T.pack String
name]
toplevelNames (JSConstant JSAnnot
_ JSCommaList JSExpression
exprs JSSemi
_) = forall a. [Maybe a] -> [a]
catMaybes forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList (\JSExpression
name [Maybe Text]
acc -> JSExpression -> Maybe Text
jsIdent JSExpression
name forall a. a -> [a] -> [a]
: [Maybe Text]
acc) JSCommaList JSExpression
exprs []
toplevelNames JSStatement
_ = []

exportName' :: JSExportSpecifier -> Maybe Text
exportName' :: JSExportSpecifier -> Maybe Text
exportName' (JSExportSpecifier (JSIdentName JSAnnot
_ String
name)) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
name
exportName' JSExportSpecifier
_ = forall a. Maybe a
Nothing

jsIdent :: JSExpression -> Maybe Text
jsIdent :: JSExpression -> Maybe Text
jsIdent (JSVarInitExpression JSExpression
ident JSVarInitializer
_) = JSExpression -> Maybe Text
jsIdent JSExpression
ident
jsIdent (JSIdentifier JSAnnot
_ String
i) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
i
jsIdent (JSStringLiteral JSAnnot
_ String
s) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s
jsIdent JSExpression
_ = forall a. Maybe a
Nothing

exportNames :: JSExportDeclaration -> [Text]
exportNames :: JSExportDeclaration -> [Text]
exportNames (JSExportLocals (JSExportClause JSAnnot
_ JSCommaList JSExportSpecifier
names JSAnnot
_) JSSemi
_) = forall a. [Maybe a] -> [a]
catMaybes forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList (\JSExportSpecifier
ex [Maybe Text]
exs -> JSExportSpecifier -> Maybe Text
exportName' JSExportSpecifier
ex forall a. a -> [a] -> [a]
: [Maybe Text]
exs) JSCommaList JSExportSpecifier
names []
exportNames (JSExportFrom (JSExportClause JSAnnot
_ JSCommaList JSExportSpecifier
names JSAnnot
_) JSFromClause
_ JSSemi
_) = forall a. [Maybe a] -> [a]
catMaybes forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList (\JSExportSpecifier
ex [Maybe Text]
exs -> JSExportSpecifier -> Maybe Text
exportName' JSExportSpecifier
ex forall a. a -> [a] -> [a]
: [Maybe Text]
exs) JSCommaList JSExportSpecifier
names []
exportNames (JSExport (JSConstant JSAnnot
_ JSCommaList JSExpression
names JSSemi
_) JSSemi
_) = forall a. [Maybe a] -> [a]
catMaybes forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b -> b) -> JSCommaList a -> b -> b
foldrJSCommaList (\JSExpression
name [Maybe Text]
nms -> JSExpression -> Maybe Text
jsIdent JSExpression
name forall a. a -> [a] -> [a]
: [Maybe Text]
nms) JSCommaList JSExpression
names []
exportNames (JSExport (JSFunction JSAnnot
_ (JSIdentName JSAnnot
_ String
name) JSAnnot
_ JSCommaList JSExpression
_ JSAnnot
_ JSBlock
_ JSSemi
_) JSSemi
_) = [String -> Text
T.pack String
name]
exportNames JSExportDeclaration
_ = []

isExportModuleItem :: JSModuleItem -> Bool
isExportModuleItem :: JSModuleItem -> Bool
isExportModuleItem (JSModuleExportDeclaration JSAnnot
_ JSExportDeclaration
_) = Bool
True
isExportModuleItem JSModuleItem
_ = Bool
False

exportedModuleItemName :: JSModuleItem -> [Text]
exportedModuleItemName :: JSModuleItem -> [Text]
exportedModuleItemName (JSModuleExportDeclaration JSAnnot
_ JSExportDeclaration
jsModuleExport) = JSExportDeclaration -> [Text]
exportNames JSExportDeclaration
jsModuleExport
exportedModuleItemName JSModuleItem
_ = []

isNameUsedByItem :: Text -> JSModuleItem -> Bool
isNameUsedByItem :: Text -> JSModuleItem -> Bool
isNameUsedByItem Text
_ (JSModuleImportDeclaration JSAnnot
_ JSImportDeclaration
_) = Bool
False
isNameUsedByItem Text
_ (JSModuleExportDeclaration JSAnnot
_ (JSExportFrom JSExportClause
_ JSFromClause
_ JSSemi
_)) = Bool
False
isNameUsedByItem Text
name (JSModuleExportDeclaration JSAnnot
_ decl :: JSExportDeclaration
decl@(JSExportLocals JSExportClause
_ JSSemi
_)) = Text
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` JSExportDeclaration -> [Text]
exportNames JSExportDeclaration
decl
isNameUsedByItem Text
name (JSModuleExportDeclaration JSAnnot
_ (JSExport JSStatement
statement JSSemi
_)) = Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
statement
isNameUsedByItem Text
name (JSModuleStatementListItem JSStatement
stmt) = Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt

isNameUsedByStatement :: Text -> JSStatement -> Bool
isNameUsedByStatement :: Text -> JSStatement -> Bool
isNameUsedByStatement Text
name (JSStatementBlock JSAnnot
_ [JSStatement]
block JSAnnot
_ JSSemi
_) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
block
isNameUsedByStatement Text
_ (JSBreak JSAnnot
_ JSIdent
_ JSSemi
_) = Bool
False
isNameUsedByStatement Text
name (JSLet JSAnnot
_ JSCommaList JSExpression
exprs JSSemi
_) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByStatement Text
name (JSClass JSAnnot
_ JSIdent
_ JSClassHeritage
heritage JSAnnot
_ [JSClassElement]
cls JSAnnot
_ JSSemi
_) =
  Text -> JSClassHeritage -> Bool
isNameUsedInHeritage Text
name JSClassHeritage
heritage Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSClassElement -> Bool
isNameUsedByClassElement Text
name) [JSClassElement]
cls
isNameUsedByStatement Text
name (JSConstant JSAnnot
_ JSCommaList JSExpression
exprs JSSemi
_) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByStatement Text
_ (JSContinue JSAnnot
_ JSIdent
_ JSSemi
_) = Bool
False
isNameUsedByStatement Text
name (JSDoWhile JSAnnot
_ JSStatement
stmt JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ JSSemi
_) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByStatement Text
name (JSFor JSAnnot
_ JSAnnot
_ JSCommaList JSExpression
exprs1 JSAnnot
_ JSCommaList JSExpression
exprs2 JSAnnot
_ JSCommaList JSExpression
exprs3 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs1 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs2 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs3)
isNameUsedByStatement Text
name (JSForIn JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForVar JSAnnot
_ JSAnnot
_ JSAnnot
_ JSCommaList JSExpression
exprs1 JSAnnot
_ JSCommaList JSExpression
exprs2 JSAnnot
_ JSCommaList JSExpression
exprs3 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs1 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs2 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs3)
isNameUsedByStatement Text
name (JSForLet JSAnnot
_ JSAnnot
_ JSAnnot
_ JSCommaList JSExpression
exprs1 JSAnnot
_ JSCommaList JSExpression
exprs2 JSAnnot
_ JSCommaList JSExpression
exprs3 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs1 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs2 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs3)
isNameUsedByStatement Text
name (JSForConst JSAnnot
_ JSAnnot
_ JSAnnot
_ JSCommaList JSExpression
exprs1 JSAnnot
_ JSCommaList JSExpression
exprs2 JSAnnot
_ JSCommaList JSExpression
exprs3 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs1 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs2 forall a. [a] -> [a] -> [a]
++ forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs3)
isNameUsedByStatement Text
name (JSForVarIn JSAnnot
_ JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForLetIn JSAnnot
_ JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForConstIn JSAnnot
_ JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForVarOf JSAnnot
_ JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForLetOf JSAnnot
_ JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForConstOf JSAnnot
_ JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSForOf JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSBinOp
_ JSExpression
expr2 JSAnnot
_ JSStatement
stmt) =
  Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByStatement Text
name (JSFunction JSAnnot
_ JSIdent
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_) JSSemi
_) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs) Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByStatement Text
name (JSGenerator JSAnnot
_ JSAnnot
_ JSIdent
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_) JSSemi
_) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs) Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByStatement Text
name (JSIf JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ JSStatement
stmt) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt
isNameUsedByStatement Text
name (JSIfElse JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ JSStatement
stmtIf JSAnnot
_ JSStatement
stmtElse) =
  Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement
stmtIf, JSStatement
stmtElse]
isNameUsedByStatement Text
name (JSLabelled JSIdent
_ JSAnnot
_ JSStatement
stmt) = Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt
isNameUsedByStatement Text
_ (JSEmptyStatement JSAnnot
_) = Bool
False
isNameUsedByStatement Text
name (JSExpressionStatement JSExpression
expr JSSemi
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByStatement Text
name (JSAssignStatement JSExpression
lhs JSAssignOp
_ JSExpression
rhs JSSemi
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
lhs, JSExpression
rhs]
isNameUsedByStatement Text
name (JSMethodCall JSExpression
expr JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ JSSemi
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (JSExpression
expr forall a. a -> [a] -> [a]
: forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByStatement Text
_ (JSReturn JSAnnot
_ Maybe JSExpression
Nothing JSSemi
_) = Bool
False
isNameUsedByStatement Text
name (JSReturn JSAnnot
_ (Just JSExpression
expr) JSSemi
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByStatement Text
name (JSSwitch JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ JSAnnot
_ [JSSwitchParts]
cases JSAnnot
_ JSSemi
_) =
  Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSSwitchParts -> Bool
isNameUsedByCase Text
name) [JSSwitchParts]
cases
isNameUsedByStatement Text
name (JSThrow JSAnnot
_ JSExpression
expr JSSemi
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByStatement Text
name (JSTry JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_) [JSTryCatch]
tryCatch JSTryFinally
tryFinally) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSTryCatch -> Bool
isNameUsedByTryCatch Text
name) [JSTryCatch]
tryCatch Bool -> Bool -> Bool
|| Text -> JSTryFinally -> Bool
isNameUsedByTryFinally Text
name JSTryFinally
tryFinally
isNameUsedByStatement Text
name (JSVariable JSAnnot
_ JSCommaList JSExpression
exprs JSSemi
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByStatement Text
name (JSWhile JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ JSStatement
stmt) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt
isNameUsedByStatement Text
name (JSWith JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ JSStatement
stmt JSSemi
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt

isNameUsedByExpr :: Text -> JSExpression -> Bool
isNameUsedByExpr :: Text -> JSExpression -> Bool
isNameUsedByExpr Text
name (JSIdentifier JSAnnot
_ String
ident) = Text
name forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack String
ident
isNameUsedByExpr Text
_ (JSDecimal JSAnnot
_ String
_) = Bool
False
isNameUsedByExpr Text
_ (JSLiteral JSAnnot
_ String
_) = Bool
False
isNameUsedByExpr Text
_ (JSHexInteger JSAnnot
_ String
_) = Bool
False
isNameUsedByExpr Text
_ (JSOctal JSAnnot
_ String
_) = Bool
False
isNameUsedByExpr Text
_ (JSStringLiteral JSAnnot
_ String
_) = Bool
False
isNameUsedByExpr Text
_ (JSRegEx JSAnnot
_ String
_) = Bool
False
isNameUsedByExpr Text
name (JSArrayLiteral JSAnnot
_ [JSArrayElement]
elems JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSArrayElement -> Bool
isNameUsedByArrayElement Text
name) [JSArrayElement]
elems
isNameUsedByExpr Text
name (JSAssignExpression JSExpression
lhs JSAssignOp
_ JSExpression
rhs) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
lhs, JSExpression
rhs]
isNameUsedByExpr Text
name (JSCallExpression JSExpression
expr JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (JSExpression
expr forall a. a -> [a] -> [a]
: forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByExpr Text
name (JSCallExpressionDot JSExpression
expr1 JSAnnot
_ JSExpression
expr2) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByExpr Text
name (JSCallExpressionSquare JSExpression
expr1 JSAnnot
_ JSExpression
expr2 JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2]
isNameUsedByExpr Text
name (JSClassExpression JSAnnot
_ JSIdent
_ JSClassHeritage
heritage JSAnnot
_ [JSClassElement]
cls JSAnnot
_) =
  Text -> JSClassHeritage -> Bool
isNameUsedInHeritage Text
name JSClassHeritage
heritage Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSClassElement -> Bool
isNameUsedByClassElement Text
name) [JSClassElement]
cls
isNameUsedByExpr Text
name (JSCommaExpression JSExpression
expr1 JSAnnot
_ JSExpression
expr2) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr1 Bool -> Bool -> Bool
|| Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr2
isNameUsedByExpr Text
name (JSExpressionBinary JSExpression
expr1 JSBinOp
_ JSExpression
expr2) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr1 Bool -> Bool -> Bool
|| Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr2
isNameUsedByExpr Text
name (JSExpressionParen JSAnnot
_ JSExpression
expr JSAnnot
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByExpr Text
name (JSExpressionPostfix JSExpression
expr JSUnaryOp
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByExpr Text
name (JSExpressionTernary JSExpression
cond JSAnnot
_ JSExpression
yes JSAnnot
_ JSExpression
no) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
cond, JSExpression
yes, JSExpression
no]
isNameUsedByExpr Text
name (JSArrowExpression JSArrowParameterList
_ JSAnnot
_ JSStatement
stmt) = Text -> JSStatement -> Bool
isNameUsedByStatement Text
name JSStatement
stmt
isNameUsedByExpr Text
name (JSFunctionExpression JSAnnot
_ JSIdent
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_)) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs) Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByExpr Text
name (JSGeneratorExpression JSAnnot
_ JSAnnot
_ JSIdent
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_)) =
  forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs) Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByExpr Text
name (JSMemberDot JSExpression
expr1 JSAnnot
_ JSExpression
expr2) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr1 Bool -> Bool -> Bool
|| Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr2
isNameUsedByExpr Text
name (JSMemberExpression JSExpression
expr JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (JSExpression
expr forall a. a -> [a] -> [a]
: forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByExpr Text
name (JSMemberNew JSAnnot
_ JSExpression
expr JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (JSExpression
expr forall a. a -> [a] -> [a]
: forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByExpr Text
name (JSMemberSquare JSExpression
expr1 JSAnnot
_ JSExpression
expr2 JSAnnot
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr1 Bool -> Bool -> Bool
|| Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr2
isNameUsedByExpr Text
name (JSNewExpression JSAnnot
_ JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByExpr Text
name (JSObjectLiteral JSAnnot
_ (JSCTLComma JSCommaList JSObjectProperty
props JSAnnot
_) JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSObjectProperty -> Bool
isNameUsedByObjectProperty Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSObjectProperty
props)
isNameUsedByExpr Text
name (JSObjectLiteral JSAnnot
_ (JSCTLNone JSCommaList JSObjectProperty
props) JSAnnot
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSObjectProperty -> Bool
isNameUsedByObjectProperty Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSObjectProperty
props)
isNameUsedByExpr Text
name (JSSpreadExpression JSAnnot
_ JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByExpr Text
name (JSTemplateLiteral Maybe JSExpression
Nothing JSAnnot
_ String
_ [JSTemplatePart]
parts) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSTemplatePart -> Bool
isNameUsedByTemplatePart Text
name) [JSTemplatePart]
parts
isNameUsedByExpr Text
name (JSTemplateLiteral (Just JSExpression
expr) JSAnnot
_ String
_ [JSTemplatePart]
parts) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSTemplatePart -> Bool
isNameUsedByTemplatePart Text
name) [JSTemplatePart]
parts
isNameUsedByExpr Text
name (JSUnaryExpression JSUnaryOp
_ JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByExpr Text
name (JSVarInitExpression JSExpression
expr JSVarInitializer
initializer) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| Text -> JSVarInitializer -> Bool
isNameUsedByVarInit Text
name JSVarInitializer
initializer
isNameUsedByExpr Text
_ (JSYieldExpression JSAnnot
_ Maybe JSExpression
Nothing) = Bool
False
isNameUsedByExpr Text
name (JSYieldExpression JSAnnot
_ (Just JSExpression
expr)) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByExpr Text
name (JSYieldFromExpression JSAnnot
_ JSAnnot
_ JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr

isNameUsedInHeritage :: Text -> JSClassHeritage -> Bool
isNameUsedInHeritage :: Text -> JSClassHeritage -> Bool
isNameUsedInHeritage Text
_ JSClassHeritage
JSExtendsNone = Bool
False
isNameUsedInHeritage Text
name (JSExtends JSAnnot
_ JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr

isNameUsedByClassElement :: Text -> JSClassElement -> Bool
isNameUsedByClassElement :: Text -> JSClassElement -> Bool
isNameUsedByClassElement Text
_ (JSClassSemi JSAnnot
_) = Bool
False
isNameUsedByClassElement Text
name (JSClassInstanceMethod JSMethodDefinition
defn) = Text -> JSMethodDefinition -> Bool
isNameUsedByMethodDefinition Text
name JSMethodDefinition
defn
isNameUsedByClassElement Text
name (JSClassStaticMethod JSAnnot
_ JSMethodDefinition
defn) = Text -> JSMethodDefinition -> Bool
isNameUsedByMethodDefinition Text
name JSMethodDefinition
defn

isNameUsedByMethodDefinition :: Text -> JSMethodDefinition -> Bool
isNameUsedByMethodDefinition :: Text -> JSMethodDefinition -> Bool
isNameUsedByMethodDefinition Text
name (JSMethodDefinition JSPropertyName
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ JSBlock
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByMethodDefinition Text
name (JSGeneratorMethodDefinition JSAnnot
_ JSPropertyName
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ JSBlock
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)
isNameUsedByMethodDefinition Text
name (JSPropertyAccessor JSAccessor
_ JSPropertyName
_ JSAnnot
_ JSCommaList JSExpression
exprs JSAnnot
_ JSBlock
_) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) (forall a. JSCommaList a -> [a]
toList JSCommaList JSExpression
exprs)

isNameUsedByCase :: Text -> JSSwitchParts -> Bool
isNameUsedByCase :: Text -> JSSwitchParts -> Bool
isNameUsedByCase Text
name (JSDefault JSAnnot
_ JSAnnot
_ [JSStatement]
stmts) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByCase Text
name (JSCase JSAnnot
_ JSExpression
expr JSAnnot
_ [JSStatement]
stmts) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts

isNameUsedByTryCatch :: Text -> JSTryCatch -> Bool
isNameUsedByTryCatch :: Text -> JSTryCatch -> Bool
isNameUsedByTryCatch Text
name (JSCatch JSAnnot
_ JSAnnot
_ JSExpression
expr JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_)) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByTryCatch Text
name (JSCatchIf JSAnnot
_ JSAnnot
_ JSExpression
expr1 JSAnnot
_ JSExpression
expr2 JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_)) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression
expr1, JSExpression
expr2] Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts

isNameUsedByTryFinally :: Text -> JSTryFinally -> Bool
isNameUsedByTryFinally :: Text -> JSTryFinally -> Bool
isNameUsedByTryFinally Text
name (JSFinally JSAnnot
_ (JSBlock JSAnnot
_ [JSStatement]
stmts JSAnnot
_)) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSStatement -> Bool
isNameUsedByStatement Text
name) [JSStatement]
stmts
isNameUsedByTryFinally Text
_ JSTryFinally
JSNoFinally = Bool
False

isNameUsedByArrayElement :: Text -> JSArrayElement -> Bool
isNameUsedByArrayElement :: Text -> JSArrayElement -> Bool
isNameUsedByArrayElement Text
_ (JSArrayComma JSAnnot
_) = Bool
False
isNameUsedByArrayElement Text
name (JSArrayElement JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr

isNameUsedByObjectProperty :: Text -> JSObjectProperty -> Bool
isNameUsedByObjectProperty :: Text -> JSObjectProperty -> Bool
isNameUsedByObjectProperty Text
name (JSPropertyNameandValue JSPropertyName
_ JSAnnot
_ [JSExpression]
exprs) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> JSExpression -> Bool
isNameUsedByExpr Text
name) [JSExpression]
exprs
isNameUsedByObjectProperty Text
name (JSPropertyIdentRef JSAnnot
_ String
ref) = Text
name forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack String
ref
isNameUsedByObjectProperty Text
name (JSObjectMethod JSMethodDefinition
mDef) = Text -> JSMethodDefinition -> Bool
isNameUsedByMethodDefinition Text
name JSMethodDefinition
mDef

isNameUsedByTemplatePart :: Text -> JSTemplatePart -> Bool
isNameUsedByTemplatePart :: Text -> JSTemplatePart -> Bool
isNameUsedByTemplatePart Text
name (JSTemplatePart JSExpression
expr JSAnnot
_ String
_) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr

isNameUsedByVarInit :: Text -> JSVarInitializer -> Bool
isNameUsedByVarInit :: Text -> JSVarInitializer -> Bool
isNameUsedByVarInit Text
name (JSVarInit JSAnnot
_ JSExpression
expr) = Text -> JSExpression -> Bool
isNameUsedByExpr Text
name JSExpression
expr
isNameUsedByVarInit Text
_ JSVarInitializer
JSVarInitNone = Bool
False