Skip to content

Commit 6bd9b76

Browse files
committed
Code review - remove 'isCallExpression' check
1 parent 58b262e commit 6bd9b76

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/services/codefixes/fixAddMissingNewOperator.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ namespace ts.codefix {
1616

1717
function addMissingNewOperator(changes: textChanges.ChangeTracker, sourceFile: SourceFile, span: TextSpan): void {
1818
const call = cast(findAncestorMatchingSpan(sourceFile, span), isCallExpression);
19-
changes.insertNodeAt(sourceFile, span.start, createToken(SyntaxKind.NewKeyword), { suffix: " " });
20-
if (isCallExpression(call.expression)) {
21-
changes.insertNodeAt(sourceFile, call.expression.getStart(sourceFile), createToken(SyntaxKind.OpenParenToken));
22-
changes.insertNodeAt(sourceFile, call.expression.end, createToken(SyntaxKind.CloseParenToken));
23-
}
19+
const newExpression = createNew(call.expression, call.typeArguments, call.arguments);
20+
21+
changes.replaceNode(sourceFile, call, newExpression);
2422
}
2523

2624
function findAncestorMatchingSpan(sourceFile: SourceFile, span: TextSpan): Node {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////class C {
4+
////}
5+
////
6+
////function foo() {
7+
//// return C;
8+
////}
9+
////
10+
////foo()!();
11+
12+
13+
verify.codeFix({
14+
description: "Add missing 'new' operator to call",
15+
index: 0,
16+
newFileContent:
17+
`class C {
18+
}
19+
20+
function foo() {
21+
return C;
22+
}
23+
24+
new (foo()!)();`
25+
});

0 commit comments

Comments
 (0)