Skip to content

Commit

Permalink
Add JSDocOverloadTag and JSDocSatisfiesTag.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 17, 2023
1 parent 9082b3d commit c4a57f8
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 463 deletions.
4 changes: 2 additions & 2 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"dist-deno"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.78.0.wasm",
"https://plugins.dprint.dev/typescript-0.83.0.wasm",
"https://plugins.dprint.dev/json-0.7.2.wasm",
"https://plugins.dprint.dev/markdown-0.14.0.wasm"
"https://plugins.dprint.dev/markdown-0.15.2.wasm"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function createNodeTypeGuards(inspector: TsMorphInspector, tsInspector: T
...common,
kind: tsMorph.StructureKind.Method,
docs: [{
description: description + "\r\n@param node - Node to check.",
description,
}],
typeParameters: method.isMixin ? [{ name: "T", constraint: "compiler.Node" }] : [],
parameters: [{ name: "node", type: method.isMixin ? "T | undefined" : "compiler.Node | undefined" }],
Expand Down
572 changes: 121 additions & 451 deletions packages/ts-morph/src/compiler/ast/common/Node.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/JSDocOverloadTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ts } from "@ts-morph/common";
import { JSDocTypeExpressionableTag } from "./base";
import { JSDocTag } from "./JSDocTag";

export const JSDocOverloadTagBase = JSDocTypeExpressionableTag(JSDocTag);
/** JS doc overload tag. */
export class JSDocOverloadTag extends JSDocOverloadTagBase<ts.JSDocOverloadTag> {
}
10 changes: 10 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/JSDocSatisfiesTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ts } from "@ts-morph/common";
import { JSDocTypeExpressionableTag } from "./base";
import { JSDocTag } from "./JSDocTag";

export const JSDocSatisfiesTagBase = JSDocTypeExpressionableTag(JSDocTag);
/**
* JS doc satifiest tag.
*/
export class JSDocSatisfiesTag extends JSDocSatisfiesTagBase<ts.JSDocSatisfiesTag> {
}
2 changes: 2 additions & 0 deletions packages/ts-morph/src/compiler/ast/doc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from "./JSDocNameReference";
export * from "./JSDocNonNullableType";
export * from "./JSDocNullableType";
export * from "./JSDocOptionalType";
export * from "./JSDocOverloadTag";
export * from "./JSDocOverrideTag";
export * from "./JSDocParameterTag";
export * from "./JSDocPrivateTag";
Expand All @@ -26,6 +27,7 @@ export * from "./JSDocProtectedTag";
export * from "./JSDocPublicTag";
export * from "./JSDocReadonlyTag";
export * from "./JSDocReturnTag";
export * from "./JSDocSatisfiesTag";
export * from "./JSDocSeeTag";
export * from "./JSDocSignature";
export * from "./JSDocTag";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ function getOverloadsAndImplementation(node: OverloadableNodeExtensionType & Ove
}

function getNameIfNamedNode(node: Node) {
const nodeAsNamedNode = (node as any as NamedNode);
const nodeAsNamedNode = node as any as NamedNode;
if (nodeAsNamedNode.getName instanceof Function)
return nodeAsNamedNode.getName();
return undefined;
}

function getStaticIfStaticable(node: Node) {
const nodeAsStaticableNode = (node as any as StaticableNode);
const nodeAsStaticableNode = node as any as StaticableNode;
if (nodeAsStaticableNode.isStatic instanceof Function)
return nodeAsStaticableNode.isStatic();
return false;
Expand Down
2 changes: 2 additions & 0 deletions packages/ts-morph/src/compiler/ast/kindToNodeMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface ImplementedKindToNodeMappings {
[SyntaxKind.JSDocPublicTag]: compiler.JSDocPublicTag;
[SyntaxKind.JSDocReturnTag]: compiler.JSDocReturnTag;
[SyntaxKind.JSDocReadonlyTag]: compiler.JSDocReadonlyTag;
[SyntaxKind.JSDocOverloadTag]: compiler.JSDocOverloadTag;
[SyntaxKind.JSDocSatisfiesTag]: compiler.JSDocSatisfiesTag;
[SyntaxKind.JSDocSeeTag]: compiler.JSDocSeeTag;
[SyntaxKind.JSDocSignature]: compiler.JSDocSignature;
[SyntaxKind.JSDocTag]: compiler.JSDocUnknownTag;
Expand Down
2 changes: 2 additions & 0 deletions packages/ts-morph/src/factories/kindToWrapperMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const kindToWrapperMappings: { [key: number]: unknown } = {
[SyntaxKind.JSDocPublicTag]: compiler.JSDocPublicTag,
[SyntaxKind.JSDocReturnTag]: compiler.JSDocReturnTag,
[SyntaxKind.JSDocReadonlyTag]: compiler.JSDocReadonlyTag,
[SyntaxKind.JSDocOverloadTag]: compiler.JSDocOverloadTag,
[SyntaxKind.JSDocSatisfiesTag]: compiler.JSDocSatisfiesTag,
[SyntaxKind.JSDocSeeTag]: compiler.JSDocSeeTag,
[SyntaxKind.JSDocSignature]: compiler.JSDocSignature,
[SyntaxKind.JSDocTag]: compiler.JSDocUnknownTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("ChildOrderableNode", () => {
describe("enum", () => {
function doThrowTest(startCode: string, newIndex: number) {
const { sourceFile } = getInfoFromText(startCode);
const enumDec = (sourceFile.getChildSyntaxListOrThrow().getChildren()[0] as EnumDeclaration);
const enumDec = sourceFile.getChildSyntaxListOrThrow().getChildren()[0] as EnumDeclaration;
expect(() => enumDec.setOrder(newIndex)).to.throw();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ts-morph/src/tests/compiler/ast/common/nodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ class MyClass {
function doTest(startText: string, replaceText: string | WriterFunction, expectedText: string) {
const { sourceFile } = getInfoFromText(startText);
const varDeclaration = sourceFile.getVariableDeclarations()[0];
const propAccess = (varDeclaration.getInitializerOrThrow() as PropertyAccessExpression);
const propAccess = varDeclaration.getInitializerOrThrow() as PropertyAccessExpression;
let newNode: Node;
if (typeof replaceText === "string")
newNode = propAccess.replaceWithText(replaceText);
Expand Down Expand Up @@ -1238,7 +1238,7 @@ class MyClass {
it("should throw when replacing with more than one node", () => {
const { sourceFile } = getInfoFromText("var t = Some.Prop.Access;");
const varDeclaration = sourceFile.getVariableDeclarations()[0];
const propAccess = (varDeclaration.getInitializerOrThrow() as PropertyAccessExpression);
const propAccess = varDeclaration.getInitializerOrThrow() as PropertyAccessExpression;
expect(() => {
propAccess.replaceWithText("SomeTest; Test");
}).to.throw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("ComputedPropertyName", () => {
describe(nameof<ComputedPropertyName>("getExpression"), () => {
function doTest(text: string, expectedText: string) {
const { firstProp } = getInfoFromTextWithFirstInterfaceProperty(text);
const computedPropertyName = (firstProp.getNameNode() as ComputedPropertyName);
const computedPropertyName = firstProp.getNameNode() as ComputedPropertyName;
expect(computedPropertyName.getExpression().getText()).to.equal(expectedText);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("PrivateIdentifier", () => {
describe(nameof<PrivateIdentifier>("getText"), () => {
function doTest(text: string, expectedText: string) {
const { firstProp } = getInfoFromTextWithFirstProperty(text);
const identifier = (firstProp.getNameNode() as PrivateIdentifier);
const identifier = firstProp.getNameNode() as PrivateIdentifier;
expect(identifier.getText()).to.equal(expectedText);
}

Expand All @@ -25,7 +25,7 @@ describe("PrivateIdentifier", () => {
describe(nameof<PrivateIdentifier>("rename"), () => {
function doTest(text: string, newName: string, expectedText: string) {
const { sourceFile, firstProp } = getInfoFromTextWithFirstProperty(text);
const identifier = (firstProp.getNameNode() as PrivateIdentifier);
const identifier = firstProp.getNameNode() as PrivateIdentifier;
identifier.rename(newName);
if (!newName.startsWith("#"))
expect(identifier.wasForgotten()).to.be.true;
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-morph/src/tests/issues/0708tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("tests for issue #706", () => {
statement;
}`,
);
const ifStatement = (file.getStatements()[0] as IfStatement);
const ifStatement = file.getStatements()[0] as IfStatement;
const elseStatement = ifStatement.getElseStatement()!;
elseStatement.remove();

Expand Down

0 comments on commit c4a57f8

Please sign in to comment.