Skip to content

Commit

Permalink
refactor: JSDocTag.getName() should be .getTagName()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `JSDocTag`'s `.getName()` is now `.getTagName()`. This was necessary because `.getName()` should return a `JSDocPropertyLikeTag`'s name.
  • Loading branch information
dsherret committed Oct 26, 2018
1 parent 674d3d2 commit c362510
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ts-simple-ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4923,7 +4923,7 @@ export declare class JSDocTag<NodeType extends ts.JSDocTag = ts.JSDocTag> extend
/**
* Gets the tag's name as a string.
*/
getName(): string;
getTagName(): string;
/**
* Gets the tag name node.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast/doc/JSDocTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class JSDocTag<NodeType extends ts.JSDocTag = ts.JSDocTag> extends Node<N
/**
* Gets the tag's name as a string.
*/
getName() {
getTagName() {
return this.getTagNameNode().getText();
}

Expand Down
47 changes: 47 additions & 0 deletions src/tests/compiler/doc/jsDocTagTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect } from "chai";
import { JSDocTag } from "../../../compiler";
import { TypeGuards } from "../../../utils";
import { getInfoFromText } from "../testHelpers";

describe(nameof(JSDocTag), () => {
function getInfo(text: string) {
const info = getInfoFromText(text);
return { descendant: info.sourceFile.getFirstDescendantOrThrow(TypeGuards.isJSDocTag), ...info };
}

describe(nameof<JSDocTag>(d => d.getAtToken), () => {
it("should get the at token", () => {
const { descendant } = getInfo("/** @param t - String */\nfunction test() {}");
expect(descendant.getAtToken().getText()).to.equal("@");
});
});

describe(nameof<JSDocTag>(d => d.getTagName), () => {
it("should get the tag name", () => {
const { descendant } = getInfo("/** @param t - String */\nfunction test() {}");
expect(descendant.getTagName()).to.equal("param");
});
});

describe(nameof<JSDocTag>(d => d.getTagNameNode), () => {
it("should get the tag name node", () => {
const { descendant } = getInfo("/** @param t - String */\nfunction test() {}");
expect(descendant.getTagNameNode().getText()).to.equal("param");
});
});

describe(nameof<JSDocTag>(d => d.getComment), () => {
function doTest(text: string, expected: string | undefined) {
const { descendant } = getInfo(text);
expect(descendant.getComment()).to.equal(expected);
}

it("should get the tag comment", () => {
doTest("/** @param t - String*/\nfunction test() {}", "- String");
});

it("should return undefined when not exists", () => {
doTest("/** @param */\nfunction test() {}", undefined);
});
});
});

0 comments on commit c362510

Please sign in to comment.