Skip to content

Commit

Permalink
Move modulesToImport up
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Aug 13, 2023
1 parent 07c496c commit 8f112b8
Showing 1 changed file with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,14 @@ mapAppFilesToSupportJsonConverters { generatedModuleNamePrefix, sourceDirs } typ
generatedFunctions =
buildJsonConverterFunctionsForMultipleTypes typeAnnotationsBeforeDeduplicating choiceTypes

modulesToImport =
generatedFunctions.generatedFunctions
|> List.map .modulesToImport
|> List.foldl Set.union Set.empty

generatedModuleModulesToImport =
encodingModuleImportBase64
:: (generatedFunctions.modulesToImport
:: (modulesToImport
|> Set.toList
|> List.map (Tuple.pair >> (|>) Nothing)
)
Expand Down Expand Up @@ -854,17 +859,29 @@ mapAppFilesToSupportJsonConverters { generatedModuleNamePrefix, sourceDirs } typ
in
( appFiles
, { generatedModuleName = generatedModuleName
, modulesToImport = Set.insert generatedModuleName generatedFunctions.modulesToImport
, modulesToImport = Set.insert generatedModuleName modulesToImport
}
)


type alias GenerateFunctionsFromTypesConfig =
{ generateFromTypeAnnotation : ElmTypeAnnotation -> List GenerateFunctionFromTypeResult
, generateFromChoiceType : ( String, ElmChoiceTypeStruct ) -> List GenerateFunctionFromTypeResult
}


type alias GenerateFunctionFromTypeResult =
{ functionName : String
, functionText : String
, modulesToImport : Set.Set (List String)
}


buildJsonConverterFunctionsForMultipleTypes :
List ElmTypeAnnotation
-> Dict.Dict String ElmChoiceTypeStruct
->
{ generatedFunctions : List { functionName : String, functionText : String }
, modulesToImport : Set.Set (List String)
{ generatedFunctions : List GenerateFunctionFromTypeResult
, modulesToImportForChoiceTypes : List (List String)
}
buildJsonConverterFunctionsForMultipleTypes typeAnnotations choiceTypes =
Expand Down Expand Up @@ -919,37 +936,11 @@ buildJsonConverterFunctionsForMultipleTypes typeAnnotations choiceTypes =
choiceTypes

generatedFunctions =
(generatedFunctionsForTypes.generatedFunctions
|> List.map
(\function ->
{ functionName = function.functionName
, functionText = function.functionText
}
)
)
++ generalSupportingFunctionsTexts

modulesToImport =
generatedFunctionsForTypes.generatedFunctions
|> List.map .modulesToImport
|> List.foldl Set.union Set.empty
++ generalSupportingFunctionsTexts
in
{ generatedFunctions = generatedFunctions
, modulesToImportForChoiceTypes = generatedFunctionsForTypes.modulesToImportForChoiceTypes
, modulesToImport = modulesToImport
}


type alias GenerateFunctionsFromTypesConfig =
{ generateFromTypeAnnotation : ElmTypeAnnotation -> List GenerateFunctionFromTypeResult
, generateFromChoiceType : ( String, ElmChoiceTypeStruct ) -> List GenerateFunctionFromTypeResult
}


type alias GenerateFunctionFromTypeResult =
{ functionName : String
, functionText : String
, modulesToImport : Set.Set (List String)
}


Expand Down Expand Up @@ -2556,7 +2547,7 @@ type Declaration
| ChoiceTypeDeclaration Elm.Syntax.Type.Type


generalSupportingFunctionsTexts : List { functionName : String, functionText : String }
generalSupportingFunctionsTexts : List GenerateFunctionFromTypeResult
generalSupportingFunctionsTexts =
(generalSupportingFunctionsTextsWithCommonNamePattern
|> List.concatMap
Expand Down Expand Up @@ -2619,6 +2610,13 @@ jsonDecodeSucceedWhenNotNull valueIfNotNull =
)"""
}
]
|> List.map
(\function ->
{ functionName = function.functionName
, functionText = function.functionText
, modulesToImport = Set.empty
}
)


generalSupportingFunctionsTextsWithCommonNamePattern :
Expand Down

0 comments on commit 8f112b8

Please sign in to comment.