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

fix(core): 🐛 Preserve meaningful whitespace #1219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TzviPM
Copy link

@TzviPM TzviPM commented Jul 8, 2023

Fixes #1218

Description

Some code generators were joining blocks with newlines (\n), which, when run through the dedent helper, would then trim any trailing whitespace. This ended up causing problems with significant whitespace in some scenarios.

This PR simply changes the join operation to use the empty string. The parser for mitosis already preserves the significant whitespace, so this makes the output components more closely resemble their mitosis source code. Prettier can still be used to format the output code, which will use a syntax tree that preserves meaningful whitespace while avoiding excessively long line lengths and adding stylistic line breaks.

The main focus for review should be:

  1. Ensure that the large changes to snapshots are correct.
  2. Considering that many generators have the same structure in terms of a componentToX function that calls a blockToX function recursively and joins children together, would it make sense to have a helper method for the join operation so that this type of change can be made more accurately across generators?

@TzviPM TzviPM requested a review from samijaber as a code owner July 8, 2023 14:58
@vercel
Copy link

vercel bot commented Jul 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mitosis-fiddle ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 8, 2023 5:59pm

Copy link
Author

Choose a reason for hiding this comment

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

This seems unrelated to my changes. It must have been regenerated when I updated the snapshots. Please confirm if this is correct, or if I should revert this file

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you on the latest main? This change shouldn't happen.

@nx-cloud
Copy link

nx-cloud bot commented Jul 10, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 2dd44ba. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

@samijaber
Copy link
Contributor

You also need to run yarn run fmt to lint your PR

@samijaber
Copy link
Contributor

Awesome PR, thanks for raising it! I believe this also helps us close #310, which was waiting on React/Solid generator to stop creating new lines for each text block. :)

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.

Meaningful whitespace is not preserved
2 participants