-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #535 - Add getTypeExpression() to JSDocReturnTag and JSDocTypeTag
- Loading branch information
1 parent
1d3c2bb
commit 61b71b3
Showing
6 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {expect} from "chai"; | ||
import {JSDocReturnTag, TypeGuards} from "../../../../main"; | ||
import {getInfoFromText} from "../../testHelpers"; | ||
|
||
describe(nameof(JSDocReturnTag), () => { | ||
function getInfo(text: string) { | ||
const info = getInfoFromText(text); | ||
return { descendant: info.sourceFile.getFirstDescendantOrThrow(TypeGuards.isJSDocReturnTag), ...info }; | ||
} | ||
|
||
describe(nameof<JSDocReturnTag>(d => d.getTypeExpression), () => { | ||
it("should get undefined when there is no type given", () => { | ||
const { descendant } = getInfo("/** @returns t - String */\nfunction test() {}"); | ||
expect(descendant.getTypeExpression()).to.be.undefined; | ||
}); | ||
|
||
it("should get when type is given", () => { | ||
const { descendant } = getInfo("/** @returns {boolean} t - String */\nfunction test() {}"); | ||
expect(descendant.getTypeExpression()!.getTypeNode().getText()).to.equal("boolean"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {expect} from "chai"; | ||
import {TypeGuards, JSDocTypeTag} from "../../../../main"; | ||
import {getInfoFromText} from "../../testHelpers"; | ||
|
||
describe(nameof(JSDocTypeTag), () => { | ||
function getInfo(text: string) { | ||
const info = getInfoFromText(text); | ||
return { descendant: info.sourceFile.getFirstDescendantOrThrow(TypeGuards.isJSDocTypeTag), ...info }; | ||
} | ||
|
||
describe(nameof<JSDocTypeTag>(d => d.getTypeExpression), () => { | ||
it("returns undefined when typeExpression is undefined", () => { | ||
const { descendant } = getInfo("/** @type */\nvar bar = 1;"); | ||
expect(descendant.getTypeExpression()).to.be.undefined; | ||
}); | ||
|
||
it("should get when type is given", () => { | ||
const { descendant } = getInfo("/** @type {boolean} */\nvar bar = 1"); | ||
expect(descendant.getTypeExpression()!.getTypeNode().getText()).to.equal("boolean"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters