-
Notifications
You must be signed in to change notification settings - Fork 12
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
Extend support for literals #23
Conversation
Nice! Thanks for digging into this. Fwiw, the support for literals has grown organically and I'm not against re-thinking it...i.e. the current approach of:
Is not great. I think the reason is historical b/c early on I had a pattern of doing:
And, in the above scenario, I wanted the So I originally did that. But then later I did actually want to output literal arrays, so here came Anyway, I'm wondering if we should just kill This would be a breaking change, but dunno, it'd be pretty easy to find the ~probably 20 or so places across ~10 or so projects I'm doing I suppose we could also canonicalize the "chunks" pattern and make like a
That's interesting, and the mutation of placeholders isn't something I'd thought of. We could probably keep that behavior by changing the Wdyt? Do you want to try tackling this in this PR? I.e. deprecate |
I had similar questions when looking at this. I didn't go that way because I would like being able to do something like
similar to how JSX works (ignore null/undefined/boolean as well). I also would expect I'm also actually ok with the current behavior (well, besides |
@ntkoopman ah yeah code Thanks for the PR! |
Released as 4.10.0 |
I wanted to add a string and thought it wasn't obvious on how to do it. Only while implementing this I found that I could have just used
JSON.stringify
, but I thinkliteralOf
should just support strings as well (and basically everything else).This PR doesn't touch
deepGenerate
, which means thatcode`const a = ${map}`
will work correctly butcode`const a = ${[map]}`
doesn't. The issue is that at the pointdeepGenerate
is executed, all the aliasing has already happened so it's too late to construct a Literal. Fixing this would require quite a lot of refactoring.Another difference is that
Literal
will create the literal at construction time, whiledeepGenerate
only generates code at the end:An an actual issue: if you put a
MaybeOutput
inside aLiteral
it will never show up.