Skip to content

Commit c2517ee

Browse files
committed
Add test for property access
1 parent b051976 commit c2517ee

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/services/codefixes/addMissingAwait.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace ts.codefix {
33
type ContextualTrackChangesFunction = (cb: (changeTracker: textChanges.ChangeTracker) => void) => FileTextChanges[];
44
const fixId = "addMissingAwait";
5+
const propertyAccessCode = Diagnostics.Property_0_does_not_exist_on_type_1.code;
56
const callableConstructableErrorCodes = [
67
Diagnostics.This_expression_is_not_callable.code,
78
Diagnostics.This_expression_is_not_constructable.code,
@@ -21,7 +22,7 @@ namespace ts.codefix {
2122
Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator.code,
2223
Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator.code,
2324
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
24-
Diagnostics.Property_0_does_not_exist_on_type_1.code,
25+
propertyAccessCode,
2526
...callableConstructableErrorCodes,
2627
];
2728

@@ -140,6 +141,12 @@ namespace ts.codefix {
140141
changeTracker.replaceNode(sourceFile, left, newLeft);
141142
changeTracker.replaceNode(sourceFile, right, newRight);
142143
}
144+
else if (errorCode === propertyAccessCode && isPropertyAccessExpression(insertionSite.parent)) {
145+
changeTracker.replaceNode(
146+
sourceFile,
147+
insertionSite.parent.expression,
148+
createParen(createAwait(insertionSite.parent.expression)));
149+
}
143150
else if (contains(callableConstructableErrorCodes, errorCode) && isCallOrNewExpression(insertionSite.parent)) {
144151
changeTracker.replaceNode(sourceFile, insertionSite, createParen(createAwait(insertionSite)));
145152
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
////async function fn(a: Promise<{ x: string }>) {
3+
//// a.x;
4+
////}
5+
6+
verify.codeFix({
7+
description: ts.Diagnostics.Add_await.message,
8+
index: 0,
9+
newFileContent:
10+
`async function fn(a: Promise<{ x: string }>) {
11+
(await a).x;
12+
}`
13+
});

0 commit comments

Comments
 (0)