/
no-await-expression-member.mjs
53 lines (46 loc) · 1.74 KB
/
no-await-expression-member.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {getTester} from './utils/test.mjs';
const {test} = getTester(import.meta);
test.snapshot({
valid: [
'const foo = await promise',
'const {foo: bar} = await promise',
'const foo = !await promise',
'const foo = typeof await promise',
'const foo = await notPromise.method()',
'const foo = foo[await promise]',
// These await expression need parenthesized, but rarely used
'new (await promiseReturnsAClass)',
'(await promiseReturnsAFunction)()',
],
invalid: [
'(await promise)[0]',
'(await promise).property',
'const foo = (await promise).bar()',
'const foo = (await promise).bar?.()',
'const foo = (await promise)?.bar()',
'const firstElement = (await getArray())[0]',
'const secondElement = (await getArray())[1]',
'const thirdElement = (await getArray())[2]',
'const optionalFirstElement = (await getArray())?.[0]',
'const {propertyOfFirstElement} = (await getArray())[0]',
'const [firstElementOfFirstElement] = (await getArray())[0]',
'let foo, firstElement = (await getArray())[0]',
'var firstElement = (await getArray())[0], bar',
'const property = (await getObject()).property',
'const renamed = (await getObject()).property',
'const property = (await getObject())[property]',
'const property = (await getObject())?.property',
'const {propertyOfProperty} = (await getObject()).property',
'const {propertyOfProperty} = (await getObject()).propertyOfProperty',
'const [firstElementOfProperty] = (await getObject()).property',
'const [firstElementOfProperty] = (await getObject()).firstElementOfProperty',
'firstElement = (await getArray())[0]',
'property = (await getArray()).property',
],
});
test.typescript({
valid: [
'function foo () {return (await promise) as string;}',
],
invalid: [],
});