mirror of https://github.com/sveltejs/svelte
fix: improve template literal expression output generation (#10147)
* fix: improve template literal expression output generation * do not proxy template literalpull/10150/head
parent
a13c946966
commit
e2fc04d0d5
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: improve template literal expression output generation
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({});
|
@ -0,0 +1,30 @@
|
|||||||
|
// index.svelte (Svelte VERSION)
|
||||||
|
// Note: compiler output will change before 5.0 is released!
|
||||||
|
import "svelte/internal/disclose-version";
|
||||||
|
import * as $ from "svelte/internal";
|
||||||
|
|
||||||
|
export default function Each_string_template($$anchor, $$props) {
|
||||||
|
$.push($$props, false);
|
||||||
|
|
||||||
|
/* Init */
|
||||||
|
var fragment = $.comment($$anchor);
|
||||||
|
var node = $.child_frag(fragment);
|
||||||
|
|
||||||
|
$.each_indexed(
|
||||||
|
node,
|
||||||
|
() => ['foo', 'bar', 'baz'],
|
||||||
|
1,
|
||||||
|
($$anchor, thing, $$index) => {
|
||||||
|
/* Init */
|
||||||
|
var node_1 = $.space($$anchor);
|
||||||
|
|
||||||
|
/* Update */
|
||||||
|
$.text_effect(node_1, () => `${$.stringify($.unwrap(thing))}, `);
|
||||||
|
$.close($$anchor, node_1);
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$.close_frag($$anchor, fragment);
|
||||||
|
$.pop();
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
// index.svelte (Svelte VERSION)
|
||||||
|
// Note: compiler output will change before 5.0 is released!
|
||||||
|
import * as $ from "svelte/internal/server";
|
||||||
|
|
||||||
|
export default function Each_string_template($$payload, $$props) {
|
||||||
|
$.push(false);
|
||||||
|
|
||||||
|
const anchor = $.create_anchor($$payload);
|
||||||
|
const each_array = $.ensure_array_like(['foo', 'bar', 'baz']);
|
||||||
|
|
||||||
|
$$payload.out += `${anchor}`;
|
||||||
|
|
||||||
|
for (let $$index = 0; $$index < each_array.length; $$index++) {
|
||||||
|
const thing = each_array[$$index];
|
||||||
|
const anchor_1 = $.create_anchor($$payload);
|
||||||
|
|
||||||
|
$$payload.out += `${anchor_1}${$.escape(thing)},${$.escape(' ')}${anchor_1}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.out += `${anchor}`;
|
||||||
|
$.pop();
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{#each ['foo', 'bar', 'baz'] as thing}
|
||||||
|
{thing},{' '}
|
||||||
|
{/each}
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({});
|
@ -0,0 +1,39 @@
|
|||||||
|
// index.svelte (Svelte VERSION)
|
||||||
|
// Note: compiler output will change before 5.0 is released!
|
||||||
|
import "svelte/internal/disclose-version";
|
||||||
|
import * as $ from "svelte/internal";
|
||||||
|
|
||||||
|
function reset(_, str, tpl) {
|
||||||
|
$.set(str, '');
|
||||||
|
$.set(str, ``);
|
||||||
|
$.set(tpl, '');
|
||||||
|
$.set(tpl, ``);
|
||||||
|
}
|
||||||
|
|
||||||
|
var frag = $.template(`<input> <input> <button>reset</button>`, true);
|
||||||
|
|
||||||
|
export default function State_proxy_literal($$anchor, $$props) {
|
||||||
|
$.push($$props, true);
|
||||||
|
|
||||||
|
let str = $.source('');
|
||||||
|
let tpl = $.source(``);
|
||||||
|
/* Init */
|
||||||
|
var fragment = $.open_frag($$anchor, true, frag);
|
||||||
|
var node = $.child_frag(fragment);
|
||||||
|
|
||||||
|
$.remove_input_attr_defaults(node);
|
||||||
|
|
||||||
|
var input = $.sibling($.sibling(node));
|
||||||
|
|
||||||
|
$.remove_input_attr_defaults(input);
|
||||||
|
|
||||||
|
var button = $.sibling($.sibling(input));
|
||||||
|
|
||||||
|
$.bind_value(node, () => $.get(str), ($$value) => $.set(str, $.proxy($$value)));
|
||||||
|
$.bind_value(input, () => $.get(tpl), ($$value) => $.set(tpl, $.proxy($$value)));
|
||||||
|
button.__click = [reset, str, tpl];
|
||||||
|
$.close_frag($$anchor, fragment);
|
||||||
|
$.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
$.delegate(["click"]);
|
@ -0,0 +1,20 @@
|
|||||||
|
// index.svelte (Svelte VERSION)
|
||||||
|
// Note: compiler output will change before 5.0 is released!
|
||||||
|
import * as $ from "svelte/internal/server";
|
||||||
|
|
||||||
|
export default function State_proxy_literal($$payload, $$props) {
|
||||||
|
$.push(true);
|
||||||
|
|
||||||
|
let str = '';
|
||||||
|
let tpl = ``;
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
str = '';
|
||||||
|
str = ``;
|
||||||
|
tpl = '';
|
||||||
|
tpl = ``;
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.out += `<input${$.attr("value", str, false)}> <input${$.attr("value", tpl, false)}> <button>reset</button>`;
|
||||||
|
$.pop();
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<script>
|
||||||
|
let str = $state('');
|
||||||
|
let tpl = $state(``);
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
str = '';
|
||||||
|
str = ``;
|
||||||
|
|
||||||
|
tpl = '';
|
||||||
|
tpl = ``;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input bind:value={str} />
|
||||||
|
<input bind:value={tpl} />
|
||||||
|
|
||||||
|
<button onclick={reset}>reset</button>
|
Loading…
Reference in new issue