Skip to content

Commit

Permalink
fix: Abstract methods were incorrectly returning true for .isOverload()
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Sep 8, 2018
1 parent 0dbe140 commit ef29ee1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/compiler/function/OverloadableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as errors from "../../errors";
import { getRangeFromArray, insertIntoParentTextRange, verifyAndGetIndex } from "../../manipulation";
import { Constructor } from "../../types";
import { SyntaxKind } from "../../typescript";
import { ArrayUtils } from "../../utils";
import { ArrayUtils, TypeGuards } from "../../utils";
import { BodyableNode, NamedNode } from "../base";
import { Node } from "../common";

Expand Down Expand Up @@ -52,6 +52,8 @@ export function OverloadableNode<T extends Constructor<OverloadableNodeExtension
}

isOverload() {
if (TypeGuards.isMethodDeclaration(this) && this.isAbstract())
return false;
return !this.isImplementation();
}

Expand Down
8 changes: 6 additions & 2 deletions src/tests/compiler/function/overloadableNodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe(nameof(OverloadableNode), () => {
const {sourceFile: functionSourceFile} = getInfoFromText<FunctionDeclaration>(functionCode);
const functions = functionSourceFile.getChildSyntaxListOrThrow().getChildren() as FunctionDeclaration[];

const constructorCode = `class MyClass { constructor();constructor();constructor() {} myMethod(): void;myMethod() {} }`;
const constructorCode = `class MyClass { constructor();constructor();constructor() {} myMethod(): void;myMethod() {} abstract test(); }`;
const {firstChild: classChild} = getInfoFromText<ClassDeclaration>(constructorCode);
const constructors = classChild.getChildSyntaxListOrThrow().getChildren().filter(c => c instanceof ConstructorDeclaration) as ConstructorDeclaration[];

Expand All @@ -22,13 +22,17 @@ describe(nameof(OverloadableNode), () => {
});

describe(nameof<OverloadableNode>(d => d.isOverload), () => {
it("should be an overload when is on", () => {
it("should be an overload when is one", () => {
expect(functions[0].isOverload()).to.be.true;
});

it("should not be an overload when not one", () => {
expect(functions[1].isOverload()).to.be.false;
});

it("should not be for abstract methods", () => {
expect(classChild.getMethodOrThrow(m => m.isAbstract()).isOverload()).to.be.false;
});
});

describe(nameof<OverloadableNode>(d => d.getOverloads), () => {
Expand Down

0 comments on commit ef29ee1

Please sign in to comment.