the-sett/elm-syntax-dsl

print `accessFun "field"` as ".field"

Opened this issue · 1 comments

In the example

import Elm.CodeGen exposing (accessFun)
import Elm.Pretty exposing (prettyExpression)
import Pretty exposing (pretty)

accessFun "field"
    |> prettyExpression
    |> pretty 120
--> "field"

I would expect the printed accessFun "field" to be

--> ".field"

Is this intentional?
If yes, I suggest using

String.replace "." ""

or something similar to make both accessFun "field" and accessFun ".field" return ".field".
Even if it isn't intentional, I'd suggest to using String.replace to make accessFun backwards compatible.

It is intentional because elm-syntax-dsl is a convenience layer on top of stil4m/elm-syntax and that is the way that it works. You can see all it does is invoke the underlying constructor.

{-| RecordAccessFunction String
-}
accessFun : String -> Expression
accessFun selector =
    RecordAccessFunction selector

At some point this package will move away from stil4m/elm-syntax for various reasons so compatability with it will cease to be an issue.

I think your suggestion of making both ways work is good though, since field names can never begin with '.', doing that will never produce a bad field name.