Skip to content

feat: use short comments #10899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]} */
Expand Down
14 changes: 7 additions & 7 deletions packages/svelte/tests/html_equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!--ssr:0--><div>Just a dummy page.</div><!--ssr:0-->
<!ssr:0><div>Just a dummy page.</div><!ssr:0>