Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/language-vue/printer-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@
const embed = require("./embed");
const docBuilders = require("../doc").builders;
const concat = docBuilders.concat;
const hardline = docBuilders.hardline;

function genericPrint(path, options, print) {
const n = path.getValue();
const res = [];
let index = n.start;
let printParent = typeof n.end === "number";

path.each(childPath => {
const child = childPath.getValue();
res.push(options.originalText.slice(index, child.start));
res.push(childPath.call(print));
index = child.end;
if (typeof child.end === "number") {
index = child.end;
} else {
printParent = false;
}
}, "children");
res.push(options.originalText.slice(index, n.end));

if (printParent) {
res.push(options.originalText.slice(index, n.end));
}

// Only force a trailing newline if there were any contents.
if (n.tag === "root" && n.children.length) {
res.push(hardline);
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.

What happens if there’s already a trailing (or more) new line, is it going to add one more?

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.

It does... I tried to do a right trim on the content but it didn't work.

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.

I also tried to normalize this but figured it would not be worth it. I think that the best way forward is to pretty print the first depth of html for vue files. This way we clean up the code a bit more and will handle this newline.

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.

Actually no, it works just fine as is.

}

return concat(res);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/multiparser_vue/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`template-bind.vue 1`] = `
<div v-bind:id=" ok ? 'YES' : 'NO' "></div>
<button @click=" foo ( arg, 'string' ) "></button>
</template>

`;

exports[`template-class.vue 1`] = `
Expand All @@ -37,6 +38,7 @@ exports[`template-class.vue 1`] = `
>
</h2>
</template>

`;

exports[`vue-component.vue 1`] = `
Expand Down Expand Up @@ -79,4 +81,5 @@ p {
text-align: center;
}
</style >

`;
Loading