mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 20:25:23 -06:00
Handle class expressions
This commit is contained in:
parent
395d736843
commit
d7d4bf6b04
@ -8,8 +8,8 @@ namespace ts.codefix {
|
||||
const token = getTokenAtPosition(sourceFile, start);
|
||||
const checker = context.program.getTypeChecker();
|
||||
|
||||
const classDecl = getAncestor(token, SyntaxKind.ClassDeclaration) as ClassDeclaration;
|
||||
if (!(classDecl && isClassLike(classDecl))) {
|
||||
const classDecl = getContainingClass(token);
|
||||
if (!classDecl) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@ -6,8 +6,8 @@ namespace ts.codefix {
|
||||
const sourceFile = context.sourceFile;
|
||||
const start = context.span.start;
|
||||
const token = getTokenAtPosition(sourceFile, start);
|
||||
const classDeclNode = getAncestor(token, SyntaxKind.ClassDeclaration) as ClassDeclaration;
|
||||
if (!(token.kind === SyntaxKind.Identifier && classDeclNode && classDeclNode.kind === SyntaxKind.ClassDeclaration)) {
|
||||
const classDeclNode = getContainingClass(token);
|
||||
if (!(token.kind === SyntaxKind.Identifier && isClassLike(classDeclNode))) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@ -1359,7 +1359,7 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function getMissingAbstractMembersInsertion(classDeclaration: ClassDeclaration, resolvedType: ResolvedType, checker: TypeChecker, newlineChar: string): string {
|
||||
export function getMissingAbstractMembersInsertion(classDeclaration: ClassLikeDeclaration, resolvedType: ResolvedType, checker: TypeChecker, newlineChar: string): string {
|
||||
const missingMembers = filterMissingMembers(filterAbstract(filterNonPrivate(resolvedType.members)), classDeclaration.symbol.members);
|
||||
return getInsertionsForMembers(missingMembers, classDeclaration, checker, newlineChar);
|
||||
}
|
||||
@ -1368,7 +1368,7 @@ namespace ts {
|
||||
* Finds members of the resolved type that are missing in the class pointed to by class decl
|
||||
* and generates source code for the missing members.
|
||||
*/
|
||||
export function getMissingMembersInsertion(classDeclaration: ClassDeclaration, resolvedType: ResolvedType, checker: TypeChecker, newlineChar: string): string {
|
||||
export function getMissingMembersInsertion(classDeclaration: ClassLikeDeclaration, resolvedType: ResolvedType, checker: TypeChecker, newlineChar: string): string {
|
||||
const missingMembers = filterMissingMembers(filterNonPrivate(resolvedType.members), classDeclaration.symbol.members);
|
||||
return getInsertionsForMembers(missingMembers, classDeclaration, checker, newlineChar);
|
||||
}
|
||||
@ -1406,7 +1406,7 @@ namespace ts {
|
||||
return filterSymbolMapByDeclaration(symbolMap, decl => !(getModifierFlags(decl) & ModifierFlags.Private));
|
||||
}
|
||||
|
||||
function getInsertionsForMembers(symbolMap: MapLike<Symbol>, enclosingDeclaration: ClassDeclaration, checker: TypeChecker, newlineChar: string): string {
|
||||
function getInsertionsForMembers(symbolMap: MapLike<Symbol>, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {
|
||||
let insertion = "";
|
||||
|
||||
for (const symbolName in symbolMap) {
|
||||
@ -1415,7 +1415,7 @@ namespace ts {
|
||||
return insertion;
|
||||
}
|
||||
|
||||
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassDeclaration, checker: TypeChecker, newlineChar: string): string {
|
||||
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {
|
||||
const name = symbol.getName();
|
||||
const type = checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration);
|
||||
const declarations = symbol.getDeclarations();
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
|
||||
//// interface I { x: number; }
|
||||
////
|
||||
//// new class implements I {[| |]};
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
`);
|
||||
Loading…
x
Reference in New Issue
Block a user