Skip to content
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

Replace JSXElement node on 'exit' instead of 'enter'. #86

Closed
nandin-borjigin opened this issue Nov 14, 2019 · 0 comments · Fixed by #87
Closed

Replace JSXElement node on 'exit' instead of 'enter'. #86

nandin-borjigin opened this issue Nov 14, 2019 · 0 comments · Fixed by #87

Comments

@nandin-borjigin
Copy link
Contributor

nandin-borjigin commented Nov 14, 2019

Current behavior of this plugin is replacing the entire JSXElement node, along with its children, on enter phase, which hinders other plugins from visiting decendants of that JSXElement recursively.

Usecase:

Suppose that a plugin foo is to collect thrid party component references in every file and then emit a file that imports and globally registeres all used components (common practice when the third party library provides tons of components but only a few of them is of interest).

Problem:

With this (referring to @vue/babel-plugin-transform-vue-jsx) plugin applied, foo can only visit the root JSXElement and all of its children would not be visited because they would have been replaced with normal h call by this plugin. Indeed, author of foo can traverse the children of root JSXElement by himself/herself but that would be duplicating the visitor pattern provided by babel.

Solution:

Changing this plugin's visitor to replace the original jsx node on exit phase would make other plugins (which are, by assumption, applied prior to this plugin) have a chance to recursively visit all the jsx nodes, without affecting the original behavior of this plugin.

Reference:

Both babel-plugin-jsx and babel-plugin-transform-react-jsx(which inherits the former) are applying the actual transformation on exit phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant