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
Group HyperScript tag #6330
base: main
Are you sure you want to change the base?
Group HyperScript tag #6330
Conversation
@lydell @streamich @tusharmath How do I keep HyperScript curly brace or short props inline? My patch groups the tag, but you might have a better solution, as you've talked about this earlier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @prettier/core
@nykula I would try to do it same as in JSX—if there are few attributes, keep them on one line. <div className={className}>Hello</div> would be h('div', {className}, 'Hello') and <div
{...rest}
style={style}
className={(rest.className || '') + className}
>
{children}
</div> would be h('div', {
...rest,
style,
className: (rest.className || '') + className,
},
children
) |
@streamich Yes matching JSX compactness is the goal. I did figure out how to stick the function name and tag together. Where I'm stuck is how to technically get { on the same line. Prettier has a group tool. Lets one treat multiple nodes in a sequence independent of their siblings, as a separate sequence, making it possible to keep short literal tokens in one line and other tokens multiline. However the {, unlike the function name and tag, is not an individual node, but a part of an object literal which is a node in its entirety. Prettier forces all nodes in a sequence onto split lines when they don't all fit in one line, even when they consitute a group independent of other nodes. When I add the object literal to the group, it outputs AFAIR either one of these no matter what solution I try:
I kept the second so far. Would be nice if anyone reading this cloned the pull request code and played with trying to get the { inline where I have the 'div', but leave the rest of the object split with newlines and no indent, without resulting in that extra newline at the end, thus replicating your example. |
You could put just the children in the group, something like this: concat([
'h(',
name,
', ',
props,
group(indent(concat([hardline, ...children]))),
hardline,
')',
]) |
This is a good start, perhaps try to get the first and second arguments of a function on one line if they are <80 width combined, separately of 3rd or 4th etc argument length? |
@PascalPixel It'd be great if you could try implementing that, maybe in a new pull request. For the HyperScript code I've been writing more recently, I apply a different tool, |
CHANGELOG.unreleased.md
file following the template.✨Try the playground for this PR✨