Skip to content

Commit d12110d

Browse files
author
Benjamin Lichtman
committed
Respond to CR
1 parent 504b5f2 commit d12110d

8 files changed

+55
-17
lines changed

src/services/codefixes/convertToAsyncFunction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,21 @@ namespace ts.codefix {
186186
}
187187
// we only care about identifiers that are parameters and declarations (don't care about other uses)
188188
else if (node.parent && (isParameter(node.parent) || isVariableDeclaration(node.parent))) {
189+
const originalName = node.text;
189190

190191
// if the identifier name conflicts with a different identifier that we've already seen
191192
if (allVarNames.some(ident => ident.originalName === node.text && ident.symbol !== symbol)) {
192193
const newName = getNewNameIfConflict(node, allVarNames);
193194
identsToRenameMap.set(symbolIdString, newName.identifier);
194195
synthNamesMap.set(symbolIdString, newName);
195-
allVarNames.push({ identifier: newName.identifier, symbol, originalName: node.text });
196+
allVarNames.push({ identifier: newName.identifier, symbol, originalName });
196197
}
197198
else {
198199
const identifier = getSynthesizedDeepClone(node);
199200
identsToRenameMap.set(symbolIdString, identifier);
200201
synthNamesMap.set(symbolIdString, { identifier, types: [], numberOfAssignmentsOriginal: allVarNames.filter(elem => elem.identifier.text === node.text).length/*, numberOfAssignmentsSynthesized: 0*/ });
201202
if ((isParameter(node.parent) && isExpressionOrCallOnTypePromise(node.parent.parent)) || isVariableDeclaration(node.parent)) {
202-
allVarNames.push({ identifier, symbol, originalName: node.text });
203+
allVarNames.push({ identifier, symbol, originalName });
203204
}
204205
}
205206
}

src/services/utilities.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,11 +1654,10 @@ namespace ts {
16541654
return clone;
16551655
}
16561656

1657-
export function getSynthesizedDeepCloneWithRenames<T extends Node | undefined>(node: T, includeTrivia = true, renameMap?: Map<Identifier>, checker?: TypeChecker, callback?: (originalNode: Node, clone: Node) => any): T {
1658-
1657+
export function getSynthesizedDeepCloneWithRenames<T extends Node>(node: T, includeTrivia = true, renameMap?: Map<Identifier>, checker?: TypeChecker, callback?: (originalNode: Node, clone: Node) => any): T {
16591658
let clone;
1660-
if (node && isIdentifier(node!) && renameMap && checker) {
1661-
const symbol = checker.getSymbolAtLocation(node!);
1659+
if (isIdentifier(node) && renameMap && checker) {
1660+
const symbol = checker.getSymbolAtLocation(node);
16621661
const renameInfo = symbol && renameMap.get(String(getSymbolId(symbol)));
16631662

16641663
if (renameInfo) {
@@ -1667,11 +1666,11 @@ namespace ts {
16671666
}
16681667

16691668
if (!clone) {
1670-
clone = node && getSynthesizedDeepCloneWorker(node as NonNullable<T>, renameMap, checker, callback);
1669+
clone = getSynthesizedDeepCloneWorker(node as NonNullable<T>, renameMap, checker, callback);
16711670
}
16721671

16731672
if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone);
1674-
if (callback && node && clone) callback(node!, clone);
1673+
if (callback && clone) callback(node, clone);
16751674

16761675
return clone as T;
16771676
}

src/testRunner/unittests/convertToAsyncFunction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ function [#|f|](): Promise<void> {
823823
}
824824
return x.then(resp => {
825825
var blob = resp.blob().then(blob => blob.byteOffset).catch(err => 'Error');
826-
return fetch("https://micorosft.com").then(res => console.log("Another one!"));
826+
return fetch("https://microsoft.com").then(res => console.log("Another one!"));
827827
});
828828
}
829829
`
@@ -1201,7 +1201,7 @@ function [#|f|]() {
12011201
`);
12021202

12031203
_testConvertToAsyncFunction("convertToAsyncFunction_bindingPattern", `
1204-
function [#|f|]():Promise<void> {
1204+
function [#|f|]() {
12051205
return fetch('https://typescriptlang.org').then(res);
12061206
}
12071207
function res({ status, trailer }){
@@ -1210,7 +1210,7 @@ function res({ status, trailer }){
12101210
`);
12111211

12121212
_testConvertToAsyncFunction("convertToAsyncFunction_bindingPatternNameCollision", `
1213-
function [#|f|]():Promise<void> {
1213+
function [#|f|]() {
12141214
const result = 'https://typescriptlang.org';
12151215
return fetch(result).then(res);
12161216
}

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_MultipleReturns2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function /*[#|*/f/*|]*/(): Promise<void> {
77
}
88
return x.then(resp => {
99
var blob = resp.blob().then(blob => blob.byteOffset).catch(err => 'Error');
10-
return fetch("https://micorosft.com").then(res => console.log("Another one!"));
10+
return fetch("https://microsoft.com").then(res => console.log("Another one!"));
1111
});
1212
}
1313

@@ -21,6 +21,6 @@ async function f(): Promise<void> {
2121
}
2222
const resp = await x;
2323
var blob = resp.blob().then(blob_1 => blob_1.byteOffset).catch(err => 'Error');
24-
const res_2 = await fetch("https://micorosft.com");
24+
const res_2 = await fetch("https://microsoft.com");
2525
return console.log("Another one!");
2626
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(res);
5+
}
6+
function res({ status, trailer }){
7+
console.log(status);
8+
}
9+
10+
// ==ASYNC FUNCTION::Convert to async function==
11+
12+
async function f() {
13+
const result = await fetch('https://typescriptlang.org');
14+
return res(result);
15+
}
16+
function res({ status, trailer }){
17+
console.log(status);
18+
}

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==ORIGINAL==
22

3-
function /*[#|*/f/*|]*/():Promise<void> {
3+
function /*[#|*/f/*|]*/() {
44
return fetch('https://typescriptlang.org').then(res);
55
}
66
function res({ status, trailer }){
@@ -9,7 +9,7 @@ function res({ status, trailer }){
99

1010
// ==ASYNC FUNCTION::Convert to async function==
1111

12-
async function f():Promise<void> {
12+
async function f() {
1313
const result = await fetch('https://typescriptlang.org');
1414
return res(result);
1515
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
const result = 'https://typescriptlang.org';
5+
return fetch(result).then(res);
6+
}
7+
function res({ status, trailer }){
8+
console.log(status);
9+
}
10+
11+
// ==ASYNC FUNCTION::Convert to async function==
12+
13+
async function f() {
14+
const result = 'https://typescriptlang.org';
15+
const result_1 = await fetch(result);
16+
return res(result_1);
17+
}
18+
function res({ status, trailer }){
19+
console.log(status);
20+
}

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==ORIGINAL==
22

3-
function /*[#|*/f/*|]*/():Promise<void> {
3+
function /*[#|*/f/*|]*/() {
44
const result = 'https://typescriptlang.org';
55
return fetch(result).then(res);
66
}
@@ -10,7 +10,7 @@ function res({ status, trailer }){
1010

1111
// ==ASYNC FUNCTION::Convert to async function==
1212

13-
async function f():Promise<void> {
13+
async function f() {
1414
const result = 'https://typescriptlang.org';
1515
const result_1 = await fetch(result);
1616
return res(result_1);

0 commit comments

Comments
 (0)