From 0dcea4128b8c3171901d2a61893d60f6a0516900 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 9 Jul 2018 20:10:28 -0400 Subject: [PATCH] allow {:then}/{:catch} to have no bound identifier (#1507) --- src/parse/state/mustache.ts | 22 +++++----- .../await-then-catch-no-values/_config.js | 41 +++++++++++++++++++ .../await-then-catch-no-values/main.html | 7 ++++ 3 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 test/runtime/samples/await-then-catch-no-values/_config.js create mode 100644 test/runtime/samples/await-then-catch-no-values/main.html diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 657aceac65..cbac76e6a1 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -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, diff --git a/test/runtime/samples/await-then-catch-no-values/_config.js b/test/runtime/samples/await-then-catch-no-values/_config.js new file mode 100644 index 0000000000..88e38784a3 --- /dev/null +++ b/test/runtime/samples/await-then-catch-no-values/_config.js @@ -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`); + }); + } +}; diff --git a/test/runtime/samples/await-then-catch-no-values/main.html b/test/runtime/samples/await-then-catch-no-values/main.html new file mode 100644 index 0000000000..414b2fd068 --- /dev/null +++ b/test/runtime/samples/await-then-catch-no-values/main.html @@ -0,0 +1,7 @@ +{#await thePromise} + waiting +{:then} + resolved +{:catch} + rejected +{/await}