await-then-catch with non-promise

pull/952/head
Rich Harris 8 years ago
parent 8f52587539
commit 56b167b44f

@ -732,7 +732,17 @@ export default class Generator {
}
}
if (node.type === 'IfBlock' || node.type === 'AwaitBlock') {
if (node.type === 'AwaitBlock') {
node.metadata = contextualise(node.expression, contextDependencies, indexes);
contextDependencies = new Map(contextDependencies);
contextDependencies.set(node.value, node.metadata.dependencies);
contextDependencies.set(node.error, node.metadata.dependencies);
contextDependenciesStack.push(contextDependencies);
}
if (node.type === 'IfBlock') {
node.metadata = contextualise(node.expression, contextDependencies, indexes);
}

@ -88,9 +88,13 @@ export default function visitAwaitBlock(
return true;
}
} else {
${resolved} = ${promise};
if (${await_block_type} !== ${create_then_block}) {
if (${await_block}) ${await_block}.d();
${await_block} = (${await_block_type} = ${create_then_block})(${params}, ${resolved} = promise, #component);
if (${await_block}) {
${await_block}.u();
${await_block}.d();
}
${await_block} = (${await_block_type} = ${create_then_block})(${params}, ${resolved}, #component);
return true;
}
}

@ -0,0 +1,19 @@
export default {
data: {
thePromise: 'not actually a promise'
},
html: `
<p>the value is not actually a promise</p>
`,
test(assert, component, target) {
component.set({
thePromise: 'still not a promise'
});
assert.htmlEqual(target.innerHTML, `
<p>the value is still not a promise</p>
`);
}
};

@ -0,0 +1,7 @@
{{#await thePromise}}
<p>loading...</p>
{{then theValue}}
<p>the value is {{theValue}}</p>
{{catch theError}}
<p>oh no! {{theError.message}}</p>
{{/await}}
Loading…
Cancel
Save