Skip to content

Commit e466bb9

Browse files
committed
Fix multi-file usage
1. Follow aliases with getSupers. 2. Make fix in file with superclass, not with the error.
1 parent 82d9576 commit e466bb9

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/services/codefixes/fixPropertyOverrideAccessor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace ts.codefix {
4747

4848
startPosition = baseProp.valueDeclaration.pos;
4949
endPosition = baseProp.valueDeclaration.end;
50+
file = getSourceFileOfNode(baseProp.valueDeclaration);
5051
}
5152
else {
5253
Debug.fail("fixPropertyOverrideAccessor codefix got unexpected error code " + code);

src/services/codefixes/generateAccessors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,11 @@ namespace ts.codefix {
229229
while (decl) {
230230
const superElement = getClassExtendsHeritageElement(decl);
231231
const superSymbol = superElement && checker.getSymbolAtLocation(superElement.expression);
232-
const superDecl = superSymbol && find(superSymbol.declarations, isClassLike);
233-
if (superDecl) { res.push(superDecl); }
232+
if (!superSymbol) break;
233+
const symbol = superSymbol.flags & SymbolFlags.Alias ? checker.getAliasedSymbol(superSymbol) : superSymbol;
234+
const superDecl = find(symbol.declarations, isClassLike);
235+
if (!superDecl) break;
236+
res.push(superDecl);
234237
decl = superDecl;
235238
}
236239
return res;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @strict: true
4+
5+
// @Filename: foo.ts
6+
//// import { A } from './source'
7+
//// class B extends A {
8+
//// get x() { return 2 }
9+
//// }
10+
// @Filename: source.ts
11+
//// export class A {
12+
//// x = 1
13+
//// }
14+
15+
verify.codeFix({
16+
description: `Generate 'get' and 'set' accessors`,
17+
newFileContent: {
18+
'/tests/cases/fourslash/source.ts': `export class A {
19+
private _x = 1;
20+
public get x() {
21+
return this._x;
22+
}
23+
public set x(value) {
24+
this._x = value;
25+
}
26+
}`},
27+
index: 0
28+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy