Merge pull request #1588 from sveltejs/gh-1507

allow {:then}/{:catch} to have no bound identifier
pull/1597/head
Rich Harris 6 years ago committed by GitHub
commit 46a134e04a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -147,11 +147,12 @@ export default function mustache(parser: Parser) {
parser.stack.pop();
const awaitBlock = parser.current();
parser.requireWhitespace();
awaitBlock.value = parser.readIdentifier();
parser.allowWhitespace();
parser.eat('}', true);
if (!parser.eat('}')) {
parser.requireWhitespace();
awaitBlock.value = parser.readIdentifier();
parser.allowWhitespace();
parser.eat('}', true);
}
const thenBlock: Node = {
start,
@ -170,11 +171,12 @@ export default function mustache(parser: Parser) {
parser.stack.pop();
const awaitBlock = parser.current();
parser.requireWhitespace();
awaitBlock.error = parser.readIdentifier();
parser.allowWhitespace();
parser.eat('}', true);
if (!parser.eat('}')) {
parser.requireWhitespace();
awaitBlock.error = parser.readIdentifier();
parser.allowWhitespace();
parser.eat('}', true);
}
const catchBlock: Node = {
start,

@ -0,0 +1,41 @@
let fulfil;
let thePromise = new Promise(f => {
fulfil = f;
});
export default {
data: {
thePromise
},
html: `waiting`,
test(assert, component, target) {
fulfil(9000);
return thePromise
.then(() => {
assert.htmlEqual(target.innerHTML, `resolved`);
let reject;
thePromise = new Promise((f, r) => {
reject = r;
});
component.set({
thePromise
});
assert.htmlEqual(target.innerHTML, `waiting`);
reject(new Error('something broke'));
return thePromise.catch(() => {});
})
.then(() => {
assert.htmlEqual(target.innerHTML, `rejected`);
});
}
};

@ -0,0 +1,7 @@
{#await thePromise}
waiting
{:then}
resolved
{:catch}
rejected
{/await}
Loading…
Cancel
Save