Skip to content

Commit fdbb624

Browse files
committed
test: add test to ensure comments are not stringified
1 parent 07bb18c commit fdbb624

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ return function render(_ctx, _cache) {
9292
}"
9393
`;
9494
95+
exports[`stringify static html > should not stringify comments 1`] = `
96+
"const { createCommentVNode: _createCommentVNode, createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
97+
98+
const _hoisted_1 = { class: "a" }
99+
100+
return function render(_ctx, _cache) {
101+
return (_openBlock(), _createElementBlock(_Fragment, null, [
102+
_createCommentVNode(" Comment 1 "),
103+
_createElementVNode("div", _hoisted_1, [
104+
_createCommentVNode(" Comment 2 "),
105+
_cache[0] || (_cache[0] = _createStaticVNode("<span class=\\"b\\"></span><span class=\\"b\\"></span><span class=\\"b\\"></span><span class=\\"b\\"></span><span class=\\"b\\"></span>", 5))
106+
])
107+
], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */))
108+
}"
109+
`;
110+
95111
exports[`stringify static html > should work for <option> elements with string values 1`] = `
96112
"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
97113

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,16 @@ describe('stringify static html', () => {
491491
expect(code).toMatchSnapshot()
492492
})
493493

494+
test('should not stringify comments', () => {
495+
const { code } = compileWithStringify(
496+
`<!-- Comment 1 --><div class="a"><!-- Comment 2 -->${repeat(
497+
`<span class="b"/>`,
498+
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
499+
)}</div>`,
500+
)
501+
expect(code).toMatchSnapshot()
502+
})
503+
494504
test('should bail for <option> elements with null values', () => {
495505
const { ast, code } = compileWithStringify(
496506
`<div><select><option :value="null" />${repeat(

0 commit comments

Comments
 (0)