Skip to content

Commit

Permalink
Fix multi-file usage
Browse files Browse the repository at this point in the history
1. Follow aliases with getSupers.
2. Make fix in file with superclass, not with the error.
  • Loading branch information
sandersn committed May 22, 2020
1 parent 82d9576 commit e466bb9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/services/codefixes/fixPropertyOverrideAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/services/codefixes/generateAccessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions tests/cases/fourslash/codeFixPropertyOverrideAccess3.ts
Original file line number Diff line number Diff line change
@@ -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
})

0 comments on commit e466bb9

Please sign in to comment.