diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 8868e38ee2..84d00b19c5 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -11,7 +11,7 @@ export function assign(tar: T, src: S): T & S { } export function is_promise(value: any): value is PromiseLike { - 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) { diff --git a/test/runtime/samples/await-function-promise/_config.js b/test/runtime/samples/await-function-promise/_config.js new file mode 100644 index 0000000000..b6a9de6856 --- /dev/null +++ b/test/runtime/samples/await-function-promise/_config.js @@ -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, ` +

42

+ `); + }); + } +}; diff --git a/test/runtime/samples/await-function-promise/main.svelte b/test/runtime/samples/await-function-promise/main.svelte new file mode 100644 index 0000000000..aaefc6b782 --- /dev/null +++ b/test/runtime/samples/await-function-promise/main.svelte @@ -0,0 +1,7 @@ + + +{#await promise then value} +

{JSON.stringify(value)}

+{/await}