|
1 | | ------------------------------------------------------------------------------ |
2 | | --- |
3 | | --- Module : Language.PureScript.CodeGen.JS.Optimizer.Common |
4 | | --- Copyright : (c) Phil Freeman 2013-14 |
5 | | --- License : MIT |
6 | | --- |
7 | | --- Maintainer : Phil Freeman <paf31@cantab.net> |
8 | | --- Stability : experimental |
9 | | --- Portability : |
10 | | --- |
11 | 1 | -- | |
12 | 2 | -- Common functions used by the various optimizer phases |
13 | 3 | -- |
14 | | ------------------------------------------------------------------------------ |
15 | | - |
16 | 4 | module Language.PureScript.CodeGen.JS.Optimizer.Common where |
17 | 5 |
|
18 | 6 | import Data.Maybe (fromMaybe) |
@@ -76,3 +64,18 @@ isUpdated var1 = everythingOnJS (||) check |
76 | 64 | removeFromBlock :: ([JS] -> [JS]) -> JS -> JS |
77 | 65 | removeFromBlock go (JSBlock sts) = JSBlock (go sts) |
78 | 66 | removeFromBlock _ js = js |
| 67 | + |
| 68 | +isFn :: (String, String) -> JS -> Bool |
| 69 | +isFn (moduleName, fnName) (JSAccessor x (JSVar y)) = x == fnName && y == moduleName |
| 70 | +isFn (moduleName, fnName) (JSIndexer (JSStringLiteral x) (JSVar y)) = x == fnName && y == moduleName |
| 71 | +isFn _ _ = False |
| 72 | + |
| 73 | +isFn' :: [(String, String)] -> JS -> Bool |
| 74 | +isFn' xs js = any (`isFn` js) xs |
| 75 | + |
| 76 | +isDict :: (String, String) -> JS -> Bool |
| 77 | +isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName |
| 78 | +isDict _ _ = False |
| 79 | + |
| 80 | +isDict' :: [(String, String)] -> JS -> Bool |
| 81 | +isDict' xs js = any (`isDict` js) xs |
0 commit comments