-
-
Notifications
You must be signed in to change notification settings - Fork 381
/
no-useless-fallback-in-spread.mjs
54 lines (52 loc) · 1.88 KB
/
no-useless-fallback-in-spread.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
54
import {getTester} from './utils/test.mjs';
const {test} = getTester(import.meta);
test.snapshot({
valid: [
'const array = [...(foo || [])]',
'const array = [...(foo || {})]',
'const array = [...(foo && {})]',
'const object = {...(foo && {})}',
'const object = {...({} || foo)}',
'const object = {...({} && foo)}',
'const object = {...({} ?? foo)}',
'const object = {...(foo ? foo : {})}',
'const object = {...foo}',
'const object = {...(foo ?? ({} || {}))}',
'const {...foo} = object',
'function foo({...bar}){}',
'const object = {...(foo || {}).toString()}',
'const object = {...fn(foo || {})}',
'const object = call({}, ...(foo || {}))',
'const object = {...(foo || {not: "empty"})}',
'const object = {...(foo || {...{}})}',
],
invalid: [
'const object = {...(foo || {})}',
'const object = {...(foo ?? {})}',
'const object = {...(foo ?? (( {} )))}',
'const object = {...((( foo )) ?? (( {} )))}',
'const object = {...(( (( foo )) ?? (( {} )) ))}',
'async ()=> ({...((await foo) || {})})',
'const object = {...(0 || {})}',
'const object = {...((-0) || {})}',
'const object = {...(.0 || {})}',
'const object = {...(0n || {})}',
'const object = {...(false || {})}',
'const object = {...(null || {})}',
'const object = {...(undefined || {})}',
'const object = {...((a && b) || {})}',
'const object = {...(NaN || {})}',
'const object = {...("" || {})}',
'const object = {...([] || {})}',
'const object = {...({} || {})}',
'const object = {...(foo || {}),}',
'const object = {...((foo ?? {}) || {})}',
'const object = {...((foo && {}) || {})}',
'const object = {...(foo && {} || {})}',
'const object = {...({...(foo || {})})}',
'const object = {...({...((0, foo) || {})})}',
'function foo(a = {...(bar || {})}){}',
// The only case we'll break, but we should not care about it.
'const object = {...(document.all || {})}',
],
});