-
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: #547 - Wrap JSDocSignature and JSDocType.
Still need to add more methods on JSDocSignature, but not going to bother for the time being.
- Loading branch information
Showing
10 changed files
with
117 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ts } from "../../../typescript"; | ||
import { JSDocType } from "./JSDocType"; | ||
|
||
/** | ||
* JS doc signature node. | ||
*/ | ||
export class JSDocSignature extends JSDocType<ts.JSDocSignature> { | ||
/** | ||
* Gets the type node of the JS doc signature. | ||
*/ | ||
getTypeNode() { | ||
return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); | ||
} | ||
|
||
// todo: more methods | ||
} |
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,8 @@ | ||
import { ts } from "../../../typescript"; | ||
import { TypeNode } from "../type"; | ||
|
||
/** | ||
* JS doc type node. | ||
*/ | ||
export class JSDocType<T extends ts.JSDocType = ts.JSDocType> extends TypeNode<T> { | ||
} |
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
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,28 @@ | ||
import { expect } from "chai"; | ||
import { JSDocSignature } from "../../../../compiler"; | ||
import { SyntaxKind } from "../../../../typescript"; | ||
import { getInfoFromTextWithDescendant } from "../../testHelpers"; | ||
|
||
describe(nameof(JSDocSignature), () => { | ||
function getInfo(text: string) { | ||
return getInfoFromTextWithDescendant<JSDocSignature>(text, SyntaxKind.JSDocSignature); | ||
} | ||
|
||
describe(nameof<JSDocSignature>(d => d.getTypeNode), () => { | ||
function doTest(text: string, expected: string | undefined) { | ||
const { descendant } = getInfo(text); | ||
if (expected == null) | ||
expect(descendant.getTypeNode()).to.be.undefined; | ||
else | ||
expect(descendant.getTypeNode()!.getText()).to.equal(expected); | ||
} | ||
|
||
it("should get when it exists", () => { | ||
doTest("/**\n * @callback cb\n * @return {string}\n */\nlet x;", "@return {string}"); | ||
}); | ||
|
||
it("should be undefined when not exists", () => { | ||
doTest("/**\n * @callback cb\n */\nlet x;", undefined); | ||
}); | ||
}); | ||
}); |
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