mirror of https://github.com/sveltejs/svelte
parent
64f91100de
commit
de48a77cb2
@ -0,0 +1,14 @@
|
|||||||
|
/** @import { AwaitExpression } from 'estree' */
|
||||||
|
/** @import { ComponentContext } from '../types.js' */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is only registered for components, currently.
|
||||||
|
* @param {AwaitExpression} node
|
||||||
|
* @param {ComponentContext} context
|
||||||
|
*/
|
||||||
|
export function AwaitExpression(node, context) {
|
||||||
|
const hoisted = context.state.analysis.hoisted_promises.get(node.argument);
|
||||||
|
if (hoisted) {
|
||||||
|
node.argument = hoisted;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
4
|
@ -0,0 +1,5 @@
|
|||||||
|
{#each await Promise.resolve([]) as item}
|
||||||
|
{await Promise.reject('This should never be reached')}
|
||||||
|
{:else}
|
||||||
|
{await Promise.resolve(4)}
|
||||||
|
{/each}
|
@ -0,0 +1 @@
|
|||||||
|
123
|
@ -0,0 +1,9 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
const first = Promise.resolve(1);
|
||||||
|
const second = Promise.resolve(2);
|
||||||
|
const third = Promise.resolve(3);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each await Promise.resolve([first, second, third]) as item}
|
||||||
|
{await item}
|
||||||
|
{/each}
|
@ -0,0 +1 @@
|
|||||||
|
yes yes yes
|
@ -0,0 +1,5 @@
|
|||||||
|
{#if await Promise.resolve(false)}
|
||||||
|
{await Promise.reject('no no no')}
|
||||||
|
{:else}
|
||||||
|
{await Promise.resolve('yes yes yes')}
|
||||||
|
{/if}
|
@ -0,0 +1 @@
|
|||||||
|
yes yes yes
|
@ -0,0 +1,5 @@
|
|||||||
|
{#if await Promise.resolve(true)}
|
||||||
|
{await Promise.resolve('yes yes yes')}
|
||||||
|
{:else}
|
||||||
|
{await Promise.reject('no no no')}
|
||||||
|
{/if}
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({ compileOptions: { experimental: { async: true } } });
|
@ -0,0 +1,35 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
export default function Async_each_fallback_hoisting($$anchor) {
|
||||||
|
var fragment = $.comment();
|
||||||
|
var node = $.first_child(fragment);
|
||||||
|
|
||||||
|
$.async(node, [() => Promise.resolve([])], (node, $$collection) => {
|
||||||
|
$.each(
|
||||||
|
node,
|
||||||
|
16,
|
||||||
|
() => $.get($$collection),
|
||||||
|
$.index,
|
||||||
|
($$anchor, item) => {
|
||||||
|
$.next();
|
||||||
|
|
||||||
|
var text = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text, $0), undefined, [() => Promise.reject('This should never be reached')]);
|
||||||
|
$.append($$anchor, text);
|
||||||
|
},
|
||||||
|
($$anchor) => {
|
||||||
|
$.next();
|
||||||
|
|
||||||
|
var text_1 = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text_1, $0), undefined, [() => Promise.resolve(4)]);
|
||||||
|
$.append($$anchor, text_1);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
$.append($$anchor, fragment);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Async_each_fallback_hoisting($$payload) {
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
const promises = [Promise.resolve([])];
|
||||||
|
const each_array = $.ensure_array_like(await promises[0]);
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
if (each_array.length !== 0) {
|
||||||
|
$$payload.push('<!--[-->');
|
||||||
|
|
||||||
|
for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
|
||||||
|
let item = each_array[$$index];
|
||||||
|
const promises_1 = [Promise.reject('This should never be reached')];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`<!---->${$.escape(await promises_1[0])}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$$payload.push('<!--[!-->');
|
||||||
|
|
||||||
|
const promises_2 = [Promise.resolve(4)];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`<!---->${$.escape(await promises_2[0])}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.push(`<!--]-->`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{#each await Promise.resolve([]) as item}
|
||||||
|
{await Promise.reject('This should never be reached')}
|
||||||
|
{:else}
|
||||||
|
{await Promise.resolve(4)}
|
||||||
|
{/each}
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({ compileOptions: { experimental: { async: true } } });
|
@ -0,0 +1,24 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
export default function Async_each_hoisting($$anchor) {
|
||||||
|
const first = Promise.resolve(1);
|
||||||
|
const second = Promise.resolve(2);
|
||||||
|
const third = Promise.resolve(3);
|
||||||
|
var fragment = $.comment();
|
||||||
|
var node = $.first_child(fragment);
|
||||||
|
|
||||||
|
$.async(node, [() => Promise.resolve([first, second, third])], (node, $$collection) => {
|
||||||
|
$.each(node, 17, () => $.get($$collection), $.index, ($$anchor, item) => {
|
||||||
|
$.next();
|
||||||
|
|
||||||
|
var text = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text, $0), undefined, [() => $.get(item)]);
|
||||||
|
$.append($$anchor, text);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$.append($$anchor, fragment);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Async_each_hoisting($$payload) {
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
const first = Promise.resolve(1);
|
||||||
|
const second = Promise.resolve(2);
|
||||||
|
const third = Promise.resolve(3);
|
||||||
|
const promises = [Promise.resolve([first, second, third])];
|
||||||
|
const each_array = $.ensure_array_like(await promises[0]);
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`<!--[-->`);
|
||||||
|
|
||||||
|
for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
|
||||||
|
let item = each_array[$$index];
|
||||||
|
const promises_1 = [item];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`<!---->${$.escape(await promises_1[0])}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.push(`<!--]-->`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
const first = Promise.resolve(1);
|
||||||
|
const second = Promise.resolve(2);
|
||||||
|
const third = Promise.resolve(3);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each await Promise.resolve([first, second, third]) as item}
|
||||||
|
{await item}
|
||||||
|
{/each}
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({ compileOptions: { experimental: { async: true } } });
|
@ -0,0 +1,30 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
export default function Async_if_alternate_hoisting($$anchor) {
|
||||||
|
var fragment = $.comment();
|
||||||
|
var node = $.first_child(fragment);
|
||||||
|
|
||||||
|
$.async(node, [() => Promise.resolve(false)], (node, $$condition) => {
|
||||||
|
var consequent = ($$anchor) => {
|
||||||
|
var text = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text, $0), undefined, [() => Promise.reject('no no no')]);
|
||||||
|
$.append($$anchor, text);
|
||||||
|
};
|
||||||
|
|
||||||
|
var alternate = ($$anchor) => {
|
||||||
|
var text_1 = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text_1, $0), undefined, [() => Promise.resolve('yes yes yes')]);
|
||||||
|
$.append($$anchor, text_1);
|
||||||
|
};
|
||||||
|
|
||||||
|
$.if(node, ($$render) => {
|
||||||
|
if ($.get($$condition)) $$render(consequent); else $$render(alternate, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$.append($$anchor, fragment);
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Async_if_alternate_hoisting($$payload) {
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
const promises = [Promise.resolve(false)];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
if (await promises[0]) {
|
||||||
|
$$payload.push('<!--[-->');
|
||||||
|
|
||||||
|
const promises_1 = [Promise.reject('no no no')];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`${$.escape(await promises_1[0])}`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$$payload.push('<!--[!-->');
|
||||||
|
|
||||||
|
const promises_2 = [Promise.resolve('yes yes yes')];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`${$.escape(await promises_2[0])}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.push(`<!--]-->`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{#if await Promise.resolve(false)}
|
||||||
|
{await Promise.reject('no no no')}
|
||||||
|
{:else}
|
||||||
|
{await Promise.resolve('yes yes yes')}
|
||||||
|
{/if}
|
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({ compileOptions: { experimental: { async: true } } });
|
@ -0,0 +1,30 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
export default function Async_if_hoisting($$anchor) {
|
||||||
|
var fragment = $.comment();
|
||||||
|
var node = $.first_child(fragment);
|
||||||
|
|
||||||
|
$.async(node, [() => Promise.resolve(true)], (node, $$condition) => {
|
||||||
|
var consequent = ($$anchor) => {
|
||||||
|
var text = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text, $0), undefined, [() => Promise.resolve('yes yes yes')]);
|
||||||
|
$.append($$anchor, text);
|
||||||
|
};
|
||||||
|
|
||||||
|
var alternate = ($$anchor) => {
|
||||||
|
var text_1 = $.text();
|
||||||
|
|
||||||
|
$.template_effect(($0) => $.set_text(text_1, $0), undefined, [() => Promise.reject('no no no')]);
|
||||||
|
$.append($$anchor, text_1);
|
||||||
|
};
|
||||||
|
|
||||||
|
$.if(node, ($$render) => {
|
||||||
|
if ($.get($$condition)) $$render(consequent); else $$render(alternate, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$.append($$anchor, fragment);
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Async_if_hoisting($$payload) {
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
const promises = [Promise.resolve(true)];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
if (await promises[0]) {
|
||||||
|
$$payload.push('<!--[-->');
|
||||||
|
|
||||||
|
const promises_1 = [Promise.resolve('yes yes yes')];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`${$.escape(await promises_1[0])}`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$$payload.push('<!--[!-->');
|
||||||
|
|
||||||
|
const promises_2 = [Promise.reject('no no no')];
|
||||||
|
|
||||||
|
$$payload.child(async ($$payload) => {
|
||||||
|
$$payload.push(`${$.escape(await promises_2[0])}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.push(`<!--]-->`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{#if await Promise.resolve(true)}
|
||||||
|
{await Promise.resolve('yes yes yes')}
|
||||||
|
{:else}
|
||||||
|
{await Promise.reject('no no no')}
|
||||||
|
{/if}
|
Loading…
Reference in new issue