fix(compiler-dom): properly stringify v-html/v-text with constant value

fix #5439
close #5445
This commit is contained in:
Evan You
2022-05-13 08:57:43 +08:00
parent cd92654510
commit 6283b2ec41
5 changed files with 89 additions and 29 deletions

View File

@@ -32,3 +32,23 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"div\\", null, _hoisted_2))
}"
`;
exports[`stringify static html stringify v-html 1`] = `
"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue
const _hoisted_1 = /*#__PURE__*/_createStaticVNode(\\"<pre data-type=\\\\\\"js\\\\\\"><code><span>show-it </span></code></pre><div class><span class>1</span><span class>2</span></div>\\", 2)
return function render(_ctx, _cache) {
return _hoisted_1
}"
`;
exports[`stringify static html stringify v-text 1`] = `
"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue
const _hoisted_1 = /*#__PURE__*/_createStaticVNode(\\"<pre data-type=\\\\\\"js\\\\\\"><code>&lt;span&gt;show-it &lt;/span&gt;</code></pre><div class><span class>1</span><span class>2</span></div>\\", 2)
return function render(_ctx, _cache) {
return _hoisted_1
}"
`;

View File

@@ -433,4 +433,25 @@ describe('stringify static html', () => {
]
})
})
// #5439
test('stringify v-html', () => {
const { code } = compileWithStringify(`
<pre data-type="js"><code v-html="'&lt;span&gt;show-it &lt;/span&gt;'"></code></pre>
<div class>
<span class>1</span><span class>2</span>
</div>`)
expect(code).toMatch(`<code><span>show-it </span></code>`)
expect(code).toMatchSnapshot()
})
test('stringify v-text', () => {
const { code } = compileWithStringify(`
<pre data-type="js"><code v-text="'&lt;span&gt;show-it &lt;/span&gt;'"></code></pre>
<div class>
<span class>1</span><span class>2</span>
</div>`)
expect(code).toMatch(`<code>&lt;span&gt;show-it &lt;/span&gt;</code>`)
expect(code).toMatchSnapshot()
})
})