Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print accessFun "field" as ".field" #33

Open
lue-bird opened this issue Sep 9, 2021 · 1 comment
Open

print accessFun "field" as ".field" #33

lue-bird opened this issue Sep 9, 2021 · 1 comment

Comments

@lue-bird
Copy link
Contributor

lue-bird commented Sep 9, 2021

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.

@lue-bird lue-bird changed the title print accessFun field as ".field" print accessFun "field" as ".field" Sep 10, 2021
@rupertlssmith
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants