1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Optimize
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15module Language.PureScript.Optimize (
22import Language.PureScript.Names
23import Language.PureScript.CodeGen.JS.AST
26optimize = etaConvert . inlineVariables
28replaceIdent :: (Data d) => Ident -> JS -> d -> d
29replaceIdent var1 js = everywhere (mkT replace)
31 replace (JSVar var2) | var1 == var2 = js
34shouldInline :: JS -> Bool
35shouldInline (JSVar _) = True
36shouldInline (JSAccessor _ val) = shouldInline val
39inlineVariables :: JS -> JS
40inlineVariables = everywhere (mkT removeFromBlock)
42 removeFromBlock :: JS -> JS
43 removeFromBlock (JSBlock sts) = JSBlock (go sts)
44 removeFromBlock js = js
47 go (JSVariableIntroduction var js : sts) | shouldInline js = go (replaceIdent var js sts)
48 go (s:sts) = s : go sts
51etaConvert = everywhere (mkT convert)
54 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing [ident] (JSBlock body)) [arg])]) | shouldInline arg = JSBlock (replaceIdent ident arg body)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list