diff --git a/src/language-html/printer-html.js b/src/language-html/printer-html.js index 98c0fde5fc71..4a714bc6e5ea 100644 --- a/src/language-html/printer-html.js +++ b/src/language-html/printer-html.js @@ -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(); return printMaybeHug( simplePathRE.test(value) || fnExpRE.test(value) ? textToDoc(value, { parser: "__js_expression" }) diff --git a/tests/html_vue/__snapshots__/jsfmt.spec.js.snap b/tests/html_vue/__snapshots__/jsfmt.spec.js.snap index 776250f5383f..365ddc220cc9 100644 --- a/tests/html_vue/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_vue/__snapshots__/jsfmt.spec.js.snap @@ -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); + } + " > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`; @@ -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); + } + " > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`; diff --git a/tests/html_vue/attributes.vue b/tests/html_vue/attributes.vue index 211fc141e480..80a6c87bd9c1 100644 --- a/tests/html_vue/attributes.vue +++ b/tests/html_vue/attributes.vue @@ -22,4 +22,10 @@ :class="(() => { return 'hello' })()" :key="index /* hello */ " :key="index // hello " + @click="() => {console.log(test)}" + @click=" + () => { + console.log(test); + } + " >