mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-24 06:54:03 +03:00
Handle required splats in generated route module.
This commit is contained in:
parent
27e58f1027
commit
c81649d93b
@ -188,7 +188,13 @@ routeToBranch route =
|
||||
nonEmpty ->
|
||||
nonEmpty |> Elm.CodeGen.record |> Just
|
||||
in
|
||||
[ ( Elm.CodeGen.listPattern
|
||||
[ ( (case ending of
|
||||
Optional _ ->
|
||||
Elm.CodeGen.listPattern
|
||||
|
||||
_ ->
|
||||
unconsPattern
|
||||
)
|
||||
((route.segments
|
||||
|> List.map
|
||||
(\segment ->
|
||||
@ -200,17 +206,18 @@ routeToBranch route =
|
||||
Elm.CodeGen.varPattern (decapitalize name)
|
||||
)
|
||||
)
|
||||
++ [ case ending of
|
||||
++ (case ending of
|
||||
Optional name ->
|
||||
Elm.CodeGen.varPattern (decapitalize name)
|
||||
[ Elm.CodeGen.varPattern (decapitalize name) ]
|
||||
|
||||
RequiredSplat ->
|
||||
-- TODO splatRest
|
||||
Elm.CodeGen.varPattern "splatFirst"
|
||||
[ Elm.CodeGen.varPattern "splatFirst"
|
||||
, Elm.CodeGen.varPattern "splatRest"
|
||||
]
|
||||
|
||||
OptionalSplat ->
|
||||
Elm.CodeGen.varPattern "splat"
|
||||
]
|
||||
[ Elm.CodeGen.varPattern "splat" ]
|
||||
)
|
||||
)
|
||||
, toRecordVariant innerType somethingNew
|
||||
)
|
||||
@ -369,7 +376,10 @@ endingToVariantNameFields ending =
|
||||
( "SPLAT_"
|
||||
, Just
|
||||
( "splat"
|
||||
, Elm.CodeGen.val "( requiredSplat, splat )"
|
||||
, Elm.CodeGen.tuple
|
||||
[ Elm.CodeGen.val "splatFirst"
|
||||
, Elm.CodeGen.val "splatRest"
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
@ -524,3 +534,19 @@ type Param
|
||||
| OptionalParam
|
||||
| RequiredSplatParam
|
||||
| OptionalSplatParam
|
||||
|
||||
|
||||
unconsPattern : List Elm.CodeGen.Pattern -> Elm.CodeGen.Pattern
|
||||
unconsPattern list =
|
||||
case list of
|
||||
[] ->
|
||||
Debug.todo ""
|
||||
|
||||
listFirst :: listRest ->
|
||||
List.foldl
|
||||
(\soFar item ->
|
||||
soFar
|
||||
|> Elm.CodeGen.unConsPattern item
|
||||
)
|
||||
listFirst
|
||||
listRest
|
||||
|
@ -173,21 +173,43 @@ suite =
|
||||
, Elm.CodeGen.val "Docs__Section__ { section = Nothing }"
|
||||
)
|
||||
]
|
||||
|
||||
--, test "splat" <|
|
||||
-- \() ->
|
||||
-- [ "Docs", "Section__" ]
|
||||
-- |> testCaseGenerator
|
||||
-- ( Elm.CodeGen.listPattern
|
||||
-- [ Elm.CodeGen.stringPattern "docs"
|
||||
-- , Elm.CodeGen.varPattern "section"
|
||||
-- ]
|
||||
-- , Elm.CodeGen.val "Docs__Section__ { section = section }"
|
||||
-- )
|
||||
, test "required splat" <|
|
||||
\() ->
|
||||
[ "Username_", "Repo_", "Blob", "SPLAT_" ]
|
||||
|> testCaseGenerator
|
||||
[ ( --Elm. """username :: repo :: "blob" :: splatFirst :: splatRest"""
|
||||
--( Elm.CodeGen.unConsPattern
|
||||
unconsPattern
|
||||
[ Elm.CodeGen.varPattern "username"
|
||||
, Elm.CodeGen.varPattern "repo"
|
||||
, Elm.CodeGen.stringPattern "blob"
|
||||
, Elm.CodeGen.varPattern "splatFirst"
|
||||
, Elm.CodeGen.varPattern "splatRest"
|
||||
]
|
||||
, Elm.CodeGen.val
|
||||
"Username___Repo___Blob__SPLAT_ { username = username, repo = repo, splat = ( splatFirst, splatRest ) }"
|
||||
)
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
unconsPattern : List Elm.CodeGen.Pattern -> Elm.CodeGen.Pattern
|
||||
unconsPattern list =
|
||||
case list of
|
||||
[] ->
|
||||
Debug.todo ""
|
||||
|
||||
listFirst :: listRest ->
|
||||
List.foldl
|
||||
(\soFar item ->
|
||||
soFar
|
||||
|> Elm.CodeGen.unConsPattern item
|
||||
)
|
||||
listFirst
|
||||
listRest
|
||||
|
||||
|
||||
testCaseGenerator : List ( Elm.CodeGen.Pattern, Elm.CodeGen.Expression ) -> List String -> Expectation
|
||||
testCaseGenerator expected moduleName =
|
||||
RoutePattern.fromModuleName moduleName
|
||||
|
Loading…
Reference in New Issue
Block a user