Initial review

This commit is contained in:
iliashkolyar committed 2018-09-11 13:56:51 +03:00
1 parent 76c6ee6e53
commit 8b14fb22ec
5 files changed
+35 -14

No files matched your search

+2 -2
View File
@@ -4624,11 +4624,11 @@
"category": "Message",
"code": 95066
},
"Add missing 'new' operator to caller": {
"Add missing 'new' operator to call": {
"category": "Message",
"code": 95067
},
"Add missing 'new' operator to all callers": {
"Add missing 'new' operator to all calls": {
"category": "Message",
"code": 95068
}
@@ -6,24 +6,23 @@ namespace ts.codefix {
errorCodes,
getCodeActions(context) {
const { sourceFile, span } = context;
const identifierWithoutNew = getIdentifier(sourceFile, span.start);
const changes = textChanges.ChangeTracker.with(context, t => addMissingNewOperator(t, sourceFile, identifierWithoutNew));
return [createCodeFixAction(fixId, changes, Diagnostics.Add_missing_new_operator_to_caller, fixId, Diagnostics.Add_missing_new_operator_to_all_callers)];
const missingNewExpression = getMissingNewExpression(sourceFile, span.start);
const changes = textChanges.ChangeTracker.with(context, t => addMissingNewOperator(t, sourceFile, missingNewExpression));
return [createCodeFixAction(fixId, changes, Diagnostics.Add_missing_new_operator_to_call, fixId, Diagnostics.Add_missing_new_operator_to_all_calls)];
},
fixIds: [fixId],
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) =>
addMissingNewOperator(changes, context.sourceFile, getIdentifier(diag.file, diag.start))),
addMissingNewOperator(changes, context.sourceFile, getMissingNewExpression(diag.file, diag.start))),
});
function getIdentifier(sourceFile: SourceFile, pos: number): Identifier {
function getMissingNewExpression(sourceFile: SourceFile, pos: number): Expression {
const token = getTokenAtPosition(sourceFile, pos);
Debug.assert(token.kind === SyntaxKind.Identifier);
Debug.assert(isCallExpression(token.parent));
return <Identifier>token;
return <Expression>token;
}
function addMissingNewOperator(changes: textChanges.ChangeTracker, sourceFile: SourceFile, identifierWithoutNew: Identifier): void {
const newTypeNode = createNew(identifierWithoutNew, /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
changes.replaceNode(sourceFile, identifierWithoutNew, newTypeNode);
function addMissingNewOperator(changes: textChanges.ChangeTracker, sourceFile: SourceFile, missingNewExpression: Expression): void {
const newTypeNode = createNew(missingNewExpression, /*typeArguments*/ undefined, /*argumentsArray*/ undefined);
changes.replaceNode(sourceFile, missingNewExpression, newTypeNode);
}
}