Fix multi-file usage

1. Follow aliases with getSupers.
2. Make fix in file with superclass, not with the error.
This commit is contained in:
Nathan Shively-Sanders 2020-05-22 09:06:05 -07:00
parent 82d9576d9b
commit e466bb94c1
3 changed files with 34 additions and 2 deletions

View file

@ -47,6 +47,7 @@ namespace ts.codefix {
startPosition = baseProp.valueDeclaration.pos;
endPosition = baseProp.valueDeclaration.end;
file = getSourceFileOfNode(baseProp.valueDeclaration);
}
else {
Debug.fail("fixPropertyOverrideAccessor codefix got unexpected error code " + code);

View file

@ -229,8 +229,11 @@ namespace ts.codefix {
while (decl) {
const superElement = getClassExtendsHeritageElement(decl);
const superSymbol = superElement && checker.getSymbolAtLocation(superElement.expression);
const superDecl = superSymbol && find(superSymbol.declarations, isClassLike);
if (superDecl) { res.push(superDecl); }
if (!superSymbol) break;
const symbol = superSymbol.flags & SymbolFlags.Alias ? checker.getAliasedSymbol(superSymbol) : superSymbol;
const superDecl = find(symbol.declarations, isClassLike);
if (!superDecl) break;
res.push(superDecl);
decl = superDecl;
}
return res;

View file

@ -0,0 +1,28 @@
/// <reference path='fourslash.ts' />
// @strict: true
// @Filename: foo.ts
//// import { A } from './source'
//// class B extends A {
//// get x() { return 2 }
//// }
// @Filename: source.ts
//// export class A {
//// x = 1
//// }
verify.codeFix({
description: `Generate 'get' and 'set' accessors`,
newFileContent: {
'/tests/cases/fourslash/source.ts': `export class A {
private _x = 1;
public get x() {
return this._x;
}
public set x(value) {
this._x = value;
}
}`},
index: 0
})