Skip to content

Vue: pretty-print binding syntax#2108

Merged
azz merged 3 commits intoprettier:masterfrom
azz:feat/vue-class
Jun 14, 2017
Merged

Vue: pretty-print binding syntax#2108
azz merged 3 commits intoprettier:masterfrom
azz:feat/vue-class

Conversation

@azz
Copy link
Copy Markdown
Member

@azz azz commented Jun 12, 2017

For #2097, this is my work-in-progress attempt at pretty-printing the contents of binding attributes for Vue.

@azz azz force-pushed the feat/vue-class branch 2 times, most recently from a1c1f21 to 3501dab Compare June 12, 2017 07:11
return {
text: node.value,
options: {
parser: parseJavaScriptExpression,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can use the custom parser API here!

return concat([name, '="', attribs[name], '"']);

// FastPath requires the next node to be a property of the current one
node._currentAttribute = {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the least worst way of doing this that I could think of.

The correct way would be to reshape the AST between parsing and printing, but I'm not sure if that would hurt performance?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're already doing it for css, I would also do it for HTML. We haven't done much performance work so far and it's been reasonable.

I'd rather do the right thing for now and when we decide that perf is important, then measure and optimize the things that are actually taking a lot of time and make trade-offs at that point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding it to the ast in this way is reasonable to me by the way, if you move it to the parsing phase, I'll be happy with it.

transformDoc: doc =>
util.hasNewlineInRange(node.value, 0, node.value.length)
? doc
: docUtils.removeLines(doc)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Stopgap to remove the trailing hardline.

type: "File",
program: ast.program.body[0].expression
};
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is so nice!

@vjeux
Copy link
Copy Markdown
Contributor

vjeux commented Jun 12, 2017

Sounds good to me, I only have 2 comments.

@vjeux
Copy link
Copy Markdown
Contributor

vjeux commented Jun 13, 2017

Can't wait to land this :)

* v-bind:id="'list-' + id"
* v-if="foo && !bar"
*/
if (/(^v-)|:/.test(node.name) && !/^\w+$/.test(node.value)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you may want to also include the @ , for things like @click="someFunction()"

@azz azz force-pushed the feat/vue-class branch from 3501dab to 07c4ed0 Compare June 14, 2017 11:36
@azz azz changed the title [WIP] Vue: pretty-print binding syntax Vue: pretty-print binding syntax Jun 14, 2017
@azz azz force-pushed the feat/vue-class branch from 07c4ed0 to a1c5b47 Compare June 14, 2017 12:04
@azz azz force-pushed the feat/vue-class branch from a1c5b47 to 2cf69f0 Compare June 14, 2017 12:19
@azz azz merged commit b7e1c36 into prettier:master Jun 14, 2017
@azz azz deleted the feat/vue-class branch June 14, 2017 12:33
@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.

3 participants