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:
parent
82d9576d9b
commit
e466bb94c1
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
28
tests/cases/fourslash/codeFixPropertyOverrideAccess3.ts
Normal file
28
tests/cases/fourslash/codeFixPropertyOverrideAccess3.ts
Normal 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
|
||||
})
|
Loading…
Reference in a new issue