@@ -8,45 +8,64 @@ test.snapshot({
88 valid : [
99 'a()' ,
1010 'a = async () => {}' ,
11- 'a = (async () => {})()' ,
11+ '(async function *() {})()' ,
1212 outdent `
13- {
14- (async () => {})();
13+ function foo() {
14+ if (foo) {
15+ (async () => {})()
16+ }
1517 }
1618 ` ,
17- '!async function() {}()' ,
18- 'void async function() {}()' ,
19- '(async function *() {})()' ,
20- '(async () => {})?.()' ,
19+ 'await (async () => {})()' ,
2120 ] ,
2221 invalid : [
2322 '(async () => {})()' ,
23+ '(async () => {})?.()' ,
2424 '(async function() {})()' ,
2525 '(async function() {}())' ,
2626 '(async function run() {})()' ,
2727 '(async function(c, d) {})(a, b)' ,
28+ 'if (foo) (async () => {})()' ,
29+ outdent `
30+ {
31+ (async () => {})();
32+ }
33+ ` ,
34+ 'a = (async () => {})()' ,
35+ '!async function() {}()' ,
36+ 'void async function() {}()' ,
37+ '(async () => {})().catch(foo)' ,
2838 ] ,
2939} ) ;
3040
3141// Promise
3242test . snapshot ( {
3343 valid : [
3444 'foo.then' ,
35- 'foo.then().toString( )' ,
36- '! foo.then()' ,
37- 'foo.then?.(bar)' ,
38- 'foo? .then(bar)' ,
39- 'foo? .then(bar).finally(qux )' ,
45+ 'await foo.then(bar )' ,
46+ 'await foo.then(bar).catch(bar )' ,
47+ 'await foo.then?.(bar)' ,
48+ 'await foo.then(bar)?.catch (bar)' ,
49+ 'await foo.then(bar)?.catch?.(bar )' ,
4050 ] ,
4151 invalid : [
4252 'foo.then(bar)' ,
53+ 'foo.then?.(bar)' ,
54+ 'foo?.then(bar)' ,
4355 'foo.catch(() => process.exit(1))' ,
4456 'foo.finally(bar)' ,
4557 'foo.then(bar, baz)' ,
4658 'foo.then(bar, baz).finally(qux)' ,
4759 '(foo.then(bar, baz)).finally(qux)' ,
4860 '(async () => {})().catch(() => process.exit(1))' ,
4961 '(async function() {}()).finally(() => {})' ,
62+ 'for (const foo of bar) foo.then(bar)' ,
63+ 'foo?.then(bar).finally(qux)' ,
64+ 'foo.then().toString()' ,
65+ '!foo.then()' ,
66+ 'foo.then(bar).then(baz)?.then(qux)' ,
67+ 'foo.then(bar).then(baz).then?.(qux)' ,
68+ 'foo.then(bar).catch(bar).finally(bar)' ,
5069 ] ,
5170} ) ;
5271
@@ -106,10 +125,6 @@ test.snapshot({
106125 ` ,
107126 parserOptions : { sourceType : 'script' } ,
108127 } ,
109- outdent `
110- const foo = async () => {};
111- foo?.();
112- ` ,
113128 outdent `
114129 const program = {async run () {}};
115130 program.run()
@@ -119,12 +134,24 @@ test.snapshot({
119134 const {run} = program;
120135 run()
121136 ` ,
137+ outdent `
138+ const foo = async () => {};
139+ await foo();
140+ ` ,
122141 ] ,
123142 invalid : [
124143 outdent `
125144 const foo = async () => {};
126145 foo();
127146 ` ,
147+ outdent `
148+ const foo = async () => {};
149+ foo?.();
150+ ` ,
151+ outdent `
152+ const foo = async () => {};
153+ foo().then(foo);
154+ ` ,
128155 outdent `
129156 const foo = async function () {}, bar = 1;
130157 foo(bar);
@@ -133,6 +160,14 @@ test.snapshot({
133160 foo();
134161 async function foo() {}
135162 ` ,
163+ outdent `
164+ const foo = async () => {};
165+ if (true) {
166+ alert();
167+ } else {
168+ foo();
169+ }
170+ ` ,
136171 ] ,
137172} ) ;
138173
0 commit comments