Skip to content

Commit 58c6486

Browse files
committed
refactor(compiler-vapor): skip unnecessary whitespace between attributes
1 parent 46a5c60 commit 58c6486

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export function render(_ctx) {
399399
400400
exports[`compiler: element transform > static props 1`] = `
401401
"import { template as _template } from 'vue';
402-
const t0 = _template("<div id=foo class=bar title=\\"has whitespace\\" data-targets=\\"foo>bar\\"></div>", true)
402+
const t0 = _template("<div id=foo class=bar title=\\"has whitespace\\"data-targets=\\"foo>bar\\"></div>", true)
403403
404404
export function render(_ctx) {
405405
const n0 = t0()

packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ describe('compiler: element transform', () => {
577577
)
578578

579579
const template =
580-
'<div id=foo class=bar title="has whitespace" data-targets="foo>bar"></div>'
580+
'<div id=foo class=bar title="has whitespace"data-targets="foo>bar"></div>'
581581
expect(code).toMatchSnapshot()
582582
expect(code).contains(JSON.stringify(template))
583583
expect(ir.template).toMatchObject([template])

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,19 @@ function transformNativeElement(
221221
getEffectIndex,
222222
)
223223
} else {
224+
let needsQuoting = false
225+
224226
for (const prop of propsResult[1]) {
225227
const { key, values } = prop
226228
if (key.isStatic && values.length === 1 && values[0].isStatic) {
227229
const value = values[0].content
228230

229-
template += ` ${key.content}`
231+
if (!needsQuoting) template += ` `
232+
template += key.content
230233

231234
if (value) {
232235
// https://html.spec.whatwg.org/multipage/introduction.html#intro-early-example
233-
const needsQuoting = /[\s>]|^["'=]/.test(value)
236+
needsQuoting = /[\s>]|^["'=]/.test(value)
234237

235238
if (needsQuoting) {
236239
template += `="${value}"`

0 commit comments

Comments
 (0)