|
38 | 38 | (list 'sci.impl.async-await/finally promise-expr callback)) |
39 | 39 |
|
40 | 40 | (defn mark-promise |
41 | | - "Mark a form as promise-producing. This marker is detected by promise-form? |
42 | | - and stripped away by the analyzer." |
| 41 | + "Mark a form as promise-producing using metadata." |
43 | 42 | [form] |
44 | | - (list 'sci.impl.async-await/promise form)) |
| 43 | + (vary-meta form assoc :sci.impl/promise true)) |
45 | 44 |
|
46 | 45 | (defn- promise-form? |
47 | 46 | "Check if form is already a promise-producing expression. |
48 | | - Detects calls to sci.impl.async-await helpers and the promise marker." |
| 47 | + Detects metadata marker or calls to sci.impl.async-await helpers." |
49 | 48 | [form] |
50 | | - (and (seq? form) |
51 | | - (let [op (first form)] |
52 | | - (or (= 'sci.impl.async-await/then op) |
53 | | - (= 'sci.impl.async-await/catch op) |
54 | | - (= 'sci.impl.async-await/finally op) |
55 | | - (= 'sci.impl.async-await/resolve op) |
56 | | - (= 'sci.impl.async-await/promise op))))) |
| 49 | + (or (:sci.impl/promise (meta form)) |
| 50 | + (and (seq? form) |
| 51 | + (let [op (first form)] |
| 52 | + (or (= 'sci.impl.async-await/then op) |
| 53 | + (= 'sci.impl.async-await/catch op) |
| 54 | + (= 'sci.impl.async-await/finally op) |
| 55 | + (= 'sci.impl.async-await/resolve op)))))) |
57 | 56 |
|
58 | 57 | (defn- ensure-promise-result |
59 | 58 | "Ensure async function body returns a promise. |
|
300 | 299 | expanded (if (and (seq? body) |
301 | 300 | (symbol? op) |
302 | 301 | (not (contains? locals op)) ;; Don't expand if locally bound |
303 | | - (not (#{'await 'let* 'loop* 'do 'fn* 'if 'quote 'try 'case* |
304 | | - 'sci.impl.async-await/promise} op))) |
| 302 | + (not (#{'await 'let* 'loop* 'do 'fn* 'if 'quote 'try 'case*} op))) |
305 | 303 | (macroexpand/macroexpand-1 ctx body) |
306 | 304 | body)] |
307 | 305 | (if (not= expanded body) |
|
0 commit comments