mirror of https://github.com/vuejs/core.git
fix(compiler-dom): avoid stringify option with null value (#12096)
close #12093
This commit is contained in:
parent
7ad289e1e7
commit
f6d9926236
|
|
@ -32,6 +32,23 @@ return function render(_ctx, _cache) {
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`stringify static html > should bail for <option> elements with null values 1`] = `
|
||||||
|
"const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
|
||||||
|
|
||||||
|
return function render(_ctx, _cache) {
|
||||||
|
return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [
|
||||||
|
_createElementVNode("select", null, [
|
||||||
|
_createElementVNode("option", { value: null }),
|
||||||
|
_createElementVNode("option", { value: "1" }),
|
||||||
|
_createElementVNode("option", { value: "1" }),
|
||||||
|
_createElementVNode("option", { value: "1" }),
|
||||||
|
_createElementVNode("option", { value: "1" }),
|
||||||
|
_createElementVNode("option", { value: "1" })
|
||||||
|
], -1 /* HOISTED */)
|
||||||
|
])))
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`stringify static html > should bail for <option> elements with number values 1`] = `
|
exports[`stringify static html > should bail for <option> elements with number values 1`] = `
|
||||||
"const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
|
"const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,17 @@ describe('stringify static html', () => {
|
||||||
expect(code).toMatchSnapshot()
|
expect(code).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should bail for <option> elements with null values', () => {
|
||||||
|
const { ast, code } = compileWithStringify(
|
||||||
|
`<div><select><option :value="null" />${repeat(
|
||||||
|
`<option value="1" />`,
|
||||||
|
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
|
||||||
|
)}</select></div>`,
|
||||||
|
)
|
||||||
|
expect(ast.cached).toMatchObject([cachedArrayBailedMatcher()])
|
||||||
|
expect(code).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
test('eligible content (elements > 20) + non-eligible content', () => {
|
test('eligible content (elements > 20) + non-eligible content', () => {
|
||||||
const { code } = compileWithStringify(
|
const { code } = compileWithStringify(
|
||||||
`<div>${repeat(
|
`<div>${repeat(
|
||||||
|
|
|
||||||
|
|
@ -261,8 +261,7 @@ function analyzeNode(node: StringifiableNode): [number, number] | false {
|
||||||
isOptionTag &&
|
isOptionTag &&
|
||||||
isStaticArgOf(p.arg, 'value') &&
|
isStaticArgOf(p.arg, 'value') &&
|
||||||
p.exp &&
|
p.exp &&
|
||||||
p.exp.ast &&
|
!p.exp.isStatic
|
||||||
p.exp.ast.type !== 'StringLiteral'
|
|
||||||
) {
|
) {
|
||||||
return bail()
|
return bail()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue