|
| 1 | +import outdent from 'outdent'; |
| 2 | +import {getTester} from './utils/test.mjs'; |
| 3 | + |
| 4 | +const {test} = getTester(import.meta); |
| 5 | + |
| 6 | +// `await`ed |
| 7 | +test.snapshot({ |
| 8 | + valid: [ |
| 9 | + ], |
| 10 | + invalid: [ |
| 11 | + 'await Promise.all([(0, promise)])', |
| 12 | + 'async function * foo() {await Promise.all([yield promise])}', |
| 13 | + 'async function * foo() {await Promise.all([yield* promise])}', |
| 14 | + 'await Promise.all([() => promise,],)', |
| 15 | + 'await Promise.all([a ? b : c,],)', |
| 16 | + 'await Promise.all([x ??= y,],)', |
| 17 | + 'await Promise.all([x ||= y,],)', |
| 18 | + 'await Promise.all([x &&= y,],)', |
| 19 | + 'await Promise.all([x |= y,],)', |
| 20 | + 'await Promise.all([x ^= y,],)', |
| 21 | + 'await Promise.all([x ??= y,],)', |
| 22 | + 'await Promise.all([x ||= y,],)', |
| 23 | + 'await Promise.all([x &&= y,],)', |
| 24 | + 'await Promise.all([x | y,],)', |
| 25 | + 'await Promise.all([x ^ y,],)', |
| 26 | + 'await Promise.all([x & y,],)', |
| 27 | + 'await Promise.all([x !== y,],)', |
| 28 | + 'await Promise.all([x == y,],)', |
| 29 | + 'await Promise.all([x in y,],)', |
| 30 | + 'await Promise.all([x >>> y,],)', |
| 31 | + 'await Promise.all([x + y,],)', |
| 32 | + 'await Promise.all([x / y,],)', |
| 33 | + 'await Promise.all([x ** y,],)', |
| 34 | + 'await Promise.all([promise,],)', |
| 35 | + 'await Promise.all([getPromise(),],)', |
| 36 | + 'await Promise.all([promises[0],],)', |
| 37 | + 'await Promise.all([await promise])', |
| 38 | + 'await Promise.any([promise])', |
| 39 | + 'await Promise.race([promise])', |
| 40 | + 'await Promise.all([new Promise(() => {})])', |
| 41 | + '+await Promise.all([+1])', |
| 42 | + |
| 43 | + // ASI, `Promise.all()` is not really `await`ed |
| 44 | + outdent` |
| 45 | + await Promise.all([(x,y)]) |
| 46 | + [0].toString() |
| 47 | + `, |
| 48 | + ], |
| 49 | +}); |
| 50 | + |
| 51 | +// Not `await`ed |
| 52 | +test.snapshot({ |
| 53 | + valid: [ |
| 54 | + 'Promise.all([promise, anotherPromise])', |
| 55 | + 'Promise.all(notArrayLiteral)', |
| 56 | + 'Promise.all([...promises])', |
| 57 | + 'Promise.any([promise, anotherPromise])', |
| 58 | + 'Promise.race([promise, anotherPromise])', |
| 59 | + 'Promise.notListedMethod([promise])', |
| 60 | + 'Promise[all]([promise])', |
| 61 | + 'Promise.all([,])', |
| 62 | + 'NotPromise.all([promise])', |
| 63 | + 'Promise?.all([promise])', |
| 64 | + 'Promise.all?.([promise])', |
| 65 | + 'Promise.all(...[promise])', |
| 66 | + 'Promise.all([promise], extraArguments)', |
| 67 | + 'Promise.all()', |
| 68 | + 'new Promise.all([promise])', |
| 69 | + |
| 70 | + // We are not checking these cases |
| 71 | + 'globalThis.Promise.all([promise])', |
| 72 | + 'Promise["all"]([promise])', |
| 73 | + |
| 74 | + // This can't be checked |
| 75 | + 'Promise.allSettled([promise])', |
| 76 | + ], |
| 77 | + invalid: [ |
| 78 | + 'Promise.all([promise,],)', |
| 79 | + outdent` |
| 80 | + foo |
| 81 | + Promise.all([(0, promise),],) |
| 82 | + `, |
| 83 | + outdent` |
| 84 | + foo |
| 85 | + Promise.all([[array][0],],) |
| 86 | + `, |
| 87 | + 'Promise.all([promise]).then()', |
| 88 | + 'Promise.all([1]).then()', |
| 89 | + 'Promise.all([1.]).then()', |
| 90 | + 'Promise.all([.1]).then()', |
| 91 | + 'Promise.all([(0, promise)]).then()', |
| 92 | + 'const _ = () => Promise.all([ a ?? b ,],)', |
| 93 | + 'Promise.all([ {a} = 1 ,],)', |
| 94 | + 'Promise.all([ function () {} ,],)', |
| 95 | + 'Promise.all([ class {} ,],)', |
| 96 | + 'Promise.all([ new Foo ,],).then()', |
| 97 | + 'Promise.all([ new Foo ,],).toString', |
| 98 | + 'foo(Promise.all([promise]))', |
| 99 | + 'Promise.all([promise]).foo = 1', |
| 100 | + 'Promise.all([promise])[0] ||= 1', |
| 101 | + 'Promise.all([undefined]).then()', |
| 102 | + 'Promise.all([null]).then()', |
| 103 | + ], |
| 104 | +}); |
0 commit comments