Await: re-throw error when there is no catch block and promise is rejected (#5149)

pull/5295/head
Irshad PI 4 years ago committed by GitHub
parent cd95654a97
commit e0e434234d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -188,6 +188,7 @@ export default class AwaitBlockWrapper extends Wrapper {
ctx: #ctx,
current: null,
token: null,
hasCatch: ${this.catch.node.start !== null ? 'true' : 'false'},
pending: ${this.pending.block.name},
then: ${this.then.block.name},
catch: ${this.catch.block.name},

@ -59,6 +59,9 @@ export function handle_promise(promise, info) {
update(info.then, 1, info.value, value);
set_current_component(null);
}, error => {
if (!info.hasCatch) {
throw error;
}
set_current_component(current_component);
update(info.catch, 2, info.error, error);
set_current_component(null);

@ -0,0 +1,44 @@
let fulfil;
let promise = new Promise(f => {
fulfil = f;
});
export default {
props: {
promise
},
html: `
<p>loading...</p>
`,
test({ assert, component, target }) {
fulfil(42);
return promise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>loaded</p>
`);
let reject;
promise = new Promise((f, r) => {
reject = r;
});
component.promise = promise;
assert.htmlEqual(target.innerHTML, `
<p>loading...</p>
`);
reject(new Error('this error should be thrown'));
return promise;
})
.catch((err) => {
assert.equal(err.message, 'this error should be thrown');
});
}
};

@ -0,0 +1,9 @@
<script>
export let promise;
</script>
{#await promise}
<p>loading...</p>
{:then value}
<p>loaded</p>
{/await}
Loading…
Cancel
Save