-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix source snippet generation #13
Fix source snippet generation #13
Conversation
Okay, ready to merge (I had a brain fart remembering if I parsed the component names correctly lol) |
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 generally looks good to me. There are a bunch of stray console.logs that should probably be cleaned up. And stylistically I'd prefer moving the try/catch in the generateSource function up a level to the surrounding scope, but that's subjective.
Biggest thing this needs is unit tests for the new source generation, to document the current behavior and make sure it doesn't regress when the code or dependencies get updated.
@shilman Okay, I cleaned up the code and added testing. And while at it, I also refactored the CI to be cleaner and added warnings for edge cases in the parser. |
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.
Looks great!!!
One small thing is are you supposed to bump the version in the PR or should you let the release script bump the versions? Asking because I'm not familiar with the release process in the repo.
@shilman Yeah, PRs handle bumping the version (easier than trusting a CD script to bump patch/minor/major correctly). |
This will fix:
A little bit on how code snippet generation will work after this PR:
SolidJS doesn't have a VDOM to get info on components and their children and handlers and whatnot.
So instead, I've opted for extracting the source code of stories and transforming them into JSX.
To do this, I'm using the source code taken from csf-tools and running Babel's standalone parser on it to get an AST.
The AST is then transformed, and then Babel's standalone generator turns it back into JS.
What is returned is some JSX with some basic formatting.
(I've messed around with different parsers (acorn, babel, @typescript-eslint/typescript-estree, typescript) and even formatters (prettier, biomejs), and this is what worked best while not being too expensive)