mdgriffith / elm-codegen

https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/
BSD 3-Clause "New" or "Revised" License
138 stars 16 forks source link

Broken import statements when local module uses import aliases #73

Open r-k-b opened 1 year ago

r-k-b commented 1 year ago

For example, this file:

module BadModuleNamedWith exposing (dummyDecoder)

import Json.Decode as JD

dummyDecoder : JD.Decoder String
dummyDecoder =
    JD.succeed ""

would produce Gen code containing:

{-| dummyDecoder: JD.Decoder String -}
dummyDecoder : Elm.Expression
dummyDecoder =
    Elm.value
        { importFrom = [ "BadModuleNamedWith" ]
        , name = "dummyDecoder"
        , annotation = Just (Type.namedWith [ "JD" ] "Decoder" [ Type.string ])
        }

which would then produce generated code that contains import JD instead of import Json.Decode.

I've added a test case to demonstrate: 3e7c05574c315658e77ddae4948c96b3386b4817

image

Thanks for creating elm-codegen, it's fantastic! :pray: