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 walk support #87

Closed
wants to merge 1 commit into from
Closed

Add walk support #87

wants to merge 1 commit into from

Conversation

adrianheine
Copy link
Member

This is on top of #86.

@RReverser
Copy link
Member

Hmm, are many consumers really using built-in walk instead of estraverse or similar?

@adrianheine
Copy link
Member Author

I'm planning on using it in bublé, but I can ship it myself. In general, I don't know what the future for acorn walk is, marijn and I had a quick talk about it in acornjs/acorn#656 (comment).

@lahmatiy
Copy link

lahmatiy commented Jun 21, 2018

@RReverser It's quite confusing when you switch to acorn-jsx, attempt to walk through AST following readme but get the error:

TypeError: base[type] is not a function

It was surprising to me that acorn-jsx doesn't extend the walker when it can, and I need to use "estraverse or similar" with no mention about it in acorn or acorn-jsx readmes.

I believe, since a walker is a part of acorn it should be extended by acorn-jsx as well.

walk.js Outdated
base.JSXOpeningFragment = base.JSXEmptyExpression = base.JSXIdentifier = base.JSXText = base.JSXClosingFragment = base.Identifier;
base.JSXAttribute = function(node, st, c) {
c(node.name, st);
c(node.value, st);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node.value can be null – if (node.value) is needed here

walk.js Outdated
for (var i = 0; i < node.children.length; ++i) {
c(node.children[i], st);
}
c(node.closingElement, st);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node.closingElement can be null – if (node.closingElement) is needed here

for (var i = 0; i < node.children.length; ++i) {
c(node.children[i], st);
}
c(node.closingFragment, st);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node.closingFragment can be null – if (node.closingFragment) is needed here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me an example for this case?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According regular rules <React.Fragment /> is a valid statement, even looks odd. You also can use <React.Fragment children={props.children} /> or <React.fragment {...props} /> for some reasons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a syntax level, that's just JSXElements. A fragment in terms of syntax is something like <></>.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, yep, probably checking is not required here, since anonymous fragments can't have attributes.

@beheh
Copy link

beheh commented Jul 10, 2018

Looking forward to seeing this landed and released! I'd like to contribute using this in the i18next-scanner project instead of the unmaintained acorn-jsx-walk. So far all the tests in i18next-scanner pass after switching to this project/fork and adding the conditionals as described by lahmatiy.

@adrianheine do you think you could get the minor changes in this PR, or @lahmatiy just manually add them and do a release? Thanks!

@adrianheine
Copy link
Member Author

Thanks for reminding me, I actually forgot this was my PR. I addressed the feedback.

@beheh
Copy link

beheh commented Jul 17, 2018

Would love to see this landed and released soon! @RReverser

@chacestew
Copy link

Hopeful for this to land soon. It would be a big fix for i18next-scanner.

@adrianheine
Copy link
Member Author

Closing this in favor of sderosiaux/acorn-jsx-walk#3.

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.

5 participants