implement inlining for template text nodes

hoist-unmodified-var
Ben McCann 2 years ago
parent d224156ec8
commit 9429dc8eeb

@ -1558,8 +1558,6 @@ function process_children(nodes, parent, { visit, state }) {
return; return;
} }
push_template_quasi(state, ' ');
const text_id = get_node_id(expression, state, 'text'); const text_id = get_node_id(expression, state, 'text');
const contains_call_expression = sequence.some( const contains_call_expression = sequence.some(
(n) => n.type === 'ExpressionTag' && n.metadata.contains_call_expression (n) => n.type === 'ExpressionTag' && n.metadata.contains_call_expression
@ -1575,21 +1573,19 @@ function process_children(nodes, parent, { visit, state }) {
); );
if (contains_call_expression && !within_bound_contenteditable) { if (contains_call_expression && !within_bound_contenteditable) {
push_template_quasi(state, ' ');
state.update_effects.push(singular); state.update_effects.push(singular);
} else if ( } else if (
sequence.some((node) => node.type === 'ExpressionTag' && node.metadata.dynamic) && sequence.some((node) => node.type === 'ExpressionTag' && node.metadata.dynamic) &&
!within_bound_contenteditable !within_bound_contenteditable
) { ) {
push_template_quasi(state, ' ');
state.update.push({ state.update.push({
singular, singular,
grouped: b.stmt(b.call('$.text', text_id, assignment)) grouped: b.stmt(b.call('$.text', text_id, assignment))
}); });
} else { } else {
// TODO: uncomment this const { can_inline } = can_inline_all_nodes(sequence, state);
// it causes a test to fail. need to understand if it's a valid test or if it should be adjusted or deleted
// see https://github.com/sveltejs/svelte/issues/6832 for more context on that test
// const { can_inline } = can_inline_all_nodes(sequence, state);
const can_inline = false;
if (can_inline) { if (can_inline) {
for (let i = 0; i < assignment.quasis.length; i++) { for (let i = 0; i < assignment.quasis.length; i++) {
push_template_quasi(state, assignment.quasis[i].value.raw); push_template_quasi(state, assignment.quasis[i].value.raw);
@ -1598,6 +1594,7 @@ function process_children(nodes, parent, { visit, state }) {
} }
} }
} else { } else {
push_template_quasi(state, ' ');
state.init.push(init); state.init.push(init);
} }
} }

@ -7,13 +7,8 @@ export default test({
test({ assert, target }) { test({ assert, target }) {
const div_list = target.querySelectorAll('div'); const div_list = target.querySelectorAll('div');
assert.equal(normalizeSpaces(div_list[0].textContent), ' hello'); assert.equal(div_list[0].textContent, ' hello');
assert.equal(normalizeSpaces(div_list[1].textContent), ' hello '); assert.equal(div_list[1].textContent, ' hello  ');
assert.equal(normalizeSpaces(div_list[2].textContent), ' hello hello'); assert.equal(div_list[2].textContent, ' hello   hello');
} }
}); });
/** @param {string | null} str */
function normalizeSpaces(str) {
return str ? str.replaceAll(String.fromCharCode(160), ' ') : str;
}

@ -8,7 +8,7 @@ const d = 'd';
import * as $ from "svelte/internal"; import * as $ from "svelte/internal";
const boolean = false; const boolean = false;
var frag = $.template(`<p autocapitalize="${`w${$.stringify(o)}r${$.stringify(d)}s`}" contenteditable="${boolean}"> </p>`); var frag = $.template(`<p autocapitalize="${`w${$.stringify(o)}r${$.stringify(d)}s`}" contenteditable="${boolean}">boolean is ${$.stringify(boolean)} and autocapitalize is w${$.stringify(o)}r${$.stringify(d)}s</p>`);
export default function Hoist_unmodified_var($$anchor, $$props) { export default function Hoist_unmodified_var($$anchor, $$props) {
$.push($$props, true); $.push($$props, true);
@ -24,7 +24,6 @@ export default function Hoist_unmodified_var($$anchor, $$props) {
var text = $.child(p); var text = $.child(p);
text.nodeValue = `boolean is ${$.stringify(boolean)} and autocapitalize is w${$.stringify(o)}r${$.stringify(d)}s`;
$.close($$anchor, p); $.close($$anchor, p);
$.pop(); $.pop();
} }
Loading…
Cancel
Save