Skip to content

[WIP] Refactor JSX to use intermediate representation#2976

Closed
karl wants to merge 1 commit intoprettier:masterfrom
karl:jsx-refactor
Closed

[WIP] Refactor JSX to use intermediate representation#2976
karl wants to merge 1 commit intoprettier:masterfrom
karl:jsx-refactor

Conversation

@karl
Copy link
Copy Markdown
Collaborator

@karl karl commented Oct 4, 2017

This is a currently broken work in progress refactor of how we handle JSX. It aims to introduce an intermediate representation that will make it easier for us to output following different formatting rules.

This should make it possible to re-use the same code for JSX, HTML, and FBT (Facebook translations).


The basic idea I wanted to explore here was an intermediate representation format.

The idea is to have a collection of alternating children and separators (one of space, new line, or nothing).

<div><br /><br /></div>
children = [nothing, BR, nothing, BR, nothing];

---

<div> Some text <br /> </div>
children = [space, "Some text", space, BR, space];

---

<div>
  <br />
  <br />
</div>
children = [newline, BR, newline, BR, newline];

From this intermediate representation we could then generate the output using one of 3 sets of rules:

  • JSX
  • FBT
  • HTML

When playing around with this the idea seemed to work OK, although if I recall correctly there are some edge cases that make it difficult to cleanly separate the AST -> Intermediate -> Prettier doc stages.

@karl karl changed the title [WIP] [WIP] Refactor JSX to use intermediate representation Oct 4, 2017
@suchipi suchipi mentioned this pull request Oct 16, 2017
@duailibe
Copy link
Copy Markdown
Collaborator

@karl Is there anything I can do to help to go forward with this? :-)

@karl
Copy link
Copy Markdown
Collaborator Author

karl commented Nov 17, 2017

Please feel free to take over from me as I’m afraid I just don’t have time to work on this at the moment.

If you’d like to do that I’d be happy to take you through my thinking and help get you up to speed!

@azz azz added the status:wip Pull requests that are a work in progress and should not be merged label Jan 9, 2018
@j-f1
Copy link
Copy Markdown
Member

j-f1 commented Jun 28, 2018

Closing this for now since we have #4753. Feel free to pick this up once that’s been merged!

@j-f1 j-f1 closed this Jun 28, 2018
@karl
Copy link
Copy Markdown
Collaborator Author

karl commented Jun 28, 2018

Good call @j-f1

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Sep 26, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:wip Pull requests that are a work in progress and should not be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants