feat: use short comments (#10899)

* use short comments

* fix
pull/10903/head
Rich Harris 9 months ago committed by GitHub
parent 32b1824198
commit 7e5e462194
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1521,7 +1521,7 @@ const template_visitors = {
if (node.fallback) {
const fallback_stmts = create_block(node, node.fallback.nodes, context);
fallback_stmts.unshift(
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--ssr:each_else-->')))
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!ssr:each_else>')))
);
state.template.push(
t_statement(
@ -1549,14 +1549,14 @@ const template_visitors = {
const consequent = create_block(node, node.consequent.nodes, context);
consequent.unshift(
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--ssr:if:true-->')))
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!ssr:if:true>')))
);
const alternate = node.alternate
? /** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
: b.block([]);
alternate.body.unshift(
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--ssr:if:false-->')))
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!ssr:if:false>')))
);
state.template.push(

@ -637,7 +637,7 @@ export function ensure_array_like(array_like_or_iterator) {
/** @param {{ anchor: number }} payload */
export function create_anchor(payload) {
const depth = payload.anchor++;
return `<!--ssr:${depth}-->`;
return `<!ssr:${depth}>`;
}
/** @returns {[() => false, (value: boolean) => void]} */

@ -77,7 +77,7 @@ export function normalize_html(
try {
const node = window.document.createElement('div');
node.innerHTML = html
.replace(/(<!--.*?-->)/g, preserveComments ? '$1' : '')
.replace(/(<!(--)?.*?\2>)/g, preserveComments ? '$1' : '')
.replace(/(data-svelte-h="[^"]+")/g, removeDataSvelte ? '' : '$1')
.replace(/>[ \t\n\r\f]+</g, '><')
.trim();
@ -135,15 +135,15 @@ export function setup_html_equal(options = {}) {
try {
assert.deepEqual(
withoutNormalizeHtml
? normalize_new_line(actual)
? normalize_new_line(actual.trim())
.replace(/(\sdata-svelte-h="[^"]+")/g, options.removeDataSvelte ? '' : '$1')
.replace(/(<!--.*?-->)/g, preserveComments !== false ? '$1' : '')
: normalize_html(window, actual, { ...options, preserveComments }),
.replace(/(<!(--)?.*?\2>)/g, preserveComments !== false ? '$1' : '')
: normalize_html(window, actual.trim(), { ...options, preserveComments }),
withoutNormalizeHtml
? normalize_new_line(expected)
? normalize_new_line(expected.trim())
.replace(/(\sdata-svelte-h="[^"]+")/g, options.removeDataSvelte ? '' : '$1')
.replace(/(<!--.*?-->)/g, preserveComments !== false ? '$1' : '')
: normalize_html(window, expected, { ...options, preserveComments }),
.replace(/(<!(--)?.*?\2>)/g, preserveComments !== false ? '$1' : '')
: normalize_html(window, expected.trim(), { ...options, preserveComments }),
message
);
} catch (e) {

@ -1,6 +1,6 @@
<!--ssr:0-->
<!ssr:0>
<title>Some Title</title>
<link rel="canonical" href="/">
<meta name="description" content="some description">
<meta name="keywords" content="some keywords">
<!--ssr:0-->
<!ssr:0>

@ -1 +1 @@
<!--ssr:0--><div>Just a dummy page.</div><!--ssr:0-->
<!ssr:0><div>Just a dummy page.</div><!ssr:0>

Loading…
Cancel
Save