correctly handle promises that are of function type

pull/8162/head
Vilsol 4 years ago committed by Yuichiro Yamashita
parent 1d658e7501
commit 5752bbf2ca

@ -11,7 +11,7 @@ export function assign<T, S>(tar: T, src: S): T & S {
} }
export function is_promise<T = any>(value: any): value is PromiseLike<T> { export function is_promise<T = any>(value: any): value is PromiseLike<T> {
return value && typeof value === 'object' && typeof value.then === 'function'; return !!value && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function';
} }
export function add_location(element, file, line, column, char) { export function add_location(element, file, line, column, char) {

@ -0,0 +1,19 @@
const realPromise = Promise.resolve(42);
const promise = () => {};
promise.then = realPromise.then.bind(realPromise);
promise.catch = realPromise.catch.bind(realPromise);
export default {
props: {
promise
},
test({ assert, target }) {
return promise.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>42</p>
`);
});
}
};

@ -0,0 +1,7 @@
<script>
export let promise;
</script>
{#await promise then value}
<p>{JSON.stringify(value)}</p>
{/await}
Loading…
Cancel
Save