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

HTML: Add parse5/htmlparser2 printer #2083

Merged
merged 1 commit into from Jun 10, 2017

Conversation

Projects
None yet
3 participants
@azz
Member

azz commented Jun 10, 2017

This PR introduces the parse5 parser, producing a htmlparser2 AST.

Parse5 was chosen due to compliance, and the ability to switch between different AST representations.

The htmlparser2 AST was chosen since it is simpler to work with in prettier. parse5's default AST doesn't track node.kind in the way we would like.

Similar to the method used to implement CSS template string formatting (#1948), the idea is to first introduce a fully compliant HTML5 printer, then use heuristics to switch to:

  • Glimmer parser, based on <script type> or <template lang>.
  • TypeScript or Babylon parsers, based on <script type> or <script lang>.
  • PostCSS parser, based on <style>.

#1951, #1882.

@vjeux

This comment has been minimized.

Collaborator

vjeux commented Jun 10, 2017

Omg, so exciting!

@vjeux vjeux merged commit d00956d into prettier:master Jun 10, 2017

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@vjeux

This comment has been minimized.

Collaborator

vjeux commented Jun 10, 2017

cc @karl to see if we can share the implementation with jsx :)

@azz

This comment has been minimized.

Member

azz commented Jun 10, 2017

Forgot to run AST_COMPARE, I'll open another PR in a moment.

@vjeux

This comment has been minimized.

Collaborator

vjeux commented Jun 10, 2017

No worries, this is seriously so exciting :)

@karl

This comment has been minimized.

Collaborator

karl commented Jun 10, 2017

This is very exciting!

Off the top of my head I'm not sure of the best way to share the formatting logic with JSX, but I'm hopefully we can share some logic.

The JSX formatting is about to get an overhaul in #1831.

We should probably base the HTML formatting on the logic in that PR. It may make sense for HTML formatting to initially take a copy of the JSX logic and modify it as needed, as HTML has a lot fewer edge cases (no JSX whitespace or Facebook translation pipeline support).

Once we have HTML formatting sorted we could then start looking at how it and JSX formatting can share code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment