Skip to content

Commit

Permalink
Merge pull request #1588 from sveltejs/gh-1507
Browse files Browse the repository at this point in the history
allow {:then}/{:catch} to have no bound identifier
  • Loading branch information
Rich-Harris committed Jul 15, 2018
2 parents de1eddd + b4d7653 commit 46a134e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/parse/state/mustache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
41 changes: 41 additions & 0 deletions test/runtime/samples/await-then-catch-no-values/_config.js
Original file line number Diff line number Diff line change
@@ -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`);
});
}
};
7 changes: 7 additions & 0 deletions test/runtime/samples/await-then-catch-no-values/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{#await thePromise}
waiting
{:then}
resolved
{:catch}
rejected
{/await}

0 comments on commit 46a134e

Please sign in to comment.