benjamn / benjamn/recast

Return statements are always printed generically if anything in the return value has changed.

Open
#552 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.3k
Forks
363
Avg merge
3d 8h
Merged PRs (30d)
3

Description

I understand that this is WAI - the code near the end if findChildReprints() indicates that this is a precautionary measure to avoid problems with ASI. I'd like the ability to disable this feature so that return statements use the normal rules for reprinting. The codebase I'm working with always has semicolons and the lack of reprinting causes problems with jscompiler type casts:

If I start with:

return /** @type {string} */ (foo());

and change "foo" to "bar", the output is:

return (
/** @type {string} */ bar();
);

This is no longer accepted by the jscompiler since jscompiler casts require parentheses around the value being cast.

Re-enabling return statement reprinting via an option should be relatively simple. I suspect the biggest problem is plumbing the option down into the code. Passing an options arg to getReprinter() seems reasonable, but I'm not sure if it would be better to explicitly pass the options through the various findReprint functions or capture the options in a local scope and move the findReprint functions into that scope. If you have a preferred way of doing this, let me know and I'll work on making the change.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the code near the end of findChildReprints() and trace how getReprinter() and the findReprint functions are called. Determine where an option can control generic return-statement printing without changing the existing default behavior. Done means the option allows normal return reprinting for projects using semicolons, while the current precaution remains the default.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.