From aeabf1cca51432c637eeba1115fbfb6376d378df Mon Sep 17 00:00:00 2001 From: Tim Hall Date: Mon, 4 Dec 2017 16:00:55 -0500 Subject: [PATCH 1/3] Failing test for #974 --- .../await-then-catch-anchor/_config.js | 49 +++++++++++++++++++ .../samples/await-then-catch-anchor/main.html | 9 ++++ 2 files changed, 58 insertions(+) create mode 100644 test/runtime/samples/await-then-catch-anchor/_config.js create mode 100644 test/runtime/samples/await-then-catch-anchor/main.html diff --git a/test/runtime/samples/await-then-catch-anchor/_config.js b/test/runtime/samples/await-then-catch-anchor/_config.js new file mode 100644 index 000000000000..697c119ccd0e --- /dev/null +++ b/test/runtime/samples/await-then-catch-anchor/_config.js @@ -0,0 +1,49 @@ +let fulfil; + +let thePromise = new Promise(f => { + fulfil = f; +}); + +export default { + data: { + thePromise + }, + + html: ` +

loading...

+ `, + + test(assert, component, target) { + fulfil(42); + + return thePromise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the value is 42

+ `); + + let reject; + + thePromise = new Promise((f, r) => { + reject = r; + }); + + component.set({ + thePromise + }); + + assert.htmlEqual(target.innerHTML, ` +

loading...

+ `); + + reject(new Error('something broke')); + + return thePromise.catch(() => {}); + }) + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

oh no! something broke

+ `); + }); + } +}; diff --git a/test/runtime/samples/await-then-catch-anchor/main.html b/test/runtime/samples/await-then-catch-anchor/main.html new file mode 100644 index 000000000000..b8e32962fafd --- /dev/null +++ b/test/runtime/samples/await-then-catch-anchor/main.html @@ -0,0 +1,9 @@ +
+{{#await thePromise}} +

loading...

+{{then theValue}} +

the value is {{theValue}}

+{{catch theError}} +

oh no! {{theError.message}}

+{{/await}} +
From a6836bd395e5eb25307be5e32948e37b8f815eb7 Mon Sep 17 00:00:00 2001 From: Tim Hall Date: Mon, 4 Dec 2017 16:10:29 -0500 Subject: [PATCH 2/3] Failing test for #975 --- .../samples/await-then-catch-if/_config.js | 43 +++++++++++++++++++ .../samples/await-then-catch-if/main.html | 11 +++++ 2 files changed, 54 insertions(+) create mode 100644 test/runtime/samples/await-then-catch-if/_config.js create mode 100644 test/runtime/samples/await-then-catch-if/main.html diff --git a/test/runtime/samples/await-then-catch-if/_config.js b/test/runtime/samples/await-then-catch-if/_config.js new file mode 100644 index 000000000000..1fe94768c37b --- /dev/null +++ b/test/runtime/samples/await-then-catch-if/_config.js @@ -0,0 +1,43 @@ +let fulfil; + +let thePromise = new Promise(f => { + fulfil = f; +}); + +export default { + data: { + show: true, + thePromise + }, + + html: ` +

loading...

+ `, + + test(assert, component, target) { + fulfil(42); + + return thePromise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the value is 42

+ `); + + component.set({ + show: false + }); + + assert.htmlEqual(target.innerHTML, ` +

Else

+ `); + + component.set({ + show: true + }); + + assert.htmlEqual(target.innerHTML, ` +

the value is 42

+ `); + }); + } +}; diff --git a/test/runtime/samples/await-then-catch-if/main.html b/test/runtime/samples/await-then-catch-if/main.html new file mode 100644 index 000000000000..20449734d403 --- /dev/null +++ b/test/runtime/samples/await-then-catch-if/main.html @@ -0,0 +1,11 @@ +{{#if show}} +{{#await thePromise}} +

loading...

+{{then theValue}} +

the value is {{theValue}}

+{{catch theError}} +

oh no! {{theError.message}}

+{{/await}} +{{else}} +

Else

+{{/if}} From 978e628e6740647f2eb4a89cb4861139b735eec4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 4 Dec 2017 21:59:02 -0500 Subject: [PATCH 3/3] mount await blocks with siblings (#974), and unmount correctly (#975) --- src/generators/dom/visitors/AwaitBlock.ts | 6 +++++- test/runtime/samples/await-then-catch-if/_config.js | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/generators/dom/visitors/AwaitBlock.ts b/src/generators/dom/visitors/AwaitBlock.ts index c0d5c25b85ab..6e014af2893e 100644 --- a/src/generators/dom/visitors/AwaitBlock.ts +++ b/src/generators/dom/visitors/AwaitBlock.ts @@ -67,7 +67,7 @@ export default function visitAwaitBlock( ${old_block}.u(); ${old_block}.d(); ${await_block}.c(); - ${await_block}.m(${anchor}.parentNode, ${anchor}); + ${await_block}.m(${state.parentNode || `${anchor}.parentNode`}, ${anchor}); } } @@ -142,6 +142,10 @@ export default function visitAwaitBlock( `); } + block.builders.unmount.addBlock(deindent` + ${await_block}.u(); + `); + block.builders.destroy.addBlock(deindent` ${await_token} = null; ${await_block}.d(); diff --git a/test/runtime/samples/await-then-catch-if/_config.js b/test/runtime/samples/await-then-catch-if/_config.js index 1fe94768c37b..bbd8d792c6d2 100644 --- a/test/runtime/samples/await-then-catch-if/_config.js +++ b/test/runtime/samples/await-then-catch-if/_config.js @@ -1,6 +1,6 @@ let fulfil; -let thePromise = new Promise(f => { +const thePromise = new Promise(f => { fulfil = f; }); @@ -35,9 +35,11 @@ export default { show: true }); - assert.htmlEqual(target.innerHTML, ` -

the value is 42

- `); + return thePromise.then(() => { + assert.htmlEqual(target.innerHTML, ` +

the value is 42

+ `); + }); }); } };