mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 07:55:10 -05:00
Code review - remove 'isCallExpression' check
This commit is contained in:
@@ -16,11 +16,9 @@ namespace ts.codefix {
|
||||
|
||||
function addMissingNewOperator(changes: textChanges.ChangeTracker, sourceFile: SourceFile, span: TextSpan): void {
|
||||
const call = cast(findAncestorMatchingSpan(sourceFile, span), isCallExpression);
|
||||
changes.insertNodeAt(sourceFile, span.start, createToken(SyntaxKind.NewKeyword), { suffix: " " });
|
||||
if (isCallExpression(call.expression)) {
|
||||
changes.insertNodeAt(sourceFile, call.expression.getStart(sourceFile), createToken(SyntaxKind.OpenParenToken));
|
||||
changes.insertNodeAt(sourceFile, call.expression.end, createToken(SyntaxKind.CloseParenToken));
|
||||
}
|
||||
const newExpression = createNew(call.expression, call.typeArguments, call.arguments);
|
||||
|
||||
changes.replaceNode(sourceFile, call, newExpression);
|
||||
}
|
||||
|
||||
function findAncestorMatchingSpan(sourceFile: SourceFile, span: TextSpan): Node {
|
||||
|
||||
25
tests/cases/fourslash/codeFixAddMissingNew5.ts
Normal file
25
tests/cases/fourslash/codeFixAddMissingNew5.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class C {
|
||||
////}
|
||||
////
|
||||
////function foo() {
|
||||
//// return C;
|
||||
////}
|
||||
////
|
||||
////foo()!();
|
||||
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add missing 'new' operator to call",
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`class C {
|
||||
}
|
||||
|
||||
function foo() {
|
||||
return C;
|
||||
}
|
||||
|
||||
new (foo()!)();`
|
||||
});
|
||||
Reference in New Issue
Block a user