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

Children print rework #160

Merged
merged 26 commits into from
Jan 2, 2021
Merged

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Nov 9, 2020

Goals:

Simon Holthausen added 2 commits November 2, 2020 11:05
Goals:
- switch logic around: prepare nodes before printing docs, try to avoid modifying printed result
- respect user's wish to have line breaks sveltejs#143 sveltejs#117
- generally try to be more in line with how prettier formats things

TODO:
- either get tag break logic on par with prettier (breaking > into new lines etc) or adjust tests
- more readable tag breaking logic for multiple children tags
- tidy up
Copy link
Contributor

@ehrencrona ehrencrona left a comment

Choose a reason for hiding this comment

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

This looks great! It's nice to get rid of the weird keepIfLonely and the manipulation of the tree. I haven't looked at the code in a while and I must admit I'm not always sure what's going on, but it is simpler than the previous code. I'd generally welcome a couple of more comments though.

src/print/node-helpers.ts Show resolved Hide resolved
src/print/index.ts Outdated Show resolved Hide resolved
src/print/index.ts Show resolved Hide resolved
src/print/index.ts Outdated Show resolved Hide resolved
@dummdidumm
Copy link
Member Author

Thanks for the early feedback! Yeah this is in a rough state right now, I'll certainly add more comments and/or split out things into separate functions for more readability. All these different cases you need to keep in mind certainly don't make this easier 😄

@ehrencrona
Copy link
Contributor

It's incredibly difficult to overview the different cases, but structuring them according to the three cases you identified certainly seems to make it easier.

@dummdidumm dummdidumm marked this pull request as ready for review December 18, 2020 17:48
@dummdidumm
Copy link
Member Author

dummdidumm commented Dec 18, 2020

This is finished now I hope. I would make this part of a 2.0 release along with some other breaking changes (default order change) just because so many things have changed and the way things break has slightly changed in some situations.


const unsupportedLanguages = ['coffee', 'coffeescript', 'pug', 'styl', 'stylus', 'sass'];

export function isInlineElement(node: Node) {
return node.type === 'Element' && inlineElements.includes(node.name as TagName);
}

export function isBlockElement(path: FastPath, node: Node): node is ElementNode {
// TODO switch to a list of tags instead
Copy link
Member Author

@dummdidumm dummdidumm Dec 18, 2020

Choose a reason for hiding this comment

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

The idea is to switch to a defined list of block elements instead of a defined set of inline elements. That will deal with #159

Simon Holthausen added 2 commits December 19, 2020 00:27
@dummdidumm dummdidumm merged commit 8a59e40 into sveltejs:master Jan 2, 2021
@dummdidumm dummdidumm deleted the tag-breaks-rework branch January 2, 2021 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants