Extract helper.

This commit is contained in:
Dillon Kearns 2022-09-15 12:27:23 -07:00
parent 09d127c3e1
commit 42d5bc2de2
2 changed files with 31 additions and 26 deletions

30
codegen/Elm/Extra.elm Normal file
View File

@ -0,0 +1,30 @@
module Elm.Extra exposing (topLevelValue)
import Elm
import Elm.Declare
topLevelValue :
String
-> Elm.Expression
->
{ declaration : Elm.Declaration
, reference : Elm.Expression
, referenceFrom : List String -> Elm.Expression
}
topLevelValue name expression =
let
declaration_ :
{ declaration : Elm.Declaration
, call : List Elm.Expression -> Elm.Expression
, callFrom : List String -> List Elm.Expression -> Elm.Expression
}
declaration_ =
Elm.Declare.function name
[]
(\_ -> expression)
in
{ declaration = declaration_.declaration
, reference = declaration_.call []
, referenceFrom = \from -> declaration_.callFrom from []
}

View File

@ -7,6 +7,7 @@ import Elm.Annotation
import Elm.Case import Elm.Case
import Elm.CodeGen import Elm.CodeGen
import Elm.Declare import Elm.Declare
import Elm.Extra exposing (topLevelValue)
import Elm.Op import Elm.Op
import Elm.Pretty import Elm.Pretty
import Gen.Basics import Gen.Basics
@ -366,32 +367,6 @@ routeToPath routes =
) )
topLevelValue :
String
-> Elm.Expression
->
{ declaration : Elm.Declaration
, reference : Elm.Expression
, referenceFrom : List String -> Elm.Expression
}
topLevelValue name expression =
let
declaration_ :
{ declaration : Elm.Declaration
, call : List Elm.Expression -> Elm.Expression
, callFrom : List String -> List Elm.Expression -> Elm.Expression
}
declaration_ =
Elm.Declare.function name
[]
(\_ -> expression)
in
{ declaration = declaration_.declaration
, reference = declaration_.call []
, referenceFrom = \from -> declaration_.callFrom from []
}
expose : Elm.Declaration -> Elm.Declaration expose : Elm.Declaration -> Elm.Declaration
expose declaration = expose declaration =
declaration declaration