elm-pages 2.1.10 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/{template/public/style.css → review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock} +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +6795 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +27617 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +110 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +187 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/package.json +1 -0
- package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +26 -0
- package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +62 -0
- package/generator/review/elm.json +13 -4
- package/{src → generator/review/src}/Pages/Review/NoContractViolations.elm +148 -148
- package/generator/review/tests/Pages/Review/NoContractViolationsTest.elm +331 -0
- package/generator/src/RouteBuilder.elm +420 -0
- package/generator/src/SharedTemplate.elm +4 -5
- package/generator/src/SiteConfig.elm +3 -9
- package/generator/src/build.js +308 -95
- package/generator/src/cli.js +103 -8
- package/generator/src/codegen.js +192 -35
- package/generator/src/compile-elm.js +183 -31
- package/generator/src/dev-server.js +353 -96
- package/generator/src/elm-application.json +3 -1
- package/generator/src/elm-codegen.js +34 -0
- package/generator/src/elm-file-constants.js +2 -0
- package/generator/src/error-formatter.js +20 -1
- package/generator/src/generate-template-module-connector.js +120 -924
- package/generator/src/hello.ts +5 -0
- package/generator/src/pre-render-html.js +58 -104
- package/generator/src/render-worker.js +27 -13
- package/generator/src/render.js +252 -197
- package/generator/src/request-cache-fs.js +18 -0
- package/generator/src/request-cache.js +128 -56
- package/generator/src/rewrite-client-elm-json.js +49 -0
- package/generator/src/route-codegen-helpers.js +62 -1
- package/generator/static-code/dev-style.css +22 -0
- package/generator/static-code/elm-pages.js +43 -39
- package/generator/static-code/hmr.js +98 -88
- package/generator/template/app/Api.elm +25 -0
- package/generator/template/app/ErrorPage.elm +38 -0
- package/generator/template/app/Route/Index.elm +87 -0
- package/generator/template/{src → app}/Shared.elm +34 -13
- package/generator/template/app/Site.elm +19 -0
- package/generator/template/{src → app}/View.elm +0 -0
- package/generator/template/elm-pages.config.mjs +5 -0
- package/generator/template/elm.json +14 -5
- package/generator/template/{public/index.js → index.ts} +7 -3
- package/generator/template/package.json +5 -5
- package/generator/template/public/favicon.ico +0 -0
- package/generator/template/public/images/icon-png.png +0 -0
- package/generator/template/src/.gitkeep +0 -0
- package/generator/template/style.css +4 -0
- package/package.json +30 -23
- package/src/ApiRoute.elm +176 -43
- package/src/BuildError.elm +10 -1
- package/src/CookieParser.elm +84 -0
- package/src/DataSource/Env.elm +38 -0
- package/src/DataSource/File.elm +27 -16
- package/src/DataSource/Glob.elm +126 -80
- package/src/DataSource/Http.elm +283 -304
- package/src/DataSource/Internal/Glob.elm +5 -21
- package/src/DataSource/Internal/Request.elm +25 -0
- package/src/DataSource/Port.elm +17 -14
- package/src/DataSource.elm +55 -318
- package/src/Form/Field.elm +717 -0
- package/src/Form/FieldStatus.elm +36 -0
- package/src/Form/FieldView.elm +417 -0
- package/src/Form/FormData.elm +22 -0
- package/src/Form/Validation.elm +391 -0
- package/src/Form/Value.elm +118 -0
- package/src/Form.elm +1683 -0
- package/src/FormData.elm +58 -0
- package/src/FormDecoder.elm +102 -0
- package/src/Head/Seo.elm +12 -4
- package/src/Head.elm +12 -2
- package/src/HtmlPrinter.elm +1 -1
- package/src/Internal/ApiRoute.elm +17 -4
- package/src/Internal/Request.elm +7 -0
- package/src/PageServerResponse.elm +68 -0
- package/src/Pages/ContentCache.elm +1 -229
- package/src/Pages/Fetcher.elm +58 -0
- package/src/Pages/FormState.elm +256 -0
- package/src/Pages/Generate.elm +800 -0
- package/src/Pages/Internal/Form.elm +17 -0
- package/src/Pages/Internal/NotFoundReason.elm +3 -55
- package/src/Pages/Internal/Platform/Cli.elm +777 -579
- package/src/Pages/Internal/Platform/Effect.elm +5 -5
- package/src/Pages/Internal/Platform/StaticResponses.elm +178 -394
- package/src/Pages/Internal/Platform/ToJsPayload.elm +24 -23
- package/src/Pages/Internal/Platform.elm +1244 -504
- package/src/Pages/Internal/ResponseSketch.elm +19 -0
- package/src/Pages/Internal/RoutePattern.elm +596 -45
- package/src/Pages/Manifest.elm +26 -0
- package/src/Pages/Msg.elm +79 -0
- package/src/Pages/ProgramConfig.elm +67 -14
- package/src/Pages/SiteConfig.elm +3 -6
- package/src/Pages/StaticHttp/Request.elm +4 -2
- package/src/Pages/StaticHttpRequest.elm +50 -215
- package/src/Pages/Transition.elm +70 -0
- package/src/Path.elm +1 -0
- package/src/Pattern.elm +98 -0
- package/src/RenderRequest.elm +2 -2
- package/src/RequestsAndPending.elm +111 -9
- package/src/Server/Request.elm +1253 -0
- package/src/Server/Response.elm +292 -0
- package/src/Server/Session.elm +316 -0
- package/src/Server/SetCookie.elm +169 -0
- package/src/TerminalText.elm +1 -1
- package/src/Test/Html/Internal/ElmHtml/Markdown.elm +0 -1
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +1 -1
- package/generator/src/Page.elm +0 -359
- package/generator/src/codegen-template-module.js +0 -183
- package/generator/src/elm-pages-js-minified.js +0 -1
- package/generator/template/src/Api.elm +0 -14
- package/generator/template/src/Page/Index.elm +0 -69
- package/generator/template/src/Site.elm +0 -41
- package/src/DataSource/ServerRequest.elm +0 -60
- package/src/Internal/OptimizedDecoder.elm +0 -18
- package/src/KeepOrDiscard.elm +0 -6
- package/src/OptimizedDecoder/Pipeline.elm +0 -335
- package/src/OptimizedDecoder.elm +0 -818
- package/src/Pages/Internal/ApplicationType.elm +0 -6
- package/src/Pages/Secrets.elm +0 -83
- package/src/Secrets.elm +0 -111
- package/src/SecretsDict.elm +0 -45
|
@@ -7,11 +7,14 @@ module Pages.Review.NoContractViolations exposing (rule)
|
|
|
7
7
|
-}
|
|
8
8
|
|
|
9
9
|
import Dict exposing (Dict)
|
|
10
|
+
import Elm.Annotation
|
|
10
11
|
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
|
|
11
12
|
import Elm.Syntax.Exposing as Exposing exposing (Exposing)
|
|
12
13
|
import Elm.Syntax.Module as Module exposing (Module)
|
|
13
14
|
import Elm.Syntax.Node as Node exposing (Node)
|
|
14
15
|
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
|
|
16
|
+
import Elm.ToString
|
|
17
|
+
import Pages.Internal.RoutePattern as RoutePattern exposing (Param(..))
|
|
15
18
|
import Review.Rule as Rule exposing (Direction, Error, Rule)
|
|
16
19
|
import Set exposing (Set)
|
|
17
20
|
|
|
@@ -52,76 +55,150 @@ elm-review --template dillonkearns/elm-review-elm-pages/example --rules Pages.Re
|
|
|
52
55
|
-}
|
|
53
56
|
rule : Rule
|
|
54
57
|
rule =
|
|
55
|
-
Rule.
|
|
56
|
-
{
|
|
57
|
-
, isPageModule = False
|
|
58
|
+
Rule.newProjectRuleSchema "Pages.Review.NoContractViolations"
|
|
59
|
+
{ visitedCoreModules = Set.empty
|
|
58
60
|
}
|
|
59
|
-
|> Rule.
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
|> Rule.withModuleVisitor
|
|
62
|
+
(Rule.withModuleDefinitionVisitor moduleDefinitionVisitor
|
|
63
|
+
>> Rule.withDeclarationVisitor declarationVisitor
|
|
64
|
+
)
|
|
65
|
+
|> Rule.withModuleContext
|
|
66
|
+
{ foldProjectContexts = \a b -> { visitedCoreModules = Set.union a.visitedCoreModules b.visitedCoreModules }
|
|
67
|
+
, fromModuleToProject = \_ moduleName _ -> { visitedCoreModules = Set.singleton (Node.value moduleName) }
|
|
68
|
+
, fromProjectToModule =
|
|
69
|
+
\_ moduleName _ ->
|
|
70
|
+
{ moduleName = Node.value moduleName
|
|
71
|
+
, isRouteModule =
|
|
72
|
+
if (Node.value moduleName |> List.take 1) == [ "Route" ] && ((Node.value moduleName |> List.length) > 1) then
|
|
73
|
+
Just RouteModule
|
|
74
|
+
|
|
75
|
+
else
|
|
76
|
+
coreModulesAndExports
|
|
77
|
+
|> Dict.get (Node.value moduleName)
|
|
78
|
+
|> Maybe.map
|
|
79
|
+
(\requiredExposes ->
|
|
80
|
+
CoreModule { requiredExposes = requiredExposes }
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|> Rule.withFinalProjectEvaluation
|
|
85
|
+
(\context ->
|
|
86
|
+
let
|
|
87
|
+
missingCoreModules : Set (List String)
|
|
88
|
+
missingCoreModules =
|
|
89
|
+
context.visitedCoreModules
|
|
90
|
+
|> Set.diff coreModules
|
|
91
|
+
in
|
|
92
|
+
if missingCoreModules |> Set.isEmpty then
|
|
93
|
+
[]
|
|
94
|
+
|
|
95
|
+
else
|
|
96
|
+
[ Rule.globalError
|
|
97
|
+
{ message = "Missing core modules"
|
|
98
|
+
, details =
|
|
99
|
+
missingCoreModules
|
|
100
|
+
|> Set.toList
|
|
101
|
+
|> List.map (String.join ".")
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
)
|
|
105
|
+
|> Rule.fromProjectRuleSchema
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
type SpecialModule
|
|
109
|
+
= RouteModule
|
|
110
|
+
| CoreModule { requiredExposes : List String }
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
coreModules : Set (List String)
|
|
114
|
+
coreModules =
|
|
115
|
+
Set.fromList
|
|
116
|
+
[ [ "Api" ]
|
|
117
|
+
, [ "Effect" ]
|
|
118
|
+
, [ "ErrorPage" ]
|
|
119
|
+
, [ "Shared" ]
|
|
120
|
+
, [ "Site" ]
|
|
121
|
+
, [ "View" ]
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
coreModulesAndExports : Dict (List String) (List String)
|
|
126
|
+
coreModulesAndExports =
|
|
127
|
+
Dict.fromList
|
|
128
|
+
[ ( [ "Api" ], [ "routes" ] )
|
|
129
|
+
, ( [ "Effect" ], [ "Effect", "batch", "fromCmd", "map", "none", "perform" ] )
|
|
130
|
+
, ( [ "ErrorPage" ], [ "ErrorPage", "notFound", "internalError", "view", "statusCode", "head" ] )
|
|
131
|
+
, ( [ "Shared" ], [ "Data", "Model", "Msg", "template" ] )
|
|
132
|
+
, ( [ "Site" ], [ "config" ] )
|
|
133
|
+
, ( [ "View" ], [ "View", "map" ] )
|
|
134
|
+
]
|
|
62
135
|
|
|
63
136
|
|
|
64
137
|
type alias Context =
|
|
65
138
|
{ moduleName : List String
|
|
66
|
-
,
|
|
139
|
+
, isRouteModule : Maybe SpecialModule
|
|
67
140
|
}
|
|
68
141
|
|
|
69
142
|
|
|
70
143
|
moduleDefinitionVisitor : Node Module -> Context -> ( List (Error {}), Context )
|
|
71
|
-
moduleDefinitionVisitor node
|
|
72
|
-
let
|
|
73
|
-
isPageModule : Bool
|
|
74
|
-
isPageModule =
|
|
75
|
-
(Node.value node |> Module.moduleName |> List.take 1)
|
|
76
|
-
== [ "Page" ]
|
|
77
|
-
&& ((Node.value node |> Module.moduleName |> List.length) > 1)
|
|
78
|
-
in
|
|
144
|
+
moduleDefinitionVisitor node context =
|
|
79
145
|
case Node.value node |> Module.exposingList of
|
|
80
146
|
Exposing.All _ ->
|
|
81
|
-
( []
|
|
82
|
-
, { moduleName = Node.value node |> Module.moduleName
|
|
83
|
-
, isPageModule = isPageModule
|
|
84
|
-
}
|
|
85
|
-
)
|
|
147
|
+
( [], context )
|
|
86
148
|
|
|
87
149
|
Exposing.Explicit exposedValues ->
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
[]
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
[ """Page Modules need to expose the following values:
|
|
102
|
-
|
|
103
|
-
- page
|
|
150
|
+
case context.isRouteModule of
|
|
151
|
+
Just RouteModule ->
|
|
152
|
+
case Set.diff (Set.fromList [ "ActionData", "Data", "Msg", "Model", "route" ]) (exposedNames exposedValues) |> Set.toList of
|
|
153
|
+
[] ->
|
|
154
|
+
( [], context )
|
|
155
|
+
|
|
156
|
+
nonEmpty ->
|
|
157
|
+
( [ Rule.error
|
|
158
|
+
{ message = "Unexposed Declaration in Route Module"
|
|
159
|
+
, details =
|
|
160
|
+
[ """Route Modules need to expose the following values:
|
|
161
|
+
|
|
162
|
+
- route
|
|
104
163
|
- Data
|
|
164
|
+
- ActionData
|
|
105
165
|
- Model
|
|
106
166
|
- Msg
|
|
107
167
|
|
|
108
168
|
But it is not exposing: """
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
)
|
|
169
|
+
++ (nonEmpty |> String.join ", ")
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
(Node.range (exposingListNode (Node.value node)))
|
|
173
|
+
]
|
|
174
|
+
, context
|
|
175
|
+
)
|
|
118
176
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
177
|
+
Just (CoreModule { requiredExposes }) ->
|
|
178
|
+
case Set.diff (Set.fromList requiredExposes) (exposedNames exposedValues) |> Set.toList of
|
|
179
|
+
[] ->
|
|
180
|
+
( [], context )
|
|
181
|
+
|
|
182
|
+
nonEmpty ->
|
|
183
|
+
( [ Rule.error
|
|
184
|
+
{ message = "A core elm-pages module needs to expose something"
|
|
185
|
+
, details =
|
|
186
|
+
[ "The "
|
|
187
|
+
++ (context.moduleName |> String.join ".")
|
|
188
|
+
++ " module must expose "
|
|
189
|
+
++ (nonEmpty
|
|
190
|
+
|> List.map (\value -> "`" ++ value ++ "`")
|
|
191
|
+
|> String.join ", "
|
|
192
|
+
)
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
(Node.range (exposingListNode (Node.value node)))
|
|
196
|
+
]
|
|
197
|
+
, context
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
_ ->
|
|
201
|
+
( [], context )
|
|
125
202
|
|
|
126
203
|
|
|
127
204
|
routeParamsMatchesNameOrError : Node TypeAnnotation -> List String -> List (Error {})
|
|
@@ -141,12 +218,12 @@ routeParamsMatchesNameOrError annotation moduleName =
|
|
|
141
218
|
|
|
142
219
|
else
|
|
143
220
|
[ Rule.error
|
|
144
|
-
{ message = "RouteParams don't match
|
|
221
|
+
{ message = "RouteParams don't match Route Module name"
|
|
145
222
|
, details =
|
|
146
223
|
[ """Expected
|
|
147
224
|
|
|
148
225
|
"""
|
|
149
|
-
++ expectedFieldsToRecordString
|
|
226
|
+
++ expectedFieldsToRecordString moduleName
|
|
150
227
|
++ "\n"
|
|
151
228
|
]
|
|
152
229
|
}
|
|
@@ -154,108 +231,31 @@ routeParamsMatchesNameOrError annotation moduleName =
|
|
|
154
231
|
]
|
|
155
232
|
|
|
156
233
|
|
|
157
|
-
expectedFieldsToRecordString :
|
|
158
|
-
expectedFieldsToRecordString
|
|
159
|
-
"type alias RouteParams =
|
|
160
|
-
++ (
|
|
161
|
-
|>
|
|
162
|
-
|>
|
|
163
|
-
|>
|
|
234
|
+
expectedFieldsToRecordString : List String -> String
|
|
235
|
+
expectedFieldsToRecordString moduleName =
|
|
236
|
+
"type alias RouteParams = "
|
|
237
|
+
++ (moduleName
|
|
238
|
+
|> RoutePattern.fromModuleName
|
|
239
|
+
|> Maybe.map (RoutePattern.toRouteParamsRecord >> Elm.Annotation.record >> Elm.ToString.annotation >> .signature)
|
|
240
|
+
|> Maybe.withDefault "ERROR"
|
|
164
241
|
)
|
|
165
|
-
++ " }"
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
paramToTypeString : Param -> String
|
|
169
|
-
paramToTypeString param =
|
|
170
|
-
case param of
|
|
171
|
-
Required ->
|
|
172
|
-
"String"
|
|
173
|
-
|
|
174
|
-
Optional ->
|
|
175
|
-
"Maybe String"
|
|
176
|
-
|
|
177
|
-
RequiredSplat ->
|
|
178
|
-
"( String, List String )"
|
|
179
|
-
|
|
180
|
-
OptionalSplat ->
|
|
181
|
-
"List String"
|
|
182
242
|
|
|
183
243
|
|
|
184
244
|
expectedRouteParamsFromModuleName : List String -> Dict String Param
|
|
185
245
|
expectedRouteParamsFromModuleName moduleSegments =
|
|
186
246
|
case moduleSegments of
|
|
187
|
-
"
|
|
247
|
+
"Route" :: segments ->
|
|
188
248
|
segments
|
|
189
|
-
|
|
249
|
+
--|> List.filterMap segmentToParam
|
|
250
|
+
|> RoutePattern.fromModuleName
|
|
251
|
+
|> Maybe.map RoutePattern.toRouteParamTypes
|
|
252
|
+
|> Maybe.withDefault []
|
|
190
253
|
|> Dict.fromList
|
|
191
254
|
|
|
192
255
|
_ ->
|
|
193
256
|
Dict.empty
|
|
194
257
|
|
|
195
258
|
|
|
196
|
-
type Param
|
|
197
|
-
= Required
|
|
198
|
-
| Optional
|
|
199
|
-
| RequiredSplat
|
|
200
|
-
| OptionalSplat
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
segmentToParam : String -> Maybe ( String, Param )
|
|
204
|
-
segmentToParam segment =
|
|
205
|
-
if segment == "SPLAT__" then
|
|
206
|
-
( "splat"
|
|
207
|
-
, OptionalSplat
|
|
208
|
-
)
|
|
209
|
-
|> Just
|
|
210
|
-
|
|
211
|
-
else if segment == "SPLAT_" then
|
|
212
|
-
( "splat"
|
|
213
|
-
, RequiredSplat
|
|
214
|
-
)
|
|
215
|
-
|> Just
|
|
216
|
-
|
|
217
|
-
else if segment |> String.endsWith "__" then
|
|
218
|
-
( segment
|
|
219
|
-
|> String.dropRight 2
|
|
220
|
-
|> decapitalize
|
|
221
|
-
, Optional
|
|
222
|
-
)
|
|
223
|
-
|> Just
|
|
224
|
-
|
|
225
|
-
else if segment |> String.endsWith "_" then
|
|
226
|
-
( segment
|
|
227
|
-
|> String.dropRight 1
|
|
228
|
-
|> decapitalize
|
|
229
|
-
, Required
|
|
230
|
-
)
|
|
231
|
-
|> Just
|
|
232
|
-
|
|
233
|
-
else
|
|
234
|
-
Nothing
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{-| Decapitalize the first letter of a string.
|
|
238
|
-
decapitalize "This is a phrase" == "this is a phrase"
|
|
239
|
-
decapitalize "Hello, World" == "hello, World"
|
|
240
|
-
-}
|
|
241
|
-
decapitalize : String -> String
|
|
242
|
-
decapitalize word =
|
|
243
|
-
-- Source: https://github.com/elm-community/string-extra/blob/4.0.1/src/String/Extra.elm
|
|
244
|
-
changeCase Char.toLower word
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
{-| Change the case of the first letter of a string to either uppercase or
|
|
248
|
-
lowercase, depending of the value of `wantedCase`. This is an internal
|
|
249
|
-
function for use in `toSentenceCase` and `decapitalize`.
|
|
250
|
-
-}
|
|
251
|
-
changeCase : (Char -> Char) -> String -> String
|
|
252
|
-
changeCase mutator word =
|
|
253
|
-
-- Source: https://github.com/elm-community/string-extra/blob/4.0.1/src/String/Extra.elm
|
|
254
|
-
String.uncons word
|
|
255
|
-
|> Maybe.map (\( head, tail ) -> String.cons (mutator head) tail)
|
|
256
|
-
|> Maybe.withDefault ""
|
|
257
|
-
|
|
258
|
-
|
|
259
259
|
stringFields :
|
|
260
260
|
Node TypeAnnotation
|
|
261
261
|
-> Result (Error {}) (Dict String (Result (Node TypeAnnotation) Param))
|
|
@@ -298,7 +298,7 @@ paramType typeAnnotation =
|
|
|
298
298
|
&& (Node.value secondType == ( [], "List" ))
|
|
299
299
|
&& (Node.value listType |> isString)
|
|
300
300
|
then
|
|
301
|
-
Ok
|
|
301
|
+
Ok RequiredSplatParam
|
|
302
302
|
|
|
303
303
|
else
|
|
304
304
|
Err typeAnnotation
|
|
@@ -310,24 +310,24 @@ paramType typeAnnotation =
|
|
|
310
310
|
-- TODO need to use module lookup table to handle Basics or aliases?
|
|
311
311
|
case ( Node.value moduleContext, innerType ) of
|
|
312
312
|
( ( [], "String" ), [] ) ->
|
|
313
|
-
Ok
|
|
313
|
+
Ok RoutePattern.RequiredParam
|
|
314
314
|
|
|
315
315
|
( ( [], "Maybe" ), [ maybeOf ] ) ->
|
|
316
316
|
if isString (Node.value maybeOf) then
|
|
317
|
-
Ok
|
|
317
|
+
Ok RoutePattern.OptionalParam
|
|
318
318
|
|
|
319
319
|
else
|
|
320
320
|
Err typeAnnotation
|
|
321
321
|
|
|
322
322
|
( ( [], "List" ), [ listOf ] ) ->
|
|
323
323
|
if isString (Node.value listOf) then
|
|
324
|
-
Ok
|
|
324
|
+
Ok RoutePattern.OptionalSplatParam
|
|
325
325
|
|
|
326
326
|
else
|
|
327
327
|
Err typeAnnotation
|
|
328
328
|
|
|
329
329
|
_ ->
|
|
330
|
-
Ok
|
|
330
|
+
Ok RoutePattern.OptionalParam
|
|
331
331
|
|
|
332
332
|
_ ->
|
|
333
333
|
Err typeAnnotation
|
|
@@ -349,7 +349,7 @@ declarationVisitor node direction context =
|
|
|
349
349
|
case ( direction, Node.value node ) of
|
|
350
350
|
( Rule.OnEnter, Declaration.AliasDeclaration { name, typeAnnotation } ) ->
|
|
351
351
|
-- TODO check that generics is empty
|
|
352
|
-
if context.
|
|
352
|
+
if context.isRouteModule == Just RouteModule && Node.value name == "RouteParams" then
|
|
353
353
|
( routeParamsMatchesNameOrError typeAnnotation context.moduleName
|
|
354
354
|
, context
|
|
355
355
|
)
|