mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 13:21:42 +03:00
Run dead-code elimination for Route Modules' action function in addition to data function.
This commit is contained in:
parent
325004f3fc
commit
5f148bf277
@ -46,7 +46,7 @@ declarationVisitor node context =
|
||||
(\recordSetter ->
|
||||
case Node.value recordSetter of
|
||||
( keyNode, valueNode ) ->
|
||||
if Node.value keyNode == "data" then
|
||||
if Node.value keyNode == "data" || Node.value keyNode == "action" then
|
||||
if isAlreadyApplied (Node.value valueNode) then
|
||||
Nothing
|
||||
|
||||
@ -66,6 +66,8 @@ declarationVisitor node context =
|
||||
, details = [ "" ]
|
||||
}
|
||||
(Node.range dataValue)
|
||||
-- TODO need to check the right way to refer to `DataSource.fail` based on imports
|
||||
-- TODO need to replace `action` as well
|
||||
[ Review.Fix.replaceRangeBy (Node.range dataValue) "data = DataSource.fail \"\"\n "
|
||||
]
|
||||
]
|
||||
@ -89,55 +91,57 @@ expressionVisitor node context =
|
||||
case applicationExpressions |> List.map (\applicationNode -> ( ModuleNameLookupTable.moduleNameFor context.lookupTable applicationNode, Node.value applicationNode )) of
|
||||
[ ( Just [ "RouteBuilder" ], Expression.FunctionOrValue _ pageBuilderName ), ( _, Expression.RecordExpr fields ) ] ->
|
||||
let
|
||||
dataFieldValue : Maybe (Node ( Node String, Node Expression ))
|
||||
dataFieldValue : List ( String, Node ( Node String, Node Expression ) )
|
||||
dataFieldValue =
|
||||
fields
|
||||
|> List.filterMap
|
||||
(\recordSetter ->
|
||||
case Node.value recordSetter of
|
||||
( keyNode, valueNode ) ->
|
||||
if Node.value keyNode == "data" then
|
||||
if Node.value keyNode == "data" || Node.value keyNode == "action" then
|
||||
if isAlreadyApplied (Node.value valueNode) then
|
||||
Nothing
|
||||
|
||||
else
|
||||
recordSetter |> Just
|
||||
( Node.value keyNode, recordSetter ) |> Just
|
||||
|
||||
else
|
||||
Nothing
|
||||
)
|
||||
|> List.head
|
||||
in
|
||||
dataFieldValue
|
||||
|> Maybe.map
|
||||
(\dataValue ->
|
||||
( [ Rule.errorWithFix
|
||||
( dataFieldValue
|
||||
|> List.concatMap
|
||||
(\( key, dataValue ) ->
|
||||
[ Rule.errorWithFix
|
||||
{ message = "Codemod"
|
||||
, details = [ "" ]
|
||||
}
|
||||
(Node.range dataValue)
|
||||
[ case pageBuilderName of
|
||||
[ Review.Fix.replaceRangeBy (Node.range dataValue)
|
||||
(key
|
||||
++ " = "
|
||||
++ (case pageBuilderName of
|
||||
"preRender" ->
|
||||
Review.Fix.replaceRangeBy (Node.range dataValue) "data = \\_ -> DataSource.fail \"\""
|
||||
"\\_ -> DataSource.fail \"\""
|
||||
|
||||
"preRenderWithFallback" ->
|
||||
Review.Fix.replaceRangeBy (Node.range dataValue) "data = \\_ -> DataSource.fail \"\""
|
||||
"\\_ -> DataSource.fail \"\""
|
||||
|
||||
"serverRender" ->
|
||||
Review.Fix.replaceRangeBy (Node.range dataValue) "data = \\_ -> Request.oneOf []\n "
|
||||
"\\_ -> Request.oneOf []\n "
|
||||
|
||||
"single" ->
|
||||
Review.Fix.replaceRangeBy (Node.range dataValue) "data = DataSource.fail \"\"\n "
|
||||
"DataSource.fail \"\"\n "
|
||||
|
||||
_ ->
|
||||
Review.Fix.replaceRangeBy (Node.range dataValue) "data = data"
|
||||
"data"
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
, context
|
||||
)
|
||||
)
|
||||
|> Maybe.withDefault
|
||||
( [], context )
|
||||
|
||||
_ ->
|
||||
( [], context )
|
||||
|
@ -222,6 +222,7 @@ route =
|
||||
RouteBuilder.serverRender
|
||||
{ head = head
|
||||
, data = data
|
||||
, action = action
|
||||
}
|
||||
|> RouteBuilder.buildNoState { view = view }
|
||||
"""
|
||||
@ -233,7 +234,7 @@ route =
|
||||
[ "" ]
|
||||
, under =
|
||||
"""data = data
|
||||
}"""
|
||||
,"""
|
||||
}
|
||||
|> Review.Test.whenFixed
|
||||
"""module Route.Login exposing (Data, Model, Msg, route)
|
||||
@ -255,6 +256,39 @@ route =
|
||||
RouteBuilder.serverRender
|
||||
{ head = head
|
||||
, data = \\_ -> Request.oneOf []
|
||||
, action = action
|
||||
}
|
||||
|> RouteBuilder.buildNoState { view = view }
|
||||
"""
|
||||
, Review.Test.error
|
||||
{ message = "Codemod"
|
||||
, details =
|
||||
[ "" ]
|
||||
, under =
|
||||
"""action = action
|
||||
}"""
|
||||
}
|
||||
|> Review.Test.whenFixed
|
||||
"""module Route.Login exposing (Data, Model, Msg, route)
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type alias Msg =
|
||||
()
|
||||
|
||||
|
||||
type alias RouteParams =
|
||||
{}
|
||||
|
||||
|
||||
route : StatelessRoute RouteParams Data ActionData
|
||||
route =
|
||||
RouteBuilder.serverRender
|
||||
{ head = head
|
||||
, data = data
|
||||
, action = \\_ -> Request.oneOf []
|
||||
}
|
||||
|> RouteBuilder.buildNoState { view = view }
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user