-
Notifications
You must be signed in to change notification settings - Fork 31
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
Allow JS plugin to nest token output #79
Conversation
🦋 Changeset detectedLatest commit: 7885492 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
if (options?.deep) { | ||
setToken(ts.modes, `${token.id}.${modeName}`, `${tokenTypes[token.$type]}['$value']`, true); | ||
} else { | ||
(ts.modes[token.id] as TSResult['modes'])[modeName] = `${tokenTypes[token.$type]}['$value']`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 I’m so sorry you had to wade through the manual .d.ts
file generation. I don’t think a lot of this code was written as well as I’d like to be easy to refactor / work on.
But this all looks fantastic 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it wasn’t that bad, it was just very specific! You did most of the work with the serializer function 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a lot of codegen stuff, taking a more AST approach is “cleaner” in some ways. But you pay for it in other ways in terms of upfront timesink / wading through the land of obscure bugs, not to mention when you set it down for a while, the confusion of “wait how does this thing work again?”
String mashing is sloppy but it’s real easy to compare “output good” vs “output bad” and know exactly where to make the adjustment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 This looks great, thank you!
Also I’m not opinionated on the name either. deep
makes sense to me!
I don’t have any feedback; this looks great 🙂
Changes
This implements a solution for #73, allowing the output from the JS plugin to be a nested object rather than a flat object with key IDs in dot-notation.
This converts JS, TS, mode, and meta data to all be nested (see the test
want
files). By default, this mode will be off to preserve backwards compatibility and can be turned on with thedeep
key in the plugin config. I'm not attached to that name, so I'm happy to change it.Some internal type information had to change a little bit, but not much, and a new (safer? maybe, not sure)
serializeTS
method was added for simplicity. Additionally, a new utilobject.set
was added for naive deep setting of a nested object key safely. It doesn't cover all the cases that something likelodash.set
would, but that's ok with the current implementation of the library, and it's documented.How to Review
Tests are the most revealing for final output, and the actual implementation is a few new functions and some refactorings to use them.