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

fix(vue): do not add invalid semicolon for event attr #5418

Merged
merged 2 commits into from Nov 10, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/language-html/printer-html.js
Expand Up @@ -873,7 +873,9 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/;
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/;

const value = getValue();
const value = getValue()
// https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104
.trim();
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, how is this related to the semicolon?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to check if we should use __js_expression (no semicolon) or babylon (semicolon) by looking at simplePathRE.test(value) || fnExpRE.test(value).

return printMaybeHug(
simplePathRE.test(value) || fnExpRE.test(value)
? textToDoc(value, { parser: "__js_expression" })
Expand Down
32 changes: 32 additions & 0 deletions tests/html_vue/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -25,6 +25,12 @@ exports[`attributes.vue - vue-verify 1`] = `
:class="(() => { return 'hello' })()"
:key="index /* hello */ "
:key="index // hello "
@click="() => {console.log(test)}"
@click="
() => {
console.log(test);
}
"
></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
Expand Down Expand Up @@ -71,6 +77,16 @@ exports[`attributes.vue - vue-verify 1`] = `
:key="
index // hello
"
@click="
() => {
console.log(test);
}
"
@click="
() => {
console.log(test);
}
"
></div>

`;
Expand Down Expand Up @@ -100,6 +116,12 @@ exports[`attributes.vue - vue-verify 2`] = `
:class="(() => { return 'hello' })()"
:key="index /* hello */ "
:key="index // hello "
@click="() => {console.log(test)}"
@click="
() => {
console.log(test);
}
"
></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
Expand Down Expand Up @@ -146,6 +168,16 @@ exports[`attributes.vue - vue-verify 2`] = `
:key="
index // hello
"
@click="
() => {
console.log(test);
}
"
@click="
() => {
console.log(test);
}
"
></div>

`;
Expand Down
6 changes: 6 additions & 0 deletions tests/html_vue/attributes.vue
Expand Up @@ -22,4 +22,10 @@
:class="(() => { return 'hello' })()"
:key="index /* hello */ "
:key="index // hello "
@click="() => {console.log(test)}"
@click="
() => {
console.log(test);
}
"
></div>