mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 05:17:43 -05:00
Use factory for all fixes
This commit is contained in:
@@ -82,15 +82,19 @@ namespace ts.codefix {
|
||||
|
||||
const className = classDeclaration.name.getText();
|
||||
|
||||
const staticInitialization = createStatement(createAssignment(
|
||||
createPropertyAccess(createIdentifier(className), tokenName),
|
||||
createIdentifier("undefined")));
|
||||
|
||||
const staticInitializationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
|
||||
staticInitializationChangeTracker.insertNodeAfter(
|
||||
classDeclarationSourceFile,
|
||||
classDeclaration,
|
||||
staticInitialization,
|
||||
{ suffix: context.newLineCharacter });
|
||||
const initializeStaticAction = {
|
||||
description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [tokenName]),
|
||||
changes: [{
|
||||
fileName: classDeclarationSourceFile.fileName,
|
||||
textChanges: [{
|
||||
span: { start: classDeclaration.getEnd(), length: 0 },
|
||||
newText: `${context.newLineCharacter}${className}.${tokenName} = undefined;${context.newLineCharacter}`
|
||||
}]
|
||||
}]
|
||||
changes: staticInitializationChangeTracker.getChanges()
|
||||
};
|
||||
|
||||
(actions || (actions = [])).push(initializeStaticAction);
|
||||
@@ -102,15 +106,20 @@ namespace ts.codefix {
|
||||
return actions;
|
||||
}
|
||||
|
||||
const propertyInitialization = createStatement(createAssignment(
|
||||
createPropertyAccess(createThis(), tokenName),
|
||||
createIdentifier("undefined")));
|
||||
|
||||
const propertyInitializationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
|
||||
propertyInitializationChangeTracker.insertNodeAt(
|
||||
classDeclarationSourceFile,
|
||||
classConstructor.body.getEnd() - 1,
|
||||
propertyInitialization,
|
||||
{ prefix: context.newLineCharacter, suffix: context.newLineCharacter });
|
||||
|
||||
const initializeAction = {
|
||||
description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]),
|
||||
changes: [{
|
||||
fileName: classDeclarationSourceFile.fileName,
|
||||
textChanges: [{
|
||||
span: { start: classConstructor.body.getEnd() - 1, length: 0 },
|
||||
newText: `this.${tokenName} = undefined;${context.newLineCharacter}`
|
||||
}]
|
||||
}]
|
||||
changes: propertyInitializationChangeTracker.getChanges()
|
||||
};
|
||||
|
||||
(actions || (actions = [])).push(initializeAction);
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
////}
|
||||
////|]
|
||||
|
||||
verify.rangeAfterCodeFix(`class C {
|
||||
verify.applyCodeFix(/*errorCode*/ undefined, /*index*/ 0);
|
||||
verify.currentFileContentIs(`class C {
|
||||
static method() {
|
||||
()=>{ this.foo === 10 };
|
||||
}
|
||||
}
|
||||
C.foo = undefined;`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0);
|
||||
C.foo = undefined;
|
||||
`);
|
||||
@@ -9,7 +9,9 @@
|
||||
////}
|
||||
////|]
|
||||
|
||||
verify.rangeAfterCodeFix(`class C {
|
||||
verify.applyCodeFix(/*errorCode*/ undefined, /*index*/ 2)
|
||||
verify.currentFileContentIs(`class C {
|
||||
static p = ()=>{ this.foo === 10 };
|
||||
}
|
||||
C.foo = undefined;`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2);
|
||||
C.foo = undefined;
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user