Closed natdm closed 7 years ago
This is the Language type: https://github.com/natdm/typewriter/blob/f91e3c8/template/funcmaps.go#L10
To be clear, I'm not saying we SHOULD do Elm right now -- you can just have it noop for Elm and that can be a PR for another day.
@scottmmjackson -- would you want to take this on?
Yeah, I'd be able to make some movement on it this afternoon possibly.
So it sounds like the status here is:
If I'm wrong about the latter, perhaps this issue can be closed.
We can separate elm out in to a new one at a later time. It's very unused.. I may be the only one that uses it :-P
Quoting @scottmmjackson -
Transform valid Go names for struct fields and types to valid TS/Flow/Elm names.
Below, Scott suggests a way to fix names that are invalid ECMA. It makes sense, but I'd like to leave room to parse invalid Elm names as well. If we could turn this in to a method on the
Language
type that will parse it somehow (likefunc (l Language) ParseFromReserved(s string) string
) that will just parse ALL input and transform to valid output (or just noop and return the word if not invalid), I feel that leaves more room for growth, as well is available anywhere that the Language type is passed in.Sure, right around here: https://github.com/natdm/typewriter/blob/master/template/template.go#L230
You've got
strings.Contains(t.name, '-')
. That test could be generalized to check for anything that makes the identifier invalid. Here's a basic attempt:See playground here: https://play.golang.org/p/SxVqckRKZ3
Note that this attempt is a little overkill, and will quote valid identifiers, but they'd be uncommon valid identifiers and it would ensure that the tool always works.