From 9b5aa3b567565a9fadf857fac9ed0f2f650b9150 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 26 Jun 2020 12:15:30 -0700 Subject: [PATCH 1/2] Preserve newlines between try/catch, if/else, do/while --- src/compiler/emitter.ts | 23 +++++--- .../convertToEs6Class_emptyCatchClause.ts | 3 +- .../fourslash/textChangesPreserveNewlines9.ts | 57 +++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 tests/cases/fourslash/textChangesPreserveNewlines9.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6cbe25b92671e..8fec41fba5fce 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2667,7 +2667,7 @@ namespace ts { emitTokenWithComment(SyntaxKind.CloseParenToken, node.expression.end, writePunctuation, node); emitEmbeddedStatement(node, node.thenStatement); if (node.elseStatement) { - writeLineOrSpace(node); + writeLineOrSpace(node, node.thenStatement, node.elseStatement); emitTokenWithComment(SyntaxKind.ElseKeyword, node.thenStatement.end, writeKeyword, node); if (node.elseStatement.kind === SyntaxKind.IfStatement) { writeSpace(); @@ -2690,11 +2690,11 @@ namespace ts { function emitDoStatement(node: DoStatement) { emitTokenWithComment(SyntaxKind.DoKeyword, node.pos, writeKeyword, node); emitEmbeddedStatement(node, node.statement); - if (isBlock(node.statement)) { + if (isBlock(node.statement) && !preserveSourceNewlines) { writeSpace(); } else { - writeLineOrSpace(node); + writeLineOrSpace(node, node.statement, node.expression); } emitWhileClause(node, node.statement.end); @@ -2836,11 +2836,11 @@ namespace ts { writeSpace(); emit(node.tryBlock); if (node.catchClause) { - writeLineOrSpace(node); + writeLineOrSpace(node, node.tryBlock, node.catchClause); emit(node.catchClause); } if (node.finallyBlock) { - writeLineOrSpace(node); + writeLineOrSpace(node, node.catchClause || node.tryBlock, node.finallyBlock); emitTokenWithComment(SyntaxKind.FinallyKeyword, (node.catchClause || node.tryBlock).end, writeKeyword, node); writeSpace(); emit(node.finallyBlock); @@ -4249,10 +4249,19 @@ namespace ts { return pos! < 0 ? pos! : pos! + tokenString.length; } - function writeLineOrSpace(node: Node) { - if (getEmitFlags(node) & EmitFlags.SingleLine) { + function writeLineOrSpace(parentNode: Node, prevChildNode: Node, nextChildNode: Node) { + if (getEmitFlags(parentNode) & EmitFlags.SingleLine) { writeSpace(); } + else if (preserveSourceNewlines) { + const lines = getLinesBetweenNodes(parentNode, prevChildNode, nextChildNode); + if (lines) { + writeLine(lines); + } + else { + writeSpace(); + } + } else { writeLine(); } diff --git a/tests/cases/fourslash/convertToEs6Class_emptyCatchClause.ts b/tests/cases/fourslash/convertToEs6Class_emptyCatchClause.ts index 7fed94e84cc63..fa6353397ca39 100644 --- a/tests/cases/fourslash/convertToEs6Class_emptyCatchClause.ts +++ b/tests/cases/fourslash/convertToEs6Class_emptyCatchClause.ts @@ -13,8 +13,7 @@ verify.codeFix({ `class MyClass { constructor() { } foo() { - try { } - catch () { } + try { } catch () { } } } `, diff --git a/tests/cases/fourslash/textChangesPreserveNewlines9.ts b/tests/cases/fourslash/textChangesPreserveNewlines9.ts new file mode 100644 index 0000000000000..efae190dff692 --- /dev/null +++ b/tests/cases/fourslash/textChangesPreserveNewlines9.ts @@ -0,0 +1,57 @@ +/// + +////function foo() { +//// /*1*/if (true) { +//// console.log(1); +//// } else { +//// console.log(1); +//// } +//// +//// do { +//// console.log(1); +//// } +//// +//// while (true); +//// +//// try { +//// console.log(1); +//// } catch { +//// void 0; +//// } finally { +//// void 0; +//// }/*2*/ +////} + +goTo.select("1", "2"); +edit.applyRefactor({ + refactorName: "Extract Symbol", + actionName: "function_scope_1", + actionDescription: "Extract to function in global scope", + newContent: +`function foo() { + /*RENAME*/newFunction(); +} + +function newFunction() { + if (true) { + console.log(1); + } else { + console.log(1); + } + + do { + console.log(1); + } + + while (true); + + try { + console.log(1); + } catch { + void 0; + } finally { + void 0; + } +} +` +}); From a1a06b59ec66ec33383e3c7bc96eb3c1e68c2ea3 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 26 Jun 2020 12:41:04 -0700 Subject: [PATCH 2/2] Update baselines --- .../convertToAsyncFunction/convertToAsyncFunction_Catch.ts | 3 +-- .../convertToAsyncFunction_CatchAndRej.ts | 6 ++---- .../convertToAsyncFunction_CatchAndRejRef.ts | 6 ++---- .../convertToAsyncFunction_CatchFollowedByThen.js | 3 +-- .../convertToAsyncFunction_CatchFollowedByThen.ts | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMatchingTypes01.ts | 3 +-- ...ction_CatchFollowedByThenMatchingTypes01NoAnnotations.js | 3 +-- ...ction_CatchFollowedByThenMatchingTypes01NoAnnotations.ts | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMatchingTypes02.ts | 3 +-- ...ction_CatchFollowedByThenMatchingTypes02NoAnnotations.js | 3 +-- ...ction_CatchFollowedByThenMatchingTypes02NoAnnotations.ts | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMismatchTypes01.js | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMismatchTypes01.ts | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMismatchTypes02.ts | 3 +-- ...ction_CatchFollowedByThenMismatchTypes02NoAnnotations.js | 3 +-- ...ction_CatchFollowedByThenMismatchTypes02NoAnnotations.ts | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMismatchTypes03.js | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMismatchTypes03.ts | 3 +-- ...ertToAsyncFunction_CatchFollowedByThenMismatchTypes04.ts | 3 +-- .../convertToAsyncFunction_CatchNoBrackets.ts | 3 +-- .../convertToAsyncFunction_CatchRef.ts | 3 +-- .../convertToAsyncFunction_InnerPromiseRet.ts | 3 +-- .../convertToAsyncFunction_InnerPromiseRetBinding1.ts | 3 +-- .../convertToAsyncFunction_InnerPromiseRetBinding2.ts | 3 +-- .../convertToAsyncFunction_InnerPromiseRetBinding3.ts | 3 +-- .../convertToAsyncFunction_InnerPromiseRetBinding4.ts | 3 +-- .../convertToAsyncFunction_LocalReturn.js | 3 +-- .../convertToAsyncFunction_LocalReturn.ts | 3 +-- .../convertToAsyncFunction_MultipleCatches.ts | 6 ++---- .../convertToAsyncFunction_NoCatchHandler.js | 3 +-- .../convertToAsyncFunction_NoCatchHandler.ts | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_NoRes.ts | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_NoRes2.ts | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_NoRes3.ts | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_NoRes4.js | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_NoRes4.ts | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_Param2.ts | 3 +-- .../convertToAsyncFunction_PromiseCallInner.js | 3 +-- .../convertToAsyncFunction_PromiseCallInner.ts | 3 +-- .../convertToAsyncFunction/convertToAsyncFunction_Scope2.ts | 3 +-- ...syncFunction_callbackReturnsRejectedPromiseInTryBlock.js | 3 +-- ...syncFunction_callbackReturnsRejectedPromiseInTryBlock.ts | 3 +-- .../convertToAsyncFunction_catchBlockUniqueParams.js | 3 +-- .../convertToAsyncFunction_catchBlockUniqueParams.ts | 3 +-- ...tToAsyncFunction_catchBlockUniqueParamsBindingPattern.js | 3 +-- ...tToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts | 3 +-- .../convertToAsyncFunction_catchTypeArgument1.ts | 3 +-- 47 files changed, 50 insertions(+), 100 deletions(-) diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Catch.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Catch.ts index b356e47f85acc..a613e92ce3b0a 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Catch.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Catch.ts @@ -9,8 +9,7 @@ async function f():Promise { try { const result = await fetch('https://typescriptlang.org'); console.log(result); - } - catch (err) { + } catch (err) { console.log(err); } } \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRej.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRej.ts index 247191aa1fb0a..6b5260baeda57 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRej.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRej.ts @@ -10,12 +10,10 @@ async function f():Promise { try { const result = await fetch('https://typescriptlang.org'); console.log(result); - } - catch (rejection) { + } catch (rejection) { console.log("rejected:", rejection); } - } - catch (err) { + } catch (err) { console.log(err); } } \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRejRef.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRejRef.ts index 883da342a6195..190ae9d18a253 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRejRef.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchAndRejRef.ts @@ -19,12 +19,10 @@ async function f():Promise { try { const result = await fetch('https://typescriptlang.org'); return res(result); - } - catch (rejection) { + } catch (rejection) { return rej(rejection); } - } - catch (err) { + } catch (err) { return catch_err(err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.js index cb39bbad5e1ad..0c08c6d7f8584 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.js @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.ts index d675993aadfb5..589cc61e67e36 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThen.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01.ts index 2c9a02e6637d8..36346c0ffbb61 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.js index 53d4d82e8dbcb..565042e2ab742 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.js @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.ts index 8e5e2c82a9735..36602399b6397 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes01NoAnnotations.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02.ts index a385d5bb13abd..6802f9f38b4fd 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02.ts @@ -15,8 +15,7 @@ async function f(){ try { const res = await fetch("https://typescriptlang.org"); result = 0; - } - catch (rej) { + } catch (rej) { result = 1; } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.js index 44a8c3b3b65f7..ee881ceabdd98 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.js @@ -15,8 +15,7 @@ async function f(){ try { const res = await fetch("https://typescriptlang.org"); result = 0; - } - catch (rej) { + } catch (rej) { result = 1; } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.ts index 68563c3a348ea..027422aeb179f 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMatchingTypes02NoAnnotations.ts @@ -15,8 +15,7 @@ async function f(){ try { const res = await fetch("https://typescriptlang.org"); result = 0; - } - catch (rej) { + } catch (rej) { result = 1; } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.js index 49cd8dd0cddba..80a645ada0c8a 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.js @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.ts index 6bbd496de7d0a..d4f8920234d54 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes01.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02.ts index 2d415c090e211..aa43966f4467d 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.js index f7be616009ffa..e44212e538c61 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.js @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.ts index 5cfae1be7584c..6c18286a77de3 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes02NoAnnotations.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.js index 5ae54306d1122..3833f9bc0a4e9 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.js @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.ts index 2ee8796ab203c..23e446282fca7 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes03.ts @@ -19,8 +19,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes04.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes04.ts index ac542ca8cf595..3e263e82f7be3 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes04.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchFollowedByThenMismatchTypes04.ts @@ -39,8 +39,7 @@ async function f(){ try { const result_1 = await fetch("https://typescriptlang.org"); result = await res(result_1); - } - catch (reject) { + } catch (reject) { result = await rej(reject); } return res(result); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchNoBrackets.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchNoBrackets.ts index 54c2b22921b1e..373350ea7c6ef 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchNoBrackets.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchNoBrackets.ts @@ -9,8 +9,7 @@ async function f():Promise { try { const result = await fetch('https://typescriptlang.org'); return console.log(result); - } - catch (err) { + } catch (err) { return console.log(err); } } \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchRef.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchRef.ts index 709e777668d11..16f48a9040ee1 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchRef.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_CatchRef.ts @@ -16,8 +16,7 @@ async function f():Promise { try { const result = await fetch('https://typescriptlang.org'); return res(result); - } - catch (err) { + } catch (err) { return catch_err(err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRet.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRet.ts index 57fe0a1a0c51e..41b9f21014aea 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRet.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRet.ts @@ -16,8 +16,7 @@ async function innerPromise(): Promise { try { const blob = await resp.blob(); blob_1 = blob.byteOffset; - } - catch (err) { + } catch (err) { blob_1 = 'Error'; } return blob_1.toString(); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding1.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding1.ts index aa683f7fd3453..9c553cc8f61bc 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding1.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding1.ts @@ -16,8 +16,7 @@ async function innerPromise(): Promise { try { const { blob } = await resp.blob(); blob_1 = blob.byteOffset; - } - catch ({ message }) { + } catch ({ message }) { blob_1 = 'Error ' + message; } return blob_1.toString(); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding2.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding2.ts index fb8c32c5efd4d..036d8da81879d 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding2.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding2.ts @@ -16,8 +16,7 @@ async function innerPromise(): Promise { try { const blob = await resp.blob(); result = blob.byteOffset; - } - catch (err) { + } catch (err) { result = 'Error'; } const { x } = result; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding3.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding3.ts index f55184aa10f8c..dd0f8a9441217 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding3.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding3.ts @@ -16,8 +16,7 @@ async function innerPromise(): Promise { try { const { blob } = await resp.blob(); result = blob.byteOffset; - } - catch ({ message }) { + } catch ({ message }) { result = 'Error ' + message; } const [x, y] = result; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding4.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding4.ts index e4dff86ffd968..83cb27dac3738 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding4.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_InnerPromiseRetBinding4.ts @@ -16,8 +16,7 @@ async function innerPromise(): Promise { try { const { blob } = await resp.blob(); result = [0, blob.byteOffset]; - } - catch ({ message }) { + } catch ({ message }) { result = ['Error ', message]; } const [x, y] = result; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.js index f9bc67dd19b71..f90801ad9e1d1 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.js @@ -12,8 +12,7 @@ async function f() { let x = fetch("https://typescriptlang.org").then(res => console.log(res)); try { return x; - } - catch (err) { + } catch (err) { return console.log("Error!", err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.ts index f9bc67dd19b71..f90801ad9e1d1 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_LocalReturn.ts @@ -12,8 +12,7 @@ async function f() { let x = fetch("https://typescriptlang.org").then(res => console.log(res)); try { return x; - } - catch (err) { + } catch (err) { return console.log("Error!", err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_MultipleCatches.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_MultipleCatches.ts index 654df9a1e4c6f..9cda464f8a8c9 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_MultipleCatches.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_MultipleCatches.ts @@ -10,12 +10,10 @@ async function f(): Promise { try { const res = await fetch('https://typescriptlang.org'); return console.log(res); - } - catch (err) { + } catch (err) { return console.log("err", err); } - } - catch (err2) { + } catch (err2) { return console.log("err2", err2); } } \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.js index 25061a4dfb5a1..01b8c5fa18a8a 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.js @@ -10,6 +10,5 @@ async function f() { try { const x = await fetch('https://typescriptlang.org'); return x.statusText; - } - catch (e) { } + } catch (e) { } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.ts index 25061a4dfb5a1..01b8c5fa18a8a 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoCatchHandler.ts @@ -10,6 +10,5 @@ async function f() { try { const x = await fetch('https://typescriptlang.org'); return x.statusText; - } - catch (e) { } + } catch (e) { } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes.ts index 8817f682a8108..3bc8dbf5f5aeb 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes.ts @@ -9,8 +9,7 @@ function /*[#|*/f/*|]*/():Promise { async function f():Promise { try { await fetch('https://typescriptlang.org'); - } - catch (rejection) { + } catch (rejection) { return console.log("rejected:", rejection); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes2.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes2.ts index 33d2f9808c97d..ada11e4260127 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes2.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes2.ts @@ -9,8 +9,7 @@ function /*[#|*/f/*|]*/():Promise { async function f():Promise { try { await fetch('https://typescriptlang.org'); - } - catch (rej) { + } catch (rej) { return console.log(rej); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes3.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes3.ts index 09081dbabd5d8..d088aba90155f 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes3.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes3.ts @@ -9,8 +9,7 @@ function /*[#|*/f/*|]*/():Promise { async function f():Promise { try { return fetch('https://typescriptlang.org'); - } - catch (rej) { + } catch (rej) { return console.log(rej); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.js index 2bbf32e46a664..61f93fa11e2c2 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.js @@ -9,8 +9,7 @@ function /*[#|*/f/*|]*/() { async function f() { try { await fetch('https://typescriptlang.org'); - } - catch (rejection) { + } catch (rejection) { return console.log("rejected:", rejection); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.ts index 2bbf32e46a664..61f93fa11e2c2 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_NoRes4.ts @@ -9,8 +9,7 @@ function /*[#|*/f/*|]*/() { async function f() { try { await fetch('https://typescriptlang.org'); - } - catch (rejection) { + } catch (rejection) { return console.log("rejected:", rejection); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Param2.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Param2.ts index 167b6430a059c..f40c9bf5befc3 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Param2.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Param2.ts @@ -17,8 +17,7 @@ function my_print (resp): Promise { async function f() { try { return my_print(fetch("https://typescriptlang.org").then(res => console.log(res))); - } - catch (err) { + } catch (err) { return console.log("Error!", err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.js index 0049c661c3904..621612a256ae9 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.js @@ -10,8 +10,7 @@ function /*[#|*/f/*|]*/() { async function f() { try { return fetch(Promise.resolve(1).then(res => "https://typescriptlang.org")); - } - catch (err) { + } catch (err) { return console.log(err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.ts index 0049c661c3904..621612a256ae9 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_PromiseCallInner.ts @@ -10,8 +10,7 @@ function /*[#|*/f/*|]*/() { async function f() { try { return fetch(Promise.resolve(1).then(res => "https://typescriptlang.org")); - } - catch (err) { + } catch (err) { return console.log(err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Scope2.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Scope2.ts index ee7cdd695db28..10370bfa502ca 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Scope2.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_Scope2.ts @@ -13,8 +13,7 @@ async function f(){ const i_1 = await fetch("https://typescriptlang.org"); const res = i_1.ok; return i + 1; - } - catch (err) { + } catch (err) { return i - 1; } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js index bbbcee9d86be7..2a614c8e7806e 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js @@ -12,8 +12,7 @@ async function f() { try { const x = await Promise.resolve(1); return await Promise.reject(x); - } - catch (err) { + } catch (err) { return console.log(err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts index bbbcee9d86be7..2a614c8e7806e 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts @@ -12,8 +12,7 @@ async function f() { try { const x = await Promise.resolve(1); return await Promise.reject(x); - } - catch (err) { + } catch (err) { return console.log(err); } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js index 8bf267e91b506..a0b40bc0f6a3b 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js @@ -11,8 +11,7 @@ async function f() { try { const x = await Promise.resolve(); x_2 = 1; - } - catch (x_1) { + } catch (x_1) { x_2 = "a"; } return !!x_2; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts index 20807ef140c5f..190e92487c207 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts @@ -11,8 +11,7 @@ async function f() { try { const x = await Promise.resolve(); x_2 = 1; - } - catch (x_1) { + } catch (x_1) { x_2 = "a"; } return !!x_2; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.js index 628a16da1a98a..845c27d45c92b 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.js @@ -11,8 +11,7 @@ async function f() { try { await Promise.resolve(); result = ({ x: 3 }); - } - catch (e) { + } catch (e) { result = ({ x: "a" }); } const { x } = result; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts index ff7ac4bc944b6..9bc5e4b178b4f 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParamsBindingPattern.ts @@ -11,8 +11,7 @@ async function f() { try { await Promise.resolve(); result = ({ x: 3 }); - } - catch (e) { + } catch (e) { result = ({ x: "a" }); } const { x } = result; diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchTypeArgument1.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchTypeArgument1.ts index cc6a114b6c0aa..728f09dc4d647 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchTypeArgument1.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchTypeArgument1.ts @@ -16,8 +16,7 @@ async function get() { try { return Promise .resolve>({ success: true, data: { email: "" } }); - } - catch (e) { + } catch (e) { const result: APIResponse<{ email: string; }> = ({ success: false }); return result; }