feat: use short comments (#10899)

* use short comments

* fix
pull/10903/head
Rich Harris 10 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) { if (node.fallback) {
const fallback_stmts = create_block(node, node.fallback.nodes, context); const fallback_stmts = create_block(node, node.fallback.nodes, context);
fallback_stmts.unshift( 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( state.template.push(
t_statement( t_statement(
@ -1549,14 +1549,14 @@ const template_visitors = {
const consequent = create_block(node, node.consequent.nodes, context); const consequent = create_block(node, node.consequent.nodes, context);
consequent.unshift( 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 const alternate = node.alternate
? /** @type {import('estree').BlockStatement} */ (context.visit(node.alternate)) ? /** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
: b.block([]); : b.block([]);
alternate.body.unshift( 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( state.template.push(

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

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

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