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

Implement parser switching (HTML, Vue, styled-components) #2086

Merged
merged 2 commits into from
Jun 10, 2017

Conversation

azz
Copy link
Member

@azz azz commented Jun 10, 2017

This PR introduces a general method for switching between different parsers in the middle of a print.

To prove the concept, I have implemented:

  • HTML → CSS via <style>
  • HTML → JavaScript via <script>
  • HTML → TypeScript via <script lang="ts">
  • JS/TS → CSS for styled-components forms:
    Button.extend` color: rebeccapurple`
    styled.button` color: firebrick`

I also moved the existing styled-jsx support (#1984) to the new method.

Currently, styled-components and styled-jsx are only formatted if there are no expressions in the template string.

#1948, #1882.

class Foo<T> {
constructor(private foo: keyof Apple) {}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm aware of the trailing hardline but I don't know a way to remove it without hacking it out of the doc.

Copy link
Contributor

Choose a reason for hiding this comment

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

The CSS piece is hacking the doc. I think the "right" thing to do is to make printers not output a final hardline and have the outer format call add it.

@azz azz changed the title Implement parser switching Implement parser switching (HTML, Vue, styled-components) Jun 10, 2017
if (
ast.type === "TaggedTemplateExpression" &&
ast.tag.type === "MemberExpression"
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not enough. Relay.QL would match. I think you need to check if the left is style or the right is extends.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, this is in clean-ast!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll copy across the logic from the other file.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries, I actually think it's a good idea to make this one lose, and not have them synced.

@vjeux vjeux merged commit d1b94c5 into prettier:master Jun 10, 2017
@vjeux
Copy link
Contributor

vjeux commented Jun 10, 2017

This is huge! You're on fire! Keep going :)

@pomber
Copy link
Contributor

pomber commented Jun 10, 2017

Awesome!
Is anyone working on formatting css template literals containing expressions? If not, I could take a look

@azz
Copy link
Member Author

azz commented Jun 10, 2017

Go ahead! I honestly have no idea how that will work...

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 20, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants