Skip to content

Commit

Permalink
Remove InfoBase
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Jul 27, 2018
1 parent c0e3731 commit 3166ef3
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/services/codefixes/fixAddMissingMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ts.codefix {
const info = getInfo(context.sourceFile, context.span.start, context.program.getTypeChecker());
if (!info) return undefined;

if (info.kind === InfoKind.enum) {
if (info.kind === InfoKind.Enum) {
const { token, parentDeclaration } = info;
const changes = textChanges.ChangeTracker.with(context, t => addEnumMemberDeclaration(t, context.program.getTypeChecker(), token, parentDeclaration));
return [createCodeFixAction(fixName, changes, [Diagnostics.Add_missing_enum_member_0, token.text], fixId, Diagnostics.Add_all_missing_members)];
Expand All @@ -39,7 +39,7 @@ namespace ts.codefix {
return;
}

if (info.kind === InfoKind.enum) {
if (info.kind === InfoKind.Enum) {
const { token, parentDeclaration } = info;
addEnumMemberDeclaration(changes, checker, token, parentDeclaration);
}
Expand Down Expand Up @@ -93,18 +93,15 @@ namespace ts.codefix {
}

type ClassOrInterface = ClassLikeDeclaration | InterfaceDeclaration;
interface InfoBase {
readonly kind: InfoKind;
const enum InfoKind { Enum, ClassOrInterface }
interface EnumInfo {
readonly kind: InfoKind.Enum;
readonly token: Identifier;
readonly parentDeclaration: EnumDeclaration | ClassOrInterface;
}
enum InfoKind { enum, class }
interface EnumInfo extends InfoBase {
readonly kind: InfoKind.enum;
readonly parentDeclaration: EnumDeclaration;
}
interface ClassOrInterfaceInfo extends InfoBase {
readonly kind: InfoKind.class;
interface ClassOrInterfaceInfo {
readonly kind: InfoKind.ClassOrInterface;
readonly token: Identifier;
readonly parentDeclaration: ClassOrInterface;
readonly makeStatic: boolean;
readonly declSourceFile: SourceFile;
Expand Down Expand Up @@ -136,11 +133,11 @@ namespace ts.codefix {
const declSourceFile = classOrInterface.getSourceFile();
const inJs = isSourceFileJavaScript(declSourceFile);
const call = tryCast(parent.parent, isCallExpression);
return { kind: InfoKind.class, token, parentDeclaration: classOrInterface, makeStatic, declSourceFile, inJs, call };
return { kind: InfoKind.ClassOrInterface, token, parentDeclaration: classOrInterface, makeStatic, declSourceFile, inJs, call };
}
const enumDeclaration = find(symbol.declarations, isEnumDeclaration);
if (enumDeclaration) {
return { kind: InfoKind.enum, token, parentDeclaration: enumDeclaration };
return { kind: InfoKind.Enum, token, parentDeclaration: enumDeclaration };
}
return undefined;
}
Expand Down

0 comments on commit 3166ef3

Please sign in to comment.