-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
feat(babel): Babel plugin: debug-label #697
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/jotai/89DWimBFRM4SqtcTzNZy3irW7utX |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit efff15c:
|
Is this ready to play with? How can we try? |
If you want to try it, you can use the CSB build and add this to your {
"presets": [],
"plugins": ["jotai/babel-plugin/debug-label"]
}
|
https://codesandbox.io/s/jotai-nextjs-babel-plugin-kc8sd |
Add tests
…jotai into babel-plugin-debug-label
I think it's getting close to ready. Please review and try it. Happy to get more test cases. |
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 think this is good for the initial version.
There could be many edge cases that need to be covered later, but it's more important to let it go.
Let's label this as "experimental" in the release note.
).toMatchInlineSnapshot(` | ||
"export const countAtom = atom(0); | ||
countAtom.debugLabel = \\"countAtom\\"; | ||
const atoms = atom(0); |
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.
How does this resolve naming conflict?
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.
Good catch. If someone has an atom called atoms
, it would break - Do you have a good idea how to guard against it?
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.
It can be any variable or even a function declaration function atom() { return 1 }
.
I would simply ignore if it finds a conflict.
This change adds a Babel plugin to Jotai for adding debug labels automatically to atoms.
Partially fixes #487, as I want to split the PRs as much as possible.
The plan is to create the following plugins:
jotai/babel/plugin-debug-label
- Handles debug labeljotai/babel/plugin-react-refresh
- Handles React refresh supportAnd the following preset to compose the plugins:
jotai/babel/preset
EDIT:
If you wanna try it out, use the new sandbox or install the CSB build and add the following to your
.babelrc
: