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

Bumped ast-types version #766

Merged
merged 4 commits into from
Oct 2, 2020
Merged

Bumped ast-types version #766

merged 4 commits into from
Oct 2, 2020

Conversation

ethancrook99
Copy link
Contributor

No description provided.

@ethancrook99
Copy link
Contributor Author

I'm not sure how to fix the failing test... I looked through the code, but I couldn't identify what change I needed to make to handle the new types. Any pointers?

@eventualbuddha
Copy link
Collaborator

My guess is that the new ast-types adds a new node type that recast doesn't know about?

@ethancrook99
Copy link
Contributor Author

@eventualbuddha It's the new ChainElement and ChainExpression types, I'm just not sure how to make recast recognize new types

@mjfaga
Copy link

mjfaga commented Sep 19, 2020

I updated the test to work past this here: #769

@benjamn
Copy link
Owner

benjamn commented Sep 20, 2020

@ethancrook99 The reason these tests exist is to ensure that the Recast pretty-printer is able to print the new AST types, so the conservative pretty-printing algorithm can fall back to generating valid (if somewhat reformatted) code wherever the original AST has been modified.

Where the AST has not been modified, Recast is able to copy the original code directly to the output (give or take some reindentation). In other words, Recast can often get away with not actually knowing how to print unchanged AST nodes, but it will fail badly when AST nodes involving a ChainExpression are modified or added to the AST, because it can't just copy the original code in those cases.

If you need [email protected] specifically because you want to write AST transforms using Recast that involve ChainExpression AST nodes, then you will almost certainly run into cases where you need Recast to be able to print these nodes, so I trust you can understand why simply adding the new types to the switch statement without actually implementing them (like #769 does) would be side-stepping the issue.

In short, the test failures are telling us that we need to add printer cases to lib/printer.ts (where you can find lots of examples of similar code). I can tackle that soon, unless you want to give it a try?

@ethancrook99
Copy link
Contributor Author

@benjamn I can give it a shot! I'll let you know if I need any guidance

@ethancrook99
Copy link
Contributor Author

I added possible implementations for the new types in printer.ts, but I feel like I may have oversimplified ChainExpression. I just copied directly from ExpressionStatement--should I have done something different here?

Copy link
Collaborator

@eventualbuddha eventualbuddha left a comment

Choose a reason for hiding this comment

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

Close, should be easy to fix.

lib/printer.ts Outdated Show resolved Hide resolved
@mjfaga
Copy link

mjfaga commented Sep 22, 2020

Thanks for putting in the remaining effort on this. I hadn't had a chance to review the patterns in play just yet and noticed the TODOs in there and followed that in the short term to resolve an issue I ran into locally on this very thing which did not require printing the Optional Chain operator.

Apologies for the side-step @benjamn 👍

@eventualbuddha
Copy link
Collaborator

Wasn't there a test? Where'd that go?

@ethancrook99
Copy link
Contributor Author

I never actually added the test, I couldn't figure out how to get it working properly. I put the code that I did have in my reply to the above thread though, if you have any suggestions on how to fix it then I'll add the test back in

@ethancrook99
Copy link
Contributor Author

Can I get some guidance on how to make a test for "a(b?.c)" not printing semicolons? I can't quite figure out how to follow the same pattern as the other printer tests.

@eventualbuddha
Copy link
Collaborator

I wouldn't worry about the semicolon thing specifically. Just have a test that generically prints a chain element.

@ethancrook99
Copy link
Contributor Author

@eventualbuddha I added a couple of tests, looks like everything is working together nicely now

@eventualbuddha eventualbuddha merged commit ae0a51e into benjamn:master Oct 2, 2020
benjamn added a commit that referenced this pull request Oct 12, 2020
benjamn added a commit that referenced this pull request Oct 12, 2020
@benjamn
Copy link
Owner

benjamn commented Oct 12, 2020

@ethancrook99 @eventualbuddha Just published these changes to npm as [email protected], with some additional tests and tweaks in #783. Thanks for working on this! 🙌

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.

4 participants