fix(compiler-dom): remove v-bind boolean attribute with literal false value when stringifying (#6635)

fix #6617
This commit is contained in:
某时橙 2022-09-27 17:18:29 +08:00 committed by Evan You
parent 57ffc3e546
commit 6c6fe2c0cd
2 changed files with 32 additions and 1 deletions

View File

@ -410,6 +410,29 @@ describe('stringify static html', () => {
})
})
// #6617
test('should remove boolean attribute for `false`', () => {
const { ast } = compileWithStringify(
`<button :disabled="false">enable</button>${repeat(
`<div></div>`,
StringifyThresholds.NODE_COUNT
)}`
)
expect(ast.hoists[0]).toMatchObject({
type: NodeTypes.JS_CALL_EXPRESSION,
callee: CREATE_STATIC,
arguments: [
JSON.stringify(
`<button>enable</button>${repeat(
`<div></div>`,
StringifyThresholds.NODE_COUNT
)}`
),
'21'
]
})
})
test('should stringify svg', () => {
const svg = `<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">`
const repeated = `<rect width="50" height="50" fill="#C4C4C4"></rect>`

View File

@ -28,7 +28,8 @@ import {
normalizeStyle,
stringifyStyle,
makeMap,
isKnownSvgAttr
isKnownSvgAttr,
isBooleanAttr
} from '@vue/shared'
import { DOMNamespaces } from '../parserOptions'
@ -298,6 +299,13 @@ function stringifyElement(
}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`
continue
}
// #6568
if (
isBooleanAttr((p.arg as SimpleExpressionNode).content) &&
exp.content === 'false'
) {
continue
}
// constant v-bind, e.g. :foo="1"
let evaluated = evaluateConstant(exp)
if (evaluated != null) {