You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 normalh
call by this plugin. Indeed, author offoo
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.The text was updated successfully, but these errors were encountered: