Skip to content

Commit 6c6fe2c

Browse files
moushichengyyx990803
authored andcommittedSep 27, 2022
fix(compiler-dom): remove v-bind boolean attribute with literal false value when stringifying (#6635)
fix #6617
1 parent 57ffc3e commit 6c6fe2c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,29 @@ describe('stringify static html', () => {
410410
})
411411
})
412412

413+
// #6617
414+
test('should remove boolean attribute for `false`', () => {
415+
const { ast } = compileWithStringify(
416+
`<button :disabled="false">enable</button>${repeat(
417+
`<div></div>`,
418+
StringifyThresholds.NODE_COUNT
419+
)}`
420+
)
421+
expect(ast.hoists[0]).toMatchObject({
422+
type: NodeTypes.JS_CALL_EXPRESSION,
423+
callee: CREATE_STATIC,
424+
arguments: [
425+
JSON.stringify(
426+
`<button>enable</button>${repeat(
427+
`<div></div>`,
428+
StringifyThresholds.NODE_COUNT
429+
)}`
430+
),
431+
'21'
432+
]
433+
})
434+
})
435+
413436
test('should stringify svg', () => {
414437
const svg = `<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">`
415438
const repeated = `<rect width="50" height="50" fill="#C4C4C4"></rect>`

‎packages/compiler-dom/src/transforms/stringifyStatic.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
normalizeStyle,
2929
stringifyStyle,
3030
makeMap,
31-
isKnownSvgAttr
31+
isKnownSvgAttr,
32+
isBooleanAttr
3233
} from '@vue/shared'
3334
import { DOMNamespaces } from '../parserOptions'
3435

@@ -298,6 +299,13 @@ function stringifyElement(
298299
}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`
299300
continue
300301
}
302+
// #6568
303+
if (
304+
isBooleanAttr((p.arg as SimpleExpressionNode).content) &&
305+
exp.content === 'false'
306+
) {
307+
continue
308+
}
301309
// constant v-bind, e.g. :foo="1"
302310
let evaluated = evaluateConstant(exp)
303311
if (evaluated != null) {

0 commit comments

Comments
 (0)
Please sign in to comment.