Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31008 from andrewbranch/bug/29358
Support binding patterns in Promise -> async/await refactor
- Loading branch information
Showing
15 changed files
with
403 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...elines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/innerPromise/*|]*/(): Promise<string> { | ||
return fetch("https://typescriptlang.org").then(resp => { | ||
return resp.blob().then(({ blob }) => blob.byteOffset).catch(({ message }) => 'Error ' + message); | ||
}).then(blob => { | ||
return blob.toString(); | ||
}); | ||
} | ||
|
||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function innerPromise(): Promise<string> { | ||
const resp = await fetch("https://typescriptlang.org"); | ||
let blob: any; | ||
try { | ||
const { blob } = await resp.blob(); | ||
blob = blob.byteOffset; | ||
} | ||
catch ({ message }) { | ||
blob = 'Error ' + message; | ||
} | ||
return blob.toString(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...elines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/innerPromise/*|]*/(): Promise<string> { | ||
return fetch("https://typescriptlang.org").then(resp => { | ||
return resp.blob().then(blob => blob.byteOffset).catch(err => 'Error'); | ||
}).then(({ x }) => { | ||
return x.toString(); | ||
}); | ||
} | ||
|
||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function innerPromise(): Promise<string> { | ||
const resp = await fetch("https://typescriptlang.org"); | ||
let result: any; | ||
try { | ||
const blob = await resp.blob(); | ||
result = blob.byteOffset; | ||
} | ||
catch (err) { | ||
result = 'Error'; | ||
} | ||
const { x } = result; | ||
return x.toString(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...elines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/innerPromise/*|]*/(): Promise<string> { | ||
return fetch("https://typescriptlang.org").then(resp => { | ||
return resp.blob().then(({ blob }) => blob.byteOffset).catch(({ message }) => 'Error ' + message); | ||
}).then(([x, y]) => { | ||
return (x || y).toString(); | ||
}); | ||
} | ||
|
||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function innerPromise(): Promise<string> { | ||
const resp = await fetch("https://typescriptlang.org"); | ||
let result: any; | ||
try { | ||
const { blob } = await resp.blob(); | ||
result = blob.byteOffset; | ||
} | ||
catch ({ message }) { | ||
result = 'Error ' + message; | ||
} | ||
const [x, y] = result; | ||
return (x || y).toString(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...elines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding4.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/innerPromise/*|]*/(): Promise<string> { | ||
return fetch("https://typescriptlang.org").then(resp => { | ||
return resp.blob().then(({ blob }: { blob: { byteOffset: number } }) => [0, blob.byteOffset]).catch(({ message }: Error) => ['Error ', message]); | ||
}).then(([x, y]) => { | ||
return (x || y).toString(); | ||
}); | ||
} | ||
|
||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function innerPromise(): Promise<string> { | ||
const resp = await fetch("https://typescriptlang.org"); | ||
let result: any[]; | ||
try { | ||
const { blob } = await resp.blob(); | ||
result = [0, blob.byteOffset]; | ||
} | ||
catch ({ message }) { | ||
result = ['Error ', message]; | ||
} | ||
const [x, y] = result; | ||
return (x || y).toString(); | ||
} |
11 changes: 11 additions & 0 deletions
11
.../baselines/reference/convertToAsyncFunction/convertToAsyncFunction_arrayBindingPattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/f/*|]*/(): Promise<void>{ | ||
return fetch('https://typescriptlang.org').then(([result]) => { console.log(result) }); | ||
} | ||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f(): Promise<void>{ | ||
const [result] = await fetch('https://typescriptlang.org'); | ||
console.log(result); | ||
} |
13 changes: 13 additions & 0 deletions
13
...ines/reference/convertToAsyncFunction/convertToAsyncFunction_arrayBindingPatternRename.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/f/*|]*/(): Promise<void>{ | ||
const result = getResult(); | ||
return fetch('https://typescriptlang.org').then(([result]) => { console.log(result) }); | ||
} | ||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f(): Promise<void>{ | ||
const result = getResult(); | ||
const [result_1] = await fetch('https://typescriptlang.org'); | ||
console.log(result_1); | ||
} |
4 changes: 2 additions & 2 deletions
4
...selines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...selines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...nce/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/f/*|]*/() { | ||
return Promise.resolve().then(() => ({ x: 3 })).catch(() => ({ x: "a" })).then(({ x }) => !!x); | ||
} | ||
|
||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f() { | ||
let result; | ||
try { | ||
await Promise.resolve(); | ||
result = ({ x: 3 }); | ||
} | ||
catch (e) { | ||
result = ({ x: "a" }); | ||
} | ||
const { x } = result; | ||
return !!x; | ||
} |
20 changes: 20 additions & 0 deletions
20
...nce/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/f/*|]*/() { | ||
return Promise.resolve().then(() => ({ x: 3 })).catch(() => ({ x: "a" })).then(({ x }) => !!x); | ||
} | ||
|
||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f() { | ||
let result: { x: number; } | { x: string; }; | ||
try { | ||
await Promise.resolve(); | ||
result = ({ x: 3 }); | ||
} | ||
catch (e) { | ||
result = ({ x: "a" }); | ||
} | ||
const { x } = result; | ||
return !!x; | ||
} |
11 changes: 11 additions & 0 deletions
11
...baselines/reference/convertToAsyncFunction/convertToAsyncFunction_objectBindingPattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/f/*|]*/(): Promise<void>{ | ||
return fetch('https://typescriptlang.org').then(({ result }) => { console.log(result) }); | ||
} | ||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f(): Promise<void>{ | ||
const { result } = await fetch('https://typescriptlang.org'); | ||
console.log(result); | ||
} |
13 changes: 13 additions & 0 deletions
13
...nes/reference/convertToAsyncFunction/convertToAsyncFunction_objectBindingPatternRename.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ==ORIGINAL== | ||
|
||
function /*[#|*/f/*|]*/(): Promise<void>{ | ||
const result = getResult(); | ||
return fetch('https://typescriptlang.org').then(({ result }) => { console.log(result) }); | ||
} | ||
// ==ASYNC FUNCTION::Convert to async function== | ||
|
||
async function f(): Promise<void>{ | ||
const result = getResult(); | ||
const { result: result_1 } = await fetch('https://typescriptlang.org'); | ||
console.log(result_1); | ||
} |