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

Add optional JSX-Support while keeping original behaviour the default #57

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

allesklarbeidir
Copy link

Esquery is a great module which I love to use.
However, unfortunately one was not able to use it with code which includes JSX-Expressions because the "normal" estraverse module is used. Luckily there already exists an estraverse-fb module which adds JSX-Support to the estraverse module in a "plug-in" way.

With this pull-request we can integrate the option to use "estravese-fb" instead of pure "estraverse" and enable querying of JSX-containing code. The default behaviour remains as it was without this modification. The readme is also updated to reflect the new option for JSX-Support.

Outsourced the module-creator function and added the estraverse-module as parameter so that we can use a different version as drop-in replacement.
Changed default entry-point script so that its behaviour does not change in respect to the original esquery-module.
Only change here is that it now calls the outsourced esquery module-creator function - but with the standard estraverse module as parameter.
require("esquery/jsx") now loads this script which creates the module with the estraverse-fb module instead of the original one.
This adds support for JSX-Nodes in a "plug-in" way because estraverse-fb also just extends the estraverse module and this way the most up to date estraverse module can always be used.
@allesklarbeidir
Copy link
Author

I'd propose to merge this pull request before any other modification is made to the repository so that jsx support is preserved for future versions.

@jorgerro
Copy link

jorgerro commented Oct 4, 2017

+1
It would be great to have this support so we can query ASTs generated with esprima from sources containing JSX.

@thabti
Copy link

thabti commented Oct 6, 2018

Thank for raising this PR.

Would be great to get this merged in. I have forked the repo and published it NPM with jsx support:

[email protected]

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 this pull request may close these issues.

3 participants